1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Unit test for mpmpxframeworkwrapper |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QSignalSpy> |
|
19 #include <hbapplication.h> |
|
20 #include <hbmainwindow.h> |
|
21 |
|
22 #include <mpxmedia.h> |
|
23 #include <mpxcollectionplaylist.h> |
|
24 |
|
25 #include "unittest_mpmpxframeworkwrapper.h" |
|
26 #include "stub/inc/mpmpxcollectiondata.h" |
|
27 #include "stub/inc/mpxcollectionopenutility.h" |
|
28 #include "stub/inc/mpxcollectionuihelper.h" |
|
29 #include "stub/inc/mpxcollectionutility.h" |
|
30 #include "stub/inc/mpxplaybackutility.h" |
|
31 #include "stub/inc/mpxharvesterutility.h" |
|
32 #include "stub/inc/mpmpxisolatedcollectionhelper.h" |
|
33 #include "mpsettingsmanager.h" |
|
34 |
|
35 // Do this so we can access all member variables. |
|
36 #define private public |
|
37 #include "mpmpxframeworkwrapper.h" |
|
38 #include "mpmpxframeworkwrapper_p.h" |
|
39 #undef private |
|
40 |
|
41 //This so we can test private functions |
|
42 #include "mpmpxframeworkwrapper_p.cpp" |
|
43 |
|
44 //Test data |
|
45 struct TTestAttrs |
|
46 { |
|
47 const wchar_t* GeneralTitle; |
|
48 const wchar_t* MusicArtist; |
|
49 const TInt GeneralCount; |
|
50 const wchar_t* MusicAlbumArtFileName; |
|
51 }; |
|
52 |
|
53 const TTestAttrs KAllSongsTestData[] = |
|
54 { |
|
55 { L"Title 1", L"Artist 1", 1, L"e:\\data\\images\\art1.jpg" } |
|
56 ,{ L"Title 2", L"Artist 2", 1, L"e:\\data\\images\\art2.jpg" } |
|
57 ,{ L"Title 3", L"Artist 3", 1, L"e:\\data\\images\\art3.jpg" } |
|
58 ,{ L"Title 4", L"Artist 4", 1, L"e:\\data\\images\\art4.jpg" } |
|
59 ,{ L"Title 5", L"Artist 5", 1, L"e:\\data\\images\\art5.jpg" } |
|
60 ,{ L"Title 6", L"Artist 6", 1, L"e:\\data\\images\\art6.jpg" } |
|
61 ,{ L"Title 7", L"Artist 7", 1, L"e:\\data\\images\\art7.jpg" } |
|
62 ,{ L"Title 8", L"Artist 8", 1, L"e:\\data\\images\\art8.jpg" } |
|
63 ,{ L"Title 9", L"Artist 9", 1, L"e:\\data\\images\\art9.jpg" } |
|
64 ,{ L"Title 10", L"Artist 10", 1, L"e:\\data\\images\\art10.jpg" } |
|
65 }; |
|
66 |
|
67 /*! |
|
68 Make our test case a stand-alone executable that runs all the test functions. |
|
69 */ |
|
70 int main(int argc, char *argv[]) |
|
71 { |
|
72 HbApplication app(argc, argv); |
|
73 HbMainWindow window; |
|
74 |
|
75 TestMpMpxFrameworkWrapper tv; |
|
76 |
|
77 char *pass[3]; |
|
78 pass[0] = argv[0]; |
|
79 pass[1] = "-o"; |
|
80 pass[2] = "c:\\data\\unittest_mpmpxframeworkwrapper.txt"; |
|
81 |
|
82 int res = QTest::qExec(&tv, 3, pass); |
|
83 |
|
84 return res; |
|
85 } |
|
86 |
|
87 TestMpMpxFrameworkWrapper::TestMpMpxFrameworkWrapper() |
|
88 : mTest(0), |
|
89 iMediaTestData(0), |
|
90 iPlaylistsTestData(0) |
|
91 { |
|
92 } |
|
93 |
|
94 TestMpMpxFrameworkWrapper::~TestMpMpxFrameworkWrapper() |
|
95 { |
|
96 delete mTest; |
|
97 } |
|
98 |
|
99 /*! |
|
100 Called before the first testfunction is executed. |
|
101 */ |
|
102 void TestMpMpxFrameworkWrapper::initTestCase() |
|
103 { |
|
104 } |
|
105 |
|
106 /*! |
|
107 Called after the last testfunction was executed. |
|
108 */ |
|
109 void TestMpMpxFrameworkWrapper::cleanupTestCase() |
|
110 { |
|
111 } |
|
112 |
|
113 /*! |
|
114 Called before each testfunction is executed. |
|
115 */ |
|
116 void TestMpMpxFrameworkWrapper::init() |
|
117 { |
|
118 mTest = new MpMpxFrameworkWrapper(); |
|
119 mTestPrivate = mTest->d_ptr; |
|
120 } |
|
121 |
|
122 /*! |
|
123 Called after every testfunction. |
|
124 */ |
|
125 void TestMpMpxFrameworkWrapper::cleanup() |
|
126 { |
|
127 delete mTest; |
|
128 mTest = 0; |
|
129 } |
|
130 |
|
131 /*! |
|
132 Tests constructor. |
|
133 */ |
|
134 void TestMpMpxFrameworkWrapper::testConstructor() |
|
135 { |
|
136 QVERIFY(mTestPrivate->iCollectionUtility != 0); |
|
137 QVERIFY(mTestPrivate->iCollectionUiHelper != 0); |
|
138 QVERIFY(mTestPrivate->iIncrementalOpenUtil != 0); |
|
139 QVERIFY(mTestPrivate->iCollectionData != 0); |
|
140 QVERIFY(mTestPrivate->iHarvesterUtility != 0); |
|
141 QCOMPARE(mTestPrivate->iHarvesterUtility->iCheckSystemEvents,TBool(ETrue)); |
|
142 } |
|
143 |
|
144 /*! |
|
145 Tests collectionData |
|
146 */ |
|
147 void TestMpMpxFrameworkWrapper::testReleaseIsolatedCollection() |
|
148 { |
|
149 mTestPrivate->iIsolatedCollectionHelper = CMpMpxIsolatedCollectionHelper::NewL( mTestPrivate ); |
|
150 mTestPrivate->iIsolatedCollectionData = new MpMpxCollectionData(); |
|
151 mTest->releaseIsolatedCollection(); |
|
152 QVERIFY(mTestPrivate->iIsolatedCollectionHelper == 0); |
|
153 QVERIFY(mTestPrivate->iIsolatedCollectionData == 0); |
|
154 } |
|
155 |
|
156 /*! |
|
157 Tests collectionData |
|
158 */ |
|
159 void TestMpMpxFrameworkWrapper::testCollectionData() |
|
160 { |
|
161 loadTestData(); |
|
162 mTestPrivate->iCollectionData->setMpxMedia(*iMediaTestData); |
|
163 MpMpxCollectionData *collectionData = mTest->collectionData(); |
|
164 QCOMPARE(collectionData->mContainerMedia->ValueTObjectL<TInt>(KMPXMediaArrayCount),iMediaTestData->ValueTObjectL<TInt>(KMPXMediaArrayCount)); |
|
165 } |
|
166 |
|
167 /*! |
|
168 Tests handleOpen when given entries. Part of private implementation. |
|
169 */ |
|
170 void TestMpMpxFrameworkWrapper::testHandleOpenEntries() |
|
171 { |
|
172 CMPXMedia* media = CMPXMedia::NewL(); |
|
173 |
|
174 //Called with some error |
|
175 mTestPrivate->HandleOpenL(*media, 0, EFalse, KErrNotFound); |
|
176 QCOMPARE(mTestPrivate->iCollectionData->mMediaSet, TBool(EFalse)); |
|
177 QCOMPARE(mTestPrivate->iCollectionUtility->iOpen, TBool(EFalse)); |
|
178 |
|
179 |
|
180 //Called without error |
|
181 mTestPrivate->iFirstIncrementalOpen = EFalse; |
|
182 mTestPrivate->HandleOpenL(*media, 0, EFalse, KErrNone); |
|
183 QCOMPARE(mTestPrivate->iCollectionData->mMediaSet, TBool(EFalse)); |
|
184 QCOMPARE(mTestPrivate->iCollectionUtility->iOpen, TBool(EFalse)); |
|
185 |
|
186 //Called without error |
|
187 mTestPrivate->iFirstIncrementalOpen = ETrue; |
|
188 mTestPrivate->HandleOpenL(*media, 0, EFalse, KErrNone); |
|
189 QCOMPARE(mTestPrivate->iCollectionData->mMediaSet, TBool(ETrue)); |
|
190 QCOMPARE(mTestPrivate->iCollectionUtility->iOpen, TBool(EFalse)); |
|
191 QCOMPARE(mTestPrivate->iFirstIncrementalOpen, TBool(EFalse)); |
|
192 } |
|
193 |
|
194 /*! |
|
195 Tests handleOpen when given a playlist. Part of private implementation. |
|
196 */ |
|
197 void TestMpMpxFrameworkWrapper::testHandleOpenPlaylist() |
|
198 { |
|
199 CMPXCollectionPlaylist* playlist = CMPXCollectionPlaylist::NewL(); |
|
200 CMPXMedia* media = CMPXMedia::NewL(); |
|
201 |
|
202 //Called with some error |
|
203 QSignalSpy spy(mTest, SIGNAL(collectionPlaylistOpened())); |
|
204 mTestPrivate->HandleOpenL(*playlist, KErrNotFound); |
|
205 QCOMPARE(spy.count(), 0); |
|
206 QVERIFY(mTestPrivate->iPlaybackUtility == 0); |
|
207 |
|
208 //Called without error |
|
209 QSignalSpy spy2( MpSettingsManager::instance(),SIGNAL(shuffleChanged(bool))); |
|
210 MpSettingsManager::setRepeat(false); |
|
211 MpSettingsManager::setShuffle(false); |
|
212 if(waitForSignal(&spy2, 1000)){ |
|
213 bool shuffle = MpSettingsManager::shuffle(); |
|
214 TX_LOG_ARGS("shuffle changed to "<< shuffle); |
|
215 bool repeat = MpSettingsManager::repeat(); |
|
216 TX_LOG_ARGS("repeat changed to "<< repeat); |
|
217 } |
|
218 mTestPrivate->HandleOpenL(*playlist, KErrNone); |
|
219 QCOMPARE(spy.count(), 1); |
|
220 QVERIFY(mTestPrivate->iPlaybackUtility != 0); |
|
221 QCOMPARE(mTestPrivate->iPlaybackUtility->iPlay, TBool(ETrue)); |
|
222 QCOMPARE(mTestPrivate->iPlaybackUtility->iShuffle, 0); |
|
223 QCOMPARE(mTestPrivate->iPlaybackUtility->iRepeat, TInt(EPbRepeatOff)); |
|
224 |
|
225 cleanup(); |
|
226 init(); |
|
227 QSignalSpy spy3(mTest, SIGNAL(collectionPlaylistOpened())); |
|
228 |
|
229 //Called without error |
|
230 spy2.clear(); |
|
231 MpSettingsManager::setRepeat(true); |
|
232 MpSettingsManager::setShuffle(true); |
|
233 |
|
234 if(waitForSignal(&spy2, 1000)){ |
|
235 bool shuffle = MpSettingsManager::shuffle(); |
|
236 TX_LOG_ARGS("shuffle2 changed to "<< shuffle); |
|
237 bool repeat = MpSettingsManager::repeat(); |
|
238 TX_LOG_ARGS("repeat2 changed to "<< repeat); |
|
239 } |
|
240 |
|
241 mTestPrivate->HandleOpenL(*playlist, KErrNone); |
|
242 QCOMPARE(spy3.count(), 1); |
|
243 QVERIFY(mTestPrivate->iPlaybackUtility != 0); |
|
244 QCOMPARE(mTestPrivate->iPlaybackUtility->iPlay, TBool(ETrue)); |
|
245 QCOMPARE(mTestPrivate->iPlaybackUtility->iRepeat, TInt(EPbRepeatAll)); |
|
246 QCOMPARE(mTestPrivate->iPlaybackUtility->iShuffle, 1); |
|
247 |
|
248 //Called without error |
|
249 spy3.clear(); |
|
250 mTestPrivate->HandleOpenL(*playlist, KErrNone); |
|
251 QCOMPARE(spy3.count(), 1); |
|
252 QVERIFY(mTestPrivate->iPlaybackUtility != 0); |
|
253 QCOMPARE(mTestPrivate->iPlaybackUtility->iPlay, TBool(ETrue)); |
|
254 } |
|
255 |
|
256 /*! |
|
257 Tests handleOperationComplete. Part of private implementation. |
|
258 */ |
|
259 void TestMpMpxFrameworkWrapper::testHandleOperationComplete() |
|
260 { |
|
261 void* temp; |
|
262 temp=0; |
|
263 QSignalSpy spy(mTest, SIGNAL(songsDeleted(bool))); |
|
264 mTestPrivate->HandleOperationCompleteL(EDeleteOp, KErrNone, temp); |
|
265 mTestPrivate->HandleOperationCompleteL(EDeleteOp, KErrNotFound, temp); |
|
266 QCOMPARE(spy.count(), 2); |
|
267 bool result = qvariant_cast<bool>(spy.at(0).at(0)); |
|
268 QCOMPARE(result, true); |
|
269 result = qvariant_cast<bool>(spy.at(1).at(0)); |
|
270 QCOMPARE(result, false); |
|
271 |
|
272 QSignalSpy spy2(mTest, SIGNAL(playlistSaved(bool))); |
|
273 mTestPrivate->HandleOperationCompleteL(EAddOp, KErrNone, temp); |
|
274 mTestPrivate->HandleOperationCompleteL(EAddOp, KErrNotFound, temp); |
|
275 QCOMPARE(spy2.count(), 2); |
|
276 result = qvariant_cast<bool>(spy2.at(0).at(0)); |
|
277 QCOMPARE(result, true); |
|
278 result = qvariant_cast<bool>(spy2.at(1).at(0)); |
|
279 QCOMPARE(result, false); |
|
280 |
|
281 QSignalSpy spy3(mTest, SIGNAL(playlistsRenamed(bool))); |
|
282 mTestPrivate->HandleOperationCompleteL(ERenameOp, KErrNone, temp); |
|
283 mTestPrivate->HandleOperationCompleteL(ERenameOp, KErrNotFound, temp); |
|
284 QCOMPARE(spy3.count(), 2); |
|
285 result = qvariant_cast<bool>(spy2.at(0).at(0)); |
|
286 QCOMPARE(result, true); |
|
287 result = qvariant_cast<bool>(spy2.at(1).at(0)); |
|
288 QCOMPARE(result, false); |
|
289 } |
|
290 |
|
291 /*! |
|
292 Tests HandleIsolatedOpen. |
|
293 */ |
|
294 void TestMpMpxFrameworkWrapper::testHandleIsolatedOpen() |
|
295 { |
|
296 loadTestData(); |
|
297 QSignalSpy spy(mTest, SIGNAL(isolatedCollectionOpened(MpMpxCollectionData*))); |
|
298 |
|
299 mTestPrivate->iIsolatedCollectionData = 0; |
|
300 mTestPrivate->HandleIsolatedOpenL( *iMediaTestData, KErrNone ) ; |
|
301 QCOMPARE(mTestPrivate->iIsolatedCollectionData->mMediaSet, TBool(ETrue)); |
|
302 delete mTestPrivate->iIsolatedCollectionData; |
|
303 |
|
304 mTestPrivate->iIsolatedCollectionData = new MpMpxCollectionData(); |
|
305 mTestPrivate->HandleIsolatedOpenL( *iMediaTestData, KErrNone ) ; |
|
306 QCOMPARE(mTestPrivate->iIsolatedCollectionData->mMediaSet, TBool(ETrue)); |
|
307 delete mTestPrivate->iIsolatedCollectionData; |
|
308 |
|
309 mTestPrivate->iIsolatedCollectionData = new MpMpxCollectionData(); |
|
310 mTestPrivate->HandleIsolatedOpenL( *iMediaTestData, KErrNotFound ) ; |
|
311 QCOMPARE(mTestPrivate->iIsolatedCollectionData->mMediaSet, TBool(EFalse)); |
|
312 |
|
313 QCOMPARE(spy.count(), 2); |
|
314 } |
|
315 |
|
316 /*! |
|
317 Tests openCollection for different contexts. |
|
318 */ |
|
319 void TestMpMpxFrameworkWrapper::testOpenCollection() |
|
320 { |
|
321 |
|
322 mTest->openCollection(ECollectionContextAllSongs); |
|
323 QCOMPARE(mTestPrivate->iCollectionUtility->iOpen,TBool(ETrue)); |
|
324 QCOMPARE(mTestPrivate->iCollectionUtility->iCountPath, 6); |
|
325 QCOMPARE(mTestPrivate->iCollectionUtility->iOpenCount, 1); |
|
326 cleanup(); |
|
327 init(); |
|
328 mTest->openCollection(ECollectionContextAlbums); |
|
329 QCOMPARE(mTestPrivate->iCollectionUtility->iOpen,TBool(ETrue)); |
|
330 QCOMPARE(mTestPrivate->iCollectionUtility->iCountPath, 1); |
|
331 QCOMPARE(mTestPrivate->iCollectionUtility->iOpenCount, 1); |
|
332 cleanup(); |
|
333 init(); |
|
334 mTest->openCollection(ECollectionContextPlaylists); |
|
335 QCOMPARE(mTestPrivate->iCollectionUtility->iOpen,TBool(ETrue)); |
|
336 QCOMPARE(mTestPrivate->iCollectionUtility->iCountPath, 4); |
|
337 QCOMPARE(mTestPrivate->iCollectionUtility->iOpenCount, 1); |
|
338 cleanup(); |
|
339 init(); |
|
340 mTest->openCollection(ECollectionContextGenres); |
|
341 QCOMPARE(mTestPrivate->iCollectionUtility->iOpen,TBool(ETrue)); |
|
342 QCOMPARE(mTestPrivate->iCollectionUtility->iCountPath, 1); |
|
343 QCOMPARE(mTestPrivate->iCollectionUtility->iOpenCount, 1); |
|
344 cleanup(); |
|
345 init(); |
|
346 mTest->openCollection(ECollectionContextUnknown); |
|
347 QCOMPARE(mTestPrivate->iCollectionUtility->iOpen,TBool(EFalse)); |
|
348 QCOMPARE(mTestPrivate->iCollectionUtility->iOpenCount, 0); |
|
349 |
|
350 } |
|
351 |
|
352 /*! |
|
353 Tests doIncrementalOpen. Part of private implementation. |
|
354 */ |
|
355 void TestMpMpxFrameworkWrapper::testDoIncrementalOpen() |
|
356 { |
|
357 mTestPrivate->DoIncrementalOpenL(); |
|
358 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iDelay, KIncrementalDelayHalfSecond); |
|
359 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iStop,TBool(ETrue)); |
|
360 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iStart,TBool(ETrue)); |
|
361 QCOMPARE(mTestPrivate->iFirstIncrementalOpen,TBool(ETrue)); |
|
362 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iDirection,CMPXCollectionOpenUtility::EFetchNormal); |
|
363 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iChunkSize, KIncrementalFetchBlockSize); |
|
364 } |
|
365 |
|
366 /*! |
|
367 Tests reopenCollection. |
|
368 */ |
|
369 void TestMpMpxFrameworkWrapper::testReopenCollection() |
|
370 { |
|
371 mTest->reopenCollection(); |
|
372 QCOMPARE(mTestPrivate->iCollectionUtility->iOpen,TBool(ETrue)); |
|
373 } |
|
374 |
|
375 /*! |
|
376 Tests openCollection for a specific item. |
|
377 */ |
|
378 void TestMpMpxFrameworkWrapper::testOpenCollectionItem() |
|
379 { |
|
380 for(int index=0; index<10; index++){ |
|
381 mTest->openCollectionItem(index); |
|
382 QCOMPARE(mTestPrivate->iCollectionUtility->iOpen,TBool(ETrue)); |
|
383 QCOMPARE(mTestPrivate->iCollectionUtility->iIndex,index); |
|
384 } |
|
385 } |
|
386 |
|
387 /*! |
|
388 Tests goBack. |
|
389 */ |
|
390 void TestMpMpxFrameworkWrapper::testGoBack() |
|
391 { |
|
392 mTest->back(); |
|
393 QCOMPARE(mTestPrivate->iCollectionUtility->iBack, TBool(ETrue)); |
|
394 } |
|
395 |
|
396 /*! |
|
397 Tests findPlaylists. |
|
398 */ |
|
399 void TestMpMpxFrameworkWrapper::testFindPlaylists() |
|
400 { |
|
401 QStringList testList; |
|
402 loadPlaylists(); |
|
403 mTestPrivate->iCollectionUtility->setPlaylists(*iPlaylistsTestData); |
|
404 mTest->findPlaylists(testList); |
|
405 TInt count = iPlaylistsTestData->ValueTObjectL<TInt>(KMPXMediaArrayCount); |
|
406 QCOMPARE(count,testList.count()); |
|
407 for(TInt i=0; i < count; i++){ |
|
408 const TDesC& title = TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[i].GeneralTitle)); |
|
409 QCOMPARE(testList.at(i),QString::fromUtf16( title.Ptr(), title.Length() )); |
|
410 } |
|
411 } |
|
412 |
|
413 /*! |
|
414 Tests createPlaylist. |
|
415 */ |
|
416 void TestMpMpxFrameworkWrapper::testCreatePlaylist() |
|
417 { |
|
418 QList<int> selection; |
|
419 selection.append(1); |
|
420 selection.append(3); |
|
421 selection.append(5); |
|
422 QString playListName("playlistname"); |
|
423 loadTestData(); |
|
424 mTestPrivate->iCollectionData->setMpxMedia(*iMediaTestData); |
|
425 mTest->createPlaylist(playListName,selection); |
|
426 QCOMPARE(mTestPrivate->iCollectionUiHelper->iIncAdd, TBool(ETrue)); |
|
427 CMPXMedia* testTracks = mTestPrivate->iCollectionUiHelper->iMedia; |
|
428 QCOMPARE(testTracks->ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType),EMPXItem); |
|
429 QCOMPARE(testTracks->ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory),EMPXPlaylist); |
|
430 const TDesC& playlistTitle = TPtrC(reinterpret_cast<const TText*>(playListName.constData())); |
|
431 const TDesC& playlistPath = TPtrC(KPlaylistPath); |
|
432 QCOMPARE(testTracks->ValueText(KMPXMediaGeneralTitle),playlistTitle); |
|
433 QCOMPARE(testTracks->ValueText(KMPXMediaGeneralUri), playlistPath); |
|
434 TInt count = testTracks->ValueTObjectL<TInt>(KMPXMediaArrayCount); |
|
435 QCOMPARE(count, selection.count()); |
|
436 CMPXMediaArray* testArray = testTracks->Value<CMPXMediaArray>( KMPXMediaArrayContents ); |
|
437 for( TInt i = 0; i < count; i++ ){ |
|
438 CMPXMedia* track( testArray->AtL(i) ); |
|
439 const TDesC& title = TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[(2*i)+1].GeneralTitle)); |
|
440 QCOMPARE(track->ValueText( KMPXMediaGeneralTitle ), title); |
|
441 QCOMPARE(track->ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType),EMPXItem); |
|
442 QCOMPARE(track->ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory),EMPXSong); |
|
443 } |
|
444 } |
|
445 |
|
446 /*! |
|
447 Tests createPlaylist with a provided collection data. |
|
448 */ |
|
449 void TestMpMpxFrameworkWrapper::testCreatePlaylistWithProvidedCollectionData() |
|
450 { |
|
451 QList<int> selection; |
|
452 selection.append(1); |
|
453 selection.append(3); |
|
454 selection.append(5); |
|
455 QString playListName("playlistname"); |
|
456 loadTestData(); |
|
457 |
|
458 //test with a collection data different that the browsing collection. |
|
459 MpMpxCollectionData *collectionData; |
|
460 collectionData = new MpMpxCollectionData(); |
|
461 collectionData->setMpxMedia(*iMediaTestData); |
|
462 mTest->createPlaylist(playListName,selection, collectionData); |
|
463 delete collectionData; |
|
464 QCOMPARE(mTestPrivate->iCollectionUiHelper->iIncAdd, TBool(ETrue)); |
|
465 CMPXMedia* testTracks = mTestPrivate->iCollectionUiHelper->iMedia; |
|
466 QCOMPARE(testTracks->ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType),EMPXItem); |
|
467 QCOMPARE(testTracks->ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory),EMPXPlaylist); |
|
468 const TDesC& playlistTitle = TPtrC(reinterpret_cast<const TText*>(playListName.constData())); |
|
469 const TDesC& playlistPath = TPtrC(KPlaylistPath); |
|
470 QCOMPARE(testTracks->ValueText(KMPXMediaGeneralTitle),playlistTitle); |
|
471 QCOMPARE(testTracks->ValueText(KMPXMediaGeneralUri), playlistPath); |
|
472 TInt count = testTracks->ValueTObjectL<TInt>(KMPXMediaArrayCount); |
|
473 QCOMPARE(count, selection.count()); |
|
474 CMPXMediaArray* testArray = testTracks->Value<CMPXMediaArray>( KMPXMediaArrayContents ); |
|
475 for( TInt i = 0; i < count; i++ ){ |
|
476 CMPXMedia* track( testArray->AtL(i) ); |
|
477 const TDesC& title = TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[(2*i)+1].GeneralTitle)); |
|
478 QCOMPARE(track->ValueText( KMPXMediaGeneralTitle ), title); |
|
479 QCOMPARE(track->ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType),EMPXItem); |
|
480 QCOMPARE(track->ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory),EMPXSong); |
|
481 } |
|
482 } |
|
483 |
|
484 /*! |
|
485 Tests saveToPlaylist. |
|
486 */ |
|
487 void TestMpMpxFrameworkWrapper::testSaveToPlaylist() |
|
488 { |
|
489 QList<int> selection; |
|
490 selection.append(1); |
|
491 selection.append(3); |
|
492 selection.append(5); |
|
493 loadTestData(); |
|
494 mTestPrivate->iCollectionData->setMpxMedia(*iMediaTestData); |
|
495 loadPlaylists(); |
|
496 mTestPrivate->iUserPlaylists = CMPXMedia::NewL(*iPlaylistsTestData); |
|
497 TInt countPlaylist = iPlaylistsTestData->ValueTObjectL<TInt>(KMPXMediaArrayCount); |
|
498 for( TInt j = 0; j < countPlaylist; j++){ |
|
499 mTest->saveToPlaylist(j,selection); |
|
500 QCOMPARE(mTestPrivate->iCollectionUiHelper->iIncAdd, TBool(ETrue)); |
|
501 CMPXMedia* testTracks = mTestPrivate->iCollectionUiHelper->iMedia; |
|
502 QCOMPARE(testTracks->ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType),EMPXItem); |
|
503 QCOMPARE(testTracks->ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory),EMPXPlaylist); |
|
504 QCOMPARE(testTracks->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId),TMPXItemId(j)); |
|
505 |
|
506 QCOMPARE(testTracks->ValueTObjectL<TUid>( KMPXMediaGeneralCollectionId),TUid::Uid(EMPXCollectionPluginMusic)); |
|
507 TInt count = testTracks->ValueTObjectL<TInt>(KMPXMediaArrayCount); |
|
508 QCOMPARE(count, selection.count()); |
|
509 CMPXMediaArray* testArray = testTracks->Value<CMPXMediaArray>( KMPXMediaArrayContents ); |
|
510 for( TInt i = 0; i < count; i++ ){ |
|
511 CMPXMedia* track( testArray->AtL(i) ); |
|
512 const TDesC& title = TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[(2*i)+1].GeneralTitle)); |
|
513 QCOMPARE(track->ValueText( KMPXMediaGeneralTitle ), title); |
|
514 QCOMPARE(track->ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType),EMPXItem); |
|
515 QCOMPARE(track->ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory),EMPXSong); |
|
516 } |
|
517 } |
|
518 } |
|
519 |
|
520 /*! |
|
521 Tests SaveToCurrentPlaylist. |
|
522 */ |
|
523 void TestMpMpxFrameworkWrapper::testSaveToCurrentPlaylist() |
|
524 { |
|
525 QList<int> selection; |
|
526 selection.append(1); |
|
527 selection.append(3); |
|
528 selection.append(5); |
|
529 loadTestData(); |
|
530 |
|
531 MpMpxCollectionData *testCollectionData = new MpMpxCollectionData(); |
|
532 testCollectionData->setMpxMedia(*iMediaTestData); |
|
533 |
|
534 //Reusing the same data, just setting some parameters to make it look like playlist tracks. |
|
535 iMediaTestData->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId,TMPXItemId(1234)); |
|
536 iMediaTestData->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem); |
|
537 iMediaTestData->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXPlaylist); |
|
538 mTestPrivate->iCollectionData->setMpxMedia(*iMediaTestData); |
|
539 mTest->saveToCurrentPlaylist( selection, testCollectionData ); |
|
540 |
|
541 QCOMPARE(mTestPrivate->iCollectionUiHelper->iIncAdd, TBool(ETrue)); |
|
542 CMPXMedia* testTracks = mTestPrivate->iCollectionUiHelper->iMedia; |
|
543 QCOMPARE(testTracks->ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType),EMPXItem); |
|
544 QCOMPARE(testTracks->ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory),EMPXPlaylist); |
|
545 QCOMPARE(testTracks->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId),TMPXItemId(1234)); |
|
546 |
|
547 QCOMPARE(testTracks->ValueTObjectL<TUid>( KMPXMediaGeneralCollectionId),TUid::Uid(EMPXCollectionPluginMusic)); |
|
548 TInt count = testTracks->ValueTObjectL<TInt>(KMPXMediaArrayCount); |
|
549 QCOMPARE(count, selection.count()); |
|
550 CMPXMediaArray* testArray = testTracks->Value<CMPXMediaArray>( KMPXMediaArrayContents ); |
|
551 for( TInt i = 0; i < count; i++ ){ |
|
552 CMPXMedia* track( testArray->AtL(i) ); |
|
553 const TDesC& title = TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[(2*i)+1].GeneralTitle)); |
|
554 QCOMPARE(track->ValueText( KMPXMediaGeneralTitle ), title); |
|
555 QCOMPARE(track->ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType),EMPXItem); |
|
556 QCOMPARE(track->ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory),EMPXSong); |
|
557 } |
|
558 |
|
559 } |
|
560 |
|
561 /*! |
|
562 Tests renamePlaylist. |
|
563 */ |
|
564 void TestMpMpxFrameworkWrapper::testRenamePlaylist() |
|
565 { |
|
566 |
|
567 loadPlaylists(); |
|
568 mTestPrivate->iCollectionData->setMpxMedia(*iPlaylistsTestData); |
|
569 QString newPlaylistName("New Playlist Name"); |
|
570 mTest->renamePlaylist(newPlaylistName,3); |
|
571 QCOMPARE(mTestPrivate->iCollectionUiHelper->iValidRename, TBool(ETrue)); |
|
572 CMPXMediaArray *mediaArray; |
|
573 mediaArray = const_cast<CMPXMediaArray*>(iPlaylistsTestData->Value<CMPXMediaArray>( KMPXMediaArrayContents ) ); |
|
574 CMPXMedia* currentPlaylistMedia( mediaArray->AtL( 3 ) ); |
|
575 QCOMPARE(mTestPrivate->iCollectionUiHelper->iPlaylistId, currentPlaylistMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId )); |
|
576 QCOMPARE(mTestPrivate->iCollectionUiHelper->iRenameTitle, newPlaylistName); |
|
577 |
|
578 loadTestData(); |
|
579 mTestPrivate->iCollectionData->setMpxMedia(*iMediaTestData); |
|
580 QString newPlaylistName2("New Playlist Name 2"); |
|
581 mTest->renamePlaylist(newPlaylistName2); |
|
582 QCOMPARE(mTestPrivate->iCollectionUiHelper->iValidRename, TBool(ETrue)); |
|
583 QCOMPARE(mTestPrivate->iCollectionUiHelper->iRenameTitle, newPlaylistName2); |
|
584 QCOMPARE(mTestPrivate->iCollectionUiHelper->iPlaylistId, TMPXItemId(1)); |
|
585 } |
|
586 |
|
587 /*! |
|
588 Tests deleteSongs. |
|
589 */ |
|
590 void TestMpMpxFrameworkWrapper::testDeleteSongs() |
|
591 { |
|
592 QList<int> selection; |
|
593 selection.append(1); |
|
594 selection.append(3); |
|
595 selection.append(5); |
|
596 mTest->deleteSongs(selection); |
|
597 QCOMPARE(mTestPrivate->iCollectionUiHelper->iDelete, TBool(ETrue)); |
|
598 } |
|
599 |
|
600 /*! |
|
601 Tests setShuffle. |
|
602 */ |
|
603 void TestMpMpxFrameworkWrapper::testSetShuffle() |
|
604 { |
|
605 |
|
606 mTest->setShuffle(true); |
|
607 QVERIFY(mTestPrivate->iPlaybackUtility == 0); |
|
608 mTestPrivate->iPlaybackUtility = MMPXPlaybackUtility::UtilityL( TUid::Uid(MpCommon::KMusicPlayerUid) ); |
|
609 mTest->setShuffle(true); |
|
610 QCOMPARE(mTestPrivate->iPlaybackUtility->iShuffle, 1); |
|
611 mTest->setShuffle(false); |
|
612 QCOMPARE(mTestPrivate->iPlaybackUtility->iShuffle, 0); |
|
613 cleanup(); |
|
614 init(); |
|
615 mTest->setShuffle(false); |
|
616 QVERIFY(mTestPrivate->iPlaybackUtility == 0); |
|
617 mTestPrivate->iPlaybackUtility = MMPXPlaybackUtility::UtilityL( TUid::Uid(MpCommon::KMusicPlayerUid) ); |
|
618 mTest->setShuffle(false); |
|
619 QCOMPARE(mTestPrivate->iPlaybackUtility->iShuffle, 0); |
|
620 mTest->setShuffle(true); |
|
621 QCOMPARE(mTestPrivate->iPlaybackUtility->iShuffle, 1); |
|
622 } |
|
623 |
|
624 /*! |
|
625 Tests scan |
|
626 */ |
|
627 void TestMpMpxFrameworkWrapper::testScan() |
|
628 { |
|
629 mTest->scan(); |
|
630 QCOMPARE(mTestPrivate->iHarvesterUtility->iScan, TBool(ETrue)); |
|
631 } |
|
632 |
|
633 /*! |
|
634 Tests cancelScan |
|
635 */ |
|
636 void TestMpMpxFrameworkWrapper::testCancelScan() |
|
637 { |
|
638 mTestPrivate->iHarvesterUtility->iScan = ETrue; |
|
639 mTest->cancelScan(); |
|
640 QCOMPARE(mTestPrivate->iHarvesterUtility->iScan, TBool(EFalse)); |
|
641 |
|
642 mTestPrivate->iHarvesterUtility->iScan = ETrue; |
|
643 mTestPrivate->iHarvesterUtility->iLeave = ETrue; |
|
644 mTest->cancelScan(); |
|
645 QVERIFY(mTestPrivate->iHarvesterUtility != 0); |
|
646 QCOMPARE(mTestPrivate->iHarvesterUtility->iCheckSystemEvents,TBool(ETrue)); |
|
647 QCOMPARE(mTestPrivate->iHarvesterUtility->iScan, TBool(EFalse)); |
|
648 } |
|
649 |
|
650 /*! |
|
651 Tests PreviewItem |
|
652 */ |
|
653 void TestMpMpxFrameworkWrapper::testPreviewItem() |
|
654 { |
|
655 loadTestData(); |
|
656 mTestPrivate->iCollectionData->setMpxMedia(*iMediaTestData); |
|
657 QSignalSpy spy(mTest, SIGNAL(collectionPlaylistOpened())); |
|
658 mTest->previewItem(1); |
|
659 |
|
660 // Playback utility should be created. |
|
661 QVERIFY(mTestPrivate->iPlaybackUtility != 0); |
|
662 QCOMPARE(mTestPrivate->iPlaybackUtility->iPlay, TBool(ETrue)); |
|
663 QCOMPARE(spy.count(), 1); |
|
664 } |
|
665 |
|
666 /*! |
|
667 Tests OpenIsolatedCollection |
|
668 */ |
|
669 void TestMpMpxFrameworkWrapper::testOpenIsolatedCollection() |
|
670 { |
|
671 |
|
672 QVERIFY(mTestPrivate->iIsolatedCollectionHelper == 0); |
|
673 mTest->openIsolatedCollection( ECollectionContextAllSongs ); |
|
674 QVERIFY(mTestPrivate->iIsolatedCollectionHelper != 0); |
|
675 QCOMPARE(dynamic_cast<MMpMpxIsolatedCollectionHelperObserver*>(mTestPrivate),mTestPrivate->iIsolatedCollectionHelper->iObserver); |
|
676 QCOMPARE(mTestPrivate->iIsolatedCollectionHelper->iOpen,TBool(ETrue)); |
|
677 QCOMPARE(mTestPrivate->iIsolatedCollectionHelper->iCountPath, 6); |
|
678 QCOMPARE(mTestPrivate->iIsolatedCollectionHelper->iOpenCount, 1); |
|
679 |
|
680 delete mTestPrivate->iIsolatedCollectionHelper; |
|
681 mTestPrivate->iIsolatedCollectionHelper = 0; |
|
682 mTest->openIsolatedCollection( ECollectionContextUnknown ); |
|
683 QVERIFY(mTestPrivate->iIsolatedCollectionHelper == 0); |
|
684 |
|
685 } |
|
686 |
|
687 |
|
688 |
|
689 /*! |
|
690 Tests handleCollectionMessage. Part of private implementation. |
|
691 */ |
|
692 void TestMpMpxFrameworkWrapper::testHandleCollectionMessage() |
|
693 { |
|
694 RArray<TInt> supportedIds; |
|
695 CleanupClosePushL( supportedIds ); |
|
696 supportedIds.AppendL( KMPXMessageContentIdGeneral ); |
|
697 CMPXMedia* testMessage = CMPXMedia::NewL(supportedIds.Array()); |
|
698 CleanupStack::PopAndDestroy(&supportedIds); |
|
699 CleanupStack::PushL(testMessage); |
|
700 testMessage->SetTObjectValueL<TMPXMessageId>( KMPXMessageGeneralId, KMPXMessageGeneral); |
|
701 |
|
702 //Incremental open |
|
703 testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralEvent,TMPXCollectionMessage::EPathChanged); |
|
704 testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralType,EMcPathChangedByOpen); |
|
705 testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralData,EMcContainerOpened); |
|
706 mTestPrivate->DoHandleCollectionMessageL(*testMessage); |
|
707 QCOMPARE(mTestPrivate->iCollectionUtility->iOpen,TBool(EFalse)); |
|
708 |
|
709 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iDelay, KIncrementalDelayHalfSecond); |
|
710 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iStop,TBool(ETrue)); |
|
711 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iStart,TBool(ETrue)); |
|
712 QCOMPARE(mTestPrivate->iFirstIncrementalOpen,TBool(ETrue)); |
|
713 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iDirection,CMPXCollectionOpenUtility::EFetchNormal); |
|
714 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iChunkSize, KIncrementalFetchBlockSize); |
|
715 |
|
716 //Refresh ended |
|
717 cleanup(); |
|
718 init(); |
|
719 QSignalSpy spy(mTest, SIGNAL(scanEnded(void))); |
|
720 testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralEvent,TMPXCollectionMessage::EBroadcastEvent); |
|
721 testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralType,EMcMsgRefreshEnd); |
|
722 testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralData,0); |
|
723 mTestPrivate->DoHandleCollectionMessageL(*testMessage); |
|
724 QCOMPARE(mTestPrivate->iCollectionUtility->iOpen,TBool(EFalse)); |
|
725 QCOMPARE(spy.count(), 1); |
|
726 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iDelay, 0); |
|
727 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iStop,TBool(EFalse)); |
|
728 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iStart,TBool(EFalse)); |
|
729 QCOMPARE(mTestPrivate->iFirstIncrementalOpen,TBool(EFalse)); |
|
730 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iDirection,CMPXCollectionOpenUtility::EFetchDown); |
|
731 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iChunkSize, 0); |
|
732 |
|
733 //Opened a song |
|
734 cleanup(); |
|
735 init(); |
|
736 testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralEvent,TMPXCollectionMessage::EPathChanged); |
|
737 testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralType,EMcPathChangedByOpen); |
|
738 testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralData,EMcItemOpened); |
|
739 mTestPrivate->DoHandleCollectionMessageL(*testMessage); |
|
740 QCOMPARE(mTestPrivate->iCollectionUtility->iOpen,TBool(ETrue)); |
|
741 |
|
742 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iDelay, 0); |
|
743 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iStop,TBool(EFalse)); |
|
744 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iStart,TBool(EFalse)); |
|
745 QCOMPARE(mTestPrivate->iFirstIncrementalOpen,TBool(EFalse)); |
|
746 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iDirection,CMPXCollectionOpenUtility::EFetchDown); |
|
747 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iChunkSize, 0); |
|
748 |
|
749 //Refresh started |
|
750 cleanup(); |
|
751 init(); |
|
752 QSignalSpy spy2(mTest, SIGNAL(scanStarted(void))); |
|
753 testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralEvent,TMPXCollectionMessage::EBroadcastEvent); |
|
754 testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralType,EMcMsgRefreshStart); |
|
755 testMessage->SetTObjectValueL<TInt>(KMPXMessageGeneralData,0); |
|
756 mTestPrivate->DoHandleCollectionMessageL(*testMessage); |
|
757 QCOMPARE(mTestPrivate->iCollectionUtility->iOpen,TBool(EFalse)); |
|
758 QCOMPARE(spy2.count(), 1); |
|
759 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iDelay, 0); |
|
760 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iStop,TBool(EFalse)); |
|
761 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iStart,TBool(EFalse)); |
|
762 QCOMPARE(mTestPrivate->iFirstIncrementalOpen,TBool(EFalse)); |
|
763 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iDirection,CMPXCollectionOpenUtility::EFetchDown); |
|
764 QCOMPARE(mTestPrivate->iIncrementalOpenUtil->iChunkSize, 0); |
|
765 |
|
766 CleanupStack::PopAndDestroy(testMessage); |
|
767 |
|
768 //Items changed |
|
769 cleanup(); |
|
770 init(); |
|
771 QSignalSpy spy3(mTest, SIGNAL(scanCountChanged( int ))); |
|
772 mTest->scan(); |
|
773 RArray<TInt> supportedIds2; |
|
774 CleanupClosePushL( supportedIds2 ); |
|
775 supportedIds2.AppendL( KMPXMessageContentIdGeneral ); |
|
776 supportedIds2.AppendL( KMPXMessageIdContainer ); |
|
777 CMPXMedia* testMessage2 = CMPXMedia::NewL(supportedIds2.Array()); |
|
778 CleanupStack::PopAndDestroy(&supportedIds2); |
|
779 CleanupStack::PushL(testMessage2); |
|
780 |
|
781 CMPXMessageArray* array = CMPXMessageArray::NewL(); |
|
782 CleanupStack::PushL(array); |
|
783 //EMPXNoCategory, EMPXCollection, EMPXPlaylist, EMPXSong, EMPXPodcast three possible and two extra items |
|
784 for (TInt i =0; i < 5; i++) { |
|
785 RArray<TInt> supportedIds3; |
|
786 CleanupClosePushL( supportedIds3 ); |
|
787 supportedIds2.AppendL( KMPXMessageContentIdGeneral ); |
|
788 CMPXMedia* media = CMPXMedia::NewL(supportedIds3.Array()); |
|
789 CleanupStack::PopAndDestroy(&supportedIds3); |
|
790 CleanupStack::PushL(media); |
|
791 media->SetTObjectValueL<TMPXChangeEventType>(KMPXMessageChangeEventType, EMPXItemInserted); |
|
792 media->SetTObjectValueL<TMPXGeneralCategory>(KMPXMessageMediaGeneralCategory, TMPXGeneralCategory(i)); |
|
793 media->SetTObjectValueL<TMPXMessageId>( KMPXMessageGeneralId, KMPXMessageIdItemChanged); |
|
794 array->AppendL(*media); |
|
795 CleanupStack::PopAndDestroy(media); |
|
796 } |
|
797 testMessage2->SetTObjectValueL<TMPXMessageId>( KMPXMessageGeneralId, KMPXMessageIdItemChanged); |
|
798 testMessage2->SetCObjectValueL(KMPXMessageArrayContents, array); |
|
799 testMessage2->SetTObjectValueL<TInt>(KMPXMessageArrayCount, array->Count()); |
|
800 CleanupStack::PopAndDestroy(array); |
|
801 mTestPrivate->DoHandleCollectionMessageL(*testMessage2); |
|
802 CleanupStack::PopAndDestroy(testMessage2); |
|
803 QCOMPARE(mTestPrivate->iNumItemsAdded, 3); |
|
804 QCOMPARE(spy3.count(), 1); |
|
805 TInt count = qvariant_cast<int>(spy3.at(0).at(0)); |
|
806 QCOMPARE(count, mTestPrivate->iNumItemsAdded); |
|
807 |
|
808 } |
|
809 |
|
810 /*! |
|
811 Tests preparePlaylistMedia for track level. Part of private implementation. |
|
812 */ |
|
813 void TestMpMpxFrameworkWrapper::testPreparePlaylistMediaSongsContext() |
|
814 { |
|
815 QList<int> selection; |
|
816 selection.append(1); |
|
817 selection.append(3); |
|
818 selection.append(5); |
|
819 |
|
820 loadTestData(); |
|
821 mTestPrivate->iCollectionData->setMpxMedia(*iMediaTestData); |
|
822 CMPXMedia* testTracks = CMPXMedia::NewL(); |
|
823 CleanupStack::PushL( testTracks ); |
|
824 |
|
825 mTestPrivate->PreparePlaylistMediaL(*testTracks,selection,mTestPrivate->iCollectionData); |
|
826 QCOMPARE(testTracks->ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType),EMPXItem); |
|
827 QCOMPARE(testTracks->ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory),EMPXPlaylist); |
|
828 TInt count = testTracks->ValueTObjectL<TInt>(KMPXMediaArrayCount); |
|
829 QCOMPARE(count, selection.count()); |
|
830 CMPXMediaArray* testArray = testTracks->Value<CMPXMediaArray>( KMPXMediaArrayContents ); |
|
831 for( TInt i = 0; i < count; i++ ){ |
|
832 CMPXMedia* track( testArray->AtL(i) ); |
|
833 const TDesC& title = TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[(2*i)+1].GeneralTitle)); |
|
834 QCOMPARE(track->ValueText( KMPXMediaGeneralTitle ), title); |
|
835 QCOMPARE(track->ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType),EMPXItem); |
|
836 QCOMPARE(track->ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory),EMPXSong); |
|
837 } |
|
838 CleanupStack::PopAndDestroy( testTracks ); |
|
839 } |
|
840 |
|
841 |
|
842 /*! |
|
843 Tests preparePlaylistMedia for artist albums level. Part of private implementation. |
|
844 */ |
|
845 void TestMpMpxFrameworkWrapper::testPreparePlaylistMediaArtistAlbumsContext() |
|
846 { |
|
847 |
|
848 |
|
849 //Loading Test Data. |
|
850 |
|
851 RArray<TInt> supportedIds; |
|
852 CleanupClosePushL( supportedIds ); |
|
853 supportedIds.AppendL( KMPXMediaIdMusic ); |
|
854 supportedIds.AppendL( KMPXMediaIdGeneral ); |
|
855 CMPXMedia* albumsTestData = CMPXMedia::NewL(supportedIds.Array()); |
|
856 CMPXMedia* albumOneTracksTestData = CMPXMedia::NewL(supportedIds.Array()); |
|
857 CMPXMedia* albumTwoTracksTestData = CMPXMedia::NewL(supportedIds.Array()); |
|
858 CleanupStack::PopAndDestroy(&supportedIds); |
|
859 CleanupStack::PushL(albumsTestData); |
|
860 CleanupStack::PushL(albumOneTracksTestData); |
|
861 CleanupStack::PushL(albumTwoTracksTestData); |
|
862 |
|
863 {//Loading pseudo data for albums container |
|
864 CMPXMediaArray* array = CMPXMediaArray::NewL(); |
|
865 CleanupStack::PushL(array); |
|
866 CMPXMedia* media1 = CMPXMedia::NewL(); |
|
867 CleanupStack::PushL(media1); |
|
868 media1->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, TMPXItemId(0)); |
|
869 array->AppendL(*media1); |
|
870 CleanupStack::PopAndDestroy(media1); |
|
871 CMPXMedia* media2 = CMPXMedia::NewL(); |
|
872 CleanupStack::PushL(media2); |
|
873 media2->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, TMPXItemId(1)); |
|
874 array->AppendL(*media2); |
|
875 CleanupStack::PopAndDestroy(media2); |
|
876 CMPXMedia* media3 = CMPXMedia::NewL(); |
|
877 CleanupStack::PushL(media3); |
|
878 media3->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, TMPXItemId(2)); |
|
879 array->AppendL(*media3); |
|
880 CleanupStack::PopAndDestroy(media3); |
|
881 albumsTestData->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXGroup); |
|
882 albumsTestData->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXAlbum); |
|
883 albumsTestData->SetCObjectValueL(KMPXMediaArrayContents, array); |
|
884 albumsTestData->SetTObjectValueL<TInt>(KMPXMediaArrayCount, array->Count()); |
|
885 albumsTestData->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId,TMPXItemId(88));//any number |
|
886 CleanupStack::PopAndDestroy(array); |
|
887 } |
|
888 |
|
889 {//Loading pseudo data for album one |
|
890 CMPXMediaArray* array = CMPXMediaArray::NewL(); |
|
891 CleanupStack::PushL(array); |
|
892 TInt count = sizeof(KAllSongsTestData)/sizeof(TTestAttrs); |
|
893 for (TInt i =0; i < count/2; i++) { |
|
894 CMPXMedia* media = CMPXMedia::NewL(); |
|
895 CleanupStack::PushL(media); |
|
896 media->SetTextValueL(KMPXMediaGeneralTitle, TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[i].GeneralTitle))); |
|
897 media->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, TMPXItemId(i)); |
|
898 array->AppendL(*media); |
|
899 CleanupStack::PopAndDestroy(media); |
|
900 } |
|
901 albumOneTracksTestData->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem); |
|
902 albumOneTracksTestData->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXAlbum); |
|
903 albumOneTracksTestData->SetCObjectValueL(KMPXMediaArrayContents, array); |
|
904 albumOneTracksTestData->SetTObjectValueL<TInt>(KMPXMediaArrayCount, array->Count()); |
|
905 albumOneTracksTestData->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId,TMPXItemId(1)); |
|
906 CleanupStack::PopAndDestroy(array); |
|
907 } |
|
908 |
|
909 {//Loading pseudo data for album two |
|
910 CMPXMediaArray* array = CMPXMediaArray::NewL(); |
|
911 CleanupStack::PushL(array); |
|
912 TInt count = sizeof(KAllSongsTestData)/sizeof(TTestAttrs); |
|
913 for (TInt i = count/2; i < count; i++) { |
|
914 CMPXMedia* media = CMPXMedia::NewL(); |
|
915 CleanupStack::PushL(media); |
|
916 media->SetTextValueL(KMPXMediaGeneralTitle, TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[i].GeneralTitle))); |
|
917 media->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, (i)); |
|
918 array->AppendL(*media); |
|
919 CleanupStack::PopAndDestroy(media); |
|
920 } |
|
921 albumTwoTracksTestData->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem); |
|
922 albumTwoTracksTestData->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXAlbum); |
|
923 albumTwoTracksTestData->SetCObjectValueL(KMPXMediaArrayContents, array); |
|
924 albumTwoTracksTestData->SetTObjectValueL<TInt>(KMPXMediaArrayCount, array->Count()); |
|
925 albumTwoTracksTestData->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId,TMPXItemId(2)); |
|
926 CleanupStack::PopAndDestroy(array); |
|
927 } |
|
928 |
|
929 CMPXMediaArray* albumsTracksTestData = CMPXMediaArray::NewL(); |
|
930 |
|
931 albumsTracksTestData->AppendL(CMPXMedia::NewL()); //empty, this album is not selected for the test case. |
|
932 albumsTracksTestData->AppendL(*albumOneTracksTestData); |
|
933 albumsTracksTestData->AppendL(*albumTwoTracksTestData); |
|
934 CleanupStack::PopAndDestroy(albumTwoTracksTestData); |
|
935 CleanupStack::PopAndDestroy(albumOneTracksTestData); |
|
936 |
|
937 |
|
938 |
|
939 QList<int> selection; |
|
940 selection.append(1); |
|
941 selection.append(2); |
|
942 |
|
943 mTestPrivate->iCollectionUtility->iAlbumSongs = albumsTracksTestData; |
|
944 mTestPrivate->iCollectionData->setMpxMedia(*albumsTestData); |
|
945 mTestPrivate->iCollectionData->mContext = ECollectionContextAlbums; |
|
946 |
|
947 CMPXMedia* testTracks = CMPXMedia::NewL(); |
|
948 CleanupStack::PushL( testTracks ); |
|
949 |
|
950 mTestPrivate->PreparePlaylistMediaL(*testTracks,selection,mTestPrivate->iCollectionData); |
|
951 QCOMPARE(testTracks->ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType),EMPXItem); |
|
952 QCOMPARE(testTracks->ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory),EMPXPlaylist); |
|
953 TInt count = sizeof(KAllSongsTestData)/sizeof(TTestAttrs); |
|
954 QCOMPARE(count, testTracks->ValueTObjectL<TInt>(KMPXMediaArrayCount)); |
|
955 const CMPXMediaArray* testArray = testTracks->Value<CMPXMediaArray>( KMPXMediaArrayContents ); |
|
956 for( TInt i = 0; i < count; i++ ){ |
|
957 CMPXMedia* track( testArray->AtL(i) ); |
|
958 const TDesC& title = TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[i].GeneralTitle)); |
|
959 QCOMPARE(track->ValueText( KMPXMediaGeneralTitle ), title); |
|
960 QCOMPARE(TInt (track->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)),i); |
|
961 QCOMPARE(track->ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType),EMPXItem); |
|
962 QCOMPARE(track->ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory),EMPXSong); |
|
963 } |
|
964 CleanupStack::PopAndDestroy( testTracks ); |
|
965 CleanupStack::PopAndDestroy(albumsTestData); |
|
966 } |
|
967 |
|
968 |
|
969 |
|
970 /*! |
|
971 Used to load test data |
|
972 */ |
|
973 void TestMpMpxFrameworkWrapper::loadTestData() |
|
974 { |
|
975 if(iMediaTestData){ |
|
976 delete iMediaTestData; |
|
977 iMediaTestData=0; |
|
978 } |
|
979 RArray<TInt> supportedIds; |
|
980 CleanupClosePushL( supportedIds ); |
|
981 supportedIds.AppendL( KMPXMediaIdMusic ); |
|
982 supportedIds.AppendL( KMPXMediaIdGeneral ); |
|
983 CMPXMedia* entries = CMPXMedia::NewL(supportedIds.Array()); |
|
984 CleanupStack::PopAndDestroy(&supportedIds); |
|
985 CleanupStack::PushL(entries); |
|
986 CMPXMediaArray* array = CMPXMediaArray::NewL(); |
|
987 CleanupStack::PushL(array); |
|
988 TInt count = sizeof(KAllSongsTestData)/sizeof(TTestAttrs); |
|
989 for (TInt i =0; i < count; i++) { |
|
990 CMPXMedia* media = CMPXMedia::NewL(); |
|
991 CleanupStack::PushL(media); |
|
992 media->SetTextValueL(KMPXMediaGeneralTitle, TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[i].GeneralTitle))); |
|
993 media->SetTextValueL(KMPXMediaMusicArtist, TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[i].MusicArtist))); |
|
994 media->SetTObjectValueL<TInt>(KMPXMediaGeneralCount, KAllSongsTestData[i].GeneralCount); |
|
995 media->SetTextValueL(KMPXMediaMusicAlbumArtFileName, TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[i].MusicAlbumArtFileName))); |
|
996 array->AppendL(*media); |
|
997 CleanupStack::PopAndDestroy(media); |
|
998 } |
|
999 |
|
1000 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXGroup); |
|
1001 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXSong); |
|
1002 entries->SetTextValueL(KMPXMediaGeneralTitle, _L("All songs")); |
|
1003 |
|
1004 entries->SetCObjectValueL(KMPXMediaArrayContents, array); |
|
1005 entries->SetTObjectValueL<TInt>(KMPXMediaArrayCount, array->Count()); |
|
1006 entries->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId,TMPXItemId(1)); |
|
1007 CleanupStack::PopAndDestroy(array); |
|
1008 |
|
1009 iMediaTestData = CMPXMedia::NewL(*entries); |
|
1010 |
|
1011 CleanupStack::PopAndDestroy(entries); |
|
1012 } |
|
1013 |
|
1014 /*! |
|
1015 Used to load test playlists |
|
1016 */ |
|
1017 void TestMpMpxFrameworkWrapper::loadPlaylists() |
|
1018 { |
|
1019 if(iPlaylistsTestData){ |
|
1020 delete iPlaylistsTestData; |
|
1021 iPlaylistsTestData=0; |
|
1022 } |
|
1023 |
|
1024 RArray<TInt> supportedIds; |
|
1025 CleanupClosePushL( supportedIds ); |
|
1026 |
|
1027 supportedIds.AppendL( KMPXMediaIdGeneral ); |
|
1028 CMPXMedia* entries = CMPXMedia::NewL(supportedIds.Array()); |
|
1029 CleanupStack::PopAndDestroy(&supportedIds); |
|
1030 CleanupStack::PushL(entries); |
|
1031 CMPXMediaArray* array = CMPXMediaArray::NewL(); |
|
1032 CleanupStack::PushL(array); |
|
1033 TInt count = sizeof(KAllSongsTestData)/sizeof(TTestAttrs); |
|
1034 for (TInt i =0; i < count; i++) { |
|
1035 CMPXMedia* media = CMPXMedia::NewL(); |
|
1036 CleanupStack::PushL(media); |
|
1037 media->SetTextValueL(KMPXMediaGeneralTitle, TPtrC(reinterpret_cast<const TUint16*>(KAllSongsTestData[i].GeneralTitle))); |
|
1038 media->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, TMPXItemId(i)); |
|
1039 array->AppendL(*media); |
|
1040 CleanupStack::PopAndDestroy(media); |
|
1041 |
|
1042 } |
|
1043 |
|
1044 entries->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXGroup); |
|
1045 entries->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXPlaylist); |
|
1046 entries->SetTextValueL(KMPXMediaGeneralTitle, _L("All playlists")); |
|
1047 |
|
1048 entries->SetCObjectValueL(KMPXMediaArrayContents, array); |
|
1049 entries->SetTObjectValueL<TInt>(KMPXMediaArrayCount, array->Count()); |
|
1050 CleanupStack::PopAndDestroy(array); |
|
1051 |
|
1052 iPlaylistsTestData = CMPXMedia::NewL(*entries); |
|
1053 |
|
1054 CleanupStack::PopAndDestroy(entries); |
|
1055 } |
|
1056 |
|
1057 /*! |
|
1058 Used to wait on spy signal |
|
1059 */ |
|
1060 bool TestMpMpxFrameworkWrapper::waitForSignal(QSignalSpy* spy, int timeoutms) |
|
1061 { |
|
1062 QTime timer; |
|
1063 timer.start(); |
|
1064 while (spy->isEmpty() && timer.elapsed() < timeoutms) |
|
1065 { |
|
1066 QCoreApplication::processEvents(); |
|
1067 } |
|
1068 return !spy->isEmpty(); |
|
1069 } |
|
1070 |
|
1071 //end of file |
|