From 8203f860d1ba2c61de28dbae5f34db6601e02214 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 30 Sep 2025 08:11:48 +0200 Subject: 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 --- tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 84 +++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp') 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 #include #include +#include #include #include #include @@ -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 object(component.create()); + QVERIFY(!object.isNull()); + + QObject *a = object->property("a").value(); + QVERIFY(a); + QVERIFY(a->property("things").value().isEmpty()); + + RefuseWrite *refuse = qobject_cast(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(42.25)})); + QVERIFY(a->property("things").value().isEmpty()); + + QMetaObject::invokeMethod(object.data(), "scopeToScope"); + + QTRY_COMPARE(refuse->pendingChanges(), 0); + QCOMPARE(refuse->things(), QVariantList({ + QVariant::fromValue(0.5), + QVariant::fromValue(42.25) + })); + QVERIFY(a->property("things").value().isEmpty()); + + QMetaObject::invokeMethod(object.data(), "idToScope"); + + QTRY_COMPARE(refuse->pendingChanges(), 0); + QCOMPARE(refuse->things(), QVariantList({ + QVariant::fromValue(0.5), + QVariant::fromValue(42.25), + QVariant::fromValue(3), + })); + QVERIFY(a->property("things").value().isEmpty()); + + QMetaObject::invokeMethod(object.data(), "scopeToId"); + + QTRY_COMPARE(refuse->pendingChanges(), 0); + QCOMPARE(refuse->things(), QVariantList({ + QVariant::fromValue(0.5), + QVariant::fromValue(42.25), + QVariant::fromValue(3), + QVariant::fromValue(4), + })); + QVERIFY(a->property("things").value().isEmpty()); + + QMetaObject::invokeMethod(object.data(), "scopeToUnrelated"); + + QTRY_COMPARE(refuse->pendingChanges(), 0); + const QVariantList expected5 = QVariantList({ + QVariant::fromValue(0.5), + QVariant::fromValue(42.25), + QVariant::fromValue(3), + QVariant::fromValue(4), + QVariant::fromValue(5), + }); + QCOMPARE(refuse->things(), expected5); + QCOMPARE(a->property("things").value(), expected5); + + QMetaObject::invokeMethod(object.data(), "idToUnrelated"); + + QTRY_COMPARE(refuse->pendingChanges(), 0); + const QVariantList expected6 = QVariantList({ + QVariant::fromValue(0.5), + QVariant::fromValue(42.25), + QVariant::fromValue(3), + QVariant::fromValue(4), + QVariant::fromValue(5), + QVariant::fromValue(6), + }); + QCOMPARE(refuse->things(), expected6); + QCOMPARE(a->property("things").value(), expected6); +} + void tst_QmlCppCodegen::readEnumFromInstance() { QQmlEngine engine; -- cgit v1.2.3