aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2024-01-25 11:18:17 +0100
committerUlf Hermann <ulf.hermann@qt.io>2024-01-25 18:35:05 +0100
commitafbf7b699061a38b27c91d3c95890dcc1f92ebe9 (patch)
tree5bb5f222f515d25ff977d78178f533f5ff8187c1 /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
parentda6680cb2eeea4c845cffac0a0f9d24e30b1625c (diff)
QmlCompiler: Handle non-resettable undefined assignment
We need to generate an exception if undefined is assigned to a property that can't be reset. We don't want to reject everything that can potentially be undefined. Therefore, we use the QVariant fallback and examine the value for undefined at run time. Pick-to: 6.7 6.6 6.5 6.2 Change-Id: I0a034032f4522f017b452690d93319eb4bfedb1c Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp46
1 files changed, 36 insertions, 10 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 548ad20c2b..2fc5129230 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -187,7 +187,10 @@ private slots:
void registerElimination();
void registerPropagation();
void renameAdjust();
+
void resettableProperty();
+ void resettableProperty_data();
+
void returnAfterReject();
void revisions();
void scopeIdLookup();
@@ -3841,23 +3844,46 @@ void tst_QmlCppCodegen::renameAdjust()
void tst_QmlCppCodegen::resettableProperty()
{
+ QFETCH(QString, url);
+
QQmlEngine engine;
- QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/resettable.qml"_s));
+ QQmlComponent c(&engine, QUrl(url));
QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+
+ QTest::ignoreMessage(
+ QtWarningMsg, qPrintable(url + u":10:5: Unable to assign [undefined] to double"_s));
+
QScopedPointer<QObject> o(c.create());
QVERIFY(o);
- ResettableProperty *resettable = qobject_cast<ResettableProperty *>(o.data());
- QVERIFY(resettable);
+ QCOMPARE(o->property("value").toDouble(), 999);
+ QMetaObject::invokeMethod(o.data(), "doReset");
+ QCOMPARE(o->property("value").toDouble(), 0);
- QCOMPARE(resettable->value(), 999);
- QMetaObject::invokeMethod(resettable, "doReset");
- QCOMPARE(resettable->value(), 0);
+ o->setProperty("value", double(82));
+ QCOMPARE(o->property("value").toDouble(), 82);
+ QMetaObject::invokeMethod(o.data(), "doReset2");
+ QCOMPARE(o->property("value").toDouble(), 0);
- resettable->setValue(82);
- QCOMPARE(resettable->value(), 82);
- QMetaObject::invokeMethod(resettable, "doReset2");
- QCOMPARE(resettable->value(), 0);
+ QTest::ignoreMessage(
+ QtWarningMsg, qPrintable(url + u":18: Error: Cannot assign [undefined] to double"_s));
+ QCOMPARE(o->property("notResettable").toDouble(), 10);
+ QMetaObject::invokeMethod(o.data(), "doNotReset");
+ QCOMPARE(o->property("notResettable").toDouble(), 10);
+ QCOMPARE(o->property("notResettable2").toDouble(), 0); // not NaN
+
+ o->setObjectName(u"namename"_s);
+ QTest::ignoreMessage(
+ QtWarningMsg, qPrintable(url + u":22: Error: Cannot assign [undefined] to QString"_s));
+ QMetaObject::invokeMethod(o.data(), "aaa");
+ QCOMPARE(o->objectName(), u"namename"_s);
+}
+
+void tst_QmlCppCodegen::resettableProperty_data()
+{
+ QTest::addColumn<QString>("url");
+ QTest::addRow("object lookups") << u"qrc:/qt/qml/TestTypes/resettable.qml"_s;
+ QTest::addRow("fallback lookups") << u"qrc:/qt/qml/TestTypes/fallbackresettable.qml"_s;
}
void tst_QmlCppCodegen::returnAfterReject()