aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlimport
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-01-17 10:28:30 +0100
committerUlf Hermann <ulf.hermann@qt.io>2023-01-17 21:58:31 +0100
commit47e111800e3c259cc5030cf841a6d43fa43a8e97 (patch)
treee837deb87742814ecb4eb3a0fb47f1bf38c56f4b /tests/auto/qml/qqmlimport
parent727ea164943fa41b9353d33861e777264bccb1f4 (diff)
Test precedence of qmlRegisterModuleImport
The last call should take precedence over previous ones. Task-number: QTBUG-110247 Change-Id: Ib5e10ab539ea6eecc3ad66aed75c81d622e0eb01 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlimport')
-rw-r--r--tests/auto/qml/qqmlimport/tst_qqmlimport.cpp39
1 files changed, 36 insertions, 3 deletions
diff --git a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
index 06df6e6919..38970a3b99 100644
--- a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
+++ b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
@@ -431,19 +431,38 @@ void tst_QQmlImport::partialImportVersions()
}
}
+class NotItem : public QObject
+{
+ Q_OBJECT
+ QML_NAMED_ELEMENT(Item)
+};
+
void tst_QQmlImport::registerModuleImport()
{
- const auto isValid = [&]() {
+ enum Result { IsItem, IsNotItem, IsNull, IsInvalid };
+ const auto check = [&]() -> Result {
QQmlEngine engine;
engine.addImportPath(directory());
QQmlComponent component(&engine);
component.setData("import MyPluginSupported; Item {}", QUrl());
if (!component.isReady())
- return false;
+ return IsInvalid;
QScopedPointer<QObject> obj(component.create());
- return !obj.isNull();
+ if (obj.isNull())
+ return IsNull;
+ if (qobject_cast<NotItem *>(obj.data()))
+ return IsNotItem;
+ else if (qobject_cast<QQuickItem *>(obj.data()))
+ return IsItem;
+ return IsInvalid;
};
+ const auto isValid = [&]() {
+ return check() == IsItem;
+ };
+
+ qmlRegisterTypesAndRevisions<NotItem>("ShadowQuick", 1);
+
qmlRegisterModuleImport("MyPluginSupported", 2, "QtQuick");
QVERIFY(isValid());
qmlUnregisterModuleImport("MyPluginSupported", 2, "QtQuick");
@@ -470,6 +489,20 @@ void tst_QQmlImport::registerModuleImport()
QVERIFY(!isValid());
qmlUnregisterModuleImport("MyPluginSupported", 1, "QtQuick");
QVERIFY(!isValid());
+
+ qmlRegisterModuleImport("MyPluginSupported", 2, "ShadowQuick", 1);
+ qmlRegisterModuleImport("MyPluginSupported", 2, "QtQuick", 2);
+ QCOMPARE(check(), IsItem);
+
+ qmlUnregisterModuleImport("MyPluginSupported", 2, "ShadowQuick", 1);
+ qmlUnregisterModuleImport("MyPluginSupported", 2, "QtQuick", 2);
+
+ qmlRegisterModuleImport("MyPluginSupported", 2, "QtQuick", 2);
+ qmlRegisterModuleImport("MyPluginSupported", 2, "ShadowQuick", 1);
+ QCOMPARE(check(), IsNotItem);
+
+ qmlUnregisterModuleImport("MyPluginSupported", 2, "QtQuick", 2);
+ qmlUnregisterModuleImport("MyPluginSupported", 2, "ShadowQuick", 1);
}
void tst_QQmlImport::importDependenciesPrecedence()