##// END OF EJS Templates
Adds chartdata unit test
Michal Klocek -
r224:0a6c58a44ab9
parent child
Show More
@@ -0,0 +1,2
1 TEMPLATE = subdirs
2 SUBDIRS += chartdataset No newline at end of file
@@ -0,0 +1,4
1 !include( ../test.pri ) {
2 error( "Couldn't find the test.pri file!" )
3 }
4 SOURCES += tst_chartdataset.cpp
This diff has been collapsed as it changes many lines, (526 lines changed) Show them Hide them
@@ -0,0 +1,526
1 #include <QtTest/QtTest>
2 #include <qchartaxis.h>
3 #include <qchartseries.h>
4 #include <qlinechartseries.h>
5 #include <private/chartdataset_p.h>
6 #include <private/domain_p.h>
7
8 QTCOMMERCIALCHART_USE_NAMESPACE
9
10 Q_DECLARE_METATYPE(Domain)
11 Q_DECLARE_METATYPE(QChartAxis*)
12 Q_DECLARE_METATYPE(QChartSeries*)
13 Q_DECLARE_METATYPE(QLineChartSeries*)
14
15 class tst_ChartDataSet: public QObject {
16 Q_OBJECT
17
18 public slots:
19 void initTestCase();
20 void cleanupTestCase();
21 void init();
22 void cleanup();
23
24 private slots:
25 void chartdataset_data();
26 void chartdataset();
27
28 void addDomain_data();
29 void addDomain();
30 void addSeries_data();
31 void addSeries();
32 void axisY_data();
33 void axisY();
34 void clearDomains_data();
35 void clearDomains();
36 void domain_data();
37 void domain();
38 void nextpreviousDomain_data();
39 void nextpreviousDomain();
40 void removeSeries_data();
41 void removeSeries();
42 };
43
44 void tst_ChartDataSet::initTestCase()
45 {
46 qRegisterMetaType<Domain>("Domain");
47 qRegisterMetaType<QChartAxis*>();
48 qRegisterMetaType<QChartSeries*>();
49 }
50
51 void tst_ChartDataSet::cleanupTestCase()
52 {
53 }
54
55 void tst_ChartDataSet::init()
56 {
57 }
58
59 void tst_ChartDataSet::cleanup()
60 {
61 }
62
63 void tst_ChartDataSet::chartdataset_data()
64 {
65 }
66
67 void tst_ChartDataSet::chartdataset()
68 {
69 ChartDataSet dataSet;
70 QVERIFY2(dataSet.axisX(), "Missing axisX.");
71 QVERIFY2(dataSet.axisY(), "Missing axisY.");
72 //check if not dangling pointer
73 dataSet.axisX()->objectName();
74 dataSet.axisY()->objectName();
75 QVERIFY(dataSet.domain(dataSet.axisX())==Domain());
76 QVERIFY(dataSet.domain(dataSet.axisY())==Domain());
77 QCOMPARE(dataSet.domainIndex(), 0);
78 }
79
80 void tst_ChartDataSet::addDomain_data()
81 {
82 QTest::addColumn<QRectF>("rect");
83 QTest::addColumn<QRectF>("viewport");
84 QTest::newRow("400x400,1000x1000") << QRectF(200, 200, 600, 600)
85 << QRectF(0, 0, 1000, 1000);
86 QTest::newRow("600x600,1000x1000") << QRectF(100, 100, 700, 700)
87 << QRectF(0, 0, 1000, 1000);
88 QTest::newRow("200x200,1000x1000") << QRectF(400, 400, 600, 600)
89 << QRectF(0, 0, 1000, 1000);
90 }
91
92 void tst_ChartDataSet::addDomain()
93 {
94 QFETCH(QRectF, rect);
95 QFETCH(QRectF, viewport);
96
97 ChartDataSet dataSet;
98
99 Domain domain1(0, 1000, 0, 1000);
100 QLineChartSeries series;
101 series.add(0, 0);
102 series.add(1000, 1000);
103
104 dataSet.addSeries(&series);
105
106 QCOMPARE(dataSet.domainIndex(), 0);
107
108 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
109 QSignalSpy spy1(&dataSet,
110 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
111 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
112 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
113 QSignalSpy spy4(&dataSet,
114 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
115 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
116
117 Domain domain2 = dataSet.domain(dataSet.axisY());
118 QVERIFY(domain1 == domain2);
119
120 dataSet.addDomain(rect, viewport);
121 QCOMPARE(dataSet.domainIndex(), 1);
122 Domain domain3 = dataSet.domain(dataSet.axisY());
123 Domain domain4 = domain1.subDomain(rect, viewport.width(),
124 viewport.height());
125 QVERIFY(domain3 == domain4);
126
127 QCOMPARE(spy0.count(), 0);
128 QCOMPARE(spy1.count(), 2);
129 QCOMPARE(spy2.count(), 0);
130 QCOMPARE(spy3.count(), 0);
131 QCOMPARE(spy4.count(), 1);
132 QCOMPARE(spy5.count(), 0);
133 }
134
135 void tst_ChartDataSet::addSeries_data()
136 {
137 QTest::addColumn<int>("seriesCount");
138 QTest::addColumn<int>("axisYCount");
139 QTest::newRow("2 series, default axis") << 2 << 0;
140 QTest::newRow("2 series, 2 new axis") << 2 << 2;
141 QTest::newRow("2 series, 1 new axis") << 2 << 2;
142 QTest::newRow("3 series, 3 new axis") << 3 << 3;
143 QTest::newRow("3 series, 2 new axis") << 3 << 2;
144 QTest::newRow("3 series, 1 new axis") << 3 << 1;
145 }
146
147 void tst_ChartDataSet::addSeries()
148 {
149 QFETCH(int, seriesCount);
150 QFETCH(int, axisYCount);
151
152 ChartDataSet dataSet;
153
154 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
155 QSignalSpy spy1(&dataSet,
156 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
157 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
158 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
159 QSignalSpy spy4(&dataSet,
160 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
161 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
162
163 QList<QChartAxis*> axisList;
164
165 for (int i = 0; i < axisYCount; i++) {
166 QChartAxis* axis = new QChartAxis();
167 axisList << axis;
168 }
169
170 QList<QChartAxis*>::iterator iterator = axisList.begin();
171
172 for (int i = 0; i < seriesCount; i++) {
173 QChartAxis* axisY = 0;
174 QLineChartSeries* series = new QLineChartSeries();
175 if (iterator != axisList.end()) {
176 axisY = *iterator;
177 iterator++;
178 } else if (axisList.count() > 0) {
179 iterator--;
180 axisY = *iterator;
181 iterator++;
182 }
183 dataSet.addSeries(series, axisY);
184 }
185
186 //default axis
187 if (axisYCount == 0)
188 axisYCount+=2;
189 else
190 axisYCount++;
191
192
193
194 QCOMPARE(spy0.count(), axisYCount);
195 QCOMPARE(spy1.count(), seriesCount*2);
196 QCOMPARE(spy2.count(), 0);
197 QCOMPARE(spy3.count(), seriesCount);
198 QCOMPARE(spy4.count(), seriesCount);
199 QCOMPARE(spy5.count(), 0);
200
201 QCOMPARE(dataSet.domainIndex(), 0);
202 }
203
204 void tst_ChartDataSet::axisY_data()
205 {
206 QTest::addColumn<QChartAxis*>("axisY");
207 QTest::newRow("axisY1") << new QChartAxis();
208 QTest::newRow("axisY2") << new QChartAxis();
209 }
210
211 void tst_ChartDataSet::axisY()
212 {
213 QFETCH(QChartAxis*, axisY);
214
215 ChartDataSet dataSet;
216
217 QChartAxis* defaultAxisY = dataSet.axisY();
218
219 QVERIFY2(defaultAxisY, "Missing axisY.");
220
221 QLineChartSeries series1;
222 dataSet.addSeries(&series1);
223
224 QLineChartSeries series2;
225 dataSet.addSeries(&series2, axisY);
226
227 QVERIFY(dataSet.axisY(&series1) == defaultAxisY);
228 QVERIFY(dataSet.axisY(&series2) == axisY);
229 }
230
231 void tst_ChartDataSet::clearDomains_data()
232 {
233 QTest::addColumn<int>("indexCount");
234 QTest::newRow("0") << 0;
235 QTest::newRow("1") << 1;
236 QTest::newRow("5") << 2;
237 QTest::newRow("8") << 3;
238 }
239
240 void tst_ChartDataSet::clearDomains()
241 {
242 QFETCH(int, indexCount);
243
244 Domain domain1(0, 100, 0, 100);
245 QLineChartSeries series;
246 series.add(0, 0);
247 series.add(100, 100);
248
249 ChartDataSet dataSet;
250
251 QCOMPARE(dataSet.domainIndex(), 0);
252
253 dataSet.addSeries(&series);
254
255 Domain domain2 = dataSet.domain(dataSet.axisY());
256
257 QVERIFY(domain2 == domain1);
258
259 QList<Domain> domains;
260
261 domains << domain1;
262
263 for (int i = 0; i < indexCount; i++) {
264 dataSet.addDomain(QRect(0, 0, 10, 10), QRect(0, 0, 100, 100));
265 domains << dataSet.domain(dataSet.axisY());
266 }
267
268 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
269 QSignalSpy spy1(&dataSet,
270 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
271 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
272 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
273 QSignalSpy spy4(&dataSet,
274 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
275 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
276
277 dataSet.clearDomains(indexCount);
278
279 QCOMPARE(dataSet.domainIndex(), indexCount);
280
281 domain2 = dataSet.domain(dataSet.axisY());
282
283 QVERIFY(domain2 == domains.at(indexCount));
284
285 QCOMPARE(spy0.count(), 0);
286 QCOMPARE(spy1.count(), 0);
287 QCOMPARE(spy2.count(), 0);
288 QCOMPARE(spy3.count(), 0);
289 QCOMPARE(spy4.count(), 0);
290 QCOMPARE(spy5.count(), 0);
291 }
292
293 void tst_ChartDataSet::domain_data()
294 {
295 QTest::addColumn<Domain>("domain1");
296 QTest::addColumn<Domain>("domain2");
297 QTest::addColumn<Domain>("domain3");
298 QTest::addColumn<Domain>("domain");
299 QTest::newRow("Domain(0,10,0,10)") << Domain(0, 10, 0, 10)
300 << Domain(0, 5, 0, 5) << Domain(0, 3, 0, 3) << Domain(0, 10, 0, 10);
301 QTest::newRow("Domain(-1,11,0,11)") << Domain(-1, 10, 0, 10)
302 << Domain(0, 11, 0, 11) << Domain(0, 3, 0, 3)
303 << Domain(-1, 11, 0, 11);
304 QTest::newRow("Domain(-5,5,1,8)") << Domain(-5, 0, 1, 1)
305 << Domain(0, 5, 0, 8) << Domain(1, 2, 1, 2) << Domain(-5, 5, 0, 8);
306 }
307
308 void tst_ChartDataSet::domain()
309 {
310 QFETCH(Domain, domain1);
311 QFETCH(Domain, domain2);
312 QFETCH(Domain, domain3);
313 QFETCH(Domain, domain);
314
315 ChartDataSet dataSet;
316 QLineChartSeries series1;
317 series1.add(domain1.m_minX, domain1.m_minY);
318 series1.add(domain1.m_maxX, domain1.m_maxY);
319 QLineChartSeries series2;
320 series2.add(domain2.m_minX, domain2.m_minY);
321 series2.add(domain2.m_maxX, domain2.m_maxY);
322 QLineChartSeries series3;
323 series3.add(domain3.m_minX, domain3.m_minY);
324 series3.add(domain3.m_maxX, domain3.m_maxY);
325
326 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
327 QSignalSpy spy1(&dataSet,
328 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
329 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
330 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
331 QSignalSpy spy4(&dataSet,
332 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
333 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
334
335 dataSet.addSeries(&series1);
336 dataSet.addSeries(&series2);
337 dataSet.addSeries(&series3);
338
339 QCOMPARE(dataSet.domainIndex(), 0);
340 QVERIFY2(dataSet.domain(dataSet.axisY()) == domain, "Domain not equal");
341
342 QCOMPARE(spy0.count(), 2);
343 QCOMPARE(spy1.count(), 6);
344 QCOMPARE(spy2.count(), 0);
345 QCOMPARE(spy3.count(), 3);
346 QCOMPARE(spy4.count(), 3);
347 QCOMPARE(spy5.count(), 0);
348 }
349
350 void tst_ChartDataSet::nextpreviousDomain_data()
351 {
352 QTest::addColumn<QRectF>("rect");
353 QTest::addColumn<QRectF>("viewport");
354 QTest::newRow("400x400,1000x1000") << QRectF(200, 200, 600, 600)
355 << QRectF(0, 0, 1000, 1000);
356 QTest::newRow("600x600,1000x1000") << QRectF(100, 100, 700, 700)
357 << QRectF(0, 0, 1000, 1000);
358 QTest::newRow("200x200,1000x1000") << QRectF(400, 400, 600, 600)
359 << QRectF(0, 0, 1000, 1000);
360 }
361
362 void tst_ChartDataSet::nextpreviousDomain()
363 {
364
365 QFETCH(QRectF, rect);
366 QFETCH(QRectF, viewport);
367
368 ChartDataSet dataSet;
369
370 Domain domain1(0, 1000, 0, 1000);
371 QLineChartSeries series;
372 series.add(0, 0);
373 series.add(1000, 1000);
374
375 dataSet.addSeries(&series);
376
377 QCOMPARE(dataSet.domainIndex(), 0);
378
379 Domain domain2 = dataSet.domain(dataSet.axisY());
380 QVERIFY(domain1 == domain2);
381
382 dataSet.addDomain(rect, viewport);
383 QCOMPARE(dataSet.domainIndex(), 1);
384 Domain domain3 = dataSet.domain(dataSet.axisY());
385 Domain domain4 = domain1.subDomain(rect, viewport.width(),
386 viewport.height());
387 QVERIFY(domain3 == domain4);
388
389 dataSet.addDomain(rect, viewport);
390 QCOMPARE(dataSet.domainIndex(), 2);
391 Domain domain5 = dataSet.domain(dataSet.axisY());
392 Domain domain6 = domain3.subDomain(rect, viewport.width(),
393 viewport.height());
394 QVERIFY(domain5 == domain6);
395
396 dataSet.addDomain(rect, viewport);
397 QCOMPARE(dataSet.domainIndex(), 3);
398 Domain domain7 = dataSet.domain(dataSet.axisY());
399 Domain domain8 = domain5.subDomain(rect, viewport.width(),
400 viewport.height());
401 QVERIFY(domain7 == domain8);
402
403 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
404 QSignalSpy spy1(&dataSet,
405 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
406 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
407 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
408 QSignalSpy spy4(&dataSet,
409 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
410 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
411
412 Domain domain;
413
414 bool previous = dataSet.previousDomain();
415 QCOMPARE(previous, true);
416 QCOMPARE(dataSet.domainIndex(), 2);
417 domain = dataSet.domain(dataSet.axisY());
418 QVERIFY(domain == domain5);
419 previous = dataSet.previousDomain();
420 QCOMPARE(previous, true);
421 QCOMPARE(dataSet.domainIndex(), 1);
422 domain = dataSet.domain(dataSet.axisY());
423 QVERIFY(domain == domain3);
424 previous = dataSet.previousDomain();
425 QCOMPARE(previous, true);
426 QCOMPARE(dataSet.domainIndex(), 0);
427 domain = dataSet.domain(dataSet.axisY());
428 QVERIFY(domain == domain1);
429 previous = dataSet.previousDomain();
430 QCOMPARE(previous, false);
431 QCOMPARE(dataSet.domainIndex(), 0);
432 domain = dataSet.domain(dataSet.axisY());
433 QVERIFY(domain == domain1);
434
435 bool next = dataSet.nextDomain();
436 QCOMPARE(next, true);
437 QCOMPARE(dataSet.domainIndex(),1);
438 next = dataSet.nextDomain();
439 QCOMPARE(next, true);
440 QCOMPARE(dataSet.domainIndex(),2);
441 next = dataSet.nextDomain();
442 QCOMPARE(next, true);
443 QCOMPARE(dataSet.domainIndex(),3);
444 next = dataSet.nextDomain();
445 QCOMPARE(next, false);
446 QCOMPARE(dataSet.domainIndex(),3);
447
448
449 QCOMPARE(spy0.count(), 0);
450 QCOMPARE(spy1.count(), 12);
451 QCOMPARE(spy2.count(), 0);
452 QCOMPARE(spy3.count(), 0);
453 QCOMPARE(spy4.count(), 6);
454 QCOMPARE(spy5.count(), 0);
455 }
456
457 void tst_ChartDataSet::removeSeries_data()
458 {
459 QTest::addColumn<int>("seriesCount");
460 QTest::addColumn<int>("axisYCount");
461 QTest::newRow("2 series, default axis") << 2 << 0;
462 QTest::newRow("2 series, 2 new axis") << 2 << 2;
463 QTest::newRow("2 series, 1 new axis") << 2 << 2;
464 QTest::newRow("3 series, 3 new axis") << 3 << 3;
465 QTest::newRow("3 series, 2 new axis") << 3 << 2;
466 QTest::newRow("3 series, 1 new axis") << 3 << 1;
467 }
468
469 void tst_ChartDataSet::removeSeries()
470 {
471 QFETCH(int, seriesCount);
472 QFETCH(int, axisYCount);
473
474 ChartDataSet dataSet;
475
476 QList<QChartAxis*> axisList;
477 QList<QChartSeries*> seriesList;
478
479 for (int i = 0; i < axisYCount; i++) {
480 QChartAxis* axis = new QChartAxis();
481 axisList << axis;
482 }
483
484 QList<QChartAxis*>::iterator iterator = axisList.begin();
485
486 for (int i = 0; i < seriesCount; i++) {
487 QChartAxis* axisY = 0;
488 QLineChartSeries* series = new QLineChartSeries();
489 if (iterator != axisList.end()) {
490 axisY = *iterator;
491 iterator++;
492 } else if (axisList.count() > 0) {
493 iterator--;
494 axisY = *iterator;
495 iterator++;
496 }
497 dataSet.addSeries(series, axisY);
498 seriesList << series;
499 }
500
501 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
502 QSignalSpy spy1(&dataSet,
503 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
504 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
505 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
506 QSignalSpy spy4(&dataSet,
507 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
508 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
509
510 for (int i = 0; i < seriesCount; i++) {
511 dataSet.removeSeries(seriesList.at(i));
512 }
513
514 QCOMPARE(spy0.count(), 0);
515 QCOMPARE(spy1.count(), 0);
516 QCOMPARE(spy2.count(), axisYCount);
517 QCOMPARE(spy3.count(), 0);
518 QCOMPARE(spy4.count(), 0);
519 QCOMPARE(spy5.count(), seriesCount);
520
521 QCOMPARE(dataSet.domainIndex(), 0);
522 }
523
524 QTEST_MAIN(tst_ChartDataSet)
525 #include "tst_chartdataset.moc"
526
@@ -0,0 +1,11
1 !include( ../../common.pri ) {
2 error( "Couldn't find the common.pri file!" )
3 }
4
5 !include( ../../integrated.pri ) {
6 error( "Couldn't find the integrated.pri file !")
7 }
8
9 TEMPLATE = app
10 CONFIG += qtestlib
11 !contains(TARGET, ^tst_.*):TARGET = $$join(TARGET,,"tst_") No newline at end of file
@@ -1,3 +1,4
1 TEMPLATE = subdirs
1 TEMPLATE = subdirs
2 SUBDIRS += chartwidgettest \
2 SUBDIRS += auto \
3 chartwidgettest \
3 qmlchart
4 qmlchart
General Comments 0
You need to be logged in to leave comments. Login now