##// END OF EJS Templates
Adds missing test cases to qlineseries
Michal Klocek -
r1099:c6df0fc3daa8
parent child
Show More
@@ -1,579 +1,632
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 #include <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <qlineseries.h>
22 #include <qlineseries.h>
23 #include <qchartview.h>
23 #include <qchartview.h>
24 #include <QStandardItemModel>
24 #include <QStandardItemModel>
25
25
26 Q_DECLARE_METATYPE(QList<QPointF>)
26 Q_DECLARE_METATYPE(QList<QPointF>)
27
27
28 QTCOMMERCIALCHART_USE_NAMESPACE
28 QTCOMMERCIALCHART_USE_NAMESPACE
29
29
30 class tst_QLineSeries : public QObject
30 class tst_QLineSeries : public QObject
31 {
31 {
32 Q_OBJECT
32 Q_OBJECT
33
33
34 public slots:
34 public slots:
35 void initTestCase();
35 void initTestCase();
36 void cleanupTestCase();
36 void cleanupTestCase();
37 void init();
37 void init();
38 void cleanup();
38 void cleanup();
39
39
40 private slots:
40 private slots:
41 void qlineseries_data();
41 void qlineseries_data();
42 void qlineseries();
42 void qlineseries();
43 void append_raw_data();
43 void append_raw_data();
44 void append_raw();
44 void append_raw();
45 void append_chart_data();
45 void append_chart_data();
46 void append_chart();
46 void append_chart();
47 void append_chart_animation_data();
47 void append_chart_animation_data();
48 void append_chart_animation();
48 void append_chart_animation();
49 void chart_append_data();
49 void chart_append_data();
50 void chart_append();
50 void chart_append();
51 void count_raw_data();
51 void count_raw_data();
52 void count_raw();
52 void count_raw();
53 void oper_data();
53 void oper_data();
54 void oper();
54 void oper();
55 void pen_data();
55 void pen_data();
56 void pen();
56 void pen();
57 void pointsVisible_raw_data();
57 void pointsVisible_raw_data();
58 void pointsVisible_raw();
58 void pointsVisible_raw();
59 void remove_raw_data();
59 void remove_raw_data();
60 void remove_raw();
60 void remove_raw();
61 void remove_chart_data();
61 void remove_chart_data();
62 void remove_chart();
62 void remove_chart();
63 void remove_chart_animation_data();
63 void remove_chart_animation_data();
64 void remove_chart_animation();
64 void remove_chart_animation();
65 void removeAll_data();
65 void removeAll_raw_data();
66 void removeAll();
66 void removeAll_raw();
67 void replace_data();
67 void removeAll_chart_data();
68 void replace();
68 void removeAll_chart();
69 void removeAll_chart_animation_data();
70 void removeAll_chart_animation();
71 void replace_raw_data();
72 void replace_raw();
73 void replace_chart_data();
74 void replace_chart();
75 void replace_chart_animation_data();
76 void replace_chart_animation();
69 void setModel_data();
77 void setModel_data();
70 void setModel();
78 void setModel();
71 void setModelMapping_data();
79 void setModelMapping_data();
72 void setModelMapping();
80 void setModelMapping();
73 void setModelMappingRange_data();
81 void setModelMappingRange_data();
74 void setModelMappingRange();
82 void setModelMappingRange();
75 void modelUpdated();
83 void modelUpdated();
76 void modelUpdatedCustomMapping();
84 void modelUpdatedCustomMapping();
77 private:
85 private:
78 void append_data();
86 void append_data();
79 void count_data();
87 void count_data();
80 void pointsVisible_data();
88 void pointsVisible_data();
81
89
82 private:
90 private:
83 QChartView* m_view;
91 QChartView* m_view;
84 QChart* m_chart;
92 QChart* m_chart;
85 QLineSeries* m_series;
93 QLineSeries* m_series;
86 };
94 };
87
95
88 void tst_QLineSeries::initTestCase()
96 void tst_QLineSeries::initTestCase()
89 {
97 {
90 }
98 }
91
99
92 void tst_QLineSeries::cleanupTestCase()
100 void tst_QLineSeries::cleanupTestCase()
93 {
101 {
94 }
102 }
95
103
96 void tst_QLineSeries::init()
104 void tst_QLineSeries::init()
97 {
105 {
98 m_view = new QChartView(new QChart());
106 m_view = new QChartView(new QChart());
99 m_chart = m_view->chart();
107 m_chart = m_view->chart();
100 m_series = new QLineSeries();
108 m_series = new QLineSeries();
101 }
109 }
102
110
103 void tst_QLineSeries::cleanup()
111 void tst_QLineSeries::cleanup()
104 {
112 {
105 delete m_series;
113 delete m_series;
106 delete m_view;
114 delete m_view;
107 m_view = 0;
115 m_view = 0;
108 m_chart = 0;
116 m_chart = 0;
109 m_series = 0;
117 m_series = 0;
110 }
118 }
111
119
112 void tst_QLineSeries::qlineseries_data()
120 void tst_QLineSeries::qlineseries_data()
113 {
121 {
114
122
115 }
123 }
116
124
117 void tst_QLineSeries::qlineseries()
125 void tst_QLineSeries::qlineseries()
118 {
126 {
119 QLineSeries series;
127 QLineSeries series;
120
128
121 QCOMPARE(series.count(),0);
129 QCOMPARE(series.count(),0);
122 QCOMPARE(series.brush(), QBrush());
130 QCOMPARE(series.brush(), QBrush());
123 QCOMPARE(series.points(), QList<QPointF>());
131 QCOMPARE(series.points(), QList<QPointF>());
124 QCOMPARE(series.pen(), QPen());
132 QCOMPARE(series.pen(), QPen());
125 QCOMPARE(series.pointsVisible(), false);
133 QCOMPARE(series.pointsVisible(), false);
126
134
127 series.append(QList<QPointF>());
135 series.append(QList<QPointF>());
128 series.append(0.0,0.0);
136 series.append(0.0,0.0);
129 series.append(QPointF());
137 series.append(QPointF());
130
138
131 series.remove(0.0,0.0);
139 series.remove(0.0,0.0);
132 series.remove(QPointF());
140 series.remove(QPointF());
133 series.removeAll();
141 series.removeAll();
134
142
135 series.replace(QPointF(),QPointF());
143 series.replace(QPointF(),QPointF());
136 series.replace(0,0,0,0);
144 series.replace(0,0,0,0);
137 series.setBrush(QBrush());
145 series.setBrush(QBrush());
138
146
139 QCOMPARE(series.setModel((QAbstractItemModel*)0), false);
147 QCOMPARE(series.setModel((QAbstractItemModel*)0), false);
140
148
141 series.setModelMapping(-1, -1, Qt::Orientation(0));
149 series.setModelMapping(-1, -1, Qt::Orientation(0));
142
150
143 series.setPen(QPen());
151 series.setPen(QPen());
144 series.setPointsVisible(false);
152 series.setPointsVisible(false);
145
153
146 m_chart->addSeries(&series);
154 m_chart->addSeries(&series);
147 m_view->show();
155 m_view->show();
148 QTest::qWaitForWindowShown(m_view);
156 QTest::qWaitForWindowShown(m_view);
149 }
157 }
150
158
151 void tst_QLineSeries::append_data()
159 void tst_QLineSeries::append_data()
152 {
160 {
153 QTest::addColumn< QList<QPointF> >("points");
161 QTest::addColumn< QList<QPointF> >("points");
154 QTest::newRow("0,0 1,1 2,2 3,3") << (QList<QPointF>() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3));
162 QTest::newRow("0,0 1,1 2,2 3,3") << (QList<QPointF>() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3));
155 QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList<QPointF>() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3));
163 QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList<QPointF>() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3));
156 }
164 }
157
165
158
166
159 void tst_QLineSeries::append_raw_data()
167 void tst_QLineSeries::append_raw_data()
160 {
168 {
161 append_data();
169 append_data();
162 }
170 }
163
171
164 void tst_QLineSeries::append_raw()
172 void tst_QLineSeries::append_raw()
165 {
173 {
166 QFETCH(QList<QPointF>, points);
174 QFETCH(QList<QPointF>, points);
167 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
175 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
168 QTest::qWait(200);
176 QTest::qWait(200);
169 m_series->append(points);
177 m_series->append(points);
170 QTest::qWait(200);
178 QTest::qWait(200);
171 QCOMPARE(spy0.count(), 0);
179 QCOMPARE(spy0.count(), 0);
172 QCOMPARE(m_series->points(), points);
180 QCOMPARE(m_series->points(), points);
173 }
181 }
174
182
175 void tst_QLineSeries::chart_append_data()
183 void tst_QLineSeries::chart_append_data()
176 {
184 {
177 append_data();
185 append_data();
178 }
186 }
179
187
180 void tst_QLineSeries::chart_append()
188 void tst_QLineSeries::chart_append()
181 {
189 {
182 append_raw();
190 append_raw();
183 m_chart->addSeries(m_series);
191 m_chart->addSeries(m_series);
184 m_view->show();
192 m_view->show();
185 QTest::qWaitForWindowShown(m_view);
193 QTest::qWaitForWindowShown(m_view);
186 }
194 }
187
195
188 void tst_QLineSeries::append_chart_data()
196 void tst_QLineSeries::append_chart_data()
189 {
197 {
190 append_data();
198 append_data();
191 }
199 }
192
200
193 void tst_QLineSeries::append_chart()
201 void tst_QLineSeries::append_chart()
194 {
202 {
195 m_view->show();
203 m_view->show();
196 m_chart->addSeries(m_series);
204 m_chart->addSeries(m_series);
197 append_raw();
198 QTest::qWaitForWindowShown(m_view);
205 QTest::qWaitForWindowShown(m_view);
206 append_raw();
207
199 }
208 }
200
209
201 void tst_QLineSeries::append_chart_animation_data()
210 void tst_QLineSeries::append_chart_animation_data()
202 {
211 {
203 append_data();
212 append_data();
204 }
213 }
205
214
206 void tst_QLineSeries::append_chart_animation()
215 void tst_QLineSeries::append_chart_animation()
207 {
216 {
208 m_chart->setAnimationOptions(QChart::AllAnimations);
217 m_chart->setAnimationOptions(QChart::AllAnimations);
209 append_chart();
218 append_chart();
210 }
219 }
211
220
212 void tst_QLineSeries::count_data()
221 void tst_QLineSeries::count_data()
213 {
222 {
214 QTest::addColumn<int>("count");
223 QTest::addColumn<int>("count");
215 QTest::newRow("0") << 0;
224 QTest::newRow("0") << 0;
216 QTest::newRow("5") << 5;
225 QTest::newRow("5") << 5;
217 QTest::newRow("10") << 5;
226 QTest::newRow("10") << 5;
218 }
227 }
219
228
220 void tst_QLineSeries::count_raw_data()
229 void tst_QLineSeries::count_raw_data()
221 {
230 {
222 count_data();
231 count_data();
223 }
232 }
224
233
225 void tst_QLineSeries::count_raw()
234 void tst_QLineSeries::count_raw()
226 {
235 {
227 QFETCH(int, count);
236 QFETCH(int, count);
228
237
229 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
238 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
230
239
231 for(int i=0 ; i< count; ++i)
240 for(int i=0 ; i< count; ++i)
232 m_series->append(i,i);
241 m_series->append(i,i);
233
242
234 QCOMPARE(spy0.count(), 0);
243 QCOMPARE(spy0.count(), 0);
235 QCOMPARE(m_series->count(), count);
244 QCOMPARE(m_series->count(), count);
236 }
245 }
237
246
238 void tst_QLineSeries::oper_data()
247 void tst_QLineSeries::oper_data()
239 {
248 {
240 append_data();
249 append_data();
241 }
250 }
242
251
243 void tst_QLineSeries::oper()
252 void tst_QLineSeries::oper()
244 {
253 {
245 QFETCH(QList<QPointF>, points);
254 QFETCH(QList<QPointF>, points);
246 QLineSeries series;
255 QLineSeries series;
247
256
248 QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&)));
257 QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&)));
249
258
250 foreach(const QPointF& point,points)
259 foreach(const QPointF& point,points)
251 {
260 {
252 series<<point;
261 series<<point;
253 }
262 }
254
263
255 QCOMPARE(series.points(), points);
264 QCOMPARE(series.points(), points);
256 QCOMPARE(spy0.count(), 0);
265 QCOMPARE(spy0.count(), 0);
257 }
266 }
258
267
259
268
260 void tst_QLineSeries::pen_data()
269 void tst_QLineSeries::pen_data()
261 {
270 {
262 QTest::addColumn<QPen>("pen");
271 QTest::addColumn<QPen>("pen");
263 QTest::newRow("null") << QPen();
272 QTest::newRow("null") << QPen();
264 QTest::newRow("blue") << QPen(Qt::blue);
273 QTest::newRow("blue") << QPen(Qt::blue);
265 QTest::newRow("black") << QPen(Qt::black);
274 QTest::newRow("black") << QPen(Qt::black);
266 QTest::newRow("red") << QPen(Qt::red);
275 QTest::newRow("red") << QPen(Qt::red);
267 }
276 }
268
277
269 void tst_QLineSeries::pen()
278 void tst_QLineSeries::pen()
270 {
279 {
271 QFETCH(QPen, pen);
280 QFETCH(QPen, pen);
272 QLineSeries series;
281 QLineSeries series;
273
282
274 QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&)));
283 QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&)));
275 series.setPen(pen);
284 series.setPen(pen);
276
285
277 QCOMPARE(spy0.count(), 0);
286 QCOMPARE(spy0.count(), 0);
278 QCOMPARE(series.pen(), pen);
287 QCOMPARE(series.pen(), pen);
279
288
280 m_chart->addSeries(&series);
289 m_chart->addSeries(&series);
281
290
282 if(pen!=QPen()) QCOMPARE(series.pen(), pen);
291 if(pen!=QPen()) QCOMPARE(series.pen(), pen);
283 }
292 }
284
293
285 void tst_QLineSeries::pointsVisible_data()
294 void tst_QLineSeries::pointsVisible_data()
286 {
295 {
287 QTest::addColumn<bool>("pointsVisible");
296 QTest::addColumn<bool>("pointsVisible");
288 QTest::newRow("true") << true;
297 QTest::newRow("true") << true;
289 QTest::newRow("false") << false;
298 QTest::newRow("false") << false;
290 }
299 }
291
300
292 void tst_QLineSeries::pointsVisible_raw_data()
301 void tst_QLineSeries::pointsVisible_raw_data()
293 {
302 {
294 pointsVisible_data();
303 pointsVisible_data();
295 }
304 }
296
305
297 void tst_QLineSeries::pointsVisible_raw()
306 void tst_QLineSeries::pointsVisible_raw()
298 {
307 {
299 QFETCH(bool, pointsVisible);
308 QFETCH(bool, pointsVisible);
300 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
309 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
301 m_series->setPointsVisible(pointsVisible);
310 m_series->setPointsVisible(pointsVisible);
302 QCOMPARE(spy0.count(), 0);
311 QCOMPARE(spy0.count(), 0);
303 QCOMPARE(m_series->pointsVisible(), pointsVisible);
312 QCOMPARE(m_series->pointsVisible(), pointsVisible);
304 }
313 }
305
314
306 void tst_QLineSeries::remove_raw_data()
315 void tst_QLineSeries::remove_raw_data()
307 {
316 {
308 append_data();
317 append_data();
309 }
318 }
310
319
311 void tst_QLineSeries::remove_raw()
320 void tst_QLineSeries::remove_raw()
312 {
321 {
313 QFETCH(QList<QPointF>, points);
322 QFETCH(QList<QPointF>, points);
314 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
323 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
315 m_series->append(points);
324 m_series->append(points);
316 QTest::qWait(200);
325 QTest::qWait(200);
317 QCOMPARE(spy0.count(), 0);
326 QCOMPARE(spy0.count(), 0);
318 QCOMPARE(m_series->points(), points);
327 QCOMPARE(m_series->points(), points);
319
328
320 foreach(const QPointF& point,points)
329 foreach(const QPointF& point,points)
321 {
330 {
322 m_series->remove(point);
331 m_series->remove(point);
323 QTest::qWait(200);
332 QTest::qWait(200);
324 }
333 }
325
334
326 QCOMPARE(spy0.count(), 0);
335 QCOMPARE(spy0.count(), 0);
327 QCOMPARE(m_series->points().count(), 0);
336 QCOMPARE(m_series->points().count(), 0);
328 }
337 }
329
338
330 void tst_QLineSeries::remove_chart_data()
339 void tst_QLineSeries::remove_chart_data()
331 {
340 {
332 append_data();
341 append_data();
333 }
342 }
334
343
335 void tst_QLineSeries::remove_chart()
344 void tst_QLineSeries::remove_chart()
336 {
345 {
337 m_view->show();
346 m_view->show();
338 m_chart->addSeries(m_series);
347 m_chart->addSeries(m_series);
339 remove_raw();
340 QTest::qWaitForWindowShown(m_view);
348 QTest::qWaitForWindowShown(m_view);
349 remove_raw();
341 }
350 }
342
351
343 void tst_QLineSeries::remove_chart_animation_data()
352 void tst_QLineSeries::remove_chart_animation_data()
344 {
353 {
345 append_data();
354 append_data();
346 }
355 }
347
356
348 void tst_QLineSeries::remove_chart_animation()
357 void tst_QLineSeries::remove_chart_animation()
349 {
358 {
350 m_chart->setAnimationOptions(QChart::AllAnimations);
359 m_chart->setAnimationOptions(QChart::AllAnimations);
351 remove_chart();
360 remove_chart();
352 }
361 }
353
362
354
363
355 void tst_QLineSeries::removeAll_data()
364 void tst_QLineSeries::removeAll_raw_data()
356 {
365 {
357 append_data();
366 append_data();
358 }
367 }
359
368
360 void tst_QLineSeries::removeAll()
369 void tst_QLineSeries::removeAll_raw()
361 {
370 {
362 #if 0
371 QFETCH(QList<QPointF>, points);
363 QFETCH(int, foo);
372 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
373 m_series->append(points);
374 QCOMPARE(spy0.count(), 0);
375 QCOMPARE(m_series->points(), points);
376 QTest::qWait(200);
377 m_series->removeAll();
378 QTest::qWait(200);
379 QCOMPARE(spy0.count(), 0);
380 QCOMPARE(m_series->points().count(), 0);
381 }
364
382
365 SubQXYSeries series;
383 void tst_QLineSeries::removeAll_chart_data()
384 {
385 append_data();
386 }
366
387
367 QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&)));
388 void tst_QLineSeries::removeAll_chart()
368 QSignalSpy spy1(&series, SIGNAL(selected()));
389 {
390 m_view->show();
391 m_chart->addSeries(m_series);
392 QTest::qWaitForWindowShown(m_view);
393 removeAll_raw();
394 }
369
395
370 series.removeAll();
396 void tst_QLineSeries::removeAll_chart_animation_data()
397 {
398 append_data();
399 }
371
400
372 QCOMPARE(spy0.count(), 0);
401 void tst_QLineSeries::removeAll_chart_animation()
373 QCOMPARE(spy1.count(), 0);
402 {
374 #endif
403 m_chart->setAnimationOptions(QChart::AllAnimations);
375 QSKIP("Test is not implemented.", SkipAll);
404 removeAll_chart();
376 }
405 }
377
406
378 void tst_QLineSeries::replace_data()
407 void tst_QLineSeries::replace_raw_data()
379 {
408 {
380 QTest::addColumn<QPointF>("point");
409 append_data();
381 QTest::newRow("null") << QPointF();
382 }
410 }
383
411
384 void tst_QLineSeries::replace()
412 void tst_QLineSeries::replace_raw()
385 {
413 {
386 #if 0
414 QFETCH(QList<QPointF>, points);
387 QFETCH(QPointF, point);
415 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
416 m_series->append(points);
417 QCOMPARE(spy0.count(), 0);
418 QCOMPARE(m_series->points(), points);
419 QTest::qWait(200);
420
421 foreach(const QPointF& point,points)
422 {
423 m_series->replace(point.x(),point.y(),point.x(),0);
424 QTest::qWait(200);
425 }
388
426
389 SubQXYSeries series;
427 QList<QPointF> newPoints = m_series->points();
390
428
391 QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&)));
429 QCOMPARE(newPoints.count(), points.count());
392 QSignalSpy spy1(&series, SIGNAL(selected()));
430
431 for(int i =0 ; i<points.count() ; ++i) {
432 QCOMPARE(points[i].x(), newPoints[i].x());
433 QCOMPARE(newPoints[i].y(), 0.0);
434 }
435 }
393
436
394 series.replace(point);
395
437
396 QCOMPARE(spy0.count(), 0);
438 void tst_QLineSeries::replace_chart_data()
397 QCOMPARE(spy1.count(), 0);
439 {
398 #endif
440 append_data();
399 QSKIP("Test is not implemented.", SkipAll);
441 }
442
443 void tst_QLineSeries::replace_chart()
444 {
445 m_view->show();
446 m_chart->addSeries(m_series);
447 QTest::qWaitForWindowShown(m_view);
448 replace_raw();
449 }
450
451 void tst_QLineSeries::replace_chart_animation_data()
452 {
453 append_data();
454 }
455
456 void tst_QLineSeries::replace_chart_animation()
457 {
458 m_chart->setAnimationOptions(QChart::AllAnimations);
459 replace_chart();
400 }
460 }
401
461
402 void tst_QLineSeries::setModel_data()
462 void tst_QLineSeries::setModel_data()
403 {
463 {
404 // QTest::addColumn<QStandardItemModel *>("model");
405 // QTest::addColumn<QStandardItemModel *>("expected");
406
464
407 // QTest::newRow("null") << 0 << 0;
408 // QTest::newRow("QStandardItemModel") << new QStandardItemModel() << new QStandardItemModel();
409 }
465 }
410
466
411 void tst_QLineSeries::setModel()
467 void tst_QLineSeries::setModel()
412 {
468 {
413 // QFETCH(QStandardItemModel *, model);
414 // QFETCH(QStandardItemModel *, expected);
415
416 QLineSeries series;
469 QLineSeries series;
417 series.setModel(0);
470 series.setModel(0);
418 QVERIFY2(series.model() == 0, "Model should be unset");
471 QVERIFY2(series.model() == 0, "Model should be unset");
419
472
420 QStandardItemModel *stdModel = new QStandardItemModel();
473 QStandardItemModel *stdModel = new QStandardItemModel();
421 series.setModel(stdModel);
474 series.setModel(stdModel);
422 QVERIFY2((series.model()) == stdModel, "Model should be stdModel");
475 QVERIFY2((series.model()) == stdModel, "Model should be stdModel");
423
476
424 // unset the model
477 // unset the model
425 series.setModel(0);
478 series.setModel(0);
426 QVERIFY2(series.model() == 0, "Model should be unset");
479 QVERIFY2(series.model() == 0, "Model should be unset");
427
480
428 }
481 }
429
482
430 Q_DECLARE_METATYPE(Qt::Orientation)
483 Q_DECLARE_METATYPE(Qt::Orientation)
431 void tst_QLineSeries::setModelMapping_data()
484 void tst_QLineSeries::setModelMapping_data()
432 {
485 {
433 QTest::addColumn<int>("modelX");
486 QTest::addColumn<int>("modelX");
434 QTest::addColumn<int>("modelY");
487 QTest::addColumn<int>("modelY");
435 QTest::addColumn<Qt::Orientation>("orientation");
488 QTest::addColumn<Qt::Orientation>("orientation");
436 QTest::newRow("different x and y, vertical") << 0 << 1 << Qt::Vertical;
489 QTest::newRow("different x and y, vertical") << 0 << 1 << Qt::Vertical;
437 QTest::newRow("same x and y, vertical") << 0 << 0 << Qt::Vertical;
490 QTest::newRow("same x and y, vertical") << 0 << 0 << Qt::Vertical;
438 QTest::newRow("invalid x, corrent y, vertical") << -1 << 1 << Qt::Vertical;
491 QTest::newRow("invalid x, corrent y, vertical") << -1 << 1 << Qt::Vertical;
439
492
440 QTest::newRow("different x and y, horizontal") << 0 << 1 << Qt::Horizontal;
493 QTest::newRow("different x and y, horizontal") << 0 << 1 << Qt::Horizontal;
441 QTest::newRow("same x and y, horizontal") << 0 << 0 << Qt::Horizontal;
494 QTest::newRow("same x and y, horizontal") << 0 << 0 << Qt::Horizontal;
442 QTest::newRow("invalid x, corrent y, horizontal") << -1 << 1 << Qt::Horizontal;
495 QTest::newRow("invalid x, corrent y, horizontal") << -1 << 1 << Qt::Horizontal;
443 }
496 }
444
497
445 void tst_QLineSeries::setModelMapping()
498 void tst_QLineSeries::setModelMapping()
446 {
499 {
447 QFETCH(int, modelX);
500 QFETCH(int, modelX);
448 QFETCH(int, modelY);
501 QFETCH(int, modelY);
449 QFETCH(Qt::Orientation, orientation);
502 QFETCH(Qt::Orientation, orientation);
450
503
451 QLineSeries series;
504 QLineSeries series;
452
505
453 // model has not been set so setting mapping should do nothing
506 // model has not been set so setting mapping should do nothing
454 series.setModelMapping(modelX, modelY, orientation);
507 series.setModelMapping(modelX, modelY, orientation);
455 QCOMPARE(series.mapX(), -1);
508 QCOMPARE(series.mapX(), -1);
456 QCOMPARE(series.mapY(), -1);
509 QCOMPARE(series.mapY(), -1);
457 QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical");
510 QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical");
458
511
459 // now let us set the model
512 // now let us set the model
460 series.setModel(new QStandardItemModel());
513 series.setModel(new QStandardItemModel());
461 series.setModelMapping(modelX, modelY, orientation);
514 series.setModelMapping(modelX, modelY, orientation);
462 QCOMPARE(series.mapX(), modelX);
515 QCOMPARE(series.mapX(), modelX);
463 QCOMPARE(series.mapY(), modelY);
516 QCOMPARE(series.mapY(), modelY);
464 QVERIFY2(series.mapOrientation() == orientation, "not good");
517 QVERIFY2(series.mapOrientation() == orientation, "not good");
465
518
466 // now let us remove the model, the values should go back to default ones.
519 // now let us remove the model, the values should go back to default ones.
467 series.setModel(0);
520 series.setModel(0);
468 QCOMPARE(series.mapX(), -1);
521 QCOMPARE(series.mapX(), -1);
469 QCOMPARE(series.mapY(), -1);
522 QCOMPARE(series.mapY(), -1);
470 QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical");
523 QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical");
471 }
524 }
472
525
473 void tst_QLineSeries::setModelMappingRange_data()
526 void tst_QLineSeries::setModelMappingRange_data()
474 {
527 {
475 QTest::addColumn<int>("first");
528 QTest::addColumn<int>("first");
476 QTest::addColumn<int>("count");
529 QTest::addColumn<int>("count");
477 QTest::newRow("first: 0, count: unlimited") << 0 << -1;
530 QTest::newRow("first: 0, count: unlimited") << 0 << -1;
478 QTest::newRow("first: 0, count: 5") << 0 << 5;
531 QTest::newRow("first: 0, count: 5") << 0 << 5;
479 QTest::newRow("first: 3, count: unlimited") << 3 << -1;
532 QTest::newRow("first: 3, count: unlimited") << 3 << -1;
480 QTest::newRow("first: 3, count: 5") << 3 << 5;
533 QTest::newRow("first: 3, count: 5") << 3 << 5;
481 QTest::newRow("first: -3, count: 5") << -3 << 5;
534 QTest::newRow("first: -3, count: 5") << -3 << 5;
482 QTest::newRow("first: 3, count: -5") << 3 << -5;
535 QTest::newRow("first: 3, count: -5") << 3 << -5;
483 QTest::newRow("first: -3, count: -5") << 3 << -5;
536 QTest::newRow("first: -3, count: -5") << 3 << -5;
484 QTest::newRow("first: -3, count: 0") << -3 << 0;
537 QTest::newRow("first: -3, count: 0") << -3 << 0;
485 QTest::newRow("first: 0, count: -5") << 0 << -5;
538 QTest::newRow("first: 0, count: -5") << 0 << -5;
486 QTest::newRow("first: 0, count: 0") << 0 << 0;
539 QTest::newRow("first: 0, count: 0") << 0 << 0;
487 }
540 }
488
541
489 void tst_QLineSeries::setModelMappingRange()
542 void tst_QLineSeries::setModelMappingRange()
490 {
543 {
491 QFETCH(int, first);
544 QFETCH(int, first);
492 QFETCH(int, count);
545 QFETCH(int, count);
493 QLineSeries series;
546 QLineSeries series;
494
547
495 QStandardItemModel *model = new QStandardItemModel(0, 2);
548 QStandardItemModel *model = new QStandardItemModel(0, 2);
496 series.setModel(model);
549 series.setModel(model);
497 series.setModelMapping(0, 1);
550 series.setModelMapping(0, 1);
498 series.setModelMappingRange(first, count);
551 series.setModelMappingRange(first, count);
499
552
500 QCOMPARE(series.mapFirst(), qMax(first, 0)); // regardles of what value was used to set the range, first should not be less than 0
553 QCOMPARE(series.mapFirst(), qMax(first, 0)); // regardles of what value was used to set the range, first should not be less than 0
501 QCOMPARE(series.mapCount(), qMax(count, -1)); // regardles of what value was used to set the range, first should not be less than 0
554 QCOMPARE(series.mapCount(), qMax(count, -1)); // regardles of what value was used to set the range, first should not be less than 0
502 QVERIFY2(series.count() == 0, "No rows in the model, count should be 0");
555 QVERIFY2(series.count() == 0, "No rows in the model, count should be 0");
503
556
504 for (int row = 0; row < 3; ++row) {
557 for (int row = 0; row < 3; ++row) {
505 for (int column = 0; column < 2; column++) {
558 for (int column = 0; column < 2; column++) {
506 QStandardItem *item = new QStandardItem(row * column);
559 QStandardItem *item = new QStandardItem(row * column);
507 model->setItem(row, column, item);
560 model->setItem(row, column, item);
508 }
561 }
509 }
562 }
510 if (qMax(count, -1) != -1)
563 if (qMax(count, -1) != -1)
511 QVERIFY2(series.count() == qMin(model->rowCount() - qMax(first, 0), qMax(count, -1)), "Count should be the number of items in a model after first item, but not more than count and not less than 0");
564 QVERIFY2(series.count() == qMin(model->rowCount() - qMax(first, 0), qMax(count, -1)), "Count should be the number of items in a model after first item, but not more than count and not less than 0");
512 else
565 else
513 QVERIFY2(series.count() == model->rowCount() - qMax(first, 0), "Count should be the number of items in a model after first item, but not less then 0");
566 QVERIFY2(series.count() == model->rowCount() - qMax(first, 0), "Count should be the number of items in a model after first item, but not less then 0");
514
567
515 // let's add few more rows to the model
568 // let's add few more rows to the model
516 for (int row = 0; row < 10; ++row) {
569 for (int row = 0; row < 10; ++row) {
517 QList<QStandardItem *> newRow;
570 QList<QStandardItem *> newRow;
518 for (int column = 0; column < 2; column++) {
571 for (int column = 0; column < 2; column++) {
519 newRow.append(new QStandardItem(row * column));
572 newRow.append(new QStandardItem(row * column));
520 }
573 }
521 model->appendRow(newRow);
574 model->appendRow(newRow);
522 }
575 }
523 if (qMax(count, -1) != -1)
576 if (qMax(count, -1) != -1)
524 QVERIFY2(series.count() == qMin(model->rowCount() - qMax(first, 0), qMax(count, -1)), "Count should be the number of items in a model after first item, but not more than count, but not more than count and not less than 0");
577 QVERIFY2(series.count() == qMin(model->rowCount() - qMax(first, 0), qMax(count, -1)), "Count should be the number of items in a model after first item, but not more than count, but not more than count and not less than 0");
525 else
578 else
526 QVERIFY2(series.count() == model->rowCount() - qMax(first, 0), "Count should be the number of items in a model after first item, but not less then 0");
579 QVERIFY2(series.count() == model->rowCount() - qMax(first, 0), "Count should be the number of items in a model after first item, but not less then 0");
527
580
528 // unset the model, values should be default
581 // unset the model, values should be default
529 series.setModel(0);
582 series.setModel(0);
530 QCOMPARE(series.mapFirst(), 0);
583 QCOMPARE(series.mapFirst(), 0);
531 QCOMPARE(series.mapCount(), -1);
584 QCOMPARE(series.mapCount(), -1);
532 QVERIFY2(series.count() == 0, "No rows in the model, count should be 0");
585 QVERIFY2(series.count() == 0, "No rows in the model, count should be 0");
533 }
586 }
534
587
535 void tst_QLineSeries::modelUpdated()
588 void tst_QLineSeries::modelUpdated()
536 {
589 {
537 QStandardItemModel *model = new QStandardItemModel;
590 QStandardItemModel *model = new QStandardItemModel;
538 for (int row = 0; row < 10; ++row) {
591 for (int row = 0; row < 10; ++row) {
539 QList<QStandardItem *> newRow;
592 QList<QStandardItem *> newRow;
540 for (int column = 0; column < 2; column++) {
593 for (int column = 0; column < 2; column++) {
541 newRow.append(new QStandardItem(row * column));
594 newRow.append(new QStandardItem(row * column));
542 }
595 }
543 model->appendRow(newRow);
596 model->appendRow(newRow);
544 }
597 }
545
598
546 QLineSeries series;
599 QLineSeries series;
547 series.setModel(model);
600 series.setModel(model);
548 series.setModelMapping(0, 1);
601 series.setModelMapping(0, 1);
549
602
550 model->setData(model->index(3, 1), 34);
603 model->setData(model->index(3, 1), 34);
551 // check that the update data is correctly taken from the model
604 // check that the update data is correctly taken from the model
552 QVERIFY(qFuzzyCompare(series.points().at(3).y(), 34));
605 QVERIFY(qFuzzyCompare(series.points().at(3).y(), 34));
553 }
606 }
554
607
555 void tst_QLineSeries::modelUpdatedCustomMapping()
608 void tst_QLineSeries::modelUpdatedCustomMapping()
556 {
609 {
557
610
558 QStandardItemModel *model = new QStandardItemModel;
611 QStandardItemModel *model = new QStandardItemModel;
559 for (int row = 0; row < 10; ++row) {
612 for (int row = 0; row < 10; ++row) {
560 QList<QStandardItem *> newRow;
613 QList<QStandardItem *> newRow;
561 for (int column = 0; column < 2; column++) {
614 for (int column = 0; column < 2; column++) {
562 newRow.append(new QStandardItem(row * column));
615 newRow.append(new QStandardItem(row * column));
563 }
616 }
564 model->appendRow(newRow);
617 model->appendRow(newRow);
565 }
618 }
566
619
567 QLineSeries series;
620 QLineSeries series;
568 series.setModel(model);
621 series.setModel(model);
569 series.setModelMapping(0, 1);
622 series.setModelMapping(0, 1);
570 series.setModelMappingRange(3, 4);
623 series.setModelMappingRange(3, 4);
571
624
572 model->setData(model->index(3, 1), 34);
625 model->setData(model->index(3, 1), 34);
573 QVERIFY(qFuzzyCompare(series.points().at(0).y(), 34));
626 QVERIFY(qFuzzyCompare(series.points().at(0).y(), 34));
574 }
627 }
575
628
576 QTEST_MAIN(tst_QLineSeries)
629 QTEST_MAIN(tst_QLineSeries)
577
630
578 #include "tst_qlineseries.moc"
631 #include "tst_qlineseries.moc"
579
632
General Comments 0
You need to be logged in to leave comments. Login now