From 31467e8649979d06ea2f676768016e6a147eadb9 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 6 Mar 2012 18:03:33 +1000 Subject: Allow threaded compilation in an async Loader Enables threaded compilation for a Loader "source". Change-Id: I2d60a3ace07aab58f3b8f069e45a2864178c959f Reviewed-by: Chris Adams --- tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) (limited to 'tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp') diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp index 603c091a03..10181aa9b8 100644 --- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp +++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp @@ -45,8 +45,14 @@ #include #include #include +#include +#include +#include #include #include "../../shared/util.h" +#include "testhttpserver.h" + +#define SERVER_PORT 14450 class MyIC : public QObject, public QQmlIncubationController { @@ -59,6 +65,37 @@ protected: } }; +class ComponentWatcher : public QObject +{ + Q_OBJECT +public: + ComponentWatcher(QQmlComponent *comp) : loading(0), error(0), ready(0) { + connect(comp, SIGNAL(statusChanged(QQmlComponent::Status)), + this, SLOT(statusChanged(QQmlComponent::Status))); + } + + int loading; + int error; + int ready; + +public slots: + void statusChanged(QQmlComponent::Status status) { + switch (status) { + case QQmlComponent::Loading: + ++loading; + break; + case QQmlComponent::Error: + ++error; + break; + case QQmlComponent::Ready: + ++ready; + break; + default: + break; + } + } +}; + class tst_qqmlcomponent : public QQmlDataTest { Q_OBJECT @@ -72,6 +109,8 @@ private slots: void qmlCreateObjectWithProperties(); void qmlIncubateObject(); void qmlCreateParentReference(); + void async(); + void asyncHierarchy(); private: QQmlEngine engine; @@ -213,6 +252,68 @@ void tst_qqmlcomponent::qmlCreateParentReference() QCOMPARE(warnings.count(), 0); } +void tst_qqmlcomponent::async() +{ + TestHTTPServer server(SERVER_PORT); + QVERIFY(server.isValid()); + server.serveDirectory(dataDirectory()); + + QQmlComponent component(&engine); + ComponentWatcher watcher(&component); + component.loadUrl(QUrl("http://127.0.0.1:14450/TestComponent.qml"), QQmlComponent::Asynchronous); + QCOMPARE(watcher.loading, 1); + QTRY_VERIFY(component.isReady()); + QCOMPARE(watcher.ready, 1); + QCOMPARE(watcher.error, 0); + + QObject *object = component.create(); + QVERIFY(object != 0); + + delete object; +} + +void tst_qqmlcomponent::asyncHierarchy() +{ + TestHTTPServer server(SERVER_PORT); + QVERIFY(server.isValid()); + server.serveDirectory(dataDirectory()); + + // ensure that the item hierarchy is compiled correctly. + QQmlComponent component(&engine); + ComponentWatcher watcher(&component); + component.loadUrl(QUrl("http://127.0.0.1:14450/TestComponent.2.qml"), QQmlComponent::Asynchronous); + QCOMPARE(watcher.loading, 1); + QTRY_VERIFY(component.isReady()); + QCOMPARE(watcher.ready, 1); + QCOMPARE(watcher.error, 0); + + QObject *root = component.create(); + QVERIFY(root != 0); + + // ensure that the parent-child relationship hierarchy is correct + QQuickItem *c1 = root->findChild("c1", Qt::FindDirectChildrenOnly); + QVERIFY(c1); + QQuickItem *c1c1 = c1->findChild("c1c1", Qt::FindDirectChildrenOnly); + QVERIFY(c1c1); + QQuickItem *c1c2 = c1->findChild("c1c2", Qt::FindDirectChildrenOnly); + QVERIFY(c1c2); + QQuickRectangle *c1c2c3 = c1c2->findChild("c1c2c3", Qt::FindDirectChildrenOnly); + QVERIFY(c1c2c3); + QQuickItem *c2 = root->findChild("c2", Qt::FindDirectChildrenOnly); + QVERIFY(c2); + QQuickRectangle *c2c1 = c2->findChild("c2c1", Qt::FindDirectChildrenOnly); + QVERIFY(c2c1); + QQuickMouseArea *c2c1c1 = c2c1->findChild("c2c1c1", Qt::FindDirectChildrenOnly); + QVERIFY(c2c1c1); + QQuickItem *c2c1c2 = c2c1->findChild("c2c1c2", Qt::FindDirectChildrenOnly); + QVERIFY(c2c1c2); + + // ensure that values and bindings are assigned correctly + QVERIFY(root->property("success").toBool()); + + delete root; +} + QTEST_MAIN(tst_qqmlcomponent) #include "tst_qqmlcomponent.moc" -- cgit v1.2.3