aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativeecmascript
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2011-11-02 10:21:37 +1000
committerQt by Nokia <qt-info@nokia.com>2011-12-01 02:40:06 +0100
commitfdbdbbdd4ff05d1ceb7667227db5b14687a77c96 (patch)
tree6f738ccc1d784a8dc18bff15cdbcb8e6973c48e8 /tests/auto/declarative/qdeclarativeecmascript
parentf304dd6fbb9d901c0a72609dc3c384eab4935f93 (diff)
Add support for assigning literal value to sequence property
It is a language semantic that we allow clients to assign a single value to a sequence/list property (assuming that the types match). Now that we support sequence types, this commit adds support for this semantic by determining whether the built-in type of the literal corresponds to the associated sequence (eg, int for QList<int>, qreal for QList<qreal>, bool for QList<bool>, QString for QStringList etc). Similarly, some value types can be constructed from literal string values (via string converters) and these need to be handled also. Task-number: QTBUG-18062 Task-number: QTBUG-21770 Change-Id: Iacd91b2af122cd8f20b7df2fa6056a7d7c52bf53 Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'tests/auto/declarative/qdeclarativeecmascript')
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.1.qml11
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.2.qml11
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.3.qml9
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.4.qml13
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.5.qml13
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.6.qml11
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp85
7 files changed, 153 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.1.qml b/tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.1.qml
new file mode 100644
index 0000000000..be283fdda1
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.1.qml
@@ -0,0 +1,11 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+MySequenceConversionObject {
+ intListProperty: [1, 2]
+ qrealListProperty: [1.1, 2.2]
+ boolListProperty: [false, true]
+ urlListProperty: [ "http://www.example1.com", "http://www.example2.com" ]
+ stringListProperty: [ "one", "two" ]
+ qstringListProperty: [ "one", "two" ]
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.2.qml
new file mode 100644
index 0000000000..c8fb28b04e
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.2.qml
@@ -0,0 +1,11 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+MySequenceConversionObject {
+ intListProperty: 1
+ qrealListProperty: 1.1
+ boolListProperty: false
+ urlListProperty: "http://www.example1.com"
+ stringListProperty: "one"
+ qstringListProperty: "two"
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.3.qml b/tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.3.qml
new file mode 100644
index 0000000000..ad8a92e317
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.3.qml
@@ -0,0 +1,9 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+MySequenceConversionObject {
+ intListProperty: 1
+ qrealListProperty: 1.1
+ boolListProperty: false
+ urlListProperty: Qt.resolvedUrl("example.html")
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.4.qml b/tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.4.qml
new file mode 100644
index 0000000000..a9f2e642d1
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.4.qml
@@ -0,0 +1,13 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+MySequenceConversionObject {
+ Component.onCompleted: {
+ intListProperty = [1, 2]
+ qrealListProperty = [1.1, 2.2]
+ boolListProperty = [false, true]
+ urlListProperty = [ "http://www.example1.com", "http://www.example2.com" ]
+ stringListProperty = [ "one", "two" ]
+ qstringListProperty = [ "one", "two" ]
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.5.qml b/tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.5.qml
new file mode 100644
index 0000000000..b8697e4290
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.5.qml
@@ -0,0 +1,13 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+MySequenceConversionObject {
+ Component.onCompleted: {
+ intListProperty = 1;
+ qrealListProperty = 1.1;
+ boolListProperty = false;
+ urlListProperty = "http://www.example1.com";
+ stringListProperty = "one";
+ qstringListProperty = "two";
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.6.qml b/tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.6.qml
new file mode 100644
index 0000000000..7a794eb694
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/assignSequenceTypes.6.qml
@@ -0,0 +1,11 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+MySequenceConversionObject {
+ Component.onCompleted: {
+ intListProperty = 1;
+ qrealListProperty = 1.1;
+ boolListProperty = false;
+ urlListProperty = Qt.resolvedUrl("example.html");
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index 3fdf1e905c..52e76614a3 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -177,8 +177,10 @@ private slots:
void sequenceConversionThreads();
void sequenceConversionBindings();
void sequenceConversionCopy();
+ void assignSequenceTypes();
void qtbug_22464();
void qtbug_21580();
+
void bug1();
void bug2();
void dynamicCreationCrash();
@@ -4320,6 +4322,89 @@ void tst_qdeclarativeecmascript::sequenceConversionCopy()
delete object;
}
+void tst_qdeclarativeecmascript::assignSequenceTypes()
+{
+ // test binding array to sequence type property
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("assignSequenceTypes.1.qml"));
+ MySequenceConversionObject *object = qobject_cast<MySequenceConversionObject *>(component.create());
+ QVERIFY(object != 0);
+ QCOMPARE(object->intListProperty(), (QList<int>() << 1 << 2));
+ QCOMPARE(object->qrealListProperty(), (QList<qreal>() << 1.1 << 2.2));
+ QCOMPARE(object->boolListProperty(), (QList<bool>() << false << true));
+ QCOMPARE(object->urlListProperty(), (QList<QUrl>() << QUrl("http://www.example1.com") << QUrl("http://www.example2.com")));
+ QCOMPARE(object->stringListProperty(), (QList<QString>() << QLatin1String("one") << QLatin1String("two")));
+ QCOMPARE(object->qstringListProperty(), (QStringList() << QLatin1String("one") << QLatin1String("two")));
+ delete object;
+ }
+
+ // test binding literal to sequence type property
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("assignSequenceTypes.2.qml"));
+ MySequenceConversionObject *object = qobject_cast<MySequenceConversionObject *>(component.create());
+ QVERIFY(object != 0);
+ QCOMPARE(object->intListProperty(), (QList<int>() << 1));
+ QCOMPARE(object->qrealListProperty(), (QList<qreal>() << 1.1));
+ QCOMPARE(object->boolListProperty(), (QList<bool>() << false));
+ QCOMPARE(object->urlListProperty(), (QList<QUrl>() << QUrl("http://www.example1.com")));
+ QCOMPARE(object->stringListProperty(), (QList<QString>() << QLatin1String("one")));
+ QCOMPARE(object->qstringListProperty(), (QStringList() << QLatin1String("two")));
+ delete object;
+ }
+
+ // test binding single value to sequence type property
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("assignSequenceTypes.3.qml"));
+ MySequenceConversionObject *object = qobject_cast<MySequenceConversionObject *>(component.create());
+ QVERIFY(object != 0);
+ QCOMPARE(object->intListProperty(), (QList<int>() << 1));
+ QCOMPARE(object->qrealListProperty(), (QList<qreal>() << 1.1));
+ QCOMPARE(object->boolListProperty(), (QList<bool>() << false));
+ QCOMPARE(object->urlListProperty(), (QList<QUrl>() << QUrl(TEST_FILE("example.html"))));
+ delete object;
+ }
+
+ // test assigning array to sequence type property in js function
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("assignSequenceTypes.4.qml"));
+ MySequenceConversionObject *object = qobject_cast<MySequenceConversionObject *>(component.create());
+ QVERIFY(object != 0);
+ QCOMPARE(object->intListProperty(), (QList<int>() << 1 << 2));
+ QCOMPARE(object->qrealListProperty(), (QList<qreal>() << 1.1 << 2.2));
+ QCOMPARE(object->boolListProperty(), (QList<bool>() << false << true));
+ QCOMPARE(object->urlListProperty(), (QList<QUrl>() << QUrl("http://www.example1.com") << QUrl("http://www.example2.com")));
+ QCOMPARE(object->stringListProperty(), (QList<QString>() << QLatin1String("one") << QLatin1String("two")));
+ QCOMPARE(object->qstringListProperty(), (QStringList() << QLatin1String("one") << QLatin1String("two")));
+ delete object;
+ }
+
+ // test assigning literal to sequence type property in js function
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("assignSequenceTypes.5.qml"));
+ MySequenceConversionObject *object = qobject_cast<MySequenceConversionObject *>(component.create());
+ QVERIFY(object != 0);
+ QCOMPARE(object->intListProperty(), (QList<int>() << 1));
+ QCOMPARE(object->qrealListProperty(), (QList<qreal>() << 1.1));
+ QCOMPARE(object->boolListProperty(), (QList<bool>() << false));
+ QCOMPARE(object->urlListProperty(), (QList<QUrl>() << QUrl("http://www.example1.com")));
+ QCOMPARE(object->stringListProperty(), (QList<QString>() << QLatin1String("one")));
+ QCOMPARE(object->qstringListProperty(), (QStringList() << QLatin1String("two")));
+ delete object;
+ }
+
+ // test assigning single value to sequence type property in js function
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("assignSequenceTypes.6.qml"));
+ MySequenceConversionObject *object = qobject_cast<MySequenceConversionObject *>(component.create());
+ QVERIFY(object != 0);
+ QCOMPARE(object->intListProperty(), (QList<int>() << 1));
+ QCOMPARE(object->qrealListProperty(), (QList<qreal>() << 1.1));
+ QCOMPARE(object->boolListProperty(), (QList<bool>() << false));
+ QCOMPARE(object->urlListProperty(), (QList<QUrl>() << QUrl(TEST_FILE("example.html"))));
+ delete object;
+ }
+}
+
// Test that assigning a null object works
// Regressed with: df1788b4dbbb2826ae63f26bdf166342595343f4
void tst_qdeclarativeecmascript::nullObjectBinding()