diff options
author | aavit <qt-info@nokia.com> | 2011-09-17 21:44:51 +0200 |
---|---|---|
committer | aavit <qt-info@nokia.com> | 2011-09-17 22:27:51 +0200 |
commit | f7a6de98e4e234833966fbe81b8ab54eba9f8429 (patch) | |
tree | 012247296bab712fcd19b92cf1a5990fd0ed2af1 /tests/auto/qtextedit/tst_qtextedit.cpp | |
parent | 8b2ee10cb1113c27d37b52dba6f7aa28d2de55b9 (diff) | |
parent | cee22b68ed811f5b26a891d6a644613ad79aa981 (diff) | |
download | qt4-tools-f7a6de98e4e234833966fbe81b8ab54eba9f8429.tar.gz |
Merge remote branch 'qt-mainline/4.8'
Diffstat (limited to 'tests/auto/qtextedit/tst_qtextedit.cpp')
-rw-r--r-- | tests/auto/qtextedit/tst_qtextedit.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/auto/qtextedit/tst_qtextedit.cpp b/tests/auto/qtextedit/tst_qtextedit.cpp index 42ea3b10d9..73d09f4371 100644 --- a/tests/auto/qtextedit/tst_qtextedit.cpp +++ b/tests/auto/qtextedit/tst_qtextedit.cpp @@ -138,6 +138,8 @@ private slots: void textSemantics(); #endif void cursorPositionChanged(); + void mouseSelection(); + void mouseSelectionDClick(); void setTextCursor(); #ifndef QT_NO_CLIPBOARD void undoAvailableAfterPaste(); @@ -785,6 +787,45 @@ void tst_QTextEdit::cursorPositionChanged() QCOMPARE(ed->textCursor().position(), 0); } +void tst_QTextEdit::mouseSelection() +{ + ed->show(); + ed->setPlainText(("Hello World")); + QTextCursor cursor = ed->textCursor(); + cursor.setPosition(1); + QPoint p1 = ed->cursorRect(cursor).center(); + cursor.setPosition(10); + QPoint p2 = ed->cursorRect(cursor).center(); + QTest::mousePress(ed->viewport(), Qt::LeftButton, 0, p1); + { QMouseEvent ev(QEvent::MouseMove, p2, Qt::LeftButton, Qt::LeftButton, 0); + QCoreApplication::sendEvent(ed->viewport(), &ev); } + QTest::mouseRelease(ed->viewport(), Qt::LeftButton, 0, p2); + QVERIFY(ed->textCursor().hasSelection()); + QCOMPARE(ed->textCursor().selectedText(), QString("ello Worl")); + +} + +void tst_QTextEdit::mouseSelectionDClick() +{ + ed->show(); + ed->setPlainText(("Hello World")); + QTextCursor cursor = ed->textCursor(); + cursor.setPosition(1); + QPoint p1 = ed->cursorRect(cursor).center(); + cursor.setPosition(10); + QPoint p2 = ed->cursorRect(cursor).center(); + QTest::mousePress(ed->viewport(), Qt::LeftButton, 0, p1); + QTest::mouseRelease(ed->viewport(), Qt::LeftButton, 0, p1); + QTest::mouseDClick(ed->viewport(), Qt::LeftButton, 0, p1); + QVERIFY(ed->textCursor().hasSelection()); + QCOMPARE(ed->textCursor().selectedText(), QString("Hello")); + { QMouseEvent ev(QEvent::MouseMove, p2, Qt::LeftButton, Qt::LeftButton, 0); + QCoreApplication::sendEvent(ed->viewport(), &ev); } + QTest::mouseRelease(ed->viewport(), Qt::LeftButton, 0, p2); + QVERIFY(ed->textCursor().hasSelection()); + QCOMPARE(ed->textCursor().selectedText(), QString("Hello World")); +} + void tst_QTextEdit::setTextCursor() { QSignalSpy spy(ed, SIGNAL(cursorPositionChanged())); |