summaryrefslogtreecommitdiffstats
path: root/tests/auto/testlib/selftests/mouse/tst_mouse.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/testlib/selftests/mouse/tst_mouse.cpp')
-rw-r--r--tests/auto/testlib/selftests/mouse/tst_mouse.cpp51
1 files changed, 50 insertions, 1 deletions
diff --git a/tests/auto/testlib/selftests/mouse/tst_mouse.cpp b/tests/auto/testlib/selftests/mouse/tst_mouse.cpp
index b2e9c61baf..dd79add5f3 100644
--- a/tests/auto/testlib/selftests/mouse/tst_mouse.cpp
+++ b/tests/auto/testlib/selftests/mouse/tst_mouse.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2018 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtGui/QWindow>
@@ -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"