summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-01-13 11:27:11 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2022-01-13 21:00:22 +0000
commit55928821d1b119112c520af3b83dc9ed210cf5f0 (patch)
treea401449afca13643c7fe045e90be575892869aa3 /tests
parentb1cf7285f9a469b8f0c62f2048e4c0828def5f1a (diff)
Improve QShortcut test
The test uses a static MainWindow so that we can execute a series of key simulations on the same window. The window is then destroyed when we reach the final test row. If some of the tests fail, then the window is left in an unknown state, resulting in cascading failures for the other tests. Fix this by always trying to show and activate the window, and always destroying the static window if we have reached the last test data row. Fixes: QTBUG-99630 Pick-to: 6.2 6.3 Change-Id: I466669f387e8b199e9e719a7ebbe3ae670658b7e Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
index 1266660cea..5530fee72a 100644
--- a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
+++ b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
@@ -1292,13 +1292,20 @@ void tst_QShortcut::testElement()
QFETCH(int, c4);
QFETCH(tst_QShortcut::Result, result);
- if (mainW.isNull()) {
+ auto mainWindowDeleter = qScopeGuard([&]{
+ if (action == TestEnd)
+ mainW.reset();
+ });
+
+ if (mainW.isNull())
mainW.reset(new MainWindow);
- mainW->setWindowTitle(QTest::currentTestFunction());
- mainW->show();
- mainW->activateWindow();
- QVERIFY(QTest::qWaitForWindowActive(mainW.data()));
- }
+ mainW->setWindowTitle(QTest::currentTestFunction());
+ mainW->show();
+ mainW->activateWindow();
+ // Don't use QVERIFY here; the data function uses QEXPECT_FAIL,
+ // which would result in an XPASS failure.
+ if (!QTest::qWaitForWindowActive(mainW.data()))
+ QVERIFY(false);
switch (action) {
case ClearAll:
@@ -1313,7 +1320,7 @@ void tst_QShortcut::testElement()
QCOMPARE(currentResult, result);
break;
case TestEnd:
- mainW.reset();
+ // taken care of by the mainWindowDeleter
break;
}
}