|
1 /* |
|
2 * Copyright (c) 2002 - 2007 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 the License "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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // [INCLUDE FILES] - do not remove |
|
20 #include <e32svr.h> |
|
21 #include <StifParser.h> |
|
22 #include <Stiftestinterface.h> |
|
23 #include <LiwServiceHandler.h> |
|
24 |
|
25 #include "tmediaprovidertesting.h" |
|
26 #include "tmediaprovidertesting.hrh" |
|
27 |
|
28 |
|
29 /* -------------------------------------------------------------------------- |
|
30 Ctmediaprovidertesting :: SetInput |
|
31 Fills the input parameter list. |
|
32 The format of the cfg input is |
|
33 key startRange endRange sortKey sortOrder errorcode |
|
34 [Expected fileName fileExtension drive fileSize fileDate fileNameAndPath mimeType |
|
35 [Next "next map data"]]. |
|
36 ----------------------------------------------------------------------------- |
|
37 */ |
|
38 void Ctmediaprovidertesting::ParseStiffInput(CStifItemParser& aItem) |
|
39 { |
|
40 TPtrC16 expectedStart(KNullDesC); |
|
41 TPtrC16 key(KNullDesC); |
|
42 TPtrC16 startRange(KNullDesC); |
|
43 TPtrC16 endRange(KNullDesC); |
|
44 TPtrC16 sortKey(KNullDesC); |
|
45 TPtrC16 sortOrder(KNullDesC); |
|
46 TPtrC16 inpType(KNullDesC); |
|
47 TPtrC16 inpFileType(KNullDesC); |
|
48 |
|
49 aItem.GetNextString(inpType); |
|
50 aItem.GetNextString(inpFileType); |
|
51 aItem.GetNextString(key); |
|
52 aItem.GetNextString(startRange); |
|
53 aItem.GetNextString(endRange); |
|
54 aItem.GetNextString(sortKey); |
|
55 aItem.GetNextString(sortOrder); |
|
56 aItem.GetNextInt(iExpErrorCode); |
|
57 aItem.GetNextString(expectedStart); |
|
58 |
|
59 if(inpFileType.CompareF(KFileTypeStreamingURL) == 0) |
|
60 { |
|
61 iFiletype = EStreamingURLFile; |
|
62 } |
|
63 else if(inpFileType.CompareF(KFileTypeMusic) == 0) |
|
64 { |
|
65 iFiletype = EMusicFile; |
|
66 } |
|
67 //check for expected key |
|
68 //if it is there then get the expected result and put it into the map. |
|
69 if(expectedStart.CompareF(KExpectedStart) == 0) |
|
70 { |
|
71 SetExpectedOutputMap(aItem); |
|
72 } |
|
73 iLog->Log(_L("The Input Parameters are:")); |
|
74 iLog->Log(key); |
|
75 iLog->Log(startRange); |
|
76 iLog->Log(endRange); |
|
77 iLog->Log(sortKey); |
|
78 iLog->Log(sortOrder); |
|
79 |
|
80 CLiwDefaultMap *sortMap = NULL; |
|
81 |
|
82 //set the content type to the fileinfo. |
|
83 if(inpType.Compare(_L("NULL")) != 0) |
|
84 { |
|
85 if(inpType.Compare(_L("NULLVALUE")) == 0) inpType.Set(KNullDesC); |
|
86 const TLiwGenericParam paramContentType(KType, TLiwVariant(inpType)); |
|
87 iInList->AppendL(paramContentType); |
|
88 } |
|
89 |
|
90 CLiwDefaultMap *filterMap = CLiwDefaultMap::NewL(); |
|
91 CleanupStack::PushL(filterMap); |
|
92 |
|
93 TLiwGenericParam filterParam(KFilter, TLiwVariant(filterMap)); |
|
94 iInList->AppendL(filterParam); |
|
95 filterMap->DecRef(); |
|
96 |
|
97 //Set the file type to image. |
|
98 if(inpFileType.Compare(_L("NULL")) != 0) |
|
99 { |
|
100 if(inpFileType.Compare(_L("NULLVALUE")) == 0) inpFileType.Set(KNullDesC); |
|
101 filterMap->InsertL(KFileType,TLiwVariant(inpFileType)); |
|
102 } |
|
103 //Get the key if it is specified. |
|
104 if(key.Compare(_L("NULL")) != 0) |
|
105 { |
|
106 if(key.Compare(_L("NULLVALUE")) == 0) key.Set(KNullDesC); |
|
107 filterMap->InsertL(KKey,TLiwVariant(key)); |
|
108 } |
|
109 //Get the startRange if it is specified. |
|
110 if(startRange.Compare(_L("NULL")) != 0) |
|
111 { |
|
112 if(startRange.Compare(_L("NULLVALUE")) == 0) startRange.Set(KNullDesC); |
|
113 filterMap->InsertL(KStartRange,TLiwVariant(startRange)); |
|
114 } |
|
115 //Get the endRange if it is specified. |
|
116 if(endRange.Compare(_L("NULL")) != 0) |
|
117 { |
|
118 if(endRange.Compare(_L("NULLVALUE")) == 0) endRange.Set(KNullDesC); |
|
119 filterMap->InsertL(KEndRange,TLiwVariant(endRange)); |
|
120 } |
|
121 //only if the sort key is specified create the map |
|
122 if(sortKey.Compare(_L("NULL")) != 0) |
|
123 { |
|
124 sortMap = CLiwDefaultMap::NewL(); |
|
125 CleanupStack::PushL(sortMap); |
|
126 if(sortKey.Compare(_L("NULLVALUE"))== 0) sortKey.Set(KNullDesC); |
|
127 sortMap->InsertL(KKey,TLiwVariant(sortKey)); |
|
128 TLiwGenericParam sortParam(KSort, TLiwVariant(sortMap)); |
|
129 iInList->AppendL(sortParam); |
|
130 sortMap->DecRef(); |
|
131 } |
|
132 //get the sort order if it is specified. |
|
133 if(sortOrder.Compare(_L("NULL")) != 0) |
|
134 { |
|
135 if(!sortMap) |
|
136 { |
|
137 sortMap = CLiwDefaultMap::NewL(); |
|
138 CleanupStack::PushL(sortMap); |
|
139 if(sortOrder.Compare(_L("NULLVALUE"))== 0) sortOrder.Set(KNullDesC); |
|
140 TLiwGenericParam sortParam(KSort, TLiwVariant(sortMap)); |
|
141 iInList->AppendL(sortParam); |
|
142 sortMap->DecRef(); |
|
143 } |
|
144 sortMap->InsertL(KOrder,TLiwVariant(sortOrder)); |
|
145 } |
|
146 //end of input params now look for expected params |
|
147 if(sortMap) |
|
148 { |
|
149 CleanupStack::Pop(sortMap); |
|
150 } |
|
151 CleanupStack::Pop(filterMap); |
|
152 } |
|
153 |
|
154 /* -------------------------------------------------------------------------- |
|
155 Ctmediaprovidertesting :: SetExpectedImageOutputMap. |
|
156 This method fills the expected output map. |
|
157 ----------------------------------------------------------------------------- |
|
158 */ |
|
159 void Ctmediaprovidertesting :: SetExpectedOutputMap(CStifItemParser& aItem) |
|
160 { |
|
161 TPtrC16 nextString(KNullDesC); |
|
162 |
|
163 iLog->Log(_L("Inside SetExpectedOutputMap")); |
|
164 |
|
165 aItem.GetNextString(nextString); |
|
166 /* |
|
167 * The expected output is in the format. |
|
168 * [ExpectredStart StartMap Key Value[...]EndMap[...]ExpectedEnd]. |
|
169 */ |
|
170 while(nextString.CompareF(KExpectedEnd)!=0) |
|
171 { |
|
172 if(nextString.CompareF(KMapStart) == 0) |
|
173 { |
|
174 CLiwDefaultMap* expectedOutPutMap = CLiwDefaultMap::NewL(); |
|
175 CleanupStack::PushL(expectedOutPutMap); |
|
176 aItem.GetNextString(nextString); |
|
177 |
|
178 while(nextString.CompareF(KMapEnd)!= 0) |
|
179 { |
|
180 TPtrC key; |
|
181 TPtrC value; |
|
182 TBuf8<255> insertKey; |
|
183 |
|
184 key.Set(nextString); |
|
185 insertKey.Copy(key); |
|
186 |
|
187 if(key.CompareF(_L("FileSize"))==0) |
|
188 { |
|
189 TInt fileSize = -1; |
|
190 aItem.GetNextInt(fileSize); |
|
191 expectedOutPutMap->InsertL(insertKey, (TInt32)fileSize); |
|
192 } |
|
193 else |
|
194 { |
|
195 aItem.GetNextString(nextString); |
|
196 value.Set(nextString); |
|
197 expectedOutPutMap->InsertL(insertKey, value); |
|
198 } |
|
199 aItem.GetNextString(nextString); |
|
200 } |
|
201 |
|
202 iExpectedOutPutArray.Append(expectedOutPutMap); |
|
203 CleanupStack::Pop(expectedOutPutMap); |
|
204 } |
|
205 aItem.GetNextString(nextString); |
|
206 } |
|
207 } |
|
208 |
|
209 /* -------------------------------------------------------------------------- |
|
210 Ctmediaprovidertesting :: IsExpectedResult. |
|
211 This method checks whether the obtained result and the expected results match. . |
|
212 ----------------------------------------------------------------------------- |
|
213 */ |
|
214 TBool Ctmediaprovidertesting::IsExpectedResult(CLiwIterable* aResultlist) |
|
215 { |
|
216 TLiwVariant fileDetails; |
|
217 TBool foundMap = EFalse; |
|
218 TInt prevFoundIndex = -1; |
|
219 TInt index = 0; |
|
220 iLog->Log(_L("Inside IsExpectedResult")); |
|
221 |
|
222 for(TInt i = 0; i<iExpectedOutPutArray.Count(); i++) |
|
223 |
|
224 { |
|
225 index = 0; |
|
226 while(aResultlist->NextL(fileDetails)) |
|
227 { |
|
228 const CLiwMap* map = fileDetails.AsMap(); |
|
229 if(map) |
|
230 { |
|
231 iLog->Log(_L("Map found from iterator"));// Lok |
|
232 //compare the two maps the result and the expected one. |
|
233 if(Ctmediaprovidertesting :: CompareMaps(iExpectedOutPutArray[i], map)) |
|
234 { |
|
235 aResultlist->Reset(); |
|
236 foundMap = ETrue; |
|
237 if(index<prevFoundIndex) |
|
238 { |
|
239 iLog->Log(_L("Result Not in Expected sort order")); |
|
240 User::Leave(KErrGeneral); |
|
241 } |
|
242 iLog->Log(_L("Map is in sorted order with positio ")); // Lok |
|
243 TBuf<10>buf; |
|
244 buf.Num(index); |
|
245 iLog->Log(buf); |
|
246 buf.Zero(); |
|
247 prevFoundIndex = index; |
|
248 break; |
|
249 } |
|
250 } |
|
251 index++; |
|
252 } |
|
253 if(foundMap) |
|
254 { |
|
255 foundMap = EFalse; |
|
256 } |
|
257 else |
|
258 { |
|
259 iLog->Log(_L("Expected map not found in the result list")); |
|
260 return EFalse; |
|
261 } |
|
262 } |
|
263 return ETrue; |
|
264 } |
|
265 |
|
266 /* -------------------------------------------------------------------------- |
|
267 Ctmediaprovidertesting :: CompareMaps. |
|
268 A static method which compares two maps. |
|
269 ----------------------------------------------------------------------------- |
|
270 */ |
|
271 TBool Ctmediaprovidertesting::CompareMaps(CLiwMap* aExpectedMap, |
|
272 const CLiwMap* aResultMap) |
|
273 { |
|
274 iLog->Log(_L("Inside CompareMaps")); |
|
275 if(!CompareStringResult(KType, aExpectedMap, aResultMap)) |
|
276 { |
|
277 return EFalse; |
|
278 } |
|
279 if(!CompareStringResult(KMgFileName, aExpectedMap, aResultMap)) |
|
280 { |
|
281 return EFalse; |
|
282 } |
|
283 if(!CompareStringResult(KMgDrive, aExpectedMap, aResultMap)) |
|
284 { |
|
285 return EFalse; |
|
286 } |
|
287 if(!CompareTIntResult(KMgFileSize, aExpectedMap, aResultMap)) |
|
288 { |
|
289 return EFalse; |
|
290 } |
|
291 if(!CompareStringResult(KMgMimeType, aExpectedMap, aResultMap)) |
|
292 { |
|
293 return EFalse; |
|
294 } |
|
295 if(!CompareStringResult(KMgFileNameAndPath, aExpectedMap, aResultMap)) |
|
296 { |
|
297 return EFalse; |
|
298 } |
|
299 if(!CompareTTimeResult(KMgFileDate, aExpectedMap, aResultMap)) |
|
300 { |
|
301 return EFalse; |
|
302 } |
|
303 //In case of streamingURL file check for few additional keys. |
|
304 if(iFiletype == EStreamingURLFile) |
|
305 { |
|
306 if(!CompareStringResult(KMgLinkFirstURL, aExpectedMap, aResultMap)) |
|
307 { |
|
308 return EFalse; |
|
309 } |
|
310 } |
|
311 //In case of Music file check for few additional keys. |
|
312 if(iFiletype == EMusicFile) |
|
313 { |
|
314 if(!CompareStringResult(KMgComposer, aExpectedMap, aResultMap)) |
|
315 { |
|
316 return EFalse; |
|
317 } |
|
318 |
|
319 if(!CompareStringResult(KMgArtist, aExpectedMap, aResultMap)) |
|
320 { |
|
321 return EFalse; |
|
322 } |
|
323 if(!CompareStringResult(KMgAlbum, aExpectedMap, aResultMap)) |
|
324 { |
|
325 return EFalse; |
|
326 } |
|
327 |
|
328 if(!CompareStringResult(KMgGenre, aExpectedMap, aResultMap)) |
|
329 { |
|
330 return EFalse; |
|
331 } |
|
332 if(!CompareTIntResult(KMgTrackNumber, aExpectedMap, aResultMap)) |
|
333 { |
|
334 return EFalse; |
|
335 } |
|
336 if(!CompareStringResult(KMgSongName, aExpectedMap, aResultMap)) |
|
337 { |
|
338 return EFalse; |
|
339 } |
|
340 } |
|
341 return ETrue; |
|
342 } |
|
343 |
|
344 |
|
345 /* -------------------------------------------------------------------------- |
|
346 Ctmediaprovidertesting :: CompareStringResult. |
|
347 A static method which compares two string results from the maps. |
|
348 ----------------------------------------------------------------------------- |
|
349 */ |
|
350 TBool Ctmediaprovidertesting::CompareStringResult(const TDesC8& aKey, |
|
351 CLiwMap* aExpectedMap, |
|
352 const CLiwMap* aResultMap) |
|
353 { |
|
354 TLiwVariant expValue; |
|
355 TLiwVariant resValue; |
|
356 TBool equal = EFalse; |
|
357 |
|
358 iLog->Log(_L("Inside CompareStringResult")); |
|
359 |
|
360 if(!aExpectedMap->FindL(aKey, expValue)) |
|
361 { |
|
362 return ETrue; |
|
363 } |
|
364 aResultMap->FindL(aKey, resValue); |
|
365 |
|
366 TPtrC expPtr = expValue.AsDes(); |
|
367 TPtrC resPtr = resValue.AsDes(); |
|
368 |
|
369 iLog->Log(_L("Expected Value")); |
|
370 iLog->Log(expPtr); |
|
371 |
|
372 iLog->Log(_L("Result Value")); |
|
373 iLog->Log(resPtr); |
|
374 |
|
375 if(expPtr.CompareF(_L("NULL"))!=0) |
|
376 { |
|
377 if(expPtr.CompareF(resPtr) == 0) |
|
378 { |
|
379 equal = ETrue; |
|
380 } |
|
381 } |
|
382 |
|
383 expValue.Reset(); |
|
384 resValue.Reset(); |
|
385 |
|
386 return equal; |
|
387 } |
|
388 |
|
389 /* -------------------------------------------------------------------------- |
|
390 Ctmediaprovidertesting :: CompareTTimeResult. |
|
391 A static method which compares two TTime results from the maps. |
|
392 ----------------------------------------------------------------------------- |
|
393 */ |
|
394 TBool Ctmediaprovidertesting::CompareTTimeResult(const TDesC8& aKey, |
|
395 CLiwMap* aExpectedMap, |
|
396 const CLiwMap* aResultMap) |
|
397 { |
|
398 iLog->Log(_L("Inside CompareStringResult")); |
|
399 TLiwVariant expValue; |
|
400 TLiwVariant resValue; |
|
401 TBool equal = EFalse; |
|
402 TBuf<255> timeString; |
|
403 |
|
404 if(!aExpectedMap->FindL(aKey, expValue)) |
|
405 { |
|
406 return ETrue; |
|
407 } |
|
408 aResultMap->FindL(aKey, resValue); |
|
409 |
|
410 TTime expTime(expValue.AsDes()); |
|
411 |
|
412 iLog->Log(_L("Expected Value")); |
|
413 iLog->Log(expValue.AsDes()); |
|
414 |
|
415 TTime resTime = resValue.AsTTime(); |
|
416 |
|
417 //resTime.FormatL(timeString, _L("%:0%J%:1%T%:2%S%.%*C3%:3%+B %*E%*D%X%*N%*Y %1 %2 '%3")); |
|
418 resTime.FormatL(timeString, _L("%F%Y%M%D%:0%H%T%S")); |
|
419 |
|
420 iLog->Log(_L("Result Value")); |
|
421 iLog->Log(timeString); |
|
422 |
|
423 if(expTime.DateTime().Day() == resTime.DateTime().Day()) |
|
424 { |
|
425 if(expTime.DateTime().Month() == resTime.DateTime().Month()) |
|
426 if(expTime.DateTime().Year() == resTime.DateTime().Year()) |
|
427 //these things can be ignored |
|
428 /*if(expTime.DateTime().Hour() == resTime.DateTime().Hour()) |
|
429 if(expTime.DateTime().Minute() == resTime.DateTime().Minute()) |
|
430 if(expTime.DateTime().Second() == resTime.DateTime().Second())*/ |
|
431 { |
|
432 equal = ETrue; |
|
433 } |
|
434 } |
|
435 expValue.Reset(); |
|
436 resValue.Reset(); |
|
437 return equal; |
|
438 } |
|
439 |
|
440 /* -------------------------------------------------------------------------- |
|
441 Ctmediaprovidertesting :: CompareTIntResult. |
|
442 A static method which compares two TInt results from the maps. |
|
443 ----------------------------------------------------------------------------- |
|
444 */ |
|
445 TBool Ctmediaprovidertesting::CompareTIntResult(const TDesC8& aKey, |
|
446 CLiwMap* aExpectedMap, |
|
447 const CLiwMap* aResultMap) |
|
448 { |
|
449 TLiwVariant expValue; |
|
450 TLiwVariant resValue; |
|
451 TBool equal = EFalse; |
|
452 TBuf<255> expIntStr; |
|
453 TBuf<255> resIntStr; |
|
454 |
|
455 if(!aExpectedMap->FindL(aKey, expValue)) |
|
456 { |
|
457 return ETrue; |
|
458 } |
|
459 aResultMap->FindL(aKey, resValue); |
|
460 |
|
461 TInt expRes = expValue.AsTInt32(); |
|
462 TInt resRes = resValue.AsTInt32(); |
|
463 |
|
464 expIntStr.AppendNum(expRes); |
|
465 resIntStr.AppendNum(resRes); |
|
466 |
|
467 iLog->Log(_L("Expected Value")); |
|
468 iLog->Log(expIntStr); |
|
469 |
|
470 iLog->Log(_L("Result Value")); |
|
471 iLog->Log(resIntStr); |
|
472 |
|
473 if(expRes == resRes) |
|
474 { |
|
475 equal = ETrue; |
|
476 } |
|
477 expValue.Reset(); |
|
478 resValue.Reset(); |
|
479 return equal; |
|
480 } |