26 #include "qmetatype.h" |
26 #include "qmetatype.h" |
27 #include <vcxmyvideosdefs.h> |
27 #include <vcxmyvideosdefs.h> |
28 |
28 |
29 #include "testvideothumbnaildata_p.h" |
29 #include "testvideothumbnaildata_p.h" |
30 #include "videothumbnailfetcher.h" |
30 #include "videothumbnailfetcher.h" |
31 #include "videosortfilterproxymodel.h" |
31 #include "videoproxymodelgeneric.h" |
32 #include "videocollectionwrapper.h" |
32 #include "videocollectionwrapper.h" |
33 |
33 |
34 #include "e32std.h" |
34 #include "e32std.h" |
35 |
35 |
36 #define private public |
36 #define private public |
113 VideoThumbnailFetcher::mContinueFetchingCallCount = 0; |
113 VideoThumbnailFetcher::mContinueFetchingCallCount = 0; |
114 VideoThumbnailFetcher::mEnableThumbnailCreationCallCount = 0; |
114 VideoThumbnailFetcher::mEnableThumbnailCreationCallCount = 0; |
115 VideoThumbnailFetcher::mAddFetchFails = false; |
115 VideoThumbnailFetcher::mAddFetchFails = false; |
116 VideoThumbnailFetcher::mThumbnailReadyError = 0; |
116 VideoThumbnailFetcher::mThumbnailReadyError = 0; |
117 |
117 |
118 mModel = new VideoSortFilterProxyModel(); |
118 mModel = new VideoProxyModelGeneric(); |
119 VideoCollectionWrapper::instance().setModel(mModel); |
119 VideoCollectionWrapper::instance().setModel(mModel); |
120 mTestObject = new VideoThumbnailDataTester(); |
120 mTestObject = new VideoThumbnailDataTester(); |
121 mTestObject->initialize(); |
121 mTestObject->initialize(); |
122 mTestObject->mCurrentModel = mModel; |
122 mTestObject->mCurrentModel = mModel; |
123 |
123 |
124 VideoSortFilterProxyModel::mReturnInvalidIndexes = false; |
124 VideoProxyModelGeneric::mReturnInvalidIndexes = false; |
125 VideoSortFilterProxyModel::mRowCountCallCount = 0; |
125 VideoProxyModelGeneric::mRowCountCallCount = 0; |
126 |
126 |
127 qRegisterMetaType<QList<TMPXItemId> >("QList<TMPXItemId>& "); |
127 qRegisterMetaType<QList<TMPXItemId> >("QList<TMPXItemId>& "); |
128 } |
128 } |
129 |
129 |
130 // --------------------------------------------------------------------------- |
130 // --------------------------------------------------------------------------- |
184 // testInitialize |
184 // testInitialize |
185 // --------------------------------------------------------------------------- |
185 // --------------------------------------------------------------------------- |
186 // |
186 // |
187 void TestVideoThumbnailData_p::testInitialize() |
187 void TestVideoThumbnailData_p::testInitialize() |
188 { |
188 { |
189 VideoCollectionWrapper::instance().setModel(0); |
|
190 |
|
191 mTestObject = new VideoThumbnailDataTester(); |
189 mTestObject = new VideoThumbnailDataTester(); |
192 QVERIFY(mTestObject->mThumbnailFetcher == 0); |
190 QVERIFY(mTestObject->initialize() == 0); |
193 QVERIFY(mTestObject->mCurrentModel == 0); |
191 VideoThumbnailFetcher *fetcher = mTestObject->mThumbnailFetcher; |
194 QVERIFY(mTestObject->mBgFetchTimer == 0); |
192 QTimer *ftimer = mTestObject->mBgFetchTimer; |
195 cleanup(); |
193 QTimer *rtimer = mTestObject->mTbnReportTimer; |
196 |
|
197 mTestObject = new VideoThumbnailDataTester(); |
|
198 mTestObject->disconnectSignals(); |
|
199 delete mTestObject->mBgFetchTimer; |
|
200 mTestObject->mBgFetchTimer = 0; |
|
201 delete mTestObject->mThumbnailFetcher; |
|
202 mTestObject->mThumbnailFetcher = 0; |
|
203 mTestObject->mCurrentModel = 0; |
|
204 |
|
205 mTestObject->initialize(); |
|
206 QVERIFY(mTestObject->mThumbnailFetcher == 0); |
|
207 QVERIFY(mTestObject->mCurrentModel == 0); |
|
208 QVERIFY(mTestObject->mBgFetchTimer == 0); |
|
209 cleanup(); |
|
210 |
|
211 init(); |
|
212 mTestObject->initialize(); |
|
213 mTestObject->initialize(); |
|
214 QVERIFY(mTestObject->mThumbnailFetcher != 0); |
194 QVERIFY(mTestObject->mThumbnailFetcher != 0); |
215 QVERIFY(mTestObject->mCurrentModel != 0); |
|
216 QVERIFY(mTestObject->mBgFetchTimer != 0); |
195 QVERIFY(mTestObject->mBgFetchTimer != 0); |
217 QCOMPARE( mTestObject->mThumbnailFetcher->mConstructorCallCount, 1); |
196 QVERIFY(mTestObject->mTbnReportTimer != 0); |
|
197 QVERIFY(mTestObject->initialize() == 0); |
|
198 // Verify they are still the same. |
|
199 QVERIFY(mTestObject->mThumbnailFetcher == fetcher); |
|
200 QVERIFY(mTestObject->mBgFetchTimer == ftimer); |
|
201 QVERIFY(mTestObject->mTbnReportTimer == rtimer); |
218 cleanup(); |
202 cleanup(); |
219 } |
203 } |
220 |
204 |
221 // --------------------------------------------------------------------------- |
205 // --------------------------------------------------------------------------- |
222 // testGetThumbnail |
206 // testGetThumbnail |
223 // --------------------------------------------------------------------------- |
207 // --------------------------------------------------------------------------- |
224 // |
208 // |
225 void TestVideoThumbnailData_p::testGetThumbnail() |
209 void TestVideoThumbnailData_p::testGetThumbnail() |
226 { |
210 { |
227 |
|
228 int mediaid(50); |
211 int mediaid(50); |
229 QPixmap pixmap(100,100); |
212 QPixmap pixmap(100,100); |
230 pixmap.fill(Qt::blue); |
213 pixmap.fill(Qt::blue); |
231 |
214 |
232 init(); |
215 init(); |
246 { |
229 { |
247 QSignalSpy* spy = 0; |
230 QSignalSpy* spy = 0; |
248 |
231 |
249 // Tests when mModel is null. |
232 // Tests when mModel is null. |
250 init(); |
233 init(); |
251 VideoSortFilterProxyModel* backupProxyModel = mTestObject->mCurrentModel; |
234 VideoProxyModelGeneric* backupProxyModel = mTestObject->mCurrentModel; |
252 mTestObject->mCurrentModel = NULL; |
235 mTestObject->mCurrentModel = NULL; |
253 spy = new QSignalSpy(mTestObject, SIGNAL(thumbnailsFetched(QList<TMPXItemId> &))); |
236 spy = new QSignalSpy(mTestObject, SIGNAL(thumbnailsFetched(QList<TMPXItemId> &))); |
254 QCOMPARE(mTestObject->startFetchingThumbnail(TMPXItemId(0, 0), TB_PRIORITY), -1); |
237 QCOMPARE(mTestObject->startFetchingThumbnail(TMPXItemId(0, 0), TB_PRIORITY), -1); |
255 QVERIFY(checkThumbnailReadyCount(spy, 0)); |
238 QVERIFY(checkThumbnailReadyCount(spy, 0)); |
256 delete spy; |
239 delete spy; |
356 init(); |
339 init(); |
357 indexes.clear(); |
340 indexes.clear(); |
358 indexes.append(mTestObject->mCurrentModel->index(0, 0, QModelIndex())); |
341 indexes.append(mTestObject->mCurrentModel->index(0, 0, QModelIndex())); |
359 indexes.append(mTestObject->mCurrentModel->index(10, 0, QModelIndex())); |
342 indexes.append(mTestObject->mCurrentModel->index(10, 0, QModelIndex())); |
360 indexes.append(mTestObject->mCurrentModel->index(20, 0, QModelIndex())); |
343 indexes.append(mTestObject->mCurrentModel->index(20, 0, QModelIndex())); |
361 VideoSortFilterProxyModel* backupProxyModel = mTestObject->mCurrentModel; |
344 VideoProxyModelGeneric* backupProxyModel = mTestObject->mCurrentModel; |
362 mTestObject->mCurrentModel = NULL; |
345 mTestObject->mCurrentModel = NULL; |
363 |
346 |
364 spy = new QSignalSpy(mTestObject, SIGNAL(thumbnailsFetched(QList<TMPXItemId> &))); |
347 spy = new QSignalSpy(mTestObject, SIGNAL(thumbnailsFetched(QList<TMPXItemId> &))); |
365 QCOMPARE(mTestObject->startFetchingThumbnails(indexes, |
348 QCOMPARE(mTestObject->startFetchingThumbnails(indexes, |
366 BACKGROUND_FETCH_PRIORITY), -1); |
349 BACKGROUND_FETCH_PRIORITY), -1); |
479 VideoThumbnailFetcher::TnRequest req; |
462 VideoThumbnailFetcher::TnRequest req; |
480 QSignalSpy* spy = 0; |
463 QSignalSpy* spy = 0; |
481 |
464 |
482 // Tests when mModel is null. |
465 // Tests when mModel is null. |
483 init(); |
466 init(); |
484 VideoSortFilterProxyModel* backupProxyModel = mTestObject->mCurrentModel; |
467 VideoProxyModelGeneric* backupProxyModel = mTestObject->mCurrentModel; |
485 mTestObject->mCurrentModel = NULL; |
468 mTestObject->mCurrentModel = NULL; |
486 spy = new QSignalSpy(mTestObject, SIGNAL(thumbnailsFetched(QList<TMPXItemId> &))); |
469 spy = new QSignalSpy(mTestObject, SIGNAL(thumbnailsFetched(QList<TMPXItemId> &))); |
487 mTestObject->emitDoBackgroundFetching(); |
470 mTestObject->emitDoBackgroundFetching(); |
488 QVERIFY(checkThumbnailReadyCount(spy, 0)); |
471 QVERIFY(checkThumbnailReadyCount(spy, 0)); |
489 delete spy; |
472 delete spy; |
490 QCOMPARE(VideoThumbnailFetcher::mRequests.count(), 0); |
473 QCOMPARE(VideoThumbnailFetcher::mRequests.count(), 0); |
491 mTestObject->mCurrentModel = backupProxyModel; |
474 mTestObject->mCurrentModel = backupProxyModel; |
492 QVERIFY(mTestObject->mCurrentFetchIndex == 0); |
475 QVERIFY(mTestObject->mCurrentFetchIndex == 0); |
493 QCOMPARE(VideoSortFilterProxyModel::mRowCountCallCount, 0); |
476 QCOMPARE(VideoProxyModelGeneric::mRowCountCallCount, 0); |
494 cleanup(); |
477 cleanup(); |
495 |
478 |
496 // Tests when mThumbnailFetcher is null. |
479 // Tests when mThumbnailFetcher is null. |
497 init(); |
480 init(); |
498 VideoThumbnailFetcher* backup = mTestObject->mThumbnailFetcher; |
481 VideoThumbnailFetcher* backup = mTestObject->mThumbnailFetcher; |
619 for(int i = 0; i < THUMBNAIL_BACKGROUND_FETCH_AMOUNT; i++) |
602 for(int i = 0; i < THUMBNAIL_BACKGROUND_FETCH_AMOUNT; i++) |
620 { |
603 { |
621 mTestObject->mCurrentModel->appendData(QString("file") + QString::number(i)); |
604 mTestObject->mCurrentModel->appendData(QString("file") + QString::number(i)); |
622 } |
605 } |
623 spy = new QSignalSpy(mTestObject, SIGNAL(thumbnailsFetched(QList<TMPXItemId>&))); |
606 spy = new QSignalSpy(mTestObject, SIGNAL(thumbnailsFetched(QList<TMPXItemId>&))); |
624 VideoSortFilterProxyModel::mReturnInvalidIndexes = true; |
607 VideoProxyModelGeneric::mReturnInvalidIndexes = true; |
625 mTestObject->mCurrentFetchIndex = THUMBNAIL_BACKGROUND_FETCH_AMOUNT/2; |
608 mTestObject->mCurrentFetchIndex = THUMBNAIL_BACKGROUND_FETCH_AMOUNT/2; |
626 mTestObject->emitDoBackgroundFetching(); |
609 mTestObject->emitDoBackgroundFetching(); |
627 QVERIFY(checkThumbnailReadyCount(spy, 0)); |
610 QVERIFY(checkThumbnailReadyCount(spy, 0)); |
628 QCOMPARE(VideoThumbnailFetcher::mRequests.count(), 0); |
611 QCOMPARE(VideoThumbnailFetcher::mRequests.count(), 0); |
629 QVERIFY(mTestObject->mCurrentFetchIndex == THUMBNAIL_BACKGROUND_FETCH_AMOUNT/2); |
612 QVERIFY(mTestObject->mCurrentFetchIndex == THUMBNAIL_BACKGROUND_FETCH_AMOUNT/2); |
714 QVERIFY( tn != 0 ); |
697 QVERIFY( tn != 0 ); |
715 QVERIFY( tn->isNull() == false ); |
698 QVERIFY( tn->isNull() == false ); |
716 // Second call when tn has been loaded already. |
699 // Second call when tn has been loaded already. |
717 QVERIFY(tn == mTestObject->defaultThumbnail(TMPXItemId(0, KVcxMvcMediaTypeAlbum))); |
700 QVERIFY(tn == mTestObject->defaultThumbnail(TMPXItemId(0, KVcxMvcMediaTypeAlbum))); |
718 QVERIFY(mTestObject->mDefaultThumbnails.count() == 2); |
701 QVERIFY(mTestObject->mDefaultThumbnails.count() == 2); |
719 |
|
720 // Default tn for unknown category |
|
721 tn = mTestObject->defaultThumbnail(TMPXItemId(555, KVcxMvcMediaTypeCategory)); |
|
722 QVERIFY( tn != 0 ); |
|
723 QVERIFY( tn->isNull() == false ); |
|
724 // Second call when tn has been loaded already. |
|
725 QVERIFY(tn == mTestObject->defaultThumbnail(TMPXItemId(0, KVcxMvcMediaTypeCategory))); |
|
726 // Still two because icon is same as default album |
|
727 QVERIFY(mTestObject->mDefaultThumbnails.count() == 2); |
|
728 |
702 |
729 // Default tn for downloads category |
703 // Default tn for downloads category |
730 tn = mTestObject->defaultThumbnail(TMPXItemId(KVcxMvcCategoryIdDownloads, KVcxMvcMediaTypeCategory)); |
704 tn = mTestObject->defaultThumbnail(TMPXItemId(KVcxMvcCategoryIdDownloads, KVcxMvcMediaTypeCategory)); |
731 QVERIFY( tn != 0 ); |
705 QVERIFY( tn != 0 ); |
732 QVERIFY( tn->isNull() == false ); |
706 QVERIFY( tn->isNull() == false ); |
741 // Second call when tn has been loaded already. |
715 // Second call when tn has been loaded already. |
742 QVERIFY(tn == mTestObject->defaultThumbnail(TMPXItemId(KVcxMvcCategoryIdCaptured, KVcxMvcMediaTypeCategory))); |
716 QVERIFY(tn == mTestObject->defaultThumbnail(TMPXItemId(KVcxMvcCategoryIdCaptured, KVcxMvcMediaTypeCategory))); |
743 QVERIFY(mTestObject->mDefaultThumbnails.count() == 4); |
717 QVERIFY(mTestObject->mDefaultThumbnails.count() == 4); |
744 |
718 |
745 cleanup(); |
719 cleanup(); |
746 |
720 |
747 |
721 init(); |
748 init(); |
|
749 |
|
750 QVERIFY(mTestObject->mDefaultThumbnails.count() == 0); |
722 QVERIFY(mTestObject->mDefaultThumbnails.count() == 0); |
751 |
723 |
752 // Default tn for unknown category, tn not loaded |
724 // Default tn for unknown category. |
753 tn = mTestObject->defaultThumbnail(TMPXItemId(555, KVcxMvcMediaTypeCategory)); |
725 tn = mTestObject->defaultThumbnail(TMPXItemId(555, KVcxMvcMediaTypeCategory)); |
754 QVERIFY( tn != 0 ); |
726 QVERIFY( tn == 0 ); |
755 QVERIFY( tn->isNull() == false ); |
|
756 // Second call when tn has been loaded already. |
|
757 QVERIFY(tn == mTestObject->defaultThumbnail(TMPXItemId(0, KVcxMvcMediaTypeCategory))); |
|
758 // Still two because icon is same as default album |
|
759 QVERIFY(mTestObject->mDefaultThumbnails.count() == 1); |
|
760 |
727 |
761 cleanup(); |
728 cleanup(); |
762 } |
729 } |
763 |
730 |
764 // --------------------------------------------------------------------------- |
731 // --------------------------------------------------------------------------- |
808 mTestObject->startBackgroundFetching(0, 10); |
775 mTestObject->startBackgroundFetching(0, 10); |
809 QVERIFY(mTestObject->mCurrentFetchIndex == 10); |
776 QVERIFY(mTestObject->mCurrentFetchIndex == 10); |
810 |
777 |
811 // Set new model. |
778 // Set new model. |
812 mTestObject->mBackgroundFetchingEnabled = true; |
779 mTestObject->mBackgroundFetchingEnabled = true; |
813 VideoSortFilterProxyModel *model = mTestObject->mCurrentModel; |
780 VideoProxyModelGeneric *model = mTestObject->mCurrentModel; |
814 mTestObject->mCurrentModel = 0; |
781 mTestObject->mCurrentModel = 0; |
815 mTestObject->mCurrentFetchIndex = -5; |
782 mTestObject->mCurrentFetchIndex = -5; |
816 mTestObject->startBackgroundFetching(model, 10); |
783 mTestObject->startBackgroundFetching(model, 10); |
817 QVERIFY(mTestObject->mCurrentFetchIndex == 10); |
784 QVERIFY(mTestObject->mCurrentFetchIndex == 10); |
818 QVERIFY(mTestObject->mCurrentModel != 0); |
785 QVERIFY(mTestObject->mCurrentModel != 0); |