diff options
Diffstat (limited to 'tests/auto/gui/kernel/qtouchevent')
-rw-r--r-- | tests/auto/gui/kernel/qtouchevent/BLACKLIST | 4 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qtouchevent/CMakeLists.txt | 11 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp | 238 |
3 files changed, 134 insertions, 119 deletions
diff --git a/tests/auto/gui/kernel/qtouchevent/BLACKLIST b/tests/auto/gui/kernel/qtouchevent/BLACKLIST index 3ae3f6d30d..c4e4b2291d 100644 --- a/tests/auto/gui/kernel/qtouchevent/BLACKLIST +++ b/tests/auto/gui/kernel/qtouchevent/BLACKLIST @@ -1,7 +1,3 @@ -[multiPointRawEventTranslationOnTouchScreen] -ubuntu-16.04 -[multiPointRawEventTranslationOnTouchScreen] -android [multiPointRawEventTranslationOnTouchPad] # QTBUG-101519 windows-11 diff --git a/tests/auto/gui/kernel/qtouchevent/CMakeLists.txt b/tests/auto/gui/kernel/qtouchevent/CMakeLists.txt index e9a6271f58..160263ac66 100644 --- a/tests/auto/gui/kernel/qtouchevent/CMakeLists.txt +++ b/tests/auto/gui/kernel/qtouchevent/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qtouchevent.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtouchevent Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtouchevent LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qtouchevent SOURCES tst_qtouchevent.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate Qt::Widgets diff --git a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp index 0a80b127e8..37ddcb8962 100644 --- a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp +++ b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2020 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtGui/QCursor> #include <QtGui/QScreen> @@ -17,6 +17,10 @@ #include <QtGui/private/qeventpoint_p.h> #include <private/qhighdpiscaling_p.h> #include <private/qpointingdevice_p.h> +#include <private/qguiapplication_p.h> +#include <qpa/qplatformintegration.h> + +#include <QtCore/qpointer.h> Q_LOGGING_CATEGORY(lcTests, "qt.gui.tests") @@ -46,6 +50,24 @@ public: deleteInTouchBegin = deleteInTouchUpdate = deleteInTouchEnd = false; } + void paintEvent(QPaintEvent *) override + { + QPainter painter(this); + painter.drawRect(rect()); + painter.setPen(Qt::darkGray); + painter.drawText(rect(), Qt::AlignHCenter | Qt::AlignCenter, objectName()); + static const QString pointFormat = QString::fromUtf8("\360\237\226\227 %1, %2"); + painter.setPen(Qt::darkGreen); + for (const auto &pt : std::as_const(touchBeginPoints)) + painter.drawText(pt.position(), pointFormat.arg(pt.position().toPoint().x()).arg(pt.position().toPoint().y())); + painter.setPen(Qt::darkYellow); + for (const auto &pt : std::as_const(touchUpdatePoints)) + painter.drawText(pt.position(), pointFormat.arg(pt.position().toPoint().x()).arg(pt.position().toPoint().y())); + painter.setPen(Qt::darkRed); + for (const auto &pt : std::as_const(touchEndPoints)) + painter.drawText(pt.position(), pointFormat.arg(pt.position().toPoint().x()).arg(pt.position().toPoint().y())); + } + bool event(QEvent *event) override { lastNormalizedPositions.clear(); @@ -59,13 +81,15 @@ public: auto touchEvent = static_cast<QTouchEvent *>(event); touchBeginPoints = touchEvent->points(); Q_ASSERT(touchBeginPoints.first().device() == touchEvent->pointingDevice()); - for (const QEventPoint &pt : qAsConst(touchBeginPoints)) + for (const QEventPoint &pt : std::as_const(touchBeginPoints)) lastNormalizedPositions << pt.normalizedPosition(); timestamp = touchEvent->timestamp(); deviceFromEvent = touchEvent->pointingDevice(); event->setAccepted(acceptTouchBegin); if (deleteInTouchBegin) delete this; + else + update(); break; } case QEvent::TouchUpdate: { @@ -75,13 +99,15 @@ public: seenTouchUpdate = seenTouchBegin && !seenTouchEnd; auto touchEvent = static_cast<QTouchEvent *>(event); touchUpdatePoints = touchEvent->points(); - for (const QEventPoint &pt : qAsConst(touchUpdatePoints)) + for (const QEventPoint &pt : std::as_const(touchUpdatePoints)) lastNormalizedPositions << pt.normalizedPosition(); timestamp = touchEvent->timestamp(); deviceFromEvent = touchEvent->pointingDevice(); event->setAccepted(acceptTouchUpdate); if (deleteInTouchUpdate) delete this; + else + update(); break; } case QEvent::TouchEnd: { @@ -91,13 +117,15 @@ public: seenTouchEnd = seenTouchBegin && !seenTouchEnd; auto touchEvent = static_cast<QTouchEvent *>(event); touchEndPoints = touchEvent->points(); - for (const QEventPoint &pt : qAsConst(touchEndPoints)) + for (const QEventPoint &pt : std::as_const(touchEndPoints)) lastNormalizedPositions << pt.normalizedPosition(); timestamp = touchEvent->timestamp(); deviceFromEvent = touchEvent->pointingDevice(); event->setAccepted(acceptTouchEnd); if (deleteInTouchEnd) delete this; + else + update(); break; } default: @@ -343,9 +371,11 @@ void tst_QTouchEvent::state() QVERIFY(!touchEvent3.isBeginEvent()); QVERIFY(!touchEvent3.isUpdateEvent()); QVERIFY(touchEvent3.isEndEvent()); +#if QT_DEPRECATED_SINCE(6, 0) QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED // test Qt 5 compatibility wrappers QCOMPARE(touchEvent3.touchPoints(), touchEvent3.points()); QT_WARNING_POP +#endif } void tst_QTouchEvent::touchDisabledByDefault() @@ -706,7 +736,7 @@ void tst_QTouchEvent::basicRawEventTranslation() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchBeginPoints.count(), 1); + QCOMPARE(touchWidget.touchBeginPoints.size(), 1); QCOMPARE(touchWidget.timestamp, timestamp); QEventPoint touchBeginPoint = touchWidget.touchBeginPoints.first(); QCOMPARE(touchBeginPoint.id(), 0); @@ -736,7 +766,7 @@ void tst_QTouchEvent::basicRawEventTranslation() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchUpdatePoints.count(), 1); + QCOMPARE(touchWidget.touchUpdatePoints.size(), 1); QEventPoint touchUpdatePoint = touchWidget.touchUpdatePoints.first(); QCOMPARE(touchUpdatePoint.id(), 0); QCOMPARE(touchUpdatePoint.state(), rawTouchPoint.state()); @@ -764,7 +794,7 @@ void tst_QTouchEvent::basicRawEventTranslation() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QVERIFY(touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchEndPoints.count(), 1); + QCOMPARE(touchWidget.touchEndPoints.size(), 1); QEventPoint touchEndPoint = touchWidget.touchEndPoints.first(); QCOMPARE(touchEndPoint.id(), 0); QCOMPARE(touchEndPoint.state(), rawTouchPoint.state()); @@ -787,9 +817,11 @@ void tst_QTouchEvent::basicRawEventTranslation() void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() { tst_QTouchEventWidget touchWidget; + touchWidget.setObjectName("parent touch widget"); touchWidget.setWindowTitle(QTest::currentTestFunction()); touchWidget.setAttribute(Qt::WA_AcceptTouchEvents); - touchWidget.setGeometry(100, 100, 400, 300); + const QPoint topLeft = QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(100, 100); + touchWidget.setGeometry({topLeft, QSize(400, 300)}); tst_QTouchEventWidget leftWidget(&touchWidget); leftWidget.setObjectName("leftWidget"); @@ -803,24 +835,25 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() touchWidget.show(); QVERIFY(QTest::qWaitForWindowExposed(&touchWidget)); + if (touchWidget.geometry().topLeft() != topLeft) { + qCDebug(lcTests) << "tried to set position 100, 100 on screen; got geometry" + << touchWidget.geometry() << "frame" << touchWidget.frameGeometry(); + QSKIP("failed to position the widget window on this platform"); + } - QPointF leftPos = leftWidget.rect().center(); - QPointF rightPos = rightWidget.rect().center(); - QPointF centerPos = touchWidget.rect().center(); - QPointF leftScreenPos = leftWidget.mapToGlobal(leftPos.toPoint()); - QPointF rightScreenPos = rightWidget.mapToGlobal(rightPos.toPoint()); - QPointF centerScreenPos = touchWidget.mapToGlobal(centerPos.toPoint()); + QPoint leftPos = leftWidget.rect().center(); + QPoint rightPos = rightWidget.rect().center(); + QPoint centerPos = touchWidget.rect().center(); + QPoint leftScenePos = leftWidget.mapToParent(leftPos); + QPoint rightScenePos = rightWidget.mapToParent(rightPos); + QPoint leftScreenPos = leftWidget.mapToGlobal(leftPos); + QPoint rightScreenPos = rightWidget.mapToGlobal(rightPos); + QPoint centerScreenPos = touchWidget.mapToGlobal(centerPos); // generate TouchBegins on both leftWidget and rightWidget - ulong timestamp = 0; - auto rawTouchPoints = QList<QEventPoint>() - << QEventPoint(0, QEventPoint::State::Pressed, QPointF(), leftScreenPos) - << QEventPoint(1, QEventPoint::State::Pressed, QPointF(), rightScreenPos); - QWindow *window = touchWidget.windowHandle(); - QList<QWindowSystemInterface::TouchPoint> nativeTouchPoints = - QWindowSystemInterfacePrivate::toNativeTouchPoints(rawTouchPoints, window); - QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchScreenDevice, nativeTouchPoints); - QCoreApplication::processEvents(); + auto touchSequence = QTest::touchEvent(touchWidget.windowHandle(), touchScreenDevice); + touchSequence.press(0, leftScenePos).press(1, rightScenePos); + QVERIFY(touchSequence.commit()); // verify acceptance QVERIFY(!touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); @@ -830,14 +863,14 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() QVERIFY(rightWidget.seenTouchBegin); QVERIFY(!rightWidget.seenTouchUpdate); QVERIFY(!rightWidget.seenTouchEnd); - QCOMPARE(leftWidget.touchBeginPoints.count(), 1); - QCOMPARE(rightWidget.touchBeginPoints.count(), 1); + QCOMPARE(leftWidget.touchBeginPoints.size(), 1); + QCOMPARE(rightWidget.touchBeginPoints.size(), 1); const int touchPointId0 = 0; const int touchPointId1 = touchPointId0 + 1; { - QEventPoint leftTouchPoint = leftWidget.touchBeginPoints.first(); + const QEventPoint &leftTouchPoint = leftWidget.touchBeginPoints.first(); QCOMPARE(leftTouchPoint.id(), touchPointId0); - QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state()); + QCOMPARE(leftTouchPoint.state(), QEventPoint::Pressed); QCOMPARE(leftTouchPoint.position(), leftPos); QCOMPARE(leftTouchPoint.pressPosition(), leftPos); QCOMPARE(leftTouchPoint.lastPosition(), leftPos); @@ -847,15 +880,12 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() QCOMPARE(leftTouchPoint.globalPosition(), leftScreenPos); QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos); QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos); - QCOMPARE(leftTouchPoint.position(), leftPos); - QCOMPARE(leftTouchPoint.scenePosition(), leftScreenPos); - QCOMPARE(leftTouchPoint.globalPosition(), leftScreenPos); QCOMPARE(leftTouchPoint.ellipseDiameters(), QSizeF(0, 0)); QCOMPARE(leftTouchPoint.pressure(), qreal(1.)); - QEventPoint rightTouchPoint = rightWidget.touchBeginPoints.first(); + const QEventPoint &rightTouchPoint = rightWidget.touchBeginPoints.first(); QCOMPARE(rightTouchPoint.id(), touchPointId1); - QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state()); + QCOMPARE(rightTouchPoint.state(), QEventPoint::Pressed); QCOMPARE(rightTouchPoint.position(), rightPos); QCOMPARE(rightTouchPoint.pressPosition(), rightPos); QCOMPARE(rightTouchPoint.lastPosition(), rightPos); @@ -865,20 +895,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() QCOMPARE(rightTouchPoint.globalPosition(), rightScreenPos); QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos); QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos); - QCOMPARE(rightTouchPoint.position(), rightPos); - QCOMPARE(rightTouchPoint.scenePosition(), rightScreenPos); - QCOMPARE(rightTouchPoint.globalPosition(), rightScreenPos); QCOMPARE(rightTouchPoint.ellipseDiameters(), QSizeF(0, 0)); QCOMPARE(rightTouchPoint.pressure(), qreal(1.)); } - rawTouchPoints.clear(); - rawTouchPoints << QEventPoint(0, QEventPoint::State::Updated, QPointF(), centerScreenPos) - << QEventPoint(1, QEventPoint::State::Updated, QPointF(), centerScreenPos); - nativeTouchPoints = - QWindowSystemInterfacePrivate::toNativeTouchPoints(rawTouchPoints, window); - QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchScreenDevice, nativeTouchPoints); - QCoreApplication::processEvents(); + // an unlikely event with the two touchpoints moving exactly on top of each other + touchSequence.move(0, centerPos).move(1, centerPos); + QVERIFY(touchSequence.commit()); // verify acceptance QVERIFY(!touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); @@ -888,13 +911,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() QVERIFY(rightWidget.seenTouchBegin); QVERIFY(rightWidget.seenTouchUpdate); QVERIFY(!rightWidget.seenTouchEnd); - QCOMPARE(leftWidget.touchUpdatePoints.count(), 1); - QCOMPARE(rightWidget.touchUpdatePoints.count(), 1); + QCOMPARE(leftWidget.touchUpdatePoints.size(), 1); + QCOMPARE(rightWidget.touchUpdatePoints.size(), 1); { - QEventPoint leftTouchPoint = leftWidget.touchUpdatePoints.first(); + const QEventPoint &leftTouchPoint = leftWidget.touchUpdatePoints.first(); QCOMPARE(leftTouchPoint.id(), touchPointId0); - QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state()); - QCOMPARE(leftTouchPoint.position(), QPointF(leftWidget.mapFromParent(centerPos.toPoint()))); + QCOMPARE(leftTouchPoint.state(), QEventPoint::Updated); + QCOMPARE(leftTouchPoint.position(), QPointF(leftWidget.mapFromParent(centerPos))); QCOMPARE(leftTouchPoint.pressPosition(), leftPos); QCOMPARE(leftTouchPoint.lastPosition(), leftPos); QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos); @@ -903,16 +926,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos); QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos); - QCOMPARE(leftTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint())); - QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos); - QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(leftTouchPoint.ellipseDiameters(), QSizeF(0, 0)); QCOMPARE(leftTouchPoint.pressure(), qreal(1.)); - QEventPoint rightTouchPoint = rightWidget.touchUpdatePoints.first(); + const QEventPoint &rightTouchPoint = rightWidget.touchUpdatePoints.first(); QCOMPARE(rightTouchPoint.id(), touchPointId1); - QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state()); - QCOMPARE(rightTouchPoint.position(), QPointF(rightWidget.mapFromParent(centerPos.toPoint()))); + QCOMPARE(rightTouchPoint.state(), QEventPoint::Updated); + QCOMPARE(rightTouchPoint.position(), QPointF(rightWidget.mapFromParent(centerPos))); QCOMPARE(rightTouchPoint.pressPosition(), rightPos); QCOMPARE(rightTouchPoint.lastPosition(), rightPos); QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos); @@ -921,21 +941,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos); QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos); - QCOMPARE(rightTouchPoint.position(), rightWidget.mapFromParent(centerPos.toPoint())); - QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos); - QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(rightTouchPoint.ellipseDiameters(), QSizeF(0, 0)); QCOMPARE(rightTouchPoint.pressure(), qreal(1.)); } // generate TouchEnds on both leftWidget and rightWidget - rawTouchPoints.clear(); - rawTouchPoints << QEventPoint(0, QEventPoint::State::Released, QPointF(), centerScreenPos) - << QEventPoint(1, QEventPoint::State::Released, QPointF(), centerScreenPos); - nativeTouchPoints = - QWindowSystemInterfacePrivate::toNativeTouchPoints(rawTouchPoints, window); - QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchScreenDevice, nativeTouchPoints); - QCoreApplication::processEvents(); + touchSequence.release(0, centerPos).release(1, centerPos); + QVERIFY(touchSequence.commit()); // verify acceptance QVERIFY(!touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); @@ -945,13 +957,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() QVERIFY(rightWidget.seenTouchBegin); QVERIFY(rightWidget.seenTouchUpdate); QVERIFY(rightWidget.seenTouchEnd); - QCOMPARE(leftWidget.touchEndPoints.count(), 1); - QCOMPARE(rightWidget.touchEndPoints.count(), 1); + QCOMPARE(leftWidget.touchEndPoints.size(), 1); + QCOMPARE(rightWidget.touchEndPoints.size(), 1); { - QEventPoint leftTouchPoint = leftWidget.touchEndPoints.first(); + const QEventPoint &leftTouchPoint = leftWidget.touchEndPoints.first(); QCOMPARE(leftTouchPoint.id(), touchPointId0); - QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state()); - QCOMPARE(leftTouchPoint.position(), QPointF(leftWidget.mapFromParent(centerPos.toPoint()))); + QCOMPARE(leftTouchPoint.state(), QEventPoint::Released); + QCOMPARE(leftTouchPoint.position(), QPointF(leftWidget.mapFromParent(centerPos))); QCOMPARE(leftTouchPoint.pressPosition(), leftPos); QCOMPARE(leftTouchPoint.lastPosition(), leftPos); QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos); @@ -960,16 +972,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos); QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos); - QCOMPARE(leftTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint())); - QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos); - QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(leftTouchPoint.ellipseDiameters(), QSizeF(0, 0)); QCOMPARE(leftTouchPoint.pressure(), qreal(0.)); - QEventPoint rightTouchPoint = rightWidget.touchEndPoints.first(); + const QEventPoint &rightTouchPoint = rightWidget.touchEndPoints.first(); QCOMPARE(rightTouchPoint.id(), touchPointId1); - QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state()); - QCOMPARE(rightTouchPoint.position(), QPointF(rightWidget.mapFromParent(centerPos.toPoint()))); + QCOMPARE(rightTouchPoint.state(), QEventPoint::Released); + QCOMPARE(rightTouchPoint.position(), QPointF(rightWidget.mapFromParent(centerPos))); QCOMPARE(rightTouchPoint.pressPosition(), rightPos); QCOMPARE(rightTouchPoint.lastPosition(), rightPos); QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos); @@ -978,9 +987,6 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos); QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos); - QCOMPARE(rightTouchPoint.position(), rightWidget.mapFromParent(centerPos.toPoint())); - QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos); - QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(rightTouchPoint.ellipseDiameters(), QSizeF(0, 0)); QCOMPARE(rightTouchPoint.pressure(), qreal(0.)); } @@ -1010,7 +1016,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchBeginPoints.count(), 1); + QCOMPARE(touchWidget.touchBeginPoints.size(), 1); QCOMPARE(touchWidget.timestamp, timestamp); QEventPoint touchBeginPoint = touchWidget.touchBeginPoints.first(); QCOMPARE(touchBeginPoint.id(), 1); @@ -1025,7 +1031,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens() QWindowSystemInterface::handleTouchEvent(window, ++timestamp, secondaryTouchScreenDevice, nativeTouchPoints); QCoreApplication::processEvents(); QVERIFY(!touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchBeginPoints.count(), 1); + QCOMPARE(touchWidget.touchBeginPoints.size(), 1); QCOMPARE(touchWidget.timestamp, timestamp); touchBeginPoint = touchWidget.touchBeginPoints[0]; QCOMPARE(touchBeginPoint.id(), 10); @@ -1040,7 +1046,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens() QWindowSystemInterface::handleTouchEvent(window, ++timestamp, secondaryTouchScreenDevice, nativeTouchPoints); QCoreApplication::processEvents(); QVERIFY(!touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchBeginPoints.count(), 1); + QCOMPARE(touchWidget.touchBeginPoints.size(), 1); QCOMPARE(touchWidget.timestamp, timestamp); touchBeginPoint = touchWidget.touchBeginPoints[0]; QCOMPARE(touchBeginPoint.id(), 11); @@ -1056,7 +1062,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchUpdatePoints.count(), 1); + QCOMPARE(touchWidget.touchUpdatePoints.size(), 1); QEventPoint touchUpdatePoint = touchWidget.touchUpdatePoints.first(); QCOMPARE(touchUpdatePoint.id(), 1); QCOMPARE(touchUpdatePoint.state(), QEventPoint::State::Updated); @@ -1071,7 +1077,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QVERIFY(touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchEndPoints.count(), 1); + QCOMPARE(touchWidget.touchEndPoints.size(), 1); QEventPoint touchEndPoint = touchWidget.touchEndPoints.first(); QCOMPARE(touchEndPoint.id(), 1); QCOMPARE(touchEndPoint.state(), QEventPoint::State::Released); @@ -1096,7 +1102,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchUpdatePoints.count(), 2); + QCOMPARE(touchWidget.touchUpdatePoints.size(), 2); QCOMPARE(touchWidget.touchUpdatePoints[0].id(), 10); QCOMPARE(touchWidget.touchUpdatePoints[1].id(), 11); @@ -1111,7 +1117,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QVERIFY(touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchEndPoints.count(), 1); + QCOMPARE(touchWidget.touchEndPoints.size(), 1); touchEndPoint = touchWidget.touchEndPoints.first(); QCOMPARE(touchEndPoint.id(), 11); QCOMPARE(touchEndPoint.state(), QEventPoint::State::Released); @@ -1127,6 +1133,9 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QSKIP("The macOS mouse cursor interferes with this test can cannot be moved away"); #endif + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("QWindow::requestActivate() is not supported."); + tst_QTouchEventWidget touchWidget; touchWidget.setObjectName("touchWidget"); touchWidget.setWindowTitle(QTest::currentTestFunction()); @@ -1145,7 +1154,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() rightWidget.setGeometry(300, 100, 100, 100); touchWidget.show(); - QVERIFY(QTest::qWaitForWindowExposed(&touchWidget)); + QVERIFY(QTest::qWaitForWindowActive(&touchWidget)); const QPointF leftPos = leftWidget.rect().center(); const QPointF rightPos = rightWidget.rect().center(); @@ -1183,8 +1192,9 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QVERIFY(!rightWidget.seenTouchBegin); QVERIFY(!rightWidget.seenTouchUpdate); QVERIFY(!rightWidget.seenTouchEnd); - QCOMPARE(leftWidget.touchBeginPoints.count(), 2); - QCOMPARE(rightWidget.touchBeginPoints.count(), 0); + QCOMPARE(leftWidget.touchBeginPoints.size(), 2); + QCOMPARE(rightWidget.touchBeginPoints.size(), 0); + QCOMPARE(leftWidget.lastNormalizedPositions.size(), 2); { QEventPoint leftTouchPoint = leftWidget.touchBeginPoints.at(0); qCDebug(lcTests) << "lastNormalizedPositions after press" << leftWidget.lastNormalizedPositions; @@ -1200,7 +1210,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QCOMPARE(leftTouchPoint.globalPosition(), leftScreenPos); QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos); QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos); - QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.2) < 0.05); // 0.198, might depend on window frame size + QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.2), 0.05); // 0.198, might depend on window frame size QCOMPARE(leftTouchPoint.position(), leftPos); QCOMPARE(leftTouchPoint.scenePosition(), leftScreenPos); QCOMPARE(leftTouchPoint.globalPosition(), leftScreenPos); @@ -1220,7 +1230,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QCOMPARE(rightTouchPoint.globalPosition(), rightScreenPos); QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos); QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos); - QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.8) < 0.05); // 0.798, might depend on window frame size + QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.8), 0.05); // 0.798, might depend on window frame size QCOMPARE(rightTouchPoint.scenePosition(), rightScreenPos); QCOMPARE(rightTouchPoint.globalPosition(), rightScreenPos); QCOMPARE(rightTouchPoint.ellipseDiameters(), QSizeF(0, 0)); @@ -1245,8 +1255,9 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QVERIFY(!rightWidget.seenTouchBegin); QVERIFY(!rightWidget.seenTouchUpdate); QVERIFY(!rightWidget.seenTouchEnd); - QCOMPARE(leftWidget.touchUpdatePoints.count(), 2); - QCOMPARE(rightWidget.touchUpdatePoints.count(), 0); + QCOMPARE(leftWidget.touchUpdatePoints.size(), 2); + QCOMPARE(rightWidget.touchUpdatePoints.size(), 0); + QCOMPARE(leftWidget.lastNormalizedPositions.size(), 2); { QEventPoint leftTouchPoint = leftWidget.touchUpdatePoints.at(0); qCDebug(lcTests) << "lastNormalizedPositions after update" << leftWidget.lastNormalizedPositions; @@ -1262,7 +1273,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos); QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos); - QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.5) < 0.05); // 0.498, might depend on window frame size + QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.5), 0.05); // 0.498, might depend on window frame size QCOMPARE(leftTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint())); QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos); QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos); @@ -1282,7 +1293,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos); QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos); - QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.5) < 0.05); // 0.498, might depend on window frame size + QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.5), 0.05); // 0.498, might depend on window frame size QCOMPARE(rightTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint())); QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos); QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos); @@ -1307,8 +1318,9 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QVERIFY(!rightWidget.seenTouchBegin); QVERIFY(!rightWidget.seenTouchUpdate); QVERIFY(!rightWidget.seenTouchEnd); - QCOMPARE(leftWidget.touchEndPoints.count(), 2); - QCOMPARE(rightWidget.touchEndPoints.count(), 0); + QCOMPARE(leftWidget.touchEndPoints.size(), 2); + QCOMPARE(rightWidget.touchEndPoints.size(), 0); + QCOMPARE(leftWidget.lastNormalizedPositions.size(), 2); { QEventPoint leftTouchPoint = leftWidget.touchEndPoints.at(0); qCDebug(lcTests) << "lastNormalizedPositions after release" << leftWidget.lastNormalizedPositions; @@ -1325,7 +1337,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos); QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos); - QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.5) < 0.05); // 0.498, might depend on window frame size + QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.5), 0.05); // 0.498, might depend on window frame size QCOMPARE(leftTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint())); QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos); QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos); @@ -1345,7 +1357,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos); QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos); QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos); - QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.5) < 0.05); // 0.498, might depend on window frame size + QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.5), 0.05); // 0.498, might depend on window frame size QCOMPARE(rightTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint())); QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos); QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos); @@ -1391,16 +1403,16 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(!touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchBeginPoints.count(), 2); + QCOMPARE(touchWidget.touchBeginPoints.size(), 2); - for (int i = 0; i < touchWidget.touchBeginPoints.count(); ++i) { + for (int i = 0; i < touchWidget.touchBeginPoints.size(); ++i) { QEventPoint touchBeginPoint = touchWidget.touchBeginPoints.at(i); QCOMPARE(touchBeginPoint.id(), i); QCOMPARE(touchBeginPoint.state(), rawTouchPoints[i].state()); } // moving the point should translate to TouchUpdate - for (int i = 0; i < rawTouchPoints.count(); ++i) { + for (int i = 0; i < rawTouchPoints.size(); ++i) { auto &p = rawTouchPoints[i]; QMutableEventPoint::setState(p, QEventPoint::State::Updated); QMutableEventPoint::setGlobalPosition(p, p.globalPosition() + delta); @@ -1412,7 +1424,7 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchUpdatePoints.count(), 2); + QCOMPARE(touchWidget.touchUpdatePoints.size(), 2); QCOMPARE(touchWidget.touchUpdatePoints.at(0).id(), 0); QCOMPARE(touchWidget.touchUpdatePoints.at(1).id(), 1); @@ -1427,7 +1439,7 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QCOMPARE(touchWidget.seenTouchEnd, false); - QCOMPARE(touchWidget.touchUpdatePoints.count(), 2); + QCOMPARE(touchWidget.touchUpdatePoints.size(), 2); QCOMPARE(touchWidget.touchUpdatePoints[0].id(), 0); QCOMPARE(touchWidget.touchUpdatePoints[1].id(), 1); @@ -1441,7 +1453,7 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QVERIFY(!touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchUpdatePoints.count(), 2); + QCOMPARE(touchWidget.touchUpdatePoints.size(), 2); QCOMPARE(touchWidget.touchUpdatePoints[0].id(), 0); QCOMPARE(touchWidget.touchUpdatePoints[1].id(), 42); @@ -1455,7 +1467,7 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds() QVERIFY(touchWidget.seenTouchBegin); QVERIFY(touchWidget.seenTouchUpdate); QVERIFY(touchWidget.seenTouchEnd); - QCOMPARE(touchWidget.touchUpdatePoints.count(), 2); + QCOMPARE(touchWidget.touchUpdatePoints.size(), 2); QCOMPARE(touchWidget.touchUpdatePoints[0].id(), 0); QCOMPARE(touchWidget.touchUpdatePoints[1].id(), 42); } @@ -1819,25 +1831,25 @@ void tst_QTouchEvent::testQGuiAppDelivery() // Now the real thing. QWindowSystemInterface::handleTouchEvent(&w, touchScreenDevice, points); // TouchBegin QCoreApplication::processEvents(); - QCOMPARE(filter.d.count(), 1); + QCOMPARE(filter.d.size(), 1); QCOMPARE(filter.d.contains(touchScreenDevice), true); - QCOMPARE(filter.d.value(touchScreenDevice).points.count(), 1); + QCOMPARE(filter.d.value(touchScreenDevice).points.size(), 1); QCOMPARE(filter.d.value(touchScreenDevice).lastSeenType, QEvent::TouchBegin); points[0].state = QEventPoint::State::Updated; QWindowSystemInterface::handleTouchEvent(&w, touchScreenDevice, points); // TouchUpdate QCoreApplication::processEvents(); - QCOMPARE(filter.d.count(), 1); + QCOMPARE(filter.d.size(), 1); QCOMPARE(filter.d.contains(touchScreenDevice), true); - QCOMPARE(filter.d.value(touchScreenDevice).points.count(), 2); + QCOMPARE(filter.d.value(touchScreenDevice).points.size(), 2); QCOMPARE(filter.d.value(touchScreenDevice).lastSeenType, QEvent::TouchUpdate); points[0].state = QEventPoint::State::Released; QWindowSystemInterface::handleTouchEvent(&w, touchScreenDevice, points); // TouchEnd QCoreApplication::processEvents(); - QCOMPARE(filter.d.count(), 1); + QCOMPARE(filter.d.size(), 1); QCOMPARE(filter.d.contains(touchScreenDevice), true); - QCOMPARE(filter.d.value(touchScreenDevice).points.count(), 3); + QCOMPARE(filter.d.value(touchScreenDevice).points.size(), 3); QCOMPARE(filter.d.value(touchScreenDevice).lastSeenType, QEvent::TouchEnd); } @@ -1880,8 +1892,8 @@ void tst_QTouchEvent::testMultiDevice() QCOMPARE(filter.d.value(touchScreenDevice).lastSeenType, QEvent::TouchBegin); QCOMPARE(filter.d.value(deviceTwo).lastSeenType, QEvent::TouchBegin); - QCOMPARE(filter.d.value(touchScreenDevice).points.count(), 1); - QCOMPARE(filter.d.value(deviceTwo).points.count(), 2); + QCOMPARE(filter.d.value(touchScreenDevice).points.size(), 1); + QCOMPARE(filter.d.value(deviceTwo).points.size(), 2); QCOMPARE(filter.d.value(touchScreenDevice).points.at(0).globalPosition(), area0.center()); // This fails because QGuiApplicationPrivate::processTouchEvent() sends synth-mouse events @@ -1936,7 +1948,7 @@ void tst_QTouchEvent::grabbers() // Ensure that grabbers are persistent between events, within the stored touchpoints QCOMPARE(devPriv->pointById(0)->exclusiveGrabber, grabExclusive ? &w : nullptr); - QCOMPARE(devPriv->pointById(0)->passiveGrabbers.count(), grabPassive ? 1 : 0); + QCOMPARE(devPriv->pointById(0)->passiveGrabbers.size(), grabPassive ? 1 : 0); if (grabPassive) QCOMPARE(devPriv->pointById(0)->passiveGrabbers.first(), &w); |