@@ -1,488 +1,519 | |||||
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 <qbarset.h> |
|
22 | #include <qbarset.h> | |
23 | #include <qbarseries.h> |
|
23 | #include <qbarseries.h> | |
24 | #include <qchartview.h> |
|
24 | #include <qchartview.h> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
26 | QTCOMMERCIALCHART_USE_NAMESPACE | |
27 |
|
27 | |||
28 | class tst_QBarSet : public QObject |
|
28 | class tst_QBarSet : public QObject | |
29 | { |
|
29 | { | |
30 | Q_OBJECT |
|
30 | Q_OBJECT | |
31 |
|
31 | |||
32 | public slots: |
|
32 | public slots: | |
33 | void initTestCase(); |
|
33 | void initTestCase(); | |
34 | void cleanupTestCase(); |
|
34 | void cleanupTestCase(); | |
35 | void init(); |
|
35 | void init(); | |
36 | void cleanup(); |
|
36 | void cleanup(); | |
37 |
|
37 | |||
38 | private slots: |
|
38 | private slots: | |
39 | void qbarset_data(); |
|
39 | void qbarset_data(); | |
40 | void qbarset(); |
|
40 | void qbarset(); | |
41 | void label_data(); |
|
41 | void label_data(); | |
42 | void label(); |
|
42 | void label(); | |
43 | void append_data(); |
|
43 | void append_data(); | |
44 | void append(); |
|
44 | void append(); | |
45 | void appendOperator_data(); |
|
45 | void appendOperator_data(); | |
46 | void appendOperator(); |
|
46 | void appendOperator(); | |
47 | void insert_data(); |
|
47 | void insert_data(); | |
48 | void insert(); |
|
48 | void insert(); | |
49 | void remove_data(); |
|
49 | void remove_data(); | |
50 | void remove(); |
|
50 | void remove(); | |
51 | void replace_data(); |
|
51 | void replace_data(); | |
52 | void replace(); |
|
52 | void replace(); | |
53 | void at_data(); |
|
53 | void at_data(); | |
54 | void at(); |
|
54 | void at(); | |
55 | void atOperator_data(); |
|
55 | void atOperator_data(); | |
56 | void atOperator(); |
|
56 | void atOperator(); | |
57 | void count_data(); |
|
57 | void count_data(); | |
58 | void count(); |
|
58 | void count(); | |
59 | void sum_data(); |
|
59 | void sum_data(); | |
60 | void sum(); |
|
60 | void sum(); | |
61 | void customize(); |
|
61 | void customize(); | |
62 |
|
62 | |||
63 | private: |
|
63 | private: | |
64 | QBarSet* m_barset; |
|
64 | QBarSet* m_barset; | |
65 | }; |
|
65 | }; | |
66 |
|
66 | |||
67 | void tst_QBarSet::initTestCase() |
|
67 | void tst_QBarSet::initTestCase() | |
68 | { |
|
68 | { | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void tst_QBarSet::cleanupTestCase() |
|
71 | void tst_QBarSet::cleanupTestCase() | |
72 | { |
|
72 | { | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void tst_QBarSet::init() |
|
75 | void tst_QBarSet::init() | |
76 | { |
|
76 | { | |
77 | m_barset = new QBarSet(QString("label")); |
|
77 | m_barset = new QBarSet(QString("label")); | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | void tst_QBarSet::cleanup() |
|
80 | void tst_QBarSet::cleanup() | |
81 | { |
|
81 | { | |
82 | delete m_barset; |
|
82 | delete m_barset; | |
83 | m_barset = 0; |
|
83 | m_barset = 0; | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | void tst_QBarSet::qbarset_data() |
|
86 | void tst_QBarSet::qbarset_data() | |
87 | { |
|
87 | { | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void tst_QBarSet::qbarset() |
|
90 | void tst_QBarSet::qbarset() | |
91 | { |
|
91 | { | |
92 | QBarSet barset(QString("label")); |
|
92 | QBarSet barset(QString("label")); | |
93 | QCOMPARE(barset.label(), QString("label")); |
|
93 | QCOMPARE(barset.label(), QString("label")); | |
94 | QCOMPARE(barset.count(), 0); |
|
94 | QCOMPARE(barset.count(), 0); | |
95 | QVERIFY(qFuzzyIsNull(barset.sum())); |
|
95 | QVERIFY(qFuzzyIsNull(barset.sum())); | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | void tst_QBarSet::label_data() |
|
98 | void tst_QBarSet::label_data() | |
99 | { |
|
99 | { | |
100 | QTest::addColumn<QString> ("label"); |
|
100 | QTest::addColumn<QString> ("label"); | |
101 | QTest::addColumn<QString> ("result"); |
|
101 | QTest::addColumn<QString> ("result"); | |
102 | QTest::newRow("label0") << QString("label0") << QString("label0"); |
|
102 | QTest::newRow("label0") << QString("label0") << QString("label0"); | |
103 | QTest::newRow("label1") << QString("label1") << QString("label1"); |
|
103 | QTest::newRow("label1") << QString("label1") << QString("label1"); | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | void tst_QBarSet::label() |
|
106 | void tst_QBarSet::label() | |
107 | { |
|
107 | { | |
108 | QFETCH(QString, label); |
|
108 | QFETCH(QString, label); | |
109 | QFETCH(QString, result); |
|
109 | QFETCH(QString, result); | |
110 |
|
110 | |||
111 | QSignalSpy labelSpy(m_barset,SIGNAL(labelChanged())); |
|
111 | QSignalSpy labelSpy(m_barset,SIGNAL(labelChanged())); | |
112 | m_barset->setLabel(label); |
|
112 | m_barset->setLabel(label); | |
113 | QCOMPARE(m_barset->label(), result); |
|
113 | QCOMPARE(m_barset->label(), result); | |
114 | QVERIFY(labelSpy.count() == 1); |
|
114 | QVERIFY(labelSpy.count() == 1); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void tst_QBarSet::append_data() |
|
117 | void tst_QBarSet::append_data() | |
118 | { |
|
118 | { | |
119 | QTest::addColumn<int> ("count"); |
|
119 | QTest::addColumn<int> ("count"); | |
120 | QTest::newRow("0") << 0; |
|
120 | QTest::newRow("0") << 0; | |
121 | QTest::newRow("5") << 5; |
|
121 | QTest::newRow("5") << 5; | |
122 | QTest::newRow("100") << 100; |
|
122 | QTest::newRow("100") << 100; | |
123 | QTest::newRow("1000") << 1000; |
|
123 | QTest::newRow("1000") << 1000; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | void tst_QBarSet::append() |
|
126 | void tst_QBarSet::append() | |
127 | { |
|
127 | { | |
128 | QFETCH(int, count); |
|
128 | QFETCH(int, count); | |
129 |
|
129 | |||
130 | QCOMPARE(m_barset->count(), 0); |
|
130 | QCOMPARE(m_barset->count(), 0); | |
131 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
131 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
132 |
|
132 | |||
133 | QSignalSpy valueSpy(m_barset, SIGNAL(valuesAdded(int,int))); |
|
133 | QSignalSpy valueSpy(m_barset, SIGNAL(valuesAdded(int,int))); | |
134 |
|
134 | |||
135 | qreal sum(0.0); |
|
135 | qreal sum(0.0); | |
136 | qreal value(0.0); |
|
136 | qreal value(0.0); | |
137 |
|
137 | |||
138 | for (int i=0; i<count; i++) { |
|
138 | for (int i=0; i<count; i++) { | |
139 | m_barset->append(value); |
|
139 | m_barset->append(value); | |
140 | QCOMPARE(m_barset->at(i), value); |
|
140 | QCOMPARE(m_barset->at(i), value); | |
141 | sum += value; |
|
141 | sum += value; | |
142 | value += 1.0; |
|
142 | value += 1.0; | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | QCOMPARE(m_barset->count(), count); |
|
145 | QCOMPARE(m_barset->count(), count); | |
146 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); |
|
146 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); | |
147 |
|
147 | |||
148 | QCOMPARE(valueSpy.count(), count); |
|
148 | QCOMPARE(valueSpy.count(), count); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | void tst_QBarSet::appendOperator_data() |
|
151 | void tst_QBarSet::appendOperator_data() | |
152 | { |
|
152 | { | |
153 | append_data(); |
|
153 | append_data(); | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void tst_QBarSet::appendOperator() |
|
156 | void tst_QBarSet::appendOperator() | |
157 | { |
|
157 | { | |
158 | QFETCH(int, count); |
|
158 | QFETCH(int, count); | |
159 |
|
159 | |||
160 | QCOMPARE(m_barset->count(), 0); |
|
160 | QCOMPARE(m_barset->count(), 0); | |
161 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
161 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
162 |
|
162 | |||
163 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int))); |
|
163 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int))); | |
164 |
|
164 | |||
165 | qreal sum(0.0); |
|
165 | qreal sum(0.0); | |
166 | qreal value(0.0); |
|
166 | qreal value(0.0); | |
167 |
|
167 | |||
168 | for (int i=0; i<count; i++) { |
|
168 | for (int i=0; i<count; i++) { | |
169 | *m_barset << value; |
|
169 | *m_barset << value; | |
170 | QCOMPARE(m_barset->at(i), value); |
|
170 | QCOMPARE(m_barset->at(i), value); | |
171 | sum += value; |
|
171 | sum += value; | |
172 | value += 1.0; |
|
172 | value += 1.0; | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | QCOMPARE(m_barset->count(), count); |
|
175 | QCOMPARE(m_barset->count(), count); | |
176 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); |
|
176 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); | |
177 | QCOMPARE(valueSpy.count(), count); |
|
177 | QCOMPARE(valueSpy.count(), count); | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | void tst_QBarSet::insert_data() |
|
180 | void tst_QBarSet::insert_data() | |
181 | { |
|
181 | { | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | void tst_QBarSet::insert() |
|
184 | void tst_QBarSet::insert() | |
185 | { |
|
185 | { | |
186 | QCOMPARE(m_barset->count(), 0); |
|
186 | QCOMPARE(m_barset->count(), 0); | |
187 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
187 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
188 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int))); |
|
188 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int))); | |
189 |
|
189 | |||
190 | m_barset->insert(0, 1.0); // 1.0 |
|
190 | m_barset->insert(0, 1.0); // 1.0 | |
191 | QCOMPARE(m_barset->at(0), 1.0); |
|
191 | QCOMPARE(m_barset->at(0), 1.0); | |
192 | QCOMPARE(m_barset->count(), 1); |
|
192 | QCOMPARE(m_barset->count(), 1); | |
193 | QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)1.0)); |
|
193 | QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)1.0)); | |
194 |
|
194 | |||
195 | m_barset->insert(0, 2.0); // 2.0 1.0 |
|
195 | m_barset->insert(0, 2.0); // 2.0 1.0 | |
196 | QCOMPARE(m_barset->at(0), 2.0); |
|
196 | QCOMPARE(m_barset->at(0), 2.0); | |
197 | QCOMPARE(m_barset->at(1), 1.0); |
|
197 | QCOMPARE(m_barset->at(1), 1.0); | |
198 | QCOMPARE(m_barset->count(), 2); |
|
198 | QCOMPARE(m_barset->count(), 2); | |
199 | QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)3.0)); |
|
199 | QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)3.0)); | |
200 |
|
200 | |||
201 | m_barset->insert(1, 3.0); // 2.0 3.0 1.0 |
|
201 | m_barset->insert(1, 3.0); // 2.0 3.0 1.0 | |
202 | QCOMPARE(m_barset->at(1), 3.0); |
|
202 | QCOMPARE(m_barset->at(1), 3.0); | |
203 | QCOMPARE(m_barset->at(0), 2.0); |
|
203 | QCOMPARE(m_barset->at(0), 2.0); | |
204 | QCOMPARE(m_barset->at(2), 1.0); |
|
204 | QCOMPARE(m_barset->at(2), 1.0); | |
205 | QCOMPARE(m_barset->count(), 3); |
|
205 | QCOMPARE(m_barset->count(), 3); | |
206 | QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)6.0)); |
|
206 | QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)6.0)); | |
207 | QCOMPARE(valueSpy.count(), 3); |
|
207 | QCOMPARE(valueSpy.count(), 3); | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | void tst_QBarSet::remove_data() |
|
210 | void tst_QBarSet::remove_data() | |
211 | { |
|
211 | { | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | void tst_QBarSet::remove() |
|
214 | void tst_QBarSet::remove() | |
215 | { |
|
215 | { | |
216 | QCOMPARE(m_barset->count(), 0); |
|
216 | QCOMPARE(m_barset->count(), 0); | |
217 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
217 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
218 |
|
218 | |||
219 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesRemoved(int,int))); |
|
219 | QSignalSpy valueSpy(m_barset,SIGNAL(valuesRemoved(int,int))); | |
220 |
|
220 | |||
221 | m_barset->append(1.0); |
|
221 | m_barset->append(1.0); | |
222 | m_barset->append(2.0); |
|
222 | m_barset->append(2.0); | |
223 | m_barset->append(3.0); |
|
223 | m_barset->append(3.0); | |
224 | m_barset->append(4.0); |
|
224 | m_barset->append(4.0); | |
225 |
|
225 | |||
226 | QCOMPARE(m_barset->count(), 4); |
|
226 | QCOMPARE(m_barset->count(), 4); | |
227 | QCOMPARE(m_barset->sum(), 10.0); |
|
227 | QCOMPARE(m_barset->sum(), 10.0); | |
228 |
|
228 | |||
229 | // Remove middle |
|
229 | // Remove middle | |
230 | m_barset->remove(2); // 1.0 2.0 4.0 |
|
230 | m_barset->remove(2); // 1.0 2.0 4.0 | |
231 | QCOMPARE(m_barset->at(0), 1.0); |
|
231 | QCOMPARE(m_barset->at(0), 1.0); | |
232 | QCOMPARE(m_barset->at(1), 2.0); |
|
232 | QCOMPARE(m_barset->at(1), 2.0); | |
233 | QCOMPARE(m_barset->at(2), 4.0); |
|
233 | QCOMPARE(m_barset->at(2), 4.0); | |
234 | QCOMPARE(m_barset->count(), 3); |
|
234 | QCOMPARE(m_barset->count(), 3); | |
235 | QCOMPARE(m_barset->sum(), 7.0); |
|
235 | QCOMPARE(m_barset->sum(), 7.0); | |
236 | QCOMPARE(valueSpy.count(), 1); |
|
236 | QCOMPARE(valueSpy.count(), 1); | |
237 |
|
237 | |||
238 | QList<QVariant> valueSpyArg = valueSpy.takeFirst(); |
|
238 | QList<QVariant> valueSpyArg = valueSpy.takeFirst(); | |
239 | // Verify index of removed signal |
|
239 | // Verify index of removed signal | |
240 | QVERIFY(valueSpyArg.at(0).type() == QVariant::Int); |
|
240 | QVERIFY(valueSpyArg.at(0).type() == QVariant::Int); | |
241 | QVERIFY(valueSpyArg.at(0).toInt() == 2); |
|
241 | QVERIFY(valueSpyArg.at(0).toInt() == 2); | |
242 | // Verify count of removed signal |
|
242 | // Verify count of removed signal | |
243 | QVERIFY(valueSpyArg.at(1).type() == QVariant::Int); |
|
243 | QVERIFY(valueSpyArg.at(1).type() == QVariant::Int); | |
244 | QVERIFY(valueSpyArg.at(1).toInt() == 1); |
|
244 | QVERIFY(valueSpyArg.at(1).toInt() == 1); | |
245 |
|
245 | |||
246 | // Remove first |
|
246 | // Remove first | |
247 | m_barset->remove(0); // 2.0 4.0 |
|
247 | m_barset->remove(0); // 2.0 4.0 | |
248 | QCOMPARE(m_barset->at(0), 2.0); |
|
248 | QCOMPARE(m_barset->at(0), 2.0); | |
249 | QCOMPARE(m_barset->at(1), 4.0); |
|
249 | QCOMPARE(m_barset->at(1), 4.0); | |
250 | QCOMPARE(m_barset->count(), 2); |
|
250 | QCOMPARE(m_barset->count(), 2); | |
251 | QCOMPARE(m_barset->sum(), 6.0); |
|
251 | QCOMPARE(m_barset->sum(), 6.0); | |
252 |
|
252 | |||
253 | QCOMPARE(valueSpy.count(), 1); |
|
253 | QCOMPARE(valueSpy.count(), 1); | |
254 | valueSpyArg = valueSpy.takeFirst(); |
|
254 | valueSpyArg = valueSpy.takeFirst(); | |
255 | // Verify index of removed signal |
|
255 | // Verify index of removed signal | |
256 | QVERIFY(valueSpyArg.at(0).type() == QVariant::Int); |
|
256 | QVERIFY(valueSpyArg.at(0).type() == QVariant::Int); | |
257 | QVERIFY(valueSpyArg.at(0).toInt() == 0); |
|
257 | QVERIFY(valueSpyArg.at(0).toInt() == 0); | |
258 | // Verify count of removed signal |
|
258 | // Verify count of removed signal | |
259 | QVERIFY(valueSpyArg.at(1).type() == QVariant::Int); |
|
259 | QVERIFY(valueSpyArg.at(1).type() == QVariant::Int); | |
260 | QVERIFY(valueSpyArg.at(1).toInt() == 1); |
|
260 | QVERIFY(valueSpyArg.at(1).toInt() == 1); | |
261 |
|
261 | |||
262 |
|
262 | |||
263 | // Illegal indexes |
|
263 | // Illegal indexes | |
264 | m_barset->remove(4); |
|
264 | m_barset->remove(4); | |
265 | QCOMPARE(m_barset->count(), 2); |
|
265 | QCOMPARE(m_barset->count(), 2); | |
266 | QCOMPARE(m_barset->sum(), 6.0); |
|
266 | QCOMPARE(m_barset->sum(), 6.0); | |
267 | m_barset->remove(-1); |
|
267 | m_barset->remove(-1); | |
268 | QCOMPARE(m_barset->count(), 2); |
|
268 | QCOMPARE(m_barset->count(), 2); | |
269 | QCOMPARE(m_barset->sum(), 6.0); |
|
269 | QCOMPARE(m_barset->sum(), 6.0); | |
270 |
|
270 | |||
271 | // nothing removed, no signals should be emitted |
|
271 | // nothing removed, no signals should be emitted | |
272 | QCOMPARE(valueSpy.count(), 0); |
|
272 | QCOMPARE(valueSpy.count(), 0); | |
273 |
|
273 | |||
274 | // Remove more items than list has |
|
274 | // Remove more items than list has | |
275 | m_barset->remove(0,312); |
|
275 | m_barset->remove(0,312); | |
276 | QCOMPARE(m_barset->count(), 0); |
|
276 | QCOMPARE(m_barset->count(), 0); | |
277 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
277 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
278 |
|
278 | |||
279 | QCOMPARE(valueSpy.count(), 1); |
|
279 | QCOMPARE(valueSpy.count(), 1); | |
280 | valueSpyArg = valueSpy.takeFirst(); |
|
280 | valueSpyArg = valueSpy.takeFirst(); | |
281 |
|
281 | |||
282 | // Verify index of removed signal |
|
282 | // Verify index of removed signal | |
283 | QVERIFY(valueSpyArg.at(0).type() == QVariant::Int); |
|
283 | QVERIFY(valueSpyArg.at(0).type() == QVariant::Int); | |
284 | QVERIFY(valueSpyArg.at(0).toInt() == 0); |
|
284 | QVERIFY(valueSpyArg.at(0).toInt() == 0); | |
285 | // Verify count of removed signal (expect 2 values removed, because list had only 2 items) |
|
285 | // Verify count of removed signal (expect 2 values removed, because list had only 2 items) | |
286 | QVERIFY(valueSpyArg.at(1).type() == QVariant::Int); |
|
286 | QVERIFY(valueSpyArg.at(1).type() == QVariant::Int); | |
287 | QVERIFY(valueSpyArg.at(1).toInt() == 2); |
|
287 | QVERIFY(valueSpyArg.at(1).toInt() == 2); | |
288 | } |
|
288 | } | |
289 |
|
289 | |||
290 | void tst_QBarSet::replace_data() |
|
290 | void tst_QBarSet::replace_data() | |
291 | { |
|
291 | { | |
292 |
|
292 | |||
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 | void tst_QBarSet::replace() |
|
295 | void tst_QBarSet::replace() | |
296 | { |
|
296 | { | |
297 | QCOMPARE(m_barset->count(), 0); |
|
297 | QCOMPARE(m_barset->count(), 0); | |
298 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
298 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
299 | QSignalSpy valueSpy(m_barset,SIGNAL(valueChanged(int))); |
|
299 | QSignalSpy valueSpy(m_barset,SIGNAL(valueChanged(int))); | |
300 |
|
300 | |||
301 | m_barset->append(1.0); |
|
301 | m_barset->append(1.0); | |
302 | m_barset->append(2.0); |
|
302 | m_barset->append(2.0); | |
303 | m_barset->append(3.0); |
|
303 | m_barset->append(3.0); | |
304 | m_barset->append(4.0); |
|
304 | m_barset->append(4.0); | |
305 |
|
305 | |||
306 | QCOMPARE(m_barset->count(), 4); |
|
306 | QCOMPARE(m_barset->count(), 4); | |
307 | QCOMPARE(m_barset->sum(), 10.0); |
|
307 | QCOMPARE(m_barset->sum(), 10.0); | |
308 |
|
308 | |||
309 | // Replace first |
|
309 | // Replace first | |
310 | m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0 |
|
310 | m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0 | |
311 | QCOMPARE(m_barset->count(), 4); |
|
311 | QCOMPARE(m_barset->count(), 4); | |
312 | QCOMPARE(m_barset->sum(), 14.0); |
|
312 | QCOMPARE(m_barset->sum(), 14.0); | |
313 | QCOMPARE(m_barset->at(0), 5.0); |
|
313 | QCOMPARE(m_barset->at(0), 5.0); | |
314 |
|
314 | |||
315 | // Replace last |
|
315 | // Replace last | |
316 | m_barset->replace(3, 6.0); |
|
316 | m_barset->replace(3, 6.0); | |
317 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
317 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 | |
318 | QCOMPARE(m_barset->sum(), 16.0); |
|
318 | QCOMPARE(m_barset->sum(), 16.0); | |
319 | QCOMPARE(m_barset->at(0), 5.0); |
|
319 | QCOMPARE(m_barset->at(0), 5.0); | |
320 | QCOMPARE(m_barset->at(1), 2.0); |
|
320 | QCOMPARE(m_barset->at(1), 2.0); | |
321 | QCOMPARE(m_barset->at(2), 3.0); |
|
321 | QCOMPARE(m_barset->at(2), 3.0); | |
322 | QCOMPARE(m_barset->at(3), 6.0); |
|
322 | QCOMPARE(m_barset->at(3), 6.0); | |
323 |
|
323 | |||
324 | // Illegal indexes |
|
324 | // Illegal indexes | |
325 | m_barset->replace(4, 6.0); |
|
325 | m_barset->replace(4, 6.0); | |
326 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
326 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 | |
327 | QCOMPARE(m_barset->sum(), 16.0); |
|
327 | QCOMPARE(m_barset->sum(), 16.0); | |
328 | m_barset->replace(-1, 6.0); |
|
328 | m_barset->replace(-1, 6.0); | |
329 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
329 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 | |
330 | QCOMPARE(m_barset->sum(), 16.0); |
|
330 | QCOMPARE(m_barset->sum(), 16.0); | |
331 | m_barset->replace(4, 1.0); |
|
331 | m_barset->replace(4, 1.0); | |
332 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
332 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 | |
333 | QCOMPARE(m_barset->sum(), 16.0); |
|
333 | QCOMPARE(m_barset->sum(), 16.0); | |
334 | m_barset->replace(-1, 1.0); |
|
334 | m_barset->replace(-1, 1.0); | |
335 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
335 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 | |
336 | QCOMPARE(m_barset->sum(), 16.0); |
|
336 | QCOMPARE(m_barset->sum(), 16.0); | |
337 |
|
337 | |||
338 | QVERIFY(valueSpy.count() == 2); |
|
338 | QVERIFY(valueSpy.count() == 2); | |
339 | } |
|
339 | } | |
340 |
|
340 | |||
341 | void tst_QBarSet::at_data() |
|
341 | void tst_QBarSet::at_data() | |
342 | { |
|
342 | { | |
343 |
|
343 | |||
344 | } |
|
344 | } | |
345 |
|
345 | |||
346 | void tst_QBarSet::at() |
|
346 | void tst_QBarSet::at() | |
347 | { |
|
347 | { | |
348 | QCOMPARE(m_barset->count(), 0); |
|
348 | QCOMPARE(m_barset->count(), 0); | |
349 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
349 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
350 |
|
350 | |||
351 | m_barset->append(1.0); |
|
351 | m_barset->append(1.0); | |
352 | m_barset->append(2.0); |
|
352 | m_barset->append(2.0); | |
353 | m_barset->append(3.0); |
|
353 | m_barset->append(3.0); | |
354 | m_barset->append(4.0); |
|
354 | m_barset->append(4.0); | |
355 |
|
355 | |||
356 | QCOMPARE(m_barset->at(0), 1.0); |
|
356 | QCOMPARE(m_barset->at(0), 1.0); | |
357 | QCOMPARE(m_barset->at(1), 2.0); |
|
357 | QCOMPARE(m_barset->at(1), 2.0); | |
358 | QCOMPARE(m_barset->at(2), 3.0); |
|
358 | QCOMPARE(m_barset->at(2), 3.0); | |
359 | QCOMPARE(m_barset->at(3), 4.0); |
|
359 | QCOMPARE(m_barset->at(3), 4.0); | |
360 | } |
|
360 | } | |
361 |
|
361 | |||
362 | void tst_QBarSet::atOperator_data() |
|
362 | void tst_QBarSet::atOperator_data() | |
363 | { |
|
363 | { | |
364 |
|
364 | |||
365 | } |
|
365 | } | |
366 |
|
366 | |||
367 | void tst_QBarSet::atOperator() |
|
367 | void tst_QBarSet::atOperator() | |
368 | { |
|
368 | { | |
369 | QCOMPARE(m_barset->count(), 0); |
|
369 | QCOMPARE(m_barset->count(), 0); | |
370 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
370 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
371 |
|
371 | |||
372 | m_barset->append(1.0); |
|
372 | m_barset->append(1.0); | |
373 | m_barset->append(2.0); |
|
373 | m_barset->append(2.0); | |
374 | m_barset->append(3.0); |
|
374 | m_barset->append(3.0); | |
375 | m_barset->append(4.0); |
|
375 | m_barset->append(4.0); | |
376 |
|
376 | |||
377 | QCOMPARE(m_barset->operator [](0), 1.0); |
|
377 | QCOMPARE(m_barset->operator [](0), 1.0); | |
378 | QCOMPARE(m_barset->operator [](1), 2.0); |
|
378 | QCOMPARE(m_barset->operator [](1), 2.0); | |
379 | QCOMPARE(m_barset->operator [](2), 3.0); |
|
379 | QCOMPARE(m_barset->operator [](2), 3.0); | |
380 | QCOMPARE(m_barset->operator [](3), 4.0); |
|
380 | QCOMPARE(m_barset->operator [](3), 4.0); | |
381 | } |
|
381 | } | |
382 |
|
382 | |||
383 | void tst_QBarSet::count_data() |
|
383 | void tst_QBarSet::count_data() | |
384 | { |
|
384 | { | |
385 |
|
385 | |||
386 | } |
|
386 | } | |
387 |
|
387 | |||
388 | void tst_QBarSet::count() |
|
388 | void tst_QBarSet::count() | |
389 | { |
|
389 | { | |
390 | QCOMPARE(m_barset->count(), 0); |
|
390 | QCOMPARE(m_barset->count(), 0); | |
391 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
391 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
392 |
|
392 | |||
393 | m_barset->append(1.0); |
|
393 | m_barset->append(1.0); | |
394 | QCOMPARE(m_barset->count(),1); |
|
394 | QCOMPARE(m_barset->count(),1); | |
395 | m_barset->append(2.0); |
|
395 | m_barset->append(2.0); | |
396 | QCOMPARE(m_barset->count(),2); |
|
396 | QCOMPARE(m_barset->count(),2); | |
397 | m_barset->append(3.0); |
|
397 | m_barset->append(3.0); | |
398 | QCOMPARE(m_barset->count(),3); |
|
398 | QCOMPARE(m_barset->count(),3); | |
399 | m_barset->append(4.0); |
|
399 | m_barset->append(4.0); | |
400 | QCOMPARE(m_barset->count(),4); |
|
400 | QCOMPARE(m_barset->count(),4); | |
401 | } |
|
401 | } | |
402 |
|
402 | |||
403 | void tst_QBarSet::sum_data() |
|
403 | void tst_QBarSet::sum_data() | |
404 | { |
|
404 | { | |
405 |
|
405 | |||
406 | } |
|
406 | } | |
407 |
|
407 | |||
408 | void tst_QBarSet::sum() |
|
408 | void tst_QBarSet::sum() | |
409 | { |
|
409 | { | |
410 | QCOMPARE(m_barset->count(), 0); |
|
410 | QCOMPARE(m_barset->count(), 0); | |
411 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
411 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
412 |
|
412 | |||
413 | m_barset->append(1.0); |
|
413 | m_barset->append(1.0); | |
414 | QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)1.0)); |
|
414 | QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)1.0)); | |
415 | m_barset->append(2.0); |
|
415 | m_barset->append(2.0); | |
416 | QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)3.0)); |
|
416 | QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)3.0)); | |
417 | m_barset->append(3.0); |
|
417 | m_barset->append(3.0); | |
418 | QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)6.0)); |
|
418 | QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)6.0)); | |
419 | m_barset->append(4.0); |
|
419 | m_barset->append(4.0); | |
420 | QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)10.0)); |
|
420 | QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)10.0)); | |
421 | } |
|
421 | } | |
422 |
|
422 | |||
423 | void tst_QBarSet::customize() |
|
423 | void tst_QBarSet::customize() | |
424 | { |
|
424 | { | |
425 | // Create sets |
|
425 | // Create sets | |
426 | QBarSet *set1 = new QBarSet("set1"); |
|
426 | QBarSet *set1 = new QBarSet("set1"); | |
427 | QBarSet *set2 = new QBarSet("set2"); |
|
427 | QBarSet *set2 = new QBarSet("set2"); | |
428 |
|
428 | |||
429 | // Append set1 to series |
|
429 | // Append set1 to series | |
430 | QBarSeries *series = new QBarSeries(); |
|
430 | QBarSeries *series = new QBarSeries(); | |
431 | bool success = series->append(set1); |
|
431 | bool success = series->append(set1); | |
432 | QVERIFY(success); |
|
432 | QVERIFY(success); | |
433 |
|
433 | |||
434 | // Add series to the chart |
|
434 | // Add series to the chart | |
435 | QChartView view(new QChart()); |
|
435 | QChartView view(new QChart()); | |
436 | view.resize(200, 200); |
|
436 | view.resize(200, 200); | |
437 | view.chart()->addSeries(series); |
|
437 | view.chart()->addSeries(series); | |
438 | view.show(); |
|
438 | view.show(); | |
439 | QTest::qWaitForWindowShown(&view); |
|
439 | QTest::qWaitForWindowShown(&view); | |
440 |
|
440 | |||
441 | // Test adding data to the sets |
|
441 | // Test adding data to the sets | |
442 | *set1 << 1 << 2 << 1 << 3; |
|
442 | *set1 << 1 << 2 << 1 << 3; | |
443 | *set2 << 2 << 1 << 3 << 1; |
|
443 | *set2 << 2 << 1 << 3 << 1; | |
444 |
|
444 | |||
|
445 | // Remove sets from series | |||
|
446 | series->remove(set1); | |||
|
447 | series->remove(set2); | |||
|
448 | ||||
445 | // Test pen |
|
449 | // Test pen | |
446 | QVERIFY(set1->pen() != QPen()); |
|
450 | QVERIFY(set1->pen() != QPen()); | |
447 | QVERIFY(set2->pen() == QPen()); |
|
451 | QVERIFY(set2->pen() == QPen()); | |
448 | QPen pen(QColor(128,128,128,128)); |
|
452 | QPen pen(QColor(128,128,128,128)); | |
449 | set1->setPen(pen); |
|
453 | set1->setPen(pen); | |
450 | QVERIFY(set1->pen() == pen); |
|
454 | ||
451 | QVERIFY(set2->pen() == QPen()); |
|
455 | // Add sets back to series | |
|
456 | series->append(set1); | |||
|
457 | series->append(set2); | |||
|
458 | ||||
|
459 | QVERIFY(set1->pen() == pen); // Should be customized | |||
|
460 | QVERIFY(set2->pen() != QPen()); // Should be decorated by theme | |||
|
461 | ||||
|
462 | // Remove sets from series | |||
|
463 | series->remove(set1); | |||
|
464 | series->remove(set2); | |||
452 |
|
465 | |||
453 | // Test brush |
|
466 | // Test brush | |
|
467 | set2->setBrush(QBrush()); | |||
454 | QVERIFY(set1->brush() != QBrush()); |
|
468 | QVERIFY(set1->brush() != QBrush()); | |
455 | QVERIFY(set2->brush() == QBrush()); |
|
469 | QVERIFY(set2->brush() == QBrush()); | |
456 | QBrush brush(QColor(128,128,128,128)); |
|
470 | QBrush brush(QColor(128,128,128,128)); | |
457 | set1->setBrush(brush); |
|
471 | set1->setBrush(brush); | |
458 | QVERIFY(set1->brush() == brush); |
|
472 | ||
459 | QVERIFY(set2->brush() == QBrush()); |
|
473 | // Add sets back to series | |
|
474 | series->append(set1); | |||
|
475 | series->append(set2); | |||
|
476 | ||||
|
477 | QVERIFY(set1->brush() == brush); // Should be customized | |||
|
478 | QVERIFY(set2->brush() != QBrush()); // Should be decorated by theme | |||
|
479 | ||||
|
480 | // Remove sets from series | |||
|
481 | series->remove(set1); | |||
|
482 | series->remove(set2); | |||
460 |
|
483 | |||
461 | // Test label brush |
|
484 | // Test label brush | |
|
485 | set2->setLabelBrush(QBrush()); | |||
462 | QVERIFY(set1->labelBrush() != QBrush()); |
|
486 | QVERIFY(set1->labelBrush() != QBrush()); | |
463 | QVERIFY(set2->labelBrush() == QBrush()); |
|
487 | QVERIFY(set2->labelBrush() == QBrush()); | |
464 | set1->setLabelBrush(brush); |
|
488 | set1->setLabelBrush(brush); | |
465 | QVERIFY(set1->labelBrush() == brush); |
|
489 | ||
466 | QVERIFY(set2->labelBrush() == QBrush()); |
|
490 | series->append(set1); | |
|
491 | series->append(set2); | |||
|
492 | QVERIFY(set1->labelBrush() == brush); // Should be customized | |||
|
493 | QVERIFY(set2->labelBrush() != QBrush()); // Should be decorated by theme | |||
467 |
|
494 | |||
468 | // Test label font |
|
495 | // Test label font | |
469 | // Note: QFont empty constructor creates font with application's default font, so the font may or may not be the |
|
496 | // Note: QFont empty constructor creates font with application's default font, so the font may or may not be the | |
470 | // same for the set added to the series (depending on the QChart's theme configuration) |
|
497 | // same for the set added to the series (depending on the QChart's theme configuration) | |
471 | QVERIFY(set1->labelFont() != QFont() || set1->labelFont() == QFont()); |
|
498 | QVERIFY(set1->labelFont() != QFont() || set1->labelFont() == QFont()); | |
472 | QVERIFY(set2->labelFont() == QFont()); |
|
499 | QVERIFY(set2->labelFont() == QFont()); | |
473 | QFont font; |
|
500 | QFont font; | |
474 | font.setBold(true); |
|
501 | font.setBold(true); | |
475 | font.setItalic(true); |
|
502 | font.setItalic(true); | |
476 | set1->setLabelFont(font); |
|
503 | set1->setLabelFont(font); | |
477 | QVERIFY(set1->labelFont() == font); |
|
504 | QVERIFY(set1->labelFont() == font); | |
478 | QVERIFY(set2->labelFont() == QFont()); |
|
505 | QVERIFY(set2->labelFont() == QFont()); | |
479 |
|
506 | |||
480 | // Test adding data to the sets |
|
507 | // Test adding data to the sets | |
481 | *set1 << 1 << 2 << 1 << 3; |
|
508 | *set1 << 1 << 2 << 1 << 3; | |
482 | *set2 << 2 << 1 << 3 << 1; |
|
509 | *set2 << 2 << 1 << 3 << 1; | |
|
510 | ||||
483 | } |
|
511 | } | |
484 |
|
512 | |||
|
513 | ||||
|
514 | ||||
|
515 | ||||
485 | QTEST_MAIN(tst_QBarSet) |
|
516 | QTEST_MAIN(tst_QBarSet) | |
486 |
|
517 | |||
487 | #include "tst_qbarset.moc" |
|
518 | #include "tst_qbarset.moc" | |
488 |
|
519 |
General Comments 0
You need to be logged in to leave comments.
Login now