From 47f6d256edf76a8a201057236226b507bcc1aa89 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 8 Apr 2015 14:10:28 +0200 Subject: tst_qquickapplication: change test case 'state' to be more stable Qt-5.4 integration can sometimes fail on this test. We have not succeeded reproducing it, but from reading the test code, it seems likely that the problem might come from already pending state events queued before the test starts. Since the test cannot know if the platform will queue state events while spinning the event loop (waitForEvents), this patch will instead only flush already queued events, which should be less prone to side effects. Change-Id: I134f98ba35faa4d9213ee658ebcbe76b390b5516 Reviewed-by: Yoann Lopes Reviewed-by: Frederik Gladhorn --- .../quick/qquickapplication/tst_qquickapplication.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'tests/auto/quick/qquickapplication') diff --git a/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp b/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp index f803a63fd7..cc6fac5b39 100644 --- a/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp +++ b/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp @@ -132,31 +132,30 @@ void tst_qquickapplication::state() QQuickWindow window; item->setParentItem(window.contentItem()); - // initial state should be ApplicationInactive - QCOMPARE(Qt::ApplicationState(item->property("state").toInt()), Qt::ApplicationInactive); - QCOMPARE(Qt::ApplicationState(item->property("state2").toInt()), Qt::ApplicationInactive); - // If the platform plugin has the ApplicationState capability, state changes originate from it // as a result of a system event. We therefore have to simulate these events here. if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) { + // Flush pending events, in case the platform have already queued real application state events + QWindowSystemInterface::flushWindowSystemEvents(); + QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationActive); - QTest::waitForEvents(); + QWindowSystemInterface::flushWindowSystemEvents(); QCOMPARE(Qt::ApplicationState(item->property("state").toInt()), Qt::ApplicationActive); QCOMPARE(Qt::ApplicationState(item->property("state2").toInt()), Qt::ApplicationActive); QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationInactive); - QTest::waitForEvents(); + QWindowSystemInterface::flushWindowSystemEvents(); QCOMPARE(Qt::ApplicationState(item->property("state").toInt()), Qt::ApplicationInactive); QCOMPARE(Qt::ApplicationState(item->property("state2").toInt()), Qt::ApplicationInactive); QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationSuspended); - QTest::waitForEvents(); + QWindowSystemInterface::flushWindowSystemEvents(); QCOMPARE(Qt::ApplicationState(item->property("state").toInt()), Qt::ApplicationSuspended); QCOMPARE(Qt::ApplicationState(item->property("state2").toInt()), Qt::ApplicationSuspended); QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationHidden); - QTest::waitForEvents(); + QWindowSystemInterface::flushWindowSystemEvents(); QCOMPARE(Qt::ApplicationState(item->property("state").toInt()), Qt::ApplicationHidden); QCOMPARE(Qt::ApplicationState(item->property("state2").toInt()), Qt::ApplicationHidden); -- cgit v1.2.3