diff options
Diffstat (limited to 'tests/auto/qtextedit')
-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())); |