|
1 /** |
|
2 * Copyright (c) 2010 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: tester for methods in VideoCollectionUiLoader |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <hbdocumentloader.h> |
|
19 #include <hbgroupbox.h> |
|
20 #include <hbaction.h> |
|
21 #include <hbapplication.h> |
|
22 #include <hbmainwindow.h> |
|
23 #include <hbinstance.h> |
|
24 #include <hbview.h> |
|
25 #include <qhash.h> |
|
26 #include <qmap.h> |
|
27 #include <qset.h> |
|
28 #include <qdebug.h> |
|
29 |
|
30 #include "testvideocollectionuiloader.h" |
|
31 #include "videohintwidget.h" |
|
32 #include "videocollectionwrapperdata.h" |
|
33 |
|
34 #define private public |
|
35 #include "videocollectionuiloader.h" |
|
36 #include "videocollectionuiloaderdef.h" |
|
37 #undef private |
|
38 |
|
39 int main(int argc, char *argv[]) |
|
40 { |
|
41 HbApplication app(argc, argv); |
|
42 HbMainWindow window; |
|
43 TestVideoCollectionUiLoader tv; |
|
44 int res; |
|
45 if (argc > 1) |
|
46 { |
|
47 res = QTest::qExec(&tv, argc, argv); |
|
48 } |
|
49 else |
|
50 { |
|
51 char *pass[3]; |
|
52 pass[0] = argv[0]; |
|
53 pass[1] = "-o"; |
|
54 pass[2] = "c:\\data\\testvideocollectionuiloader.txt"; |
|
55 res = QTest::qExec(&tv, 3, pass); |
|
56 } |
|
57 |
|
58 return res; |
|
59 } |
|
60 |
|
61 TestVideoCollectionUiLoader::TestVideoCollectionUiLoader(): |
|
62 mTestObject(0) |
|
63 { |
|
64 |
|
65 } |
|
66 |
|
67 TestVideoCollectionUiLoader::~TestVideoCollectionUiLoader() |
|
68 { |
|
69 cleanup(); |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // init |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 void TestVideoCollectionUiLoader::init() |
|
77 { |
|
78 // create test object |
|
79 if (!mTestObject) |
|
80 { |
|
81 mTestObject = new VideoCollectionUiLoader; |
|
82 } |
|
83 |
|
84 // clear object list |
|
85 mObjects.clear(); |
|
86 |
|
87 HbDocumentLoader::cleanup(); |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // cleanup |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 void TestVideoCollectionUiLoader::cleanup() |
|
95 { |
|
96 // delete test object |
|
97 delete mTestObject; |
|
98 mTestObject = 0; |
|
99 } |
|
100 |
|
101 // TEST CASES START ---------------------------------------------------------- |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // testAddData |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 void TestVideoCollectionUiLoader::testAddData() |
|
108 { |
|
109 VideoCollectionUiLoaderParam banner( |
|
110 DOCML_NAME_VC_HEADINGBANNER, |
|
111 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
112 true, |
|
113 VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
114 VideoCollectionUiLoaderParam collectionWidget( |
|
115 DOCML_NAME_VC_COLLECTIONWIDGET, |
|
116 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
117 DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST, |
|
118 true, |
|
119 VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
120 VideoCollectionUiLoaderParam collectionContentWidget( |
|
121 DOCML_NAME_VC_COLLECTIONCONTENTWIDGET, |
|
122 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
123 DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST, |
|
124 true, |
|
125 VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
126 const int COUNT = 3; |
|
127 |
|
128 // add items |
|
129 QList<VideoCollectionUiLoaderParam> params; |
|
130 params.append(banner); |
|
131 params.append(collectionWidget); |
|
132 params.append(collectionContentWidget); |
|
133 mTestObject->addData(params, |
|
134 this, |
|
135 SLOT(handleObjectReady(QObject*, const QString&))); |
|
136 QVERIFY(mTestObject->mQueue.count() == COUNT); |
|
137 QVERIFY(mTestObject->mQueue.contains(banner)); |
|
138 QVERIFY(mTestObject->mQueue.contains(collectionWidget)); |
|
139 QVERIFY(mTestObject->mQueue.contains(collectionContentWidget)); |
|
140 |
|
141 // add duplicate items |
|
142 mTestObject->addData(params, |
|
143 this, |
|
144 SLOT(handleObjectReady(QObject*, const QString&))); |
|
145 QVERIFY(mTestObject->mQueue.count() == COUNT); |
|
146 QVERIFY(mTestObject->mQueue.contains(banner)); |
|
147 QVERIFY(mTestObject->mQueue.contains(collectionWidget)); |
|
148 QVERIFY(mTestObject->mQueue.contains(collectionContentWidget)); |
|
149 |
|
150 // load first phase and add duplicate items |
|
151 mTestObject->loadPhase(VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
152 QTest::qWait(1000); // wait 1 second |
|
153 mTestObject->addData(params, |
|
154 this, |
|
155 SLOT(handleObjectReady(QObject*, const QString&))); |
|
156 QCOMPARE(mTestObject->mQueue.count(), 0); |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------------------------- |
|
160 // testFindWidget |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 void TestVideoCollectionUiLoader::testFindWidget() |
|
164 { |
|
165 HbDocumentLoader::cleanup(); |
|
166 |
|
167 QList<VideoCollectionUiLoaderParam> params; |
|
168 VideoCollectionUiLoaderParam banner( |
|
169 DOCML_NAME_VC_HEADINGBANNER, |
|
170 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
171 true, |
|
172 VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
173 VideoCollectionUiLoaderParam hint( |
|
174 DOCML_NAME_VC_VIDEOHINTWIDGET, |
|
175 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
176 DOCML_VIDEOCOLLECTIONVIEW_SECTION_HINT, |
|
177 true, |
|
178 VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
179 |
|
180 // pre-load widget asynchronously and find widget |
|
181 params.append(banner); |
|
182 mTestObject->addData(params, |
|
183 this, |
|
184 SLOT(handleObjectReady(QObject*, const QString&))); |
|
185 mTestObject->loadPhase(VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
186 QTest::qWait(1000); // wait 1 second |
|
187 HbGroupBox *bannerWidget = |
|
188 mTestObject->findWidget<HbGroupBox>( |
|
189 DOCML_NAME_VC_HEADINGBANNER); |
|
190 QVERIFY(bannerWidget); |
|
191 QVERIFY(mObjects.contains(DOCML_NAME_VC_HEADINGBANNER)); |
|
192 params.clear(); |
|
193 cleanup(); |
|
194 init(); |
|
195 |
|
196 // do not pre-load widget and load it, docml not loaded |
|
197 HbDocumentLoader::mFindWidgetFails = true; |
|
198 bannerWidget = |
|
199 mTestObject->findWidget<HbGroupBox>( |
|
200 DOCML_NAME_VC_HEADINGBANNER); |
|
201 QVERIFY(!bannerWidget); |
|
202 QVERIFY(!mObjects.contains(DOCML_NAME_VC_HEADINGBANNER)); |
|
203 cleanup(); |
|
204 init(); |
|
205 |
|
206 // do not pre-load widget but add it in queue, docml loaded |
|
207 bool ok = false; |
|
208 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, &ok); |
|
209 QVERIFY(ok); |
|
210 params.append(banner); |
|
211 mTestObject->addData(params, |
|
212 this, |
|
213 SLOT(handleObjectReady(QObject*, const QString&))); |
|
214 bannerWidget = |
|
215 mTestObject->findWidget<HbGroupBox>( |
|
216 DOCML_NAME_VC_HEADINGBANNER); |
|
217 QVERIFY(bannerWidget); |
|
218 QVERIFY(mObjects.contains(DOCML_NAME_VC_HEADINGBANNER)); |
|
219 params.clear(); |
|
220 cleanup(); |
|
221 init(); |
|
222 |
|
223 // do not pre-load widget, docml loaded |
|
224 ok = false; |
|
225 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, &ok); |
|
226 QVERIFY(ok); |
|
227 bannerWidget = |
|
228 mTestObject->findWidget<HbGroupBox>( |
|
229 DOCML_NAME_VC_HEADINGBANNER); |
|
230 QVERIFY(bannerWidget); |
|
231 QVERIFY(!mObjects.contains(DOCML_NAME_VC_HEADINGBANNER)); |
|
232 cleanup(); |
|
233 init(); |
|
234 |
|
235 // do not pre-load widget but add it in queue, section loaded |
|
236 ok = false; |
|
237 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, &ok); |
|
238 QVERIFY(ok); |
|
239 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
240 DOCML_VIDEOCOLLECTIONVIEW_SECTION_HINT, |
|
241 &ok); |
|
242 QVERIFY(ok); |
|
243 params.append(hint); |
|
244 mTestObject->addData(params, |
|
245 this, |
|
246 SLOT(handleObjectReady(QObject*, const QString&))); |
|
247 VideoHintWidget *hintWidget = |
|
248 mTestObject->findWidget<VideoHintWidget>( |
|
249 DOCML_NAME_VC_VIDEOHINTWIDGET); |
|
250 QVERIFY(hintWidget); |
|
251 QVERIFY(mObjects.contains(DOCML_NAME_VC_VIDEOHINTWIDGET)); |
|
252 params.clear(); |
|
253 cleanup(); |
|
254 init(); |
|
255 |
|
256 // do not pre-load widget, section not loaded |
|
257 ok = false; |
|
258 HbDocumentLoader::mFindWidgetFails = true; |
|
259 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, &ok); |
|
260 QVERIFY(ok); |
|
261 hintWidget = |
|
262 mTestObject->findWidget<VideoHintWidget>( |
|
263 DOCML_NAME_VC_VIDEOHINTWIDGET); |
|
264 QVERIFY(!hintWidget); |
|
265 QVERIFY(!mObjects.contains(DOCML_NAME_VC_VIDEOHINTWIDGET)); |
|
266 } |
|
267 |
|
268 // --------------------------------------------------------------------------- |
|
269 // testFindObject |
|
270 // --------------------------------------------------------------------------- |
|
271 // |
|
272 void TestVideoCollectionUiLoader::testFindObject() |
|
273 { |
|
274 HbDocumentLoader::cleanup(); |
|
275 |
|
276 QList<VideoCollectionUiLoaderParam> params; |
|
277 VideoCollectionUiLoaderParam addToCollectionParam( |
|
278 DOCML_NAME_ADD_TO_COLLECTION, |
|
279 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
280 false, |
|
281 VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
282 |
|
283 // find object: |
|
284 // -docml not loaded |
|
285 // -object not added in loading queue |
|
286 HbDocumentLoader::mFindObjectFails = true; |
|
287 HbAction *addToCollection = mTestObject->findObject<HbAction>(DOCML_NAME_ADD_TO_COLLECTION); |
|
288 QVERIFY(!addToCollection); |
|
289 QVERIFY(!mObjects.contains(DOCML_NAME_ADD_TO_COLLECTION)); |
|
290 cleanup(); |
|
291 init(); |
|
292 |
|
293 // find object: |
|
294 // -docml not loaded |
|
295 // -object added in loading queue |
|
296 params.append(addToCollectionParam); |
|
297 mTestObject->addData(params, this, SLOT(handleObjectReady(QObject*, const QString&))); |
|
298 addToCollection = mTestObject->findObject<HbAction>(DOCML_NAME_ADD_TO_COLLECTION); |
|
299 QVERIFY(addToCollection); |
|
300 QVERIFY(mObjects.contains(DOCML_NAME_ADD_TO_COLLECTION)); |
|
301 params.clear(); |
|
302 cleanup(); |
|
303 init(); |
|
304 |
|
305 // find object: |
|
306 // -docml loaded |
|
307 // -object not added in loading queue |
|
308 bool ok = false; |
|
309 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, &ok); |
|
310 QVERIFY(ok); |
|
311 addToCollection = mTestObject->findObject<HbAction>(DOCML_NAME_ADD_TO_COLLECTION); |
|
312 QVERIFY(addToCollection); |
|
313 QVERIFY(!mObjects.contains(DOCML_NAME_ADD_TO_COLLECTION)); |
|
314 cleanup(); |
|
315 init(); |
|
316 |
|
317 // find object: |
|
318 // -docml loaded |
|
319 // -object added in loading queue |
|
320 ok = false; |
|
321 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, &ok); |
|
322 QVERIFY(ok); |
|
323 params.append(addToCollectionParam); |
|
324 mTestObject->addData(params, this, SLOT(handleObjectReady(QObject*, const QString&))); |
|
325 addToCollection = mTestObject->findObject<HbAction>(DOCML_NAME_ADD_TO_COLLECTION); |
|
326 QVERIFY(addToCollection); |
|
327 QVERIFY(mObjects.contains(DOCML_NAME_ADD_TO_COLLECTION)); |
|
328 params.clear(); |
|
329 } |
|
330 |
|
331 // --------------------------------------------------------------------------- |
|
332 // testIsService |
|
333 // --------------------------------------------------------------------------- |
|
334 // |
|
335 void TestVideoCollectionUiLoader::testIsService() |
|
336 { |
|
337 // is service: |
|
338 // -service flag set |
|
339 mTestObject->setIsService(true); |
|
340 QVERIFY(mTestObject->mIsService); |
|
341 cleanup(); |
|
342 init(); |
|
343 |
|
344 // is service: |
|
345 // -service flag not set |
|
346 mTestObject->setIsService(false); |
|
347 QVERIFY(!mTestObject->mIsService); |
|
348 } |
|
349 |
|
350 // --------------------------------------------------------------------------- |
|
351 // testLoadDocml |
|
352 // --------------------------------------------------------------------------- |
|
353 // |
|
354 void TestVideoCollectionUiLoader::testLoadDocml() |
|
355 { |
|
356 HbDocumentLoader::mLoadReturns.append(new QObject()); |
|
357 |
|
358 // load docml: |
|
359 // -correct docml once |
|
360 bool ok = false; |
|
361 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, &ok); |
|
362 QVERIFY(ok); |
|
363 QVERIFY(mTestObject->mDocmls.contains(DOCML_VIDEOCOLLECTIONVIEW_FILE)); |
|
364 cleanup(); |
|
365 init(); |
|
366 |
|
367 // load docml: |
|
368 // -two correct docmls |
|
369 ok = false; |
|
370 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, &ok); |
|
371 QVERIFY(ok); |
|
372 QVERIFY(mTestObject->mDocmls.contains(DOCML_VIDEOCOLLECTIONVIEW_FILE)); |
|
373 mTestObject->load(DOCML_VIDEOSELECTIONDIALOG_FILE, &ok); |
|
374 QVERIFY(ok); |
|
375 QVERIFY(mTestObject->mDocmls.contains(DOCML_VIDEOSELECTIONDIALOG_FILE)); |
|
376 cleanup(); |
|
377 init(); |
|
378 |
|
379 // load docml: |
|
380 // -same docml twice |
|
381 ok = false; |
|
382 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, &ok); |
|
383 QVERIFY(ok); |
|
384 QVERIFY(mTestObject->mDocmls.contains(DOCML_VIDEOCOLLECTIONVIEW_FILE)); |
|
385 int objectCount = mTestObject->mOrphans.count(); |
|
386 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, &ok); |
|
387 QVERIFY(ok); |
|
388 QVERIFY(mTestObject->mDocmls.contains(DOCML_VIDEOCOLLECTIONVIEW_FILE)); |
|
389 QVERIFY(objectCount == mTestObject->mOrphans.count()); |
|
390 cleanup(); |
|
391 init(); |
|
392 |
|
393 // load docml: |
|
394 // -incorrect docml |
|
395 const char *INVALID_DOCML = "invalid docml"; |
|
396 ok = false; |
|
397 HbDocumentLoader::mLoadFails = true; |
|
398 mTestObject->load(INVALID_DOCML, &ok); |
|
399 QVERIFY(!ok); |
|
400 QVERIFY(!mTestObject->mDocmls.contains(INVALID_DOCML)); |
|
401 } |
|
402 |
|
403 // --------------------------------------------------------------------------- |
|
404 // testLoadSection |
|
405 // --------------------------------------------------------------------------- |
|
406 // |
|
407 void TestVideoCollectionUiLoader::testLoadSection() |
|
408 { |
|
409 HbDocumentLoader::cleanup(); |
|
410 |
|
411 // load section: |
|
412 // -docml loaded |
|
413 // -correct section once |
|
414 bool ok = false; |
|
415 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, &ok); |
|
416 QVERIFY(ok); |
|
417 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST, &ok); |
|
418 QVERIFY(ok); |
|
419 QVERIFY(mTestObject->mSections.contains(DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST)); |
|
420 cleanup(); |
|
421 init(); |
|
422 |
|
423 // load section: |
|
424 // -docml loaded |
|
425 // -two correct sections |
|
426 ok = false; |
|
427 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, &ok); |
|
428 QVERIFY(ok); |
|
429 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST, &ok); |
|
430 QVERIFY(ok); |
|
431 QVERIFY(mTestObject->mSections.contains(DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST)); |
|
432 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, DOCML_VIDEOCOLLECTIONVIEW_SECTION_HINT, &ok); |
|
433 QVERIFY(ok); |
|
434 QVERIFY(mTestObject->mSections.contains(DOCML_VIDEOCOLLECTIONVIEW_SECTION_HINT)); |
|
435 cleanup(); |
|
436 init(); |
|
437 |
|
438 // load section: |
|
439 // -docml loaded |
|
440 // -same section twice |
|
441 ok = false; |
|
442 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, &ok); |
|
443 QVERIFY(ok); |
|
444 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST, &ok); |
|
445 QVERIFY(ok); |
|
446 QVERIFY(mTestObject->mSections.contains(DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST)); |
|
447 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST, &ok); |
|
448 int sectionCount = mTestObject->mSections.count(); |
|
449 QVERIFY(ok); |
|
450 QVERIFY(mTestObject->mSections.contains(DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST)); |
|
451 QVERIFY(sectionCount == mTestObject->mSections.count()); |
|
452 cleanup(); |
|
453 init(); |
|
454 |
|
455 // load section: |
|
456 // -docml not loaded |
|
457 // -correct section once |
|
458 ok = false; |
|
459 HbDocumentLoader::mLoadFails = true; |
|
460 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST, &ok); |
|
461 QVERIFY(!ok); |
|
462 QVERIFY(!mTestObject->mSections.contains(DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST)); |
|
463 cleanup(); |
|
464 init(); |
|
465 } |
|
466 |
|
467 // --------------------------------------------------------------------------- |
|
468 // testLoadPhase |
|
469 // --------------------------------------------------------------------------- |
|
470 // |
|
471 void TestVideoCollectionUiLoader::testLoadPhase() |
|
472 { |
|
473 HbDocumentLoader::cleanup(); |
|
474 |
|
475 // load phase: |
|
476 // -add first phase items in queue |
|
477 // -load first phase |
|
478 VideoCollectionUiLoaderParam videoWidgetParam( |
|
479 DOCML_NAME_VC_VIDEOLISTWIDGET, |
|
480 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
481 true, |
|
482 VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
483 VideoCollectionUiLoaderParam collectionWidgetParam( |
|
484 DOCML_NAME_VC_COLLECTIONWIDGET, |
|
485 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
486 DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST, |
|
487 true, |
|
488 VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
489 VideoCollectionUiLoaderParam collectionContentWidgetParam( |
|
490 DOCML_NAME_VC_COLLECTIONCONTENTWIDGET, |
|
491 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
492 DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST, |
|
493 true, |
|
494 VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
495 QList<VideoCollectionUiLoaderParam> params; |
|
496 params.append(videoWidgetParam); |
|
497 params.append(collectionWidgetParam); |
|
498 params.append(collectionContentWidgetParam); |
|
499 mTestObject->addData(params, |
|
500 this, |
|
501 SLOT(handleObjectReady(QObject*, const QString&))); |
|
502 mTestObject->loadPhase(VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
503 QTest::qWait(1000); // wait 1 second |
|
504 QVERIFY(mTestObject->mPhases.contains(VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
505 QCOMPARE(mTestObject->mObjects.count(), 3); |
|
506 QVERIFY(mTestObject->mObjects.contains(DOCML_NAME_VC_VIDEOLISTWIDGET)); |
|
507 QVERIFY(mTestObject->mObjects.contains(DOCML_NAME_VC_COLLECTIONWIDGET)); |
|
508 QVERIFY(mTestObject->mObjects.contains(DOCML_NAME_VC_COLLECTIONCONTENTWIDGET)); |
|
509 params.clear(); |
|
510 cleanup(); |
|
511 init(); |
|
512 |
|
513 // load phase: |
|
514 // -add second phase items in queue |
|
515 // -load first phase |
|
516 // -load second phase |
|
517 VideoCollectionUiLoaderParam addToCollectionParam( |
|
518 DOCML_NAME_ADD_TO_COLLECTION, |
|
519 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
520 false, |
|
521 VideoCollectionUiLoaderParam::LoadPhaseSecondary); |
|
522 VideoCollectionUiLoaderParam createCollectionParam( |
|
523 DOCML_NAME_CREATE_COLLECTION, |
|
524 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
525 false, |
|
526 VideoCollectionUiLoaderParam::LoadPhaseSecondary); |
|
527 VideoCollectionUiLoaderParam deleteMultipleParam( |
|
528 DOCML_NAME_DELETE_MULTIPLE, |
|
529 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
530 false, |
|
531 VideoCollectionUiLoaderParam::LoadPhaseSecondary); |
|
532 params.append(addToCollectionParam); |
|
533 params.append(createCollectionParam); |
|
534 params.append(deleteMultipleParam); |
|
535 mTestObject->addData(params, |
|
536 this, |
|
537 SLOT(handleObjectReady(QObject*, const QString&))); |
|
538 mTestObject->loadPhase(VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
539 QTest::qWait(1000); // wait 1 second |
|
540 QVERIFY(mTestObject->mPhases.contains(VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
541 QVERIFY(mTestObject->mObjects.count() == 0); |
|
542 mTestObject->loadPhase(VideoCollectionUiLoaderParam::LoadPhaseSecondary); |
|
543 QTest::qWait(1000); // wait 1 second |
|
544 QVERIFY(mTestObject->mPhases.contains(VideoCollectionUiLoaderParam::LoadPhaseSecondary)); |
|
545 QCOMPARE(mTestObject->mObjects.count(), 3); |
|
546 QVERIFY(mTestObject->mObjects.contains(DOCML_NAME_ADD_TO_COLLECTION)); |
|
547 QVERIFY(mTestObject->mObjects.contains(DOCML_NAME_CREATE_COLLECTION)); |
|
548 QVERIFY(mTestObject->mObjects.contains(DOCML_NAME_DELETE_MULTIPLE)); |
|
549 params.clear(); |
|
550 cleanup(); |
|
551 init(); |
|
552 |
|
553 // load phase: |
|
554 // -add first phase items in queue |
|
555 // -add second phase items in queue |
|
556 // -load first phase |
|
557 // -load second phase |
|
558 params.append(videoWidgetParam); |
|
559 params.append(addToCollectionParam); |
|
560 mTestObject->addData(params, |
|
561 this, |
|
562 SLOT(handleObjectReady(QObject*, const QString&))); |
|
563 mTestObject->loadPhase(VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
564 mTestObject->loadPhase(VideoCollectionUiLoaderParam::LoadPhaseSecondary); |
|
565 QTest::qWait(1000); // wait 1 second |
|
566 QVERIFY(mTestObject->mPhases.contains(VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
567 QVERIFY(mTestObject->mPhases.contains(VideoCollectionUiLoaderParam::LoadPhaseSecondary)); |
|
568 QCOMPARE(mTestObject->mObjects.count(), 2); |
|
569 QVERIFY(mTestObject->mObjects.contains(DOCML_NAME_VC_VIDEOLISTWIDGET)); |
|
570 QVERIFY(mTestObject->mObjects.contains(DOCML_NAME_ADD_TO_COLLECTION)); |
|
571 params.clear(); |
|
572 cleanup(); |
|
573 init(); |
|
574 } |
|
575 |
|
576 // --------------------------------------------------------------------------- |
|
577 // testLoadPhase_2 |
|
578 // --------------------------------------------------------------------------- |
|
579 // |
|
580 void TestVideoCollectionUiLoader::testLoadPhase_2() |
|
581 { |
|
582 // load phase: |
|
583 // -add all items |
|
584 // -load all items |
|
585 QList<VideoCollectionUiLoaderParam> params; |
|
586 params.append(VideoCollectionUiLoaderParam( |
|
587 DOCML_NAME_VIEW, |
|
588 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
589 true, |
|
590 VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
591 params.append(VideoCollectionUiLoaderParam( |
|
592 DOCML_NAME_VC_HEADINGBANNER, |
|
593 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
594 true, |
|
595 VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
596 params.append(VideoCollectionUiLoaderParam( |
|
597 DOCML_NAME_VC_COLLECTIONWIDGET, |
|
598 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
599 DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST, |
|
600 true, |
|
601 VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
602 params.append(VideoCollectionUiLoaderParam( |
|
603 DOCML_NAME_VC_COLLECTIONCONTENTWIDGET, |
|
604 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
605 DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST, |
|
606 true, |
|
607 VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
608 params.append(VideoCollectionUiLoaderParam( |
|
609 DOCML_NAME_VC_VIDEOLISTWIDGET, |
|
610 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
611 true, |
|
612 VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
613 params.append(VideoCollectionUiLoaderParam( |
|
614 DOCML_NAME_VC_VIDEOHINTWIDGET, |
|
615 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
616 DOCML_VIDEOCOLLECTIONVIEW_SECTION_HINT, |
|
617 true, |
|
618 VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
619 params.append(VideoCollectionUiLoaderParam( |
|
620 DOCML_NAME_OPTIONS_MENU, |
|
621 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
622 true, |
|
623 VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
624 params.append(VideoCollectionUiLoaderParam( |
|
625 DOCML_NAME_SORT_MENU, |
|
626 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
627 true, |
|
628 VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
629 params.append(VideoCollectionUiLoaderParam( |
|
630 DOCML_NAME_SORT_BY_DATE, |
|
631 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
632 false, |
|
633 VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
634 params.append(VideoCollectionUiLoaderParam( |
|
635 DOCML_NAME_SORT_BY_NAME, |
|
636 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
637 false, |
|
638 VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
639 params.append(VideoCollectionUiLoaderParam( |
|
640 DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS, |
|
641 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
642 false, |
|
643 VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
644 params.append(VideoCollectionUiLoaderParam( |
|
645 DOCML_NAME_SORT_BY_SIZE, |
|
646 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
647 false, |
|
648 VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
649 params.append(VideoCollectionUiLoaderParam( |
|
650 DOCML_NAME_ADD_TO_COLLECTION, |
|
651 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
652 false, |
|
653 VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
654 params.append(VideoCollectionUiLoaderParam( |
|
655 DOCML_NAME_CREATE_COLLECTION, |
|
656 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
657 false, |
|
658 VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
659 params.append(VideoCollectionUiLoaderParam( |
|
660 DOCML_NAME_DELETE_MULTIPLE, |
|
661 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
662 false, |
|
663 VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
664 params.append(VideoCollectionUiLoaderParam( |
|
665 DOCML_NAME_HINT_BUTTON, |
|
666 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
667 DOCML_VIDEOCOLLECTIONVIEW_SECTION_HINT, |
|
668 true, |
|
669 VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
670 params.append(VideoCollectionUiLoaderParam( |
|
671 DOCML_NAME_HINT_LABEL, |
|
672 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
673 DOCML_VIDEOCOLLECTIONVIEW_SECTION_HINT, |
|
674 true, |
|
675 VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
676 params.append(VideoCollectionUiLoaderParam( |
|
677 DOCML_NAME_NO_VIDEOS_LABEL, |
|
678 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
679 DOCML_VIDEOCOLLECTIONVIEW_SECTION_HINT, |
|
680 true, |
|
681 VideoCollectionUiLoaderParam::LoadPhasePrimary)); |
|
682 params.append(VideoCollectionUiLoaderParam( |
|
683 DOCML_NAME_DIALOG, |
|
684 DOCML_VIDEOSELECTIONDIALOG_FILE, |
|
685 true, |
|
686 VideoCollectionUiLoaderParam::LoadPhaseSecondary)); |
|
687 params.append(VideoCollectionUiLoaderParam( |
|
688 DOCML_NAME_DLG_HEADINGLBL, |
|
689 DOCML_VIDEOSELECTIONDIALOG_FILE, |
|
690 true, |
|
691 VideoCollectionUiLoaderParam::LoadPhaseSecondary)); |
|
692 params.append(VideoCollectionUiLoaderParam( |
|
693 DOCML_NAME_CHECK_CONTAINER, |
|
694 DOCML_VIDEOSELECTIONDIALOG_FILE, |
|
695 true, |
|
696 VideoCollectionUiLoaderParam::LoadPhaseSecondary)); |
|
697 params.append(VideoCollectionUiLoaderParam( |
|
698 DOCML_NAME_MARKALL, |
|
699 DOCML_VIDEOSELECTIONDIALOG_FILE, |
|
700 true, |
|
701 VideoCollectionUiLoaderParam::LoadPhaseSecondary)); |
|
702 params.append(VideoCollectionUiLoaderParam( |
|
703 DOCML_NAME_LBL_SELECTION, |
|
704 DOCML_VIDEOSELECTIONDIALOG_FILE, |
|
705 true, |
|
706 VideoCollectionUiLoaderParam::LoadPhaseSecondary)); |
|
707 params.append(VideoCollectionUiLoaderParam( |
|
708 DOCML_NAME_LIST_CONTAINER, |
|
709 DOCML_VIDEOSELECTIONDIALOG_FILE, |
|
710 true, |
|
711 VideoCollectionUiLoaderParam::LoadPhaseSecondary)); |
|
712 mTestObject->addData(params, |
|
713 this, |
|
714 SLOT(handleObjectReady(QObject*, const QString&))); |
|
715 mTestObject->loadPhase(VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
716 mTestObject->loadPhase(VideoCollectionUiLoaderParam::LoadPhaseSecondary); |
|
717 QTest::qWait(5000); // 5 seconds |
|
718 QCOMPARE(mObjects.count(), params.count()); |
|
719 QHash<QString, QObject*>::const_iterator i = mObjects.constBegin(); |
|
720 while (i != mObjects.constEnd()) |
|
721 { |
|
722 bool found = false; |
|
723 foreach (const VideoCollectionUiLoaderParam ¶m, params) |
|
724 { |
|
725 if (param == i.key()) |
|
726 { |
|
727 found = true; |
|
728 break; |
|
729 } |
|
730 } |
|
731 QVERIFY(found); |
|
732 i++; |
|
733 } |
|
734 |
|
735 // Getting proxymodel fails. |
|
736 cleanup(); |
|
737 init(); |
|
738 mTestObject->addData(params, |
|
739 this, |
|
740 SLOT(handleObjectReady(QObject*, const QString&))); |
|
741 VideoCollectionWrapperData::mGetModelFails = true; |
|
742 mTestObject->loadPhase(VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
743 mTestObject->loadPhase(VideoCollectionUiLoaderParam::LoadPhaseSecondary); |
|
744 QTest::qWait(5000); // 5 seconds |
|
745 QCOMPARE(mObjects.count(), params.count()); |
|
746 i = mObjects.constBegin(); |
|
747 while (i != mObjects.constEnd()) |
|
748 { |
|
749 bool found = false; |
|
750 foreach (const VideoCollectionUiLoaderParam ¶m, params) |
|
751 { |
|
752 if (param == i.key()) |
|
753 { |
|
754 found = true; |
|
755 break; |
|
756 } |
|
757 } |
|
758 QVERIFY(found); |
|
759 i++; |
|
760 } |
|
761 params.clear(); |
|
762 } |
|
763 |
|
764 // --------------------------------------------------------------------------- |
|
765 // testDelete |
|
766 // --------------------------------------------------------------------------- |
|
767 // |
|
768 void TestVideoCollectionUiLoader::testDelete() |
|
769 { |
|
770 VideoCollectionWrapperData::reset(); |
|
771 |
|
772 // delete: |
|
773 // -load docml |
|
774 // -delete one "root" item |
|
775 bool ok = false; |
|
776 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, &ok); |
|
777 QVERIFY(ok); |
|
778 HbAction *addToCollection = mTestObject->findObject<HbAction>(DOCML_NAME_ADD_TO_COLLECTION); |
|
779 HbAction *tempAction = addToCollection; |
|
780 delete addToCollection; |
|
781 QVERIFY(!mTestObject->mOrphans.contains(tempAction)); |
|
782 cleanup(); |
|
783 init(); |
|
784 |
|
785 // delete: |
|
786 // -load docml |
|
787 // -delete all items |
|
788 ok = false; |
|
789 mTestObject->load(DOCML_VIDEOCOLLECTIONVIEW_FILE, &ok); |
|
790 foreach (QObject *object, mTestObject->mOrphans) |
|
791 { |
|
792 delete object; |
|
793 } |
|
794 QVERIFY(!mTestObject->mOrphans.count()); |
|
795 QVERIFY(ok); |
|
796 } |
|
797 |
|
798 // --------------------------------------------------------------------------- |
|
799 // testRemoveOrphanFromList |
|
800 // --------------------------------------------------------------------------- |
|
801 // |
|
802 void TestVideoCollectionUiLoader::testRemoveOrphanFromList() |
|
803 { |
|
804 QObject *obj = 0; |
|
805 |
|
806 // Nothing in the object lists. |
|
807 cleanup(); |
|
808 init(); |
|
809 connect(this, SIGNAL(testSignal(QObject *)), mTestObject, SLOT(removeOrphanFromList(QObject *))); |
|
810 emit testSignal(obj); |
|
811 disconnect(this, SIGNAL(testSignal(QObject *)), mTestObject, SLOT(removeOrphanFromList(QObject *))); |
|
812 QCOMPARE(mTestObject->mOrphans.count(), 0); |
|
813 QCOMPARE(mTestObject->mObjects.count(), 0); |
|
814 |
|
815 // Orphans and objects contain the object. |
|
816 cleanup(); |
|
817 init(); |
|
818 connect(this, SIGNAL(testSignal(QObject *)), mTestObject, SLOT(removeOrphanFromList(QObject *))); |
|
819 obj = new QObject(); |
|
820 mTestObject->mOrphans.append(obj); |
|
821 mTestObject->mObjects.insert("test", obj); |
|
822 emit testSignal(obj); |
|
823 disconnect(this, SIGNAL(testSignal(QObject *)), mTestObject, SLOT(removeOrphanFromList(QObject *))); |
|
824 QCOMPARE(mTestObject->mOrphans.count(), 0); |
|
825 QCOMPARE(mTestObject->mObjects.count(), 0); |
|
826 delete obj; |
|
827 |
|
828 // Orphans contain the object, objects has different |
|
829 cleanup(); |
|
830 init(); |
|
831 connect(this, SIGNAL(testSignal(QObject *)), mTestObject, SLOT(removeOrphanFromList(QObject *))); |
|
832 obj = new QObject(); |
|
833 mTestObject->mOrphans.append(obj); |
|
834 mTestObject->mObjects.insert("test", new QObject()); |
|
835 emit testSignal(obj); |
|
836 disconnect(this, SIGNAL(testSignal(QObject *)), mTestObject, SLOT(removeOrphanFromList(QObject *))); |
|
837 QCOMPARE(mTestObject->mOrphans.count(), 0); |
|
838 QCOMPARE(mTestObject->mObjects.count(), 1); |
|
839 delete obj; |
|
840 } |
|
841 |
|
842 // TEST CASES END ------------------------------------------------------------- |
|
843 |
|
844 void TestVideoCollectionUiLoader::handleObjectReady(QObject *object, const QString &name) |
|
845 { |
|
846 qDebug() << "Received object :" << name; |
|
847 |
|
848 if (object) |
|
849 { |
|
850 if (name == DOCML_NAME_VIEW) |
|
851 { |
|
852 HbMainWindow *window = hbInstance->allMainWindows().at(0); |
|
853 if (window) |
|
854 { |
|
855 HbView *view = qobject_cast<HbView*>(object); |
|
856 if (view) |
|
857 { |
|
858 window->setCurrentView(view); |
|
859 } |
|
860 } |
|
861 } |
|
862 mObjects.insert(name, object); |
|
863 } |
|
864 } |
|
865 |
|
866 // --------------------------------------------------------------------------- |
|
867 // testPrepareDocmlAndSection |
|
868 // --------------------------------------------------------------------------- |
|
869 // |
|
870 void TestVideoCollectionUiLoader::testPrepareDocmlAndSection() |
|
871 { |
|
872 VideoCollectionUiLoaderParam banner( |
|
873 DOCML_NAME_VC_HEADINGBANNER, |
|
874 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
875 DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST, |
|
876 true, |
|
877 VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
878 VideoCollectionUiLoaderParam collectionWidget( |
|
879 DOCML_NAME_VC_COLLECTIONWIDGET, |
|
880 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
881 0, |
|
882 true, |
|
883 VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
884 VideoCollectionUiLoaderParam collectionContentWidget( |
|
885 DOCML_NAME_VC_COLLECTIONCONTENTWIDGET, |
|
886 0, |
|
887 DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST, |
|
888 true, |
|
889 VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
890 const int COUNT = 3; |
|
891 |
|
892 // add items |
|
893 QList<VideoCollectionUiLoaderParam> params; |
|
894 params.append(banner); |
|
895 params.append(collectionWidget); |
|
896 params.append(collectionContentWidget); |
|
897 |
|
898 cleanup(); |
|
899 init(); |
|
900 HbDocumentLoader::mFindWidgetFails = true; |
|
901 mTestObject->addData(params, |
|
902 this, |
|
903 SLOT(handleObjectReady(QObject*, const QString&))); |
|
904 mTestObject->loadPhase(VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
905 QTest::qWait(1000); // wait 1 second |
|
906 QVERIFY(mTestObject->mQueue.count() == 0); |
|
907 QVERIFY(!mTestObject->mQueue.contains(banner)); |
|
908 QVERIFY(!mTestObject->mQueue.contains(collectionWidget)); |
|
909 QVERIFY(!mTestObject->mQueue.contains(collectionContentWidget)); |
|
910 QCOMPARE(mTestObject->mQueue.count(), 0); |
|
911 |
|
912 cleanup(); |
|
913 init(); |
|
914 HbDocumentLoader::mFindWidgetFails = true; |
|
915 HbDocumentLoader::mLoadFails = true; |
|
916 mTestObject->addData(params, |
|
917 this, |
|
918 SLOT(handleObjectReady(QObject*, const QString&))); |
|
919 mTestObject->loadPhase(VideoCollectionUiLoaderParam::LoadPhasePrimary); |
|
920 QTest::qWait(1000); // wait 1 second |
|
921 QVERIFY(mTestObject->mQueue.count() == 0); |
|
922 QVERIFY(!mTestObject->mQueue.contains(banner)); |
|
923 QVERIFY(!mTestObject->mQueue.contains(collectionWidget)); |
|
924 QVERIFY(!mTestObject->mQueue.contains(collectionContentWidget)); |
|
925 QCOMPARE(mTestObject->mQueue.count(), 0); |
|
926 } |
|
927 |
|
928 // end of file |