Add waitForRendering() function for qmltest
authorCharles Yin <charles.yin@nokia.com>
Tue, 12 Jun 2012 05:38:52 +0000 (15:38 +1000)
committerQt by Nokia <qt-info@nokia.com>
Wed, 25 Jul 2012 02:09:33 +0000 (04:09 +0200)
Change-Id: I6357412d84fdb4a8b6bd8603baba7d10a2bcc245
Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
src/imports/testlib/TestCase.qml
src/imports/testlib/testcase.qdoc
src/qmltest/quicktest.cpp
src/qmltest/quicktestresult.cpp
src/qmltest/quicktestresult_p.h
tests/auto/qmltest/pixel/tst_pixel.qml

index ddd7f70..79c68a7 100644 (file)
@@ -357,6 +357,12 @@ Item {
         qtest_results.wait(ms)
     }
 
+    function waitForRendering(item, timeout) {
+        if (timeout === undefined)
+            timeout = 5000
+        return qtest_results.waitForRendering(item, timeout)
+    }
+
     function sleep(ms) {
         qtest_results.sleep(ms)
     }
index 8a0f770..77cfae1 100644 (file)
 
     Waits for \a ms milliseconds while processing Qt events.
 
-    \sa sleep()
+    \sa sleep(), waitForRendering()
+*/
+
+/*!
+    \qmlmethod TestCase::waitForRendering(item, timeout = 5000)
+
+    Waits for \a timeout milliseconds or until the \a item is rendered by the renderer.
+    Returns true if \c item is rendered in \a timeout milliseconds, otherwise returns false.
+    The default \a timeout value is 5000.
+
+    \sa sleep(), wait()
 */
 
 /*!
 
     Sleeps for \a ms milliseconds without processing Qt events.
 
-    \sa wait()
+    \sa wait(), waitForRendering()
 */
 
 /*!
index ef026d4..cfa503a 100644 (file)
@@ -147,7 +147,7 @@ void handleCompileErrors(const QFileInfo &fi, QQuickView *view)
     results.stopLogging();
 }
 
-static bool qWaitForSignal(QObject *obj, const char* signal, int timeout = 5000)
+bool qWaitForSignal(QObject *obj, const char* signal, int timeout = 5000)
 {
     QSignalSpy spy(obj, signal);
     QElapsedTimer timer;
index f6fd873..751ee9e 100644 (file)
@@ -65,6 +65,8 @@ static const char *globalProgramName = 0;
 static bool loggingStarted = false;
 static QBenchmarkGlobalData globalBenchmarkData;
 
+extern bool qWaitForSignal(QObject *obj, const char* signal, int timeout = 5000);
+
 class Q_QUICK_TEST_EXPORT QuickTestImageObject : public QObject
 {
     Q_OBJECT
@@ -573,6 +575,13 @@ void QuickTestResult::sleep(int ms)
     QTest::qSleep(ms);
 }
 
+bool QuickTestResult::waitForRendering(QQuickItem *item, int timeout)
+{
+    Q_ASSERT(item);
+
+    return qWaitForSignal(item->canvas(), SIGNAL(frameSwapped()), timeout);
+}
+
 void QuickTestResult::startMeasurement()
 {
     Q_D(QuickTestResult);
index 0ef41ad..448f2da 100644 (file)
@@ -132,6 +132,7 @@ public Q_SLOTS:
 
     void wait(int ms);
     void sleep(int ms);
+    bool waitForRendering(QQuickItem *item, int timeout = 5000);
 
     void startMeasurement();
     void beginDataRun();
index f2a9d5f..dbcca4a 100644 (file)
@@ -64,7 +64,7 @@ Rectangle {
            fuzzyCompare(img.pixel(1,1), "#FF0201", 2);
 
            rect.color = "blue";
-           wait(200);
+           waitForRendering(rect);
            img = grabImage(rect);
            compare(img.pixel(20, 20), Qt.rgba(0, 0, 255, 255));
            compare(img.red(1,1), 0);