mpengine/tsrc/unittest_mpmpxcollectionframeworkwrapper/src/unittest_mpmpxcollectionframeworkwrapper.cpp
changeset 48 af3740e3753f
parent 32 c163ef0b758d
child 51 560ce2306a17
equal deleted inserted replaced
42:79c49924ae23 48:af3740e3753f
    18 #include <QSignalSpy>
    18 #include <QSignalSpy>
    19 
    19 
    20 #include <mpxmedia.h>
    20 #include <mpxmedia.h>
    21 #include <mpxcollectionplaylist.h>
    21 #include <mpxcollectionplaylist.h>
    22 
    22 
       
    23 #include "mpcommondefs.h"
    23 #include "unittest_mpmpxcollectionframeworkwrapper.h"
    24 #include "unittest_mpmpxcollectionframeworkwrapper.h"
    24 #include "stub/inc/mpmpxcollectiondata.h"
    25 #include "stub/inc/mpmpxcollectiondata.h"
    25 #include "stub/inc/mpxcollectionopenutility.h"
    26 #include "stub/inc/mpxcollectionopenutility.h"
    26 #include "stub/inc/mpxcollectionuihelper.h"
    27 #include "stub/inc/mpxcollectionuihelper.h"
    27 #include "stub/inc/mpxcollectionutility.h"
    28 #include "stub/inc/mpxcollectionutility.h"
    28 #include "stub/inc/mpxplaybackutility.h"
    29 #include "stub/inc/mpxplaybackutility.h"
    29 #include "stub/inc/mpmpxisolatedcollectionhelper.h"
    30 #include "stub/inc/mpmpxisolatedcollectionhelper.h"
    30 #include "stub/inc/mpsettingsmanager.h"
    31 #include "stub/inc/mpsettingsmanager.h"
       
    32 #include "stub/inc/mpsongdata.h"
    31 
    33 
    32 // Do this so we can access all member variables.
    34 // Do this so we can access all member variables.
    33 #define private public
    35 #define private public
    34 #include "mpmpxcollectionframeworkwrapper.h"
    36 #include "mpmpxcollectionframeworkwrapper.h"
    35 #include "mpmpxcollectionframeworkwrapper_p.h"
    37 #include "mpmpxcollectionframeworkwrapper_p.h"
    36 #undef private
    38 #undef private
    37 
    39 
    38 //This so we can test private functions
    40 // This so we can test private functions
    39 #include "mpmpxcollectionframeworkwrapper_p.cpp"
    41 #include "mpmpxcollectionframeworkwrapper_p.cpp"
    40 
    42 
    41 //Test data
    43 // Test data
    42 struct TTestAttrs
    44 struct TTestAttrs
    43     {
    45     {
    44     const wchar_t* GeneralTitle;
    46     const wchar_t* GeneralTitle;
    45     const wchar_t* MusicArtist;
    47     const wchar_t* MusicArtist;
    46     const TInt GeneralCount;
    48     const TInt GeneralCount;
    84 
    86 
    85 TestMpMpxCollectionFrameworkWrapper::TestMpMpxCollectionFrameworkWrapper()
    87 TestMpMpxCollectionFrameworkWrapper::TestMpMpxCollectionFrameworkWrapper()
    86     : mTest(0),
    88     : mTest(0),
    87       iMediaTestData(0),
    89       iMediaTestData(0),
    88       iPlaylistsTestData(0),
    90       iPlaylistsTestData(0),
    89       iAlbumsTestData(0)
    91       iAlbumsTestData(0),
       
    92       mSongData(0)
    90 {
    93 {
    91 }
    94 }
    92 
    95 
    93 TestMpMpxCollectionFrameworkWrapper::~TestMpMpxCollectionFrameworkWrapper()
    96 TestMpMpxCollectionFrameworkWrapper::~TestMpMpxCollectionFrameworkWrapper()
    94 {
    97 {
       
    98     delete mSongData;
    95     delete mTest;
    99     delete mTest;
    96 }
   100 }
    97 
   101 
    98 /*!
   102 /*!
    99  Called before the first testfunction is executed.
   103  Called before the first testfunction is executed.
   100  */
   104  */
   101 void TestMpMpxCollectionFrameworkWrapper::initTestCase()
   105 void TestMpMpxCollectionFrameworkWrapper::initTestCase()
   102 {
   106 {
       
   107     mSongData = new MpSongData();
   103 }
   108 }
   104 
   109 
   105 /*!
   110 /*!
   106  Called after the last testfunction was executed.
   111  Called after the last testfunction was executed.
   107  */
   112  */
   112 /*!
   117 /*!
   113  Called before each testfunction is executed.
   118  Called before each testfunction is executed.
   114  */
   119  */
   115 void TestMpMpxCollectionFrameworkWrapper::init()
   120 void TestMpMpxCollectionFrameworkWrapper::init()
   116 {
   121 {
   117     mTest = new MpMpxCollectionFrameworkWrapper();
   122     mTest = new MpMpxCollectionFrameworkWrapper(TUid::Uid(MpCommon::KMusicPlayerUid), mSongData);
   118     mTestPrivate = mTest->d_ptr;
   123     mTestPrivate = mTest->d_ptr;
   119 }
   124 }
   120 
   125 
   121 /*!
   126 /*!
   122  Called after every testfunction.
   127  Called after every testfunction.
   294     QCOMPARE(mTestPrivate->iIsolatedCollectionData->mMediaSet, TBool(EFalse));
   299     QCOMPARE(mTestPrivate->iIsolatedCollectionData->mMediaSet, TBool(EFalse));
   295 
   300 
   296     QCOMPARE(spy.count(), 2);
   301     QCOMPARE(spy.count(), 2);
   297 }
   302 }
   298 
   303 
       
   304 /*!
       
   305  Tests HandleIsolatedOpenRestorePath.
       
   306  */
       
   307 void TestMpMpxCollectionFrameworkWrapper::testHandleIsolatedOpenRestorePath()
       
   308 {
       
   309     QSignalSpy spy(mTest, SIGNAL(restorePathFailed()));
       
   310     CMPXCollectionPath *testPath = CMPXCollectionPath::NewL();
       
   311     mTestPrivate->iIsolatedCollectionHelper = CMpMpxIsolatedCollectionHelper::NewL( mTestPrivate );
       
   312     RArray<TMPXItemId> pathItems;
       
   313     testPath->AppendL(5);
       
   314     for (int i = 0; i < 5; i++ ) {
       
   315         pathItems.AppendL( TMPXItemId( 300 + i ) );
       
   316     }
       
   317     testPath->AppendL( pathItems.Array() );
       
   318     
       
   319     //Restored path item is in the same index
       
   320     mTestPrivate->iRestorePathIndex = 3;
       
   321     mTestPrivate->iRestorePathIndexId = TMPXItemId( 303 );
       
   322     mTestPrivate->HandleIsolatedOpenRestorePathL( *testPath, KErrNone );
       
   323     QCOMPARE(mTestPrivate->iIsolatedCollectionHelper->iOpen,TBool(EFalse));
       
   324     QCOMPARE(spy.count(), 0);
       
   325     
       
   326     //Restored path item is not in same index, go to start of path
       
   327     mTestPrivate->iRestorePathIndex = 2;
       
   328     mTestPrivate->iRestorePathIndexId = TMPXItemId( 303 );
       
   329     mTestPrivate->HandleIsolatedOpenRestorePathL( *testPath, KErrNone );
       
   330     
       
   331     QCOMPARE( mTestPrivate->iRestorePathIndex, 0 );
       
   332     QCOMPARE( mTestPrivate->iIsolatedCollectionHelper->iMode, CMpMpxIsolatedCollectionHelper::RestorePathMode );
       
   333     QCOMPARE(mTestPrivate->iIsolatedCollectionHelper->iOpen,TBool(ETrue));
       
   334     QCOMPARE(spy.count(), 0);
       
   335     
       
   336     //Restored path has no items (MMC removed)
       
   337     testPath->Reset();
       
   338     mTestPrivate->iIsolatedCollectionHelper->iOpen = EFalse;
       
   339     mTestPrivate->HandleIsolatedOpenRestorePathL( *testPath, KErrNone );
       
   340     QCOMPARE( mTestPrivate->iIsolatedCollectionHelper->iMode, CMpMpxIsolatedCollectionHelper::RestorePathMode );
       
   341     QCOMPARE(mTestPrivate->iIsolatedCollectionHelper->iOpen,TBool(ETrue));
       
   342     QCOMPARE(spy.count(), 0);
       
   343   
       
   344     //Restored path has no items, go back to collection view
       
   345     mTestPrivate->iIsolatedCollectionHelper->iOpen = EFalse;
       
   346     mTestPrivate->iIsolatedCollectionHelper->iMode = CMpMpxIsolatedCollectionHelper::DefaultMode;
       
   347     mTestPrivate->iRestoreDefaultPath = true;
       
   348     mTestPrivate->HandleIsolatedOpenRestorePathL( *testPath, KErrNone );
       
   349     QCOMPARE( mTestPrivate->iIsolatedCollectionHelper->iMode, CMpMpxIsolatedCollectionHelper::DefaultMode );
       
   350     QCOMPARE(mTestPrivate->iIsolatedCollectionHelper->iOpen,TBool(EFalse));
       
   351     QCOMPARE(spy.count(), 1);
       
   352     
       
   353     //Restored path not found
       
   354     mTestPrivate->HandleIsolatedOpenRestorePathL( *testPath, KErrNotFound );
       
   355     QCOMPARE( mTestPrivate->iIsolatedCollectionHelper->iMode, CMpMpxIsolatedCollectionHelper::RestorePathMode );
       
   356     QCOMPARE( mTestPrivate->iIsolatedCollectionHelper->iMode, CMpMpxIsolatedCollectionHelper::RestorePathMode );
       
   357     QCOMPARE(mTestPrivate->iIsolatedCollectionHelper->iOpen,TBool(ETrue));
       
   358     QCOMPARE(spy.count(), 1);
       
   359 
       
   360 }
   299 /*!
   361 /*!
   300  Tests openCollection for different contexts.
   362  Tests openCollection for different contexts.
   301  */
   363  */
   302 void TestMpMpxCollectionFrameworkWrapper::testOpenCollection()
   364 void TestMpMpxCollectionFrameworkWrapper::testOpenCollection()
   303 {
   365 {
   750 /*!
   812 /*!
   751  Tests handleCollectionMessage. Part of private implementation.
   813  Tests handleCollectionMessage. Part of private implementation.
   752  */
   814  */
   753 void TestMpMpxCollectionFrameworkWrapper::testHandleCollectionMediaL()
   815 void TestMpMpxCollectionFrameworkWrapper::testHandleCollectionMediaL()
   754 {
   816 {
   755     //HandleCollectionMediaL does nothing, test added just to cover all member functions.
   817     mTestPrivate->HandleCollectionMediaL( *iMediaTestData, KErrNotFound );
   756     mTestPrivate->HandleCollectionMediaL( *iMediaTestData, KErrNone);
   818     QCOMPARE(mTestPrivate->iSongData->iSetMedia, false);
   757     QVERIFY( iMediaTestData );
   819 
       
   820     mTestPrivate->HandleCollectionMediaL( *iMediaTestData, KErrNone );
       
   821     QCOMPARE(mTestPrivate->iSongData->iSetMedia, true);
   758 }
   822 }
   759 
   823 
   760 /*!
   824 /*!
   761  Tests preparePlaylistMedia for track level. Part of private implementation.
   825  Tests preparePlaylistMedia for track level. Part of private implementation.
   762  */
   826  */
  1228     CleanupStack::PopAndDestroy(albumTwoTracksTestData);
  1292     CleanupStack::PopAndDestroy(albumTwoTracksTestData);
  1229     CleanupStack::PopAndDestroy(albumOneTracksTestData);
  1293     CleanupStack::PopAndDestroy(albumOneTracksTestData);
  1230     CleanupStack::Pop(iAlbumsTestData);
  1294     CleanupStack::Pop(iAlbumsTestData);
  1231 }
  1295 }
  1232 
  1296 
       
  1297 /*!
       
  1298  Used to test saving path
       
  1299  */
       
  1300 void TestMpMpxCollectionFrameworkWrapper::testSavePath()
       
  1301 {
       
  1302     mTestPrivate->createPlaybackUtilityL();
       
  1303     //Create testPath
       
  1304     CMPXCollectionPath *testPath = CMPXCollectionPath::NewL();
       
  1305     RArray<TMPXItemId> pathItems;
       
  1306     testPath->AppendL(5);
       
  1307     for (int i = 0; i < 5; i++ ) {
       
  1308         pathItems.AppendL( TMPXItemId( 300 + i ) );
       
  1309     }
       
  1310     CleanupStack::PushL(testPath);
       
  1311     testPath->AppendL( pathItems.Array() );
       
  1312     //Create testPlaylist
       
  1313     CMPXCollectionPlaylist *testPlaylist = CMPXCollectionPlaylist::NewL( *testPath );
       
  1314     mTestPrivate->iPlaybackUtility->iCurrentPlaylist = testPlaylist;
       
  1315     QByteArray serializedRestorePath;
       
  1316     mTest->savePath( serializedRestorePath );
       
  1317     
       
  1318     
       
  1319     //Verify the path is the same
       
  1320     int dataSize = serializedRestorePath.size();
       
  1321     if ( dataSize > 0 ) {
       
  1322         TPtrC8 activityDataDescriptor( reinterpret_cast<const unsigned char*> ( serializedRestorePath.constData() ), serializedRestorePath.size() );
       
  1323          
       
  1324         //Take a copy of the data
       
  1325         CBufFlat* buffer = CBufFlat::NewL( dataSize );
       
  1326         CleanupStack::PushL( buffer );
       
  1327         buffer->InsertL( 0, activityDataDescriptor, dataSize );
       
  1328         
       
  1329         TBufBuf bufBuf;
       
  1330         bufBuf.Set( *buffer, 0, TBufBuf::ERead );
       
  1331         RReadStream readStream( &bufBuf );
       
  1332         readStream.PushL();
       
  1333         
       
  1334         CMPXCollectionPath* cpath( NULL );
       
  1335         cpath = CMPXCollectionPath::NewL(readStream);
       
  1336         CleanupStack::PushL(cpath);
       
  1337         
       
  1338         QCOMPARE( testPath->Levels(), cpath->Levels() );
       
  1339         QCOMPARE( testPath->Count(), cpath->Count() );
       
  1340         QCOMPARE( testPath->Id(), cpath->Id() );
       
  1341         QCOMPARE( testPath->Index(), cpath->Index() );
       
  1342         QCOMPARE( testPath->Items().Count(), cpath->Items().Count() );
       
  1343         for ( int i = 0; i < testPath->Items().Count(); i++ ){
       
  1344             QCOMPARE( testPath->Items()[i], cpath->Items()[i] );
       
  1345         }
       
  1346         
       
  1347         CleanupStack::PopAndDestroy( cpath );
       
  1348         CleanupStack::PopAndDestroy( 2, buffer ); //readStream and buffer
       
  1349     }
       
  1350     CleanupStack::PopAndDestroy( testPath );
       
  1351 }
       
  1352 
       
  1353 /*!
       
  1354  Used to test restoring path
       
  1355  */
       
  1356 void TestMpMpxCollectionFrameworkWrapper::testRestorePath()
       
  1357 {
       
  1358     QByteArray serializedRestorePath;
       
  1359     mTestPrivate->iIsolatedCollectionHelper = CMpMpxIsolatedCollectionHelper::NewL( mTestPrivate );
       
  1360     //No path was saved
       
  1361     mTest->restorePath( serializedRestorePath );
       
  1362     QCOMPARE( mTestPrivate->iIsolatedCollectionHelper->iMode, CMpMpxIsolatedCollectionHelper::DefaultMode );
       
  1363     QCOMPARE(mTestPrivate->iIsolatedCollectionHelper->iOpen,TBool(EFalse));
       
  1364     
       
  1365     //Create testPath and serialize it
       
  1366     mTestPrivate->createPlaybackUtilityL();
       
  1367     CMPXCollectionPath *testPath = CMPXCollectionPath::NewL();
       
  1368     RArray<TMPXItemId> pathItems;
       
  1369     testPath->AppendL(5);
       
  1370     for (int i = 0; i < 5; i++ ) {
       
  1371         pathItems.AppendL( TMPXItemId( 300 + i ) );
       
  1372     }
       
  1373     CleanupStack::PushL(testPath);
       
  1374     testPath->AppendL( pathItems.Array() );
       
  1375     //Create testPlaylist
       
  1376     CMPXCollectionPlaylist *testPlaylist = CMPXCollectionPlaylist::NewL( *testPath );
       
  1377     mTestPrivate->iPlaybackUtility->iCurrentPlaylist = testPlaylist;
       
  1378     mTest->savePath( serializedRestorePath );
       
  1379     
       
  1380     //Restore path sent to be opened
       
  1381     mTest->restorePath( serializedRestorePath );
       
  1382     QCOMPARE( mTestPrivate->iIsolatedCollectionHelper->iMode, CMpMpxIsolatedCollectionHelper::RestorePathMode );
       
  1383     QCOMPARE(mTestPrivate->iIsolatedCollectionHelper->iOpen,TBool(ETrue));
       
  1384     
       
  1385     CleanupStack::PopAndDestroy( testPath );
       
  1386 }
       
  1387 
       
  1388 /*!
       
  1389  Used to test song details retrieval
       
  1390  */
       
  1391 void TestMpMpxCollectionFrameworkWrapper::testRetrieveSongDetails()
       
  1392 {
       
  1393     // Retrieve details for track
       
  1394     loadTestData();
       
  1395     mTestPrivate->iCollectionData->setMpxMedia(*iMediaTestData);
       
  1396 
       
  1397     mTest->retrieveSongDetails(1);
       
  1398     QVERIFY(mTestPrivate->iCollectionUtility != 0);
       
  1399     QCOMPARE(mTestPrivate->iCollectionUtility->iMedia, TBool(ETrue));
       
  1400 
       
  1401     // Retrieve details for track in TBone list
       
  1402     cleanup();
       
  1403     init();
       
  1404     loadAlbumsTestData();
       
  1405     mTestPrivate->iCollectionData->setMpxMedia(*iAlbumsTestData);
       
  1406     mTestPrivate->iCollectionData->mContext = ECollectionContextAlbumsTBone;
       
  1407     mTestPrivate->iCollectionData->mCurrentAlbumIndex = 1;
       
  1408 
       
  1409     mTest->retrieveSongDetails(1);
       
  1410     QVERIFY(mTestPrivate->iCollectionUtility != 0);
       
  1411     QCOMPARE(mTestPrivate->iCollectionUtility->iMedia, TBool(ETrue));
       
  1412 }
       
  1413 
  1233 //end of file
  1414 //end of file