aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2025-02-11 12:12:16 +0100
committerUlf Hermann <ulf.hermann@qt.io>2025-02-26 20:54:39 +0100
commitf7e29f7d2757e6ac577aea998f53ba6745b0e75d (patch)
treeb4e16b69fe5fc6947ef6df433ff6bdcdf54ce683 /tests/auto/qml/qmlcppcodegen
parent61043329619c2de9652c56207855217ec502c413 (diff)
QtQml: Clean up qmldir redirection
We need to perform the redirection before inserting imports into namespaces. Through the redirection we might discover a module that we have already imported before. In that case we must not import it again. Pick-to: 6.9 6.8 Fixes: QTBUG-133587 Change-Id: I47a279461763b5397137002a9e7c7d3bfc7ad15d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen')
-rw-r--r--tests/auto/qml/qmlcppcodegen/CMakeLists.txt4
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt2
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/WithSubDir/CMakeLists.txt23
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/WithSubDir/qml/GreenRect.qml6
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/WithSubDir/qml/MyScript.js2
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/multiRedirect.qml7
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp13
7 files changed, 57 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/CMakeLists.txt
index 48a89a409c..39044bd3b2 100644
--- a/tests/auto/qml/qmlcppcodegen/CMakeLists.txt
+++ b/tests/auto/qml/qmlcppcodegen/CMakeLists.txt
@@ -25,6 +25,8 @@ qt_internal_add_test(tst_qmlcppcodegen
codegen_test_stringbuilderplugin
confused_test_module
confused_test_moduleplugin
+ with_subdir_test_module
+ with_subdir_test_moduleplugin
DEFINES
QT_NO_CAST_FROM_ASCII
)
@@ -45,6 +47,8 @@ qt_internal_add_test(tst_qmlcppcodegen_interpreted
codegen_test_stringbuilderplugin
confused_test_module
confused_test_moduleplugin
+ with_subdir_test_module
+ with_subdir_test_moduleplugin
DEFINES
QT_TEST_FORCE_INTERPRETER
)
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
index d2c3707ba8..dbf750c463 100644
--- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
+++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
@@ -2,6 +2,7 @@
# SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(Confused)
+add_subdirectory(WithSubDir)
set(cpp_sources
ambiguous.h
@@ -220,6 +221,7 @@ set(qml_files
methods.qml
modulePrefix.qml
moveRegVoid.qml
+ multiRedirect.qml
multiforeign.qml
multipleCtors.qml
namespaceWithEnum.qml
diff --git a/tests/auto/qml/qmlcppcodegen/data/WithSubDir/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/WithSubDir/CMakeLists.txt
new file mode 100644
index 0000000000..a887c39283
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/WithSubDir/CMakeLists.txt
@@ -0,0 +1,23 @@
+qt_add_library(with_subdir_test_module STATIC)
+qt_autogen_tools_initial_setup(with_subdir_test_module)
+
+qt_policy(SET QTP0001 NEW)
+qt_policy(SET QTP0004 NEW)
+
+qt_add_qml_module(with_subdir_test_module
+ URI WithSubDir
+ VERSION 1.0
+ QML_FILES
+ qml/GreenRect.qml
+ qml/MyScript.js
+
+ # Hide it at compile time. Otherwise the "TestTypes" module may see it,
+ # but the "verify" module won't.
+ OUTPUT_DIRECTORY HiddenWithSubdir
+)
+
+target_link_libraries(with_subdir_test_module
+ PRIVATE Qt6::Qml
+)
+
+qt_autogen_tools_initial_setup(with_subdir_test_moduleplugin)
diff --git a/tests/auto/qml/qmlcppcodegen/data/WithSubDir/qml/GreenRect.qml b/tests/auto/qml/qmlcppcodegen/data/WithSubDir/qml/GreenRect.qml
new file mode 100644
index 0000000000..51ccd233ed
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/WithSubDir/qml/GreenRect.qml
@@ -0,0 +1,6 @@
+import QtQml
+import WithSubDir
+
+QtObject {
+ objectName: "green"
+}
diff --git a/tests/auto/qml/qmlcppcodegen/data/WithSubDir/qml/MyScript.js b/tests/auto/qml/qmlcppcodegen/data/WithSubDir/qml/MyScript.js
new file mode 100644
index 0000000000..fd59bc74fd
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/WithSubDir/qml/MyScript.js
@@ -0,0 +1,2 @@
+.pragma library
+function hello() { console.log("World") }
diff --git a/tests/auto/qml/qmlcppcodegen/data/multiRedirect.qml b/tests/auto/qml/qmlcppcodegen/data/multiRedirect.qml
new file mode 100644
index 0000000000..dab692dce0
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/multiRedirect.qml
@@ -0,0 +1,7 @@
+import QtQml
+import WithSubDir
+
+QtObject {
+ property GreenRect g: GreenRect {}
+ objectName: g.objectName
+}
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 8216bf0125..d3f917e280 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -187,6 +187,7 @@ private slots:
void multiDirectory();
void multiForeign();
void multiLookup();
+ void multiRedirect();
void multipleCtors();
void namespaceWithEnum();
void noBuiltinsImport();
@@ -3804,6 +3805,18 @@ void tst_QmlCppCodegen::multiLookup()
QCOMPARE(quitSpy.size(), 1);
}
+void tst_QmlCppCodegen::multiRedirect()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, QUrl(u"qrc:/qt/qml/TestTypes/multiRedirect.qml"_s));
+ QVERIFY2(!component.isError(), qPrintable(component.errorString()));
+
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY(!object.isNull());
+
+ QCOMPARE(object->objectName(), u"green"_s);
+}
+
void tst_QmlCppCodegen::multipleCtors()
{
QQmlEngine engine;