44 //This so we can test private functions |
42 //This so we can test private functions |
45 #include "mpmpxcollectiondata_p.cpp" |
43 #include "mpmpxcollectiondata_p.cpp" |
46 |
44 |
47 struct TTestAttrs |
45 struct TTestAttrs |
48 { |
46 { |
|
47 const TInt GeneralId; |
49 const wchar_t* GeneralTitle; |
48 const wchar_t* GeneralTitle; |
50 const wchar_t* MusicArtist; |
49 const wchar_t* MusicArtist; |
51 const TInt GeneralCount; |
50 const TInt GeneralCount; |
52 const wchar_t* MusicAlbumArtFileName; |
51 const wchar_t* MusicAlbumArtFileName; |
53 }; |
52 }; |
54 |
53 |
55 const TTestAttrs KAllSongsTestData[] = |
54 const TTestAttrs KAllSongsTestData[] = |
56 { |
55 { |
57 { L"Title 1", L"Artist 1", 1, L"e:\\data\\images\\art1.jpg" } |
56 { 1001, L"Title 1", L"Artist 1", 1, L"e:\\data\\images\\art1.jpg" } |
58 ,{ L"Title 2", L"Artist 2", 1, L"e:\\data\\images\\art2.jpg" } |
57 ,{ 1002, L"Title 2", L"Artist 2", 1, L"e:\\data\\images\\art2.jpg" } |
59 ,{ L"Title 3", L"Artist 3", 1, L"e:\\data\\images\\art3.jpg" } |
58 ,{ 1003, L"Title 3", L"Artist 3", 1, L"e:\\data\\images\\art3.jpg" } |
60 ,{ L"Title 4", L"Artist 4", 1, L"e:\\data\\images\\art4.jpg" } |
59 ,{ 1004, L"Title 4", L"Artist 4", 1, L"e:\\data\\images\\art4.jpg" } |
61 ,{ L"Title 5", L"Artist 5", 1, L"e:\\data\\images\\art5.jpg" } |
60 ,{ 1005, L"Title 5", L"Artist 5", 1, L"e:\\data\\images\\art5.jpg" } |
62 ,{ L"Title 6", L"Artist 6", 1, L"e:\\data\\images\\art6.jpg" } |
61 ,{ 1006, L"Title 6", L"Artist 6", 1, L"e:\\data\\images\\art6.jpg" } |
63 ,{ L"Title 7", L"Artist 7", 1, L"e:\\data\\images\\art7.jpg" } |
62 ,{ 1007, L"Title 7", L"Artist 7", 1, L"e:\\data\\images\\art7.jpg" } |
64 ,{ L"Title 8", L"Artist 8", 1, L"e:\\data\\images\\art8.jpg" } |
63 ,{ 1008, L"Title 8", L"Artist 8", 1, L"e:\\data\\images\\art8.jpg" } |
65 ,{ L"Title 9", L"Artist 9", 1, L"e:\\data\\images\\art9.jpg" } |
64 ,{ 1009, L"Title 9", L"Artist 9", 1, L"e:\\data\\images\\art9.jpg" } |
66 ,{ L"Title 10", L"Artist 10", 1, L"e:\\data\\images\\art10.jpg" } |
65 ,{ 1010, L"Title 10", L"Artist 10", 1, L"e:\\data\\images\\art10.jpg" } |
67 }; |
66 }; |
68 |
67 |
69 |
68 |
70 /*! |
69 /*! |
71 Make our test case a stand-alone executable that runs all the test functions. |
70 Make our test case a stand-alone executable that runs all the test functions. |
72 */ |
71 */ |
73 int main(int argc, char *argv[]) |
72 int main(int argc, char *argv[]) |
74 { |
73 { |
75 HbApplication app(argc, argv); |
|
76 HbMainWindow window; |
|
77 |
|
78 TestMpMpxCollectionData tv; |
74 TestMpMpxCollectionData tv; |
79 |
75 |
80 char *pass[3]; |
76 if ( argc > 1 ) { |
81 pass[0] = argv[0]; |
77 return QTest::qExec( &tv, argc, argv); |
82 pass[1] = "-o"; |
78 } |
83 pass[2] = "c:\\data\\unittest_mpmpxcollectiondata.txt"; |
79 else { |
84 |
80 char *pass[3]; |
85 int res = QTest::qExec(&tv, 3, pass); |
81 pass[0] = argv[0]; |
86 |
82 pass[1] = "-o"; |
87 return res; |
83 pass[2] = "c:\\data\\unittest_mpmpxcollectiondata.txt"; |
|
84 |
|
85 return QTest::qExec(&tv, 3, pass); |
|
86 } |
88 } |
87 } |
89 |
88 |
90 TestMpMpxCollectionData::TestMpMpxCollectionData() |
89 TestMpMpxCollectionData::TestMpMpxCollectionData() |
91 : mTest(0) |
90 : mTest(0) |
92 { |
91 { |
248 media->SetTObjectValueL<TInt>(KMPXMediaGeneralCount, 0); |
245 media->SetTObjectValueL<TInt>(KMPXMediaGeneralCount, 0); |
249 media->SetTextValueL(KMPXMediaMusicAlbumArtFileName, KNullDesC); |
246 media->SetTextValueL(KMPXMediaMusicAlbumArtFileName, KNullDesC); |
250 array->AppendL(*media); |
247 array->AppendL(*media); |
251 CleanupStack::PopAndDestroy(media); |
248 CleanupStack::PopAndDestroy(media); |
252 mTestPrivate->iMediaArray = array; |
249 mTestPrivate->iMediaArray = array; |
253 |
250 |
254 //Media without attributes. |
251 //Media without attributes. |
255 QVERIFY(mTest->itemData( count, MpMpxCollectionData::Title).isNull()); |
252 QVERIFY(mTest->itemData( count, MpMpxCollectionData::Title).isNull()); |
256 QVERIFY(mTest->itemData( count, MpMpxCollectionData::Artist).isNull()); |
253 QVERIFY(mTest->itemData( count, MpMpxCollectionData::Artist).isNull()); |
257 //verification depends on language, just exercising the item. |
254 QCOMPARE(mTest->itemData( count, MpMpxCollectionData::Count), QString().setNum(0)); |
258 QVERIFY(!mTest->itemData( count, MpMpxCollectionData::Count).isNull()); |
|
259 QVERIFY(mTest->itemData( count, MpMpxCollectionData::AlbumArtUri).isNull()); |
255 QVERIFY(mTest->itemData( count, MpMpxCollectionData::AlbumArtUri).isNull()); |
260 |
256 |
261 //Media with empty attributes. |
257 //Media with empty attributes. |
262 QVERIFY(mTest->itemData( count + 1, MpMpxCollectionData::Title).isNull()); |
258 QVERIFY(mTest->itemData( count + 1, MpMpxCollectionData::Title).isNull()); |
263 QVERIFY(mTest->itemData( count + 1, MpMpxCollectionData::Artist).isNull()); |
259 QVERIFY(mTest->itemData( count + 1, MpMpxCollectionData::Artist).isNull()); |
264 //verification depends on language, just exercising the item. |
260 QCOMPARE(mTest->itemData( count + 1, MpMpxCollectionData::Count), QString().setNum(0)); |
265 QVERIFY(!mTest->itemData( count + 1, MpMpxCollectionData::Count).isNull()); |
|
266 QVERIFY(mTest->itemData( count + 1, MpMpxCollectionData::AlbumArtUri).isNull()); |
261 QVERIFY(mTest->itemData( count + 1, MpMpxCollectionData::AlbumArtUri).isNull()); |
267 |
262 |
268 /*Test Attributes that are not implemented yet. |
263 // Test Attributes that are not implemented yet: |
269 Uri, |
264 // Uri, Duration, Album, Genre, Rating |
270 Duration, |
|
271 Album, |
|
272 Genre, |
|
273 Rating, |
|
274 */ |
|
275 QVERIFY(mTest->itemData( 0, MpMpxCollectionData::Uri).isNull()); |
265 QVERIFY(mTest->itemData( 0, MpMpxCollectionData::Uri).isNull()); |
276 QVERIFY(mTest->itemData( 0, MpMpxCollectionData::Duration).isNull()); |
266 QVERIFY(mTest->itemData( 0, MpMpxCollectionData::Duration).isNull()); |
277 QVERIFY(mTest->itemData( 0, MpMpxCollectionData::Album).isNull()); |
267 QVERIFY(mTest->itemData( 0, MpMpxCollectionData::Album).isNull()); |
278 QVERIFY(mTest->itemData( 0, MpMpxCollectionData::Genre).isNull()); |
268 QVERIFY(mTest->itemData( 0, MpMpxCollectionData::Genre).isNull()); |
279 QVERIFY(mTest->itemData( 0, MpMpxCollectionData::Rating).isNull()); |
269 QVERIFY(mTest->itemData( 0, MpMpxCollectionData::Rating).isNull()); |
309 QSignalSpy spy(mTest, SIGNAL(contextChanged(TCollectionContext))); |
299 QSignalSpy spy(mTest, SIGNAL(contextChanged(TCollectionContext))); |
310 mTest->setMpxMedia(*entries); |
300 mTest->setMpxMedia(*entries); |
311 QCOMPARE(spy.count(), 1); |
301 QCOMPARE(spy.count(), 1); |
312 TCollectionContext context = qvariant_cast<TCollectionContext>(spy.at(0).at(0)); |
302 TCollectionContext context = qvariant_cast<TCollectionContext>(spy.at(0).at(0)); |
313 QCOMPARE(context, ECollectionContextPlaylistSongs); |
303 QCOMPARE(context, ECollectionContextPlaylistSongs); |
314 QVERIFY(!mTest->isAutoPlaylist()); |
304 QVERIFY(!mTest->isAutoPlaylist()); |
315 |
305 |
316 entries->SetTObjectValueL<TMPXGeneralNonPermissibleActions>( |
306 entries->SetTObjectValueL<TMPXGeneralNonPermissibleActions>( |
317 KMPXMediaGeneralNonPermissibleActions, EMPXWrite); |
307 KMPXMediaGeneralNonPermissibleActions, EMPXWrite); |
318 mTest->setMpxMedia(*entries); |
308 mTest->setMpxMedia(*entries); |
319 QCOMPARE(spy.count(), 2); |
309 QCOMPARE(spy.count(), 2); |
320 context = qvariant_cast<TCollectionContext>(spy.at(1).at(0)); |
310 context = qvariant_cast<TCollectionContext>(spy.at(1).at(0)); |
321 QCOMPARE(context, ECollectionContextPlaylistSongs); |
311 QCOMPARE(context, ECollectionContextPlaylistSongs); |
322 QVERIFY(mTest->isAutoPlaylist()); |
312 QVERIFY(mTest->isAutoPlaylist()); |
323 CleanupStack::PopAndDestroy(entries); |
313 CleanupStack::PopAndDestroy(entries); |
324 |
|
325 } |
314 } |
326 |
315 |
327 /*! |
316 /*! |
328 Tests testIsAutoPlaylist(int) |
317 Tests testIsAutoPlaylist(int) |
329 */ |
318 */ |
330 void TestMpMpxCollectionData::testIsAutoPlaylistWithIndex() |
319 void TestMpMpxCollectionData::testIsAutoPlaylistWithIndex() |
331 { |
320 { |
332 //if cotext is different than playlists value returned should be false |
321 // If context is different than playlists value returned should be false |
333 QVERIFY(!mTest->isAutoPlaylist(0)); |
322 QVERIFY(!mTest->isAutoPlaylist(0)); |
334 |
323 |
335 RArray<TInt> supportedIds; |
324 RArray<TInt> supportedIds; |
336 CleanupClosePushL( supportedIds ); |
325 CleanupClosePushL( supportedIds ); |
337 supportedIds.AppendL( KMPXMediaIdMusic ); |
326 supportedIds.AppendL( KMPXMediaIdMusic ); |
338 supportedIds.AppendL( KMPXMediaIdGeneral ); |
327 supportedIds.AppendL( KMPXMediaIdGeneral ); |
339 CMPXMedia* entries = CMPXMedia::NewL(supportedIds.Array()); |
328 CMPXMedia* entries = CMPXMedia::NewL(supportedIds.Array()); |
361 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXPlaylist); |
350 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXPlaylist); |
362 entries->SetTextValueL(KMPXMediaGeneralTitle, _L("My Test Playlist container")); |
351 entries->SetTextValueL(KMPXMediaGeneralTitle, _L("My Test Playlist container")); |
363 entries->SetCObjectValueL(KMPXMediaArrayContents, array); |
352 entries->SetCObjectValueL(KMPXMediaArrayContents, array); |
364 entries->SetTObjectValueL<TInt>(KMPXMediaArrayCount, array->Count()); |
353 entries->SetTObjectValueL<TInt>(KMPXMediaArrayCount, array->Count()); |
365 CleanupStack::PopAndDestroy(array); |
354 CleanupStack::PopAndDestroy(array); |
366 |
355 |
367 qRegisterMetaType<TCollectionContext>(); |
356 qRegisterMetaType<TCollectionContext>(); |
368 QSignalSpy spy(mTest, SIGNAL(contextChanged(TCollectionContext))); |
357 QSignalSpy spy(mTest, SIGNAL(contextChanged(TCollectionContext))); |
369 mTest->setMpxMedia(*entries); |
358 mTest->setMpxMedia(*entries); |
370 QCOMPARE(spy.count(), 1); |
359 QCOMPARE(spy.count(), 1); |
371 TCollectionContext context = qvariant_cast<TCollectionContext>(spy.at(0).at(0)); |
360 TCollectionContext context = qvariant_cast<TCollectionContext>(spy.at(0).at(0)); |
372 QCOMPARE(context, ECollectionContextPlaylists); |
361 QCOMPARE(context, ECollectionContextPlaylists); |
373 QVERIFY(!mTest->isAutoPlaylist( 0 )); |
362 QVERIFY(!mTest->isAutoPlaylist( 0 )); |
374 QVERIFY(mTest->isAutoPlaylist( 1 )); |
363 QVERIFY(mTest->isAutoPlaylist( 1 )); |
|
364 CleanupStack::PopAndDestroy(entries); |
375 } |
365 } |
376 |
366 |
377 /*! |
367 /*! |
378 Tests itemCount(int). |
368 Tests itemCount(int). |
379 */ |
369 */ |
380 void TestMpMpxCollectionData::TestItemCountWithIndex() |
370 void TestMpMpxCollectionData::TestItemCountWithIndex() |
381 { |
371 { |
382 |
372 CMPXMediaArray* array = CMPXMediaArray::NewL(); |
383 |
373 CleanupStack::PushL(array); |
384 CMPXMediaArray* array = CMPXMediaArray::NewL(); |
374 |
385 CleanupStack::PushL(array); |
|
386 |
|
387 CMPXMedia* media = CMPXMedia::NewL(); |
375 CMPXMedia* media = CMPXMedia::NewL(); |
388 CleanupStack::PushL(media); |
376 CleanupStack::PushL(media); |
389 //no attributes |
377 //no attributes |
390 array->AppendL(*media); |
378 array->AppendL(*media); |
391 CleanupStack::PopAndDestroy(media); |
379 CleanupStack::PopAndDestroy(media); |
415 /*! |
402 /*! |
416 Tests setCollectionContext(). |
403 Tests setCollectionContext(). |
417 */ |
404 */ |
418 void TestMpMpxCollectionData::testSetCollectionContextL() |
405 void TestMpMpxCollectionData::testSetCollectionContextL() |
419 { |
406 { |
420 |
|
421 RArray<TInt> supportedIds; |
407 RArray<TInt> supportedIds; |
422 CleanupClosePushL( supportedIds ); |
408 CleanupClosePushL( supportedIds ); |
423 supportedIds.AppendL( KMPXMediaIdMusic ); |
409 supportedIds.AppendL( KMPXMediaIdMusic ); |
424 supportedIds.AppendL( KMPXMediaIdGeneral ); |
410 supportedIds.AppendL( KMPXMediaIdGeneral ); |
425 CMPXMedia* entries = CMPXMedia::NewL(supportedIds.Array()); |
411 CMPXMedia* entries = CMPXMedia::NewL(supportedIds.Array()); |
426 CleanupStack::PopAndDestroy(&supportedIds); |
412 CleanupStack::PopAndDestroy(&supportedIds); |
427 CleanupStack::PushL(entries); |
413 CleanupStack::PushL(entries); |
428 |
414 |
429 |
|
430 |
|
431 /* FROM MPXDBPLUGIN.CPP |
|
432 // All Songs |
|
433 SetMediaGeneralAttributesL(aEntries, EMPXGroup, EMPXSong ... |
|
434 ... |
|
435 // All artists |
|
436 SetMediaGeneralAttributesL(aEntries, EMPXGroup, EMPXArtist ... |
|
437 ... |
|
438 // All albums of an artist |
|
439 SetMediaGeneralAttributesL(aEntries, EMPXItem, EMPXArtist ... |
|
440 ... |
|
441 // all songs for an artist |
|
442 SetMediaGeneralAttributesL(aEntries, EMPXItem, EMPXSong ... |
|
443 ... |
|
444 // all songs of an album for an artist |
|
445 SetMediaGeneralAttributesL(aEntries, EMPXItem, EMPXAlbum ... |
|
446 ... |
|
447 // All Albums |
|
448 SetMediaGeneralAttributesL(aEntries, EMPXGroup, EMPXAlbum ... |
|
449 ... |
|
450 // All songs in one or multiple albums |
|
451 SetMediaGeneralAttributesL(aEntries, EMPXItem, EMPXAlbum ... |
|
452 ... |
|
453 // All playlists |
|
454 SetMediaGeneralAttributesL(aEntries, EMPXGroup, EMPXPlaylist ... |
|
455 ... |
|
456 // All songs in a playlist |
|
457 SetMediaGeneralAttributesL(aEntries, EMPXItem, EMPXPlaylist ... |
|
458 ... |
|
459 // All genres |
|
460 SetMediaGeneralAttributesL(aEntries, EMPXGroup, EMPXGenre ... |
|
461 ... |
|
462 // All songs of a genre |
|
463 SetMediaGeneralAttributesL(aEntries, EMPXItem, EMPXGenre ... |
|
464 ... |
|
465 // All composers |
|
466 SetMediaGeneralAttributesL(aEntries, EMPXGroup, EMPXComposer ... |
|
467 ... |
|
468 // All songs of a composer |
|
469 SetMediaGeneralAttributesL(aEntries, EMPXItem, EMPXComposer ... |
|
470 */ |
|
471 |
|
472 // All Songs |
415 // All Songs |
473 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXGroup); |
416 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXGroup); |
474 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXSong); |
417 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXSong); |
475 mTestPrivate->iContainerMedia = entries; |
418 mTestPrivate->iContainerMedia = entries; |
476 mTestPrivate->SetCollectionContextL(); |
419 mTestPrivate->SetCollectionContextL(); |
477 QCOMPARE(mTestPrivate->iContext,ECollectionContextAllSongs); |
420 QCOMPARE(mTestPrivate->iContext, ECollectionContextAllSongs); |
478 |
421 |
479 // All artists |
422 // All artists |
480 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXGroup); |
423 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXGroup); |
481 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXArtist); |
424 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXArtist); |
482 mTestPrivate->iContainerMedia = entries; |
425 mTestPrivate->iContainerMedia = entries; |
483 mTestPrivate->SetCollectionContextL(); |
426 mTestPrivate->SetCollectionContextL(); |
484 QCOMPARE(mTestPrivate->iContext,ECollectionContextUnknown);//not implemented because is not in use. |
427 QCOMPARE(mTestPrivate->iContext, ECollectionContextArtists); |
485 |
428 |
486 // All albums of an artist |
429 // All albums of an artist |
487 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem); |
430 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem); |
488 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXArtist); |
431 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXArtist); |
489 mTestPrivate->iContainerMedia = entries; |
432 mTestPrivate->iContainerMedia = entries; |
|
433 CMPXMediaArray* array = CMPXMediaArray::NewL(); |
|
434 CleanupStack::PushL(array); |
|
435 CMPXMedia* media = CMPXMedia::NewL(); |
|
436 CleanupStack::PushL(media); |
|
437 array->AppendL(*media); |
|
438 CleanupStack::PopAndDestroy(media); |
|
439 CMPXMedia* media2 = CMPXMedia::NewL(); |
|
440 CleanupStack::PushL(media2); |
|
441 array->AppendL(*media2); |
|
442 CleanupStack::PopAndDestroy(media2); |
|
443 mTestPrivate->iMediaArray = array; |
490 mTestPrivate->SetCollectionContextL(); |
444 mTestPrivate->SetCollectionContextL(); |
491 QCOMPARE(mTestPrivate->iContext,ECollectionContextUnknown);//not implemented because is not in use. |
445 QCOMPARE(mTestPrivate->iContext, ECollectionContextArtistAlbums); |
492 |
446 mTestPrivate->iMediaArray = NULL; |
493 // all songs for an artist |
447 CleanupStack::PopAndDestroy(array); |
|
448 |
|
449 // All albums of an artist - Artist has only 1 album |
|
450 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem); |
|
451 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXArtist); |
|
452 mTestPrivate->iContainerMedia = entries; |
|
453 array = CMPXMediaArray::NewL(); |
|
454 CleanupStack::PushL(array); |
|
455 CMPXMedia* media3 = CMPXMedia::NewL(); |
|
456 CleanupStack::PushL(media3); |
|
457 array->AppendL(*media3); |
|
458 CleanupStack::PopAndDestroy(media3); |
|
459 mTestPrivate->iMediaArray = array; |
|
460 mTestPrivate->SetCollectionContextL(); |
|
461 QCOMPARE(mTestPrivate->iContext, ECollectionContextArtistAlbumsTBone); |
|
462 mTestPrivate->iMediaArray=NULL; |
|
463 CleanupStack::PopAndDestroy(array); |
|
464 |
|
465 // All songs for an artist |
494 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem); |
466 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem); |
495 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXSong); |
467 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXSong); |
496 mTestPrivate->iContainerMedia = entries; |
468 mTestPrivate->iContainerMedia = entries; |
497 mTestPrivate->SetCollectionContextL(); |
469 mTestPrivate->SetCollectionContextL(); |
498 QCOMPARE(mTestPrivate->iContext,ECollectionContextUnknown);//not implemented because is not in use. |
470 QCOMPARE(mTestPrivate->iContext, ECollectionContextArtistAllSongs); |
499 |
471 |
500 // all songs of an album for an artist |
472 // All albums |
501 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem); |
|
502 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXAlbum); |
|
503 mTestPrivate->iContainerMedia = entries; |
|
504 mTestPrivate->SetCollectionContextL(); |
|
505 QCOMPARE(mTestPrivate->iContext,ECollectionContextAlbumSongs); |
|
506 |
|
507 // All Albums |
|
508 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXGroup); |
473 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXGroup); |
509 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXAlbum); |
474 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXAlbum); |
510 mTestPrivate->iContainerMedia = entries; |
475 mTestPrivate->iContainerMedia = entries; |
511 mTestPrivate->SetCollectionContextL(); |
476 mTestPrivate->SetCollectionContextL(); |
512 QCOMPARE(mTestPrivate->iContext,ECollectionContextAlbums); |
477 QCOMPARE(mTestPrivate->iContext,ECollectionContextAlbums); |
513 |
478 |
514 // All songs in one or multiple albums |
|
515 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem); |
|
516 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXAlbum); |
|
517 mTestPrivate->iContainerMedia = entries; |
|
518 mTestPrivate->SetCollectionContextL(); |
|
519 QCOMPARE(mTestPrivate->iContext,ECollectionContextAlbumSongs); |
|
520 |
|
521 // All playlists |
479 // All playlists |
522 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXGroup); |
480 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXGroup); |
523 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXPlaylist); |
481 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXPlaylist); |
524 mTestPrivate->iContainerMedia = entries; |
482 mTestPrivate->iContainerMedia = entries; |
525 mTestPrivate->SetCollectionContextL(); |
483 mTestPrivate->SetCollectionContextL(); |
526 QCOMPARE(mTestPrivate->iContext,ECollectionContextPlaylists); |
484 QCOMPARE(mTestPrivate->iContext,ECollectionContextPlaylists); |
527 |
485 |
528 // All songs in a playlist |
486 // All songs in a playlist |
529 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem); |
487 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem); |
530 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXPlaylist); |
488 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXPlaylist); |
531 mTestPrivate->iContainerMedia = entries; |
489 mTestPrivate->iContainerMedia = entries; |
532 mTestPrivate->SetCollectionContextL(); |
490 mTestPrivate->SetCollectionContextL(); |
533 QCOMPARE(mTestPrivate->iContext,ECollectionContextPlaylistSongs); |
491 QCOMPARE(mTestPrivate->iContext,ECollectionContextPlaylistSongs); |
534 |
492 |
535 // All genres |
|
536 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXGroup); |
|
537 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXGenre); |
|
538 mTestPrivate->iContainerMedia = entries; |
|
539 mTestPrivate->SetCollectionContextL(); |
|
540 QCOMPARE(mTestPrivate->iContext,ECollectionContextGenres);//not in use and implementation could go away. |
|
541 |
|
542 // All songs of a genre |
|
543 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem); |
|
544 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXGenre); |
|
545 mTestPrivate->iContainerMedia = entries; |
|
546 mTestPrivate->SetCollectionContextL(); |
|
547 QCOMPARE(mTestPrivate->iContext,ECollectionContextGenreSongs);///not in use and implementation could go away. |
|
548 |
|
549 // All composers |
|
550 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXGroup); |
|
551 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXComposer); |
|
552 mTestPrivate->iContainerMedia = entries; |
|
553 mTestPrivate->SetCollectionContextL(); |
|
554 QCOMPARE(mTestPrivate->iContext,ECollectionContextUnknown);//not implemented because is not in use. |
|
555 |
|
556 // All songs of a composer |
|
557 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem); |
|
558 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXComposer); |
|
559 mTestPrivate->iContainerMedia = entries; |
|
560 mTestPrivate->SetCollectionContextL(); |
|
561 QCOMPARE(mTestPrivate->iContext,ECollectionContextUnknown);//not implemented because is not in use. |
|
562 |
|
563 |
|
564 mTestPrivate->iContainerMedia = NULL; |
493 mTestPrivate->iContainerMedia = NULL; |
565 CleanupStack::PopAndDestroy(entries); |
494 CleanupStack::PopAndDestroy(entries); |
566 } |
495 } |
567 |
496 |
568 /*! |
497 /*! |
569 Tests SetMpxMedia use case for all songs. |
498 Tests SetMpxMedia use case for all songs. |
570 */ |
499 */ |
571 void TestMpMpxCollectionData::testSetMpxMediaAllSongs() |
500 void TestMpMpxCollectionData::testSetMpxMediaAllSongs() |
572 { |
501 { |
573 |
|
574 |
|
575 RArray<TInt> supportedIds; |
502 RArray<TInt> supportedIds; |
576 CleanupClosePushL( supportedIds ); |
503 CleanupClosePushL( supportedIds ); |
577 supportedIds.AppendL( KMPXMediaIdMusic ); |
504 supportedIds.AppendL( KMPXMediaIdMusic ); |
578 supportedIds.AppendL( KMPXMediaIdGeneral ); |
505 supportedIds.AppendL( KMPXMediaIdGeneral ); |
579 CMPXMedia* entries = CMPXMedia::NewL(supportedIds.Array()); |
506 CMPXMedia* entries = CMPXMedia::NewL(supportedIds.Array()); |
695 */ |
622 */ |
696 void TestMpMpxCollectionData::testInsertCachedItemItem() |
623 void TestMpMpxCollectionData::testInsertCachedItemItem() |
697 { |
624 { |
698 int itemId = 147; |
625 int itemId = 147; |
699 CMPXMedia* item = CMPXMedia::NewL(); |
626 CMPXMedia* item = CMPXMedia::NewL(); |
700 |
627 |
701 mTestPrivate->iCachedRemovedItem = item; |
628 mTestPrivate->iCachedRemovedItem = item; |
702 QVERIFY( !mTest->testCachedItem( itemId ) ); |
629 QVERIFY( !mTest->testCachedItem( itemId ) ); |
703 |
630 |
704 item->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, itemId ); |
631 item->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, itemId ); |
705 QVERIFY( mTest->testCachedItem( itemId ) ); |
632 QVERIFY( mTest->testCachedItem( itemId ) ); |
706 |
633 |
707 delete mTestPrivate->iCachedRemovedItem; |
634 delete mTestPrivate->iCachedRemovedItem; |
708 mTestPrivate->iCachedRemovedItem = 0; |
635 mTestPrivate->iCachedRemovedItem = 0; |
709 } |
636 } |
710 |
637 |
711 //EOF |
638 /*! |
|
639 Tests setContext(). |
|
640 */ |
|
641 void TestMpMpxCollectionData::testSetContext() |
|
642 { |
|
643 qRegisterMetaType<TCollectionContext>(); |
|
644 QSignalSpy spy(mTest, SIGNAL(contextChanged(TCollectionContext))); |
|
645 mTest->setContext(ECollectionContextPlaylistSongs); |
|
646 // Verify that: |
|
647 // - contextChanged() signal is emitted |
|
648 // - Context is changed |
|
649 // - album index mapping is not cashed. |
|
650 QCOMPARE(spy.count(), 1); |
|
651 TCollectionContext context = qvariant_cast<TCollectionContext>(spy.at(0).at(0)); |
|
652 QCOMPARE(context, ECollectionContextPlaylistSongs); |
|
653 QCOMPARE(mTestPrivate->iContext, ECollectionContextPlaylistSongs); |
|
654 QVERIFY(mTestPrivate->albumIdIndexMapping.isEmpty()); |
|
655 } |
|
656 |
|
657 /*! |
|
658 Tests setContext() for media wall use case. |
|
659 Tests setContext() for media wall use case. |
|
660 */ |
|
661 void TestMpMpxCollectionData::testSetContextMediaWall() |
|
662 { |
|
663 CMPXMediaArray* array = CMPXMediaArray::NewL(); |
|
664 CleanupStack::PushL(array); |
|
665 TInt count = sizeof(KAllSongsTestData)/sizeof(TTestAttrs); |
|
666 for (TInt i =0; i < count; i++) { |
|
667 mTestPrivate->iMediaArray = array; |
|
668 QCOMPARE(mTest->count(), i); |
|
669 CMPXMedia* media = CMPXMedia::NewL(); |
|
670 CleanupStack::PushL(media); |
|
671 media->SetTObjectValueL<TInt>(KMPXMediaGeneralId, KAllSongsTestData[i].GeneralId); |
|
672 array->AppendL(*media); |
|
673 CleanupStack::PopAndDestroy(media); |
|
674 } |
|
675 mTestPrivate->iMediaArray = array; |
|
676 |
|
677 qRegisterMetaType<TCollectionContext>(); |
|
678 QSignalSpy spy(mTest, SIGNAL(contextChanged(TCollectionContext))); |
|
679 |
|
680 mTest->setContext(ECollectionContextAlbumsMediaWall); |
|
681 // Verify that: |
|
682 // - contextChanged() signal is emitted |
|
683 // - Context is changed |
|
684 // - album index mapping is cashed. |
|
685 // - album index mapping is cleared when changing context again. |
|
686 QCOMPARE(spy.count(), 1); |
|
687 TCollectionContext context = qvariant_cast<TCollectionContext>(spy.at(0).at(0)); |
|
688 QCOMPARE(context, ECollectionContextAlbumsMediaWall); |
|
689 QCOMPARE(mTestPrivate->iContext, ECollectionContextAlbumsMediaWall); |
|
690 QVERIFY(!mTestPrivate->albumIdIndexMapping.isEmpty()); |
|
691 for (TInt i =0; i < count; i++) { |
|
692 QCOMPARE(mTest->itemIndex(KAllSongsTestData[i].GeneralId),i); |
|
693 } |
|
694 mTest->setContext(ECollectionContextPlaylistSongs); |
|
695 QVERIFY(mTestPrivate->albumIdIndexMapping.isEmpty()); |
|
696 CleanupStack::PopAndDestroy(array); |
|
697 } |
|
698 |
|
699 |
|
700 /*! |
|
701 Tests setAlbumContent(). |
|
702 */ |
|
703 void TestMpMpxCollectionData::testSetAlbumContent() |
|
704 { |
|
705 CMPXMediaArray* array = CMPXMediaArray::NewL(); |
|
706 CleanupStack::PushL(array); |
|
707 CMPXMedia* media = CMPXMedia::NewL(); |
|
708 CleanupStack::PushL(media); |
|
709 array->AppendL(*media); |
|
710 CleanupStack::PopAndDestroy(media); |
|
711 |
|
712 mTestPrivate->iMediaArray = array; |
|
713 mTestPrivate->iCurrentAlbumIndex = 0; |
|
714 |
|
715 CMPXMedia* albumContent = CMPXMedia::NewL(); |
|
716 CleanupStack::PushL(albumContent); |
|
717 CMPXMediaArray* songArray = CMPXMediaArray::NewL(); |
|
718 CleanupStack::PushL(songArray); |
|
719 TInt count = sizeof(KAllSongsTestData)/sizeof(TTestAttrs); |
|
720 for (TInt i =0; i < count; i++) { |
|
721 CMPXMedia* song = CMPXMedia::NewL(); |
|
722 CleanupStack::PushL(song); |
|
723 songArray->AppendL(*song); |
|
724 CleanupStack::PopAndDestroy(song); |
|
725 } |
|
726 albumContent->SetCObjectValueL(KMPXMediaArrayContents, songArray); |
|
727 CleanupStack::PopAndDestroy(songArray); |
|
728 |
|
729 // Verify that: |
|
730 // - refreshAlbumSongs() signal is emitted |
|
731 // - Album song count is updated correctly |
|
732 QSignalSpy spy(mTest, SIGNAL(refreshAlbumSongs())); |
|
733 mTest->setAlbumContent(*albumContent); |
|
734 QCOMPARE(spy.count(), 1); |
|
735 QCOMPARE(mTest->albumSongsCount(), count); |
|
736 QCOMPARE(mTestPrivate->iMediaArray->AtL(0)->ValueTObjectL<TInt>(KMPXMediaArrayCount), count); |
|
737 |
|
738 CleanupStack::PopAndDestroy(albumContent); |
|
739 mTestPrivate->iMediaArray = NULL; |
|
740 CleanupStack::PopAndDestroy(array); |
|
741 } |
|
742 |
|
743 /*! |
|
744 Tests setCurrentAlbum(). |
|
745 */ |
|
746 void TestMpMpxCollectionData::testSetCurrentAlbum() |
|
747 { |
|
748 QSignalSpy spy(mTest, SIGNAL(refreshAlbumSongs())); |
|
749 |
|
750 // Create media array that doesn't have the album songs yet. |
|
751 CMPXMediaArray* array = CMPXMediaArray::NewL(); |
|
752 CleanupStack::PushL(array); |
|
753 CMPXMedia* media = CMPXMedia::NewL(); |
|
754 CleanupStack::PushL(media); |
|
755 array->AppendL(*media); |
|
756 CleanupStack::PopAndDestroy(media); |
|
757 mTestPrivate->iMediaArray = array; |
|
758 mTestPrivate->iCurrentAlbumIndex = -1; |
|
759 |
|
760 // Verify that: |
|
761 // - refreshAlbumSongs() signal is NOT emitted |
|
762 // - album index is set |
|
763 // - availability is returned as false (this means that client |
|
764 // should initiate a find) |
|
765 bool available = mTest->setCurrentAlbum(0); |
|
766 QCOMPARE(available, false); |
|
767 QCOMPARE(mTest->currentAlbumIndex(), 0); |
|
768 QCOMPARE(spy.count(), 0); |
|
769 |
|
770 // Now populate the media (album) with songs. This is basically |
|
771 // simulating setAlbumContent(). |
|
772 CMPXMediaArray* songArray = CMPXMediaArray::NewL(); |
|
773 CleanupStack::PushL(songArray); |
|
774 TInt count = sizeof(KAllSongsTestData)/sizeof(TTestAttrs); |
|
775 for (TInt i =0; i < count; i++) { |
|
776 CMPXMedia* media = CMPXMedia::NewL(); |
|
777 CleanupStack::PushL(media); |
|
778 songArray->AppendL(*media); |
|
779 CleanupStack::PopAndDestroy(media); |
|
780 } |
|
781 media = CMPXMedia::NewL(); |
|
782 CleanupStack::PushL(media); |
|
783 media->SetCObjectValueL(KMPXMediaArrayContents, songArray); |
|
784 array->AppendL(*media); |
|
785 CleanupStack::PopAndDestroy(media); |
|
786 CleanupStack::PopAndDestroy(songArray); |
|
787 mTestPrivate->iAlbumSongCount = 0; |
|
788 |
|
789 // Verify that: |
|
790 // - refreshAlbumSongs() signal is emitted |
|
791 // - album index is set |
|
792 // - availability is returned as true |
|
793 // - album song count is set |
|
794 available = mTest->setCurrentAlbum(1); |
|
795 QCOMPARE(available, true); |
|
796 QCOMPARE(mTest->currentAlbumIndex(), 1); |
|
797 QCOMPARE(mTest->albumSongsCount(), count); |
|
798 QCOMPARE(spy.count(), 1); |
|
799 |
|
800 mTestPrivate->iMediaArray = NULL; |
|
801 CleanupStack::PopAndDestroy(array); |
|
802 } |
|
803 |
|
804 /*! |
|
805 Tests albumSongData(). |
|
806 */ |
|
807 void TestMpMpxCollectionData::testAlbumSongData() |
|
808 { |
|
809 // Populate the media (album) with songs. This is basically |
|
810 // simulating setAlbumContent(). |
|
811 CMPXMediaArray* array = CMPXMediaArray::NewL(); |
|
812 CleanupStack::PushL(array); |
|
813 CMPXMedia* media = CMPXMedia::NewL(); |
|
814 CleanupStack::PushL(media); |
|
815 CMPXMediaArray* songArray = CMPXMediaArray::NewL(); |
|
816 CleanupStack::PushL(songArray); |
|
817 TInt count = sizeof(KAllSongsTestData)/sizeof(TTestAttrs); |
|
818 for (TInt i = 0; i < count; i++) { |
|
819 CMPXMedia* song = CMPXMedia::NewL(); |
|
820 CleanupStack::PushL(song); |
|
821 song->SetTextValueL(KMPXMediaGeneralTitle, TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[i].GeneralTitle))); |
|
822 song->SetTextValueL(KMPXMediaGeneralUri, TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[i].MusicAlbumArtFileName))); |
|
823 songArray->AppendL(*song); |
|
824 CleanupStack::PopAndDestroy(song); |
|
825 } |
|
826 media->SetCObjectValueL(KMPXMediaArrayContents, songArray); |
|
827 array->AppendL(*media); |
|
828 |
|
829 mTestPrivate->iMediaArray = array; |
|
830 mTestPrivate->iCurrentAlbumIndex = 0; |
|
831 |
|
832 // Loop through all items to verify the album song data |
|
833 for (TInt i =0; i < count; i++) { |
|
834 const TDesC& title = TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[i].GeneralTitle)); |
|
835 QCOMPARE(mTest->albumSongData( i, MpMpxCollectionData::Title), QString::fromUtf16( title.Ptr(), title.Length())); |
|
836 |
|
837 const TDesC& uri = TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[i].MusicAlbumArtFileName)); |
|
838 QCOMPARE(mTest->albumSongData( i, MpMpxCollectionData::Uri), QString::fromUtf16( uri.Ptr(), uri.Length())); |
|
839 } |
|
840 |
|
841 // Create a song entry that doesn't have Title or Uri. |
|
842 CMPXMedia* song = CMPXMedia::NewL(); |
|
843 CleanupStack::PushL(song); |
|
844 song->SetTextValueL(KMPXMediaGeneralTitle, KNullDesC ); |
|
845 song->SetTextValueL(KMPXMediaMusicArtist, KNullDesC); |
|
846 songArray->AppendL(*song); |
|
847 CleanupStack::PopAndDestroy(song); |
|
848 |
|
849 // Verify that it returned empty string. |
|
850 QVERIFY(mTest->albumSongData( count, MpMpxCollectionData::Title).isNull()); |
|
851 QVERIFY(mTest->albumSongData( count, MpMpxCollectionData::Uri).isNull()); |
|
852 |
|
853 CleanupStack::PopAndDestroy(songArray); |
|
854 CleanupStack::PopAndDestroy(media); |
|
855 mTestPrivate->iMediaArray = NULL; |
|
856 CleanupStack::PopAndDestroy(array); |
|
857 } |