summaryrefslogtreecommitdiffstats
path: root/tests/auto/testlib/selftests/mouse
diff options
context:
space:
mode:
authorJan Arve Sæther <jan-arve.saether@qt.io>2020-02-04 11:32:00 +0100
committerJan Arve Sæther <jan-arve.saether@qt.io>2020-02-06 09:31:47 +0100
commit8c6c4df3e83776d821f357582a717dbfbeb1c3ff (patch)
treeaaeb78842920fcffd3dcb6ec2d62643c0557ce64 /tests/auto/testlib/selftests/mouse
parent6d6ca70538851e8334eb01550a93b60ceba75d34 (diff)
Maintain at least 500ms timestamp distance between each test function
If we had one test function that just did tst_Mouse::f1() { QTest::mouseMove(w, QPoint(0,0)); } and another test function that did tst_Mouse::f2() { QTest::mouseMove(w, QPoint(500,500)); } their corresponding event timestamps were only 1 apart from each other. This meant that any code that tried to estimate the velocity of a mouse cursor would get a really high velocity estimate inside f2(). This would come as a surprise to most people. So to avoid this, we add a 500 ms timestamp delay between each test function call. In theory this could also prevent generating a mouseDoubleClickEvent when a pair of test functions containing a press-release sequence was run, but there is a separate pre-existing mechanism to handle that case. Change-Id: Icd4fc35853c09f080466d22411208c7b5c4174b5 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/testlib/selftests/mouse')
-rw-r--r--tests/auto/testlib/selftests/mouse/tst_mouse.cpp67
1 files changed, 66 insertions, 1 deletions
diff --git a/tests/auto/testlib/selftests/mouse/tst_mouse.cpp b/tests/auto/testlib/selftests/mouse/tst_mouse.cpp
index d097027e7e..43dda31daf 100644
--- a/tests/auto/testlib/selftests/mouse/tst_mouse.cpp
+++ b/tests/auto/testlib/selftests/mouse/tst_mouse.cpp
@@ -42,6 +42,8 @@ class tst_Mouse : public QObject
Q_OBJECT
private slots:
+ void timestampBetweenTestFunction_data();
+ void timestampBetweenTestFunction();
void stateHandlingPart1_data();
void stateHandlingPart1();
void stateHandlingPart2();
@@ -55,20 +57,83 @@ public:
Qt::MouseButtons stateInMouseMove = Qt::NoButton;
int moveCount = 0;
int pressCount = 0;
+ int doubleClickCount = 0;
+ ulong lastTimeStamp = 0;
protected:
- void mousePressEvent(QMouseEvent *)
+ void mousePressEvent(QMouseEvent *e)
{
pressCount++;
+ processEvent(e);
}
void mouseMoveEvent(QMouseEvent *e)
{
moveCount++;
stateInMouseMove = e->buttons();
+ processEvent(e);
}
+
+ void mouseReleaseEvent(QMouseEvent *e)
+ {
+ processEvent(e);
+ }
+
+ void mouseDoubleClickEvent(QMouseEvent *e)
+ {
+ doubleClickCount++;
+ processEvent(e);
+ }
+
+ void processEvent(QMouseEvent *e)
+ {
+ lastTimeStamp = e->timestamp();
+ }
+
};
+static ulong lastTimeStampInPreviousTestFunction = 0;
+
+void tst_Mouse::timestampBetweenTestFunction_data()
+{
+ QTest::addColumn<bool>("hoverLast");
+ QTest::addColumn<bool>("pressAndRelease");
+ QTest::newRow("press, release") << true << false;
+ QTest::newRow("press, release, hover") << true << true;
+ QTest::newRow("hover") << false << true;
+ QTest::newRow("hover #2") << false << true;
+ QTest::newRow("press, release #2") << true << false;
+ QTest::newRow("press, release, hover #2") << true << true;
+}
+
+void tst_Mouse::timestampBetweenTestFunction()
+{
+ QFETCH(bool, hoverLast);
+ QFETCH(bool, pressAndRelease);
+
+ MouseWindow w;
+ w.show();
+ w.setGeometry(100, 100, 200, 200);
+ QVERIFY(QTest::qWaitForWindowActive(&w));
+
+ QPoint point(10, 10);
+ QCOMPARE(w.pressCount, 0);
+ if (pressAndRelease) {
+ QTest::mousePress(&w, Qt::LeftButton, { }, point);
+ QVERIFY(w.lastTimeStamp - lastTimeStampInPreviousTestFunction > 500); // Should be at least 500 ms timestamp between each test case
+ QCOMPARE(w.pressCount, 1);
+ QTest::mouseRelease(&w, Qt::LeftButton, { }, point);
+ }
+ QCOMPARE(w.doubleClickCount, 0);
+ if (hoverLast) {
+ static int xMove = 0;
+ xMove += 5; // Just make sure we generate different hover coordinates
+ point.rx() += xMove;
+ QTest::mouseMove(&w, point); // a hover move. This doesn't generate a timestamp delay of 500 ms
+ }
+ lastTimeStampInPreviousTestFunction = w.lastTimeStamp;
+}
+
void tst_Mouse::stateHandlingPart1_data()
{
QTest::addColumn<bool>("dummy");