summaryrefslogtreecommitdiff
path: root/tests/auto
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-05-02 17:09:30 +0200
committerUlf Hermann <ulf.hermann@qt.io>2023-05-03 14:38:52 +0200
commit1abfb04fae4a347ea8a96364f682968a956779fb (patch)
tree0a080c065c4cee7d78677e73bae036e23b524b8d /tests/auto
parentc17226bf98cd0d7cdcf194a23ce6e8d20ca9a770 (diff)
downloadqtdeclarative-1abfb04fae4a347ea8a96364f682968a956779fb.tar.gz
QmlCompiler: Do not stop parsing on top-level Component elements
This just creates an inconsistent state where some of the document has been parsed and some hasn't. The only thing we actually need is the log message. Also, fix the warning message. Amends commit 169f0f71665a3a5155f8d63a9c11bc2484353561. Pick-to: 6.5 Fixes: QTBUG-112897 Change-Id: Ie8486909f9bea9ee1b87f2857f7b77fb7cc561e8 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt1
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/topLevelComponent.qml14
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp26
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp6
4 files changed, 44 insertions, 3 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
index 41c1af0286..9640500910 100644
--- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
+++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
@@ -200,6 +200,7 @@ set(qml_files
thisObject.qml
throwObjectName.qml
toString.qml
+ topLevelComponent.qml
translation.qml
trivialSignalHandler.qml
typePropagationLoop.qml
diff --git a/tests/auto/qml/qmlcppcodegen/data/topLevelComponent.qml b/tests/auto/qml/qmlcppcodegen/data/topLevelComponent.qml
new file mode 100644
index 0000000000..a73e28f642
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/topLevelComponent.qml
@@ -0,0 +1,14 @@
+pragma Strict
+import QtQml
+
+Component {
+ QtObject {
+ id: root
+
+ function myOpen() {
+ root.objectName = "foo"
+ }
+
+ Component.onCompleted: myOpen()
+ }
+}
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index e3292b52f3..0814d92429 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -184,6 +184,7 @@ private slots:
void jsArrayMethodsWithParams_data();
void jsArrayMethodsWithParams();
void shadowedMethod();
+ void topLevelComponent();
};
void tst_QmlCppCodegen::initTestCase()
@@ -3767,6 +3768,31 @@ void tst_QmlCppCodegen::shadowedMethod()
QCOMPARE(o->property("cthing"), QVariant::fromValue(u"c"_s));
}
+void tst_QmlCppCodegen::topLevelComponent()
+{
+ // TODO: Once we stop accepting top level Component elements, this test can be removed.
+
+ QQmlEngine e;
+
+ const QUrl url(u"qrc:/qt/qml/TestTypes/topLevelComponent.qml"_s);
+ QTest::ignoreMessage(
+ QtWarningMsg,
+ qPrintable(url.toString() + u":4:1: Using a Component as the root of a QML document "
+ "is deprecated: types defined in qml documents are "
+ "automatically wrapped into Components when needed."_s));
+
+ QQmlComponent c(&e, url);
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(!o.isNull());
+
+ QQmlComponent *inner = qobject_cast<QQmlComponent *>(o.data());
+ QVERIFY(inner);
+
+ QScopedPointer<QObject> o2(inner->create());
+ QCOMPARE(o2->objectName(), u"foo"_s);
+}
+
QTEST_MAIN(tst_QmlCppCodegen)
#include "tst_qmlcppcodegen.moc"
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
index 89f5258819..371179a39e 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -1388,13 +1388,13 @@ void tst_qqmllanguage::rootItemIsComponent()
QtWarningMsg,
QRegularExpression(
".*/rootItemIsComponent\\.qml:3:1: Using a Component as the root of "
- "a qmldocument is deprecated: types defined in qml documents are automatically "
- "wrapped into Components when needed\\."));
+ "a QML document is deprecated: types defined in qml documents are "
+ "automatically wrapped into Components when needed\\."));
QTest::ignoreMessage(
QtWarningMsg,
QRegularExpression(
".*/EvilComponentType\\.qml:3:1: Using a Component as the root of a "
- "qmldocument is deprecated: types defined in qml documents are automatically "
+ "QML document is deprecated: types defined in qml documents are automatically "
"wrapped into Components when needed\\."));
QTest::ignoreMessage(
QtWarningMsg,