diff options
author | mae <qt-info@nokia.com> | 2009-12-04 12:57:44 (GMT) |
---|---|---|
committer | mae <qt-info@nokia.com> | 2009-12-04 13:07:02 (GMT) |
commit | 9c8a41a157cf9ffbb6d839d05c4502fef59e21c6 (patch) | |
tree | 03b3d82d5126c2f1529f9b88c4a0a6dcf5416a6c /tests/auto/qtextcursor | |
parent | 500996b13b96d2868a7da78d782108c2996684ec (diff) | |
download | Qt-9c8a41a157cf9ffbb6d839d05c4502fef59e21c6.zip Qt-9c8a41a157cf9ffbb6d839d05c4502fef59e21c6.tar.gz Qt-9c8a41a157cf9ffbb6d839d05c4502fef59e21c6.tar.bz2 |
Added auto test for the cursor position when doing block undo and redo
Block changes in different selections happens quite frequently with
Qt Creator, e.g. when renaming local variables. This test tests the
desired cursor position behaviour: after an undo, the cursor should be
where it was when the block operation started. After a redo, the cursor
should be where it was after the block operation ended.
Diffstat (limited to 'tests/auto/qtextcursor')
-rw-r--r-- | tests/auto/qtextcursor/tst_qtextcursor.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/auto/qtextcursor/tst_qtextcursor.cpp b/tests/auto/qtextcursor/tst_qtextcursor.cpp index d910c8d..d0c2afd 100644 --- a/tests/auto/qtextcursor/tst_qtextcursor.cpp +++ b/tests/auto/qtextcursor/tst_qtextcursor.cpp @@ -149,6 +149,8 @@ private slots: void adjustCursorsOnInsert(); + void cursorPositionWithBlockUndoAndRedo(); + private: int blockCount(); @@ -1747,9 +1749,33 @@ void tst_QTextCursor::adjustCursorsOnInsert() QCOMPARE(selection.anchor(), posAfter); doc->undo(); +} +void tst_QTextCursor::cursorPositionWithBlockUndoAndRedo() +{ + cursor.insertText("AAAABBBBCCCCDDDD"); + cursor.beginEditBlock(); + cursor.setPosition(12); + int cursorPositionBefore = cursor.position(); + cursor.insertText("*"); + cursor.setPosition(8); + cursor.insertText("*"); + cursor.setPosition(4); + cursor.insertText("*"); + cursor.setPosition(0); + cursor.insertText("*"); + int cursorPositionAfter = cursor.position(); + cursor.endEditBlock(); + QVERIFY(doc->toPlainText() == "*AAAA*BBBB*CCCC*DDDD"); + QCOMPARE(12, cursorPositionBefore); + QCOMPARE(1, cursorPositionAfter); - + doc->undo(&cursor); + QVERIFY(doc->toPlainText() == "AAAABBBBCCCCDDDD"); + QCOMPARE(cursor.position(), cursorPositionBefore); + doc->redo(&cursor); + QVERIFY(doc->toPlainText() == "*AAAA*BBBB*CCCC*DDDD"); + QCOMPARE(cursor.position(), cursorPositionAfter); } QTEST_MAIN(tst_QTextCursor) |