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