|
1 /* |
|
2 * Copyright (c) 2009 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: TestVideoFileDetails class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "hbmessagebox.h" |
|
20 |
|
21 #include <QtTest/QtTest> |
|
22 #include <qdebug.h> |
|
23 #include <hbglobal.h> |
|
24 #include <hbinstance.h> |
|
25 #include <hbwidget.h> |
|
26 #include <hblistwidget.h> |
|
27 #include <hblistwidgetitem.h> |
|
28 #include <hbpushbutton.h> |
|
29 #include <hblabel.h> |
|
30 #include <hbaction.h> |
|
31 #include <hbapplication.h> |
|
32 #include <hbmarqueeitem.h> |
|
33 #include <hbstackedwidget.h> |
|
34 #include <hbparameterlengthlimiter.h> |
|
35 |
|
36 #include "videodetailslabel.h" |
|
37 #include "hbmessagebox.h" |
|
38 #include "shareui.h" |
|
39 #include "thumbnailmanager_qt.h" |
|
40 #include "videocollectioncommon.h" |
|
41 #include "mpxhbvideocommondefs.h" |
|
42 #include "videocollectionwrapper.h" |
|
43 #include "videosortfilterproxymodel.h" |
|
44 #include "testvideofiledetails.h" |
|
45 |
|
46 // trick to get access to protected/private members. |
|
47 #define private public |
|
48 #include "videofiledetailsviewplugin.h" |
|
49 #undef private |
|
50 |
|
51 const char *TEST_VIDEO_DETAILS_GFX_DEFAULT = "qtg_large_video"; |
|
52 const char *TEST_VIDEO_DETAILS_VIEW = "videofiledetailsview"; |
|
53 const char *TEST_VIDEO_DETAILS_WIDGET = "mContent"; |
|
54 const char *TEST_VIDEO_DETAILS_TITLE = "mLblTitle"; |
|
55 const char *TEST_VIDEO_DETAILS_LISTWIDGET ="mDetailsList"; |
|
56 const char* const VIDEO_DETAILS_THUMBNAIL = "mDetailsLabel"; |
|
57 const char* const VIDEO_DETAILS_BUTTON = "mButton"; |
|
58 const char *TEST_VIDEO_DETAILS_MENUACTION_DELETE = "mOptionsDelete"; |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // initTestCase |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 void TestVideoFileDetails::initTestCase() |
|
65 { |
|
66 mDummyModel = 0; |
|
67 mDummyModel = new VideoSortFilterProxyModel(); |
|
68 |
|
69 connect(this, SIGNAL(shortDetailsReady(TMPXItemId)), mDummyModel, SIGNAL(shortDetailsReady(TMPXItemId))); |
|
70 connect(this, SIGNAL(fullDetailsReady(QVariant&)), mDummyModel, SIGNAL(fullVideoDetailsReady(QVariant&))); |
|
71 |
|
72 connect(this, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), |
|
73 mDummyModel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&))); |
|
74 |
|
75 connect(this, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), |
|
76 mDummyModel, SIGNAL(rowsRemoved(const QModelIndex&, int, int))); |
|
77 |
|
78 VideoCollectionWrapper::instance().setModel(mDummyModel); |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // cleanupTestCase |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 void TestVideoFileDetails::cleanupTestCase() |
|
86 { |
|
87 disconnect(this, SIGNAL(shortDetailsReady(TMPXItemId)), mDummyModel, SIGNAL(shortDetailsReady(TMPXItemId))); |
|
88 disconnect(this, SIGNAL(fullDetailsReady(QVariant&)),mDummyModel, SIGNAL(fullVideoDetailsReady(QVariant&))); |
|
89 disconnect(this, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), |
|
90 mDummyModel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&))); |
|
91 disconnect(this, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), |
|
92 mDummyModel, SIGNAL(rowsRemoved(const QModelIndex&, int, int))); |
|
93 delete mDummyModel; mDummyModel = 0; |
|
94 delete mPlugin; mPlugin = 0; |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // init before every test function |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void TestVideoFileDetails::init() |
|
102 { |
|
103 mDummyModel->reset(); |
|
104 |
|
105 mPlugin = new VideoFileDetailsViewPlugin(); |
|
106 mPlugin->createView(); |
|
107 mCommandReceived = false; |
|
108 mReceivedCommand = -1; |
|
109 ThumbnailManager::mRequests.clear(); |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // cleanup after every test function |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 void TestVideoFileDetails::cleanup() |
|
117 { |
|
118 if(mPlugin->getView()) { |
|
119 hbInstance->allMainWindows().at(0)->removeView(mPlugin->getView()); |
|
120 } |
|
121 mDummyModel->reset(); |
|
122 delete mPlugin; mPlugin = 0; |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // Helper function that activates view after init() |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 void TestVideoFileDetails::activateView() |
|
130 { |
|
131 hbInstance->allMainWindows().at(0)->addView(mPlugin->getView()); |
|
132 mPlugin->activateView(); |
|
133 |
|
134 // without this the xml loaded objects don't have the correct geometry. |
|
135 mPlugin->getView()->setGeometry(hbInstance->allMainWindows().at(0)->rect()); |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------------------------- |
|
139 // Helper function that populates a qmap with dummy data. |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 QMap<QString, QVariant> TestVideoFileDetails::createDummyMetadata() |
|
143 { |
|
144 using namespace VideoCollectionCommon; |
|
145 |
|
146 QMap<QString, QVariant> map; |
|
147 |
|
148 int detailCount = sizeof(VideoDetailLabelKeys) / sizeof(int); |
|
149 QString txt; |
|
150 for(int i = 0; i<detailCount; i++) { |
|
151 txt = QString(VideoDetailLabelKeys[i]); |
|
152 if(i%2 == 0) |
|
153 { |
|
154 map[VideoDetailLabelKeys[i]] = txt; |
|
155 } |
|
156 else |
|
157 { |
|
158 txt.append(QString("test test test test test test test test test test test test test test test test test test test")); |
|
159 map[VideoDetailLabelKeys[i]] = txt; |
|
160 } |
|
161 } |
|
162 return map; |
|
163 } |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // One round for the activate view test |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 inline void TestVideoFileDetails::activateViewTestRound() |
|
170 { |
|
171 init(); |
|
172 |
|
173 activateView(); |
|
174 |
|
175 QVERIFY( mPlugin->getView() != 0 ); |
|
176 QVERIFY( mPlugin->viewPlugin() == mPlugin ); |
|
177 QCOMPARE( mPlugin->mVideoId, TMPXItemId::InvalidId() ); |
|
178 |
|
179 // verify that actions are currently disabled. |
|
180 HbStackedWidget* thumbWidget = findWidget<HbStackedWidget>(VIDEO_DETAILS_THUMBNAIL); |
|
181 VideoDetailsLabel* thumbLabel = (VideoDetailsLabel*)thumbWidget->widgetAt(0); |
|
182 HbAction* deleteAction = findObject<HbAction>(TEST_VIDEO_DETAILS_MENUACTION_DELETE); |
|
183 |
|
184 HbPushButton* button = findWidget<HbPushButton>(VIDEO_DETAILS_BUTTON); |
|
185 |
|
186 QVERIFY( button != 0 ); |
|
187 QVERIFY( thumbLabel != 0 ); |
|
188 QVERIFY( deleteAction != 0 ); |
|
189 QVERIFY( deleteAction->isEnabled() ); |
|
190 |
|
191 QVERIFY(mPlugin->mActivated); |
|
192 // second activation should not affect |
|
193 activateView(); |
|
194 QVERIFY(mPlugin->mActivated); |
|
195 QVERIFY( button != 0 ); |
|
196 QVERIFY( thumbLabel != 0 ); |
|
197 QVERIFY( deleteAction != 0 ); |
|
198 QVERIFY( deleteAction->isEnabled() ); |
|
199 |
|
200 cleanup(); |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------------------------- |
|
204 // Slot: create view |
|
205 // --------------------------------------------------------------------------- |
|
206 // |
|
207 void TestVideoFileDetails::handleCommand(int command) |
|
208 { |
|
209 mCommandReceived = true; |
|
210 mReceivedCommand = command; |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // Slot: create view |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 void TestVideoFileDetails::testCreateView() |
|
218 { |
|
219 init(); |
|
220 // actual create view is done in the init. |
|
221 QVERIFY( mPlugin->mModel == mDummyModel ); |
|
222 QVERIFY( mPlugin->mIsService == false); |
|
223 QVERIFY( mPlugin->mVideoServices == 0); |
|
224 // testing the special case where the model is null. |
|
225 cleanup(); |
|
226 VideoCollectionWrapper::instance().setModel(0); |
|
227 init(); |
|
228 QVERIFY( mPlugin->mModel == 0 ); |
|
229 QVERIFY( mPlugin->mIsService == false); |
|
230 QVERIFY( mPlugin->mVideoServices == 0); |
|
231 |
|
232 // restoring the proper model. |
|
233 VideoCollectionWrapper::instance().setModel(mDummyModel); |
|
234 cleanup(); |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // Slot: destroy view |
|
239 // --------------------------------------------------------------------------- |
|
240 // |
|
241 void TestVideoFileDetails::testDestroyView() |
|
242 { |
|
243 init(); |
|
244 activateView(); |
|
245 mPlugin->destroyView(); |
|
246 QVERIFY( mPlugin->getView() == 0 ); |
|
247 // plugin is still alive |
|
248 QVERIFY( mPlugin->viewPlugin() == mPlugin ); |
|
249 QVERIFY( mPlugin->mNavKeyBackAction == 0 ); |
|
250 QVERIFY( mPlugin->mActivated == false ); |
|
251 cleanup(); |
|
252 } |
|
253 |
|
254 // --------------------------------------------------------------------------- |
|
255 // Slot: activate view |
|
256 // --------------------------------------------------------------------------- |
|
257 // |
|
258 void TestVideoFileDetails::testActivateViewPortrait() |
|
259 { |
|
260 hbInstance->allMainWindows().at(0)->setOrientation(Qt::Vertical); |
|
261 activateViewTestRound(); |
|
262 } |
|
263 |
|
264 // --------------------------------------------------------------------------- |
|
265 // Slot: activate view |
|
266 // --------------------------------------------------------------------------- |
|
267 // |
|
268 void TestVideoFileDetails::testActivateViewLandscape() |
|
269 { |
|
270 hbInstance->allMainWindows().at(0)->setOrientation(Qt::Horizontal); |
|
271 activateViewTestRound(); |
|
272 } |
|
273 |
|
274 // --------------------------------------------------------------------------- |
|
275 // Slot: activate view |
|
276 // --------------------------------------------------------------------------- |
|
277 // |
|
278 void TestVideoFileDetails::testDeactivateView() |
|
279 { |
|
280 init(); |
|
281 activateView(); |
|
282 mPlugin->deactivateView(); |
|
283 QVERIFY( mPlugin->mActivated == false ); |
|
284 QCOMPARE( mPlugin->mVideoId, TMPXItemId::InvalidId() ); |
|
285 mPlugin->deactivateView(); |
|
286 QVERIFY( mPlugin->mActivated == false ); |
|
287 QCOMPARE( mPlugin->mVideoId, TMPXItemId::InvalidId() ); |
|
288 cleanup(); |
|
289 } |
|
290 |
|
291 // --------------------------------------------------------------------------- |
|
292 // Slot: data for orientation change test |
|
293 // --------------------------------------------------------------------------- |
|
294 // |
|
295 void TestVideoFileDetails::testOrientationChange_data() |
|
296 { |
|
297 QTest::addColumn<int>("start"); |
|
298 QTest::addColumn<int>("switchTo"); |
|
299 |
|
300 QTest::newRow("from portrait to landscape") |
|
301 << static_cast<int>(Qt::Vertical) |
|
302 << static_cast<int>(Qt::Horizontal); |
|
303 QTest::newRow("from landscape to portrait") |
|
304 << static_cast<int>(Qt::Horizontal) |
|
305 << static_cast<int>(Qt::Vertical); |
|
306 } |
|
307 |
|
308 // --------------------------------------------------------------------------- |
|
309 // Slot: test for the orientationChange slot |
|
310 // --------------------------------------------------------------------------- |
|
311 // |
|
312 void TestVideoFileDetails::testOrientationChange() |
|
313 { |
|
314 QFETCH(int, start); |
|
315 QFETCH(int, switchTo); |
|
316 |
|
317 init(); |
|
318 hbInstance->allMainWindows().at(0)->setOrientation(static_cast<Qt::Orientation>(start)); |
|
319 activateView(); |
|
320 |
|
321 hbInstance->allMainWindows().at(0)->setOrientation(static_cast<Qt::Orientation>(switchTo)); |
|
322 |
|
323 // without this the view doesn't have the correct geometry. |
|
324 mPlugin->getView()->setGeometry(hbInstance->allMainWindows().at(0)->rect()); |
|
325 // give fw some time to update content |
|
326 QTest::qWait(100); |
|
327 |
|
328 cleanup(); |
|
329 } |
|
330 |
|
331 // --------------------------------------------------------------------------- |
|
332 // Slot: test for the back slot |
|
333 // --------------------------------------------------------------------------- |
|
334 // |
|
335 void TestVideoFileDetails::testBack() |
|
336 { |
|
337 init(); |
|
338 connect(this, SIGNAL(testSignal()), mPlugin, SLOT(back())); |
|
339 connect(mPlugin, SIGNAL(command(int)), this, SLOT(handleCommand(int))); |
|
340 |
|
341 emit testSignal(); |
|
342 QCOMPARE( mCommandReceived, false ); |
|
343 QCOMPARE( mReceivedCommand, -1 ); |
|
344 |
|
345 mPlugin->mNavKeyBackAction->trigger(); |
|
346 QCOMPARE( mCommandReceived, false ); |
|
347 QCOMPARE( mReceivedCommand, -1 ); |
|
348 |
|
349 activateView(); |
|
350 |
|
351 emit testSignal(); |
|
352 QCOMPARE( mCommandReceived, true ); |
|
353 QCOMPARE( mReceivedCommand, static_cast<int>(MpxHbVideoCommon::ActivateCollectionView) ); |
|
354 |
|
355 mCommandReceived = false; |
|
356 mReceivedCommand = -1; |
|
357 |
|
358 mPlugin->mNavKeyBackAction->trigger(); |
|
359 QCOMPARE( mCommandReceived, true ); |
|
360 QCOMPARE( mReceivedCommand, static_cast<int>(MpxHbVideoCommon::ActivateCollectionView) ); |
|
361 |
|
362 mCommandReceived = false; |
|
363 mReceivedCommand = -1; |
|
364 |
|
365 mPlugin->deactivateView(); |
|
366 |
|
367 emit testSignal(); |
|
368 QCOMPARE( mCommandReceived, false ); |
|
369 QCOMPARE( mReceivedCommand, -1 ); |
|
370 |
|
371 mPlugin->mNavKeyBackAction->trigger(); |
|
372 QCOMPARE( mCommandReceived, false ); |
|
373 QCOMPARE( mReceivedCommand, -1 ); |
|
374 |
|
375 disconnect(mPlugin, SIGNAL(command(int)), this, SLOT(handleCommand(int))); |
|
376 disconnect(this, SIGNAL(testSignal()), mPlugin, SLOT(back())); |
|
377 cleanup(); |
|
378 } |
|
379 |
|
380 // --------------------------------------------------------------------------- |
|
381 // Slot: test for the shortDetailsReadySlot |
|
382 // --------------------------------------------------------------------------- |
|
383 // |
|
384 void TestVideoFileDetails::testShortDetailsReadySlot() |
|
385 { |
|
386 TMPXItemId testIndex(5,0); |
|
387 QString title("title"); |
|
388 QString filepath("filepath"); |
|
389 |
|
390 init(); |
|
391 activateView(); |
|
392 |
|
393 // no data |
|
394 emit shortDetailsReady(testIndex); |
|
395 |
|
396 QCOMPARE( mPlugin->mVideoId, testIndex ); |
|
397 QVERIFY( mPlugin->mTitleAnim->text().isEmpty() ); |
|
398 QCOMPARE( mPlugin->mThumbnailManager->mRequests.count(), 0 ); |
|
399 |
|
400 mDummyModel->setData(VideoCollectionCommon::KeyTitle, title); |
|
401 mDummyModel->setData(VideoCollectionCommon::KeyFilePath, filepath); |
|
402 |
|
403 // no tn manager |
|
404 ThumbnailManager *tmpTnManager = mPlugin->mThumbnailManager; |
|
405 mPlugin->mThumbnailManager = 0; |
|
406 emit shortDetailsReady(testIndex); |
|
407 QCOMPARE( mPlugin->mVideoId, testIndex ); |
|
408 QCOMPARE( mPlugin->mTitleAnim->text(), title ); |
|
409 mPlugin->mThumbnailManager = tmpTnManager; |
|
410 |
|
411 // thumbnail fetching fails |
|
412 tmpTnManager->mGetThumbFails = true; |
|
413 emit shortDetailsReady(testIndex); |
|
414 QCOMPARE( mPlugin->mVideoId, testIndex ); |
|
415 QCOMPARE( mPlugin->mTitleAnim->text(), title ); |
|
416 QCOMPARE( mPlugin->mThumbLabel->icon().iconName(), QString(TEST_VIDEO_DETAILS_GFX_DEFAULT) ); |
|
417 tmpTnManager->mGetThumbFails = false; |
|
418 |
|
419 // data exists |
|
420 emit shortDetailsReady(testIndex); |
|
421 |
|
422 QCOMPARE( mPlugin->mVideoId, testIndex ); |
|
423 QCOMPARE( mDummyModel->lastId(), testIndex ); |
|
424 QCOMPARE( mPlugin->mTitleAnim->text(), title ); |
|
425 QVERIFY( ThumbnailManager::mRequests.contains(0) ); |
|
426 ThumbnailManager::TnRequest request = ThumbnailManager::mRequests[0]; |
|
427 QCOMPARE( request.name, filepath ); |
|
428 // 20 == priorityHight in this case |
|
429 QCOMPARE( request.priority, 5000 ); |
|
430 |
|
431 |
|
432 QVariant variant = QVariant(createDummyMetadata()); |
|
433 emit fullDetailsReady(variant); |
|
434 |
|
435 emit shortDetailsReady(testIndex); |
|
436 |
|
437 int detailCount = sizeof(VideoCollectionCommon::VideoDetailLabelKeys) / sizeof(int); |
|
438 |
|
439 HbListWidget* list = findWidget<HbListWidget>(TEST_VIDEO_DETAILS_LISTWIDGET); |
|
440 |
|
441 QVERIFY(list); |
|
442 QVERIFY(list->count() == 0); |
|
443 |
|
444 cleanup(); |
|
445 } |
|
446 |
|
447 // --------------------------------------------------------------------------- |
|
448 // Slot: test for the fullDetailsReadySlot |
|
449 // --------------------------------------------------------------------------- |
|
450 // |
|
451 void TestVideoFileDetails::testFullDetailsReadySlot() |
|
452 { |
|
453 TMPXItemId testIndex(6,0); |
|
454 init(); |
|
455 activateView(); |
|
456 |
|
457 int detailCount = sizeof(VideoCollectionCommon::VideoDetailLabelKeys) / sizeof(int); |
|
458 |
|
459 HbListWidget* list = findWidget<HbListWidget>(TEST_VIDEO_DETAILS_LISTWIDGET); |
|
460 QVERIFY(list); |
|
461 QVERIFY(list->count() == 0); |
|
462 |
|
463 QVariant variant = QVariant(createDummyMetadata()); |
|
464 |
|
465 emit fullDetailsReady(variant); |
|
466 |
|
467 // verify that actions are currently enabled. |
|
468 HbStackedWidget* thumbWidget = findWidget<HbStackedWidget>(VIDEO_DETAILS_THUMBNAIL); |
|
469 VideoDetailsLabel* thumbLabel = (VideoDetailsLabel*)thumbWidget->widgetAt(0); |
|
470 HbAction* deleteAction = findObject<HbAction>(TEST_VIDEO_DETAILS_MENUACTION_DELETE); |
|
471 |
|
472 QVERIFY( thumbLabel != 0 ); |
|
473 QVERIFY( deleteAction != 0 ); |
|
474 QVERIFY( deleteAction->isEnabled() ); |
|
475 |
|
476 QVERIFY(list->count() == detailCount); |
|
477 |
|
478 for(int i = 0; i<detailCount; i++) |
|
479 { |
|
480 QString expected = tr(VideoCollectionCommon::VideoDetailLabels[i]).arg( |
|
481 VideoCollectionCommon::VideoDetailLabelKeys[i]); |
|
482 HbListWidgetItem* detail = list->item(i); |
|
483 QVERIFY( detail != 0 ); |
|
484 QVERIFY( detail->text().contains(expected) ); |
|
485 } |
|
486 |
|
487 cleanup(); |
|
488 } |
|
489 |
|
490 // --------------------------------------------------------------------------- |
|
491 // Slot: test for the testStartPlaybackSlot |
|
492 // --------------------------------------------------------------------------- |
|
493 // |
|
494 void TestVideoFileDetails::testStartPlaybackSlot() |
|
495 { |
|
496 TMPXItemId testIndex(6,0); |
|
497 mDummyModel->reset(); |
|
498 init(); |
|
499 activateView(); |
|
500 |
|
501 // Note that if the details view has not received signal in it's |
|
502 // fullDetailsReadySlot, the button is disabled and should not do anything. |
|
503 |
|
504 HbStackedWidget* thumbWidget = findWidget<HbStackedWidget>(VIDEO_DETAILS_THUMBNAIL); |
|
505 VideoDetailsLabel* thumbLabel = (VideoDetailsLabel*)thumbWidget->widgetAt(0); |
|
506 QVERIFY( thumbLabel != 0 ); |
|
507 thumbLabel->click(); |
|
508 |
|
509 QCOMPARE( mDummyModel->startPlaybackIndex(), TMPXItemId::InvalidId() ); |
|
510 |
|
511 QVariant variant = QVariant(createDummyMetadata()); |
|
512 emit fullDetailsReady(variant); |
|
513 mPlugin->mVideoId = testIndex; |
|
514 |
|
515 thumbLabel->click(); |
|
516 |
|
517 QCOMPARE( mDummyModel->startPlaybackIndex(), testIndex ); |
|
518 |
|
519 // invalid index |
|
520 mPlugin->mVideoId = TMPXItemId::InvalidId(); |
|
521 thumbLabel->click(); |
|
522 // startplayback index has not changed since previous |
|
523 QCOMPARE( mDummyModel->startPlaybackIndex(), testIndex ); |
|
524 |
|
525 cleanup(); |
|
526 } |
|
527 |
|
528 // --------------------------------------------------------------------------- |
|
529 // Slot: test for the sendVideoSlot |
|
530 // --------------------------------------------------------------------------- |
|
531 // |
|
532 void TestVideoFileDetails::testSendVideoSlot() |
|
533 { |
|
534 |
|
535 mDummyModel->reset(); |
|
536 init(); |
|
537 mPlugin->activateView(); |
|
538 |
|
539 HbPushButton* shareAction = findWidget<HbPushButton>(VIDEO_DETAILS_BUTTON); |
|
540 |
|
541 QVERIFY( shareAction != 0 ); |
|
542 shareAction->click(); |
|
543 QCOMPARE( mDummyModel->dataAccessCount(), 0 ); |
|
544 mPlugin->mVideoId = (0,0); |
|
545 |
|
546 mDummyModel->setDataReturnInvalid(true); |
|
547 QModelIndex expected = mDummyModel->index(0, 0); |
|
548 shareAction->click(); |
|
549 QCOMPARE( mDummyModel->dataAccessCount(), 1 ); |
|
550 QVERIFY( mDummyModel->lastIndex() == expected ); |
|
551 QCOMPARE( ShareUi::mFileList.count(), 0 ); |
|
552 QVERIFY( ShareUi::mEmbedded == false ); |
|
553 |
|
554 mDummyModel->setDataReturnInvalid(false); |
|
555 QString filePath("dummyfilepath"); |
|
556 mDummyModel->setData(VideoCollectionCommon::KeyFilePath, filePath); |
|
557 shareAction->click(); |
|
558 QCOMPARE( mDummyModel->dataAccessCount(), 2 ); |
|
559 QVERIFY( mDummyModel->lastIndex() == expected ); |
|
560 QVERIFY( ShareUi::mEmbedded ); |
|
561 QCOMPARE( ShareUi::mFileList.count(), 1 ); |
|
562 QCOMPARE( ShareUi::mFileList.at(0), filePath ); |
|
563 |
|
564 mPlugin->deactivateView(); |
|
565 |
|
566 QVERIFY(!mPlugin->mShareUi); |
|
567 |
|
568 cleanup(); |
|
569 } |
|
570 |
|
571 // --------------------------------------------------------------------------- |
|
572 // Slot: test for the deleteVideoSlot |
|
573 // --------------------------------------------------------------------------- |
|
574 // |
|
575 void TestVideoFileDetails::testDeleteVideoSlot() |
|
576 { |
|
577 mDummyModel->reset(); |
|
578 init(); |
|
579 |
|
580 HbAction* deleteAction = findObject<HbAction>(TEST_VIDEO_DETAILS_MENUACTION_DELETE); |
|
581 |
|
582 QVERIFY( deleteAction != 0 ); |
|
583 deleteAction->trigger(); |
|
584 QCOMPARE( mDummyModel->dataAccessCount(), 0 ); |
|
585 mPlugin->mVideoId = (0,0); |
|
586 |
|
587 mDummyModel->setDataReturnInvalid(true); |
|
588 QModelIndex expected = mDummyModel->index(0, 0); |
|
589 deleteAction->trigger(); |
|
590 QCOMPARE( mDummyModel->dataAccessCount(), 1 ); |
|
591 QVERIFY( mDummyModel->lastIndex() == expected ); |
|
592 QCOMPARE( mDummyModel->deleteFileIndex(), -1 ); // verify that no file was deleted. |
|
593 mDummyModel->setDataReturnInvalid(false); |
|
594 |
|
595 mPlugin->mVideoId = (0,0); |
|
596 expected = mDummyModel->index(0, 0); |
|
597 deleteAction->trigger(); |
|
598 QCOMPARE( mDummyModel->dataAccessCount(), 2 ); |
|
599 QVERIFY( mDummyModel->lastIndex() == expected ); |
|
600 QCOMPARE( mDummyModel->deleteFileIndex(), -1 ); // verify that no file was deleted. |
|
601 |
|
602 HbMessageBox *msgBox = new HbMessageBox(); |
|
603 |
|
604 QStringList display; |
|
605 display.append("first row"); |
|
606 display.append("second row"); |
|
607 mDummyModel->setData(VideoCollectionCommon::KeyTitle, display); |
|
608 |
|
609 QString expectedText = hbTrId("txt_videos_info_do_you_want_to_delete_1").arg( |
|
610 display.first()); |
|
611 deleteAction->trigger(); |
|
612 msgBox->emitDialogFinished(mPlugin, SLOT(deleteVideoDialogFinished(int)), HbMessageBox::Yes); // Yes selected |
|
613 QCOMPARE( mDummyModel->dataAccessCount(), 3 ); |
|
614 QVERIFY( mDummyModel->lastIndex() == expected ); |
|
615 QCOMPARE( mDummyModel->deleteFileIndex(), expected.row() ); |
|
616 QCOMPARE( HbMessageBox::mLatestTxt, expectedText ); |
|
617 |
|
618 deleteAction->trigger(); |
|
619 msgBox->emitDialogFinished(mPlugin, SLOT(deleteVideoDialogFinished(int)), HbMessageBox::No); // No selected |
|
620 QCOMPARE( mDummyModel->dataAccessCount(), 4 ); |
|
621 QVERIFY( mDummyModel->lastIndex() == expected ); |
|
622 QCOMPARE( mDummyModel->deleteFileIndex(), expected.row() ); |
|
623 QCOMPARE( HbMessageBox::mLatestTxt, expectedText ); |
|
624 |
|
625 |
|
626 mDummyModel->reset(); |
|
627 deleteAction->trigger(); |
|
628 msgBox->emitDialogFinished(mPlugin, SLOT(deleteVideoDialogFinished(int)), HbMessageBox::No); // No selected |
|
629 QCOMPARE( mDummyModel->dataAccessCount(), 1 ); |
|
630 QVERIFY( mDummyModel->lastIndex() == expected ); |
|
631 QCOMPARE( mDummyModel->deleteFileIndex(), -1 ); // verify that no file was deleted. |
|
632 QCOMPARE( HbMessageBox::mLatestTxt, expectedText ); |
|
633 |
|
634 delete msgBox; |
|
635 cleanup(); |
|
636 } |
|
637 |
|
638 // --------------------------------------------------------------------------- |
|
639 // Slot: test for the testRowsRemovedSlot |
|
640 // --------------------------------------------------------------------------- |
|
641 // |
|
642 void TestVideoFileDetails::testRowsRemovedSlot() |
|
643 { |
|
644 const int testIndex = 9; |
|
645 TMPXItemId testID(9,0); |
|
646 init(); |
|
647 connect(mPlugin, SIGNAL(command(int)), this, SLOT(handleCommand(int))); |
|
648 |
|
649 emit rowsRemoved(QModelIndex(), testIndex, testIndex); |
|
650 QCOMPARE( mCommandReceived, false ); |
|
651 QCOMPARE( mReceivedCommand, -1 ); |
|
652 |
|
653 activateView(); |
|
654 |
|
655 emit rowsRemoved(QModelIndex(), testIndex, testIndex); |
|
656 QCOMPARE( mCommandReceived, false ); |
|
657 QCOMPARE( mReceivedCommand, -1 ); |
|
658 |
|
659 QVariant variant = QVariant(createDummyMetadata()); |
|
660 emit fullDetailsReady(variant); |
|
661 mPlugin->mVideoId = testID; |
|
662 mPlugin->mDeletedIndex = testIndex; |
|
663 |
|
664 emit rowsRemoved(QModelIndex(), testIndex+1, testIndex-1); |
|
665 QCOMPARE( mCommandReceived, false ); |
|
666 QCOMPARE( mReceivedCommand, -1 ); |
|
667 |
|
668 emit rowsRemoved(QModelIndex(), testIndex-3, testIndex-1); |
|
669 QCOMPARE( mCommandReceived, false ); |
|
670 QCOMPARE( mReceivedCommand, -1 ); |
|
671 |
|
672 emit rowsRemoved(QModelIndex(), testIndex+1, testIndex+3); |
|
673 QCOMPARE( mCommandReceived, false ); |
|
674 QCOMPARE( mReceivedCommand, -1 ); |
|
675 |
|
676 emit rowsRemoved(QModelIndex(), testIndex, testIndex); |
|
677 QCOMPARE( mCommandReceived, true ); |
|
678 QCOMPARE( mReceivedCommand, static_cast<int>(MpxHbVideoCommon::ActivateCollectionView) ); |
|
679 |
|
680 disconnect(mPlugin, SIGNAL(command(int)), this, SLOT(handleCommand(int))); |
|
681 cleanup(); |
|
682 } |
|
683 |
|
684 // --------------------------------------------------------------------------- |
|
685 // Slot: testHandleErrorSlot test error messages |
|
686 // --------------------------------------------------------------------------- |
|
687 // |
|
688 void TestVideoFileDetails::testHandleErrorSlot() |
|
689 { |
|
690 init(); |
|
691 connect(this, SIGNAL(testErrorSignal(int, QVariant&)), mPlugin, SLOT(handleErrorSlot(int, QVariant&))); |
|
692 |
|
693 HbMessageBox::mLatestTxt = ""; |
|
694 QVariant additional = QVariant(); |
|
695 // invalid msg, |
|
696 emit testErrorSignal( VideoCollectionCommon::statusMultipleDeleteFail + 1, additional); |
|
697 |
|
698 QVERIFY(HbMessageBox::mLatestTxt.isEmpty()); |
|
699 |
|
700 // VideoCollectionCommon::statusSingleDeleteFail |
|
701 // - without additional data |
|
702 emit testErrorSignal( VideoCollectionCommon::statusSingleDeleteFail , additional); |
|
703 QVERIFY(HbMessageBox::mLatestTxt.isEmpty()); |
|
704 |
|
705 // - with additional data |
|
706 QString txt = "testdata"; |
|
707 additional = txt; |
|
708 emit testErrorSignal( VideoCollectionCommon::statusSingleDeleteFail , additional); |
|
709 QString expected = HbParameterLengthLimiter(hbTrId("txt_videos_info_unable_to_delete_1_it_is_current")).arg(txt); |
|
710 QCOMPARE(HbMessageBox::mLatestTxt, expected); |
|
711 |
|
712 HbMessageBox::mLatestTxt = ""; |
|
713 // VideoCollectionCommon::statusMultipleDeleteFail |
|
714 emit testErrorSignal( VideoCollectionCommon::statusMultipleDeleteFail , additional); |
|
715 QVERIFY(HbMessageBox::mLatestTxt.isEmpty()); |
|
716 |
|
717 disconnect(this, SIGNAL(testErrorSignal(int, QVariant&)), mPlugin, SLOT(handleErrorSlot(int, QVariant&))); |
|
718 |
|
719 cleanup(); |
|
720 } |
|
721 |
|
722 // --------------------------------------------------------------------------- |
|
723 // Slot: test for the testThumbnailReadySlot |
|
724 // --------------------------------------------------------------------------- |
|
725 // |
|
726 void TestVideoFileDetails::testThumbnailReadySlot() |
|
727 { |
|
728 TMPXItemId testIndex(9,0); |
|
729 QStringList display; |
|
730 display.append("first row"); |
|
731 display.append("second row"); |
|
732 QString filepath("filepath"); |
|
733 |
|
734 init(); |
|
735 activateView(); |
|
736 |
|
737 mDummyModel->setData(VideoCollectionCommon::KeyTitle, display); |
|
738 mDummyModel->setData(VideoCollectionCommon::KeyFilePath, filepath); |
|
739 |
|
740 emit shortDetailsReady(testIndex); |
|
741 |
|
742 mPlugin->mThumbnailManager->mThumbnailReadyError = -1; |
|
743 mPlugin->mThumbnailManager->emitThumbnailReady(0); |
|
744 |
|
745 HbStackedWidget* thumbWidget = findWidget<HbStackedWidget>(VIDEO_DETAILS_THUMBNAIL); |
|
746 VideoDetailsLabel* thumbLabel = (VideoDetailsLabel*)thumbWidget->widgetAt(0); |
|
747 QVERIFY( thumbLabel->icon().qicon().isNull() == false ); |
|
748 |
|
749 mPlugin->mThumbnailManager->mThumbnailReadyError = 0; |
|
750 emit shortDetailsReady(testIndex); |
|
751 mPlugin->mThumbnailManager->emitThumbnailReady(0); |
|
752 |
|
753 QVERIFY( thumbLabel->icon().qicon().isNull() == false ); |
|
754 |
|
755 cleanup(); |
|
756 } |
|
757 |
|
758 |
|
759 // --------------------------------------------------------------------------- |
|
760 // findWidget |
|
761 // --------------------------------------------------------------------------- |
|
762 // |
|
763 template<class T> |
|
764 T* TestVideoFileDetails::findWidget(QString name) |
|
765 { |
|
766 return qobject_cast<T *>(mPlugin->mLoader.findWidget(name)); |
|
767 } |
|
768 |
|
769 // --------------------------------------------------------------------------- |
|
770 // findObject |
|
771 // --------------------------------------------------------------------------- |
|
772 // |
|
773 template<class T> |
|
774 T* TestVideoFileDetails::findObject(QString name) |
|
775 { |
|
776 return qobject_cast<T *>(mPlugin->mLoader.findObject(name)); |
|
777 } |
|
778 |
|
779 // --------------------------------------------------------------------------- |
|
780 // main |
|
781 // --------------------------------------------------------------------------- |
|
782 // |
|
783 int main(int argc, char *argv[]) |
|
784 { |
|
785 HbApplication app(argc, argv); |
|
786 HbApplication::setKeypadNavigationEnabled(false); |
|
787 HbMainWindow mainWindow; |
|
788 mainWindow.show(); |
|
789 |
|
790 TestVideoFileDetails tc; |
|
791 |
|
792 char *pass[3]; |
|
793 pass[0] = argv[0]; |
|
794 pass[1] = "-o"; |
|
795 pass[2] = "c:\\data\\testvideofiledetailsviewplugin.txt"; |
|
796 |
|
797 return QTest::qExec(&tc, 3, pass); |
|
798 } |
|
799 |
|
800 // end of file |