diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-07-03 14:38:46 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-07-03 15:07:24 +0000 |
commit | c42f0a618271b845cda3ba179f8b7831d2aaca39 (patch) | |
tree | 9b7552b0ff2e3a31f62cbf9257cef7359de77e3b /tests | |
parent | 284979ae8a6522ef6454966be69085e618c5c478 (diff) |
Quick tests: remember positions of stationary points
We need Items to receive accurate positions for stationary touch
points: that is, the last-known position from the previous touch
event. (And we hope that all actual touch-capable platforms also send
proper QPA events with correct positions for stationary points.
We assert that it's a bug if they don't.)
As explained in qtbase 7cef4b6463fdb73ff602ade64b222333dd23e46c, it's
OK to retain a copy of a QTest::QTouchEventSequence for this purpose,
so that the QMap<int, QTouchEvent::TouchPoint> previousPoints will not
be discarded between events.
Change-Id: I12a04323b0d82dc325348c0fa3e067a4b63f57e9
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquickwindow/tst_qquickwindow.cpp | 45 | ||||
-rw-r--r-- | tests/auto/quick/touchmouse/tst_touchmouse.cpp | 50 |
2 files changed, 49 insertions, 46 deletions
diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp index 44cd1dd656..381da76fa3 100644 --- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp +++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp @@ -631,9 +631,10 @@ void tst_qquickwindow::touchEvent_basic() topItem->setSize(QSizeF(150, 150)); QPointF pos(10, 10); + QTest::QTouchEventSequence touchSeq = QTest::touchEvent(window, touchDevice, false); // press single point - QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(),window); + touchSeq.press(0, topItem->mapToScene(pos).toPoint(),window).commit(); QQuickTouchUtils::flush(window); QTRY_COMPARE(topItem->lastEvent.touchPoints.count(), 1); @@ -643,11 +644,11 @@ void tst_qquickwindow::touchEvent_basic() // would put the decorated window at that position rather than the window itself. COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed, makeTouchPoint(topItem, pos))); topItem->reset(); - QTest::touchEvent(window, touchDevice).release(0, topItem->mapToScene(pos).toPoint(), window); + touchSeq.release(0, topItem->mapToScene(pos).toPoint(), window).commit(); // press multiple points - QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(), window) - .press(1, bottomItem->mapToScene(pos).toPoint(), window); + touchSeq.press(0, topItem->mapToScene(pos).toPoint(), window) + .press(1, bottomItem->mapToScene(pos).toPoint(), window).commit(); QQuickTouchUtils::flush(window); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); QVERIFY(middleItem->lastEvent.touchPoints.isEmpty()); @@ -656,35 +657,35 @@ void tst_qquickwindow::touchEvent_basic() COMPARE_TOUCH_DATA(bottomItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed, makeTouchPoint(bottomItem, pos))); topItem->reset(); bottomItem->reset(); - QTest::touchEvent(window, touchDevice).release(0, topItem->mapToScene(pos).toPoint(), window).release(1, bottomItem->mapToScene(pos).toPoint(), window); + touchSeq.release(0, topItem->mapToScene(pos).toPoint(), window).release(1, bottomItem->mapToScene(pos).toPoint(), window).commit(); // touch point on top item moves to bottom item, but top item should still receive the event - QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(), window); + touchSeq.press(0, topItem->mapToScene(pos).toPoint(), window).commit(); QQuickTouchUtils::flush(window); - QTest::touchEvent(window, touchDevice).move(0, bottomItem->mapToScene(pos).toPoint(), window); + touchSeq.move(0, bottomItem->mapToScene(pos).toPoint(), window).commit(); QQuickTouchUtils::flush(window); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchUpdate, window, Qt::TouchPointMoved, makeTouchPoint(topItem, topItem->mapFromItem(bottomItem, pos), pos))); topItem->reset(); - QTest::touchEvent(window, touchDevice).release(0, bottomItem->mapToScene(pos).toPoint(), window); + touchSeq.release(0, bottomItem->mapToScene(pos).toPoint(), window).commit(); // touch point on bottom item moves to top item, but bottom item should still receive the event - QTest::touchEvent(window, touchDevice).press(0, bottomItem->mapToScene(pos).toPoint(), window); + touchSeq.press(0, bottomItem->mapToScene(pos).toPoint(), window).commit(); QQuickTouchUtils::flush(window); - QTest::touchEvent(window, touchDevice).move(0, topItem->mapToScene(pos).toPoint(), window); + touchSeq.move(0, topItem->mapToScene(pos).toPoint(), window).commit(); QQuickTouchUtils::flush(window); QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 1); COMPARE_TOUCH_DATA(bottomItem->lastEvent, makeTouchData(QEvent::TouchUpdate, window, Qt::TouchPointMoved, makeTouchPoint(bottomItem, bottomItem->mapFromItem(topItem, pos), pos))); bottomItem->reset(); - QTest::touchEvent(window, touchDevice).release(0, bottomItem->mapToScene(pos).toPoint(), window); + touchSeq.release(0, bottomItem->mapToScene(pos).toPoint(), window).commit(); // a single stationary press on an item shouldn't cause an event - QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(), window); + touchSeq.press(0, topItem->mapToScene(pos).toPoint(), window).commit(); QQuickTouchUtils::flush(window); - QTest::touchEvent(window, touchDevice).stationary(0) - .press(1, bottomItem->mapToScene(pos).toPoint(), window); + touchSeq.stationary(0) + .press(1, bottomItem->mapToScene(pos).toPoint(), window).commit(); QQuickTouchUtils::flush(window); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); // received press only, not stationary QVERIFY(middleItem->lastEvent.touchPoints.isEmpty()); @@ -696,13 +697,13 @@ void tst_qquickwindow::touchEvent_basic() // cleanup: what is pressed must be released // Otherwise you will get an assertion failure: // ASSERT: "itemForTouchPointId.isEmpty()" in file items/qquickwindow.cpp - QTest::touchEvent(window, touchDevice).release(0, pos.toPoint(), window).release(1, pos.toPoint(), window); + touchSeq.release(0, pos.toPoint(), window).release(1, pos.toPoint(), window).commit(); QQuickTouchUtils::flush(window); // move touch point from top item to bottom, and release - QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(),window); + touchSeq.press(0, topItem->mapToScene(pos).toPoint(),window).commit(); QQuickTouchUtils::flush(window); - QTest::touchEvent(window, touchDevice).release(0, bottomItem->mapToScene(pos).toPoint(),window); + touchSeq.release(0, bottomItem->mapToScene(pos).toPoint(),window).commit(); QQuickTouchUtils::flush(window); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); COMPARE_TOUCH_DATA(topItem->lastEvent, makeTouchData(QEvent::TouchEnd, window, Qt::TouchPointReleased, @@ -710,13 +711,13 @@ void tst_qquickwindow::touchEvent_basic() topItem->reset(); // release while another point is pressed - QTest::touchEvent(window, touchDevice).press(0, topItem->mapToScene(pos).toPoint(),window) - .press(1, bottomItem->mapToScene(pos).toPoint(), window); + touchSeq.press(0, topItem->mapToScene(pos).toPoint(),window) + .press(1, bottomItem->mapToScene(pos).toPoint(), window).commit(); QQuickTouchUtils::flush(window); - QTest::touchEvent(window, touchDevice).move(0, bottomItem->mapToScene(pos).toPoint(), window); + touchSeq.move(0, bottomItem->mapToScene(pos).toPoint(), window).commit(); QQuickTouchUtils::flush(window); - QTest::touchEvent(window, touchDevice).release(0, bottomItem->mapToScene(pos).toPoint(), window) - .stationary(1); + touchSeq.release(0, bottomItem->mapToScene(pos).toPoint(), window) + .stationary(1).commit(); QQuickTouchUtils::flush(window); QCOMPARE(topItem->lastEvent.touchPoints.count(), 1); QVERIFY(middleItem->lastEvent.touchPoints.isEmpty()); diff --git a/tests/auto/quick/touchmouse/tst_touchmouse.cpp b/tests/auto/quick/touchmouse/tst_touchmouse.cpp index a69cd5bc34..2fc56c2ad8 100644 --- a/tests/auto/quick/touchmouse/tst_touchmouse.cpp +++ b/tests/auto/quick/touchmouse/tst_touchmouse.cpp @@ -824,6 +824,7 @@ void tst_TouchMouse::buttonOnTouch() EventItem *eventItem4 = window->rootObject()->findChild<EventItem*>("eventItem4"); QVERIFY(eventItem4); + QTest::QTouchEventSequence touchSeq = QTest::touchEvent(window.data(), device, false); // Test the common case of a mouse area on top of pinch eventItem1->setAcceptedMouseButtons(Qt::LeftButton); @@ -835,9 +836,9 @@ void tst_TouchMouse::buttonOnTouch() // Normal touch click QPoint p1 = QPoint(10, 110); - QTest::touchEvent(window.data(), device).press(0, p1, window.data()); + touchSeq.press(0, p1, window.data()).commit(); QQuickTouchUtils::flush(window.data()); - QTest::touchEvent(window.data(), device).release(0, p1, window.data()); + touchSeq.release(0, p1, window.data()).commit(); QQuickTouchUtils::flush(window.data()); QCOMPARE(eventItem1->eventList.size(), 5); QCOMPARE(eventItem1->eventList.at(0).type, QEvent::TouchBegin); @@ -860,9 +861,9 @@ void tst_TouchMouse::buttonOnTouch() QPoint p2 = QPoint(60, 10); // Start the events after each other - QTest::touchEvent(window.data(), device).press(0, p1, window.data()); + touchSeq.press(0, p1, window.data()).commit(); QQuickTouchUtils::flush(window.data()); - QTest::touchEvent(window.data(), device).stationary(0).press(1, p2, window.data()); + touchSeq.stationary(0).press(1, p2, window.data()).commit(); QQuickTouchUtils::flush(window.data()); QCOMPARE(button1->scale(), 1.0); @@ -870,24 +871,24 @@ void tst_TouchMouse::buttonOnTouch() // This event seems to be discarded, let's ignore it for now until someone digs into pincharea p1 -= QPoint(10, 0); p2 += QPoint(10, 0); - QTest::touchEvent(window.data(), device).move(0, p1, window.data()).move(1, p2, window.data()); + touchSeq.move(0, p1, window.data()).move(1, p2, window.data()).commit(); QQuickTouchUtils::flush(window.data()); p1 -= QPoint(10, 0); p2 += QPoint(10, 0); - QTest::touchEvent(window.data(), device).move(0, p1, window.data()).move(1, p2, window.data()); + touchSeq.move(0, p1, window.data()).move(1, p2, window.data()).commit(); QQuickTouchUtils::flush(window.data()); // QCOMPARE(button1->scale(), 1.5); qDebug() << "Button scale: " << button1->scale(); p1 -= QPoint(10, 0); p2 += QPoint(10, 0); - QTest::touchEvent(window.data(), device).move(0, p1, window.data()).move(1, p2, window.data()); + touchSeq.move(0, p1, window.data()).move(1, p2, window.data()).commit(); QQuickTouchUtils::flush(window.data()); // QCOMPARE(button1->scale(), 2.0); qDebug() << "Button scale: " << button1->scale(); - QTest::touchEvent(window.data(), device).release(0, p1, window.data()).release(1, p2, window.data()); + touchSeq.release(0, p1, window.data()).release(1, p2, window.data()).commit(); QQuickTouchUtils::flush(window.data()); // QVERIFY(eventItem1->eventList.isEmpty()); // QCOMPARE(button1->scale(), 2.0); @@ -901,7 +902,7 @@ void tst_TouchMouse::buttonOnTouch() button1->setScale(1.0); p1 = QPoint(40, 110); p2 = QPoint(60, 110); - QTest::touchEvent(window.data(), device).press(0, p1, window.data()).press(1, p2, window.data()); + touchSeq.press(0, p1, window.data()).press(1, p2, window.data()).commit(); QQuickTouchUtils::flush(window.data()); QCOMPARE(button1->scale(), 1.0); QCOMPARE(eventItem1->eventList.count(), 2); @@ -911,24 +912,24 @@ void tst_TouchMouse::buttonOnTouch() // This event seems to be discarded, let's ignore it for now until someone digs into pincharea p1 -= QPoint(10, 0); p2 += QPoint(10, 0); - QTest::touchEvent(window.data(), device).move(0, p1, window.data()).move(1, p2, window.data()); + touchSeq.move(0, p1, window.data()).move(1, p2, window.data()).commit(); QQuickTouchUtils::flush(window.data()); p1 -= QPoint(10, 0); p2 += QPoint(10, 0); - QTest::touchEvent(window.data(), device).move(0, p1, window.data()).move(1, p2, window.data()); + touchSeq.move(0, p1, window.data()).move(1, p2, window.data()).commit(); QQuickTouchUtils::flush(window.data()); //QCOMPARE(button1->scale(), 1.5); qDebug() << button1->scale(); p1 -= QPoint(10, 0); p2 += QPoint(10, 0); - QTest::touchEvent(window.data(), device).move(0, p1, window.data()).move(1, p2, window.data()); + touchSeq.move(0, p1, window.data()).move(1, p2, window.data()).commit(); QQuickTouchUtils::flush(window.data()); qDebug() << button1->scale(); //QCOMPARE(button1->scale(), 2.0); - QTest::touchEvent(window.data(), device).release(0, p1, window.data()).release(1, p2, window.data()); + touchSeq.release(0, p1, window.data()).release(1, p2, window.data()).commit(); QQuickTouchUtils::flush(window.data()); // QCOMPARE(eventItem1->eventList.size(), 99); qDebug() << button1->scale(); @@ -1334,6 +1335,7 @@ void tst_TouchMouse::touchPointDeliveryOrder() QPoint pLeftMiddle = QPoint(200, 100); QPoint pRightMiddle = QPoint(350, 100); + QTest::QTouchEventSequence touchSeq = QTest::touchEvent(window.data(), device, false); QVector<QQuickItem*> events; EventItem *background = window->rootObject()->findChild<EventItem*>("background"); @@ -1349,7 +1351,7 @@ void tst_TouchMouse::touchPointDeliveryOrder() connect(middle, &EventItem::onTouchEvent, [&events](QQuickItem* receiver){ events.append(receiver); }); connect(right, &EventItem::onTouchEvent, [&events](QQuickItem* receiver){ events.append(receiver); }); - QTest::touchEvent(window.data(), device).press(0, pLeft, window.data()); + touchSeq.press(0, pLeft, window.data()).commit(); QQuickTouchUtils::flush(window.data()); // Touch on left, then background @@ -1359,7 +1361,7 @@ void tst_TouchMouse::touchPointDeliveryOrder() events.clear(); // New press events are deliverd first, the stationary point was not accepted, thus it doesn't get delivered - QTest::touchEvent(window.data(), device).stationary(0).press(1, pRightMiddle, window.data()); + touchSeq.stationary(0).press(1, pRightMiddle, window.data()).commit(); QQuickTouchUtils::flush(window.data()); QCOMPARE(events.size(), 3); QCOMPARE(events.at(0), middle); @@ -1367,49 +1369,49 @@ void tst_TouchMouse::touchPointDeliveryOrder() QCOMPARE(events.at(2), background); events.clear(); - QTest::touchEvent(window.data(), device).release(0, pLeft, window.data()).release(1, pRightMiddle, window.data()); + touchSeq.release(0, pLeft, window.data()).release(1, pRightMiddle, window.data()).commit(); QQuickTouchUtils::flush(window.data()); QCOMPARE(events.size(), 0); // no accepted events // Two presses, the first point should come first - QTest::touchEvent(window.data(), device).press(0, pLeft, window.data()).press(1, pRight, window.data()); + touchSeq.press(0, pLeft, window.data()).press(1, pRight, window.data()).commit(); QQuickTouchUtils::flush(window.data()); QCOMPARE(events.size(), 3); QCOMPARE(events.at(0), left); QCOMPARE(events.at(1), right); QCOMPARE(events.at(2), background); - QTest::touchEvent(window.data(), device).release(0, pLeft, window.data()).release(1, pRight, window.data()); + touchSeq.release(0, pLeft, window.data()).release(1, pRight, window.data()).commit(); events.clear(); // Again, pressing right first - QTest::touchEvent(window.data(), device).press(0, pRight, window.data()).press(1, pLeft, window.data()); + touchSeq.press(0, pRight, window.data()).press(1, pLeft, window.data()).commit(); QQuickTouchUtils::flush(window.data()); QCOMPARE(events.size(), 3); QCOMPARE(events.at(0), right); QCOMPARE(events.at(1), left); QCOMPARE(events.at(2), background); - QTest::touchEvent(window.data(), device).release(0, pRight, window.data()).release(1, pLeft, window.data()); + touchSeq.release(0, pRight, window.data()).release(1, pLeft, window.data()).commit(); events.clear(); // Two presses, both hitting the middle item on top, then branching left and right, then bottom // Each target should be offered the events exactly once, middle first, left must come before right (id 0) - QTest::touchEvent(window.data(), device).press(0, pLeftMiddle, window.data()).press(1, pRightMiddle, window.data()); + touchSeq.press(0, pLeftMiddle, window.data()).press(1, pRightMiddle, window.data()).commit(); QCOMPARE(events.size(), 4); QCOMPARE(events.at(0), middle); QCOMPARE(events.at(1), left); QCOMPARE(events.at(2), right); QCOMPARE(events.at(3), background); - QTest::touchEvent(window.data(), device).release(0, pLeftMiddle, window.data()).release(1, pRightMiddle, window.data()); + touchSeq.release(0, pLeftMiddle, window.data()).release(1, pRightMiddle, window.data()).commit(); events.clear(); - QTest::touchEvent(window.data(), device).press(0, pRightMiddle, window.data()).press(1, pLeftMiddle, window.data()); + touchSeq.press(0, pRightMiddle, window.data()).press(1, pLeftMiddle, window.data()).commit(); qDebug() << events; QCOMPARE(events.size(), 4); QCOMPARE(events.at(0), middle); QCOMPARE(events.at(1), right); QCOMPARE(events.at(2), left); QCOMPARE(events.at(3), background); - QTest::touchEvent(window.data(), device).release(0, pRightMiddle, window.data()).release(1, pLeftMiddle, window.data()); + touchSeq.release(0, pRightMiddle, window.data()).release(1, pLeftMiddle, window.data()).commit(); } void tst_TouchMouse::hoverEnabled() |