diff options
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen')
9 files changed, 75 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/CMakeLists.txt index e2a939ac87..485c88c8fe 100644 --- a/tests/auto/qml/qmlcppcodegen/CMakeLists.txt +++ b/tests/auto/qml/qmlcppcodegen/CMakeLists.txt @@ -11,6 +11,8 @@ qt_internal_add_test(tst_qmlcppcodegen Qt::GuiPrivate codegen_test_module codegen_test_moduleplugin + confused_test_module + confused_test_moduleplugin ) qt_internal_add_test(tst_qmlcppcodegen_interpreted @@ -21,6 +23,8 @@ qt_internal_add_test(tst_qmlcppcodegen_interpreted Qt::GuiPrivate codegen_test_module codegen_test_moduleplugin + confused_test_module + confused_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 620818c5d6..d80783078f 100644 --- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt +++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt @@ -1,6 +1,8 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause +add_subdirectory(Confused) + set(cpp_sources ambiguous.h birthdayparty.cpp birthdayparty.h diff --git a/tests/auto/qml/qmlcppcodegen/data/Confused/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/Confused/CMakeLists.txt new file mode 100644 index 0000000000..1d03252ff9 --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/Confused/CMakeLists.txt @@ -0,0 +1,27 @@ +qt_add_library(confused_test_module STATIC) +qt_autogen_tools_initial_setup(confused_test_module) + +qt_policy(SET QTP0001 NEW) +# Not QTP0004, since we have a manually written qmldir in a strange place + +set_source_files_properties("Test/broken.js" + PROPERTIES QT_RESOURCE_ALIAS "Test/broken.qml" +) + +qt_add_qml_module(confused_test_module + URI Confused + VERSION 1.0 + QML_FILES + Main.qml + Main2.qml + Test/test.js + Test/broken.js + RESOURCES + Test/qmldir +) + +target_link_libraries(confused_test_module + PRIVATE Qt6::Qml +) + +qt_autogen_tools_initial_setup(confused_test_moduleplugin) diff --git a/tests/auto/qml/qmlcppcodegen/data/Confused/Main.qml b/tests/auto/qml/qmlcppcodegen/data/Confused/Main.qml new file mode 100644 index 0000000000..b1020610cf --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/Confused/Main.qml @@ -0,0 +1,6 @@ +import QtQml +import "Test" as T + +QtObject { + Component.onCompleted: T.Test.Print() +} diff --git a/tests/auto/qml/qmlcppcodegen/data/Confused/Main2.qml b/tests/auto/qml/qmlcppcodegen/data/Confused/Main2.qml new file mode 100644 index 0000000000..1878122b91 --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/Confused/Main2.qml @@ -0,0 +1,6 @@ +import QtQml +import "Test" as T + +QtObject { + Component.onCompleted: T.Broken.Print() +} diff --git a/tests/auto/qml/qmlcppcodegen/data/Confused/Test/broken.js b/tests/auto/qml/qmlcppcodegen/data/Confused/Test/broken.js new file mode 100644 index 0000000000..682e1d6e89 --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/Confused/Test/broken.js @@ -0,0 +1,3 @@ +.pragma library + +function Print() { console.log("Hello from Broken") } diff --git a/tests/auto/qml/qmlcppcodegen/data/Confused/Test/qmldir b/tests/auto/qml/qmlcppcodegen/data/Confused/Test/qmldir new file mode 100644 index 0000000000..5315ead60c --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/Confused/Test/qmldir @@ -0,0 +1,2 @@ +Test test.js +Broken broken.qml diff --git a/tests/auto/qml/qmlcppcodegen/data/Confused/Test/test.js b/tests/auto/qml/qmlcppcodegen/data/Confused/Test/test.js new file mode 100644 index 0000000000..b571c1657e --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/Confused/Test/test.js @@ -0,0 +1,3 @@ +.pragma library + +function Print() { console.log("Hello from Test") } diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 6a61f08986..dae83e2c86 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -21,6 +21,7 @@ using namespace Qt::StringLiterals; Q_IMPORT_QML_PLUGIN(TestTypesPlugin) +Q_IMPORT_QML_PLUGIN(ConfusedPlugin) class tst_QmlCppCodegen : public QObject { @@ -44,6 +45,7 @@ private slots: void scopedEnum(); void sequenceToIterable(); void compositeTypeMethod(); + void confusedModule(); void excessiveParameters(); void jsImport(); void jsmoduleImport(); @@ -513,6 +515,26 @@ void tst_QmlCppCodegen::compositeTypeMethod() QTRY_VERIFY(spy.size() > 0); } +void tst_QmlCppCodegen::confusedModule() +{ + QQmlEngine engine; + QQmlComponent component(&engine, QUrl(u"qrc:/qt/qml/Confused/Main.qml"_s)); + QVERIFY2(!component.isError(), component.errorString().toUtf8()); + QTest::ignoreMessage(QtDebugMsg, "Hello from Test"); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); + + QQmlComponent component2(&engine, QUrl(u"qrc:/qt/qml/Confused/Main2.qml"_s)); + QVERIFY2(!component2.isError(), component2.errorString().toUtf8()); + // TODO: We would like to have a better error here, but we currently cannot propagate it. + QTest::ignoreMessage( + QtWarningMsg, + "qrc:/qt/qml/Confused/Main2.qml:5: " + "TypeError: Property 'Print' of object [object Object] is not a function"); + QScopedPointer<QObject> object2(component2.create()); + QVERIFY(!object2.isNull()); +} + void tst_QmlCppCodegen::excessiveParameters() { QQmlEngine engine; |
