diff options
Diffstat (limited to 'tests/auto/quick/qquickloader/tst_qquickloader.cpp')
-rw-r--r-- | tests/auto/quick/qquickloader/tst_qquickloader.cpp | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/tests/auto/quick/qquickloader/tst_qquickloader.cpp b/tests/auto/quick/qquickloader/tst_qquickloader.cpp index a28db9eaf8..50ded4d95a 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(); @@ -115,14 +126,21 @@ private slots: void parented(); void sizeBound(); + void QTBUG_30183(); 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 +480,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 +1044,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 +1067,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; @@ -1101,6 +1127,22 @@ void tst_QQuickLoader::sizeBound() delete root; } +void tst_QQuickLoader::QTBUG_30183() +{ + QQmlComponent component(&engine, testFileUrl("/QTBUG_30183.qml")); + QQuickLoader *loader = qobject_cast<QQuickLoader*>(component.create()); + QVERIFY(loader != 0); + QCOMPARE(loader->width(), 240.0); + QCOMPARE(loader->height(), 120.0); + + // the loaded item must follow the size + QQuickItem *rect = qobject_cast<QQuickItem*>(loader->item()); + QVERIFY(rect); + QCOMPARE(rect->width(), 240.0); + QCOMPARE(rect->height(), 120.0); + + delete loader; +} QTEST_MAIN(tst_QQuickLoader) |