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; |
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 { |
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 |