mpdata/tsrc/unittest_mpmpxcollectiondata/src/unittest_mpmpxcollectiondata.cpp
changeset 35 fdb31ab341af
parent 22 ecf06a08d4d9
child 38 b93f525c9244
equal deleted inserted replaced
34:2c5162224003 35:fdb31ab341af
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <QSignalSpy>
    18 #include <QSignalSpy>
    19 #include <QMetaType>
    19 #include <QMetaType>
    20 #include <hbapplication.h>
       
    21 #include <hbmainwindow.h>
       
    22 
    20 
    23 #include <apacmdln.h>
    21 #include <apacmdln.h>
    24 #include <mpxmediamusicdefs.h>
    22 #include <mpxmediamusicdefs.h>
    25 #include <mpxmediacontainerdefs.h>
    23 #include <mpxmediacontainerdefs.h>
    26 #include <mpxmedia.h>
    24 #include <mpxmedia.h>
    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 {
   145     QCOMPARE(mTest->context(), ECollectionContextUnknown);
   144     QCOMPARE(mTest->context(), ECollectionContextUnknown);
   146     mTestPrivate->iContext = ECollectionContextPlaylistSongs;
   145     mTestPrivate->iContext = ECollectionContextPlaylistSongs;
   147     QCOMPARE(mTest->context(), ECollectionContextPlaylistSongs);
   146     QCOMPARE(mTest->context(), ECollectionContextPlaylistSongs);
   148 }
   147 }
   149 
   148 
   150 
       
   151 /*!
   149 /*!
   152  Tests count().
   150  Tests count().
   153  */
   151  */
   154 void TestMpMpxCollectionData::testCount()
   152 void TestMpMpxCollectionData::testCount()
   155 {
   153 {
   156     mTestPrivate->iMediaArray = NULL;
   154     mTestPrivate->iMediaArray = NULL;
   157     QCOMPARE(mTest->count(), 0);
   155     QCOMPARE(mTest->count(), 0);
   158     
   156 
   159     CMPXMediaArray* array = CMPXMediaArray::NewL();
   157     CMPXMediaArray* array = CMPXMediaArray::NewL();
   160     CleanupStack::PushL(array);   
   158     CleanupStack::PushL(array);
   161     TInt count = sizeof(KAllSongsTestData)/sizeof(TTestAttrs);
   159     TInt count = sizeof(KAllSongsTestData)/sizeof(TTestAttrs);
   162     for (TInt i =0; i < count; i++) {
   160     for (TInt i =0; i < count; i++) {
   163         mTestPrivate->iMediaArray = array;
   161         mTestPrivate->iMediaArray = array;
   164         QCOMPARE(mTest->count(), i);
   162         QCOMPARE(mTest->count(), i);
   165         CMPXMedia* media = CMPXMedia::NewL();
   163         CMPXMedia* media = CMPXMedia::NewL();
   180  Tests collectionTitle().
   178  Tests collectionTitle().
   181  */
   179  */
   182 void TestMpMpxCollectionData::testCollectionTitle()
   180 void TestMpMpxCollectionData::testCollectionTitle()
   183 {
   181 {
   184     mTestPrivate->iContainerMedia = NULL;
   182     mTestPrivate->iContainerMedia = NULL;
   185     QCOMPARE(mTest->collectionTitle(), QString());   
   183     QCOMPARE(mTest->collectionTitle(), QString());
   186     RArray<TInt> supportedIds;
   184     RArray<TInt> supportedIds;
   187     CleanupClosePushL( supportedIds );
   185     CleanupClosePushL( supportedIds );
   188     supportedIds.AppendL( KMPXMediaIdMusic );
   186     supportedIds.AppendL( KMPXMediaIdMusic );
   189     supportedIds.AppendL( KMPXMediaIdGeneral );
   187     supportedIds.AppendL( KMPXMediaIdGeneral );
   190     CMPXMedia* entries = CMPXMedia::NewL(supportedIds.Array());
   188     CMPXMedia* entries = CMPXMedia::NewL(supportedIds.Array());
   191     CleanupStack::PopAndDestroy(&supportedIds);
   189     CleanupStack::PopAndDestroy(&supportedIds);
   192     CleanupStack::PushL(entries);
   190     CleanupStack::PushL(entries);
   193         
   191 
   194     mTestPrivate->iContainerMedia = entries;
   192     mTestPrivate->iContainerMedia = entries;
   195     QCOMPARE(mTest->collectionTitle(), QString());
   193     QCOMPARE(mTest->collectionTitle(), QString());
   196     
   194 
   197     entries->SetTextValueL(KMPXMediaGeneralTitle, _L("All songs"));
   195     entries->SetTextValueL(KMPXMediaGeneralTitle, _L("All songs"));
   198 
   196 
   199     mTestPrivate->iContainerMedia = entries;
   197     mTestPrivate->iContainerMedia = entries;
   200     QCOMPARE(mTest->collectionTitle(), QString("All songs"));
   198     QCOMPARE(mTest->collectionTitle(), QString("All songs"));
   201     mTestPrivate->iContainerMedia = NULL;
   199     mTestPrivate->iContainerMedia = NULL;
   206  Tests itemData().
   204  Tests itemData().
   207  */
   205  */
   208 void TestMpMpxCollectionData::testItemData()
   206 void TestMpMpxCollectionData::testItemData()
   209 {
   207 {
   210     CMPXMediaArray* array = CMPXMediaArray::NewL();
   208     CMPXMediaArray* array = CMPXMediaArray::NewL();
   211     CleanupStack::PushL(array);   
   209     CleanupStack::PushL(array);
   212     mTestPrivate->iMediaArray = array;
   210     mTestPrivate->iMediaArray = array;
   213         
   211 
   214     TInt count = sizeof(KAllSongsTestData)/sizeof(TTestAttrs);
   212     TInt count = sizeof(KAllSongsTestData)/sizeof(TTestAttrs);
   215     for (TInt i =0; i < count; i++) {
   213     for (TInt i =0; i < count; i++) {
   216 
   214 
   217         CMPXMedia* media = CMPXMedia::NewL();
   215         CMPXMedia* media = CMPXMedia::NewL();
   218         CleanupStack::PushL(media);
   216         CleanupStack::PushL(media);
   228         QCOMPARE(mTest->itemData( i, MpMpxCollectionData::Title), QString::fromUtf16( title.Ptr(), title.Length()));
   226         QCOMPARE(mTest->itemData( i, MpMpxCollectionData::Title), QString::fromUtf16( title.Ptr(), title.Length()));
   229 
   227 
   230         const TDesC& artist = TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[i].MusicArtist));
   228         const TDesC& artist = TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[i].MusicArtist));
   231         QCOMPARE(mTest->itemData( i, MpMpxCollectionData::Artist), QString::fromUtf16( artist.Ptr(), artist.Length()));
   229         QCOMPARE(mTest->itemData( i, MpMpxCollectionData::Artist), QString::fromUtf16( artist.Ptr(), artist.Length()));
   232 
   230 
   233         //verification depends on language, just exercising the item.
   231         QCOMPARE(mTest->itemData( i, MpMpxCollectionData::Count), QString().setNum(1));
   234         QVERIFY(!mTest->itemData( i, MpMpxCollectionData::Count).isNull());
       
   235 
   232 
   236         const TDesC& albumArtUri = TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[i].MusicAlbumArtFileName));
   233         const TDesC& albumArtUri = TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[i].MusicAlbumArtFileName));
   237         QCOMPARE(mTest->itemData( i, MpMpxCollectionData::AlbumArtUri), QString::fromUtf16( albumArtUri.Ptr(), albumArtUri.Length()));
   234         QCOMPARE(mTest->itemData( i, MpMpxCollectionData::AlbumArtUri), QString::fromUtf16( albumArtUri.Ptr(), albumArtUri.Length()));
   238 
   235 
   239     }
   236     }
   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());
   281     CleanupStack::PopAndDestroy(array);
   271     CleanupStack::PopAndDestroy(array);
   282     mTestPrivate->iMediaArray = NULL;
   272     mTestPrivate->iMediaArray = NULL;
   283 }
   273 }
   284 
   274 
   285 /*!
   275 /*!
   286  Tests isAutoPlaylis().
   276  Tests isAutoPlaylist().
   287  */
   277  */
   288 void TestMpMpxCollectionData::testIsAutoPlaylist()
   278 void TestMpMpxCollectionData::testIsAutoPlaylist()
   289 {
   279 {
   290     //if cotext is different than playlistsongs value returned should be false
   280     //if context is different than playlistsongs value returned should be false
   291     QVERIFY(!mTest->isAutoPlaylist());
   281     QVERIFY(!mTest->isAutoPlaylist());
   292     RArray<TInt> supportedIds;
   282     RArray<TInt> supportedIds;
   293     CleanupClosePushL( supportedIds );
   283     CleanupClosePushL( supportedIds );
   294     supportedIds.AppendL( KMPXMediaIdMusic );
   284     supportedIds.AppendL( KMPXMediaIdMusic );
   295     supportedIds.AppendL( KMPXMediaIdGeneral );
   285     supportedIds.AppendL( KMPXMediaIdGeneral );
   296     CMPXMedia* entries = CMPXMedia::NewL(supportedIds.Array());
   286     CMPXMedia* entries = CMPXMedia::NewL(supportedIds.Array());
   297     CleanupStack::PopAndDestroy(&supportedIds);
   287     CleanupStack::PopAndDestroy(&supportedIds);
   298     CleanupStack::PushL(entries);
   288     CleanupStack::PushL(entries);
   299     CMPXMediaArray* array = CMPXMediaArray::NewL();
   289     CMPXMediaArray* array = CMPXMediaArray::NewL();
   300     CleanupStack::PushL(array);
   290     CleanupStack::PushL(array);
   301     
   291 
   302     entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem);
   292     entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem);
   303     entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXPlaylist);
   293     entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXPlaylist);
   304     entries->SetTextValueL(KMPXMediaGeneralTitle, _L("My Test Playlist Songs"));
   294     entries->SetTextValueL(KMPXMediaGeneralTitle, _L("My Test Playlist Songs"));
   305     entries->SetCObjectValueL(KMPXMediaArrayContents, array);
   295     entries->SetCObjectValueL(KMPXMediaArrayContents, array);
   306     entries->SetTObjectValueL<TInt>(KMPXMediaArrayCount, array->Count());
   296     entries->SetTObjectValueL<TInt>(KMPXMediaArrayCount, array->Count());
   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);
   399     CMPXMedia* media3 = CMPXMedia::NewL();
   387     CMPXMedia* media3 = CMPXMedia::NewL();
   400     CleanupStack::PushL(media3);
   388     CleanupStack::PushL(media3);
   401     media3->SetTObjectValueL<TInt>(KMPXMediaGeneralCount,20);
   389     media3->SetTObjectValueL<TInt>(KMPXMediaGeneralCount,20);
   402     array->AppendL(*media3);
   390     array->AppendL(*media3);
   403     CleanupStack::PopAndDestroy(media3);
   391     CleanupStack::PopAndDestroy(media3);
   404     
   392 
   405     
       
   406     mTestPrivate->iMediaArray=array;
   393     mTestPrivate->iMediaArray=array;
   407     QCOMPARE(mTest->itemCount(0),0);
   394     QCOMPARE(mTest->itemCount(0),0);
   408     QCOMPARE(mTest->itemCount(1),0);
   395     QCOMPARE(mTest->itemCount(1),0);
   409     QCOMPARE(mTest->itemCount(2),20);
   396     QCOMPARE(mTest->itemCount(2),20);
   410 
   397 
   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());
   590         media->SetTObjectValueL<TInt>(KMPXMediaGeneralCount, KAllSongsTestData[i].GeneralCount);
   517         media->SetTObjectValueL<TInt>(KMPXMediaGeneralCount, KAllSongsTestData[i].GeneralCount);
   591         media->SetTextValueL(KMPXMediaMusicAlbumArtFileName, TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[i].MusicAlbumArtFileName)));
   518         media->SetTextValueL(KMPXMediaMusicAlbumArtFileName, TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[i].MusicAlbumArtFileName)));
   592         array->AppendL(*media);
   519         array->AppendL(*media);
   593         CleanupStack::PopAndDestroy(media);
   520         CleanupStack::PopAndDestroy(media);
   594     }
   521     }
   595     
   522 
   596     entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXGroup);
   523     entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXGroup);
   597     entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXSong);
   524     entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXSong);
   598     entries->SetTextValueL(KMPXMediaGeneralTitle, _L("All songs"));
   525     entries->SetTextValueL(KMPXMediaGeneralTitle, _L("All songs"));
   599    
   526 
   600     entries->SetCObjectValueL(KMPXMediaArrayContents, array);
   527     entries->SetCObjectValueL(KMPXMediaArrayContents, array);
   601     entries->SetTObjectValueL<TInt>(KMPXMediaArrayCount, array->Count());
   528     entries->SetTObjectValueL<TInt>(KMPXMediaArrayCount, array->Count());
   602     CleanupStack::PopAndDestroy(array);
   529     CleanupStack::PopAndDestroy(array);
   603  
   530 
   604     qRegisterMetaType<TCollectionContext>();
   531     qRegisterMetaType<TCollectionContext>();
   605     QSignalSpy spy(mTest, SIGNAL(contextChanged(TCollectionContext)));
   532     QSignalSpy spy(mTest, SIGNAL(contextChanged(TCollectionContext)));
   606     mTest->setMpxMedia(*entries);
   533     mTest->setMpxMedia(*entries);
   607     QCOMPARE(spy.count(), 1);
   534     QCOMPARE(spy.count(), 1);
   608     TCollectionContext context = qvariant_cast<TCollectionContext>(spy.at(0).at(0));
   535     TCollectionContext context = qvariant_cast<TCollectionContext>(spy.at(0).at(0));
   622 
   549 
   623     container->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, containerId );
   550     container->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, containerId );
   624     QCOMPARE( mTest->containerId(), containerId);
   551     QCOMPARE( mTest->containerId(), containerId);
   625     delete container;
   552     delete container;
   626     mTestPrivate->iContainerMedia = 0;
   553     mTestPrivate->iContainerMedia = 0;
   627     
   554 
   628 }
   555 }
   629 
   556 
   630 /*!
   557 /*!
   631  Tests itemId().
   558  Tests itemId().
   632  */
   559  */
   640     mTestPrivate->iMediaArray = array;
   567     mTestPrivate->iMediaArray = array;
   641     QCOMPARE( mTest->itemId(0), -1);
   568     QCOMPARE( mTest->itemId(0), -1);
   642 
   569 
   643     item->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, itemId );
   570     item->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, itemId );
   644     QCOMPARE( mTest->itemId(0), itemId);
   571     QCOMPARE( mTest->itemId(0), itemId);
   645     
   572 
   646     delete array;
   573     delete array;
   647     mTestPrivate->iMediaArray = 0;
   574     mTestPrivate->iMediaArray = 0;
   648     
   575 
   649 }
   576 }
   650 
   577 
   651 /*!
   578 /*!
   652  Tests removeItem().
   579  Tests removeItem().
   653  */
   580  */
   657     CMPXMedia* item = CMPXMedia::NewL();
   584     CMPXMedia* item = CMPXMedia::NewL();
   658     item->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, itemId );
   585     item->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, itemId );
   659     CMPXMediaArray* array = CMPXMediaArray::NewL();
   586     CMPXMediaArray* array = CMPXMediaArray::NewL();
   660     array->AppendL(item);
   587     array->AppendL(item);
   661     mTestPrivate->iMediaArray = array;
   588     mTestPrivate->iMediaArray = array;
   662     
   589 
   663     mTest->removeItem(0);
   590     mTest->removeItem(0);
   664     QVERIFY( mTestPrivate->iCachedRemovedItem );
   591     QVERIFY( mTestPrivate->iCachedRemovedItem );
   665     QCOMPARE( int(mTestPrivate->iCachedRemovedItem->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId )), itemId );
   592     QCOMPARE( int(mTestPrivate->iCachedRemovedItem->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId )), itemId );
   666     QCOMPARE( mTestPrivate->iMediaArray->Count(), 0 );
   593     QCOMPARE( mTestPrivate->iMediaArray->Count(), 0 );
   667     
   594 
   668     delete array;
   595     delete array;
   669     mTestPrivate->iMediaArray = 0;
   596     mTestPrivate->iMediaArray = 0;
   670 }
   597 }
   671 
   598 
   672 /*!
   599 /*!
   678     CMPXMedia* item = CMPXMedia::NewL();
   605     CMPXMedia* item = CMPXMedia::NewL();
   679     item->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, itemId );
   606     item->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, itemId );
   680     mTestPrivate->iCachedRemovedItem = item;
   607     mTestPrivate->iCachedRemovedItem = item;
   681     CMPXMediaArray* array = CMPXMediaArray::NewL();
   608     CMPXMediaArray* array = CMPXMediaArray::NewL();
   682     mTestPrivate->iMediaArray = array;
   609     mTestPrivate->iMediaArray = array;
   683     
   610 
   684     mTest->insertCachedItem(0);
   611     mTest->insertCachedItem(0);
   685     QCOMPARE( mTestPrivate->iMediaArray->Count(), 1 );
   612     QCOMPARE( mTestPrivate->iMediaArray->Count(), 1 );
   686     QCOMPARE( int(mTestPrivate->iMediaArray->AtL( 0 )->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId )), itemId );
   613     QCOMPARE( int(mTestPrivate->iMediaArray->AtL( 0 )->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId )), itemId );
   687     QVERIFY( !mTestPrivate->iCachedRemovedItem );
   614     QVERIFY( !mTestPrivate->iCachedRemovedItem );
   688     
   615 
   689     delete array;
   616     delete array;
   690     mTestPrivate->iMediaArray = 0;
   617     mTestPrivate->iMediaArray = 0;
   691 }
   618 }
   692 
   619 
   693 /*!
   620 /*!
   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 }