##// END OF EJS Templates
clearWithAnimations() test case is skipped. Known issue. Won't be fixed for beta
Marek Rosa -
r1413:48d5d53f1f4a
parent child
Show More
@@ -1,514 +1,515
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 <qbarseries.h>
23 23 #include <qbarset.h>
24 24 #include <qchartview.h>
25 25 #include <qchart.h>
26 26
27 27 QTCOMMERCIALCHART_USE_NAMESPACE
28 28
29 29 Q_DECLARE_METATYPE(QBarSet*)
30 30
31 31 class tst_QBarSeries : public QObject
32 32 {
33 33 Q_OBJECT
34 34
35 35 public slots:
36 36 void initTestCase();
37 37 void cleanupTestCase();
38 38 void init();
39 39 void cleanup();
40 40
41 41 private slots:
42 42 void qbarseries_data();
43 43 void qbarseries();
44 44 void type_data();
45 45 void type();
46 46 void append_data();
47 47 void append();
48 48 void remove_data();
49 49 void remove();
50 50 void appendList_data();
51 51 void appendList();
52 52 void barsetCount_data();
53 53 void barsetCount();
54 54 void barSets_data();
55 55 void barSets();
56 56 void setLabelsVisible_data();
57 57 void setLabelsVisible();
58 58 void mouseclicked_data();
59 59 void mouseclicked();
60 60 void mousehovered_data();
61 61 void mousehovered();
62 62 void clearWithAnimations();
63 63
64 64 private:
65 65 QBarSeries* m_barseries;
66 66 QBarSeries* m_barseries_with_sets;
67 67
68 68 QList<QBarSet*> m_testSets;
69 69
70 70 };
71 71
72 72 void tst_QBarSeries::initTestCase()
73 73 {
74 74 qRegisterMetaType<QBarSet*>("QBarSet*");
75 75 }
76 76
77 77 void tst_QBarSeries::cleanupTestCase()
78 78 {
79 79 }
80 80
81 81 void tst_QBarSeries::init()
82 82 {
83 83 m_barseries = new QBarSeries();
84 84 m_barseries_with_sets = new QBarSeries();
85 85
86 86 for (int i=0; i<5; i++) {
87 87 m_testSets.append(new QBarSet("testset"));
88 88 m_barseries_with_sets->append(m_testSets.at(i));
89 89 }
90 90 }
91 91
92 92 void tst_QBarSeries::cleanup()
93 93 {
94 94 foreach(QBarSet* s, m_testSets) {
95 95 m_barseries_with_sets->remove(s);
96 96 delete s;
97 97 }
98 98 m_testSets.clear();
99 99
100 100 delete m_barseries;
101 101 m_barseries = 0;
102 102 delete m_barseries_with_sets;
103 103 m_barseries_with_sets = 0;
104 104 }
105 105
106 106 void tst_QBarSeries::qbarseries_data()
107 107 {
108 108 }
109 109
110 110 void tst_QBarSeries::qbarseries()
111 111 {
112 112 QBarSeries *barseries = new QBarSeries();
113 113 QVERIFY(barseries != 0);
114 114 }
115 115
116 116 void tst_QBarSeries::type_data()
117 117 {
118 118
119 119 }
120 120
121 121 void tst_QBarSeries::type()
122 122 {
123 123 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar);
124 124 }
125 125
126 126 void tst_QBarSeries::append_data()
127 127 {
128 128 }
129 129
130 130 void tst_QBarSeries::append()
131 131 {
132 132 QVERIFY(m_barseries->barsetCount() == 0);
133 133
134 134 bool ret = false;
135 135
136 136 // Try adding barset
137 137 QBarSet *barset = new QBarSet("testset");
138 138 ret = m_barseries->append(barset);
139 139
140 140 QVERIFY(ret == true);
141 141 QVERIFY(m_barseries->barsetCount() == 1);
142 142
143 143 // Try adding another set
144 144 QBarSet *barset2 = new QBarSet("testset2");
145 145 ret = m_barseries->append(barset2);
146 146
147 147 QVERIFY(ret == true);
148 148 QVERIFY(m_barseries->barsetCount() == 2);
149 149
150 150 // Try adding same set again
151 151 ret = m_barseries->append(barset2);
152 152 QVERIFY(ret == false);
153 153 QVERIFY(m_barseries->barsetCount() == 2);
154 154
155 155 // Try adding null set
156 156 ret = m_barseries->append(0);
157 157 QVERIFY(ret == false);
158 158 QVERIFY(m_barseries->barsetCount() == 2);
159 159
160 160 }
161 161
162 162 void tst_QBarSeries::remove_data()
163 163 {
164 164 }
165 165
166 166 void tst_QBarSeries::remove()
167 167 {
168 168 int count = m_testSets.count();
169 169 QVERIFY(m_barseries_with_sets->barsetCount() == count);
170 170
171 171 // Try to remove null pointer (should not remove, should not crash)
172 172 bool ret = false;
173 173 ret = m_barseries_with_sets->remove(0);
174 174 QVERIFY(ret == false);
175 175 QVERIFY(m_barseries_with_sets->barsetCount() == count);
176 176
177 177 // Try to remove invalid pointer (should not remove, should not crash)
178 178 ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) );
179 179 QVERIFY(ret == false);
180 180 QVERIFY(m_barseries_with_sets->barsetCount() == count);
181 181
182 182 // remove some sets
183 183 ret = m_barseries_with_sets->remove(m_testSets.at(2));
184 184 QVERIFY(ret == true);
185 185 ret = m_barseries_with_sets->remove(m_testSets.at(3));
186 186 QVERIFY(ret == true);
187 187 ret = m_barseries_with_sets->remove(m_testSets.at(4));
188 188 QVERIFY(ret == true);
189 189
190 190 QVERIFY(m_barseries_with_sets->barsetCount() == 2);
191 191
192 192 QList<QBarSet*> verifysets = m_barseries_with_sets->barSets();
193 193
194 194 QVERIFY(verifysets.at(0) == m_testSets.at(0));
195 195 QVERIFY(verifysets.at(1) == m_testSets.at(1));
196 196
197 197 // Try removing all sets again (should be ok, even if some sets have already been removed)
198 198 ret = false;
199 199 for (int i=0; i<count; i++) {
200 200 ret |= m_barseries_with_sets->remove(m_testSets.at(i));
201 201 }
202 202
203 203 QVERIFY(ret == true);
204 204 QVERIFY(m_barseries_with_sets->barsetCount() == 0);
205 205 }
206 206
207 207 void tst_QBarSeries::appendList_data()
208 208 {
209 209
210 210 }
211 211
212 212 void tst_QBarSeries::appendList()
213 213 {
214 214 int count = 5;
215 215 QVERIFY(m_barseries->barsetCount() == 0);
216 216
217 217 QList<QBarSet*> sets;
218 218 for (int i=0; i<count; i++) {
219 219 sets.append(new QBarSet("testset"));
220 220 }
221 221
222 222 // Append new sets (should succeed, count should match the count of sets)
223 223 bool ret = false;
224 224 ret = m_barseries->append(sets);
225 225 QVERIFY(ret == true);
226 226 QVERIFY(m_barseries->barsetCount() == count);
227 227
228 228 // Append same sets again (should fail, count should remain same)
229 229 ret = m_barseries->append(sets);
230 230 QVERIFY(ret == false);
231 231 QVERIFY(m_barseries->barsetCount() == count);
232 232
233 233 // Try append empty list (should succeed, but count should remain same)
234 234 QList<QBarSet*> invalidList;
235 235 ret = m_barseries->append(invalidList);
236 236 QVERIFY(ret == true);
237 237 QVERIFY(m_barseries->barsetCount() == count);
238 238
239 239 // Try append list with one new and one existing set (should fail, count remains same)
240 240 invalidList.append(new QBarSet("ok set"));
241 241 invalidList.append(sets.at(0));
242 242 ret = m_barseries->append(invalidList);
243 243 QVERIFY(ret == false);
244 244 QVERIFY(m_barseries->barsetCount() == count);
245 245
246 246 // Try append list with null pointers (should fail, count remains same)
247 247 QList<QBarSet*> invalidList2;
248 248 invalidList2.append(0);
249 249 invalidList2.append(0);
250 250 invalidList2.append(0);
251 251 ret = m_barseries->append(invalidList2);
252 252 QVERIFY(ret == false);
253 253 QVERIFY(m_barseries->barsetCount() == count);
254 254 }
255 255
256 256 void tst_QBarSeries::barsetCount_data()
257 257 {
258 258
259 259 }
260 260
261 261 void tst_QBarSeries::barsetCount()
262 262 {
263 263 QVERIFY(m_barseries->barsetCount() == 0);
264 264 QVERIFY(m_barseries_with_sets->barsetCount() == m_testSets.count());
265 265 }
266 266
267 267 void tst_QBarSeries::barSets_data()
268 268 {
269 269
270 270 }
271 271
272 272 void tst_QBarSeries::barSets()
273 273 {
274 274 QVERIFY(m_barseries->barSets().count() == 0);
275 275
276 276 QList<QBarSet*> sets = m_barseries_with_sets->barSets();
277 277 QVERIFY(sets.count() == m_testSets.count());
278 278
279 279 for (int i=0; i<m_testSets.count(); i++) {
280 280 QVERIFY(sets.at(i) == m_testSets.at(i));
281 281 }
282 282 }
283 283
284 284 void tst_QBarSeries::setLabelsVisible_data()
285 285 {
286 286
287 287 }
288 288
289 289 void tst_QBarSeries::setLabelsVisible()
290 290 {
291 291 // labels should be invisible by default
292 292 QVERIFY(m_barseries->isLabelsVisible() == false);
293 293 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
294 294
295 295 // turn labels to visible
296 296 m_barseries_with_sets->setLabelsVisible(true);
297 297 // TODO: test the signal
298 298 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
299 299
300 300 // turn labels to invisible
301 301 m_barseries_with_sets->setLabelsVisible(false);
302 302 // TODO: test the signal
303 303 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
304 304
305 305 // without parameter, should turn labels to visible
306 306 m_barseries_with_sets->setLabelsVisible();
307 307 // TODO: test the signal
308 308 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
309 309 }
310 310
311 311 void tst_QBarSeries::mouseclicked_data()
312 312 {
313 313
314 314 }
315 315
316 316 void tst_QBarSeries::mouseclicked()
317 317 {
318 318 QBarSeries* series = new QBarSeries();
319 319
320 320 QBarSet* set1 = new QBarSet(QString("set 1"));
321 321 *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10);
322 322 series->append(set1);
323 323
324 324 QBarSet* set2 = new QBarSet(QString("set 2"));
325 325 *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
326 326 series->append(set2);
327 327
328 328 QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*,int)));
329 329
330 330 QChartView view(new QChart());
331 331 view.resize(400,300);
332 332 view.chart()->addSeries(series);
333 333 view.show();
334 334 QTest::qWaitForWindowShown(&view);
335 335
336 336 //====================================================================================
337 337 // barset 1, bar 0
338 338 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(95,142));
339 339 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
340 340
341 341 QCOMPARE(seriesSpy.count(), 1);
342 342
343 343 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
344 344 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
345 345 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
346 346 QVERIFY(seriesSpyArg.at(1).toInt() == 0);
347 347
348 348 //====================================================================================
349 349 // barset 1, bar 1
350 350 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(164,142));
351 351 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
352 352
353 353 QCOMPARE(seriesSpy.count(), 1);
354 354
355 355 seriesSpyArg = seriesSpy.takeFirst();
356 356 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
357 357 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
358 358 QVERIFY(seriesSpyArg.at(1).toInt() == 1);
359 359
360 360 //====================================================================================
361 361 // barset 1, bar 2
362 362 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(234,142));
363 363 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
364 364
365 365 QCOMPARE(seriesSpy.count(), 1);
366 366
367 367 seriesSpyArg = seriesSpy.takeFirst();
368 368 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
369 369 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
370 370 QVERIFY(seriesSpyArg.at(1).toInt() == 2);
371 371
372 372 //====================================================================================
373 373 // barset 2, bar 0
374 374 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(115,142));
375 375 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
376 376
377 377 QCOMPARE(seriesSpy.count(), 1);
378 378
379 379 seriesSpyArg = seriesSpy.takeFirst();
380 380 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
381 381 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
382 382 QVERIFY(seriesSpyArg.at(1).toInt() == 0);
383 383
384 384 //====================================================================================
385 385 // barset 2, bar 1
386 386 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(185,142));
387 387 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
388 388
389 389 QCOMPARE(seriesSpy.count(), 1);
390 390
391 391 seriesSpyArg = seriesSpy.takeFirst();
392 392 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
393 393 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
394 394 QVERIFY(seriesSpyArg.at(1).toInt() == 1);
395 395
396 396 //====================================================================================
397 397 // barset 2, bar 2
398 398 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(254,142));
399 399 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
400 400
401 401 QCOMPARE(seriesSpy.count(), 1);
402 402
403 403 seriesSpyArg = seriesSpy.takeFirst();
404 404 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
405 405 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
406 406 QVERIFY(seriesSpyArg.at(1).toInt() == 2);
407 407 }
408 408
409 409 void tst_QBarSeries::mousehovered_data()
410 410 {
411 411
412 412 }
413 413
414 414 void tst_QBarSeries::mousehovered()
415 415 {
416 416 QBarSeries* series = new QBarSeries();
417 417 QStringList categories;
418 418 categories << "test1" << "test2" << "test3";
419 419 // series->setCategories(categories);
420 420
421 421 QBarSet* set1 = new QBarSet(QString("set 1"));
422 422 *set1 << QPointF(0.1,10) << QPointF(1.1,10) << QPointF(2.1,10);
423 423 series->append(set1);
424 424
425 425 QBarSet* set2 = new QBarSet(QString("set 2"));
426 426 *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
427 427 series->append(set2);
428 428
429 429 QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool)));
430 430
431 431 QChartView view(new QChart());
432 432 view.resize(400,300);
433 433 view.chart()->addSeries(series);
434 434 view.show();
435 435 QTest::qWaitForWindowShown(&view);
436 436
437 437 //this is hack since view does not get events otherwise
438 438 view.setMouseTracking(true);
439 439
440 440 //=======================================================================
441 441 // move mouse to left border
442 442 QTest::mouseMove(view.viewport(), QPoint(0, 142));
443 443
444 444 QVERIFY(seriesSpy.count() == 0);
445 445
446 446 //=======================================================================
447 447 // move mouse on top of set1
448 448 QTest::mouseMove(view.viewport(), QPoint(95,142));
449 449
450 450 QVERIFY(seriesSpy.count() == 1);
451 451
452 452 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
453 453 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
454 454 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
455 455 QVERIFY(seriesSpyArg.at(1).toBool() == true);
456 456
457 457 //=======================================================================
458 458 // move mouse from top of set1 to top of set2
459 459 QTest::mouseMove(view.viewport(), QPoint(116,142));
460 460
461 461 QVERIFY(seriesSpy.count() == 2);
462 462
463 463 // should leave set1
464 464 seriesSpyArg = seriesSpy.takeFirst();
465 465 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
466 466 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
467 467 QVERIFY(seriesSpyArg.at(1).toBool() == false);
468 468
469 469 // should enter set2
470 470 seriesSpyArg = seriesSpy.takeFirst();
471 471 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
472 472 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
473 473 QVERIFY(seriesSpyArg.at(1).toBool() == true);
474 474
475 475 //=======================================================================
476 476 // move mouse from top of set2 to background
477 477 QTest::mouseMove(view.viewport(), QPoint(116,0));
478 478 QVERIFY(seriesSpy.count() == 1);
479 479
480 480 // should leave set2
481 481 seriesSpyArg = seriesSpy.takeFirst();
482 482 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
483 483 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
484 484 QVERIFY(seriesSpyArg.at(1).toBool() == false);
485 485 }
486 486
487 487 void tst_QBarSeries::clearWithAnimations()
488 488 {
489 QSKIP("Known issue with the animation handling", SkipAll);
489 490 QBarSeries* series = new QBarSeries();
490 491 QStringList categories;
491 492 categories << "test1" << "test2" << "test3";
492 493 // series->setCategories(categories);
493 494
494 495 QBarSet* set1 = new QBarSet(QString("set 1"));
495 496 *set1 << QPointF(0.1,10) << QPointF(1.1,10) << QPointF(2.1,10);
496 497 series->append(set1);
497 498
498 499 QBarSet* set2 = new QBarSet(QString("set 2"));
499 500 *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
500 501 series->append(set2);
501 502
502 503 QChartView view(new QChart());
503 504 view.resize(400,300);
504 505 view.chart()->setAnimationOptions(QChart::SeriesAnimations);
505 506 view.chart()->addSeries(series);
506 507 view.show();
507 508
508 509 series->clear();
509 510 }
510 511
511 512 QTEST_MAIN(tst_QBarSeries)
512 513
513 514 #include "tst_qbarseries.moc"
514 515
General Comments 0
You need to be logged in to leave comments. Login now