aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2021-01-11 13:07:37 +0100
committerMaximilian Goldstein <max.goldstein@qt.io>2021-01-11 15:23:24 +0100
commit2c82f4f8b61e8d7c22a979ef7ca3ea0465da278d (patch)
treefdb054f199790947cf2e6b50c630882141ab5692 /tests
parent8a3ede5ba1daf2d9314d71db972175b2791456c0 (diff)
qqmlengine: Fix crash when encountering bad singletons
Previously errors occurring when parsing QML singletons would just be ignored resulting in a crash. The errors are now properly printed and the execution is aborted in time. Fixes: QTBUG-85932 Change-Id: I61cef5f97546ce2e0753bc46c548838a21b1f506 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmllanguage/data/SingletonTest.qml14
-rw-r--r--tests/auto/qml/qqmllanguage/data/qmldir2
-rw-r--r--tests/auto/qml/qqmllanguage/data/qtbug_85932.qml5
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp22
4 files changed, 43 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/SingletonTest.qml b/tests/auto/qml/qqmllanguage/data/SingletonTest.qml
new file mode 100644
index 0000000000..70e1671754
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/SingletonTest.qml
@@ -0,0 +1,14 @@
+pragma Singleton
+
+import QtQml 2.0
+
+// This causes a duplicate id error on purpose
+QtObject {
+ id: foo
+
+ QtObject {
+ id: foo
+ }
+
+ function test() { return "Foobar"; }
+}
diff --git a/tests/auto/qml/qqmllanguage/data/qmldir b/tests/auto/qml/qqmllanguage/data/qmldir
new file mode 100644
index 0000000000..c946de657c
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/qmldir
@@ -0,0 +1,2 @@
+singleton SingletonTest 1.0 SingletonTest.qml
+
diff --git a/tests/auto/qml/qqmllanguage/data/qtbug_85932.qml b/tests/auto/qml/qqmllanguage/data/qtbug_85932.qml
new file mode 100644
index 0000000000..aa21558220
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/qtbug_85932.qml
@@ -0,0 +1,5 @@
+import QtQml 2.0
+
+QtObject {
+ Component.onCompleted: console.log(SingletonTest.test())
+}
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
index 448ecaa5b3..4f4ee45f68 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -344,6 +344,7 @@ private slots:
void extendedNamespace();
void factorySingleton();
void extendedSingleton();
+ void qtbug_85932();
private:
QQmlEngine engine;
@@ -6095,6 +6096,27 @@ void tst_qqmllanguage::extendedSingleton()
QCOMPARE(obj->property("d").toInt(), 9);
}
+void tst_qqmllanguage::qtbug_85932()
+{
+ QString warning1 = QLatin1String("%1:10:9: id is not unique").arg(testFileUrl("SingletonTest.qml").toString());
+ QString warning2 = QLatin1String("%1:4: Error: Due to the preceding error(s), Singleton \"SingletonTest\" could not be loaded.").arg(testFileUrl("qtbug_85932.qml").toString());
+
+ QTest::ignoreMessage(QtMsgType::QtWarningMsg, qPrintable(warning1));
+ QTest::ignoreMessage(QtMsgType::QtWarningMsg, qPrintable(warning2));
+
+ QQmlEngine engine;
+ QList<QQmlError> allWarnings;
+ QObject::connect(&engine, &QQmlEngine::warnings, [&allWarnings](const QList<QQmlError> &warnings) {
+ allWarnings.append(warnings);
+ });
+
+ QQmlComponent c(&engine, testFileUrl("qtbug_85932.qml"));
+ QScopedPointer<QObject> obj(c.create());
+ QTRY_COMPARE(allWarnings.count(), 2);
+ QCOMPARE(allWarnings.at(0).toString(), warning1);
+ QCOMPARE(allWarnings.at(1).toString(), warning2);
+}
+
QTEST_MAIN(tst_qqmllanguage)
#include "tst_qqmllanguage.moc"