##// END OF EJS Templates
removed count signal test from tst_qbarset
sauimone -
r1467:fda4040aa838
parent child
Show More
@@ -1,435 +1,427
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QtTest/QtTest>
22 22 #include <qbarset.h>
23 23 #include <qgroupedbarseries.h>
24 24 #include <qchartview.h>
25 25
26 26 QTCOMMERCIALCHART_USE_NAMESPACE
27 27
28 28 class tst_QBarSet : public QObject
29 29 {
30 30 Q_OBJECT
31 31
32 32 public slots:
33 33 void initTestCase();
34 34 void cleanupTestCase();
35 35 void init();
36 36 void cleanup();
37 37
38 38 private slots:
39 39 void qbarset_data();
40 40 void qbarset();
41 41 void label_data();
42 42 void label();
43 43 void append_data();
44 44 void append();
45 45 void appendOperator_data();
46 46 void appendOperator();
47 47 void insert_data();
48 48 void insert();
49 49 void remove_data();
50 50 void remove();
51 51 void replace_data();
52 52 void replace();
53 53 void at_data();
54 54 void at();
55 55 void atOperator_data();
56 56 void atOperator();
57 57 void count_data();
58 58 void count();
59 59 void sum_data();
60 60 void sum();
61 61 void customize();
62 62
63 63 private:
64 64 QBarSet* m_barset;
65 65 };
66 66
67 67 void tst_QBarSet::initTestCase()
68 68 {
69 69 }
70 70
71 71 void tst_QBarSet::cleanupTestCase()
72 72 {
73 73 }
74 74
75 75 void tst_QBarSet::init()
76 76 {
77 77 m_barset = new QBarSet(QString("label"));
78 78 }
79 79
80 80 void tst_QBarSet::cleanup()
81 81 {
82 82 delete m_barset;
83 83 m_barset = 0;
84 84 }
85 85
86 86 void tst_QBarSet::qbarset_data()
87 87 {
88 88 }
89 89
90 90 void tst_QBarSet::qbarset()
91 91 {
92 92 QBarSet barset(QString("label"));
93 93 QCOMPARE(barset.label(), QString("label"));
94 94 QCOMPARE(barset.count(), 0);
95 95 QVERIFY(qFuzzyIsNull(barset.sum()));
96 96 }
97 97
98 98 void tst_QBarSet::label_data()
99 99 {
100 100 QTest::addColumn<QString> ("label");
101 101 QTest::addColumn<QString> ("result");
102 102 QTest::newRow("label0") << QString("label0") << QString("label0");
103 103 QTest::newRow("label1") << QString("label1") << QString("label1");
104 104 }
105 105
106 106 void tst_QBarSet::label()
107 107 {
108 108 QFETCH(QString, label);
109 109 QFETCH(QString, result);
110 110
111 111 QSignalSpy labelSpy(m_barset,SIGNAL(labelChanged()));
112 112 m_barset->setLabel(label);
113 113 QCOMPARE(m_barset->label(), result);
114 114 QVERIFY(labelSpy.count() == 1);
115 115 }
116 116
117 117 void tst_QBarSet::append_data()
118 118 {
119 119 QTest::addColumn<int> ("count");
120 120 QTest::newRow("0") << 0;
121 121 QTest::newRow("5") << 5;
122 122 QTest::newRow("100") << 100;
123 123 QTest::newRow("1000") << 1000;
124 124 }
125 125
126 126 void tst_QBarSet::append()
127 127 {
128 128 QFETCH(int, count);
129 129
130 130 QCOMPARE(m_barset->count(), 0);
131 131 QVERIFY(qFuzzyIsNull(m_barset->sum()));
132 132
133 133 QSignalSpy valueSpy(m_barset, SIGNAL(valuesAdded(int,int)));
134 QSignalSpy countSpy(m_barset, SIGNAL(countChanged(int)));
135 134
136 135 qreal sum(0.0);
137 136 qreal value(0.0);
138 137
139 138 for (int i=0; i<count; i++) {
140 139 m_barset->append(value);
141 140 QCOMPARE(m_barset->at(i).y(), value);
142 141 sum += value;
143 142 value += 1.0;
144 143 }
145 144
146 145 QCOMPARE(m_barset->count(), count);
147 146 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
148 147
149 148 QCOMPARE(valueSpy.count(), count);
150 QCOMPARE(countSpy.count(), count);
151 149 }
152 150
153 151 void tst_QBarSet::appendOperator_data()
154 152 {
155 153 append_data();
156 154 }
157 155
158 156 void tst_QBarSet::appendOperator()
159 157 {
160 158 QFETCH(int, count);
161 159
162 160 QCOMPARE(m_barset->count(), 0);
163 161 QVERIFY(qFuzzyIsNull(m_barset->sum()));
164 162
165 163 QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int)));
166 QSignalSpy countSpy(m_barset, SIGNAL(countChanged(int)));
167 164
168 165 qreal sum(0.0);
169 166 qreal value(0.0);
170 167
171 168 for (int i=0; i<count; i++) {
172 169 *m_barset << value;
173 170 QCOMPARE(m_barset->at(i).y(), value);
174 171 sum += value;
175 172 value += 1.0;
176 173 }
177 174
178 175 QCOMPARE(m_barset->count(), count);
179 176 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
180 177 QCOMPARE(valueSpy.count(), count);
181 QCOMPARE(countSpy.count(), count);
182 178 }
183 179
184 180 void tst_QBarSet::insert_data()
185 181 {
186 182 }
187 183
188 184 void tst_QBarSet::insert()
189 185 {
190 186 QCOMPARE(m_barset->count(), 0);
191 187 QVERIFY(qFuzzyIsNull(m_barset->sum()));
192 188 QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int)));
193 QSignalSpy countSpy(m_barset, SIGNAL(countChanged(int)));
194 189
195 190 m_barset->insert(0, 1.0); // 1.0
196 191 QCOMPARE(m_barset->at(0).y(), 1.0);
197 192 QCOMPARE(m_barset->count(), 1);
198 193 QVERIFY(qFuzzyCompare(m_barset->sum(), 1.0));
199 194
200 195 m_barset->insert(0, 2.0); // 2.0 1.0
201 196 QCOMPARE(m_barset->at(0).y(), 2.0);
202 197 QCOMPARE(m_barset->at(1).y(), 1.0);
203 198 QCOMPARE(m_barset->count(), 2);
204 199 QVERIFY(qFuzzyCompare(m_barset->sum(), 3.0));
205 200
206 201 m_barset->insert(1, 3.0); // 2.0 3.0 1.0
207 202 QCOMPARE(m_barset->at(1).y(), 3.0);
208 203 QCOMPARE(m_barset->at(0).y(), 2.0);
209 204 QCOMPARE(m_barset->at(2).y(), 1.0);
210 205 QCOMPARE(m_barset->count(), 3);
211 206 QVERIFY(qFuzzyCompare(m_barset->sum(), 6.0));
212 207 QCOMPARE(valueSpy.count(), 3);
213 QCOMPARE(countSpy.count(), 3);
214 208 }
215 209
216 210 void tst_QBarSet::remove_data()
217 211 {
218 212 }
219 213
220 214 void tst_QBarSet::remove()
221 215 {
222 216 QCOMPARE(m_barset->count(), 0);
223 217 QVERIFY(qFuzzyIsNull(m_barset->sum()));
224 218
225 219 QSignalSpy valueSpy(m_barset,SIGNAL(valuesRemoved(int,int)));
226 QSignalSpy countSpy(m_barset, SIGNAL(countChanged(int)));
227 220
228 221 m_barset->append(1.0);
229 222 m_barset->append(2.0);
230 223 m_barset->append(3.0);
231 224 m_barset->append(4.0);
232 225
233 226 QCOMPARE(m_barset->count(), 4);
234 227 QCOMPARE(m_barset->sum(), 10.0);
235 228
236 229 m_barset->remove(2); // 1.0 2.0 4.0
237 230 QCOMPARE(m_barset->at(0).y(), 1.0);
238 231 QCOMPARE(m_barset->at(1).y(), 2.0);
239 232 QCOMPARE(m_barset->at(2).y(), 4.0);
240 233 QCOMPARE(m_barset->count(), 3);
241 234 QCOMPARE(m_barset->sum(), 7.0);
242 235
243 236 m_barset->remove(0); // 2.0 4.0
244 237 QCOMPARE(m_barset->at(0).y(), 2.0);
245 238 QCOMPARE(m_barset->at(1).y(), 4.0);
246 239 QCOMPARE(m_barset->count(), 2);
247 240 QCOMPARE(m_barset->sum(), 6.0);
248 241
249 242 QCOMPARE(valueSpy.count(), 2);
250 QCOMPARE(countSpy.count(), 6);
251 243 }
252 244
253 245 void tst_QBarSet::replace_data()
254 246 {
255 247
256 248 }
257 249
258 250 void tst_QBarSet::replace()
259 251 {
260 252 QCOMPARE(m_barset->count(), 0);
261 253 QVERIFY(qFuzzyIsNull(m_barset->sum()));
262 254 QSignalSpy valueSpy(m_barset,SIGNAL(valueChanged(int)));
263 255
264 256 m_barset->append(1.0);
265 257 m_barset->append(2.0);
266 258 m_barset->append(3.0);
267 259 m_barset->append(4.0);
268 260
269 261 QCOMPARE(m_barset->count(), 4);
270 262 QCOMPARE(m_barset->sum(), 10.0);
271 263
272 264 m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0
273 265 QCOMPARE(m_barset->count(), 4);
274 266 QCOMPARE(m_barset->sum(), 14.0);
275 267 QCOMPARE(m_barset->at(0).y(), 5.0);
276 268
277 269 m_barset->replace(3, 6.0);
278 270 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
279 271 QCOMPARE(m_barset->sum(), 16.0);
280 272 QCOMPARE(m_barset->at(0).y(), 5.0);
281 273 QCOMPARE(m_barset->at(1).y(), 2.0);
282 274 QCOMPARE(m_barset->at(2).y(), 3.0);
283 275 QCOMPARE(m_barset->at(3).y(), 6.0);
284 276
285 277 QVERIFY(valueSpy.count() == 2);
286 278 }
287 279
288 280 void tst_QBarSet::at_data()
289 281 {
290 282
291 283 }
292 284
293 285 void tst_QBarSet::at()
294 286 {
295 287 QCOMPARE(m_barset->count(), 0);
296 288 QVERIFY(qFuzzyIsNull(m_barset->sum()));
297 289
298 290 m_barset->append(1.0);
299 291 m_barset->append(2.0);
300 292 m_barset->append(3.0);
301 293 m_barset->append(4.0);
302 294
303 295 QCOMPARE(m_barset->at(0).y(), 1.0);
304 296 QCOMPARE(m_barset->at(1).y(), 2.0);
305 297 QCOMPARE(m_barset->at(2).y(), 3.0);
306 298 QCOMPARE(m_barset->at(3).y(), 4.0);
307 299 }
308 300
309 301 void tst_QBarSet::atOperator_data()
310 302 {
311 303
312 304 }
313 305
314 306 void tst_QBarSet::atOperator()
315 307 {
316 308 QCOMPARE(m_barset->count(), 0);
317 309 QVERIFY(qFuzzyIsNull(m_barset->sum()));
318 310
319 311 m_barset->append(1.0);
320 312 m_barset->append(2.0);
321 313 m_barset->append(3.0);
322 314 m_barset->append(4.0);
323 315
324 316 QCOMPARE(m_barset->operator [](0).y(), 1.0);
325 317 QCOMPARE(m_barset->operator [](1).y(), 2.0);
326 318 QCOMPARE(m_barset->operator [](2).y(), 3.0);
327 319 QCOMPARE(m_barset->operator [](3).y(), 4.0);
328 320 }
329 321
330 322 void tst_QBarSet::count_data()
331 323 {
332 324
333 325 }
334 326
335 327 void tst_QBarSet::count()
336 328 {
337 329 QCOMPARE(m_barset->count(), 0);
338 330 QVERIFY(qFuzzyIsNull(m_barset->sum()));
339 331
340 332 m_barset->append(1.0);
341 333 QCOMPARE(m_barset->count(),1);
342 334 m_barset->append(2.0);
343 335 QCOMPARE(m_barset->count(),2);
344 336 m_barset->append(3.0);
345 337 QCOMPARE(m_barset->count(),3);
346 338 m_barset->append(4.0);
347 339 QCOMPARE(m_barset->count(),4);
348 340 }
349 341
350 342 void tst_QBarSet::sum_data()
351 343 {
352 344
353 345 }
354 346
355 347 void tst_QBarSet::sum()
356 348 {
357 349 QCOMPARE(m_barset->count(), 0);
358 350 QVERIFY(qFuzzyIsNull(m_barset->sum()));
359 351
360 352 m_barset->append(1.0);
361 353 QVERIFY(qFuzzyCompare(m_barset->sum(),1.0));
362 354 m_barset->append(2.0);
363 355 QVERIFY(qFuzzyCompare(m_barset->sum(),3.0));
364 356 m_barset->append(3.0);
365 357 QVERIFY(qFuzzyCompare(m_barset->sum(),6.0));
366 358 m_barset->append(4.0);
367 359 QVERIFY(qFuzzyCompare(m_barset->sum(),10.0));
368 360 }
369 361
370 362 void tst_QBarSet::customize()
371 363 {
372 364 // Create sets
373 365 QBarSet *set1 = new QBarSet("set1");
374 366 QBarSet *set2 = new QBarSet("set2");
375 367
376 368 // Append set1 to series
377 369 QGroupedBarSeries *series = new QGroupedBarSeries();
378 370 bool success = series->append(set1);
379 371 QVERIFY(success);
380 372
381 373 // Add series to the chart
382 374 QChartView view(new QChart());
383 375 view.resize(200, 200);
384 376 view.chart()->addSeries(series);
385 377 view.show();
386 378 QTest::qWaitForWindowShown(&view);
387 379
388 380 // Test adding data to the sets
389 381 *set1 << 1 << 2 << 1 << 3;
390 382 *set2 << 2 << 1 << 3 << 1;
391 383
392 384 // Test pen
393 385 QVERIFY(set1->pen() != QPen());
394 386 QVERIFY(set2->pen() == QPen());
395 387 QPen pen(QColor(128,128,128,128));
396 388 set1->setPen(pen);
397 389 QVERIFY(set1->pen() == pen);
398 390 QVERIFY(set2->pen() == QPen());
399 391
400 392 // Test brush
401 393 QVERIFY(set1->brush() != QBrush());
402 394 QVERIFY(set2->brush() == QBrush());
403 395 QBrush brush(QColor(128,128,128,128));
404 396 set1->setBrush(brush);
405 397 QVERIFY(set1->brush() == brush);
406 398 QVERIFY(set2->brush() == QBrush());
407 399
408 400 // Test label brush
409 401 QVERIFY(set1->labelBrush() != QBrush());
410 402 QVERIFY(set2->labelBrush() == QBrush());
411 403 set1->setLabelBrush(brush);
412 404 QVERIFY(set1->labelBrush() == brush);
413 405 QVERIFY(set2->labelBrush() == QBrush());
414 406
415 407 // Test label font
416 408 // Note: QFont empty constructor creates font with application's default font, so the font may or may not be the
417 409 // same for the set added to the series (depending on the QChart's theme configuration)
418 410 QVERIFY(set1->labelFont() != QFont() || set1->labelFont() == QFont());
419 411 QVERIFY(set2->labelFont() == QFont());
420 412 QFont font;
421 413 font.setBold(true);
422 414 font.setItalic(true);
423 415 set1->setLabelFont(font);
424 416 QVERIFY(set1->labelFont() == font);
425 417 QVERIFY(set2->labelFont() == QFont());
426 418
427 419 // Test adding data to the sets
428 420 *set1 << 1 << 2 << 1 << 3;
429 421 *set2 << 2 << 1 << 3 << 1;
430 422 }
431 423
432 424 QTEST_MAIN(tst_QBarSet)
433 425
434 426 #include "tst_qbarset.moc"
435 427
General Comments 0
You need to be logged in to leave comments. Login now