aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/imports/testlib/TestCase.qml6
-rw-r--r--src/imports/testlib/testcase.qdoc14
-rw-r--r--src/qmltest/quicktest.cpp2
-rw-r--r--src/qmltest/quicktestresult.cpp9
-rw-r--r--src/qmltest/quicktestresult_p.h1
-rw-r--r--tests/auto/qmltest/pixel/tst_pixel.qml2
6 files changed, 30 insertions, 4 deletions
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml
index ddd7f7030f..79c68a75a7 100644
--- a/src/imports/testlib/TestCase.qml
+++ b/src/imports/testlib/TestCase.qml
@@ -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)
}
diff --git a/src/imports/testlib/testcase.qdoc b/src/imports/testlib/testcase.qdoc
index 8a0f770544..77cfae140e 100644
--- a/src/imports/testlib/testcase.qdoc
+++ b/src/imports/testlib/testcase.qdoc
@@ -474,7 +474,17 @@
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()
*/
/*!
@@ -482,7 +492,7 @@
Sleeps for \a ms milliseconds without processing Qt events.
- \sa wait()
+ \sa wait(), waitForRendering()
*/
/*!
diff --git a/src/qmltest/quicktest.cpp b/src/qmltest/quicktest.cpp
index ef026d4573..cfa503a113 100644
--- a/src/qmltest/quicktest.cpp
+++ b/src/qmltest/quicktest.cpp
@@ -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;
diff --git a/src/qmltest/quicktestresult.cpp b/src/qmltest/quicktestresult.cpp
index f6fd873011..751ee9e6f4 100644
--- a/src/qmltest/quicktestresult.cpp
+++ b/src/qmltest/quicktestresult.cpp
@@ -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);
diff --git a/src/qmltest/quicktestresult_p.h b/src/qmltest/quicktestresult_p.h
index 0ef41ade29..448f2da954 100644
--- a/src/qmltest/quicktestresult_p.h
+++ b/src/qmltest/quicktestresult_p.h
@@ -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();
diff --git a/tests/auto/qmltest/pixel/tst_pixel.qml b/tests/auto/qmltest/pixel/tst_pixel.qml
index f2a9d5fdb8..dbcca4a3f5 100644
--- a/tests/auto/qmltest/pixel/tst_pixel.qml
+++ b/tests/auto/qmltest/pixel/tst_pixel.qml
@@ -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);