diff options
author | Jan Arve Saether <jan-arve.saether@qt.io> | 2019-02-13 12:43:56 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-02-13 21:10:45 +0000 |
commit | 68d0377736a541fa29d1aaba6b7aa4a4cf8781ef (patch) | |
tree | 65430ac9c6d04018f5cebfc2cbe4150c5291e82d | |
parent | 1e3ed172f35abaa0e0af43ee22259bc3cd188ad8 (diff) |
Make test more robust in case we have interleaved update events
This could for instance happen if the window gets exposed under the
cursor, and it sends a mouse move event that might interleave the press
and release events, causing the eventCount variable to jump to 3.
Change-Id: Icce59b2aa1a937a990baa83f503907633003e2bb
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r-- | tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp b/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp index feb356a7d5..2b6482465c 100644 --- a/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp +++ b/tests/auto/quick/pointerhandlers/qquickpointerhandler/tst_qquickpointerhandler.cpp @@ -188,7 +188,10 @@ public: QQuickPointerHandler::handlePointerEventImpl(event); if (!enabled()) return; - ++eventCount; + if (event->isPressEvent()) + ++pressEventCount; + if (event->isReleaseEvent()) + ++releaseEventCount; EventItem *item = qmlobject_cast<EventItem *>(target()); if (!item) { event->point(0)->setGrabberPointerHandler(this); @@ -218,7 +221,8 @@ public: static_cast<Qt::TouchPointState>(point->state()), stateChange, eventPos(point), point->scenePosition())); } - int eventCount = 0; + int pressEventCount = 0; + int releaseEventCount = 0; }; class tst_PointerHandlers : public QQmlDataTest @@ -646,9 +650,9 @@ void tst_PointerHandlers::handlerInWindow() QPoint p1(20, 20); QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, p1); - QTRY_COMPARE(handler->eventCount, 1); + QTRY_COMPARE(handler->pressEventCount, 1); QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, p1); - QTRY_COMPARE(handler->eventCount, 2); + QTRY_COMPARE(handler->releaseEventCount, 1); } void tst_PointerHandlers::dynamicCreationInWindow() @@ -670,9 +674,9 @@ void tst_PointerHandlers::dynamicCreationInWindow() QPoint p1(20, 20); QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, p1); - QTRY_COMPARE(handler->eventCount, 1); + QTRY_COMPARE(handler->pressEventCount, 1); QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, p1); - QTRY_COMPARE(handler->eventCount, 2); + QTRY_COMPARE(handler->releaseEventCount, 1); } QTEST_MAIN(tst_PointerHandlers) |