summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel
diff options
context:
space:
mode:
authorDimitrios Apostolou <jimis@qt.io>2022-07-22 14:46:10 +0200
committerDimitrios Apostolou <jimis@qt.io>2022-07-22 19:19:59 +0200
commit45501f6ca60c79eb826cc10422d15e98b167814a (patch)
tree85af5731267940dd353c786c7284202febccbc01 /tests/auto/gui/kernel
parent60f61198f2308e4767d57ec22331d77d46c6eb44 (diff)
Ensure list has elements before getting them
Before a recent fix it would happen occasionally that lastNormalizedPositions.at(0) would segfault because the list was empty. The cause of the flakiness was fixed, but make the test more resilient anyway by checking first the list is correctly populated. Furthermore on some platforms this check fails: qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.8) < 0.05 So instead of QVERIFY use QCOMPARE_LT to print the values when it fails. Task-number: QTBUG-104268 Change-Id: Id5430eb53c133cf5d23647cfd9749f01f266efce Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/gui/kernel')
-rw-r--r--tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
index 2f0863fc54..1df80a5683 100644
--- a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
+++ b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
@@ -1185,6 +1185,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QVERIFY(!rightWidget.seenTouchEnd);
QCOMPARE(leftWidget.touchBeginPoints.count(), 2);
QCOMPARE(rightWidget.touchBeginPoints.count(), 0);
+ QCOMPARE(leftWidget.lastNormalizedPositions.count(), 2);
{
QEventPoint leftTouchPoint = leftWidget.touchBeginPoints.at(0);
qCDebug(lcTests) << "lastNormalizedPositions after press" << leftWidget.lastNormalizedPositions;
@@ -1200,7 +1201,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 +1221,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));
@@ -1247,6 +1248,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QVERIFY(!rightWidget.seenTouchEnd);
QCOMPARE(leftWidget.touchUpdatePoints.count(), 2);
QCOMPARE(rightWidget.touchUpdatePoints.count(), 0);
+ QCOMPARE(leftWidget.lastNormalizedPositions.count(), 2);
{
QEventPoint leftTouchPoint = leftWidget.touchUpdatePoints.at(0);
qCDebug(lcTests) << "lastNormalizedPositions after update" << leftWidget.lastNormalizedPositions;
@@ -1262,7 +1264,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 +1284,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);
@@ -1309,6 +1311,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QVERIFY(!rightWidget.seenTouchEnd);
QCOMPARE(leftWidget.touchEndPoints.count(), 2);
QCOMPARE(rightWidget.touchEndPoints.count(), 0);
+ QCOMPARE(leftWidget.lastNormalizedPositions.count(), 2);
{
QEventPoint leftTouchPoint = leftWidget.touchEndPoints.at(0);
qCDebug(lcTests) << "lastNormalizedPositions after release" << leftWidget.lastNormalizedPositions;
@@ -1325,7 +1328,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 +1348,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);