diff options
Diffstat (limited to 'tests/auto/testlib/selftests/mouse/tst_mouse.cpp')
-rw-r--r-- | tests/auto/testlib/selftests/mouse/tst_mouse.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/auto/testlib/selftests/mouse/tst_mouse.cpp b/tests/auto/testlib/selftests/mouse/tst_mouse.cpp index b2e9c61baf..c9793da553 100644 --- a/tests/auto/testlib/selftests/mouse/tst_mouse.cpp +++ b/tests/auto/testlib/selftests/mouse/tst_mouse.cpp @@ -24,6 +24,7 @@ private slots: void stateHandlingPart2(); void deterministicEvents_data(); void deterministicEvents(); + void doubleClick(); }; class MouseWindow : public QWindow @@ -251,5 +252,53 @@ void tst_Mouse::deterministicEvents() QCOMPARE(w.moveCount, 1); } +void tst_Mouse::doubleClick() +{ + MouseWindow w; + w.show(); + w.setGeometry(100, 100, 200, 200); + QVERIFY(QTest::qWaitForWindowActive(&w)); + + // click + QPoint point(10, 10); + QCOMPARE(w.pressCount, 0); + QTest::mousePress(&w, Qt::LeftButton, { }, point); + QCOMPARE(w.pressCount, 1); + // give a delay of 10ms + auto ts = w.lastTimeStamp; + QTest::mouseRelease(&w, Qt::LeftButton, { }, point, 10); + QCOMPARE(w.lastTimeStamp, ts + 10); + QCOMPARE(w.doubleClickCount, 0); + + // click again within a short time to generate double-click + QTest::mousePress(&w, Qt::LeftButton, { }, point, 10); + QCOMPARE(w.pressCount, 2); + QCOMPARE(w.lastTimeStamp, ts + 20); + // this time, let some virtual time elapse, because we're going to test double-click again afterwards + QTest::mouseRelease(&w, Qt::LeftButton, { }, point); + QCOMPARE_GT(w.lastTimeStamp, ts + 20); + QCOMPARE(w.doubleClickCount, 1); + + // use the mouseClick function to generate another double-click + ts = w.lastTimeStamp; + QTest::mouseClick(&w, Qt::LeftButton, {}, point, 10); + QCOMPARE_GE(w.lastTimeStamp, ts + 500); // because the last release had a default delay + QTest::mouseClick(&w, Qt::LeftButton, {}, point); + QCOMPARE(w.doubleClickCount, 2); + + // use the mouseDClick function to generate another double-click + ts = w.lastTimeStamp; + QTest::mouseDClick(&w, Qt::LeftButton, {}, point); + QCOMPARE_GE(w.lastTimeStamp, ts + 500); // because the last release had a default delay + QCOMPARE(w.doubleClickCount, 3); + + // use the mouseClick function with default delay to avoid double-click + ts = w.lastTimeStamp; + QTest::mouseClick(&w, Qt::LeftButton, {}, point); + QCOMPARE_GE(w.lastTimeStamp, ts + 500); // because the last release had a default delay + QTest::mouseClick(&w, Qt::LeftButton, {}, point); + QCOMPARE(w.doubleClickCount, 3); +} + QTEST_MAIN(tst_Mouse) #include "tst_mouse.moc" |