aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlimport
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-06-04 15:47:50 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-06-11 18:06:53 +0200
commit8311d0135ed27b457144bfa0b9587f12cf17b364 (patch)
treeb96fc9e18cd9ca9864cfb118a37887d7b15bc5db /tests/auto/qml/qqmlimport
parent11a09e212877988d37416842ad73d9aa357ba51f (diff)
QML: Fix precedence of module imports
Types imported transitively via a qmldir import statement should not shadow types available from the module itself. Change-Id: Id34edc5c5e2fff4ba37009f4bab9039b7ed18dff Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlimport')
-rw-r--r--tests/auto/qml/qqmlimport/data/A/Child.qml5
-rw-r--r--tests/auto/qml/qqmlimport/data/A/qmldir3
-rw-r--r--tests/auto/qml/qqmlimport/data/B/Child.qml5
-rw-r--r--tests/auto/qml/qqmlimport/data/B/qmldir3
-rw-r--r--tests/auto/qml/qqmlimport/data/dependencies.qml12
-rw-r--r--tests/auto/qml/qqmlimport/tst_qqmlimport.cpp15
6 files changed, 43 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlimport/data/A/Child.qml b/tests/auto/qml/qqmlimport/data/A/Child.qml
new file mode 100644
index 0000000000..d1713ba804
--- /dev/null
+++ b/tests/auto/qml/qqmlimport/data/A/Child.qml
@@ -0,0 +1,5 @@
+import QtQml
+
+QtObject {
+ objectName: "a"
+}
diff --git a/tests/auto/qml/qqmlimport/data/A/qmldir b/tests/auto/qml/qqmlimport/data/A/qmldir
new file mode 100644
index 0000000000..7488570377
--- /dev/null
+++ b/tests/auto/qml/qqmlimport/data/A/qmldir
@@ -0,0 +1,3 @@
+module A
+Child 1.0 Child.qml
+import B
diff --git a/tests/auto/qml/qqmlimport/data/B/Child.qml b/tests/auto/qml/qqmlimport/data/B/Child.qml
new file mode 100644
index 0000000000..587c996b7e
--- /dev/null
+++ b/tests/auto/qml/qqmlimport/data/B/Child.qml
@@ -0,0 +1,5 @@
+import QtQml
+
+QtObject {
+ objectName: "b"
+}
diff --git a/tests/auto/qml/qqmlimport/data/B/qmldir b/tests/auto/qml/qqmlimport/data/B/qmldir
new file mode 100644
index 0000000000..595583a2a3
--- /dev/null
+++ b/tests/auto/qml/qqmlimport/data/B/qmldir
@@ -0,0 +1,3 @@
+module B
+Child 1.0 Child.qml
+ChildB 1.0 Child.qml
diff --git a/tests/auto/qml/qqmlimport/data/dependencies.qml b/tests/auto/qml/qqmlimport/data/dependencies.qml
new file mode 100644
index 0000000000..e6cf51e467
--- /dev/null
+++ b/tests/auto/qml/qqmlimport/data/dependencies.qml
@@ -0,0 +1,12 @@
+import QtQml
+import A
+
+QtObject {
+ // Type Child imported from A takes precedence over type Child indirectly imported from B.
+ property QtObject childA: Child {}
+ property string a: childA.objectName
+
+ // ChildB only exists in B.
+ property QtObject childB: ChildB {}
+ property string b: childB.objectName
+}
diff --git a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
index 316c4cb168..ac21a2fac6 100644
--- a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
+++ b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
@@ -52,6 +52,7 @@ private slots:
void partialImportVersions_data();
void partialImportVersions();
void registerModuleImport();
+ void importDependenciesPrecedence();
void cleanup();
void envResourceImportPath();
};
@@ -388,6 +389,20 @@ void tst_QQmlImport::registerModuleImport()
}
}
+void tst_QQmlImport::importDependenciesPrecedence()
+{
+ QQmlEngine engine;
+ engine.addImportPath(dataDirectory());
+
+ QQmlComponent component(&engine, testFile("dependencies.qml"));
+ QVERIFY(component.isReady());
+
+ QScopedPointer<QObject> instance(component.create());
+ QVERIFY(!instance.isNull());
+ QCOMPARE(instance->property("a").toString(), QString::fromLatin1("a"));
+ QCOMPARE(instance->property("b").toString(), QString::fromLatin1("b"));
+}
+
QTEST_MAIN(tst_QQmlImport)