File indexing completed on 2024-04-21 07:44:11

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2012-2018 Dominik Haumann <dhaumann@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "bug313769.h"
0009 #include "moc_bug313769.cpp"
0010 
0011 #include <katebuffer.h>
0012 #include <kateconfig.h>
0013 #include <katedocument.h>
0014 #include <kateglobal.h>
0015 #include <kateview.h>
0016 #include <ktexteditor/range.h>
0017 
0018 #include <QTest>
0019 
0020 QTEST_MAIN(BugTest)
0021 
0022 using namespace KTextEditor;
0023 
0024 BugTest::BugTest()
0025     : QObject()
0026 {
0027 }
0028 
0029 BugTest::~BugTest()
0030 {
0031 }
0032 
0033 void BugTest::initTestCase()
0034 {
0035     KTextEditor::EditorPrivate::enableUnitTestMode();
0036 }
0037 
0038 void BugTest::cleanupTestCase()
0039 {
0040 }
0041 
0042 void BugTest::tryCrash()
0043 {
0044     KTextEditor::DocumentPrivate doc(false, false);
0045     const QUrl url = QUrl::fromLocalFile(QLatin1String(TEST_DATA_DIR "bug313769.cpp"));
0046     doc.openUrl(url);
0047     doc.discardDataRecovery();
0048     doc.setHighlightingMode(QStringLiteral("C++"));
0049     doc.buffer().ensureHighlighted(doc.lines());
0050 
0051     // view must be visible...
0052     KTextEditor::ViewPrivate *view = static_cast<KTextEditor::ViewPrivate *>(doc.createView(nullptr));
0053     view->show();
0054     view->resize(900, 800);
0055     view->config()->setDynWordWrap(true);
0056     view->setSelection(Range(2, 0, 74, 0));
0057     view->setCursorPosition(Cursor(74, 0));
0058 
0059     doc.editStart();
0060     QString text = doc.line(1);
0061     doc.insertLine(74, text);
0062     doc.removeLine(1);
0063     view->setCursorPosition(Cursor(1, 0));
0064     doc.editEnd();
0065 
0066     QTest::qWait(200);
0067     // fold toplevel nodes
0068     for (int line = 0; line < doc.lines(); ++line) {
0069         if (view->textFolding().isLineVisible(line)) {
0070             view->foldLine(line);
0071         }
0072     }
0073     doc.buffer().ensureHighlighted(doc.lines());
0074 
0075     view->setCursorPosition(Cursor(0, 0));
0076 
0077     QTest::qWait(100);
0078     doc.undo();
0079     QTest::qWait(100);
0080     doc.redo();
0081     QTest::qWait(500);
0082     qDebug() << "!!! Does undo crash?";
0083     doc.undo();
0084 
0085     QTest::qWait(500);
0086     qDebug() << "!!! No crash (qWait not long enough)? Nice!";
0087 }