From 68d0377736a541fa29d1aaba6b7aa4a4cf8781ef Mon Sep 17 00:00:00 2001 From: Jan Arve Saether Date: Wed, 13 Feb 2019 12:43:56 +0100 Subject: 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 --- .../qquickpointerhandler/tst_qquickpointerhandler.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'tests') 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(target()); if (!item) { event->point(0)->setGrabberPointerHandler(this); @@ -218,7 +221,8 @@ public: static_cast(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) -- cgit v1.2.3