##// END OF EJS Templates
QML unit tests for setting illegal axes
Tero Ahola -
r2330:2968500e2441
parent child
Show More
@@ -1,260 +1,271
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtQuickTest 1.0
22 import QtQuickTest 1.0
23 import QtCommercial.Chart 1.2
23 import QtCommercial.Chart 1.2
24
24
25 Rectangle {
25 Rectangle {
26 width: 400
26 width: 400
27 height: 300
27 height: 300
28
28
29 TestCase {
29 TestCase {
30 id: tc1
30 id: tc1
31 name: "tst_qml-qtquicktest XY Series"
31 name: "tst_qml-qtquicktest XY Series"
32 when: windowShown
32 when: windowShown
33
33
34 function test_properties() {
34 function test_properties() {
35 verify(lineSeries.color != undefined);
35 verify(lineSeries.color != undefined);
36 compare(lineSeries.pointsVisible, false);
36 compare(lineSeries.pointsVisible, false);
37 compare(lineSeries.capStyle, Qt.SquareCap);
37 compare(lineSeries.capStyle, Qt.SquareCap);
38 compare(lineSeries.style, Qt.SolidLine);
38 compare(lineSeries.style, Qt.SolidLine);
39 compare(lineSeries.width, 2.0);
39 compare(lineSeries.width, 2.0);
40
40
41 verify(splineSeries.color != undefined);
41 verify(splineSeries.color != undefined);
42 compare(splineSeries.pointsVisible, false);
42 compare(splineSeries.pointsVisible, false);
43 compare(splineSeries.capStyle, Qt.SquareCap);
43 compare(splineSeries.capStyle, Qt.SquareCap);
44 compare(splineSeries.style, Qt.SolidLine);
44 compare(splineSeries.style, Qt.SolidLine);
45 compare(splineSeries.width, 2.0);
45 compare(splineSeries.width, 2.0);
46
46
47 verify(scatterSeries.color != undefined);
47 verify(scatterSeries.color != undefined);
48 verify(scatterSeries.borderColor != undefined);
48 verify(scatterSeries.borderColor != undefined);
49 compare(scatterSeries.borderWidth, 2.0);
49 compare(scatterSeries.borderWidth, 2.0);
50 compare(scatterSeries.markerShape, ScatterSeries.MarkerShapeCircle);
50 compare(scatterSeries.markerShape, ScatterSeries.MarkerShapeCircle);
51 compare(scatterSeries.markerSize, 15.0);
51 compare(scatterSeries.markerSize, 15.0);
52
52
53 verify(areaSeries.color != undefined);
53 verify(areaSeries.color != undefined);
54 verify(areaSeries.borderColor != undefined);
54 verify(areaSeries.borderColor != undefined);
55 compare(areaSeries.borderWidth, 2.0);
55 compare(areaSeries.borderWidth, 2.0);
56 }
56 }
57
57
58 function test_axes() {
58 function test_axes() {
59 // Axis initialization
59 compare(chartView.axes.length, 2);
60 compare(chartView.axes.length, 2);
60 verify(chartView.axes[0] == lineSeries.axisX || chartView.axes[1] == lineSeries.axisX);
61 verify(chartView.axes[0] == lineSeries.axisX || chartView.axes[1] == lineSeries.axisX);
61 verify(chartView.axes[0] == lineSeries.axisY || chartView.axes[1] == lineSeries.axisY);
62 verify(chartView.axes[0] == lineSeries.axisY || chartView.axes[1] == lineSeries.axisY);
62 verify(lineSeries.axisX == splineSeries.axisX);
63 compare(lineSeries.axisX, splineSeries.axisX);
63 verify(lineSeries.axisY == splineSeries.axisY);
64 compare(lineSeries.axisY, splineSeries.axisY);
64 verify(lineSeries.axisX == areaSeries.axisX);
65 compare(lineSeries.axisX, areaSeries.axisX);
65 verify(lineSeries.axisY == areaSeries.axisY);
66 compare(lineSeries.axisY, areaSeries.axisY);
67
68 // Set illegal axes
69 lineSeries.axisX = lineSeries.axisY;
70 compare(lineSeries.axisX, splineSeries.axisX);
71 lineSeries.axisXTop = lineSeries.axisX;
72 compare(lineSeries.axisX, splineSeries.axisX);
73 lineSeries.axisY = lineSeries.axisX;
74 compare(lineSeries.axisY, splineSeries.axisY);
75 lineSeries.axisYRight = lineSeries.axisY;
76 compare(lineSeries.axisY, splineSeries.axisY);
66 }
77 }
67
78
68 function test_append() {
79 function test_append() {
69 lineSeriesPointAddedSpy.clear();
80 lineSeriesPointAddedSpy.clear();
70 splineSeriesPointAddedSpy.clear();
81 splineSeriesPointAddedSpy.clear();
71 scatterSeriesPointAddedSpy.clear();
82 scatterSeriesPointAddedSpy.clear();
72 var count = append();
83 var count = append();
73 compare(lineSeries.count, count);
84 compare(lineSeries.count, count);
74 compare(splineSeries.count, count);
85 compare(splineSeries.count, count);
75 compare(scatterSeries.count, count);
86 compare(scatterSeries.count, count);
76 tryCompare(lineSeriesPointAddedSpy.count, count);
87 tryCompare(lineSeriesPointAddedSpy.count, count);
77 tryCompare(splineSeriesPointAddedSpy.count, count);
88 tryCompare(splineSeriesPointAddedSpy.count, count);
78 tryCompare(scatterSeriesPointAddedSpy.count, count);
89 tryCompare(scatterSeriesPointAddedSpy.count, count);
79 clear();
90 clear();
80 compare(lineSeries.count, 0);
91 compare(lineSeries.count, 0);
81 compare(splineSeries.count, 0);
92 compare(splineSeries.count, 0);
82 compare(scatterSeries.count, 0);
93 compare(scatterSeries.count, 0);
83 }
94 }
84
95
85 function test_replace() {
96 function test_replace() {
86 var count = append();
97 var count = append();
87 for (var i = 0; i < count; i++) {
98 for (var i = 0; i < count; i++) {
88 lineSeries.replace(lineSeries.at(i).x, lineSeries.at(i).y, i, Math.random());
99 lineSeries.replace(lineSeries.at(i).x, lineSeries.at(i).y, i, Math.random());
89 splineSeries.replace(splineSeries.at(i).x, splineSeries.at(i).y, i, Math.random());
100 splineSeries.replace(splineSeries.at(i).x, splineSeries.at(i).y, i, Math.random());
90 scatterSeries.replace(scatterSeries.at(i).x, scatterSeries.at(i).y, i, Math.random());
101 scatterSeries.replace(scatterSeries.at(i).x, scatterSeries.at(i).y, i, Math.random());
91 }
102 }
92 compare(lineSeries.count, count);
103 compare(lineSeries.count, count);
93 compare(splineSeries.count, count);
104 compare(splineSeries.count, count);
94 compare(scatterSeries.count, count);
105 compare(scatterSeries.count, count);
95 tryCompare(lineSeriesPointReplacedSpy.count, count);
106 tryCompare(lineSeriesPointReplacedSpy.count, count);
96 tryCompare(splineSeriesPointReplacedSpy.count, count);
107 tryCompare(splineSeriesPointReplacedSpy.count, count);
97 tryCompare(scatterSeriesPointReplacedSpy.count, count);
108 tryCompare(scatterSeriesPointReplacedSpy.count, count);
98 clear();
109 clear();
99 }
110 }
100
111
101 function test_insert() {
112 function test_insert() {
102 var count = append();
113 var count = append();
103 lineSeriesPointAddedSpy.clear();
114 lineSeriesPointAddedSpy.clear();
104 splineSeriesPointAddedSpy.clear();
115 splineSeriesPointAddedSpy.clear();
105 scatterSeriesPointAddedSpy.clear();
116 scatterSeriesPointAddedSpy.clear();
106 for (var i = 0; i < count; i++) {
117 for (var i = 0; i < count; i++) {
107 lineSeries.insert(i * 2, i, Math.random());
118 lineSeries.insert(i * 2, i, Math.random());
108 splineSeries.insert(i * 2, i, Math.random());
119 splineSeries.insert(i * 2, i, Math.random());
109 scatterSeries.insert(i * 2, i, Math.random());
120 scatterSeries.insert(i * 2, i, Math.random());
110 }
121 }
111 compare(lineSeries.count, count * 2);
122 compare(lineSeries.count, count * 2);
112 compare(splineSeries.count, count * 2);
123 compare(splineSeries.count, count * 2);
113 compare(scatterSeries.count, count * 2);
124 compare(scatterSeries.count, count * 2);
114 tryCompare(lineSeriesPointAddedSpy.count, count);
125 tryCompare(lineSeriesPointAddedSpy.count, count);
115 tryCompare(splineSeriesPointAddedSpy.count, count);
126 tryCompare(splineSeriesPointAddedSpy.count, count);
116 tryCompare(scatterSeriesPointAddedSpy.count, count);
127 tryCompare(scatterSeriesPointAddedSpy.count, count);
117 clear();
128 clear();
118 }
129 }
119
130
120 function test_remove() {
131 function test_remove() {
121 lineSeriesPointRemovedSpy.clear();
132 lineSeriesPointRemovedSpy.clear();
122 splineSeriesPointRemovedSpy.clear();
133 splineSeriesPointRemovedSpy.clear();
123 scatterSeriesPointRemovedSpy.clear();
134 scatterSeriesPointRemovedSpy.clear();
124 var count = append();
135 var count = append();
125 for (var i = 0; i < count; i++) {
136 for (var i = 0; i < count; i++) {
126 lineSeries.remove(lineSeries.at(0).x, lineSeries.at(0).y);
137 lineSeries.remove(lineSeries.at(0).x, lineSeries.at(0).y);
127 splineSeries.remove(splineSeries.at(0).x, splineSeries.at(0).y);
138 splineSeries.remove(splineSeries.at(0).x, splineSeries.at(0).y);
128 scatterSeries.remove(scatterSeries.at(0).x, scatterSeries.at(0).y);
139 scatterSeries.remove(scatterSeries.at(0).x, scatterSeries.at(0).y);
129 }
140 }
130 compare(lineSeries.count, 0);
141 compare(lineSeries.count, 0);
131 compare(splineSeries.count, 0);
142 compare(splineSeries.count, 0);
132 compare(scatterSeries.count, 0);
143 compare(scatterSeries.count, 0);
133 tryCompare(lineSeriesPointRemovedSpy.count, count);
144 tryCompare(lineSeriesPointRemovedSpy.count, count);
134 tryCompare(splineSeriesPointRemovedSpy.count, count);
145 tryCompare(splineSeriesPointRemovedSpy.count, count);
135 tryCompare(scatterSeriesPointRemovedSpy.count, count);
146 tryCompare(scatterSeriesPointRemovedSpy.count, count);
136 }
147 }
137
148
138 // Not a test function, called from test functions
149 // Not a test function, called from test functions
139 function append() {
150 function append() {
140 var count = 100;
151 var count = 100;
141 chartView.axisX().min = 0;
152 chartView.axisX().min = 0;
142 chartView.axisX().max = 100;
153 chartView.axisX().max = 100;
143 chartView.axisY().min = 0;
154 chartView.axisY().min = 0;
144 chartView.axisY().max = 1;
155 chartView.axisY().max = 1;
145
156
146 for (var i = 0; i < count; i++) {
157 for (var i = 0; i < count; i++) {
147 lineSeries.append(i, Math.random());
158 lineSeries.append(i, Math.random());
148 splineSeries.append(i, Math.random());
159 splineSeries.append(i, Math.random());
149 scatterSeries.append(i, Math.random());
160 scatterSeries.append(i, Math.random());
150 }
161 }
151
162
152 return count;
163 return count;
153 }
164 }
154
165
155 // Not a test function, called from test functions
166 // Not a test function, called from test functions
156 function clear() {
167 function clear() {
157 lineSeries.clear();
168 lineSeries.clear();
158 splineSeries.clear();
169 splineSeries.clear();
159 scatterSeries.clear();
170 scatterSeries.clear();
160 }
171 }
161 }
172 }
162
173
163 ChartView {
174 ChartView {
164 id: chartView
175 id: chartView
165 anchors.fill: parent
176 anchors.fill: parent
166
177
167 LineSeries {
178 LineSeries {
168 id: lineSeries
179 id: lineSeries
169 name: "line"
180 name: "line"
170
181
171 SignalSpy {
182 SignalSpy {
172 id: lineSeriesPointAddedSpy
183 id: lineSeriesPointAddedSpy
173 target: lineSeries
184 target: lineSeries
174 signalName: "pointAdded"
185 signalName: "pointAdded"
175 }
186 }
176
187
177 SignalSpy {
188 SignalSpy {
178 id: lineSeriesPointReplacedSpy
189 id: lineSeriesPointReplacedSpy
179 target: lineSeries
190 target: lineSeries
180 signalName: "pointReplaced"
191 signalName: "pointReplaced"
181 }
192 }
182
193
183 SignalSpy {
194 SignalSpy {
184 id: lineSeriesPointsReplacedSpy
195 id: lineSeriesPointsReplacedSpy
185 target: lineSeries
196 target: lineSeries
186 signalName: "pointsReplaced"
197 signalName: "pointsReplaced"
187 }
198 }
188
199
189 SignalSpy {
200 SignalSpy {
190 id: lineSeriesPointRemovedSpy
201 id: lineSeriesPointRemovedSpy
191 target: lineSeries
202 target: lineSeries
192 signalName: "pointRemoved"
203 signalName: "pointRemoved"
193 }
204 }
194 }
205 }
195
206
196 AreaSeries {
207 AreaSeries {
197 id: areaSeries
208 id: areaSeries
198 name: "area"
209 name: "area"
199 upperSeries: lineSeries
210 upperSeries: lineSeries
200 }
211 }
201
212
202 SplineSeries {
213 SplineSeries {
203 id: splineSeries
214 id: splineSeries
204 name: "spline"
215 name: "spline"
205
216
206 SignalSpy {
217 SignalSpy {
207 id: splineSeriesPointAddedSpy
218 id: splineSeriesPointAddedSpy
208 target: splineSeries
219 target: splineSeries
209 signalName: "pointAdded"
220 signalName: "pointAdded"
210 }
221 }
211
222
212 SignalSpy {
223 SignalSpy {
213 id: splineSeriesPointReplacedSpy
224 id: splineSeriesPointReplacedSpy
214 target: splineSeries
225 target: splineSeries
215 signalName: "pointReplaced"
226 signalName: "pointReplaced"
216 }
227 }
217
228
218 SignalSpy {
229 SignalSpy {
219 id: splineSeriesPointsReplacedSpy
230 id: splineSeriesPointsReplacedSpy
220 target: splineSeries
231 target: splineSeries
221 signalName: "pointsReplaced"
232 signalName: "pointsReplaced"
222 }
233 }
223
234
224 SignalSpy {
235 SignalSpy {
225 id: splineSeriesPointRemovedSpy
236 id: splineSeriesPointRemovedSpy
226 target: splineSeries
237 target: splineSeries
227 signalName: "pointRemoved"
238 signalName: "pointRemoved"
228 }
239 }
229 }
240 }
230
241
231 ScatterSeries {
242 ScatterSeries {
232 id: scatterSeries
243 id: scatterSeries
233 name: "scatter"
244 name: "scatter"
234
245
235 SignalSpy {
246 SignalSpy {
236 id: scatterSeriesPointAddedSpy
247 id: scatterSeriesPointAddedSpy
237 target: scatterSeries
248 target: scatterSeries
238 signalName: "pointAdded"
249 signalName: "pointAdded"
239 }
250 }
240
251
241 SignalSpy {
252 SignalSpy {
242 id: scatterSeriesPointReplacedSpy
253 id: scatterSeriesPointReplacedSpy
243 target: scatterSeries
254 target: scatterSeries
244 signalName: "pointReplaced"
255 signalName: "pointReplaced"
245 }
256 }
246
257
247 SignalSpy {
258 SignalSpy {
248 id: scatterSeriesPointsReplacedSpy
259 id: scatterSeriesPointsReplacedSpy
249 target: scatterSeries
260 target: scatterSeries
250 signalName: "pointsReplaced"
261 signalName: "pointsReplaced"
251 }
262 }
252
263
253 SignalSpy {
264 SignalSpy {
254 id: scatterSeriesPointRemovedSpy
265 id: scatterSeriesPointRemovedSpy
255 target: scatterSeries
266 target: scatterSeries
256 signalName: "pointRemoved"
267 signalName: "pointRemoved"
257 }
268 }
258 }
269 }
259 }
270 }
260 }
271 }
General Comments 0
You need to be logged in to leave comments. Login now