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>
This commit is contained in:
parent
b1cf7285f9
commit
55928821d1
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user