aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativeecmascript/data
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2011-10-03 10:52:38 +1000
committerQt by Nokia <qt-info@nokia.com>2011-11-02 01:17:09 +0100
commitc177691118e4e2bace9b5c1f4f57343190e6ad64 (patch)
treeb177efd1493e33dc28c57b5a2980fd020b3c9395 /tests/auto/declarative/qdeclarativeecmascript/data
parent9dd6d4e9b8f7c2df6369c336b429bc965a2697d4 (diff)
Add support for more sequence types
This commit adds support for more sequence types by adding a sequence wrapper. This class enables conversion between v8::Array and C++ sequences of various types (currently just QList<int>, QList<qreal>, QList<bool>, QList<QString>, QList<QUrl> and QStringList), but more types can be added later if required). When a JavaScript object is created from such a sequence, its prototype object is set to the v8::Array prototype object. The indexed setter, indexed getter, length and toString methods are implemented directly or in terms of the underlying sequence resource. Note that currently, sequences of ValueTypes are NOT supported, due to the fact that operations like: someObj.someValueTypeSequence[i].x = 5; would not behave as required. Task-number: QTBUG-20826 Task-number: QTBUG-21770 Change-Id: I36deb448fb0e87a32084a900e70a2604ff369309 Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Diffstat (limited to 'tests/auto/declarative/qdeclarativeecmascript/data')
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/SequenceConversionComponent.qml7
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.array.qml152
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.bindings.error.qml19
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.bindings.qml28
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.copy.qml160
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.read.error.qml21
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.read.qml105
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.threads.qml69
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.write.error.qml18
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.write.qml109
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/threadScript.js4
11 files changed, 692 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/SequenceConversionComponent.qml b/tests/auto/declarative/qdeclarativeecmascript/data/SequenceConversionComponent.qml
new file mode 100644
index 0000000000..0c7f60b062
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/SequenceConversionComponent.qml
@@ -0,0 +1,7 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+MySequenceConversionObject {
+ id: sccmsco
+ objectName: "sccmsco"
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.array.qml b/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.array.qml
new file mode 100644
index 0000000000..5eaa225708
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.array.qml
@@ -0,0 +1,152 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+Item {
+ id: root
+ objectName: "root"
+
+ MySequenceConversionObject {
+ id: msco
+ objectName: "msco"
+ }
+
+ property bool success: false
+
+ property variant intList
+ property variant qrealList
+ property variant boolList
+ property variant stringList
+
+ function indexedAccess() {
+ intList = msco.intListProperty;
+ var jsIntList = msco.intListProperty;
+ qrealList = msco.qrealListProperty;
+ var jsQrealList = msco.qrealListProperty;
+ boolList = msco.boolListProperty;
+ var jsBoolList = msco.boolListProperty;
+ stringList = msco.stringListProperty;
+ var jsStringList = msco.stringListProperty;
+
+ // Three cases: direct property modification, variant copy modification, js var reference modification.
+ // Only the first and third should "write back" to the original QObject Q_PROPERTY; the second one
+ // should have no effect whatsoever to maintain "property variant" semantics (see e.g., valuetype).
+ success = true;
+
+ msco.intListProperty[1] = 33;
+ if (msco.intListProperty[1] != 33) success = false; // ensure write back
+ intList[1] = 44;
+ if (intList[1] == 44) success = false; // ensure no effect
+ jsIntList[1] = 55;
+ if (jsIntList[1] != 55
+ || jsIntList[1] != msco.intListProperty[1]) success = false; // ensure write back
+
+ msco.qrealListProperty[1] = 33.3;
+ if (msco.qrealListProperty[1] != 33.3) success = false; // ensure write back
+ qrealList[1] = 44.4;
+ if (qrealList[1] == 44.4) success = false; // ensure no effect
+ jsQrealList[1] = 55.5;
+ if (jsQrealList[1] != 55.5
+ || jsQrealList[1] != msco.qrealListProperty[1]) success = false; // ensure write back
+
+ msco.boolListProperty[1] = true;
+ if (msco.boolListProperty[1] != true) success = false; // ensure write back
+ boolList[1] = true;
+ if (boolList[1] != false) success = false; // ensure no effect
+ jsBoolList[1] = false;
+ if (jsBoolList[1] != false
+ || jsBoolList[1] != msco.boolListProperty[1]) success = false; // ensure write back
+
+ msco.stringListProperty[1] = "changed";
+ if (msco.stringListProperty[1] != "changed") success = false; // ensure write back
+ stringList[1] = "changed";
+ if (stringList[1] != "second") success = false; // ensure no effect
+ jsStringList[1] = "different";
+ if (jsStringList[1] != "different"
+ || jsStringList[1] != msco.stringListProperty[1]) success = false; // ensure write back
+ }
+
+ function arrayOperations() {
+ success = true;
+ var expected = 0;
+ var expectedStr = "";
+
+ // ecma262r3 defines array as implementing Length and Put. Test put here.
+ msco.intListProperty.asdf = 5; // shouldn't work, only indexes are valid names.
+ if (msco.intListProperty.asdf == 5) success = false;
+ msco.intListProperty[3] = 38; // should work.
+ if (msco.intListProperty[3] != 38) success = false;
+ msco.intListProperty[199] = 200; // should work, and should set length to 200.
+ if (msco.intListProperty[199] != 200) success = false;
+ if (msco.intListProperty.length != 200) success = false;
+
+ // other operations are defined on the array prototype; see if they work.
+ msco.intListProperty = [ 0, 1, 2, 3, 4, 5, 6, 7 ];
+ msco.intListProperty.splice(1,3, 33, 44, 55, 66);
+ expected = [ 0, 33, 44, 55, 66, 4, 5, 6, 7 ];
+ if (msco.intListProperty.toString() != expected.toString()) success = false;
+
+ msco.qrealListProperty = [ 0.1, 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1 ];
+ msco.qrealListProperty.splice(1,3, 33.33, 44.44, 55.55, 66.66);
+ expected = [ 0.1, 33.33, 44.44, 55.55, 66.66, 4.1, 5.1, 6.1, 7.1 ];
+ if (msco.qrealListProperty.toString() != expected.toString()) success = false;
+
+ msco.boolListProperty = [ false, true, true, false, false, true, false, true ];
+ msco.boolListProperty.splice(1,3, false, true, false, false);
+ expected = [ false, false, true, false, false, false, true, false, true ];
+ if (msco.boolListProperty.toString() != expected.toString()) success = false;
+
+ msco.stringListProperty = [ "one", "two", "three", "four", "five", "six", "seven", "eight" ];
+ msco.stringListProperty.splice(1,3, "nine", "ten", "eleven", "twelve");
+ expected = [ "one", "nine", "ten", "eleven", "twelve", "five", "six", "seven", "eight" ];
+ if (msco.stringListProperty.toString() != expected.toString()) success = false;
+ }
+
+ property variant variantList: [ 1, 2, 3, 4, 5 ];
+ property variant variantList2: [ 1, 2, 3, 4, 5 ];
+ function testEqualitySemantics() {
+ // ensure equality semantics match JS array equality semantics
+ success = true;
+
+ msco.intListProperty = [ 1, 2, 3, 4, 5 ];
+ msco.intListProperty2 = [ 1, 2, 3, 4, 5 ];
+ var jsIntList = [ 1, 2, 3, 4, 5 ];
+ var jsIntList2 = [ 1, 2, 3, 4, 5 ];
+
+ if (jsIntList != jsIntList) success = false;
+ if (jsIntList == jsIntList2) success = false;
+ if (jsIntList == msco.intListProperty) success = false;
+ if (jsIntList == variantList) success = false;
+
+ if (msco.intListProperty != msco.intListProperty) success = false;
+ if (msco.intListProperty == msco.intListProperty2) success = false;
+ if (msco.intListProperty == jsIntList) success = false;
+ if (msco.intListProperty == variantList) success = false;
+
+ if (variantList == variantList) return false;
+ if (variantList == variantList2) return false;
+ if (variantList == msco.intListProperty) return false;
+ if (variantList == jsIntList) return false;
+
+ if ((jsIntList == jsIntList2) != (jsIntList == msco.intListProperty)) success = false;
+ if ((jsIntList == jsIntList2) != (msco.intListProperty == msco.intListProperty2)) success = false;
+ if ((jsIntList == jsIntList) != (msco.intListProperty == msco.intListProperty)) success = false;
+ if ((jsIntList == variantList) != (msco.intListProperty == variantList)) success = false;
+ if ((variantList == jsIntList) != (variantList == msco.intListProperty)) success = false;
+ if ((msco.intListProperty == variantList) != (variantList == msco.intListProperty)) success = false;
+ }
+
+ property bool referenceDeletion: false
+ function testReferenceDeletion() {
+ referenceDeletion = true;
+ var testObj = msco.generateTestObject();
+ testObj.intListProperty = [1, 2, 3, 4, 5];
+ var testSequence = testObj.intListProperty;
+ var prevString = testSequence.toString();
+ var prevValueOf = testSequence.valueOf();
+ var prevLength = testSequence.length;
+ msco.deleteTestObject(testObj); // delete referenced object.
+ if (testSequence.toString() == prevString) referenceDeletion = false;
+ if (testSequence.valueOf() == prevValueOf) referenceDeletion = false;
+ if (testSequence.length == prevLength) referenceDeletion = false;
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.bindings.error.qml b/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.bindings.error.qml
new file mode 100644
index 0000000000..9c87dd293e
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.bindings.error.qml
@@ -0,0 +1,19 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+Item {
+ id: root
+ objectName: "root"
+
+ MySequenceConversionObject {
+ id: msco
+ objectName: "msco"
+ intListProperty: [ 1, 2, 3, 6, 7 ]
+ }
+
+ MySequenceConversionObject {
+ id: mscoTwo
+ objectName: "mscoTwo"
+ boolListProperty: msco.intListProperty
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.bindings.qml b/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.bindings.qml
new file mode 100644
index 0000000000..8d83e9f9f5
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.bindings.qml
@@ -0,0 +1,28 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+Item {
+ id: root
+ objectName: "root"
+
+ MySequenceConversionObject {
+ id: msco
+ objectName: "msco"
+ intListProperty: [ 1, 2, 3, 6, 7 ]
+ }
+
+ MySequenceConversionObject {
+ id: mscoTwo
+ objectName: "mscoTwo"
+ intListProperty: msco.intListProperty
+ }
+
+ property variant boundSequence: msco.intListProperty
+ property int boundElement: msco.intListProperty[3]
+ property variant boundSequenceTwo: mscoTwo.intListProperty
+
+ Component.onCompleted: {
+ msco.intListProperty[3] = 12;
+ mscoTwo.intListProperty[4] = 14;
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.copy.qml b/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.copy.qml
new file mode 100644
index 0000000000..f6614dad0c
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.copy.qml
@@ -0,0 +1,160 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+Item {
+ id: root
+ objectName: "root"
+
+ MySequenceConversionObject {
+ id: msco
+ objectName: "msco"
+ }
+
+ property bool success: true
+
+ property variant intList
+ property variant qrealList
+ property variant boolList
+ property variant stringList
+ property variant urlList
+ property variant qstringList
+
+ // this test ensures that the "copy resource" codepaths work
+ function testCopySequences() {
+ success = true;
+
+ // create "copy resource" sequences
+ var jsIntList = msco.generateIntSequence();
+ var jsQrealList = msco.generateQrealSequence();
+ var jsBoolList = msco.generateBoolSequence();
+ var jsStringList = msco.generateStringSequence();
+ var jsUrlList = msco.generateUrlSequence();
+ var jsQStringList = msco.generateQStringSequence();
+
+ if (jsIntList.toString() != [1, 2, 3].toString())
+ success = false;
+ if (jsQrealList.toString() != [1.1, 2.2, 3.3].toString())
+ success = false;
+ if (jsBoolList.toString() != [true, false, true].toString())
+ success = false;
+ if (jsStringList.toString() != ["one", "two", "three"].toString())
+ success = false;
+ if (jsUrlList.toString() != ["http://www.example1.com", "http://www.example2.com", "http://www.example3.com"].toString())
+ success = false;
+ if (jsQStringList.toString() != ["one", "two", "three"].toString())
+ success = false;
+
+ // copy the sequence; should result in a new copy
+ intList = jsIntList;
+ qrealList = jsQrealList;
+ boolList = jsBoolList;
+ stringList = jsStringList;
+ urlList = jsUrlList;
+ qstringList = jsQStringList;
+
+ // these operations shouldn't modify either variables - because
+ // we don't handle writing to the intermediate variant at list[index]
+ // for variant properties.
+ intList[1] = 8;
+ qrealList[1] = 8.8;
+ boolList[1] = true;
+ stringList[1] = "eight";
+ urlList[1] = "http://www.example8.com";
+ qstringList[1] = "eight";
+
+ if (jsIntList[1] == 8)
+ success = false;
+ if (jsQrealList[1] == 8.8)
+ success = false;
+ if (jsBoolList[1] == true)
+ success = false;
+ if (jsStringList[1] == "eight")
+ success = false;
+ if (jsUrlList[1] == "http://www.example8.com")
+ success = false;
+ if (jsQStringList[1] == "eight")
+ success = false;
+
+ // assign a "copy resource" sequence to a QObject Q_PROPERTY
+ msco.intListProperty = intList;
+ msco.qrealListProperty = qrealList;
+ msco.boolListProperty = boolList;
+ msco.stringListProperty = stringList;
+ msco.urlListProperty = urlList;
+ msco.qstringListProperty = qstringList;
+
+ if (msco.intListProperty.toString() != [1, 2, 3].toString())
+ success = false;
+ if (msco.qrealListProperty.toString() != [1.1, 2.2, 3.3].toString())
+ success = false;
+ if (msco.boolListProperty.toString() != [true, false, true].toString())
+ success = false;
+ if (msco.stringListProperty.toString() != ["one", "two", "three"].toString())
+ success = false;
+ if (msco.urlListProperty.toString() != ["http://www.example1.com", "http://www.example2.com", "http://www.example3.com"].toString())
+ success = false;
+ if (msco.qstringListProperty.toString() != ["one", "two", "three"].toString())
+ success = false;
+
+ // now modify the QObject Q_PROPERTY (reference resource) sequences - shouldn't modify the copy resource sequences.
+ msco.intListProperty[2] = 9;
+ msco.qrealListProperty[2] = 9.9;
+ msco.boolListProperty[2] = false;
+ msco.stringListProperty[2] = "nine";
+ msco.urlListProperty[2] = "http://www.example9.com";
+ msco.qstringListProperty[2] = "nine";
+
+ if (intList[2] == 9)
+ success = false;
+ if (qrealList[2] == 9.9)
+ success = false;
+ if (boolList[2] == false)
+ success = false;
+ if (stringList[2] == "nine")
+ success = false;
+ if (urlList[2] == "http://www.example9.com")
+ success = false;
+ if (qstringList[2] == "nine")
+ success = false;
+ }
+
+ property int intVal
+ property real qrealVal
+ property bool boolVal
+ property string stringVal
+
+ // this test ensures that indexed access works for copy resource sequences.
+ function readSequenceCopyElements() {
+ success = true;
+
+ var jsIntList = msco.generateIntSequence();
+ var jsQrealList = msco.generateQrealSequence();
+ var jsBoolList = msco.generateBoolSequence();
+ var jsStringList = msco.generateStringSequence();
+
+ intVal = jsIntList[1];
+ qrealVal = jsQrealList[1];
+ boolVal = jsBoolList[1];
+ stringVal = jsStringList[1];
+
+ if (intVal != 2)
+ success = false;
+ if (qrealVal != 2.2)
+ success = false;
+ if (boolVal != false)
+ success = false;
+ if (stringVal != "two")
+ success = false;
+ }
+
+ // this test ensures that equality works for copy resource sequences.
+ function testEqualitySemantics() {
+ success = true;
+
+ var jsIntList = msco.generateIntSequence();
+ var jsIntList2 = msco.generateIntSequence();
+
+ if (jsIntList == jsIntList2) success = false;
+ if (jsIntList != jsIntList) success = false;
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.read.error.qml b/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.read.error.qml
new file mode 100644
index 0000000000..12a76d7e7d
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.read.error.qml
@@ -0,0 +1,21 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+Item {
+ id: root
+ objectName: "root"
+
+ MySequenceConversionObject {
+ id: msco
+ objectName: "msco"
+ }
+
+ property int pointListLength: 0
+ property variant pointList
+
+ function performTest() {
+ // we have NOT registered QList<QPoint> as a type
+ pointListLength = msco.pointListProperty.length;
+ pointList = msco.pointListProperty;
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.read.qml b/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.read.qml
new file mode 100644
index 0000000000..4a8a4a17b2
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.read.qml
@@ -0,0 +1,105 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+Item {
+ id: root
+ objectName: "root"
+
+ MySequenceConversionObject {
+ id: msco
+ objectName: "msco"
+ }
+
+ property int intListLength: 0
+ property variant intList
+ property int qrealListLength: 0
+ property variant qrealList
+ property int boolListLength: 0
+ property variant boolList
+ property int stringListLength: 0
+ property variant stringList
+ property int urlListLength: 0
+ property variant urlList
+ property int qstringListLength: 0
+ property variant qstringList
+
+ function readSequences() {
+ intListLength = msco.intListProperty.length;
+ intList = msco.intListProperty;
+ qrealListLength = msco.qrealListProperty.length;
+ qrealList = msco.qrealListProperty;
+ boolListLength = msco.boolListProperty.length;
+ boolList = msco.boolListProperty;
+ stringListLength = msco.stringListProperty.length;
+ stringList = msco.stringListProperty;
+ urlListLength = msco.urlListProperty.length;
+ urlList = msco.urlListProperty;
+ qstringListLength = msco.qstringListProperty.length;
+ qstringList = msco.qstringListProperty;
+ }
+
+ property int intVal
+ property real qrealVal
+ property bool boolVal
+ property string stringVal
+ property url urlVal
+ property string qstringVal
+
+ function readSequenceElements() {
+ intVal = msco.intListProperty[1];
+ qrealVal = msco.qrealListProperty[1];
+ boolVal = msco.boolListProperty[1];
+ stringVal = msco.stringListProperty[1];
+ urlVal = msco.urlListProperty[1];
+ qstringVal = msco.qstringListProperty[1];
+ }
+
+ property bool enumerationMatches
+ function enumerateSequenceElements() {
+ var jsIntList = [1, 2, 3, 4, 5];
+ msco.intListProperty = [1, 2, 3, 4, 5];
+
+ var jsIntListProps = []
+ var seqIntListProps = []
+
+ enumerationMatches = true;
+ for (var i in jsIntList) {
+ jsIntListProps.push(i);
+ if (jsIntList[i] != msco.intListProperty[i]) {
+ enumerationMatches = false;
+ }
+ }
+ for (var j in msco.intListProperty) {
+ seqIntListProps.push(j);
+ if (jsIntList[j] != msco.intListProperty[j]) {
+ enumerationMatches = false;
+ }
+ }
+
+ if (jsIntListProps.length != seqIntListProps.length) {
+ enumerationMatches = false;
+ }
+
+ var emptyList = [];
+ msco.stringListProperty = []
+ if (emptyList.toString() != msco.stringListProperty.toString()) {
+ enumerationMatches = false;
+ }
+ if (emptyList.valueOf() != msco.stringListProperty.valueOf()) {
+ enumerationMatches = false;
+ }
+ }
+
+ property bool referenceDeletion: false
+ function testReferenceDeletion() {
+ referenceDeletion = true;
+ var testObj = msco.generateTestObject();
+ testObj.intListProperty = [1, 2, 3, 4, 5];
+ var testSequence = testObj.intListProperty;
+ if (testSequence[4] != 5)
+ referenceDeletion = false;
+ msco.deleteTestObject(testObj); // delete referenced object.
+ if (testSequence[4] == 5)
+ referenceDeletion = false;
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.threads.qml b/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.threads.qml
new file mode 100644
index 0000000000..5c4afe0574
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.threads.qml
@@ -0,0 +1,69 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+Item {
+ id: root
+ objectName: "root"
+
+ MySequenceConversionObject {
+ id: msco
+ objectName: "msco"
+ }
+
+ property bool success: false
+ property bool finished: false
+
+ function testIntSequence() {
+ msco.intListProperty = [ 0, 1, 2, 3, 4, 5, 6, 7 ];
+ worker.sendSequence(msco.intListProperty);
+ }
+
+ function testQrealSequence() {
+ msco.qrealListProperty = [ 0.1, 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1 ];
+ worker.sendSequence(msco.qrealListProperty);
+ }
+
+ function testBoolSequence() {
+ msco.boolListProperty = [ false, true, true, false, false, true, false, true ];
+ worker.sendSequence(msco.boolListProperty);
+ }
+
+ function testStringSequence() {
+ msco.stringListProperty = [ "one", "two", "three", "four" ];
+ worker.sendSequence(msco.stringListProperty);
+ }
+
+ function testQStringSequence() {
+ msco.qstringListProperty = [ "one", "two", "three", "four" ];
+ worker.sendSequence(msco.qstringListProperty);
+ }
+
+ function testUrlSequence() {
+ msco.urlListProperty = [ "www.example1.com", "www.example2.com", "www.example3.com", "www.example4.com" ];
+ worker.sendSequence(msco.urlListProperty);
+ }
+
+ WorkerScript {
+ id: worker
+ source: "threadScript.js"
+
+ property variant expected
+ property variant response
+
+ function sendSequence(seq) {
+ root.success = false;
+ root.finished = false;
+ worker.expected = seq;
+ worker.sendMessage(seq);
+ }
+
+ onMessage: {
+ worker.response = messageObject;
+ if (worker.response.toString() == worker.expected.toString())
+ root.success = true;
+ else
+ root.success = false;
+ root.finished = true;
+ }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.write.error.qml b/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.write.error.qml
new file mode 100644
index 0000000000..75beafd1ee
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.write.error.qml
@@ -0,0 +1,18 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+Item {
+ id: root
+ objectName: "root"
+
+ MySequenceConversionObject {
+ id: msco
+ objectName: "msco"
+ }
+
+ function performTest() {
+ // we have NOT registered QList<QPoint> as a type
+ var pointList = [ Qt.point(7,7), Qt.point(8,8), Qt.point(9,9) ];
+ msco.pointListProperty = pointList; // error.
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.write.qml b/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.write.qml
new file mode 100644
index 0000000000..812de043b7
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/sequenceConversion.write.qml
@@ -0,0 +1,109 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+Item {
+ id: root
+ objectName: "root"
+
+ MySequenceConversionObject {
+ id: msco
+ objectName: "msco"
+ }
+
+ property bool success
+
+ function writeSequences() {
+ success = true;
+
+ var intList = [ 9, 8, 7, 6 ];
+ msco.intListProperty = intList;
+ var qrealList = [ 9.9, 8.8, 7.7, 6.6 ];
+ msco.qrealListProperty = qrealList;
+ var boolList = [ false, false, false, true ];
+ msco.boolListProperty = boolList;
+ var stringList = [ "nine", "eight", "seven", "six" ]
+ msco.stringListProperty = stringList;
+ var urlList = [ "http://www.example9.com", "http://www.example8.com", "http://www.example7.com", "http://www.example6.com" ]
+ msco.urlListProperty = urlList;
+ var qstringList = [ "nine", "eight", "seven", "six" ]
+ msco.qstringListProperty = qstringList;
+
+ if (msco.intListProperty[0] != 9 || msco.intListProperty[1] != 8 || msco.intListProperty[2] != 7 || msco.intListProperty[3] != 6)
+ success = false;
+ if (msco.qrealListProperty[0] != 9.9 || msco.qrealListProperty[1] != 8.8 || msco.qrealListProperty[2] != 7.7 || msco.qrealListProperty[3] != 6.6)
+ success = false;
+ if (msco.boolListProperty[0] != false || msco.boolListProperty[1] != false || msco.boolListProperty[2] != false || msco.boolListProperty[3] != true)
+ success = false;
+ if (msco.stringListProperty[0] != "nine" || msco.stringListProperty[1] != "eight" || msco.stringListProperty[2] != "seven" || msco.stringListProperty[3] != "six")
+ success = false;
+ if (msco.urlListProperty[0] != "http://www.example9.com" || msco.urlListProperty[1] != "http://www.example8.com" || msco.urlListProperty[2] != "http://www.example7.com" || msco.urlListProperty[3] != "http://www.example6.com")
+ success = false;
+ if (msco.qstringListProperty[0] != "nine" || msco.qstringListProperty[1] != "eight" || msco.qstringListProperty[2] != "seven" || msco.qstringListProperty[3] != "six")
+ success = false;
+ }
+
+ function writeSequenceElements() {
+ // set up initial conditions.
+ writeSequences();
+ success = true;
+
+ // element set.
+ msco.intListProperty[3] = 2;
+ msco.qrealListProperty[3] = 2.2;
+ msco.boolListProperty[3] = false;
+ msco.stringListProperty[3] = "changed";
+ msco.urlListProperty[3] = "http://www.examplechanged.com";
+ msco.qstringListProperty[3] = "changed";
+
+ if (msco.intListProperty[0] != 9 || msco.intListProperty[1] != 8 || msco.intListProperty[2] != 7 || msco.intListProperty[3] != 2)
+ success = false;
+ if (msco.qrealListProperty[0] != 9.9 || msco.qrealListProperty[1] != 8.8 || msco.qrealListProperty[2] != 7.7 || msco.qrealListProperty[3] != 2.2)
+ success = false;
+ if (msco.boolListProperty[0] != false || msco.boolListProperty[1] != false || msco.boolListProperty[2] != false || msco.boolListProperty[3] != false)
+ success = false;
+ if (msco.stringListProperty[0] != "nine" || msco.stringListProperty[1] != "eight" || msco.stringListProperty[2] != "seven" || msco.stringListProperty[3] != "changed")
+ success = false;
+ if (msco.urlListProperty[0] != "http://www.example9.com" || msco.urlListProperty[1] != "http://www.example8.com" || msco.urlListProperty[2] != "http://www.example7.com" || msco.urlListProperty[3] != "http://www.examplechanged.com")
+ success = false;
+ if (msco.qstringListProperty[0] != "nine" || msco.qstringListProperty[1] != "eight" || msco.qstringListProperty[2] != "seven" || msco.qstringListProperty[3] != "changed")
+ success = false;
+ }
+
+ function writeOtherElements() {
+ success = true;
+ var jsIntList = [1, 2, 3, 4, 5];
+ msco.intListProperty = [1, 2, 3, 4, 5];
+
+ jsIntList[8] = 8;
+ msco.intListProperty[8] = 8;
+ if (jsIntList[8] != msco.intListProperty[8])
+ success = false;
+ if (jsIntList.length != msco.intListProperty.length)
+ success = false;
+
+ // NOTE: we can't exactly match the spec here -- we fill the sequence with a default (rather than empty) value
+ if (msco.intListProperty[5] != 0 || msco.intListProperty[6] != 0 || msco.intListProperty[7] != 0)
+ success = false;
+
+ // should have no effect
+ var currLength = jsIntList.length;
+ jsIntList.someThing = 9;
+ msco.intListProperty.someThing = 9;
+ if (msco.intListProperty.length != currLength)
+ success = false;
+ }
+
+ property bool referenceDeletion: false
+ function testReferenceDeletion() {
+ referenceDeletion = true;
+ var testObj = msco.generateTestObject();
+ testObj.intListProperty = [1, 2, 3, 4, 5];
+ var testSequence = testObj.intListProperty;
+ if (testSequence[4] != 5)
+ referenceDeletion = false;
+ msco.deleteTestObject(testObj); // delete referenced object.
+ testSequence[4] = 5; // shouldn't work, since referenced object no longer exists.
+ if (testSequence[4] == 5)
+ referenceDeletion = false;
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/threadScript.js b/tests/auto/declarative/qdeclarativeecmascript/data/threadScript.js
new file mode 100644
index 0000000000..9f94de1bc1
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/threadScript.js
@@ -0,0 +1,4 @@
+WorkerScript.onMessage = function(msg) {
+ WorkerScript.sendMessage(msg);
+}
+