aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2025-09-30 08:11:48 +0200
committerUlf Hermann <ulf.hermann@qt.io>2025-10-06 13:21:01 +0200
commit8203f860d1ba2c61de28dbae5f34db6601e02214 (patch)
treecf56da643caf8630cb651063458fcf06c2c17164 /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
parent5d29d63e77af7129e67c5bce6dfddaf5cf266ed0 (diff)
QtQml: Add test for writing to delayed properties
This proves that commit a7349e6433d092398d76cafa5408753f06892cd7 fixes QTBUG-139687. Pick-to: 6.10 6.8 Fixes: QTBUG-139687 Change-Id: I2730b545738bf75e381b0b396b74c5060fa9b0e1 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp84
1 files changed, 83 insertions, 1 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 43b6e99f73..884372bfa4 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -11,6 +11,7 @@
#include <data/listprovider.h>
#include <data/objectwithmethod.h>
#include <data/qmlusing.h>
+#include <data/refuseWrite.h>
#include <data/resettable.h>
#include <data/sequenceToIterable.h>
#include <data/takenumber.h>
@@ -234,9 +235,10 @@ private slots:
void propertyOfParent();
void qmlUsing();
void qtfont();
- void reduceWithNullThis();
void readEnumFromInstance();
void readonlyListProperty();
+ void reduceWithNullThis();
+ void refuseWrite();
void registerElimination();
void registerPropagation();
void renameAdjust();
@@ -4991,6 +4993,86 @@ void tst_QmlCppCodegen::reduceWithNullThis()
QCOMPARE(object->property("preferredHeight2").toDouble(), 28.0);
}
+void tst_QmlCppCodegen::refuseWrite()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, QUrl(u"qrc:/qt/qml/TestTypes/writeBackReferenceObject.qml"_s));
+ QVERIFY2(component.isReady(), qPrintable(component.errorString()));
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY(!object.isNull());
+
+ QObject *a = object->property("a").value<QObject*>();
+ QVERIFY(a);
+ QVERIFY(a->property("things").value<QVariantList>().isEmpty());
+
+ RefuseWrite *refuse = qobject_cast<RefuseWrite *>(object.data());
+ QVERIFY(refuse->things().isEmpty());
+ QCOMPARE(refuse->pendingChanges(), 0);
+
+ QMetaObject::invokeMethod(object.data(), "idToId");
+
+ QTRY_COMPARE(refuse->pendingChanges(), 0);
+ QCOMPARE(refuse->things(), QVariantList({QVariant(), QVariant::fromValue<double>(42.25)}));
+ QVERIFY(a->property("things").value<QVariantList>().isEmpty());
+
+ QMetaObject::invokeMethod(object.data(), "scopeToScope");
+
+ QTRY_COMPARE(refuse->pendingChanges(), 0);
+ QCOMPARE(refuse->things(), QVariantList({
+ QVariant::fromValue<double>(0.5),
+ QVariant::fromValue<double>(42.25)
+ }));
+ QVERIFY(a->property("things").value<QVariantList>().isEmpty());
+
+ QMetaObject::invokeMethod(object.data(), "idToScope");
+
+ QTRY_COMPARE(refuse->pendingChanges(), 0);
+ QCOMPARE(refuse->things(), QVariantList({
+ QVariant::fromValue<double>(0.5),
+ QVariant::fromValue<double>(42.25),
+ QVariant::fromValue<double>(3),
+ }));
+ QVERIFY(a->property("things").value<QVariantList>().isEmpty());
+
+ QMetaObject::invokeMethod(object.data(), "scopeToId");
+
+ QTRY_COMPARE(refuse->pendingChanges(), 0);
+ QCOMPARE(refuse->things(), QVariantList({
+ QVariant::fromValue<double>(0.5),
+ QVariant::fromValue<double>(42.25),
+ QVariant::fromValue<double>(3),
+ QVariant::fromValue<double>(4),
+ }));
+ QVERIFY(a->property("things").value<QVariantList>().isEmpty());
+
+ QMetaObject::invokeMethod(object.data(), "scopeToUnrelated");
+
+ QTRY_COMPARE(refuse->pendingChanges(), 0);
+ const QVariantList expected5 = QVariantList({
+ QVariant::fromValue<double>(0.5),
+ QVariant::fromValue<double>(42.25),
+ QVariant::fromValue<double>(3),
+ QVariant::fromValue<double>(4),
+ QVariant::fromValue<double>(5),
+ });
+ QCOMPARE(refuse->things(), expected5);
+ QCOMPARE(a->property("things").value<QVariantList>(), expected5);
+
+ QMetaObject::invokeMethod(object.data(), "idToUnrelated");
+
+ QTRY_COMPARE(refuse->pendingChanges(), 0);
+ const QVariantList expected6 = QVariantList({
+ QVariant::fromValue<double>(0.5),
+ QVariant::fromValue<double>(42.25),
+ QVariant::fromValue<double>(3),
+ QVariant::fromValue<double>(4),
+ QVariant::fromValue<double>(5),
+ QVariant::fromValue<double>(6),
+ });
+ QCOMPARE(refuse->things(), expected6);
+ QCOMPARE(a->property("things").value<QVariantList>(), expected6);
+}
+
void tst_QmlCppCodegen::readEnumFromInstance()
{
QQmlEngine engine;