tests/auto/qtextcursor/tst_qtextcursor.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   146 
   146 
   147     void task244408_wordUnderCursor_data();
   147     void task244408_wordUnderCursor_data();
   148     void task244408_wordUnderCursor();
   148     void task244408_wordUnderCursor();
   149 
   149 
   150     void adjustCursorsOnInsert();
   150     void adjustCursorsOnInsert();
       
   151 
       
   152     void cursorPositionWithBlockUndoAndRedo();
   151 
   153 
   152 private:
   154 private:
   153     int blockCount();
   155     int blockCount();
   154 
   156 
   155     QTextDocument *doc;
   157     QTextDocument *doc;
  1745     cursor.insertText(QLatin1String("x"));
  1747     cursor.insertText(QLatin1String("x"));
  1746     QCOMPARE(selection.position(), posBefore);
  1748     QCOMPARE(selection.position(), posBefore);
  1747     QCOMPARE(selection.anchor(), posAfter);
  1749     QCOMPARE(selection.anchor(), posAfter);
  1748     doc->undo();
  1750     doc->undo();
  1749 
  1751 
  1750 
  1752 }
  1751 
  1753 void tst_QTextCursor::cursorPositionWithBlockUndoAndRedo()
  1752 
  1754 {
       
  1755     cursor.insertText("AAAABBBBCCCCDDDD");
       
  1756     cursor.beginEditBlock();
       
  1757     cursor.setPosition(12);
       
  1758     int cursorPositionBefore = cursor.position();
       
  1759     cursor.insertText("*");
       
  1760     cursor.setPosition(8);
       
  1761     cursor.insertText("*");
       
  1762     cursor.setPosition(4);
       
  1763     cursor.insertText("*");
       
  1764     cursor.setPosition(0);
       
  1765     cursor.insertText("*");
       
  1766     int cursorPositionAfter = cursor.position();
       
  1767     cursor.endEditBlock();
       
  1768 
       
  1769     QVERIFY(doc->toPlainText() == "*AAAA*BBBB*CCCC*DDDD");
       
  1770     QCOMPARE(12, cursorPositionBefore);
       
  1771     QCOMPARE(1, cursorPositionAfter);
       
  1772 
       
  1773     doc->undo(&cursor);
       
  1774     QVERIFY(doc->toPlainText() == "AAAABBBBCCCCDDDD");
       
  1775     QCOMPARE(cursor.position(), cursorPositionBefore);
       
  1776     doc->redo(&cursor);
       
  1777     QVERIFY(doc->toPlainText() == "*AAAA*BBBB*CCCC*DDDD");
       
  1778     QCOMPARE(cursor.position(), cursorPositionAfter);
  1753 }
  1779 }
  1754 
  1780 
  1755 QTEST_MAIN(tst_QTextCursor)
  1781 QTEST_MAIN(tst_QTextCursor)
  1756 #include "tst_qtextcursor.moc"
  1782 #include "tst_qtextcursor.moc"