@@ -30,6 +30,7 | |||
|
30 | 30 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
31 | 31 | |
|
32 | 32 | Q_DECLARE_METATYPE(QPieSlice*) |
|
33 | Q_DECLARE_METATYPE(QList<QPieSlice*>) | |
|
33 | 34 | |
|
34 | 35 | class tst_qpieseries : public QObject |
|
35 | 36 | { |
@@ -60,6 +61,7 private: | |||
|
60 | 61 | void tst_qpieseries::initTestCase() |
|
61 | 62 | { |
|
62 | 63 | qRegisterMetaType<QPieSlice*>("QPieSlice*"); |
|
64 | qRegisterMetaType<QList<QPieSlice*> >("QList<QPieSlice*>"); | |
|
63 | 65 | } |
|
64 | 66 | |
|
65 | 67 | void tst_qpieseries::cleanupTestCase() |
@@ -149,6 +151,7 void tst_qpieseries::properties() | |||
|
149 | 151 | void tst_qpieseries::append() |
|
150 | 152 | { |
|
151 | 153 | QPieSeries s; |
|
154 | QSignalSpy addedSpy(&s, SIGNAL(added(QList<QPieSlice*>))); | |
|
152 | 155 | |
|
153 | 156 | // append pointer |
|
154 | 157 | QPieSlice *slice1 = 0; |
@@ -157,6 +160,10 void tst_qpieseries::append() | |||
|
157 | 160 | QVERIFY(s.append(slice1)); |
|
158 | 161 | QVERIFY(!s.append(slice1)); |
|
159 | 162 | QCOMPARE(s.count(), 1); |
|
163 | QCOMPARE(addedSpy.count(), 1); | |
|
164 | QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0)); | |
|
165 | QCOMPARE(added.count(), 1); | |
|
166 | QCOMPARE(added.first(), slice1); | |
|
160 | 167 | |
|
161 | 168 | // append pointer list |
|
162 | 169 | QList<QPieSlice *> list; |
@@ -169,11 +176,20 void tst_qpieseries::append() | |||
|
169 | 176 | QVERIFY(s.append(list)); |
|
170 | 177 | QVERIFY(!s.append(list)); |
|
171 | 178 | QCOMPARE(s.count(), 3); |
|
179 | QCOMPARE(addedSpy.count(), 2); | |
|
180 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0)); | |
|
181 | QCOMPARE(added.count(), 2); | |
|
182 | QCOMPARE(added, list); | |
|
172 | 183 | |
|
173 | 184 | // append operator |
|
174 |
|
|
|
185 | QPieSlice *slice4 = new QPieSlice("slice 4", 4); | |
|
186 | s << slice4; | |
|
175 | 187 | s << slice1; // fails because already added |
|
176 | 188 | QCOMPARE(s.count(), 4); |
|
189 | QCOMPARE(addedSpy.count(), 3); | |
|
190 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0)); | |
|
191 | QCOMPARE(added.count(), 1); | |
|
192 | QCOMPARE(added.first(), slice4); | |
|
177 | 193 | |
|
178 | 194 | // append with params |
|
179 | 195 | QPieSlice *slice5 = s.append("slice 5", 5); |
@@ -181,6 +197,10 void tst_qpieseries::append() | |||
|
181 | 197 | QCOMPARE(slice5->value(), 5.0); |
|
182 | 198 | QCOMPARE(slice5->label(), QString("slice 5")); |
|
183 | 199 | QCOMPARE(s.count(), 5); |
|
200 | QCOMPARE(addedSpy.count(), 4); | |
|
201 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0)); | |
|
202 | QCOMPARE(added.count(), 1); | |
|
203 | QCOMPARE(added.first(), slice5); | |
|
184 | 204 | |
|
185 | 205 | // check slices |
|
186 | 206 | QVERIFY(!s.isEmpty()); |
@@ -193,6 +213,7 void tst_qpieseries::append() | |||
|
193 | 213 | void tst_qpieseries::insert() |
|
194 | 214 | { |
|
195 | 215 | QPieSeries s; |
|
216 | QSignalSpy addedSpy(&s, SIGNAL(added(QList<QPieSlice*>))); | |
|
196 | 217 | |
|
197 | 218 | // insert one slice |
|
198 | 219 | QPieSlice *slice1 = 0; |
@@ -203,15 +224,31 void tst_qpieseries::insert() | |||
|
203 | 224 | QVERIFY(s.insert(0, slice1)); |
|
204 | 225 | QVERIFY(!s.insert(0, slice1)); |
|
205 | 226 | QCOMPARE(s.count(), 1); |
|
227 | QCOMPARE(addedSpy.count(), 1); | |
|
228 | QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0)); | |
|
229 | QCOMPARE(added.count(), 1); | |
|
230 | QCOMPARE(added.first(), slice1); | |
|
206 | 231 | |
|
207 | 232 | // add some more slices |
|
208 | s.append("slice 2", 2); | |
|
209 | s.append("slice 4", 4); | |
|
233 | QPieSlice *slice2 = s.append("slice 2", 2); | |
|
234 | QPieSlice *slice4 = s.append("slice 4", 4); | |
|
210 | 235 | QCOMPARE(s.count(), 3); |
|
236 | QCOMPARE(addedSpy.count(), 3); | |
|
237 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0)); | |
|
238 | QCOMPARE(added.count(), 1); | |
|
239 | QCOMPARE(added.first(), slice2); | |
|
240 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0)); | |
|
241 | QCOMPARE(added.count(), 1); | |
|
242 | QCOMPARE(added.first(), slice4); | |
|
211 | 243 | |
|
212 | 244 | // insert between slices |
|
213 |
|
|
|
245 | QPieSlice *slice3 = new QPieSlice("slice 3", 3); | |
|
246 | s.insert(2, slice3); | |
|
214 | 247 | QCOMPARE(s.count(), 4); |
|
248 | QCOMPARE(addedSpy.count(), 4); | |
|
249 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0)); | |
|
250 | QCOMPARE(added.count(), 1); | |
|
251 | QCOMPARE(added.first(), slice3); | |
|
215 | 252 | |
|
216 | 253 | // check slices |
|
217 | 254 | for (int i=0; i<s.count(); i++) { |
@@ -223,6 +260,7 void tst_qpieseries::insert() | |||
|
223 | 260 | void tst_qpieseries::remove() |
|
224 | 261 | { |
|
225 | 262 | QPieSeries s; |
|
263 | QSignalSpy removedSpy(&s, SIGNAL(removed(QList<QPieSlice*>))); | |
|
226 | 264 | |
|
227 | 265 | // add some slices |
|
228 | 266 | QPieSlice *slice1 = s.append("slice 1", 1); |
@@ -241,12 +279,21 void tst_qpieseries::remove() | |||
|
241 | 279 | QVERIFY(!s.remove(slice1)); |
|
242 | 280 | QCOMPARE(s.count(), 2); |
|
243 | 281 | QCOMPARE(s.slices().at(0)->label(), slice2->label()); |
|
282 | QCOMPARE(removedSpy.count(), 1); | |
|
283 | QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0)); | |
|
284 | QCOMPARE(removed.count(), 1); | |
|
285 | QCOMPARE(removed.first(), slice1); | |
|
244 | 286 | |
|
245 | 287 | // remove all |
|
246 | 288 | s.clear(); |
|
247 | 289 | QVERIFY(s.isEmpty()); |
|
248 | 290 | QVERIFY(s.slices().isEmpty()); |
|
249 | 291 | QCOMPARE(s.count(), 0); |
|
292 | QCOMPARE(removedSpy.count(), 2); | |
|
293 | removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(1).at(0)); | |
|
294 | QCOMPARE(removed.count(), 2); | |
|
295 | QCOMPARE(removed.first(), slice2); | |
|
296 | QCOMPARE(removed.last(), slice3); | |
|
250 | 297 | |
|
251 | 298 | // check that slices were actually destroyed |
|
252 | 299 | TRY_COMPARE(spy1.count(), 1); |
General Comments 0
You need to be logged in to leave comments.
Login now