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