|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Tests for WidgetBase class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "testwidgetmodel.h" |
|
20 #include "hswidget.h" |
|
21 #include "hswidget_p.h" |
|
22 #include "ihswidgetpreferenceservice.h" |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 void TestWidgetModel::testWidgetInterface() |
|
30 { |
|
31 QGraphicsWidget parent; |
|
32 |
|
33 TestWidget3 *w = new TestWidget3(&parent); |
|
34 w->mStartResult = HsWidget::StartResultRunning; |
|
35 w->mStopResult = HsWidget::StopResultFinished; |
|
36 |
|
37 QSignalSpy succeededSpy(w, SIGNAL(succeeded())); |
|
38 QSignalSpy stoppedSpy(w, SIGNAL(stopped())); |
|
39 QSignalSpy faultedSpy(w, SIGNAL(faulted())); |
|
40 |
|
41 w->start(); |
|
42 |
|
43 QCOMPARE(succeededSpy.count(), 0); |
|
44 QCOMPARE(stoppedSpy.count(), 0); |
|
45 QCOMPARE(faultedSpy.count(), 0); |
|
46 |
|
47 w->suspend(); |
|
48 |
|
49 QCOMPARE(succeededSpy.count(), 0); |
|
50 QCOMPARE(stoppedSpy.count(), 0); |
|
51 QCOMPARE(faultedSpy.count(), 0); |
|
52 |
|
53 w->resume(); |
|
54 |
|
55 QCOMPARE(succeededSpy.count(), 0); |
|
56 QCOMPARE(stoppedSpy.count(), 0); |
|
57 QCOMPARE(faultedSpy.count(), 0); |
|
58 |
|
59 w->stop(); |
|
60 |
|
61 QCOMPARE(succeededSpy.count(), 0); |
|
62 QCOMPARE(stoppedSpy.count(), 1); |
|
63 QCOMPARE(faultedSpy.count(), 0); |
|
64 stoppedSpy.clear(); |
|
65 |
|
66 w->start(); |
|
67 |
|
68 QCOMPARE(succeededSpy.count(), 0); |
|
69 QCOMPARE(stoppedSpy.count(), 0); |
|
70 QCOMPARE(faultedSpy.count(), 0); |
|
71 |
|
72 w->setFinishedState(); |
|
73 |
|
74 QCOMPARE(succeededSpy.count(), 1); |
|
75 QCOMPARE(stoppedSpy.count(), 0); |
|
76 QCOMPARE(faultedSpy.count(), 0); |
|
77 succeededSpy.clear(); |
|
78 |
|
79 w->start(); |
|
80 |
|
81 QCOMPARE(succeededSpy.count(), 0); |
|
82 QCOMPARE(stoppedSpy.count(), 0); |
|
83 QCOMPARE(faultedSpy.count(), 0); |
|
84 |
|
85 w->setFaultingState(); |
|
86 |
|
87 QCOMPARE(succeededSpy.count(), 0); |
|
88 QCOMPARE(stoppedSpy.count(), 0); |
|
89 QCOMPARE(faultedSpy.count(), 0); |
|
90 |
|
91 w->setFaultedState(); |
|
92 |
|
93 QCOMPARE(succeededSpy.count(), 0); |
|
94 QCOMPARE(stoppedSpy.count(), 0); |
|
95 QCOMPARE(faultedSpy.count(), 1); |
|
96 |
|
97 faultedSpy.clear(); |
|
98 } |
|
99 |
|
100 |
|
101 void TestWidgetModel::testWidgetConstructor() |
|
102 { |
|
103 { |
|
104 TestWidget w(0); |
|
105 QVERIFY(!w.widgetPreferenceService()); |
|
106 } |
|
107 |
|
108 { |
|
109 HsWidget *parent = new TestWidget(0); |
|
110 QVERIFY(parent); |
|
111 HsWidget *child = new TestWidget(parent); |
|
112 QVERIFY(child); |
|
113 QVERIFY(child->parentItem() == parent); |
|
114 delete parent; |
|
115 } |
|
116 } |
|
117 |
|
118 |
|
119 void TestWidgetModel::testWidgetPreferenceService() |
|
120 { |
|
121 QGraphicsWidget parent; |
|
122 |
|
123 HsWidget *w = new TestWidget(&parent); |
|
124 QObject invalid; |
|
125 w->setProperty("http://homescreen.nokia.com/runtimeservices/widgetpreferenceservice", qVariantFromValue(&invalid)); |
|
126 QVERIFY(!w->widgetPreferenceService()); |
|
127 |
|
128 } |
|
129 |
|
130 |
|
131 void TestWidgetModel::testWidgetStart_data() |
|
132 { |
|
133 QTest::addColumn<int>("fromState"); |
|
134 QTest::addColumn<int>("toState"); |
|
135 QTest::addColumn<int>("startResult"); |
|
136 QTest::addColumn<int>("succeededEmitCount"); |
|
137 QTest::addColumn<int>("stoppedEmitCount"); |
|
138 QTest::addColumn<int>("faultedEmitCount"); |
|
139 |
|
140 // --- |
|
141 |
|
142 QTest::newRow("Constructed -> Running") |
|
143 << (int)HsWidgetPrivate::WidgetStateConstructed |
|
144 << (int)HsWidgetPrivate::WidgetStateRunning |
|
145 << (int)HsWidget::StartResultRunning |
|
146 << 0 |
|
147 << 0 |
|
148 << 0; |
|
149 |
|
150 QTest::newRow("Finished -> Running") |
|
151 << (int)HsWidgetPrivate::WidgetStateFinished |
|
152 << (int)HsWidgetPrivate::WidgetStateRunning |
|
153 << (int)HsWidget::StartResultRunning |
|
154 << 0 |
|
155 << 0 |
|
156 << 0; |
|
157 |
|
158 // --- |
|
159 |
|
160 QTest::newRow("Constructed -> Finished") |
|
161 << (int)HsWidgetPrivate::WidgetStateConstructed |
|
162 << (int)HsWidgetPrivate::WidgetStateFinished |
|
163 << (int)HsWidget::StartResultFinished |
|
164 << 1 |
|
165 << 0 |
|
166 << 0; |
|
167 |
|
168 QTest::newRow("Finished -> Finished") |
|
169 << (int)HsWidgetPrivate::WidgetStateFinished |
|
170 << (int)HsWidgetPrivate::WidgetStateFinished |
|
171 << (int)HsWidget::StartResultFinished |
|
172 << 1 |
|
173 << 0 |
|
174 << 0; |
|
175 |
|
176 // --- |
|
177 |
|
178 QTest::newRow("Constructed -> Faulted") |
|
179 << (int)HsWidgetPrivate::WidgetStateConstructed |
|
180 << (int)HsWidgetPrivate::WidgetStateFinished |
|
181 << (int)HsWidget::StartResultFaulted |
|
182 << 0 |
|
183 << 0 |
|
184 << 1; |
|
185 |
|
186 QTest::newRow("Finished -> Faulted") |
|
187 << (int)HsWidgetPrivate::WidgetStateFinished |
|
188 << (int)HsWidgetPrivate::WidgetStateFinished |
|
189 << (int)HsWidget::StartResultFaulted |
|
190 << 0 |
|
191 << 0 |
|
192 << 1; |
|
193 |
|
194 // --- |
|
195 |
|
196 QTest::newRow("Running -> Running") |
|
197 << (int)HsWidgetPrivate::WidgetStateRunning |
|
198 << (int)HsWidgetPrivate::WidgetStateRunning |
|
199 << (int)HsWidget::StartResultFaulted |
|
200 << 0 |
|
201 << 0 |
|
202 << 0; |
|
203 |
|
204 QTest::newRow("Faulting -> Faulting") |
|
205 << (int)HsWidgetPrivate::WidgetStateFaulting |
|
206 << (int)HsWidgetPrivate::WidgetStateFaulting |
|
207 << (int)HsWidget::StartResultFaulted |
|
208 << 0 |
|
209 << 0 |
|
210 << 0; |
|
211 |
|
212 QTest::newRow("Finishing -> Finishing") |
|
213 << (int)HsWidgetPrivate::WidgetStateFinishing |
|
214 << (int)HsWidgetPrivate::WidgetStateFinishing |
|
215 << (int)HsWidget::StartResultFaulted |
|
216 << 0 |
|
217 << 0 |
|
218 << 0; |
|
219 |
|
220 QTest::newRow("Suspended -> Suspended") |
|
221 << (int)HsWidgetPrivate::WidgetStateSuspended |
|
222 << (int)HsWidgetPrivate::WidgetStateSuspended |
|
223 << (int)HsWidget::StartResultFaulted |
|
224 << 0 |
|
225 << 0 |
|
226 << 0; |
|
227 } |
|
228 |
|
229 |
|
230 void TestWidgetModel::testWidgetStart() |
|
231 { |
|
232 QFETCH(int, fromState); |
|
233 QFETCH(int, toState); |
|
234 QFETCH(int, startResult); |
|
235 QFETCH(int, succeededEmitCount); |
|
236 QFETCH(int, stoppedEmitCount); |
|
237 QFETCH(int, faultedEmitCount); |
|
238 |
|
239 TestWidget* w = new TestWidget(); |
|
240 HsWidgetPrivate *wp = new HsWidgetPrivate(w); |
|
241 |
|
242 wp->mState = (HsWidgetPrivate::WidgetState)fromState; |
|
243 w->mStartResult = (HsWidget::StartResult)startResult; |
|
244 |
|
245 QSignalSpy succeededSpy(w, SIGNAL(succeeded())); |
|
246 QSignalSpy stoppedSpy(w, SIGNAL(stopped())); |
|
247 QSignalSpy faultedSpy(w, SIGNAL(faulted())); |
|
248 |
|
249 wp->start(); |
|
250 |
|
251 QVERIFY(wp->mState == toState); |
|
252 QCOMPARE(succeededSpy.count(), succeededEmitCount); |
|
253 QCOMPARE(stoppedSpy.count(), stoppedEmitCount); |
|
254 QCOMPARE(faultedSpy.count(), faultedEmitCount); |
|
255 |
|
256 delete w; |
|
257 } |
|
258 |
|
259 |
|
260 void TestWidgetModel::testWidgetSuspend_data() |
|
261 { |
|
262 QTest::addColumn<int>("fromState"); |
|
263 QTest::addColumn<int>("toState"); |
|
264 QTest::addColumn<int>("suspendResult"); |
|
265 QTest::addColumn<int>("succeededEmitCount"); |
|
266 QTest::addColumn<int>("stoppedEmitCount"); |
|
267 QTest::addColumn<int>("faultedEmitCount"); |
|
268 |
|
269 // --- |
|
270 |
|
271 QTest::newRow("Running -> Suspended") |
|
272 << (int)HsWidgetPrivate::WidgetStateRunning |
|
273 << (int)HsWidgetPrivate::WidgetStateSuspended |
|
274 << (int)HsWidget::SuspendResultSuspended |
|
275 << 0 |
|
276 << 0 |
|
277 << 0; |
|
278 |
|
279 QTest::newRow("Running -> Faulted") |
|
280 << (int)HsWidgetPrivate::WidgetStateRunning |
|
281 << (int)HsWidgetPrivate::WidgetStateFinished |
|
282 << (int)HsWidget::SuspendResultFaulted |
|
283 << 0 |
|
284 << 0 |
|
285 << 1; |
|
286 |
|
287 QTest::newRow("Running -> Faulting") |
|
288 << (int)HsWidgetPrivate::WidgetStateRunning |
|
289 << (int)HsWidgetPrivate::WidgetStateFaulting |
|
290 << (int)HsWidget::SuspendResultFaulting |
|
291 << 0 |
|
292 << 0 |
|
293 << 0; |
|
294 |
|
295 // --- |
|
296 |
|
297 QTest::newRow("Constructed -> Constructed") |
|
298 << (int)HsWidgetPrivate::WidgetStateConstructed |
|
299 << (int)HsWidgetPrivate::WidgetStateConstructed |
|
300 << (int)HsWidget::SuspendResultFaulted |
|
301 << 0 |
|
302 << 0 |
|
303 << 0; |
|
304 |
|
305 QTest::newRow("Finished -> Finished") |
|
306 << (int)HsWidgetPrivate::WidgetStateFinished |
|
307 << (int)HsWidgetPrivate::WidgetStateFinished |
|
308 << (int)HsWidget::SuspendResultFaulted |
|
309 << 0 |
|
310 << 0 |
|
311 << 0; |
|
312 |
|
313 QTest::newRow("Faulting -> Faulting") |
|
314 << (int)HsWidgetPrivate::WidgetStateFaulting |
|
315 << (int)HsWidgetPrivate::WidgetStateFaulting |
|
316 << (int)HsWidget::SuspendResultFaulted |
|
317 << 0 |
|
318 << 0 |
|
319 << 0; |
|
320 |
|
321 QTest::newRow("Finishing -> Finishing") |
|
322 << (int)HsWidgetPrivate::WidgetStateFinishing |
|
323 << (int)HsWidgetPrivate::WidgetStateFinishing |
|
324 << (int)HsWidget::SuspendResultFaulted |
|
325 << 0 |
|
326 << 0 |
|
327 << 0; |
|
328 |
|
329 QTest::newRow("Suspended -> Suspended") |
|
330 << (int)HsWidgetPrivate::WidgetStateSuspended |
|
331 << (int)HsWidgetPrivate::WidgetStateSuspended |
|
332 << (int)HsWidget::SuspendResultFaulted |
|
333 << 0 |
|
334 << 0 |
|
335 << 0; |
|
336 } |
|
337 |
|
338 |
|
339 void TestWidgetModel::testWidgetSuspend() |
|
340 { |
|
341 QFETCH(int, fromState); |
|
342 QFETCH(int, toState); |
|
343 QFETCH(int, suspendResult); |
|
344 QFETCH(int, succeededEmitCount); |
|
345 QFETCH(int, stoppedEmitCount); |
|
346 QFETCH(int, faultedEmitCount); |
|
347 |
|
348 TestWidget* w = new TestWidget(); |
|
349 HsWidgetPrivate *wp = new HsWidgetPrivate(w); |
|
350 |
|
351 wp->mState = (HsWidgetPrivate::WidgetState)fromState; |
|
352 w->mSuspendResult = (HsWidget::SuspendResult)suspendResult; |
|
353 |
|
354 QSignalSpy succeededSpy(w, SIGNAL(succeeded())); |
|
355 QSignalSpy stoppedSpy(w, SIGNAL(stopped())); |
|
356 QSignalSpy faultedSpy(w, SIGNAL(faulted())); |
|
357 |
|
358 wp->suspend(); |
|
359 |
|
360 QVERIFY(wp->mState == toState); |
|
361 QCOMPARE(succeededSpy.count(), succeededEmitCount); |
|
362 QCOMPARE(stoppedSpy.count(), stoppedEmitCount); |
|
363 QCOMPARE(faultedSpy.count(), faultedEmitCount); |
|
364 |
|
365 delete w; |
|
366 } |
|
367 |
|
368 |
|
369 void TestWidgetModel::testWidgetResume_data() |
|
370 { |
|
371 QTest::addColumn<int>("fromState"); |
|
372 QTest::addColumn<int>("toState"); |
|
373 QTest::addColumn<int>("resumeResult"); |
|
374 QTest::addColumn<int>("succeededEmitCount"); |
|
375 QTest::addColumn<int>("stoppedEmitCount"); |
|
376 QTest::addColumn<int>("faultedEmitCount"); |
|
377 |
|
378 // --- |
|
379 |
|
380 QTest::newRow("Suspended -> Running") |
|
381 << (int)HsWidgetPrivate::WidgetStateSuspended |
|
382 << (int)HsWidgetPrivate::WidgetStateRunning |
|
383 << (int)HsWidget::ResumeResultRunning |
|
384 << 0 |
|
385 << 0 |
|
386 << 0; |
|
387 |
|
388 QTest::newRow("Suspended -> Faulted") |
|
389 << (int)HsWidgetPrivate::WidgetStateSuspended |
|
390 << (int)HsWidgetPrivate::WidgetStateFinished |
|
391 << (int)HsWidget::ResumeResultFaulted |
|
392 << 0 |
|
393 << 0 |
|
394 << 1; |
|
395 |
|
396 QTest::newRow("Suspended -> Faulting") |
|
397 << (int)HsWidgetPrivate::WidgetStateSuspended |
|
398 << (int)HsWidgetPrivate::WidgetStateFaulting |
|
399 << (int)HsWidget::ResumeResultFaulting |
|
400 << 0 |
|
401 << 0 |
|
402 << 0; |
|
403 |
|
404 // --- |
|
405 |
|
406 QTest::newRow("Constructed -> Constructed") |
|
407 << (int)HsWidgetPrivate::WidgetStateConstructed |
|
408 << (int)HsWidgetPrivate::WidgetStateConstructed |
|
409 << (int)HsWidget::ResumeResultFaulted |
|
410 << 0 |
|
411 << 0 |
|
412 << 0; |
|
413 |
|
414 QTest::newRow("Running -> Running") |
|
415 << (int)HsWidgetPrivate::WidgetStateRunning |
|
416 << (int)HsWidgetPrivate::WidgetStateRunning |
|
417 << (int)HsWidget::ResumeResultFaulted |
|
418 << 0 |
|
419 << 0 |
|
420 << 0; |
|
421 |
|
422 QTest::newRow("Finished -> Finished") |
|
423 << (int)HsWidgetPrivate::WidgetStateFinished |
|
424 << (int)HsWidgetPrivate::WidgetStateFinished |
|
425 << (int)HsWidget::ResumeResultFaulted |
|
426 << 0 |
|
427 << 0 |
|
428 << 0; |
|
429 |
|
430 QTest::newRow("Faulting -> Faulting") |
|
431 << (int)HsWidgetPrivate::WidgetStateFaulting |
|
432 << (int)HsWidgetPrivate::WidgetStateFaulting |
|
433 << (int)HsWidget::ResumeResultFaulted |
|
434 << 0 |
|
435 << 0 |
|
436 << 0; |
|
437 |
|
438 QTest::newRow("Finishing -> Finishing") |
|
439 << (int)HsWidgetPrivate::WidgetStateFinishing |
|
440 << (int)HsWidgetPrivate::WidgetStateFinishing |
|
441 << (int)HsWidget::ResumeResultFaulted |
|
442 << 0 |
|
443 << 0 |
|
444 << 0; |
|
445 } |
|
446 |
|
447 |
|
448 void TestWidgetModel::testWidgetResume() |
|
449 { |
|
450 QFETCH(int, fromState); |
|
451 QFETCH(int, toState); |
|
452 QFETCH(int, resumeResult); |
|
453 QFETCH(int, succeededEmitCount); |
|
454 QFETCH(int, stoppedEmitCount); |
|
455 QFETCH(int, faultedEmitCount); |
|
456 |
|
457 TestWidget* w = new TestWidget(); |
|
458 HsWidgetPrivate *wp = new HsWidgetPrivate(w); |
|
459 |
|
460 wp->mState = (HsWidgetPrivate::WidgetState)fromState; |
|
461 w->mResumeResult = (HsWidget::ResumeResult)resumeResult; |
|
462 |
|
463 QSignalSpy succeededSpy(w, SIGNAL(succeeded())); |
|
464 QSignalSpy stoppedSpy(w, SIGNAL(stopped())); |
|
465 QSignalSpy faultedSpy(w, SIGNAL(faulted())); |
|
466 |
|
467 wp->resume(); |
|
468 |
|
469 QVERIFY(wp->mState == toState); |
|
470 QCOMPARE(succeededSpy.count(), succeededEmitCount); |
|
471 QCOMPARE(stoppedSpy.count(), stoppedEmitCount); |
|
472 QCOMPARE(faultedSpy.count(), faultedEmitCount); |
|
473 |
|
474 delete w; |
|
475 } |
|
476 |
|
477 |
|
478 void TestWidgetModel::testWidgetStop_data() |
|
479 { |
|
480 QTest::addColumn<int>("fromState"); |
|
481 QTest::addColumn<int>("toState"); |
|
482 QTest::addColumn<int>("stopResult"); |
|
483 QTest::addColumn<int>("succeededEmitCount"); |
|
484 QTest::addColumn<int>("stoppedEmitCount"); |
|
485 QTest::addColumn<int>("faultedEmitCount"); |
|
486 |
|
487 // --- |
|
488 |
|
489 QTest::newRow("Running -> Finished") |
|
490 << (int)HsWidgetPrivate::WidgetStateRunning |
|
491 << (int)HsWidgetPrivate::WidgetStateFinished |
|
492 << (int)HsWidget::StopResultFinished |
|
493 << 0 |
|
494 << 1 |
|
495 << 0; |
|
496 |
|
497 QTest::newRow("Running -> Finishing") |
|
498 << (int)HsWidgetPrivate::WidgetStateRunning |
|
499 << (int)HsWidgetPrivate::WidgetStateFinishing |
|
500 << (int)HsWidget::StopResultFinishing |
|
501 << 0 |
|
502 << 0 |
|
503 << 0; |
|
504 |
|
505 QTest::newRow("Running -> Faulted") |
|
506 << (int)HsWidgetPrivate::WidgetStateRunning |
|
507 << (int)HsWidgetPrivate::WidgetStateFinished |
|
508 << (int)HsWidget::StopResultFaulted |
|
509 << 0 |
|
510 << 0 |
|
511 << 1; |
|
512 |
|
513 QTest::newRow("Running -> Faulting") |
|
514 << (int)HsWidgetPrivate::WidgetStateRunning |
|
515 << (int)HsWidgetPrivate::WidgetStateFaulting |
|
516 << (int)HsWidget::StopResultFaulting |
|
517 << 0 |
|
518 << 0 |
|
519 << 0; |
|
520 |
|
521 // --- |
|
522 |
|
523 QTest::newRow("Suspended -> Finished") |
|
524 << (int)HsWidgetPrivate::WidgetStateSuspended |
|
525 << (int)HsWidgetPrivate::WidgetStateFinished |
|
526 << (int)HsWidget::StopResultFinished |
|
527 << 0 |
|
528 << 1 |
|
529 << 0; |
|
530 |
|
531 QTest::newRow("Suspended -> Finishing") |
|
532 << (int)HsWidgetPrivate::WidgetStateSuspended |
|
533 << (int)HsWidgetPrivate::WidgetStateFinishing |
|
534 << (int)HsWidget::StopResultFinishing |
|
535 << 0 |
|
536 << 0 |
|
537 << 0; |
|
538 |
|
539 QTest::newRow("Suspended -> Faulted") |
|
540 << (int)HsWidgetPrivate::WidgetStateSuspended |
|
541 << (int)HsWidgetPrivate::WidgetStateFinished |
|
542 << (int)HsWidget::StopResultFaulted |
|
543 << 0 |
|
544 << 0 |
|
545 << 1; |
|
546 |
|
547 QTest::newRow("Suspended -> Faulting") |
|
548 << (int)HsWidgetPrivate::WidgetStateSuspended |
|
549 << (int)HsWidgetPrivate::WidgetStateFaulting |
|
550 << (int)HsWidget::StopResultFaulting |
|
551 << 0 |
|
552 << 0 |
|
553 << 0; |
|
554 |
|
555 // --- |
|
556 |
|
557 QTest::newRow("Constructed -> Constructed") |
|
558 << (int)HsWidgetPrivate::WidgetStateConstructed |
|
559 << (int)HsWidgetPrivate::WidgetStateConstructed |
|
560 << (int)HsWidget::StopResultFaulted |
|
561 << 0 |
|
562 << 0 |
|
563 << 0; |
|
564 |
|
565 QTest::newRow("Finished -> Finished") |
|
566 << (int)HsWidgetPrivate::WidgetStateFinished |
|
567 << (int)HsWidgetPrivate::WidgetStateFinished |
|
568 << (int)HsWidget::StopResultFaulted |
|
569 << 0 |
|
570 << 0 |
|
571 << 0; |
|
572 |
|
573 QTest::newRow("Faulting -> Faulting") |
|
574 << (int)HsWidgetPrivate::WidgetStateFaulting |
|
575 << (int)HsWidgetPrivate::WidgetStateFaulting |
|
576 << (int)HsWidget::StopResultFaulted |
|
577 << 0 |
|
578 << 0 |
|
579 << 0; |
|
580 |
|
581 QTest::newRow("Finishing -> Finishing") |
|
582 << (int)HsWidgetPrivate::WidgetStateFinishing |
|
583 << (int)HsWidgetPrivate::WidgetStateFinishing |
|
584 << (int)HsWidget::StopResultFaulted |
|
585 << 0 |
|
586 << 0 |
|
587 << 0; |
|
588 } |
|
589 |
|
590 |
|
591 void TestWidgetModel::testWidgetStop() |
|
592 { |
|
593 QFETCH(int, fromState); |
|
594 QFETCH(int, toState); |
|
595 QFETCH(int, stopResult); |
|
596 QFETCH(int, succeededEmitCount); |
|
597 QFETCH(int, stoppedEmitCount); |
|
598 QFETCH(int, faultedEmitCount); |
|
599 |
|
600 TestWidget* w = new TestWidget(); |
|
601 HsWidgetPrivate *wp = new HsWidgetPrivate(w); |
|
602 |
|
603 wp->mState = (HsWidgetPrivate::WidgetState)fromState; |
|
604 w->mStopResult = (HsWidget::StopResult)stopResult; |
|
605 |
|
606 QSignalSpy succeededSpy(w, SIGNAL(succeeded())); |
|
607 QSignalSpy stoppedSpy(w, SIGNAL(stopped())); |
|
608 QSignalSpy faultedSpy(w, SIGNAL(faulted())); |
|
609 |
|
610 wp->stop(); |
|
611 |
|
612 QVERIFY(wp->mState == toState); |
|
613 QCOMPARE(succeededSpy.count(), succeededEmitCount); |
|
614 QCOMPARE(stoppedSpy.count(), stoppedEmitCount); |
|
615 QCOMPARE(faultedSpy.count(), faultedEmitCount); |
|
616 |
|
617 delete w; |
|
618 } |
|
619 |
|
620 |
|
621 void TestWidgetModel::testWidgetSetFinished_data() |
|
622 { |
|
623 QTest::addColumn<int>("fromState"); |
|
624 QTest::addColumn<int>("toState"); |
|
625 QTest::addColumn<int>("succeededEmitCount"); |
|
626 QTest::addColumn<int>("stoppedEmitCount"); |
|
627 QTest::addColumn<int>("faultedEmitCount"); |
|
628 |
|
629 // --- |
|
630 |
|
631 QTest::newRow("Constructed -> Constructed") |
|
632 << (int)HsWidgetPrivate::WidgetStateConstructed |
|
633 << (int)HsWidgetPrivate::WidgetStateConstructed |
|
634 << 0 |
|
635 << 0 |
|
636 << 0; |
|
637 |
|
638 QTest::newRow("Finished -> Finished") |
|
639 << (int)HsWidgetPrivate::WidgetStateFinished |
|
640 << (int)HsWidgetPrivate::WidgetStateFinished |
|
641 << 0 |
|
642 << 0 |
|
643 << 0; |
|
644 |
|
645 QTest::newRow("Running -> Finished") |
|
646 << (int)HsWidgetPrivate::WidgetStateRunning |
|
647 << (int)HsWidgetPrivate::WidgetStateFinished |
|
648 << 1 |
|
649 << 0 |
|
650 << 0; |
|
651 |
|
652 QTest::newRow("Suspended -> Finished") |
|
653 << (int)HsWidgetPrivate::WidgetStateSuspended |
|
654 << (int)HsWidgetPrivate::WidgetStateFinished |
|
655 << 1 |
|
656 << 0 |
|
657 << 0; |
|
658 |
|
659 QTest::newRow("Finishing -> Finished") |
|
660 << (int)HsWidgetPrivate::WidgetStateFinishing |
|
661 << (int)HsWidgetPrivate::WidgetStateFinished |
|
662 << 0 |
|
663 << 1 |
|
664 << 0; |
|
665 |
|
666 QTest::newRow("Faulting -> Finished") |
|
667 << (int)HsWidgetPrivate::WidgetStateFaulting |
|
668 << (int)HsWidgetPrivate::WidgetStateFinished |
|
669 << 0 |
|
670 << 0 |
|
671 << 1; |
|
672 } |
|
673 |
|
674 |
|
675 void TestWidgetModel::testWidgetSetFinished() |
|
676 { |
|
677 QFETCH(int, fromState); |
|
678 QFETCH(int, toState); |
|
679 QFETCH(int, succeededEmitCount); |
|
680 QFETCH(int, stoppedEmitCount); |
|
681 QFETCH(int, faultedEmitCount); |
|
682 |
|
683 TestWidget* w = new TestWidget(); |
|
684 HsWidgetPrivate *wp = new HsWidgetPrivate(w); |
|
685 |
|
686 wp->mState = (HsWidgetPrivate::WidgetState)fromState; |
|
687 |
|
688 QSignalSpy succeededSpy(w, SIGNAL(succeeded())); |
|
689 QSignalSpy stoppedSpy(w, SIGNAL(stopped())); |
|
690 QSignalSpy faultedSpy(w, SIGNAL(faulted())); |
|
691 |
|
692 wp->setFinished(); |
|
693 |
|
694 QVERIFY(wp->mState == toState); |
|
695 QCOMPARE(succeededSpy.count(), succeededEmitCount); |
|
696 QCOMPARE(stoppedSpy.count(), stoppedEmitCount); |
|
697 QCOMPARE(faultedSpy.count(), faultedEmitCount); |
|
698 |
|
699 delete w; |
|
700 } |
|
701 |
|
702 |
|
703 void TestWidgetModel::testWidgetSetFaulted_data() |
|
704 { |
|
705 QTest::addColumn<int>("fromState"); |
|
706 QTest::addColumn<int>("toState"); |
|
707 QTest::addColumn<int>("succeededEmitCount"); |
|
708 QTest::addColumn<int>("stoppedEmitCount"); |
|
709 QTest::addColumn<int>("faultedEmitCount"); |
|
710 |
|
711 // --- |
|
712 |
|
713 QTest::newRow("Constructed -> Constructed") |
|
714 << (int)HsWidgetPrivate::WidgetStateConstructed |
|
715 << (int)HsWidgetPrivate::WidgetStateConstructed |
|
716 << 0 |
|
717 << 0 |
|
718 << 0; |
|
719 |
|
720 QTest::newRow("Finished -> Finished") |
|
721 << (int)HsWidgetPrivate::WidgetStateFinished |
|
722 << (int)HsWidgetPrivate::WidgetStateFinished |
|
723 << 0 |
|
724 << 0 |
|
725 << 0; |
|
726 |
|
727 QTest::newRow("Running -> Finished") |
|
728 << (int)HsWidgetPrivate::WidgetStateRunning |
|
729 << (int)HsWidgetPrivate::WidgetStateFinished |
|
730 << 0 |
|
731 << 0 |
|
732 << 1; |
|
733 |
|
734 QTest::newRow("Suspended -> Finished") |
|
735 << (int)HsWidgetPrivate::WidgetStateSuspended |
|
736 << (int)HsWidgetPrivate::WidgetStateFinished |
|
737 << 0 |
|
738 << 0 |
|
739 << 1; |
|
740 |
|
741 QTest::newRow("Finishing -> Finished") |
|
742 << (int)HsWidgetPrivate::WidgetStateFinishing |
|
743 << (int)HsWidgetPrivate::WidgetStateFinished |
|
744 << 0 |
|
745 << 0 |
|
746 << 1; |
|
747 |
|
748 QTest::newRow("Faulting -> Finished") |
|
749 << (int)HsWidgetPrivate::WidgetStateFaulting |
|
750 << (int)HsWidgetPrivate::WidgetStateFinished |
|
751 << 0 |
|
752 << 0 |
|
753 << 1; |
|
754 } |
|
755 |
|
756 |
|
757 void TestWidgetModel::testWidgetSetFaulted() |
|
758 { |
|
759 QFETCH(int, fromState); |
|
760 QFETCH(int, toState); |
|
761 QFETCH(int, succeededEmitCount); |
|
762 QFETCH(int, stoppedEmitCount); |
|
763 QFETCH(int, faultedEmitCount); |
|
764 |
|
765 TestWidget* w = new TestWidget(); |
|
766 HsWidgetPrivate *wp = new HsWidgetPrivate(w); |
|
767 |
|
768 wp->mState = (HsWidgetPrivate::WidgetState)fromState; |
|
769 |
|
770 QSignalSpy succeededSpy(w, SIGNAL(succeeded())); |
|
771 QSignalSpy stoppedSpy(w, SIGNAL(stopped())); |
|
772 QSignalSpy faultedSpy(w, SIGNAL(faulted())); |
|
773 |
|
774 wp->setFaulted(); |
|
775 |
|
776 QVERIFY(wp->mState == toState); |
|
777 QCOMPARE(succeededSpy.count(), succeededEmitCount); |
|
778 QCOMPARE(stoppedSpy.count(), stoppedEmitCount); |
|
779 QCOMPARE(faultedSpy.count(), faultedEmitCount); |
|
780 |
|
781 delete w; |
|
782 } |
|
783 |
|
784 |
|
785 void TestWidgetModel::testWidgetSetFaulting_data() |
|
786 { |
|
787 QTest::addColumn<int>("fromState"); |
|
788 QTest::addColumn<int>("toState"); |
|
789 QTest::addColumn<int>("succeededEmitCount"); |
|
790 QTest::addColumn<int>("stoppedEmitCount"); |
|
791 QTest::addColumn<int>("faultedEmitCount"); |
|
792 |
|
793 // --- |
|
794 |
|
795 QTest::newRow("Constructed -> Constructed") |
|
796 << (int)HsWidgetPrivate::WidgetStateConstructed |
|
797 << (int)HsWidgetPrivate::WidgetStateConstructed |
|
798 << 0 |
|
799 << 0 |
|
800 << 0; |
|
801 |
|
802 QTest::newRow("Finished -> Finished") |
|
803 << (int)HsWidgetPrivate::WidgetStateFinished |
|
804 << (int)HsWidgetPrivate::WidgetStateFinished |
|
805 << 0 |
|
806 << 0 |
|
807 << 0; |
|
808 |
|
809 QTest::newRow("Faulting -> Faulting") |
|
810 << (int)HsWidgetPrivate::WidgetStateFaulting |
|
811 << (int)HsWidgetPrivate::WidgetStateFaulting |
|
812 << 0 |
|
813 << 0 |
|
814 << 0; |
|
815 |
|
816 QTest::newRow("Running -> Faulting") |
|
817 << (int)HsWidgetPrivate::WidgetStateRunning |
|
818 << (int)HsWidgetPrivate::WidgetStateFaulting |
|
819 << 0 |
|
820 << 0 |
|
821 << 0; |
|
822 |
|
823 QTest::newRow("Suspended -> Faulting") |
|
824 << (int)HsWidgetPrivate::WidgetStateSuspended |
|
825 << (int)HsWidgetPrivate::WidgetStateFaulting |
|
826 << 0 |
|
827 << 0 |
|
828 << 0; |
|
829 |
|
830 QTest::newRow("Finishing -> Faulting") |
|
831 << (int)HsWidgetPrivate::WidgetStateFinishing |
|
832 << (int)HsWidgetPrivate::WidgetStateFaulting |
|
833 << 0 |
|
834 << 0 |
|
835 << 0; |
|
836 } |
|
837 |
|
838 |
|
839 void TestWidgetModel::testWidgetSetFaulting() |
|
840 { |
|
841 QFETCH(int, fromState); |
|
842 QFETCH(int, toState); |
|
843 QFETCH(int, succeededEmitCount); |
|
844 QFETCH(int, stoppedEmitCount); |
|
845 QFETCH(int, faultedEmitCount); |
|
846 |
|
847 TestWidget* w = new TestWidget(); |
|
848 HsWidgetPrivate *wp = new HsWidgetPrivate(w); |
|
849 |
|
850 wp->mState = (HsWidgetPrivate::WidgetState)fromState; |
|
851 |
|
852 QSignalSpy succeededSpy(w, SIGNAL(succeeded())); |
|
853 QSignalSpy stoppedSpy(w, SIGNAL(stopped())); |
|
854 QSignalSpy faultedSpy(w, SIGNAL(faulted())); |
|
855 |
|
856 wp->setFaulting(); |
|
857 |
|
858 QVERIFY(wp->mState == toState); |
|
859 QCOMPARE(succeededSpy.count(), succeededEmitCount); |
|
860 QCOMPARE(stoppedSpy.count(), stoppedEmitCount); |
|
861 QCOMPARE(faultedSpy.count(), faultedEmitCount); |
|
862 |
|
863 delete w; |
|
864 } |
|
865 |