diff options
author | Chris Adams <christopher.adams@nokia.com> | 2012-07-19 10:46:35 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-24 04:04:33 +0200 |
commit | cc688cc0cc4f5d4fc8f01411798872205df1d59c (patch) | |
tree | 7258f74e3769f598a0a22609c095a71d0d1c3fc5 /tests/auto/qml | |
parent | ec0ad9abc684604e7fbb9eb25899e95b58c0f7ad (diff) |
Fix value-type semantics in variant properties
Previously, variant properties storing value-type values would be
treated as value-type-copy values rather than value-type-reference
values. This caused inconsistency in behaviour with value-type
subproperty assignment.
Task-number: QTBUG-26562
Change-Id: I524ee06ab8e02bf9582c1a88f3317278199225e0
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests/auto/qml')
-rw-r--r-- | tests/auto/qml/qqmlvaluetypes/data/variant_write.1.qml | 25 | ||||
-rw-r--r-- | tests/auto/qml/qqmlvaluetypes/data/variant_write.2.qml | 40 | ||||
-rw-r--r-- | tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp | 22 |
3 files changed, 87 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlvaluetypes/data/variant_write.1.qml b/tests/auto/qml/qqmlvaluetypes/data/variant_write.1.qml new file mode 100644 index 0000000000..6063917dd4 --- /dev/null +++ b/tests/auto/qml/qqmlvaluetypes/data/variant_write.1.qml @@ -0,0 +1,25 @@ +import QtQuick 2.0 + +Item { + property bool complete: false + property bool success: false + + property variant v1: Qt.vector3d(1,2,3) + property variant v2: Qt.vector3d(4,5,6) + property variant v3: v1.plus(v2) // set up doomed binding + + Component.onCompleted: { + complete = false; + success = true; + + v1 = Qt.vector2d(1,2) // changing the type of the property shouldn't cause crash + + v1.x = 8; + v2.x = 9; + + if (v1 != Qt.vector2d(8,2)) success = false; + if (v2 != Qt.vector3d(9,5,6)) success = false; + + complete = true; + } +} diff --git a/tests/auto/qml/qqmlvaluetypes/data/variant_write.2.qml b/tests/auto/qml/qqmlvaluetypes/data/variant_write.2.qml new file mode 100644 index 0000000000..0dbfd2a012 --- /dev/null +++ b/tests/auto/qml/qqmlvaluetypes/data/variant_write.2.qml @@ -0,0 +1,40 @@ +import QtQuick 2.0 + +Item { + property bool complete: false + property bool success: false + + property variant v1 + + Component.onCompleted: { + complete = false; + success = true; + + // store a js reference to the VariantReference vt in a temp var. + v1 = Qt.vector3d(1,2,3) + var ref = v1; + ref.z = 5 + if (v1 != Qt.vector3d(1,2,5)) success = false; + + // now change the type of a reference, and attempt a valid write. + v1 = Qt.vector2d(1,2); + ref.x = 5; + if (v1 != Qt.vector2d(5,2)) success = false; + + // now change the type of a reference, and attempt an invalid write. + v1 = Qt.rgba(1,0,0,1); + ref.x = 5; + if (v1.toString() != Qt.rgba(1,0,0,1).toString()) success = false; + v1 = 6; + ref.x = 5; + if (v1 != 6) success = false; + + // now change the type of a reference, and attempt an invalid read. + v1 = Qt.vector3d(1,2,3); + ref = v1; + v1 = Qt.vector2d(1,2); + if (ref.z == 3) success = false; + + complete = true; + } +} diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp index af5e914290..a323db5d5f 100644 --- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp +++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp @@ -290,6 +290,7 @@ void tst_qqmlvaluetypes::sizef() void tst_qqmlvaluetypes::variant() { + { QQmlComponent component(&engine, testFileUrl("variant_read.qml")); MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create()); QVERIFY(object != 0); @@ -299,6 +300,27 @@ void tst_qqmlvaluetypes::variant() QCOMPARE(object->property("copy"), QVariant(QSizeF(0.1, 100923.2))); delete object; + } + + { + QString w1 = testFileUrl("variant_write.1.qml").toString() + QLatin1String(":9: TypeError: Object QVector2D(8, 2) has no method 'plus'"); + QTest::ignoreMessage(QtWarningMsg, qPrintable(w1)); + QQmlComponent component(&engine, testFileUrl("variant_write.1.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + QVERIFY(object->property("complete").toBool()); + QVERIFY(object->property("success").toBool()); + delete object; + } + + { + QQmlComponent component(&engine, testFileUrl("variant_write.2.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + QVERIFY(object->property("complete").toBool()); + QVERIFY(object->property("success").toBool()); + delete object; + } } void tst_qqmlvaluetypes::sizereadonly() |