aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlvaluetypes
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qqmlvaluetypes')
-rw-r--r--tests/auto/qml/qqmlvaluetypes/data/bindingAssignment.2.qml12
-rw-r--r--tests/auto/qml/qqmlvaluetypes/data/bindingAssignment.qml5
-rw-r--r--tests/auto/qml/qqmlvaluetypes/qqmlvaluetypes.pro2
-rw-r--r--tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp36
4 files changed, 46 insertions, 9 deletions
diff --git a/tests/auto/qml/qqmlvaluetypes/data/bindingAssignment.2.qml b/tests/auto/qml/qqmlvaluetypes/data/bindingAssignment.2.qml
new file mode 100644
index 0000000000..0da717ba5c
--- /dev/null
+++ b/tests/auto/qml/qqmlvaluetypes/data/bindingAssignment.2.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.0
+import Test 1.0
+
+MyTypeObject {
+ property int value: 10
+ rect.y: Qt.binding(function() { return value; }); // error.
+
+ Component.onCompleted: {
+ rect.x = 5;
+ rect.x = (function() { return value; }); // error.
+ }
+}
diff --git a/tests/auto/qml/qqmlvaluetypes/data/bindingAssignment.qml b/tests/auto/qml/qqmlvaluetypes/data/bindingAssignment.qml
index a65218669b..9b10803649 100644
--- a/tests/auto/qml/qqmlvaluetypes/data/bindingAssignment.qml
+++ b/tests/auto/qml/qqmlvaluetypes/data/bindingAssignment.qml
@@ -1,7 +1,12 @@
+import QtQuick 2.0
import Test 1.0
MyTypeObject {
property int value: 10
rect.x: value
+
+ Component.onCompleted: {
+ rect.y = Qt.binding(function() { return value + 5; });
+ }
}
diff --git a/tests/auto/qml/qqmlvaluetypes/qqmlvaluetypes.pro b/tests/auto/qml/qqmlvaluetypes/qqmlvaluetypes.pro
index 9155cbee96..8d9acb65b3 100644
--- a/tests/auto/qml/qqmlvaluetypes/qqmlvaluetypes.pro
+++ b/tests/auto/qml/qqmlvaluetypes/qqmlvaluetypes.pro
@@ -13,4 +13,4 @@ TESTDATA = data/*
CONFIG += parallel_test
-QT += core-private gui-private v8-private qml-private testlib
+QT += core-private gui-private v8-private qml-private quick-private gui testlib
diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
index 0aa223e733..359653caa4 100644
--- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
+++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
@@ -43,12 +43,12 @@
#include <QQmlEngine>
#include <QQmlComponent>
#include <QDebug>
-#include <private/qqmlvaluetype_p.h>
+#include <private/qquickvaluetypes_p.h>
#include "../../shared/util.h"
#include "testtypes.h"
QT_BEGIN_NAMESPACE
-extern int qt_defaultDpi();
+extern int qt_defaultDpi(void);
QT_END_NAMESPACE
class tst_qqmlvaluetypes : public QQmlDataTest
@@ -871,17 +871,37 @@ void tst_qqmlvaluetypes::color()
// Test bindings can write to value types
void tst_qqmlvaluetypes::bindingAssignment()
{
+ // binding declaration
+ {
QQmlComponent component(&engine, testFileUrl("bindingAssignment.qml"));
MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
QVERIFY(object != 0);
QCOMPARE(object->rect().x(), 10);
+ QCOMPARE(object->rect().y(), 15);
object->setProperty("value", QVariant(92));
QCOMPARE(object->rect().x(), 92);
+ QCOMPARE(object->rect().y(), 97);
delete object;
+ }
+
+ // function assignment should fail without crashing
+ {
+ QString warning1 = testFileUrl("bindingAssignment.2.qml").toString() + QLatin1String(":6:13: Invalid use of Qt.binding() in a binding declaration.");
+ QString warning2 = testFileUrl("bindingAssignment.2.qml").toString() + QLatin1String(":10: Error: Cannot assign JavaScript function to value-type property");
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
+ QQmlComponent component(&engine, testFileUrl("bindingAssignment.2.qml"));
+ MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
+ QVERIFY(object != 0);
+ QCOMPARE(object->rect().x(), 5);
+ object->setProperty("value", QVariant(92));
+ QCOMPARE(object->rect().x(), 5);
+ delete object;
+ }
}
// Test bindings can read from value types
@@ -1109,13 +1129,13 @@ void tst_qqmlvaluetypes::cppClasses()
CPP_TEST(QQmlSizeFValueType, QSizeF(-100.7, 18.2));
CPP_TEST(QQmlRectValueType, QRect(13, 39, 10928, 88));
CPP_TEST(QQmlRectFValueType, QRectF(88.2, -90.1, 103.2, 118));
- CPP_TEST(QQmlVector2DValueType, QVector2D(19.7, 1002));
- CPP_TEST(QQmlVector3DValueType, QVector3D(18.2, 19.7, 1002));
- CPP_TEST(QQmlVector4DValueType, QVector4D(18.2, 19.7, 1002, 54));
- CPP_TEST(QQmlQuaternionValueType, QQuaternion(18.2, 19.7, 1002, 54));
- CPP_TEST(QQmlMatrix4x4ValueType,
+ CPP_TEST(QQuickVector2DValueType, QVector2D(19.7, 1002));
+ CPP_TEST(QQuickVector3DValueType, QVector3D(18.2, 19.7, 1002));
+ CPP_TEST(QQuickVector4DValueType, QVector4D(18.2, 19.7, 1002, 54));
+ CPP_TEST(QQuickQuaternionValueType, QQuaternion(18.2, 19.7, 1002, 54));
+ CPP_TEST(QQuickMatrix4x4ValueType,
QMatrix4x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16));
- CPP_TEST(QQmlFontValueType, QFont("Helvetica"));
+ CPP_TEST(QQuickFontValueType, QFont("Helvetica"));
}