aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickloader/tst_qquickloader.cpp
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2013-03-06 18:47:17 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-11 22:16:36 +0100
commit8325f2dead9b5257113d260ab673d51f8891f097 (patch)
tree2d5e14247d80923328545bd380787e45cb7dbd2e /tests/auto/quick/qquickloader/tst_qquickloader.cpp
parent457abe24baa709c55cf6d1951c7fb13400f0202e (diff)
Improve timer dependent tests.
tst_QQuickLoader::loadedSignal depended on sharing the engine with simultaneousSyncAsync and that function being run before it. After each test run call clearComponentCache() as that is important for caching of the network tests. The test server would send the item after 500ms. Sometimes the CI would be faster or slower. Instead of relying on timing, simply call a function when the reply should be sent. Change-Id: Ifb0447041197e1cba103570597a62a2510d31aab Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Diffstat (limited to 'tests/auto/quick/qquickloader/tst_qquickloader.cpp')
-rw-r--r--tests/auto/quick/qquickloader/tst_qquickloader.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/tests/auto/quick/qquickloader/tst_qquickloader.cpp b/tests/auto/quick/qquickloader/tst_qquickloader.cpp
index a28db9eaf8..d01e8aae52 100644
--- a/tests/auto/quick/qquickloader/tst_qquickloader.cpp
+++ b/tests/auto/quick/qquickloader/tst_qquickloader.cpp
@@ -52,6 +52,15 @@
#define SERVER_PORT 14458
#define SERVER_ADDR "http://localhost:14458"
+class SlowComponent : public QQmlComponent
+{
+ Q_OBJECT
+public:
+ SlowComponent() {
+ QTest::qSleep(500);
+ }
+};
+
class PeriodicIncubationController : public QObject,
public QQmlIncubationController
{
@@ -81,6 +90,8 @@ public:
tst_QQuickLoader();
private slots:
+ void cleanup();
+
void sourceOrComponent();
void sourceOrComponent_data();
void clear();
@@ -120,9 +131,15 @@ private:
QQmlEngine engine;
};
+void tst_QQuickLoader::cleanup()
+{
+ // clear components. otherwise we even bypass the test server by using the cache.
+ engine.clearComponentCache();
+}
tst_QQuickLoader::tst_QQuickLoader()
{
+ qmlRegisterType<SlowComponent>("LoaderTest", 1, 0, "SlowComponent");
}
void tst_QQuickLoader::sourceOrComponent()
@@ -462,12 +479,14 @@ void tst_QQuickLoader::networkComponent()
" Component { id: comp; NW.Rect120x60 {} }\n"
" Loader { sourceComponent: comp } }")
, dataDirectory());
+ QCOMPARE(component.status(), QQmlComponent::Loading);
+ server.sendDelayedItem();
QTRY_COMPARE(component.status(), QQmlComponent::Ready);
QQuickItem *item = qobject_cast<QQuickItem*>(component.create());
QVERIFY(item);
- QQuickLoader *loader = qobject_cast<QQuickLoader*>(item->QQuickItem::children().at(1));
+ QQuickLoader *loader = qobject_cast<QQuickLoader*>(item->children().at(1));
QVERIFY(loader);
QTRY_VERIFY(loader->status() == QQuickLoader::Ready);
@@ -1024,6 +1043,11 @@ void tst_QQuickLoader::simultaneousSyncAsync()
void tst_QQuickLoader::loadedSignal()
{
+ PeriodicIncubationController *controller = new PeriodicIncubationController;
+ QQmlIncubationController *previous = engine.incubationController();
+ engine.setIncubationController(controller);
+ delete previous;
+
{
// ensure that triggering loading (by setting active = true)
// and then immediately setting active to false, causes the
@@ -1042,8 +1066,9 @@ void tst_QQuickLoader::loadedSignal()
QVERIFY(obj->property("success").toBool());
QMetaObject::invokeMethod(obj, "triggerMultipleLoad");
+ controller->start();
QTest::qWait(100);
- QCOMPARE(obj->property("loadCount").toInt(), 1); // only one loaded signal should be emitted.
+ QTRY_COMPARE(obj->property("loadCount").toInt(), 1); // only one loaded signal should be emitted.
QVERIFY(obj->property("success").toBool());
delete obj;