summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Rutledge <[email protected]>2024-10-08 16:09:47 +0200
committerShawn Rutledge <[email protected]>2024-10-09 06:20:17 +0200
commit069858008c87fa251838c869bb449b6fc6759b20 (patch)
tree5316402a0ca412b2ca511a34338889073fa4fbc5
parentfbe61def33a2708e35e5e6a796e88976b04941f7 (diff)
QTestLib: increment timestamp by specified delay before each event
Some test functions generate series of mouse events, and the docs have always said that the specified delay applies to each event, not just to the first one. This brings reality into agreement with the docs. We're still keeping 0f94430a0fba5509d2d756832cb44a266d1d2e86 : the delay cannot be 0, because if we never increment the timestamp at all, that would never be a realistic simulation of any real-world scenario. Checking elapsed time is increasingly useful in Qt, and unrealistic timestamps can cause strange behavior. [ChangeLog][QTestLib] QTest::mouseClick() and mouseDClick() now apply the given delay to the timestamps of each event in the sequence, as it has been documented all along. As before, the delay is never allowed to be less than 1 ms. Fixes: QTBUG-129794 Change-Id: I03de902b57582de239fc9491b95fb406b879f7e3 Reviewed-by: Axel Spoerl <[email protected]>
-rw-r--r--src/testlib/qtestmouse.h8
-rw-r--r--tests/auto/testlib/selftests/mouse/tst_mouse.cpp6
2 files changed, 10 insertions, 4 deletions
diff --git a/src/testlib/qtestmouse.h b/src/testlib/qtestmouse.h
index 567d80c521a..e7a767258d7 100644
--- a/src/testlib/qtestmouse.h
+++ b/src/testlib/qtestmouse.h
@@ -77,8 +77,7 @@ namespace QTest
pos.x(), pos.y(), windowSize.width(), windowSize.height());
}
- int actualDelay = (delay == -1 || delay < defaultMouseDelay()) ? defaultMouseDelay() : delay;
- lastMouseTimestamp += qMax(1, actualDelay);
+ int actualDelay = qMax(1, (delay == -1 || delay < defaultMouseDelay()) ? defaultMouseDelay() : delay);
if (pos.isNull())
pos = QPoint(window->width() / 2, window->height() / 2);
@@ -95,15 +94,18 @@ namespace QTest
{
case MouseDClick:
qtestMouseButtons.setFlag(button, true);
+ lastMouseTimestamp += actualDelay;
qt_handleMouseEvent(w, pos, global, qtestMouseButtons, button, QEvent::MouseButtonPress,
stateKey, lastMouseTimestamp);
qtestMouseButtons.setFlag(button, false);
+ lastMouseTimestamp += actualDelay;
qt_handleMouseEvent(w, pos, global, qtestMouseButtons, button, QEvent::MouseButtonRelease,
stateKey, lastMouseTimestamp);
Q_FALLTHROUGH();
case MousePress:
case MouseClick:
qtestMouseButtons.setFlag(button, true);
+ lastMouseTimestamp += actualDelay;
qt_handleMouseEvent(w, pos, global, qtestMouseButtons, button, QEvent::MouseButtonPress,
stateKey, lastMouseTimestamp);
if (action == MousePress)
@@ -111,12 +113,14 @@ namespace QTest
Q_FALLTHROUGH();
case MouseRelease:
qtestMouseButtons.setFlag(button, false);
+ lastMouseTimestamp += actualDelay;
qt_handleMouseEvent(w, pos, global, qtestMouseButtons, button, QEvent::MouseButtonRelease,
stateKey, lastMouseTimestamp);
if (delay == -1)
lastMouseTimestamp += mouseDoubleClickInterval; // avoid double clicks being generated
break;
case MouseMove:
+ lastMouseTimestamp += actualDelay;
qt_handleMouseEvent(w, pos, global, qtestMouseButtons, Qt::NoButton, QEvent::MouseMove,
stateKey, lastMouseTimestamp);
break;
diff --git a/tests/auto/testlib/selftests/mouse/tst_mouse.cpp b/tests/auto/testlib/selftests/mouse/tst_mouse.cpp
index dd79add5f3f..4af55adde91 100644
--- a/tests/auto/testlib/selftests/mouse/tst_mouse.cpp
+++ b/tests/auto/testlib/selftests/mouse/tst_mouse.cpp
@@ -283,13 +283,15 @@ void tst_Mouse::doubleClick()
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);
+ ts = w.lastTimeStamp;
+ QTest::mouseClick(&w, Qt::LeftButton, {}, point, 10); // 10 ms before press, 10 ms before release
QCOMPARE(w.doubleClickCount, 2);
+ QCOMPARE(w.lastTimeStamp, ts + 20);
// 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.lastTimeStamp, ts + 4); // 1 ms before each press and release
QCOMPARE(w.doubleClickCount, 3);
// use the mouseClick function with default delay to avoid double-click