|
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 // EPOC includes |
|
17 #include <e32base.h> |
|
18 |
|
19 // MDA includes |
|
20 #include <mdaimageconverter.h> |
|
21 #include "MdaImageConverter.inl" |
|
22 |
|
23 // Test system includes |
|
24 #include <testframework.h> |
|
25 #include "TestStepMediaSvr.h" |
|
26 #include "TestSuiteMediaSvr.h" |
|
27 |
|
28 // Directory that the test files will be stored on |
|
29 _LIT(KMediaSvrTestSourcePathOnC,"c:\\MediaSvrTest\\"); |
|
30 _LIT(KMediaSvrTestSourcePathOnD,"d:\\MediaSvrTest\\"); |
|
31 _LIT(KMediaSvrTestSourcePathOnE,"e:\\MediaSvrTest\\"); |
|
32 _LIT(KMediaSvrTestSourcePathOnZ,"z:\\MediaSvrTest\\"); |
|
33 |
|
34 /** |
|
35 * |
|
36 * CTestStepMediaSvr constructor |
|
37 * |
|
38 * @xxxx |
|
39 * |
|
40 */ |
|
41 CTestStepMediaSvr::CTestStepMediaSvr() |
|
42 { |
|
43 // set up parameters for member format functions |
|
44 // this is done in this way due to the awkward design of the API being tested |
|
45 iJfifFormatMonoQ50.iSettings.iSampleScheme = TMdaJpgSettings::EMonochrome; |
|
46 iJfifFormatColor420Q50.iSettings.iSampleScheme = TMdaJpgSettings::EColor420; |
|
47 iJfifFormatColor422Q50.iSettings.iSampleScheme = TMdaJpgSettings::EColor422; |
|
48 iJfifFormatColor444Q50.iSettings.iSampleScheme = TMdaJpgSettings::EColor444; |
|
49 iJfifFormatMonoQ50.iSettings.iQualityFactor = 50; |
|
50 iJfifFormatColor420Q50.iSettings.iQualityFactor = 50; |
|
51 iJfifFormatColor422Q50.iSettings.iQualityFactor = 50; |
|
52 iJfifFormatColor444Q50.iSettings.iQualityFactor = 50; |
|
53 |
|
54 iJfifFormatColor444Q10.iSettings.iQualityFactor = 10; |
|
55 iJfifFormatColor444Q30.iSettings.iQualityFactor = 30; |
|
56 iJfifFormatColor444Q60.iSettings.iQualityFactor = 60; |
|
57 iJfifFormatColor444Q100.iSettings.iQualityFactor = 100; |
|
58 |
|
59 iMbmFormatGray2.iDisplayMode = EGray2; |
|
60 iMbmFormatGray4.iDisplayMode = EGray4; |
|
61 iMbmFormatGray16.iDisplayMode = EGray16; |
|
62 iMbmFormatGray256.iDisplayMode = EGray256; |
|
63 iMbmFormatColor16.iDisplayMode = EColor16; |
|
64 iMbmFormatColor256.iDisplayMode = EColor256; |
|
65 iMbmFormatColor4K.iDisplayMode = EColor4K; |
|
66 iMbmFormatColor64K.iDisplayMode = EColor64K; |
|
67 iMbmFormatColor16M.iDisplayMode = EColor16M; |
|
68 } |
|
69 |
|
70 TVerdict CTestStepMediaSvr::DoTestStepPreambleL() |
|
71 { |
|
72 // connect to the bitmap server and check the error code |
|
73 TInt errCode = RFbsSession::Connect(); |
|
74 if( errCode != KErrNone ) |
|
75 { |
|
76 //[failed to connect to bitmap server |
|
77 ERR_PRINTF2(_L("Failed to connect to bitmap server in teststep preamble = %d"), errCode ); |
|
78 return EFail; |
|
79 } |
|
80 |
|
81 iScheduler = new(ELeave)CActiveScheduler; |
|
82 |
|
83 //[install the active scheduler ] |
|
84 CActiveScheduler::Install( iScheduler ); |
|
85 |
|
86 InitSystemPath(); |
|
87 |
|
88 return EPass; |
|
89 } |
|
90 |
|
91 /** |
|
92 * The post amble step cleans up the allocated memory in the preamble |
|
93 * @returns TVerdict EPass or EFail |
|
94 * @leaves can leave due to insufficient memory |
|
95 * @lib "TS_BitmapTransforms.lib" |
|
96 * @xxxx |
|
97 */ |
|
98 |
|
99 TVerdict CTestStepMediaSvr::DoTestStepPostambleL() |
|
100 { |
|
101 // Destroy the scheduler |
|
102 CActiveScheduler::Install(NULL); // Uninstall the active scheduler |
|
103 delete iScheduler; |
|
104 iScheduler = NULL; |
|
105 // disconnect from the bitmap server |
|
106 RFbsSession::Disconnect(); |
|
107 return EPass; |
|
108 } |
|
109 |
|
110 void CTestStepMediaSvr::Complete(TInt aError) |
|
111 { |
|
112 iError = aError; |
|
113 CActiveScheduler::Stop(); |
|
114 } |
|
115 |
|
116 void CTestStepMediaSvr::MiuoCreateComplete(TInt aError) |
|
117 { |
|
118 Complete(aError); |
|
119 } |
|
120 |
|
121 void CTestStepMediaSvr::MiuoOpenComplete(TInt aError) |
|
122 { |
|
123 Complete(aError); |
|
124 } |
|
125 void CTestStepMediaSvr::MiuoConvertComplete(TInt aError) |
|
126 { |
|
127 Complete(aError); |
|
128 } |
|
129 |
|
130 TInt CTestStepMediaSvr::WaitForResult() |
|
131 { |
|
132 CActiveScheduler::Start(); |
|
133 return iError; |
|
134 } |
|
135 |
|
136 /** |
|
137 * |
|
138 * Intialiases the default system path for the tests |
|
139 * |
|
140 * @xxxx |
|
141 * |
|
142 */ |
|
143 void CTestStepMediaSvr::InitSystemPath() |
|
144 { |
|
145 TUint att; |
|
146 RFs fs; |
|
147 TInt ret = fs.Connect(); |
|
148 __ASSERT_ALWAYS(ret == KErrNone,User::Panic(_L("Sys path not setup"),ret)); |
|
149 |
|
150 if (fs.Att(KMediaSvrTestSourcePathOnE,att) == KErrNone) |
|
151 iDefaultPath = KMediaSvrTestSourcePathOnE; |
|
152 else if (fs.Att(KMediaSvrTestSourcePathOnD,att) == KErrNone) |
|
153 iDefaultPath = KMediaSvrTestSourcePathOnD; |
|
154 else if (fs.Att(KMediaSvrTestSourcePathOnC,att) == KErrNone) |
|
155 iDefaultPath = KMediaSvrTestSourcePathOnC; |
|
156 else if (fs.Att(KMediaSvrTestSourcePathOnZ,att) == KErrNone) |
|
157 iDefaultPath = KMediaSvrTestSourcePathOnZ; |
|
158 else |
|
159 User::Panic(_L("Test files not found"),KErrNotFound); |
|
160 |
|
161 fs.Close(); |
|
162 } |
|
163 |
|
164 const TDesC& CTestStepMediaSvr::DefaultPath() const |
|
165 { |
|
166 return iDefaultPath; |
|
167 } |
|
168 |
|
169 /** |
|
170 * |
|
171 * Load an image from a file |
|
172 * |
|
173 * @param "const TDesC& aFileName" |
|
174 * Name of file to load |
|
175 * @param "TMdaClipFormat* aFormat" |
|
176 * Format of the image |
|
177 * @param "TMdaPackage* aCodec" |
|
178 * Format of the image |
|
179 * @leave "" |
|
180 * Will leave with appropriate system codes if a problem is encountered reading the file |
|
181 * @return "CFbsBitmap*" |
|
182 * The bitmap read from the file |
|
183 * @xxxx |
|
184 * |
|
185 */ |
|
186 CFbsBitmap* CTestStepMediaSvr::LoadImageL(const TDesC& aFileName, TMdaClipFormat* aFormat, TMdaPackage* aCodec) |
|
187 { |
|
188 CFbsBitmap* bmp = new(ELeave) CFbsBitmap; |
|
189 CleanupStack::PushL(bmp); |
|
190 |
|
191 CMdaImageFileToBitmapUtility* ftob = CMdaImageFileToBitmapUtility::NewL(*this); |
|
192 CleanupStack::PushL(ftob); |
|
193 |
|
194 TFileName fileName = iDefaultPath; |
|
195 fileName.Append(aFileName); |
|
196 |
|
197 ftob->OpenL(fileName,aFormat,aCodec); |
|
198 WaitForResult(); |
|
199 User::LeaveIfError(iError); |
|
200 |
|
201 TFrameInfo frameInfo; |
|
202 |
|
203 // TODO: Note - doing it this way causes a corrupt iDecoder pointer to be |
|
204 // returned. Not sure why this happens at present time! |
|
205 // (CTestStepMediaSvr must be a friend of CMdaImageFileToBitmapUtility) |
|
206 // |
|
207 // CMdaImageFileToBitmapUtilityPriv* test = ftob->Properties(); |
|
208 // frameInfo = ftob->Properties()->iDecoder->FrameInfo(0); |
|
209 |
|
210 ftob->FrameInfo(0,frameInfo); |
|
211 |
|
212 User::LeaveIfError(bmp->Create(frameInfo.iOverallSizeInPixels,EColor16M)); |
|
213 ftob->ConvertL(*bmp,0); |
|
214 WaitForResult(); |
|
215 User::LeaveIfError(iError); |
|
216 CleanupStack::PopAndDestroy(); //ftob |
|
217 CleanupStack::Pop(); //bmp; |
|
218 return bmp; |
|
219 } |
|
220 /** |
|
221 * |
|
222 * Test loading a transparent image from a file |
|
223 * |
|
224 * @param "CFbsBitmap* aBitmap" |
|
225 * Bitmap to store the image |
|
226 * @param "CFbsBitmap* aMask" |
|
227 * Bitmap to store the mask |
|
228 * @param "TDesC& aFileName" |
|
229 * Name of file to load |
|
230 * @param "TMdaClipFormat* aFormat" |
|
231 * Format of the image |
|
232 * @param "TMdaPackage* aCodec" |
|
233 * Format of the image |
|
234 * @leave "" |
|
235 * Will leave with appropriate system codes if a problem is encountered reading the file |
|
236 * |
|
237 * @xxxx |
|
238 * |
|
239 */ |
|
240 void CTestStepMediaSvr::LoadTransparentImageL(CFbsBitmap* aBitmap, CFbsBitmap* aMask,const TDesC& aFileName, TMdaClipFormat* aFormat, TMdaPackage* aCodec) |
|
241 { |
|
242 CMdaImageFileToBitmapUtility* ftob = CMdaImageFileToBitmapUtility::NewL(*this); |
|
243 CleanupStack::PushL(ftob); |
|
244 |
|
245 TFileName fileName = iDefaultPath; |
|
246 fileName.Append(aFileName); |
|
247 |
|
248 ftob->OpenL(fileName,aFormat,aCodec); |
|
249 WaitForResult(); |
|
250 User::LeaveIfError(iError); |
|
251 |
|
252 TFrameInfo frameInfo; |
|
253 ftob->FrameInfo(0,frameInfo); |
|
254 User::LeaveIfError(aBitmap->Create(frameInfo.iOverallSizeInPixels,EGray2)); |
|
255 User::LeaveIfError(aMask->Create(frameInfo.iOverallSizeInPixels,EGray2)); |
|
256 ftob->ConvertL(*aBitmap,*aMask,0); |
|
257 WaitForResult(); |
|
258 CleanupStack::PopAndDestroy(); //ftob |
|
259 User::LeaveIfError(iError); |
|
260 } |
|
261 /** |
|
262 * |
|
263 * Test loading a transparent image from a file, specifying an incorrect format for the target |
|
264 * bitmaps. The Convert should fail gracefully |
|
265 * |
|
266 * @param "CFbsBitmap* aBitmap" |
|
267 * Bitmap to store the image |
|
268 * @param "CFbsBitmap* aMask" |
|
269 * Bitmap to store the mask |
|
270 * @param "TDesC& aFileName" |
|
271 * Name of file to load |
|
272 * @param "TMdaClipFormat* aFormat" |
|
273 * Format of the image |
|
274 * @param "TMdaPackage* aCodec" |
|
275 * Format of the image |
|
276 * @leave "" |
|
277 * Will leave with appropriate system codes if a problem is encountered opening |
|
278 * |
|
279 * @xxxx |
|
280 * |
|
281 */ |
|
282 void CTestStepMediaSvr::FailLoadTransparentImageL(CFbsBitmap* aBitmap, CFbsBitmap* aMask,const TDesC& aFileName, TMdaClipFormat* aFormat, TMdaPackage* aCodec) |
|
283 { |
|
284 CMdaImageFileToBitmapUtility* ftob = CMdaImageFileToBitmapUtility::NewL(*this); |
|
285 CleanupStack::PushL(ftob); |
|
286 |
|
287 TFileName fileName = iDefaultPath; |
|
288 fileName.Append(aFileName); |
|
289 |
|
290 ftob->OpenL(fileName,aFormat,aCodec); |
|
291 WaitForResult(); |
|
292 User::LeaveIfError(iError); |
|
293 |
|
294 TFrameInfo frameInfo; |
|
295 ftob->FrameInfo(0,frameInfo); |
|
296 User::LeaveIfError(aBitmap->Create(frameInfo.iOverallSizeInPixels,EColor4K)); |
|
297 User::LeaveIfError(aMask->Create(frameInfo.iOverallSizeInPixels,EColor4K)); |
|
298 ftob->ConvertL(*aBitmap,*aMask,0); |
|
299 WaitForResult(); |
|
300 CleanupStack::PopAndDestroy(); //ftob |
|
301 User::LeaveIfError(iError); |
|
302 } |
|
303 |
|
304 /** |
|
305 * |
|
306 * Tests loading an image from a file, cancelling and restarting the operation several times before |
|
307 * allowing the load to complete |
|
308 * |
|
309 * @param "TDesC& aFileName" |
|
310 * Name of file to load |
|
311 * @param "TMdaClipFormat* aFormat" |
|
312 * Format of the image |
|
313 * @param "TMdaPackage* aCodec" |
|
314 * Format of the image |
|
315 * @leave "" |
|
316 * Will leave with appropriate system codes if a problem is encountered reading the file |
|
317 * @return "CFbsBitmap*" |
|
318 * The bitmap read from the file |
|
319 * @xxxx |
|
320 * |
|
321 */ |
|
322 CFbsBitmap* CTestStepMediaSvr::CancelLoadImageL(const TDesC& imageFileName, TMdaClipFormat* aFormat, TMdaPackage* aCodec) |
|
323 { |
|
324 |
|
325 TFrameInfo frameInfo; |
|
326 |
|
327 CFbsBitmap* bmp = new(ELeave) CFbsBitmap; |
|
328 CleanupStack::PushL(bmp); |
|
329 |
|
330 |
|
331 CMdaImageFileToBitmapUtility* ftob = CMdaImageFileToBitmapUtility::NewL(*this); |
|
332 CleanupStack::PushL(ftob); |
|
333 |
|
334 TFileName fileName = iDefaultPath; |
|
335 fileName.Append(imageFileName); |
|
336 |
|
337 ftob->OpenL(fileName,aFormat,aCodec); |
|
338 |
|
339 WaitForResult(); |
|
340 User::LeaveIfError(iError); |
|
341 |
|
342 |
|
343 ftob->FrameInfo(0,frameInfo); |
|
344 User::LeaveIfError(bmp->Create(frameInfo.iOverallSizeInPixels,EColor16M)); |
|
345 ftob->ConvertL(*bmp,0); |
|
346 ftob->CancelConvertL(); |
|
347 ftob->ConvertL(*bmp,0); |
|
348 ftob->CancelConvertL(); |
|
349 |
|
350 ftob->ConvertL(*bmp,0); |
|
351 |
|
352 WaitForResult(); |
|
353 User::LeaveIfError(iError); |
|
354 CleanupStack::PopAndDestroy(); //ftob |
|
355 |
|
356 CleanupStack::Pop(); //bmp; |
|
357 return bmp; |
|
358 } |
|
359 /** |
|
360 * |
|
361 * Save an image to a File |
|
362 * |
|
363 * @param "CFbsBitmap* aBitmap" |
|
364 * Bitmap to write to file |
|
365 * @param "const TDesC& aImageFileName" |
|
366 * Filename to write to |
|
367 * @param "TMdaClipFormat* aFormat" |
|
368 * Format of the image |
|
369 * @param "TMdaPackage* aCodec" |
|
370 * Format of the image |
|
371 * @leave "" |
|
372 * Will leave with appropriate system codes if a problem is encountered writing the file |
|
373 * @xxxx |
|
374 * |
|
375 */ |
|
376 void CTestStepMediaSvr::SaveImageL(CFbsBitmap* aBitmap, const TDesC& aImageFileName, TMdaClipFormat* aFormat, TMdaPackage* aCodec) |
|
377 { |
|
378 CMdaImageBitmapToFileUtility* ftob = CMdaImageBitmapToFileUtility::NewL(*this); |
|
379 CleanupStack::PushL(ftob); |
|
380 |
|
381 TFileName fileName = iDefaultPath; |
|
382 fileName.Append(aImageFileName); |
|
383 ftob->CreateL(fileName,aFormat,aCodec,NULL); |
|
384 |
|
385 WaitForResult(); |
|
386 User::LeaveIfError(iError); |
|
387 |
|
388 ftob->ConvertL(*aBitmap,0); |
|
389 WaitForResult(); |
|
390 User::LeaveIfError(iError); |
|
391 |
|
392 CleanupStack::PopAndDestroy(); //ftob |
|
393 } |
|
394 /** |
|
395 * |
|
396 * Save an image to a File, cancelling and restarting the operation a few times before it |
|
397 * is allowed to complete |
|
398 * |
|
399 * @param "CFbsBitmap* aBitmap" |
|
400 * Bitmap to write to file |
|
401 * @param "const TDesC& aImageFileName" |
|
402 * Filename to write to |
|
403 * @param "TMdaClipFormat* aFormat" |
|
404 * Format of the image |
|
405 * @param "TMdaPackage* aCodec" |
|
406 * Format of the image |
|
407 * @leave "" |
|
408 * Will leave with appropriate system codes if a problem is encountered writing the file |
|
409 * @xxxx |
|
410 * |
|
411 */ |
|
412 void CTestStepMediaSvr::CancelSaveImageL(CFbsBitmap* aBitmap, const TDesC& aImageFileName, TMdaClipFormat* aFormat, TMdaPackage* aCodec) |
|
413 { |
|
414 CMdaImageBitmapToFileUtility* ftob = CMdaImageBitmapToFileUtility::NewL(*this); |
|
415 CleanupStack::PushL(ftob); |
|
416 |
|
417 TFileName fileName = iDefaultPath; |
|
418 fileName.Append(aImageFileName); |
|
419 ftob->CreateL(fileName,aFormat,aCodec,NULL); |
|
420 |
|
421 WaitForResult(); |
|
422 User::LeaveIfError(iError); |
|
423 |
|
424 ftob->ConvertL(*aBitmap,0); |
|
425 ftob->CancelConvertL(); |
|
426 ftob->ConvertL(*aBitmap,0); |
|
427 ftob->CancelConvertL(); |
|
428 ftob->ConvertL(*aBitmap,0); |
|
429 |
|
430 WaitForResult(); |
|
431 User::LeaveIfError(iError); |
|
432 |
|
433 CleanupStack::PopAndDestroy(); //ftob |
|
434 } |
|
435 |
|
436 /** |
|
437 * |
|
438 * Tests streaming an image from a descriptor |
|
439 * |
|
440 * @param "TPtr8 aImageBuffer" |
|
441 * Descriptor containing image |
|
442 * @param "TMdaClipFormat* aFormat" |
|
443 * Format of the image |
|
444 * @param "TMdaPackage* aCodec" |
|
445 * Format of the image |
|
446 * @leave "" |
|
447 * Will leave with appropriate system codes if a problem is encountered reading the file |
|
448 * @return "CFbsBitmap*" |
|
449 * The bitmap read from the descriptor |
|
450 * @xxxx |
|
451 * |
|
452 */ |
|
453 CFbsBitmap* CTestStepMediaSvr::StreamImageFromDescriptorL(const TPtr8& aImageBuffer, TMdaClipFormat* aFormat, TMdaPackage* aCodec) |
|
454 { |
|
455 CFbsBitmap* bmp = new(ELeave) CFbsBitmap; |
|
456 CleanupStack::PushL(bmp); |
|
457 |
|
458 CMdaImageDescToBitmapUtility* dtob = CMdaImageDescToBitmapUtility::NewL(*this); |
|
459 CleanupStack::PushL(dtob); |
|
460 dtob->OpenL(aImageBuffer,aFormat,aCodec); |
|
461 WaitForResult(); |
|
462 User::LeaveIfError(iError); |
|
463 |
|
464 TFrameInfo frameInfo; |
|
465 dtob->FrameInfo(0,frameInfo); |
|
466 User::LeaveIfError(bmp->Create(frameInfo.iOverallSizeInPixels,EColor16M)); |
|
467 |
|
468 TPtr8& buf = CONST_CAST(TPtr8&,aImageBuffer); // we can't modify const parameter, so make a copy |
|
469 TInt len = buf.Length(); |
|
470 TInt templen = 1; |
|
471 dtob->ConvertL(*bmp,0); |
|
472 WaitForResult(); |
|
473 while (iError==KErrUnderflow && templen < len) |
|
474 { |
|
475 if (len - templen <128) |
|
476 templen+=128; |
|
477 else |
|
478 templen = len; |
|
479 |
|
480 buf.SetLength(templen); |
|
481 dtob->ConvertL(*bmp,0); |
|
482 WaitForResult(); |
|
483 } |
|
484 User::LeaveIfError(iError); |
|
485 CleanupStack::PopAndDestroy(); // dtob |
|
486 CleanupStack::Pop(); // bmp |
|
487 return bmp; |
|
488 } |
|
489 |
|
490 /** |
|
491 * |
|
492 * Tests streaming an image from a file |
|
493 * |
|
494 * @param "TDesC& aFileName" |
|
495 * Name of file to load |
|
496 * @param "TMdaClipFormat* aFormat" |
|
497 * Format of the image |
|
498 * @param "TMdaPackage* aCodec" |
|
499 * Format of the image |
|
500 * @leave "" |
|
501 * Will leave with appropriate system codes if a problem is encountered reading the file |
|
502 * @return "CFbsBitmap*" |
|
503 * The bitmap read |
|
504 * @xxxx |
|
505 * |
|
506 */ |
|
507 CFbsBitmap* CTestStepMediaSvr::StreamImageL(const TDesC& aFileName, TMdaClipFormat* aFormat, TMdaPackage* aCodec) |
|
508 { |
|
509 CFbsBitmap* bmp = new(ELeave) CFbsBitmap; |
|
510 CleanupStack::PushL(bmp); |
|
511 |
|
512 TBuf<256> tempFileName; |
|
513 |
|
514 |
|
515 RFile srcFile, tempFile; |
|
516 RFs fs; |
|
517 User::LeaveIfError(fs.Connect()); |
|
518 CleanupClosePushL(fs); |
|
519 |
|
520 TFileName fileName = iDefaultPath; |
|
521 fileName.Append(aFileName); |
|
522 User::LeaveIfError(srcFile.Open(fs,fileName,EFileShareAny|EFileStream|EFileRead)); |
|
523 CleanupClosePushL(srcFile); |
|
524 |
|
525 User::LeaveIfError(tempFile.Temp(fs,_L("c:\\"),tempFileName,EFileShareAny|EFileStream|EFileWrite)); |
|
526 CleanupClosePushL(tempFile); |
|
527 |
|
528 TInt fileSize; |
|
529 |
|
530 TInt copySize = 128; |
|
531 |
|
532 User::LeaveIfError(srcFile.Size(fileSize)); |
|
533 HBufC8* copyBuf = HBufC8::NewMaxLC(copySize); |
|
534 TPtr8 copyBufPtr(copyBuf->Des()); |
|
535 |
|
536 TInt templen = copySize; |
|
537 |
|
538 User::LeaveIfError(srcFile.Read(copyBufPtr,copySize)); |
|
539 User::LeaveIfError(tempFile.Write(copyBufPtr,copySize)); |
|
540 |
|
541 CMdaImageFileToBitmapUtility* ftob = CMdaImageFileToBitmapUtility::NewL(*this); |
|
542 CleanupStack::PushL(ftob); |
|
543 |
|
544 ftob->OpenL(tempFileName,aFormat,aCodec); |
|
545 WaitForResult(); |
|
546 User::LeaveIfError(iError); |
|
547 |
|
548 TFrameInfo frameInfo; |
|
549 ftob->FrameInfo(0,frameInfo); |
|
550 User::LeaveIfError(bmp->Create(frameInfo.iOverallSizeInPixels,EColor16M)); |
|
551 |
|
552 |
|
553 ftob->ConvertL(*bmp,0); |
|
554 WaitForResult(); |
|
555 while (iError==KErrUnderflow && templen < fileSize) |
|
556 { |
|
557 TInt copySize; |
|
558 if (fileSize - templen >128) |
|
559 copySize=128; |
|
560 else |
|
561 copySize= fileSize - templen; |
|
562 |
|
563 User::LeaveIfError(srcFile.Read(copyBufPtr,copySize)); |
|
564 User::LeaveIfError(tempFile.Write(copyBufPtr,copySize)); |
|
565 templen+=copySize; |
|
566 |
|
567 ftob->ConvertL(*bmp,0); |
|
568 WaitForResult(); |
|
569 } |
|
570 User::LeaveIfError(iError); |
|
571 |
|
572 srcFile.Close(); |
|
573 |
|
574 CleanupStack::PopAndDestroy(); // ftob, must close in order to delete the temporary file |
|
575 |
|
576 tempFile.Close(); |
|
577 fs.Delete(tempFileName); |
|
578 |
|
579 CleanupStack::PopAndDestroy(4); // tempFile,srcFile, copyBuf, fs |
|
580 CleanupStack::Pop(); // bmp |
|
581 return bmp; |
|
582 } |
|
583 /** |
|
584 * |
|
585 * Tests loading an image from a File, with additional alloc failure testing |
|
586 * |
|
587 * @param "const TDesC& aImageFileName" |
|
588 * Filename of the image to load |
|
589 * @param "TMdaClipFormat* aFormat" |
|
590 * Format of the image |
|
591 * @param "TMdaPackage* aCodec" |
|
592 * Format of the image |
|
593 * @leave "" |
|
594 * Will leave with appropriate system codes if a problem is encountered reading the file |
|
595 * @return "CFbsBitmap*" |
|
596 * The bitmap read from the descriptor |
|
597 * @xxxx |
|
598 * |
|
599 */ |
|
600 CFbsBitmap* CTestStepMediaSvr::LoadImageWithAllocFailL(const TDesC& aImageFileName, TMdaClipFormat* aFormat, TMdaPackage* aCodec) |
|
601 { |
|
602 TInt failCount = 1; |
|
603 TInt err; |
|
604 |
|
605 CFbsBitmap* bmp = NULL; |
|
606 |
|
607 TRAP(err,bmp = LoadImageL(aImageFileName,aFormat,aCodec)); |
|
608 CleanupStack::PushL(bmp); |
|
609 User::LeaveIfError(err); |
|
610 |
|
611 CleanupStack::PopAndDestroy();//bmp |
|
612 |
|
613 for(;;) { |
|
614 __UHEAP_SETFAIL(RHeap::EDeterministic, failCount); |
|
615 |
|
616 TRAP(err,bmp = LoadImageL(aImageFileName,aFormat,aCodec)); |
|
617 |
|
618 |
|
619 if (err != KErrNoMemory && err != KErrNone) |
|
620 User::Leave(err); |
|
621 |
|
622 __UHEAP_SETFAIL(RHeap::ENone, 0); |
|
623 |
|
624 if (err!=KErrNoMemory) |
|
625 break; |
|
626 |
|
627 ++failCount; |
|
628 } |
|
629 --failCount; // we are one over |
|
630 INFO_PRINTF2(_L("Completed OK with %d memory allocations tested"),failCount); |
|
631 return bmp; |
|
632 } |
|
633 /** |
|
634 * |
|
635 * Tests saving an image to a File, with additional alloc failure testing |
|
636 * |
|
637 * @param "CFbsBitmap* aBitmap" |
|
638 * Bitmap to write to file |
|
639 * @param "const TDesC& aImageFileName" |
|
640 * Filename to write to |
|
641 * @param "TMdaClipFormat* aFormat" |
|
642 * Format of the image |
|
643 * @param "TMdaPackage* aCodec" |
|
644 * Format of the image |
|
645 * @leave "" |
|
646 * Will leave with appropriate system codes if a problem is encountered writing the file |
|
647 * @xxxx |
|
648 * |
|
649 */ |
|
650 void CTestStepMediaSvr::SaveImageWithAllocFailL(CFbsBitmap* aBitmap, const TDesC& aImageFileName, TMdaClipFormat* aFormat, TMdaPackage* aCodec) |
|
651 { |
|
652 TInt failCount = 1; |
|
653 TInt err; |
|
654 |
|
655 __MM_HEAP_MARK; |
|
656 TRAP(err, SaveImageL(aBitmap, aImageFileName,aFormat,aCodec)); |
|
657 User::LeaveIfError(err); |
|
658 __MM_HEAP_MARKEND; |
|
659 |
|
660 for(;;) { |
|
661 __UHEAP_SETFAIL(RHeap::EDeterministic, failCount); |
|
662 __MM_HEAP_MARK; |
|
663 TRAP(err, SaveImageL(aBitmap, aImageFileName,aFormat,aCodec)); |
|
664 |
|
665 if (err != KErrNoMemory && err != KErrNone) |
|
666 User::Leave(err); |
|
667 |
|
668 __MM_HEAP_MARKEND; |
|
669 __UHEAP_SETFAIL(RHeap::ENone, 0); |
|
670 |
|
671 if (err!=KErrNoMemory) |
|
672 break; |
|
673 |
|
674 ++failCount; |
|
675 } |
|
676 --failCount; // we are one over |
|
677 |
|
678 INFO_PRINTF2(_L("Completed OK with %d memory allocations tested"),failCount); |
|
679 } |
|
680 /** |
|
681 * |
|
682 * Tests streaming an image from a descriptor, with additional alloc failure testing |
|
683 * |
|
684 * @param "TPtr8 aImageBuffer" |
|
685 * Descriptor containing image |
|
686 * @param "TMdaClipFormat* aFormat" |
|
687 * Format of the image |
|
688 * @param "TMdaPackage* aCodec" |
|
689 * Format of the image |
|
690 * @leave "" |
|
691 * Will leave with appropriate system codes if a problem is encountered reading the file |
|
692 * @return "CFbsBitmap*" |
|
693 * The bitmap read from the descriptor |
|
694 * @xxxx |
|
695 * |
|
696 */ |
|
697 CFbsBitmap* CTestStepMediaSvr::StreamImageFromDescWithAllocFailL(const TPtr8& aImageBuffer, TMdaClipFormat* aFormat, TMdaPackage* aCodec) |
|
698 { |
|
699 TInt failCount = 1; |
|
700 TInt err; |
|
701 |
|
702 CFbsBitmap* bmp = NULL; |
|
703 |
|
704 __MM_HEAP_MARK; |
|
705 TRAP(err,bmp = StreamImageFromDescriptorL(aImageBuffer,aFormat,aCodec)); |
|
706 CleanupStack::PushL(bmp); |
|
707 User::LeaveIfError(err); |
|
708 |
|
709 |
|
710 CleanupStack::PopAndDestroy(); //bmp |
|
711 __MM_HEAP_MARKEND; |
|
712 |
|
713 for(;;) |
|
714 { |
|
715 __UHEAP_SETFAIL(RHeap::EDeterministic, failCount); |
|
716 |
|
717 TRAP(err,bmp = StreamImageFromDescriptorL(aImageBuffer,aFormat,aCodec)); |
|
718 |
|
719 if (err != KErrNoMemory && err != KErrNone) |
|
720 User::Leave(err); |
|
721 |
|
722 __UHEAP_SETFAIL(RHeap::ENone, 0); |
|
723 |
|
724 if (err!=KErrNoMemory) |
|
725 break; |
|
726 |
|
727 ++failCount; |
|
728 } |
|
729 --failCount; // we are one over |
|
730 |
|
731 INFO_PRINTF2(_L("Completed OK with %d memory allocations tested"),failCount); |
|
732 return bmp; |
|
733 } |
|
734 /** |
|
735 * |
|
736 * Check that the contents of the two bitmaps provided are identical |
|
737 * |
|
738 * @param "CFbsBitmap& aBitmap1" |
|
739 * The first bitmap to compare |
|
740 * @param "CFbsBitmap& aBitmap2" |
|
741 * The second bitmap to compare |
|
742 * @return "TVerdict" |
|
743 * EPass if the files are identical |
|
744 * EFail otherwise |
|
745 * @xxxx |
|
746 * |
|
747 */ |
|
748 TVerdict CTestStepMediaSvr::CheckBitmaps(const CFbsBitmap& aBitmap1, const CFbsBitmap& aBitmap2) const |
|
749 { |
|
750 const TSize size = aBitmap1.SizeInPixels(); |
|
751 |
|
752 for (TInt y = 0; y < size.iHeight; y++) |
|
753 { |
|
754 for (TInt x = 0; x < size.iWidth; x++) |
|
755 { |
|
756 TPoint pt(x,y); |
|
757 TRgb color1,color2; |
|
758 aBitmap1.GetPixel(color1,pt); |
|
759 aBitmap2.GetPixel(color2,pt); |
|
760 |
|
761 if (color1 != color2) |
|
762 { |
|
763 return EFail; |
|
764 } |
|
765 } |
|
766 } |
|
767 return EPass; |
|
768 } |
|
769 /* |
|
770 * |
|
771 * Writes an image to a descriptor |
|
772 * |
|
773 * @param "CFbsBitmap* aBitmap" |
|
774 * Bitmap to write to descriptor |
|
775 * @param "TMdaClipFormat* aFormat" |
|
776 * Format of the image |
|
777 * @param "TMdaPackage* aCodec" |
|
778 * Format of the image |
|
779 * @param "TInt aDesSize" |
|
780 * Optional explicit setting of the descriptor size to use |
|
781 * @leave "" |
|
782 * Will leave with appropriate system codes if a problem is encountered reading the file |
|
783 * @return "HBufC8*" |
|
784 * The descriptor containing the image |
|
785 * @xxxx |
|
786 * |
|
787 */ |
|
788 HBufC8* CTestStepMediaSvr::WriteImageToDescriptorL(CFbsBitmap* aBitmap, TMdaClipFormat* aFormat, TMdaPackage* aCodec, TInt aDesSize) |
|
789 { |
|
790 const TSize size = aBitmap->SizeInPixels(); |
|
791 const TInt descSize = aDesSize>0 ? aDesSize : ((size.iWidth * size.iHeight * 3) + 10000); |
|
792 HBufC8* descBuf = HBufC8::NewLC(descSize); |
|
793 TPtr8 imageBuffer(descBuf->Des()); |
|
794 |
|
795 CMdaImageBitmapToDescUtility* btod = CMdaImageBitmapToDescUtility::NewL(*this); |
|
796 CleanupStack::PushL(btod); |
|
797 btod->CreateL(imageBuffer,aFormat,aCodec,NULL); |
|
798 WaitForResult(); |
|
799 User::LeaveIfError(iError); |
|
800 btod->ConvertL(*aBitmap); |
|
801 WaitForResult(); |
|
802 User::LeaveIfError(iError); |
|
803 CleanupStack::PopAndDestroy(); // btod |
|
804 CleanupStack::Pop(); // descBuf |
|
805 return descBuf; |
|
806 } |
|
807 |
|
808 /** |
|
809 * |
|
810 * Reads an image from a descriptor |
|
811 * |
|
812 * @param "TPtr8 aImageBuffer" |
|
813 * Descriptor containing image |
|
814 * @param "TMdaClipFormat* aFormat" |
|
815 * Format of the image |
|
816 * @param "TMdaPackage* aCodec" |
|
817 * Format of the image |
|
818 * @leave "" |
|
819 * Will leave with appropriate system codes if a problem is encountered reading the file |
|
820 * @return "CFbsBitmap*" |
|
821 * The bitmap read from the descriptor |
|
822 * @xxxx |
|
823 * |
|
824 */ |
|
825 CFbsBitmap* CTestStepMediaSvr::ReadImageFromDescriptorL(const TPtr8& aImageBuffer, TMdaClipFormat* aFormat, TMdaPackage* aCodec) |
|
826 { |
|
827 CFbsBitmap* bmp = new(ELeave) CFbsBitmap; |
|
828 CleanupStack::PushL(bmp); |
|
829 |
|
830 CMdaImageDescToBitmapUtility* dtob = CMdaImageDescToBitmapUtility::NewL(*this); |
|
831 CleanupStack::PushL(dtob); |
|
832 dtob->OpenL(aImageBuffer,aFormat,aCodec); |
|
833 WaitForResult(); |
|
834 User::LeaveIfError(iError); |
|
835 |
|
836 TFrameInfo frameInfo; |
|
837 dtob->FrameInfo(0,frameInfo); |
|
838 User::LeaveIfError(bmp->Create(frameInfo.iOverallSizeInPixels,EColor16M)); |
|
839 dtob->ConvertL(*bmp,0); |
|
840 WaitForResult(); |
|
841 User::LeaveIfError(iError); |
|
842 CleanupStack::PopAndDestroy(); // dtob |
|
843 CleanupStack::Pop(); // bmp |
|
844 return bmp; |
|
845 } |
|
846 /** |
|
847 * |
|
848 * Writes a message to the log. Intended for tests which have multiple test |
|
849 * cases |
|
850 * |
|
851 * @param "TDesC& aContext" |
|
852 * The context of the failure eg. The test file that gave rise to the message |
|
853 * @param "TDesC& aMessage" |
|
854 * A message to log |
|
855 * @xxxx |
|
856 * |
|
857 */ |
|
858 void CTestStepMediaSvr::LogMessage(const TDesC& aContext, const TDesC& aMessage) |
|
859 { |
|
860 INFO_PRINTF3(_L("%S: %S"),&aContext,&aMessage); |
|
861 } |
|
862 |
|
863 /** |
|
864 * |
|
865 * Writes a error to the log. Intended for tests which have multiple test |
|
866 * cases |
|
867 * |
|
868 * @param "TDesC& aContext" |
|
869 * The context of the failure eg. The test file that gave rise to the message |
|
870 * @param "TDesC& aMessage" |
|
871 * A message to log |
|
872 * @xxxx |
|
873 * |
|
874 */ |
|
875 void CTestStepMediaSvr::LogError(const TDesC& aContext, const TDesC& aMessage) |
|
876 { |
|
877 ERR_PRINTF3(_L("%S: %S"),&aContext,&aMessage); |
|
878 } |
|
879 |
|
880 /** |
|
881 * |
|
882 * Compare two binary files |
|
883 * |
|
884 * @param "const TDesC& aFile1" |
|
885 * The first file to compare |
|
886 * @param "const TDesC& aFile2" |
|
887 * The second file to compare |
|
888 * @leave "" |
|
889 * Will leave with appropriate system codes if a problem is encountered reading either file |
|
890 * @return "TVerdict" |
|
891 * EPass if the files are identical |
|
892 * EFail otherwise |
|
893 * @xxxx |
|
894 * |
|
895 */ |
|
896 TVerdict CTestStepMediaSvr::CompareFilesL(const TDesC& aFile1,const TDesC& aFile2) const |
|
897 { |
|
898 RFile file1, file2; |
|
899 RFs fs; |
|
900 User::LeaveIfError(fs.Connect()); |
|
901 CleanupClosePushL(fs); |
|
902 |
|
903 TFileName fileName1 = iDefaultPath; |
|
904 fileName1.Append(aFile1); |
|
905 User::LeaveIfError(file1.Open(fs,fileName1,EFileShareAny|EFileStream|EFileRead)); |
|
906 CleanupClosePushL(file1); |
|
907 |
|
908 TFileName fileName2 = iDefaultPath; |
|
909 fileName2.Append(aFile2); |
|
910 User::LeaveIfError(file2.Open(fs,fileName2,EFileShareAny|EFileStream|EFileRead)); |
|
911 CleanupClosePushL(file2); |
|
912 |
|
913 TInt fileSize1, fileSize2; |
|
914 |
|
915 TVerdict result = EPass; |
|
916 TInt blockSize = 1024; |
|
917 |
|
918 User::LeaveIfError(file1.Size(fileSize1)); |
|
919 User::LeaveIfError(file2.Size(fileSize2)); |
|
920 |
|
921 if (fileSize1 == fileSize2) |
|
922 { |
|
923 HBufC8* buf1 = HBufC8::NewMaxLC(blockSize); |
|
924 TPtr8 buf1Ptr(buf1->Des()); |
|
925 HBufC8* buf2 = HBufC8::NewMaxLC(blockSize); |
|
926 TPtr8 buf2Ptr(buf2->Des()); |
|
927 |
|
928 TInt length = 0; |
|
929 |
|
930 while (length<fileSize1 && result == EPass) |
|
931 { |
|
932 TInt copySize; |
|
933 |
|
934 if (fileSize1 - length > blockSize) |
|
935 copySize = blockSize; |
|
936 else |
|
937 copySize = fileSize1 - length; |
|
938 User::LeaveIfError(file1.Read(buf1Ptr,copySize)); |
|
939 User::LeaveIfError(file2.Read(buf2Ptr,copySize)); |
|
940 |
|
941 if (Mem::Compare(buf1Ptr.Ptr(),copySize,buf2Ptr.Ptr(),copySize)!=0) |
|
942 result = EFail; |
|
943 |
|
944 length += copySize; |
|
945 } |
|
946 CleanupStack::PopAndDestroy(2); // buf1, buf2 |
|
947 } |
|
948 else |
|
949 result = EFail; |
|
950 |
|
951 file1.Close(); |
|
952 file2.Close(); |
|
953 fs.Close(); |
|
954 |
|
955 CleanupStack::PopAndDestroy(3); //fs, file1, file2 |
|
956 |
|
957 return result; |
|
958 } |
|
959 /** |
|
960 * |
|
961 * Retrieves frame info from a file |
|
962 * |
|
963 * @param "TDesC& aFileName" |
|
964 * Name of file to open |
|
965 * @param "TMdaClipFormat* aFormat" |
|
966 * Format of the image |
|
967 * @param "TMdaPackage* aCodec" |
|
968 * Format of the image |
|
969 * @leave "" |
|
970 * Will leave with appropriate system codes if a problem is encountered opening the file |
|
971 * @return "TFrameInfo" |
|
972 * The frame information |
|
973 * @xxxx |
|
974 * |
|
975 */ |
|
976 TFrameInfo CTestStepMediaSvr::GetFrameInfoL(const TDesC& aFileName, TMdaClipFormat* aFormat, TMdaPackage* aCodec) |
|
977 { |
|
978 CMdaImageFileToBitmapUtility* ftob = CMdaImageFileToBitmapUtility::NewL(*this); |
|
979 CleanupStack::PushL(ftob); |
|
980 |
|
981 TFileName fileName = iDefaultPath; |
|
982 fileName.Append(aFileName); |
|
983 |
|
984 ftob->OpenL(fileName,aFormat,aCodec); |
|
985 WaitForResult(); |
|
986 User::LeaveIfError(iError); |
|
987 TFrameInfo frameInfo; |
|
988 ftob->FrameInfo(0,frameInfo); |
|
989 CleanupStack::PopAndDestroy(); //ftob |
|
990 return frameInfo; |
|
991 } |