diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-09-04 10:23:47 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-09-14 11:39:29 +0200 |
commit | 147a8bc4c86dd7c818acd2614ee67cd7098cfa5e (patch) | |
tree | ffa57273c7db5a9884a3e1d0811ebe3d15c364a3 /tests/auto/gui/kernel | |
parent | f59f67287fa17e8d4edf6a231c010f768d1b76e8 (diff) |
tst_QWindow: Remove usages of deprecated QWSI API
Use the standard testlib helpers for generating clicks and port the
remaining occurrences to the new versions of
QWindowSystemInterface::handleMouseEvent(). Similarly, fix
QWindowSystemInterface::handleTabletEvent().
Task-number: QTBUG-76491
Change-Id: I6a30957164891b56a018696606956c3cab56047f
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'tests/auto/gui/kernel')
-rw-r--r-- | tests/auto/gui/kernel/qwindow/tst_qwindow.cpp | 104 |
1 files changed, 52 insertions, 52 deletions
diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index 4f26950192..1290347eab 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -1025,6 +1025,23 @@ public: Qt::MouseButtons buttonStateInGeneratedMove; }; +static void simulateMouseClick(QWindow *target, const QPointF &local, const QPointF &global) +{ + QWindowSystemInterface::handleMouseEvent(target, local, global, + {}, Qt::LeftButton, QEvent::MouseButtonPress); + QWindowSystemInterface::handleMouseEvent(target, local, global, + Qt::LeftButton, Qt::LeftButton, QEvent::MouseButtonRelease); +} + +static void simulateMouseClick(QWindow *target, ulong &timeStamp, + const QPointF &local, const QPointF &global) +{ + QWindowSystemInterface::handleMouseEvent(target, timeStamp++, local, global, + {}, Qt::LeftButton, QEvent::MouseButtonPress); + QWindowSystemInterface::handleMouseEvent(target, timeStamp++, local, global, + Qt::LeftButton, Qt::LeftButton, QEvent::MouseButtonRelease); +} + void tst_QWindow::testInputEvents() { InputTestWindow window; @@ -1066,15 +1083,13 @@ void tst_QWindow::testInputEvents() window.mousePressButton = window.mouseReleaseButton = 0; const QPointF nonWindowGlobal(window.geometry().topRight() + QPoint(200, 50)); // not inside the window const QPointF deviceNonWindowGlobal = QHighDpi::toNativePixels(nonWindowGlobal, window.screen()); - QWindowSystemInterface::handleMouseEvent(nullptr, deviceNonWindowGlobal, deviceNonWindowGlobal, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(nullptr, deviceNonWindowGlobal, deviceNonWindowGlobal, Qt::NoButton); + simulateMouseClick(nullptr, deviceNonWindowGlobal, deviceNonWindowGlobal); QCoreApplication::processEvents(); QCOMPARE(window.mousePressButton, 0); QCOMPARE(window.mouseReleaseButton, 0); const QPointF windowGlobal = window.mapToGlobal(local.toPoint()); const QPointF deviceWindowGlobal = QHighDpi::toNativePixels(windowGlobal, window.screen()); - QWindowSystemInterface::handleMouseEvent(nullptr, deviceWindowGlobal, deviceWindowGlobal, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(nullptr, deviceWindowGlobal, deviceWindowGlobal, Qt::NoButton); + simulateMouseClick(nullptr, deviceWindowGlobal, deviceWindowGlobal); QCoreApplication::processEvents(); QCOMPARE(window.mousePressButton, int(Qt::LeftButton)); QCOMPARE(window.mouseReleaseButton, int(Qt::LeftButton)); @@ -1198,8 +1213,7 @@ void tst_QWindow::mouseToTouchTranslation() window.show(); QVERIFY(QTest::qWaitForWindowExposed(&window)); - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton); + QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10)); QCoreApplication::processEvents(); QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false); @@ -1211,8 +1225,7 @@ void tst_QWindow::mouseToTouchTranslation() window.ignoreMouse = false; - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton); + QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10)); QCoreApplication::processEvents(); QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false); @@ -1223,8 +1236,7 @@ void tst_QWindow::mouseToTouchTranslation() window.ignoreMouse = true; - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton); + QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10)); QCoreApplication::processEvents(); // touch event synthesis disabled @@ -1249,8 +1261,7 @@ void tst_QWindow::mouseToTouchLoop() window.show(); QVERIFY(QTest::qWaitForWindowExposed(&window)); - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton); + QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10)); QCoreApplication::processEvents(); QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false); @@ -1545,8 +1556,8 @@ void tst_QWindow::mouseEventSequence() ulong timestamp = 0; QPointF local(12, 34); const QPointF deviceLocal = QHighDpi::toNativePixels(local, &window); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, deviceLocal, deviceLocal, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, deviceLocal, deviceLocal, Qt::NoButton); + + simulateMouseClick(&window, timestamp, deviceLocal, deviceLocal); QCoreApplication::processEvents(); QCOMPARE(window.mousePressedCount, 1); QCOMPARE(window.mouseReleasedCount, 1); @@ -1558,10 +1569,8 @@ void tst_QWindow::mouseEventSequence() // A double click must result in press, release, press, doubleclick, release. // Check that no unexpected event suppression occurs and that the order is correct. - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); + simulateMouseClick(&window, timestamp, local, local); QCoreApplication::processEvents(); QCOMPARE(window.mousePressedCount, 2); QCOMPARE(window.mouseReleasedCount, 2); @@ -1572,12 +1581,9 @@ void tst_QWindow::mouseEventSequence() window.resetCounters(); // Triple click = double + single click - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); + simulateMouseClick(&window, timestamp, local, local); + simulateMouseClick(&window, timestamp, local, local); QCoreApplication::processEvents(); QCOMPARE(window.mousePressedCount, 3); QCOMPARE(window.mouseReleasedCount, 3); @@ -1588,14 +1594,10 @@ void tst_QWindow::mouseEventSequence() window.resetCounters(); // Two double clicks. - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); + simulateMouseClick(&window, timestamp, local, local); + simulateMouseClick(&window, timestamp, local, local); + simulateMouseClick(&window, timestamp, local, local); QCoreApplication::processEvents(); QCOMPARE(window.mousePressedCount, 4); QCOMPARE(window.mouseReleasedCount, 4); @@ -1606,17 +1608,13 @@ void tst_QWindow::mouseEventSequence() window.resetCounters(); // Four clicks, none of which qualifies as a double click. - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); timestamp += doubleClickInterval; - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); timestamp += doubleClickInterval; - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); timestamp += doubleClickInterval; - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); timestamp += doubleClickInterval; QCoreApplication::processEvents(); QCOMPARE(window.mousePressedCount, 4); @@ -1668,10 +1666,13 @@ void tst_QWindow::inputReentrancy() // Queue three events. QPointF local(12, 34); - QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::LeftButton); + QWindowSystemInterface::handleMouseEvent(&window, local, local, {}, + Qt::LeftButton, QEvent::MouseButtonPress); local += QPointF(2, 2); - QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::NoButton); + QWindowSystemInterface::handleMouseEvent(&window, local, local, + Qt::LeftButton, Qt::LeftButton, QEvent::MouseMove); + QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::LeftButton, + Qt::LeftButton, QEvent::MouseButtonRelease); // Process them. However, the event handler for the press will also call // processEvents() so the move and release will be delivered before returning // from mousePressEvent(). The point is that no events should get lost. @@ -1741,12 +1742,14 @@ void tst_QWindow::tabletEvents() const QPoint global = window.mapToGlobal(local); const QPoint deviceLocal = QHighDpi::toNativeLocalPosition(local, &window); const QPoint deviceGlobal = QHighDpi::toNativePixels(global, window.screen()); - QWindowSystemInterface::handleTabletEvent(&window, true, deviceLocal, deviceGlobal, 1, 2, 0.5, 1, 2, 0.1, 0, 0, 0); + QWindowSystemInterface::handleTabletEvent(&window, deviceLocal, deviceGlobal, + 1, 2, Qt::LeftButton, 0.5, 1, 2, 0.1, 0, 0, 0); QCoreApplication::processEvents(); QTRY_VERIFY(window.eventType == QEvent::TabletPress); QTRY_COMPARE(window.eventGlobal.toPoint(), global); QTRY_COMPARE(window.eventLocal.toPoint(), local); - QWindowSystemInterface::handleTabletEvent(&window, false, deviceLocal, deviceGlobal, 1, 2, 0.5, 1, 2, 0.1, 0, 0, 0); + QWindowSystemInterface::handleTabletEvent(&window, deviceLocal, deviceGlobal, 1, 2, + {}, 0.5, 1, 2, 0.1, 0, 0, 0); QCoreApplication::processEvents(); QTRY_COMPARE(window.eventType, QEvent::TabletRelease); @@ -1782,11 +1785,9 @@ void tst_QWindow::windowModality_QTBUG27039() modalB.setModality(Qt::ApplicationModal); modalB.show(); - QPointF local(5, 5); - QWindowSystemInterface::handleMouseEvent(&modalA, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&modalA, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&modalB, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&modalB, local, local, Qt::NoButton); + QPoint local(5, 5); + QTest::mouseClick(&modalA, Qt::LeftButton, {}, local); + QTest::mouseClick(&modalB, Qt::LeftButton, {}, local); QCoreApplication::processEvents(); // modal A should be blocked since it was shown first, but modal B should not be blocked @@ -1794,8 +1795,7 @@ void tst_QWindow::windowModality_QTBUG27039() QCOMPARE(modalA.mousePressedCount, 0); modalB.hide(); - QWindowSystemInterface::handleMouseEvent(&modalA, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&modalA, local, local, Qt::NoButton); + QTest::mouseClick(&modalA, Qt::LeftButton, {}, local); QCoreApplication::processEvents(); // modal B has been hidden, modal A should be unblocked again |