autotest for setting parent in a component created by Loader.
authorMartin Jones <martin.jones@nokia.com>
Mon, 14 Nov 2011 03:00:31 +0000 (13:00 +1000)
committerQt by Nokia <qt-info@nokia.com>
Mon, 14 Nov 2011 05:38:57 +0000 (06:38 +0100)
Change-Id: I1b6850ce5e4a820b5ab7b2d06a877307104478a1
Reviewed-by: Alan Alpert <alan.alpert@nokia.com>
tests/auto/declarative/qquickloader/data/parented.qml [new file with mode: 0644]
tests/auto/declarative/qquickloader/tst_qquickloader.cpp

diff --git a/tests/auto/declarative/qquickloader/data/parented.qml b/tests/auto/declarative/qquickloader/data/parented.qml
new file mode 100644 (file)
index 0000000..1c19d4d
--- /dev/null
@@ -0,0 +1,21 @@
+import QtQuick 2.0
+
+Item {
+    id: root
+    width: 300; height: 300
+
+    Component {
+        id: comp
+        Rectangle {
+            objectName: "comp"
+            parent: root
+            anchors.fill: parent
+            color: "blue"
+        }
+    }
+
+    Loader {
+        width: 200; height: 200
+        sourceComponent: comp
+    }
+}
index 0096bc3..96d0d88 100644 (file)
@@ -108,6 +108,8 @@ private slots:
     void asynchronous();
     void asynchronous_clear();
 
+    void parented();
+
 private:
     QDeclarativeEngine engine;
 };
@@ -944,6 +946,23 @@ void tst_QQuickLoader::asynchronous_clear()
     QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 1);
 }
 
+void tst_QQuickLoader::parented()
+{
+    QDeclarativeComponent component(&engine, TEST_FILE("parented.qml"));
+    QQuickItem *root = qobject_cast<QQuickItem*>(component.create());
+    QVERIFY(root);
+
+    QQuickItem *item = root->findChild<QQuickItem*>("comp");
+    QVERIFY(item);
+
+    QVERIFY(item->parentItem() == root);
+
+    QCOMPARE(item->width(), 300.);
+    QCOMPARE(item->height(), 300.);
+
+    delete root;
+}
+
 
 QTEST_MAIN(tst_QQuickLoader)