aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlcomponent/data
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2012-04-19 17:30:59 +1000
committerQt by Nokia <qt-info@nokia.com>2012-04-23 02:05:22 +0200
commit6d2ed5d0b645f5af383a123e869d061b235b4b85 (patch)
tree72034ba88aff417ece70cc3d57e73c50b4a900bb /tests/auto/qml/qqmlcomponent/data
parentb86b3bb0f44cdbdb21413b967be67d37b7fefa64 (diff)
Add some component path canonicalization tests
Previously, no unit test existed to ensure that url canonicalization worked correctly, which could result in two import statements using relative paths to the same actual component triggering two separate types being generated. This commit adds a unit test with various relative-addressing and both static and dynamic imports, to enforce type-consistency. Change-Id: I7772e3c531069322d5fa44063cbf57a758ed3710 Reviewed-by: Matthew Vogt <matthew.vogt@nokia.com>
Diffstat (limited to 'tests/auto/qml/qqmlcomponent/data')
-rw-r--r--tests/auto/qml/qqmlcomponent/data/NestedDirectories/NDTLC.qml23
-rw-r--r--tests/auto/qml/qqmlcomponent/data/NestedDirectories/NestedDirOne/NDComponentOne.qml9
-rw-r--r--tests/auto/qml/qqmlcomponent/data/NestedDirectories/NestedDirOne/NestedDirTwo/NDComponentTwo.qml6
-rw-r--r--tests/auto/qml/qqmlcomponent/data/NestedDirectories/NestedDirOne/NestedDirTwo/qmldir1
-rw-r--r--tests/auto/qml/qqmlcomponent/data/NestedDirectories/NestedDirOne/qmldir1
-rw-r--r--tests/auto/qml/qqmlcomponent/data/NestedDirectories/qmldir1
-rw-r--r--tests/auto/qml/qqmlcomponent/data/OtherComponent/OtherComponent.qml6
-rw-r--r--tests/auto/qml/qqmlcomponent/data/OtherComponent/qmldir1
-rw-r--r--tests/auto/qml/qqmlcomponent/data/SpecificComponent/SpecificComponent.qml7
-rw-r--r--tests/auto/qml/qqmlcomponent/data/SpecificComponent/qmldir1
-rw-r--r--tests/auto/qml/qqmlcomponent/data/componentUrlCanonicalization.2.qml24
-rw-r--r--tests/auto/qml/qqmlcomponent/data/componentUrlCanonicalization.3.qml53
-rw-r--r--tests/auto/qml/qqmlcomponent/data/componentUrlCanonicalization.qml31
13 files changed, 164 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlcomponent/data/NestedDirectories/NDTLC.qml b/tests/auto/qml/qqmlcomponent/data/NestedDirectories/NDTLC.qml
new file mode 100644
index 0000000000..b966cb30d1
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/NestedDirectories/NDTLC.qml
@@ -0,0 +1,23 @@
+import QtQuick 2.0
+import "NestedDirOne"
+import "NestedDirOne/NestedDirTwo/../../../SpecificComponent"
+
+// NestedDirectoriesTopLevelComponent
+
+Item {
+ id: ndtlcId
+ property NDComponentOne a: NDComponentOne { }
+ property NDComponentOne b: NDComponentOne { }
+ property SpecificComponent scOne: SpecificComponent { }
+ property SpecificComponent scTwo
+
+ function assignScTwo() {
+ // It seems that doing this in onCompleted doesn't work,
+ // since that handler will be evaluated after the
+ // componentUrlCanonicalization.3.qml onCompleted handler.
+ // So, call this function manually....
+ var c1 = Qt.createComponent("NestedDirOne/NestedDirTwo/NDComponentTwo.qml");
+ var o1 = c1.createObject(ndtlcId);
+ scTwo = o1.sc;
+ }
+}
diff --git a/tests/auto/qml/qqmlcomponent/data/NestedDirectories/NestedDirOne/NDComponentOne.qml b/tests/auto/qml/qqmlcomponent/data/NestedDirectories/NestedDirOne/NDComponentOne.qml
new file mode 100644
index 0000000000..2cfcd47737
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/NestedDirectories/NestedDirOne/NDComponentOne.qml
@@ -0,0 +1,9 @@
+import QtQuick 2.0
+import "../../SpecificComponent"
+import "NestedDirTwo"
+
+Item {
+ property int a
+ property NDComponentTwo b: NDComponentTwo { }
+ property SpecificComponent sc: SpecificComponent { }
+}
diff --git a/tests/auto/qml/qqmlcomponent/data/NestedDirectories/NestedDirOne/NestedDirTwo/NDComponentTwo.qml b/tests/auto/qml/qqmlcomponent/data/NestedDirectories/NestedDirOne/NestedDirTwo/NDComponentTwo.qml
new file mode 100644
index 0000000000..d2df36adc4
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/NestedDirectories/NestedDirOne/NestedDirTwo/NDComponentTwo.qml
@@ -0,0 +1,6 @@
+import QtQuick 2.0
+import "../../../SpecificComponent"
+
+Item {
+ property SpecificComponent sc: SpecificComponent { }
+}
diff --git a/tests/auto/qml/qqmlcomponent/data/NestedDirectories/NestedDirOne/NestedDirTwo/qmldir b/tests/auto/qml/qqmlcomponent/data/NestedDirectories/NestedDirOne/NestedDirTwo/qmldir
new file mode 100644
index 0000000000..11c6fdd311
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/NestedDirectories/NestedDirOne/NestedDirTwo/qmldir
@@ -0,0 +1 @@
+NDComponentTwo 1.0 NDComponentTwo.qml
diff --git a/tests/auto/qml/qqmlcomponent/data/NestedDirectories/NestedDirOne/qmldir b/tests/auto/qml/qqmlcomponent/data/NestedDirectories/NestedDirOne/qmldir
new file mode 100644
index 0000000000..5ef4d13c15
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/NestedDirectories/NestedDirOne/qmldir
@@ -0,0 +1 @@
+NDComponentOne 1.0 NDComponentOne.qml
diff --git a/tests/auto/qml/qqmlcomponent/data/NestedDirectories/qmldir b/tests/auto/qml/qqmlcomponent/data/NestedDirectories/qmldir
new file mode 100644
index 0000000000..adb0fdcbae
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/NestedDirectories/qmldir
@@ -0,0 +1 @@
+NDTLC 1.0 NDTLC.qml
diff --git a/tests/auto/qml/qqmlcomponent/data/OtherComponent/OtherComponent.qml b/tests/auto/qml/qqmlcomponent/data/OtherComponent/OtherComponent.qml
new file mode 100644
index 0000000000..0b6623d467
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/OtherComponent/OtherComponent.qml
@@ -0,0 +1,6 @@
+import QtQuick 2.0
+import "../SpecificComponent"
+
+Item {
+ property SpecificComponent sc: SpecificComponent { }
+}
diff --git a/tests/auto/qml/qqmlcomponent/data/OtherComponent/qmldir b/tests/auto/qml/qqmlcomponent/data/OtherComponent/qmldir
new file mode 100644
index 0000000000..c592dc6ff0
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/OtherComponent/qmldir
@@ -0,0 +1 @@
+OtherComponent 1.0 OtherComponent.qml
diff --git a/tests/auto/qml/qqmlcomponent/data/SpecificComponent/SpecificComponent.qml b/tests/auto/qml/qqmlcomponent/data/SpecificComponent/SpecificComponent.qml
new file mode 100644
index 0000000000..0086737970
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/SpecificComponent/SpecificComponent.qml
@@ -0,0 +1,7 @@
+import QtQuick 2.0
+
+Item {
+ // ensure we have a dynamic meta object
+ property int someInt: 5
+ property var someVar: 12
+}
diff --git a/tests/auto/qml/qqmlcomponent/data/SpecificComponent/qmldir b/tests/auto/qml/qqmlcomponent/data/SpecificComponent/qmldir
new file mode 100644
index 0000000000..1f961788be
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/SpecificComponent/qmldir
@@ -0,0 +1 @@
+SpecificComponent 1.0 SpecificComponent.qml
diff --git a/tests/auto/qml/qqmlcomponent/data/componentUrlCanonicalization.2.qml b/tests/auto/qml/qqmlcomponent/data/componentUrlCanonicalization.2.qml
new file mode 100644
index 0000000000..2e2d2de400
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/componentUrlCanonicalization.2.qml
@@ -0,0 +1,24 @@
+import QtQuick 2.0
+import "SpecificComponent"
+
+Item {
+ id: root
+ property SpecificComponent first
+ property SpecificComponent second
+
+ property bool success: false
+
+ Component.onCompleted: {
+ var c1 = Qt.createComponent("./SpecificComponent/SpecificComponent.qml");
+ var o1 = c1.createObject(root);
+ first = o1;
+
+ var c2 = Qt.createComponent("./OtherComponent/OtherComponent.qml");
+ var o2 = c2.createObject(root);
+ second = o2.sc;
+
+ var ft = first.toString().substr(0, first.toString().indexOf('('));
+ var st = second.toString().substr(0, second.toString().indexOf('('));
+ if (ft == st) success = true;
+ }
+}
diff --git a/tests/auto/qml/qqmlcomponent/data/componentUrlCanonicalization.3.qml b/tests/auto/qml/qqmlcomponent/data/componentUrlCanonicalization.3.qml
new file mode 100644
index 0000000000..b520b7d0ec
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/componentUrlCanonicalization.3.qml
@@ -0,0 +1,53 @@
+import QtQuick 2.0
+import "SpecificComponent"
+import "OtherComponent"
+import "NestedDirectories"
+
+Item {
+ id: root
+
+ property SpecificComponent scOne
+ property SpecificComponent scTwo
+ property SpecificComponent scThree
+ property SpecificComponent scFour
+ property SpecificComponent scFive
+ property SpecificComponent scSix
+ property SpecificComponent scSeven
+ property SpecificComponent scEight
+
+ property OtherComponent ocOne: OtherComponent { }
+ property NDTLC ndtlc: NDTLC { }
+
+ property bool success: false
+
+ Component.onCompleted: {
+ var c1 = Qt.createComponent("./SpecificComponent/SpecificComponent.qml");
+ var o1 = c1.createObject(root);
+ scOne = o1;
+ scTwo = ocOne.sc;
+ scThree = ndtlc.a.sc;
+ scFour = ndtlc.b.sc;
+ scFive = ndtlc.a.b.sc;
+ scSix = ndtlc.b.b.sc;
+ scSeven = ndtlc.scOne;
+ ndtlc.assignScTwo(); // XXX should be able to do this in NDTLC.onCompleted handler?!
+ scEight = ndtlc.scTwo;
+
+ // in our case, the type string should be:
+ // SpecificComponent_QMLTYPE_0
+ var t1 = scOne.toString().substr(0, scOne.toString().indexOf('('));
+ var t2 = scTwo.toString().substr(0, scTwo.toString().indexOf('('));
+ var t3 = scThree.toString().substr(0, scThree.toString().indexOf('('));
+ var t4 = scFour.toString().substr(0, scFour.toString().indexOf('('));
+ var t5 = scFive.toString().substr(0, scFive.toString().indexOf('('));
+ var t6 = scSix.toString().substr(0, scSix.toString().indexOf('('));
+ var t7 = scSeven.toString().substr(0, scSeven.toString().indexOf('('));
+ var t8 = scEight.toString().substr(0, scEight.toString().indexOf('('));
+
+ if (t1 == t2 && t2 == t3 && t3 == t4 && t4 == t5 && t5 == t6 && t6 == t7 && t7 == t8) {
+ success = true;
+ } else {
+ success = false;
+ }
+ }
+}
diff --git a/tests/auto/qml/qqmlcomponent/data/componentUrlCanonicalization.qml b/tests/auto/qml/qqmlcomponent/data/componentUrlCanonicalization.qml
new file mode 100644
index 0000000000..ad4cbbd2a9
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/componentUrlCanonicalization.qml
@@ -0,0 +1,31 @@
+import QtQuick 2.0
+import "SpecificComponent"
+import "OtherComponent"
+
+Item {
+ id: root
+ property SpecificComponent first
+ property SpecificComponent second
+ property OtherComponent oc: OtherComponent { }
+
+ property bool success: false
+
+ Component.onCompleted: {
+ var c1 = Qt.createComponent("./SpecificComponent/SpecificComponent.qml");
+ var o1 = c1.createObject(root);
+ first = o1;
+ second = oc.sc;
+
+ // We want to ensure that the types are the same, ie, that the
+ // component hasn't been registered twice due to failed
+ // canonicalization of the component path when importing.
+ // The type is reported in the toString() output prior to the
+ // instance pointer value.
+
+ // in our case, the type string should be:
+ // SpecificComponent_QMLTYPE_0
+ var ft = first.toString().substr(0, first.toString().indexOf('('));
+ var st = second.toString().substr(0, second.toString().indexOf('('));
+ if (ft == st) success = true;
+ }
+}