aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-10-18 14:07:11 +0200
committerUlf Hermann <ulf.hermann@qt.io>2023-10-23 14:23:38 +0200
commit1ba14d58ebdb5def5f48c99a67b9869bd1966ecd (patch)
tree0b507fa7a6e727404cea2e0805ae7f2984c70be2 /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
parent59f9e1dd771631345151751477cbb75926f84313 (diff)
QmlCompiler: Disallow reading enums from instances
Pick-to: 6.6 6.5 6.2 Fixes: QTBUG-118089 Change-Id: Ib98bb84159847439614341a3cbd4d34d6eabfc8a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 9b7eff5507..3496ca25dd 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -168,6 +168,7 @@ private slots:
void popContextAfterRet();
void prefixedType();
void propertyOfParent();
+ void readEnumFromInstance();
void registerElimination();
void registerPropagation();
void revisions();
@@ -3497,6 +3498,33 @@ void tst_QmlCppCodegen::propertyOfParent()
}
}
+void tst_QmlCppCodegen::readEnumFromInstance()
+{
+ QQmlEngine engine;
+
+ const QString url = u"qrc:/qt/qml/TestTypes/readEnumFromInstance.qml"_s;
+
+ QQmlComponent component(&engine, QUrl(url));
+ QVERIFY2(component.isReady(), component.errorString().toUtf8());
+
+ QTest::ignoreMessage(
+ QtWarningMsg, qPrintable(url + ":7:5: Unable to assign [undefined] to int"_L1));
+
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY(!object.isNull());
+
+ QCOMPARE(object->property("priority"), QVariant::fromValue<int>(0));
+ QCOMPARE(object->property("prop2"), QVariant::fromValue<int>(1));
+ QCOMPARE(object->property("priorityIsVeryHigh"), QVariant::fromValue<bool>(false));
+
+ QTest::ignoreMessage(
+ QtWarningMsg, qPrintable(url + ":13: Error: Cannot assign [undefined] to int"_L1));
+
+ int result = 0;
+ QMetaObject::invokeMethod(object.data(), "cyclePriority", Q_RETURN_ARG(int, result));
+ QCOMPARE(result, 0);
+}
+
void tst_QmlCppCodegen::registerElimination()
{
QQmlEngine engine;