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