Commit 2086aa20 authored by Dominik Haumann's avatar Dominik Haumann
Browse files

add unit test for crash in code folding (bug311866)

todo: make sure the cursor position is valid (in visible text area)
if the code folding changes. This fix should not be done in
KateViewInternal::regionVisibilityChanged() as then we run into selection
bugs like e.g. http://bugs.kde.org/show_bug.cgi?id=295632

bug tracker: http://bugs.kde.org/show_bug.cgi?id=311866
CCBUG: 311866
parent 07c16f50
int main()
{
int this_line_is_safe=1;
int that_line_will_cause_havoc=1;
}
\ No newline at end of file
......@@ -22,6 +22,8 @@
#include <qtest_kde.h>
#include <kateglobal.h>
#include <katebuffer.h>
#include <katedocument.h>
#include <kateview.h>
#include <ktexteditor/movingcursor.h>
......@@ -42,6 +44,16 @@ QTEST_KDEMAIN(KateFoldingTest, GUI)
}
}
void KateFoldingTest::initTestCase()
{
KateGlobal::self()->incRef();
}
void KateFoldingTest::cleanupTestCase()
{
KateGlobal::self()->decRef();
}
void KateFoldingTest::testFolding_data()
{
QTest::addColumn<QString>("text");
......@@ -417,3 +429,29 @@ void KateFoldingTest::testFindNodeForPosition()
QVERIFY(doc.foldingTree()->findNodeForLine(1));
QVERIFY(doc.foldingTree()->findNodeForLine(0));
}
// This is a unit test for bug 311866 (http://bugs.kde.org/show_bug.cgi?id=311866)
// It loads 5 lines of C++ code, places the cursor in line 4, and then folds
// the code.
// Expected behavior: the cursor should be moved so it stays visible
// Buggy behavior: the cursor is hidden, and moving the hidden cursor crashes kate
void KateFoldingTest::testCrash311866()
{
KateDocument doc(false, false, false);
QString url = KDESRCDIR + QString("bug311866.cpp");
doc.openUrl(url);
doc.setHighlightingMode("C++");
doc.buffer().ensureHighlighted (6);
KateView* view = static_cast<KateView*>(doc.createView(0));
view->show();
view->resize(400, 300);
view->setCursorPosition(Cursor(3, 0));
QTest::qWait(100);
doc.foldingTree()->collapseToplevelNodes();
doc.buffer().ensureHighlighted (6);
qDebug() << "!!! Does the next line crash?";
view->up();
}
......@@ -25,14 +25,13 @@
class KateFoldingTest : public QObject
{
//friend class KateCodeFoldingTree;
Q_OBJECT
//public:
public Q_SLOTS:
void initTestCase();
void cleanupTestCase();
private Q_SLOTS:
void testFolding_data();
void testFolding();
void testFoldingReload();
......@@ -43,6 +42,8 @@ private Q_SLOTS:
void testFolding_collapse_dsComments_C();
void testFolding_collapse_dsComments_XML();
void testFindNodeForPosition();
void testCrash311866();
};
#endif // KATE_FOLDING_TEST_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment