##// END OF EJS Templates
Fix bug in tst_qxyseries
Jani Honkonen -
r1289:9a04bc58b0cb
parent child
Show More
@@ -1,347 +1,350
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 "tst_qxyseries.h"
21 #include "tst_qxyseries.h"
22
22
23 Q_DECLARE_METATYPE(QList<QPointF>)
23 Q_DECLARE_METATYPE(QList<QPointF>)
24
24
25 void tst_QXYSeries::initTestCase()
25 void tst_QXYSeries::initTestCase()
26 {
26 {
27 }
27 }
28
28
29 void tst_QXYSeries::cleanupTestCase()
29 void tst_QXYSeries::cleanupTestCase()
30 {
30 {
31 }
31 }
32
32
33 void tst_QXYSeries::init()
33 void tst_QXYSeries::init()
34 {
34 {
35 m_view = new QChartView(new QChart());
35 m_view = new QChartView(new QChart());
36 m_chart = m_view->chart();
36 m_chart = m_view->chart();
37 }
37 }
38
38
39 void tst_QXYSeries::cleanup()
39 void tst_QXYSeries::cleanup()
40 {
40 {
41 delete m_view;
41 delete m_view;
42 m_view = 0;
42 m_view = 0;
43 m_chart = 0;
43 m_chart = 0;
44 m_series = 0;
44 m_series = 0;
45 }
45 }
46
46
47 void tst_QXYSeries::append_data()
47 void tst_QXYSeries::append_data()
48 {
48 {
49 QTest::addColumn< QList<QPointF> >("points");
49 QTest::addColumn< QList<QPointF> >("points");
50 QTest::newRow("0,0 1,1 2,2 3,3") << (QList<QPointF>() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3));
50 QTest::newRow("0,0 1,1 2,2 3,3") << (QList<QPointF>() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3));
51 QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList<QPointF>() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3));
51 QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList<QPointF>() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3));
52 }
52 }
53
53
54
54
55 void tst_QXYSeries::append_raw_data()
55 void tst_QXYSeries::append_raw_data()
56 {
56 {
57 append_data();
57 append_data();
58 }
58 }
59
59
60 void tst_QXYSeries::append_raw()
60 void tst_QXYSeries::append_raw()
61 {
61 {
62 QFETCH(QList<QPointF>, points);
62 QFETCH(QList<QPointF>, points);
63 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
63 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
64 m_series->append(points);
64 m_series->append(points);
65 TRY_COMPARE(spy0.count(), 0);
65 TRY_COMPARE(spy0.count(), 0);
66 QCOMPARE(m_series->points(), points);
66 QCOMPARE(m_series->points(), points);
67 }
67 }
68
68
69 void tst_QXYSeries::chart_append_data()
69 void tst_QXYSeries::chart_append_data()
70 {
70 {
71 append_data();
71 append_data();
72 }
72 }
73
73
74 void tst_QXYSeries::chart_append()
74 void tst_QXYSeries::chart_append()
75 {
75 {
76 append_raw();
76 append_raw();
77 m_chart->addSeries(m_series);
77 m_chart->addSeries(m_series);
78 m_view->show();
78 m_view->show();
79 QTest::qWaitForWindowShown(m_view);
79 QTest::qWaitForWindowShown(m_view);
80 }
80 }
81
81
82 void tst_QXYSeries::append_chart_data()
82 void tst_QXYSeries::append_chart_data()
83 {
83 {
84 append_data();
84 append_data();
85 }
85 }
86
86
87 void tst_QXYSeries::append_chart()
87 void tst_QXYSeries::append_chart()
88 {
88 {
89 m_view->show();
89 m_view->show();
90 m_chart->addSeries(m_series);
90 m_chart->addSeries(m_series);
91 QTest::qWaitForWindowShown(m_view);
91 QTest::qWaitForWindowShown(m_view);
92 append_raw();
92 append_raw();
93
93
94 }
94 }
95
95
96 void tst_QXYSeries::append_chart_animation_data()
96 void tst_QXYSeries::append_chart_animation_data()
97 {
97 {
98 append_data();
98 append_data();
99 }
99 }
100
100
101 void tst_QXYSeries::append_chart_animation()
101 void tst_QXYSeries::append_chart_animation()
102 {
102 {
103 m_chart->setAnimationOptions(QChart::AllAnimations);
103 m_chart->setAnimationOptions(QChart::AllAnimations);
104 append_chart();
104 append_chart();
105 }
105 }
106
106
107 void tst_QXYSeries::count_data()
107 void tst_QXYSeries::count_data()
108 {
108 {
109 QTest::addColumn<int>("count");
109 QTest::addColumn<int>("count");
110 QTest::newRow("0") << 0;
110 QTest::newRow("0") << 0;
111 QTest::newRow("5") << 5;
111 QTest::newRow("5") << 5;
112 QTest::newRow("10") << 5;
112 QTest::newRow("10") << 5;
113 }
113 }
114
114
115 void tst_QXYSeries::count_raw_data()
115 void tst_QXYSeries::count_raw_data()
116 {
116 {
117 count_data();
117 count_data();
118 }
118 }
119
119
120 void tst_QXYSeries::count_raw()
120 void tst_QXYSeries::count_raw()
121 {
121 {
122 QFETCH(int, count);
122 QFETCH(int, count);
123
123
124 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
124 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
125
125
126 for(int i=0 ; i< count; ++i)
126 for(int i=0 ; i< count; ++i)
127 m_series->append(i,i);
127 m_series->append(i,i);
128
128
129 TRY_COMPARE(spy0.count(), 0);
129 TRY_COMPARE(spy0.count(), 0);
130 QCOMPARE(m_series->count(), count);
130 QCOMPARE(m_series->count(), count);
131 }
131 }
132
132
133 void tst_QXYSeries::remove_raw_data()
133 void tst_QXYSeries::remove_raw_data()
134 {
134 {
135 append_data();
135 append_data();
136 }
136 }
137
137
138 void tst_QXYSeries::remove_raw()
138 void tst_QXYSeries::remove_raw()
139 {
139 {
140 QFETCH(QList<QPointF>, points);
140 QFETCH(QList<QPointF>, points);
141 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
141 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
142 m_series->append(points);
142 m_series->append(points);
143 TRY_COMPARE(spy0.count(), 0);
143 TRY_COMPARE(spy0.count(), 0);
144 QCOMPARE(m_series->points(), points);
144 QCOMPARE(m_series->points(), points);
145
145
146 foreach(const QPointF& point,points)
146 foreach(const QPointF& point,points)
147 m_series->remove(point);
147 m_series->remove(point);
148
148
149 QCOMPARE(m_series->points().count(), 0);
149 QCOMPARE(m_series->points().count(), 0);
150 TRY_COMPARE(spy0.count(), 0);
150 TRY_COMPARE(spy0.count(), 0);
151
151
152 m_series->append(points);
152 m_series->append(points);
153 QCOMPARE(m_series->points(), points);
153 QCOMPARE(m_series->points(), points);
154
154
155 //reverse order
155 //reverse order
156 for(int i = points.count()-1 ; i>=0; i--){
156 for(int i = points.count()-1 ; i>=0; i--){
157 m_series->remove(points[i]);
157 m_series->remove(points[i]);
158 }
158 }
159 QCOMPARE(m_series->points().count(), 0);
159 QCOMPARE(m_series->points().count(), 0);
160 }
160 }
161
161
162 void tst_QXYSeries::remove_chart_data()
162 void tst_QXYSeries::remove_chart_data()
163 {
163 {
164 append_data();
164 append_data();
165 }
165 }
166
166
167 void tst_QXYSeries::remove_chart()
167 void tst_QXYSeries::remove_chart()
168 {
168 {
169 m_view->show();
169 m_view->show();
170 m_chart->addSeries(m_series);
170 m_chart->addSeries(m_series);
171 QTest::qWaitForWindowShown(m_view);
171 QTest::qWaitForWindowShown(m_view);
172 remove_raw();
172 remove_raw();
173 }
173 }
174
174
175 void tst_QXYSeries::remove_chart_animation_data()
175 void tst_QXYSeries::remove_chart_animation_data()
176 {
176 {
177 append_data();
177 append_data();
178 }
178 }
179
179
180 void tst_QXYSeries::remove_chart_animation()
180 void tst_QXYSeries::remove_chart_animation()
181 {
181 {
182 m_chart->setAnimationOptions(QChart::AllAnimations);
182 m_chart->setAnimationOptions(QChart::AllAnimations);
183 remove_chart();
183 remove_chart();
184 }
184 }
185
185
186
186
187 void tst_QXYSeries::removeAll_raw_data()
187 void tst_QXYSeries::removeAll_raw_data()
188 {
188 {
189 append_data();
189 append_data();
190 }
190 }
191
191
192 void tst_QXYSeries::removeAll_raw()
192 void tst_QXYSeries::removeAll_raw()
193 {
193 {
194 QFETCH(QList<QPointF>, points);
194 QFETCH(QList<QPointF>, points);
195 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
195 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
196 m_series->append(points);
196 m_series->append(points);
197 TRY_COMPARE(spy0.count(), 0);
197 TRY_COMPARE(spy0.count(), 0);
198 QCOMPARE(m_series->points(), points);
198 QCOMPARE(m_series->points(), points);
199 m_series->removeAll();
199 m_series->removeAll();
200 TRY_COMPARE(spy0.count(), 0);
200 TRY_COMPARE(spy0.count(), 0);
201 QCOMPARE(m_series->points().count(), 0);
201 QCOMPARE(m_series->points().count(), 0);
202 }
202 }
203
203
204 void tst_QXYSeries::removeAll_chart_data()
204 void tst_QXYSeries::removeAll_chart_data()
205 {
205 {
206 append_data();
206 append_data();
207 }
207 }
208
208
209 void tst_QXYSeries::removeAll_chart()
209 void tst_QXYSeries::removeAll_chart()
210 {
210 {
211 m_view->show();
211 m_view->show();
212 m_chart->addSeries(m_series);
212 m_chart->addSeries(m_series);
213 QTest::qWaitForWindowShown(m_view);
213 QTest::qWaitForWindowShown(m_view);
214 removeAll_raw();
214 removeAll_raw();
215 }
215 }
216
216
217 void tst_QXYSeries::removeAll_chart_animation_data()
217 void tst_QXYSeries::removeAll_chart_animation_data()
218 {
218 {
219 append_data();
219 append_data();
220 }
220 }
221
221
222 void tst_QXYSeries::removeAll_chart_animation()
222 void tst_QXYSeries::removeAll_chart_animation()
223 {
223 {
224 m_chart->setAnimationOptions(QChart::AllAnimations);
224 m_chart->setAnimationOptions(QChart::AllAnimations);
225 removeAll_chart();
225 removeAll_chart();
226 }
226 }
227
227
228 void tst_QXYSeries::replace_raw_data()
228 void tst_QXYSeries::replace_raw_data()
229 {
229 {
230 append_data();
230 append_data();
231 }
231 }
232
232
233 void tst_QXYSeries::replace_raw()
233 void tst_QXYSeries::replace_raw()
234 {
234 {
235 QFETCH(QList<QPointF>, points);
235 QFETCH(QList<QPointF>, points);
236 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
236 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
237 m_series->append(points);
237 m_series->append(points);
238 TRY_COMPARE(spy0.count(), 0);
238 TRY_COMPARE(spy0.count(), 0);
239 QCOMPARE(m_series->points(), points);
239 QCOMPARE(m_series->points(), points);
240
240
241 foreach(const QPointF& point,points)
241 foreach(const QPointF& point,points)
242 m_series->replace(point.x(),point.y(),point.x(),0);
242 m_series->replace(point.x(),point.y(),point.x(),0);
243
243
244 QList<QPointF> newPoints = m_series->points();
244 QList<QPointF> newPoints = m_series->points();
245
245
246 QCOMPARE(newPoints.count(), points.count());
246 QCOMPARE(newPoints.count(), points.count());
247
247
248 for(int i =0 ; i<points.count() ; ++i) {
248 for(int i =0 ; i<points.count() ; ++i) {
249 QCOMPARE(points[i].x(), newPoints[i].x());
249 QCOMPARE(points[i].x(), newPoints[i].x());
250 QCOMPARE(newPoints[i].y(), 0.0);
250 QCOMPARE(newPoints[i].y(), 0.0);
251 }
251 }
252 }
252 }
253
253
254
254
255 void tst_QXYSeries::replace_chart_data()
255 void tst_QXYSeries::replace_chart_data()
256 {
256 {
257 append_data();
257 append_data();
258 }
258 }
259
259
260 void tst_QXYSeries::replace_chart()
260 void tst_QXYSeries::replace_chart()
261 {
261 {
262 m_view->show();
262 m_view->show();
263 m_chart->addSeries(m_series);
263 m_chart->addSeries(m_series);
264 QTest::qWaitForWindowShown(m_view);
264 QTest::qWaitForWindowShown(m_view);
265 replace_raw();
265 replace_raw();
266 }
266 }
267
267
268 void tst_QXYSeries::replace_chart_animation_data()
268 void tst_QXYSeries::replace_chart_animation_data()
269 {
269 {
270 append_data();
270 append_data();
271 }
271 }
272
272
273 void tst_QXYSeries::replace_chart_animation()
273 void tst_QXYSeries::replace_chart_animation()
274 {
274 {
275 m_chart->setAnimationOptions(QChart::AllAnimations);
275 m_chart->setAnimationOptions(QChart::AllAnimations);
276 replace_chart();
276 replace_chart();
277 }
277 }
278
278
279 void tst_QXYSeries::oper_data()
279 void tst_QXYSeries::oper_data()
280 {
280 {
281 append_data();
281 append_data();
282 }
282 }
283
283
284 void tst_QXYSeries::oper()
284 void tst_QXYSeries::oper()
285 {
285 {
286 QFETCH(QList<QPointF>, points);
286 QFETCH(QList<QPointF>, points);
287
287
288 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
288 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
289
289
290 foreach(const QPointF& point,points)
290 foreach(const QPointF& point,points)
291 {
291 {
292 *m_series<<point;
292 *m_series<<point;
293 }
293 }
294
294
295 QCOMPARE(m_series->points(), points);
295 QCOMPARE(m_series->points(), points);
296 TRY_COMPARE(spy0.count(), 0);
296 TRY_COMPARE(spy0.count(), 0);
297 }
297 }
298
298
299
299
300 void tst_QXYSeries::pen_data()
300 void tst_QXYSeries::pen_data()
301 {
301 {
302 QTest::addColumn<QPen>("pen");
302 QTest::addColumn<QPen>("pen");
303 QTest::newRow("null") << QPen();
303 QTest::newRow("null") << QPen();
304 QTest::newRow("blue") << QPen(Qt::blue);
304 QTest::newRow("blue") << QPen(Qt::blue);
305 QTest::newRow("black") << QPen(Qt::black);
305 QTest::newRow("black") << QPen(Qt::black);
306 QTest::newRow("red") << QPen(Qt::red);
306 QTest::newRow("red") << QPen(Qt::red);
307 }
307 }
308
308
309 void tst_QXYSeries::pen()
309 void tst_QXYSeries::pen()
310 {
310 {
311 QFETCH(QPen, pen);
311 QFETCH(QPen, pen);
312
312
313 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
313 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
314 m_series->setPen(pen);
314 m_series->setPen(pen);
315
315
316 TRY_COMPARE(spy0.count(), 0);
316 TRY_COMPARE(spy0.count(), 0);
317 QCOMPARE(m_series->pen(), pen);
317 QCOMPARE(m_series->pen(), pen);
318
318
319 m_chart->addSeries(m_series);
319 m_chart->addSeries(m_series);
320
320
321 if(pen!=QPen()) QCOMPARE(m_series->pen(), pen);
321 if (pen != QPen())
322 QCOMPARE(m_series->pen(), pen);
322
323
323 m_chart->setTheme(QChart::ChartThemeDark);
324 m_chart->setTheme(QChart::ChartThemeDark);
324
325
325 if(pen!=QPen()) QCOMPARE(m_series->pen(), pen);
326 // setting a theme will overwrite all customizations
327 if (pen != QPen())
328 QVERIFY(m_series->pen() != pen);
326 }
329 }
327
330
328 void tst_QXYSeries::pointsVisible_data()
331 void tst_QXYSeries::pointsVisible_data()
329 {
332 {
330 QTest::addColumn<bool>("pointsVisible");
333 QTest::addColumn<bool>("pointsVisible");
331 QTest::newRow("true") << true;
334 QTest::newRow("true") << true;
332 QTest::newRow("false") << false;
335 QTest::newRow("false") << false;
333 }
336 }
334
337
335 void tst_QXYSeries::pointsVisible_raw_data()
338 void tst_QXYSeries::pointsVisible_raw_data()
336 {
339 {
337 pointsVisible_data();
340 pointsVisible_data();
338 }
341 }
339
342
340 void tst_QXYSeries::pointsVisible_raw()
343 void tst_QXYSeries::pointsVisible_raw()
341 {
344 {
342 QFETCH(bool, pointsVisible);
345 QFETCH(bool, pointsVisible);
343 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
346 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
344 m_series->setPointsVisible(pointsVisible);
347 m_series->setPointsVisible(pointsVisible);
345 TRY_COMPARE(spy0.count(), 0);
348 TRY_COMPARE(spy0.count(), 0);
346 QCOMPARE(m_series->pointsVisible(), pointsVisible);
349 QCOMPARE(m_series->pointsVisible(), pointsVisible);
347 }
350 }
General Comments 0
You need to be logged in to leave comments. Login now