##// END OF EJS Templates
Added test case to tst_qlineseries
Marek Rosa -
r1071:da6f7932fa27
parent child
Show More
@@ -1,457 +1,470
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 #include <QtTest/QtTest>
22 22 #include <qlineseries.h>
23 23 #include <qchartview.h>
24 #include <QStandardItemModel>
24 25
25 26 Q_DECLARE_METATYPE(QList<QPointF>)
26 27
27 28 QTCOMMERCIALCHART_USE_NAMESPACE
28 29
29 30 class tst_QLineSeries : public QObject
30 31 {
31 32 Q_OBJECT
32 33
33 34 public slots:
34 35 void initTestCase();
35 36 void cleanupTestCase();
36 37 void init();
37 38 void cleanup();
38 39
39 40 private slots:
40 41 void qlineseries_data();
41 42 void qlineseries();
42 43 void append_raw_data();
43 44 void append_raw();
44 45 void append_chart_data();
45 46 void append_chart();
46 47 void append_chart_animation_data();
47 48 void append_chart_animation();
48 49 void chart_append_data();
49 50 void chart_append();
50 51 void count_raw_data();
51 52 void count_raw();
52 53 void oper_data();
53 54 void oper();
54 55 void pen_data();
55 56 void pen();
56 57 void pointsVisible_raw_data();
57 58 void pointsVisible_raw();
58 59 void remove_raw_data();
59 60 void remove_raw();
60 61 void remove_chart_data();
61 62 void remove_chart();
62 63 void remove_chart_animation_data();
63 64 void remove_chart_animation();
64 65 void removeAll_data();
65 66 void removeAll();
66 67 void replace_data();
67 68 void replace();
68 69 void setModel_data();
69 70 void setModel();
70 71 void setModelMapping_data();
71 72 void setModelMapping();
72 73 private:
73 74 void append_data();
74 75 void count_data();
75 76 void pointsVisible_data();
76 77
77 78 private:
78 79 QChartView* m_view;
79 80 QChart* m_chart;
80 81 QLineSeries* m_series;
81 82 };
82 83
83 84 void tst_QLineSeries::initTestCase()
84 85 {
85 86 }
86 87
87 88 void tst_QLineSeries::cleanupTestCase()
88 89 {
89 90 }
90 91
91 92 void tst_QLineSeries::init()
92 93 {
93 94 m_view = new QChartView(new QChart());
94 95 m_chart = m_view->chart();
95 96 m_series = new QLineSeries();
96 97 }
97 98
98 99 void tst_QLineSeries::cleanup()
99 100 {
100 101 delete m_series;
101 102 delete m_view;
102 103 m_view = 0;
103 104 m_chart = 0;
104 105 m_series = 0;
105 106 }
106 107
107 108 void tst_QLineSeries::qlineseries_data()
108 109 {
109 110
110 111 }
111 112
112 113 void tst_QLineSeries::qlineseries()
113 114 {
114 115 QLineSeries series;
115 116
116 117 QCOMPARE(series.count(),0);
117 118 QCOMPARE(series.brush(), QBrush());
118 119 QCOMPARE(series.points(), QList<QPointF>());
119 120 QCOMPARE(series.pen(), QPen());
120 121 QCOMPARE(series.pointsVisible(), false);
121 122
122 123 series.append(QList<QPointF>());
123 124 series.append(0.0,0.0);
124 125 series.append(QPointF());
125 126
126 127 series.remove(0.0,0.0);
127 128 series.remove(QPointF());
128 129 series.removeAll();
129 130
130 131 series.replace(QPointF(),QPointF());
131 132 series.replace(0,0,0,0);
132 133 series.setBrush(QBrush());
133 134
134 135 QCOMPARE(series.setModel((QAbstractItemModel*)0), false);
135 136
136 137 series.setModelMapping(-1, -1, Qt::Orientation(0));
137 138
138 139 series.setPen(QPen());
139 140 series.setPointsVisible(false);
140 141
141 142 m_chart->addSeries(&series);
142 143 m_view->show();
143 144 QTest::qWaitForWindowShown(m_view);
144 145 }
145 146
146 147 void tst_QLineSeries::append_data()
147 148 {
148 149 QTest::addColumn< QList<QPointF> >("points");
149 150 QTest::newRow("0,0 1,1 2,2 3,3") << (QList<QPointF>() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3));
150 151 QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList<QPointF>() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3));
151 152 }
152 153
153 154
154 155 void tst_QLineSeries::append_raw_data()
155 156 {
156 157 append_data();
157 158 }
158 159
159 160 void tst_QLineSeries::append_raw()
160 161 {
161 162 QFETCH(QList<QPointF>, points);
162 163 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
163 164 QTest::qWait(200);
164 165 m_series->append(points);
165 166 QTest::qWait(200);
166 167 QCOMPARE(spy0.count(), 0);
167 168 QCOMPARE(m_series->points(), points);
168 169 }
169 170
170 171 void tst_QLineSeries::chart_append_data()
171 172 {
172 173 append_data();
173 174 }
174 175
175 176 void tst_QLineSeries::chart_append()
176 177 {
177 178 append_raw();
178 179 m_chart->addSeries(m_series);
179 180 m_view->show();
180 181 QTest::qWaitForWindowShown(m_view);
181 182 }
182 183
183 184 void tst_QLineSeries::append_chart_data()
184 185 {
185 186 append_data();
186 187 }
187 188
188 189 void tst_QLineSeries::append_chart()
189 190 {
190 191 m_view->show();
191 192 m_chart->addSeries(m_series);
192 193 append_raw();
193 194 QTest::qWaitForWindowShown(m_view);
194 195 }
195 196
196 197 void tst_QLineSeries::append_chart_animation_data()
197 198 {
198 199 append_data();
199 200 }
200 201
201 202 void tst_QLineSeries::append_chart_animation()
202 203 {
203 204 m_chart->setAnimationOptions(QChart::AllAnimations);
204 205 append_chart();
205 206 }
206 207
207 208 void tst_QLineSeries::count_data()
208 209 {
209 210 QTest::addColumn<int>("count");
210 211 QTest::newRow("0") << 0;
211 212 QTest::newRow("5") << 5;
212 213 QTest::newRow("10") << 5;
213 214 }
214 215
215 216 void tst_QLineSeries::count_raw_data()
216 217 {
217 218 count_data();
218 219 }
219 220
220 221 void tst_QLineSeries::count_raw()
221 222 {
222 223 QFETCH(int, count);
223 224
224 225 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
225 226
226 227 for(int i=0 ; i< count; ++i)
227 228 m_series->append(i,i);
228 229
229 230 QCOMPARE(spy0.count(), 0);
230 231 QCOMPARE(m_series->count(), count);
231 232 }
232 233
233 234 void tst_QLineSeries::oper_data()
234 235 {
235 236 append_data();
236 237 }
237 238
238 239 void tst_QLineSeries::oper()
239 240 {
240 241 QFETCH(QList<QPointF>, points);
241 242 QLineSeries series;
242 243
243 244 QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&)));
244 245
245 246 foreach(const QPointF& point,points)
246 247 {
247 248 series<<point;
248 249 }
249 250
250 251 QCOMPARE(series.points(), points);
251 252 QCOMPARE(spy0.count(), 0);
252 253 }
253 254
254 255
255 256 void tst_QLineSeries::pen_data()
256 257 {
257 258 QTest::addColumn<QPen>("pen");
258 259 QTest::newRow("null") << QPen();
259 260 QTest::newRow("blue") << QPen(Qt::blue);
260 261 QTest::newRow("black") << QPen(Qt::black);
261 262 QTest::newRow("red") << QPen(Qt::red);
262 263 }
263 264
264 265 void tst_QLineSeries::pen()
265 266 {
266 267 QFETCH(QPen, pen);
267 268 QLineSeries series;
268 269
269 270 QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&)));
270 271 series.setPen(pen);
271 272
272 273 QCOMPARE(spy0.count(), 0);
273 274 QCOMPARE(series.pen(), pen);
274 275
275 276 m_chart->addSeries(&series);
276 277
277 278 if(pen!=QPen()) QCOMPARE(series.pen(), pen);
278 279 }
279 280
280 281 void tst_QLineSeries::pointsVisible_data()
281 282 {
282 283 QTest::addColumn<bool>("pointsVisible");
283 284 QTest::newRow("true") << true;
284 285 QTest::newRow("false") << false;
285 286 }
286 287
287 288 void tst_QLineSeries::pointsVisible_raw_data()
288 289 {
289 290 pointsVisible_data();
290 291 }
291 292
292 293 void tst_QLineSeries::pointsVisible_raw()
293 294 {
294 295 QFETCH(bool, pointsVisible);
295 296 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
296 297 m_series->setPointsVisible(pointsVisible);
297 298 QCOMPARE(spy0.count(), 0);
298 299 QCOMPARE(m_series->pointsVisible(), pointsVisible);
299 300 }
300 301
301 302 void tst_QLineSeries::remove_raw_data()
302 303 {
303 304 append_data();
304 305 }
305 306
306 307 void tst_QLineSeries::remove_raw()
307 308 {
308 309 QFETCH(QList<QPointF>, points);
309 310 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
310 311 m_series->append(points);
311 312 QTest::qWait(200);
312 313 QCOMPARE(spy0.count(), 0);
313 314 QCOMPARE(m_series->points(), points);
314 315
315 316 foreach(const QPointF& point,points)
316 317 {
317 318 m_series->remove(point);
318 319 QTest::qWait(200);
319 320 }
320 321
321 322 QCOMPARE(spy0.count(), 0);
322 323 QCOMPARE(m_series->points().count(), 0);
323 324 }
324 325
325 326 void tst_QLineSeries::remove_chart_data()
326 327 {
327 328 append_data();
328 329 }
329 330
330 331 void tst_QLineSeries::remove_chart()
331 332 {
332 333 m_view->show();
333 334 m_chart->addSeries(m_series);
334 335 remove_raw();
335 336 QTest::qWaitForWindowShown(m_view);
336 337 }
337 338
338 339 void tst_QLineSeries::remove_chart_animation_data()
339 340 {
340 341 append_data();
341 342 }
342 343
343 344 void tst_QLineSeries::remove_chart_animation()
344 345 {
345 346 m_chart->setAnimationOptions(QChart::AllAnimations);
346 347 remove_chart();
347 348 }
348 349
349 350
350 351 void tst_QLineSeries::removeAll_data()
351 352 {
352 353 append_data();
353 354 }
354 355
355 356 void tst_QLineSeries::removeAll()
356 357 {
357 358 #if 0
358 359 QFETCH(int, foo);
359 360
360 361 SubQXYSeries series;
361 362
362 363 QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&)));
363 364 QSignalSpy spy1(&series, SIGNAL(selected()));
364 365
365 366 series.removeAll();
366 367
367 368 QCOMPARE(spy0.count(), 0);
368 369 QCOMPARE(spy1.count(), 0);
369 370 #endif
370 371 QSKIP("Test is not implemented.", SkipAll);
371 372 }
372 373
373 374 void tst_QLineSeries::replace_data()
374 375 {
375 376 QTest::addColumn<QPointF>("point");
376 377 QTest::newRow("null") << QPointF();
377 378 }
378 379
379 380 void tst_QLineSeries::replace()
380 381 {
381 382 #if 0
382 383 QFETCH(QPointF, point);
383 384
384 385 SubQXYSeries series;
385 386
386 387 QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&)));
387 388 QSignalSpy spy1(&series, SIGNAL(selected()));
388 389
389 390 series.replace(point);
390 391
391 392 QCOMPARE(spy0.count(), 0);
392 393 QCOMPARE(spy1.count(), 0);
393 394 #endif
394 395 QSKIP("Test is not implemented.", SkipAll);
395 396 }
396 397
397 398 void tst_QLineSeries::setModel_data()
398 399 {
399 400 QTest::addColumn<int>("modelCount");
400 401 QTest::addColumn<bool>("setModel");
401 402 QTest::newRow("null") << 0 << false;
402 403 }
403 404
404 405 void tst_QLineSeries::setModel()
405 406 {
406 407 #if 0
407 408 QFETCH(int, modelCount);
408 409 QFETCH(bool, setModel);
409 410
410 411 SubQXYSeries series;
411 412
412 413 QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&)));
413 414 QSignalSpy spy1(&series, SIGNAL(selected()));
414 415
415 416 QCOMPARE(series.setModel(model), setModel);
416 417
417 418 QCOMPARE(spy0.count(), 0);
418 419 QCOMPARE(spy1.count(), 0);
419 420 #endif
420 421 QSKIP("Test is not implemented.", SkipAll);
421 422 }
422 423
423 424 Q_DECLARE_METATYPE(Qt::Orientation)
424 425 void tst_QLineSeries::setModelMapping_data()
425 426 {
426 #if 0
427 427 QTest::addColumn<int>("modelX");
428 428 QTest::addColumn<int>("modelY");
429 429 QTest::addColumn<Qt::Orientation>("orientation");
430 QTest::newRow("null") << 0 << 0 << Qt::Orientation();
431 #endif
430 QTest::newRow("different x and y, vertical") << 0 << 1 << Qt::Vertical;
431 QTest::newRow("same x and y, vertical") << 0 << 0 << Qt::Vertical;
432 QTest::newRow("invalid x, corrent y, vertical") << -1 << 1 << Qt::Vertical;
433
434 QTest::newRow("different x and y, horizontal") << 0 << 1 << Qt::Horizontal;
435 QTest::newRow("same x and y, horizontal") << 0 << 0 << Qt::Horizontal;
436 QTest::newRow("invalid x, corrent y, horizontal") << -1 << 1 << Qt::Horizontal;
432 437 }
433 438
434 439 void tst_QLineSeries::setModelMapping()
435 440 {
436 #if 0
437 441 QFETCH(int, modelX);
438 442 QFETCH(int, modelY);
439 443 QFETCH(Qt::Orientation, orientation);
440 444
441 SubQXYSeries series;
442
443 QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&)));
444 QSignalSpy spy1(&series, SIGNAL(selected()));
445 QLineSeries series;
445 446
447 // model has not been set so setting mapping should do nothing
446 448 series.setModelMapping(modelX, modelY, orientation);
449 QCOMPARE(series.mapX(), -1);
450 QCOMPARE(series.mapY(), -1);
451 QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical");
447 452
448 QCOMPARE(spy0.count(), 0);
449 QCOMPARE(spy1.count(), 0);
450 #endif
451 QSKIP("Test is not implemented.", SkipAll);
453 // now let us set the model
454 series.setModel(new QStandardItemModel());
455 series.setModelMapping(modelX, modelY, orientation);
456 QCOMPARE(series.mapX(), modelX);
457 QCOMPARE(series.mapY(), modelY);
458 QVERIFY2(series.mapOrientation() == orientation, "not good");
459
460 // now let us remove the model, the values should go back to default ones.
461 series.setModel(0);
462 QCOMPARE(series.mapX(), -1);
463 QCOMPARE(series.mapY(), -1);
464 QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical");
452 465 }
453 466
454 467 QTEST_MAIN(tst_QLineSeries)
455 468
456 469 #include "tst_qlineseries.moc"
457 470
General Comments 0
You need to be logged in to leave comments. Login now