aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmltest
diff options
context:
space:
mode:
authorCharles Yin <charles.yin@nokia.com>2012-06-12 14:46:12 +1000
committerQt by Nokia <qt-info@nokia.com>2012-06-14 02:44:19 +0200
commit4276def0405d22e7cbfb75465a42b5a68e7472fe (patch)
tree05877ad9a2f64eb09af4ec597a15f59072f26327 /src/qmltest
parent5eeffd021996f1bae32973681aa4db3e354aacdb (diff)
Align windowShown flag with qml renderer state
Previously, we set windowShown to true once the window is active, this is not enough for some tests as the initial rendering may not be finished yet and will give the wrong result for some tests which require reading back pixels. Change-Id: Idd67329d207aaf1734a795b40a5bcc40093cf6b8 Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'src/qmltest')
-rw-r--r--src/qmltest/quicktest.cpp27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/qmltest/quicktest.cpp b/src/qmltest/quicktest.cpp
index 66f1d861a2..ef026d4573 100644
--- a/src/qmltest/quicktest.cpp
+++ b/src/qmltest/quicktest.cpp
@@ -62,6 +62,8 @@
#include <stdio.h>
#include <QtGui/QGuiApplication>
#include <QtCore/QTranslator>
+#include <QtTest/QSignalSpy>
+
QT_BEGIN_NAMESPACE
class QTestRootObject : public QObject
@@ -145,6 +147,24 @@ void handleCompileErrors(const QFileInfo &fi, QQuickView *view)
results.stopLogging();
}
+static bool qWaitForSignal(QObject *obj, const char* signal, int timeout = 5000)
+{
+ QSignalSpy spy(obj, signal);
+ QElapsedTimer timer;
+ timer.start();
+
+ while (!spy.size()) {
+ int remaining = timeout - int(timer.elapsed());
+ if (remaining <= 0)
+ break;
+ QCoreApplication::processEvents(QEventLoop::AllEvents, remaining);
+ QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
+ QTest::qSleep(10);
+ }
+
+ return spy.size();
+}
+
int quick_test_main(int argc, char **argv, const char *name, const char *sourceDir)
{
QGuiApplication* app = 0;
@@ -284,10 +304,11 @@ int quick_test_main(int argc, char **argv, const char *name, const char *sourceD
// If the test already quit, then it was performed
// synchronously during setSource(). Otherwise it is
// an asynchronous test and we need to show the window
- // and wait for the quit indication.
+ // and wait for the first frame to be rendered
+ // and then wait for quit indication.
view->show();
- QTest::qWaitForWindowShown(view);
- rootobj.setWindowShown(true);
+ if (qWaitForSignal(view, SIGNAL(frameSwapped())))
+ rootobj.setWindowShown(true);
if (!rootobj.hasQuit && rootobj.hasTestCase())
eventLoop.exec();
}