Use V4 binding for non-final properties where possible
[profile/ivi/qtdeclarative.git] / tests / auto / qml / qqmlecmascript / data / sequenceConversion.copy.qml
1 import QtQuick 2.0
2 import Qt.test 1.0
3
4 Item {
5     id: root
6     objectName: "root"
7
8     MySequenceConversionObject {
9         id: msco
10         objectName: "msco"
11     }
12
13     property bool success: true
14
15     property variant intList
16     property variant qrealList
17     property variant boolList
18     property variant stringList
19     property variant urlList
20     property variant qstringList
21
22     // this test ensures that the "copy resource" codepaths work
23     function testCopySequences() {
24         success = true;
25
26         // create "copy resource" sequences
27         var jsIntList = msco.generateIntSequence();
28         var jsQrealList = msco.generateQrealSequence();
29         var jsBoolList = msco.generateBoolSequence();
30         var jsStringList = msco.generateStringSequence();
31         var jsUrlList = msco.generateUrlSequence();
32         var jsQStringList = msco.generateQStringSequence();
33
34         if (jsIntList.toString() != [1, 2, 3].toString())
35             success = false;
36         if (jsQrealList.toString() != [1.1, 2.2, 3.3].toString())
37             success = false;
38         if (jsBoolList.toString() != [true, false, true].toString())
39             success = false;
40         if (jsStringList.toString() != ["one", "two", "three"].toString())
41             success = false;
42         if (jsUrlList.toString() != ["http://www.example1.com", "http://www.example2.com", "http://www.example3.com"].toString())
43             success = false;
44         if (jsQStringList.toString() != ["one", "two", "three"].toString())
45             success = false;
46
47         // copy the sequence; should result in a new copy
48         intList = jsIntList;
49         qrealList = jsQrealList;
50         boolList = jsBoolList;
51         stringList = jsStringList;
52         urlList = jsUrlList;
53         qstringList = jsQStringList;
54
55         // these operations shouldn't modify either variables - because
56         // we don't handle writing to the intermediate variant at list[index]
57         // for variant properties.
58         intList[1] = 8;
59         qrealList[1] = 8.8;
60         boolList[1] = true;
61         stringList[1] = "eight";
62         urlList[1] = "http://www.example8.com";
63         qstringList[1] = "eight";
64
65         if (jsIntList[1] == 8)
66             success = false;
67         if (jsQrealList[1] == 8.8)
68             success = false;
69         if (jsBoolList[1] == true)
70             success = false;
71         if (jsStringList[1] == "eight")
72             success = false;
73         if (jsUrlList[1] == "http://www.example8.com")
74             success = false;
75         if (jsQStringList[1] == "eight")
76             success = false;
77
78         // assign a "copy resource" sequence to a QObject Q_PROPERTY
79         msco.intListProperty = intList;
80         msco.qrealListProperty = qrealList;
81         msco.boolListProperty = boolList;
82         msco.stringListProperty = stringList;
83         msco.urlListProperty = urlList;
84         msco.qstringListProperty = qstringList;
85
86         if (msco.intListProperty.toString() != [1, 2, 3].toString())
87             success = false;
88         if (msco.qrealListProperty.toString() != [1.1, 2.2, 3.3].toString())
89             success = false;
90         if (msco.boolListProperty.toString() != [true, false, true].toString())
91             success = false;
92         if (msco.stringListProperty.toString() != ["one", "two", "three"].toString())
93             success = false;
94         if (msco.urlListProperty.toString() != ["http://www.example1.com", "http://www.example2.com", "http://www.example3.com"].toString())
95             success = false;
96         if (msco.qstringListProperty.toString() != ["one", "two", "three"].toString())
97             success = false;
98
99         // now modify the QObject Q_PROPERTY (reference resource) sequences - shouldn't modify the copy resource sequences.
100         msco.intListProperty[2] = 9;
101         msco.qrealListProperty[2] = 9.9;
102         msco.boolListProperty[2] = false;
103         msco.stringListProperty[2] = "nine";
104         msco.urlListProperty[2] = "http://www.example9.com";
105         msco.qstringListProperty[2] = "nine";
106
107         if (intList[2] == 9)
108             success = false;
109         if (qrealList[2] == 9.9)
110             success = false;
111         if (boolList[2] == false)
112             success = false;
113         if (stringList[2] == "nine")
114             success = false;
115         if (urlList[2] == "http://www.example9.com")
116             success = false;
117         if (qstringList[2] == "nine")
118             success = false;
119     }
120
121     property int intVal
122     property real qrealVal
123     property bool boolVal
124     property string stringVal
125
126     // this test ensures that indexed access works for copy resource sequences.
127     function readSequenceCopyElements() {
128         success = true;
129
130         var jsIntList = msco.generateIntSequence();
131         var jsQrealList = msco.generateQrealSequence();
132         var jsBoolList = msco.generateBoolSequence();
133         var jsStringList = msco.generateStringSequence();
134
135         intVal = jsIntList[1];
136         qrealVal = jsQrealList[1];
137         boolVal = jsBoolList[1];
138         stringVal = jsStringList[1];
139
140         if (intVal != 2)
141             success = false;
142         if (qrealVal != 2.2)
143             success = false;
144         if (boolVal != false)
145             success = false;
146         if (stringVal != "two")
147             success = false;
148     }
149
150     // this test ensures that equality works for copy resource sequences.
151     function testEqualitySemantics() {
152         success = true;
153
154         var jsIntList = msco.generateIntSequence();
155         var jsIntList2 = msco.generateIntSequence();
156
157         if (jsIntList == jsIntList2) success = false;
158         if (jsIntList != jsIntList) success = false;
159     }
160 }