|
1 // Copyright (c) 1999-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 // TMDAVID6.CPP |
|
15 // |
|
16 // |
|
17 |
|
18 #include "tmdatest.h" |
|
19 |
|
20 /* |
|
21 |
|
22 Tests: |
|
23 File -> Bitmap with alloc failure |
|
24 File -> Bitmap streaming with alloc failure |
|
25 Bitmap -> File with alloc failure |
|
26 |
|
27 */ |
|
28 |
|
29 // |
|
30 // CTestImageIO |
|
31 // walking class that does image reads and writes. Exploits asynchronous behaviour |
|
32 // of own properties. Calls are essentially synchronous using AS recursion |
|
33 // |
|
34 |
|
35 const TInt KViaDesIncrement = 0x1000; |
|
36 const TInt KTempHeapSize = 0x100000; // 1M 0x20000; // 128K |
|
37 |
|
38 class CTestImageIO : public CBase, public MMdaImageUtilObserver |
|
39 { |
|
40 // New data types |
|
41 protected: |
|
42 enum TOperation {ERead, EReadViaDes, EReadViaFile, EWrite}; |
|
43 enum TState {EStateIdle, EStateOpening, EStateConverting}; |
|
44 // Construction, Destruction |
|
45 public: |
|
46 static CTestImageIO *NewL(RFs &aFs); |
|
47 static CTestImageIO *NewLC(RFs &aFs); |
|
48 ~CTestImageIO(); |
|
49 protected: |
|
50 CTestImageIO(RFs &aFs); |
|
51 void ConstructL(); |
|
52 // New public functions |
|
53 public: |
|
54 void ReadL(CFbsBitmap& aBitmap, const TDesC& aFileName, TInt aZoomFactor); |
|
55 void ReadViaDesL(CFbsBitmap& aBitmap, const TDesC& aFileName, TInt aZoomFactor); |
|
56 void ReadViaFileL(CFbsBitmap& aBitmap, const TDesC& aFileName, TInt aZoomFactor); |
|
57 void WriteL(CFbsBitmap& aBitmap, const TDesC& aFileName, TMdaClipFormat* aFormat,TMdaPackage* aCodec); |
|
58 // Virtual functions from MMdaImageUtilObserver |
|
59 protected: |
|
60 virtual void MiuoCreateComplete(TInt aError); |
|
61 virtual void MiuoOpenComplete(TInt aError); |
|
62 virtual void MiuoConvertComplete(TInt aError); |
|
63 // Helper functions |
|
64 protected: |
|
65 void Leave(TInt aError); |
|
66 void OpenOrigAndTempFilesL(); |
|
67 void CloseOrigAndTempFiles(); |
|
68 void CopyFileToTempL(TInt aSize); |
|
69 void ResetStreamBufferedSize(); |
|
70 void IncrementStreamBufferedSize(); |
|
71 TInt StreamBufferedSize() const { return iBufferedSize; } |
|
72 // Data properties: |
|
73 protected: |
|
74 CMdaImageUtility* iUtility; |
|
75 TOperation iOperation; |
|
76 TState iState; |
|
77 TInt iReturnedError; |
|
78 TPtr8 iBuffer; // used in via des streaming |
|
79 TPtr8 iCopyBuffer; |
|
80 TInt iBufferedSize; // running required buffer size for streaming |
|
81 TInt iFileSize; |
|
82 TInt iZoomFactor; |
|
83 RFile iOrigFile; // used in ReadViaFileL |
|
84 RFile iTempFile; |
|
85 TInt iTempFileSize; |
|
86 // Linked data |
|
87 CFbsBitmap* iBitmap; |
|
88 TPtrC iFileName; |
|
89 RFs& iFs; |
|
90 }; |
|
91 |
|
92 CTestImageIO* CTestImageIO::NewL(RFs &aFs) |
|
93 { |
|
94 CTestImageIO* result = NewLC(aFs); |
|
95 CleanupStack::Pop(); |
|
96 return result; |
|
97 } |
|
98 |
|
99 CTestImageIO* CTestImageIO::NewLC(RFs &aFs) |
|
100 { |
|
101 CTestImageIO* result = new (ELeave) CTestImageIO(aFs); |
|
102 CleanupStack::PushL(result); |
|
103 result->ConstructL(); |
|
104 return result; |
|
105 } |
|
106 |
|
107 CTestImageIO::CTestImageIO(RFs &aFs): |
|
108 iBuffer(NULL, 0, 0), |
|
109 iCopyBuffer(NULL, 0, 0), |
|
110 iFs(aFs) |
|
111 { |
|
112 } |
|
113 |
|
114 void CTestImageIO::ConstructL() |
|
115 { |
|
116 const TInt copySize=KViaDesIncrement; |
|
117 iCopyBuffer.Set(STATIC_CAST(TUint8*, User::AllocL(copySize)), 0, copySize); |
|
118 } |
|
119 |
|
120 CTestImageIO::~CTestImageIO() |
|
121 { |
|
122 delete iUtility; |
|
123 User::Free(REINTERPRET_CAST(TAny*,CONST_CAST(TUint8*, iBuffer.Ptr()))); |
|
124 User::Free(REINTERPRET_CAST(TAny*,CONST_CAST(TUint8*, iCopyBuffer.Ptr()))); |
|
125 CloseOrigAndTempFiles(); |
|
126 } |
|
127 |
|
128 void CTestImageIO::Leave(TInt aError) |
|
129 { |
|
130 iReturnedError = aError; |
|
131 CActiveScheduler::Stop(); |
|
132 } |
|
133 |
|
134 void CTestImageIO::OpenOrigAndTempFilesL() |
|
135 { |
|
136 User::LeaveIfError(iOrigFile.Open(iFs, iFileName, EFileShareReadersOnly|EFileStream|EFileRead)); |
|
137 User::LeaveIfError(iTempFile.Replace(iFs, KFailVideoTempTestFileName, EFileShareAny|EFileStream|EFileWrite)); |
|
138 iTempFileSize = 0; |
|
139 } |
|
140 |
|
141 void CTestImageIO::CloseOrigAndTempFiles() |
|
142 { |
|
143 iOrigFile.Close(); |
|
144 iTempFile.Close(); |
|
145 } |
|
146 |
|
147 void CTestImageIO::CopyFileToTempL(TInt aSize) |
|
148 { |
|
149 TInt copySize = aSize - iTempFileSize; |
|
150 ASSERT(copySize >= 0); // should not occur |
|
151 |
|
152 if(copySize == 0) |
|
153 return; |
|
154 |
|
155 User::LeaveIfError(iOrigFile.Read(iCopyBuffer, copySize)); |
|
156 |
|
157 ASSERT(iCopyBuffer.Length() == copySize); // should not have any shortfall |
|
158 |
|
159 User::LeaveIfError(iTempFile.Write(iCopyBuffer)); |
|
160 |
|
161 iTempFileSize += copySize; |
|
162 } |
|
163 |
|
164 void CTestImageIO::ResetStreamBufferedSize() |
|
165 { |
|
166 ASSERT(iFileSize>0); // don't copy with real empty files |
|
167 iBufferedSize = 1; // start stream at size 1 |
|
168 } |
|
169 |
|
170 void CTestImageIO::IncrementStreamBufferedSize() |
|
171 { |
|
172 TInt newSize; |
|
173 if (iBufferedSize < 100) |
|
174 newSize = iBufferedSize + 1; |
|
175 else |
|
176 newSize = iBufferedSize + KViaDesIncrement; |
|
177 iBufferedSize = Min(iFileSize, newSize); |
|
178 #if defined(_DEBUG) && 0 |
|
179 RDebug::Print(_L("IncrementStreamBuffer->%d"), iBufferedSize); |
|
180 #endif defined(_DEBUG) |
|
181 } |
|
182 |
|
183 |
|
184 void CTestImageIO::ReadL(CFbsBitmap& aBitmap, const TDesC& aFileName, TInt aZoomFactor) |
|
185 { |
|
186 ASSERT(iState==EStateIdle); // ensure in idle state |
|
187 delete iUtility; iUtility=NULL; // could be non-NULL if previous error |
|
188 |
|
189 iFileName.Set(aFileName); // remember parameters |
|
190 iBitmap = &aBitmap; |
|
191 iZoomFactor = aZoomFactor; |
|
192 |
|
193 iOperation = ERead; |
|
194 |
|
195 iUtility = CMdaImageFileToBitmapUtility::NewL(*this, NULL); |
|
196 CMdaImageFileToBitmapUtility* utility = STATIC_CAST(CMdaImageFileToBitmapUtility*, iUtility); |
|
197 utility->OpenL(iFileName); |
|
198 iState = EStateOpening; |
|
199 CActiveScheduler::Start(); // recurse into AO |
|
200 |
|
201 ASSERT(iState == EStateIdle); // we should have come back here |
|
202 delete iUtility; iUtility = NULL; |
|
203 |
|
204 User::LeaveIfError(iReturnedError); |
|
205 } |
|
206 |
|
207 void CTestImageIO::ReadViaDesL(CFbsBitmap& aBitmap, const TDesC& aFileName, TInt aZoomFactor) |
|
208 { |
|
209 ASSERT(iState==EStateIdle); // ensure in idle state |
|
210 delete iUtility; iUtility=NULL; // could be non-NULL if previous error |
|
211 |
|
212 iFileName.Set(aFileName); // remember parameters |
|
213 iBitmap = &aBitmap; |
|
214 iZoomFactor = aZoomFactor; |
|
215 |
|
216 iOperation = EReadViaDes; |
|
217 |
|
218 // read the whole of the original file into a buffer of the correct size |
|
219 RFile file; |
|
220 User::LeaveIfError(file.Open(iFs, aFileName, EFileShareReadersOnly|EFileStream|EFileRead)); |
|
221 CleanupClosePushL(file); |
|
222 User::LeaveIfError(file.Size(iFileSize)); |
|
223 iBuffer.Set(STATIC_CAST(TUint8 *, User::AllocL(iFileSize)), 0, iFileSize); |
|
224 User::LeaveIfError(file.Read(iBuffer)); |
|
225 CleanupStack::PopAndDestroy(); // file |
|
226 |
|
227 ResetStreamBufferedSize(); // initial bit we try to read |
|
228 iBuffer.SetLength(StreamBufferedSize()); |
|
229 |
|
230 iUtility = CMdaImageDescToBitmapUtility::NewL(*this, NULL); |
|
231 CMdaImageDescToBitmapUtility* utility = STATIC_CAST(CMdaImageDescToBitmapUtility*, iUtility); |
|
232 utility->OpenL(iBuffer); |
|
233 iState = EStateOpening; |
|
234 CActiveScheduler::Start(); // recurse into AO |
|
235 |
|
236 ASSERT(iState == EStateIdle); // we should have come back here |
|
237 delete iUtility; iUtility = NULL; |
|
238 |
|
239 User::LeaveIfError(iReturnedError); |
|
240 } |
|
241 |
|
242 void CTestImageIO::ReadViaFileL(CFbsBitmap& aBitmap, const TDesC& aFileName, TInt aZoomFactor) |
|
243 { |
|
244 ASSERT(iState==EStateIdle); // ensure in idle state |
|
245 delete iUtility; iUtility=NULL; // could be non-NULL if previous error |
|
246 |
|
247 iFileName.Set(aFileName); // remember parameters |
|
248 iBitmap = &aBitmap; |
|
249 iZoomFactor = aZoomFactor; |
|
250 |
|
251 iOperation = EReadViaFile; |
|
252 |
|
253 TEntry entry; |
|
254 User::LeaveIfError(iFs.Entry(iFileName, entry)); |
|
255 iFileSize = entry.iSize; |
|
256 |
|
257 // copy bytes from the original file, as required |
|
258 OpenOrigAndTempFilesL(); |
|
259 ResetStreamBufferedSize(); // initial bit we try to read |
|
260 CopyFileToTempL(StreamBufferedSize()); |
|
261 |
|
262 iUtility = CMdaImageFileToBitmapUtility::NewL(*this, NULL); |
|
263 CMdaImageFileToBitmapUtility* utility = STATIC_CAST(CMdaImageFileToBitmapUtility*, iUtility); |
|
264 TPtrC tempFileName(KFailVideoTempTestFileName); |
|
265 utility->OpenL(tempFileName); |
|
266 iState = EStateOpening; |
|
267 CActiveScheduler::Start(); // recurse into AO |
|
268 |
|
269 ASSERT(iState == EStateIdle); // we should have come back here |
|
270 delete iUtility; iUtility = NULL; |
|
271 |
|
272 CloseOrigAndTempFiles(); |
|
273 (void) iFs.Delete(KFailVideoTempTestFileName); // delete temp file |
|
274 |
|
275 User::LeaveIfError(iReturnedError); |
|
276 } |
|
277 |
|
278 void CTestImageIO::WriteL(CFbsBitmap& aBitmap, const TDesC& aFileName, TMdaClipFormat* aFormat,TMdaPackage* aCodec) |
|
279 { |
|
280 ASSERT(iState==EStateIdle); // ensure in idle state |
|
281 delete iUtility; iUtility=NULL; // could be non-NULL if previous error |
|
282 |
|
283 iFileName.Set(aFileName); // remember parameters |
|
284 iBitmap = &aBitmap; |
|
285 |
|
286 iOperation = EWrite; |
|
287 |
|
288 iUtility = CMdaImageBitmapToFileUtility::NewL(*this, NULL); |
|
289 CMdaImageBitmapToFileUtility* utility = STATIC_CAST(CMdaImageBitmapToFileUtility*, iUtility); |
|
290 utility->CreateL(iFileName, aFormat, aCodec, aCodec); |
|
291 // note some of the standard codec's look at the standard codec info and some the extra |
|
292 iState = EStateOpening; |
|
293 CActiveScheduler::Start(); // recurse into AO |
|
294 |
|
295 ASSERT(iState == EStateIdle); // we should have come back here |
|
296 delete iUtility; iUtility = NULL; |
|
297 |
|
298 User::LeaveIfError(iReturnedError); |
|
299 } |
|
300 |
|
301 void CTestImageIO::MiuoOpenComplete(TInt aError) |
|
302 { |
|
303 ASSERT(iOperation == ERead || iOperation == EReadViaDes || iOperation == EReadViaFile); // only these operations should get here |
|
304 |
|
305 ASSERT(iState == EStateOpening); // to be expected |
|
306 |
|
307 if (aError!=KErrNone) |
|
308 { |
|
309 if ((iOperation==EReadViaDes || iOperation==EReadViaFile) && |
|
310 aError == KErrUnderflow && StreamBufferedSize() < iFileSize) |
|
311 { |
|
312 // doing stream operation and not yet enough data to open the file |
|
313 IncrementStreamBufferedSize(); |
|
314 TInt error = KErrNone; |
|
315 if (iOperation == EReadViaDes) |
|
316 { |
|
317 iBuffer.SetLength(StreamBufferedSize()); |
|
318 CMdaImageDescToBitmapUtility* utility = STATIC_CAST(CMdaImageDescToBitmapUtility*, iUtility); |
|
319 TRAP(error, utility->OpenL(iBuffer)); |
|
320 } |
|
321 else |
|
322 { |
|
323 ASSERT(iOperation == EReadViaFile); |
|
324 TRAP(error, CopyFileToTempL(StreamBufferedSize())); |
|
325 CMdaImageFileToBitmapUtility* utility = STATIC_CAST(CMdaImageFileToBitmapUtility*, iUtility); |
|
326 TPtrC tempFileName(KFailVideoTempTestFileName); |
|
327 if (error==KErrNone) |
|
328 TRAP(error,utility->OpenL(tempFileName)); |
|
329 } |
|
330 if (error != KErrNone) |
|
331 { |
|
332 iState = EStateIdle; |
|
333 Leave(error); |
|
334 } |
|
335 } |
|
336 else |
|
337 { |
|
338 iState = EStateIdle; |
|
339 Leave(aError); |
|
340 } |
|
341 } |
|
342 else |
|
343 { |
|
344 // note for readviades and viafile we only have to resize once - not on subsequent tries |
|
345 TFrameInfo frameInfo; |
|
346 iUtility->FrameInfo(0, frameInfo); |
|
347 TSize frameSize = frameInfo.iFrameCoordsInPixels.Size(); |
|
348 frameSize.iWidth = (frameSize.iWidth+iZoomFactor-1) / iZoomFactor; |
|
349 frameSize.iHeight = (frameSize.iHeight+iZoomFactor-1) / iZoomFactor; |
|
350 TInt error = iBitmap->Resize(TSize(0,0)); |
|
351 if (error==KErrNone) |
|
352 error = iBitmap->Resize(frameSize); |
|
353 if (error==KErrNone) |
|
354 TRAP(error, iUtility->ConvertL(*iBitmap)); |
|
355 if (error!=KErrNone) |
|
356 { |
|
357 iState = EStateIdle; |
|
358 Leave(error); |
|
359 } |
|
360 else |
|
361 iState = EStateConverting; |
|
362 } |
|
363 } |
|
364 |
|
365 void CTestImageIO::MiuoCreateComplete(TInt aError) |
|
366 { |
|
367 ASSERT(iOperation == EWrite); // only called on write operation |
|
368 |
|
369 ASSERT(iState == EStateOpening); // to be expected |
|
370 |
|
371 if (aError!=KErrNone) |
|
372 { |
|
373 iState = EStateIdle; |
|
374 Leave(aError); |
|
375 } |
|
376 else |
|
377 { |
|
378 TRAPD(error, iUtility->ConvertL(*iBitmap)); |
|
379 if (error!=KErrNone) |
|
380 { |
|
381 iState = EStateIdle; |
|
382 Leave(error); |
|
383 } |
|
384 else |
|
385 iState = EStateConverting; |
|
386 } |
|
387 } |
|
388 |
|
389 void CTestImageIO::MiuoConvertComplete(TInt aError) |
|
390 { |
|
391 ASSERT(iState == EStateConverting); // to be expected |
|
392 |
|
393 if (iOperation == ERead || iOperation == EWrite) |
|
394 { |
|
395 iState = EStateIdle; |
|
396 Leave(aError); |
|
397 } |
|
398 else |
|
399 { |
|
400 ASSERT(iOperation == EReadViaDes || iOperation == EReadViaFile); |
|
401 |
|
402 if (aError == KErrUnderflow && StreamBufferedSize() < iFileSize) |
|
403 // partial decode event - try to decode a bit more |
|
404 { |
|
405 IncrementStreamBufferedSize(); |
|
406 TInt error = KErrNone; |
|
407 if (iOperation == EReadViaDes) |
|
408 iBuffer.SetLength(StreamBufferedSize()); |
|
409 else |
|
410 { |
|
411 ASSERT(iOperation == EReadViaFile); |
|
412 TRAP(error, CopyFileToTempL(StreamBufferedSize())); |
|
413 } |
|
414 if (error==KErrNone) |
|
415 TRAP(error, iUtility->ConvertL(*iBitmap)); |
|
416 if (error != KErrNone) |
|
417 { |
|
418 iState = EStateIdle; |
|
419 Leave(error); |
|
420 } |
|
421 } |
|
422 else |
|
423 { |
|
424 iState = EStateIdle; |
|
425 Leave(aError); |
|
426 } |
|
427 } |
|
428 } |
|
429 |
|
430 // |
|
431 // CMdaFailVid1 |
|
432 // |
|
433 |
|
434 void CMdaFailVidTest1::DoTestL() |
|
435 { |
|
436 User::LeaveIfError(iFs.Connect()); |
|
437 CleanupClosePushL(iFs); |
|
438 |
|
439 CDir* dir = NULL; |
|
440 iFs.GetDir(KNullDesC,0,0,dir); |
|
441 CleanupStack::PushL(dir); |
|
442 |
|
443 TInt error=KErrNone; |
|
444 |
|
445 __UHEAP_MARK; |
|
446 TRAP(error,Test1L(*dir)); |
|
447 iEngine->Print(_L("After Test1")); |
|
448 __UHEAP_MARKEND; |
|
449 |
|
450 User::LeaveIfError(error); |
|
451 |
|
452 __UHEAP_MARK; |
|
453 TRAP(error,Test2L(*dir)); |
|
454 iEngine->Print(_L("After Test2")); |
|
455 __UHEAP_MARKEND; |
|
456 |
|
457 User::LeaveIfError(error); |
|
458 |
|
459 // preload and destroy CFbsBitmap to avoid "memory leak" - really side effect of |
|
460 // CFbsBitmap::Load() that is cleaned up properly later |
|
461 { |
|
462 TFileName fileName; |
|
463 User::LeaveIfError(iFs.DefaultPath(fileName)); |
|
464 fileName.Append(KVideoTestSourceFileName); |
|
465 |
|
466 CFbsBitmap* srcBmp = new(ELeave) CFbsBitmap; |
|
467 CleanupStack::PushL(srcBmp); |
|
468 User::LeaveIfError(srcBmp->Load(fileName)); |
|
469 CleanupStack::PopAndDestroy(); // srcBmp |
|
470 } |
|
471 |
|
472 __UHEAP_MARK; |
|
473 TRAP(error,Test3L()); |
|
474 iEngine->Print(_L("After Test3")); |
|
475 __UHEAP_MARKEND; |
|
476 |
|
477 User::LeaveIfError(error); |
|
478 |
|
479 CleanupStack::PopAndDestroy(2); // dir, iFs |
|
480 } |
|
481 |
|
482 void CMdaFailVidTest1::Test1L(CDir& aDir) |
|
483 { |
|
484 CFbsBitmap *bmp = new (ELeave) CFbsBitmap; |
|
485 CleanupStack::PushL(bmp); |
|
486 User::LeaveIfError(bmp->Create(TSize(0,0),EColor16M)); |
|
487 CFbsBitmap *src = new (ELeave) CFbsBitmap; |
|
488 CleanupStack::PushL(src); |
|
489 User::LeaveIfError(src->Create(TSize(0,0),EColor16M)); |
|
490 |
|
491 TInt entries = aDir.Count(); |
|
492 |
|
493 for (TInt count = 0; count < entries; count++) |
|
494 { |
|
495 __UHEAP_MARK; |
|
496 const TEntry& entry = aDir[count]; |
|
497 |
|
498 TFileName fileName; |
|
499 User::LeaveIfError(iFs.DefaultPath(fileName)); |
|
500 fileName.Append(entry.iName); |
|
501 |
|
502 TBuf<80> text; |
|
503 text.Zero(); |
|
504 text.Append(_L("Load with alloc fail - ")); |
|
505 text.Append(entry.iName); |
|
506 iEngine->Print(text); |
|
507 |
|
508 LoadImageL(*src,fileName,1); |
|
509 LoadImageWithAllocFailureL(*bmp,fileName,1); |
|
510 CheckBitmaps(*src,*bmp); |
|
511 |
|
512 LoadImageL(*src,fileName,8); |
|
513 LoadImageWithAllocFailureL(*bmp,fileName,8); |
|
514 CheckBitmaps(*src,*bmp); |
|
515 __UHEAP_MARKEND; |
|
516 } |
|
517 |
|
518 CleanupStack::PopAndDestroy(2); // src and bmp |
|
519 } |
|
520 |
|
521 void CMdaFailVidTest1::Test2L(CDir& aDir) |
|
522 { |
|
523 CFbsBitmap *bmp = new (ELeave) CFbsBitmap; |
|
524 CleanupStack::PushL(bmp); |
|
525 User::LeaveIfError(bmp->Create(TSize(0,0),EColor16M)); |
|
526 CFbsBitmap *bmp2 = new (ELeave) CFbsBitmap; |
|
527 CleanupStack::PushL(bmp2); |
|
528 User::LeaveIfError(bmp2->Create(TSize(0,0),EColor16M)); |
|
529 CFbsBitmap *src = new (ELeave) CFbsBitmap; |
|
530 CleanupStack::PushL(src); |
|
531 User::LeaveIfError(src->Create(TSize(0,0),EColor16M)); |
|
532 |
|
533 TInt entries = aDir.Count(); |
|
534 |
|
535 for (TInt count = 0; count < entries; count++) |
|
536 { |
|
537 __UHEAP_MARK; |
|
538 const TEntry& entry = aDir[count]; |
|
539 |
|
540 TBuf<64> text; |
|
541 text.Zero(); |
|
542 text.Append(_L("Stream with alloc fail - ")); |
|
543 text.Append(entry.iName); |
|
544 iEngine->Print(text); |
|
545 |
|
546 TFileName fileName; |
|
547 User::LeaveIfError(iFs.DefaultPath(fileName)); |
|
548 fileName.Append(entry.iName); |
|
549 |
|
550 StreamImageWithAllocFailureL(*bmp,fileName,1,EStreamViaDes); |
|
551 LoadImageL(*src,fileName,1); |
|
552 CheckBitmaps(*src,*bmp); |
|
553 StreamImageWithAllocFailureL(*bmp2,fileName,1,EStreamViaFile); |
|
554 CheckBitmaps(*bmp, *bmp2); |
|
555 |
|
556 StreamImageWithAllocFailureL(*bmp,fileName,8,EStreamViaDes); |
|
557 LoadImageL(*src,fileName,8); |
|
558 CheckBitmaps(*src,*bmp); |
|
559 StreamImageWithAllocFailureL(*bmp2,fileName,8,EStreamViaFile); |
|
560 CheckBitmaps(*bmp, *bmp2); |
|
561 __UHEAP_MARKEND; |
|
562 } |
|
563 |
|
564 CleanupStack::PopAndDestroy(3); // src, bmp2 and bmp |
|
565 } |
|
566 |
|
567 void CMdaFailVidTest1::Test3L() |
|
568 { |
|
569 TFileName fileName; |
|
570 User::LeaveIfError(iFs.DefaultPath(fileName)); |
|
571 fileName.Append(KVideoTestSourceFileName); |
|
572 |
|
573 CFbsBitmap* srcBmp = new(ELeave) CFbsBitmap; |
|
574 CleanupStack::PushL(srcBmp); |
|
575 User::LeaveIfError(srcBmp->Load(fileName)); |
|
576 |
|
577 for (TInt formatIndex = 0; ; formatIndex++) |
|
578 { |
|
579 TMdaClipFormat* format = NULL; |
|
580 TMdaPackage* codec = NULL; |
|
581 ConfigDestPortL(format,codec,formatIndex); |
|
582 |
|
583 if (format == NULL && codec == NULL) |
|
584 break; |
|
585 |
|
586 TBuf<64> text(_L("Save with alloc fail - ")); |
|
587 text.Append(SaveFileName(formatIndex)); |
|
588 iEngine->Print(text); |
|
589 |
|
590 SaveImageWithAllocFailureL(*srcBmp,format,codec); |
|
591 |
|
592 iFs.Delete(KFailVideoTempTestFileName); |
|
593 } |
|
594 |
|
595 CleanupStack::PopAndDestroy(); // srcBmp |
|
596 } |
|
597 |
|
598 void CMdaFailVidTest1::LoadImageWithAllocFailureL(CFbsBitmap& aBitmap,const TDesC& aFileName,TInt aZoomFactor) |
|
599 { |
|
600 TInt failCount = 1; |
|
601 TInt err; |
|
602 |
|
603 __UHEAP_MARK; |
|
604 TRAP(err,LoadImageL(aBitmap,aFileName,aZoomFactor)); |
|
605 if (err != KErrNone) |
|
606 iEngine->TestFailed(err); |
|
607 __UHEAP_MARKEND; |
|
608 |
|
609 for(;;) { |
|
610 #if defined(_DEBUG) && 0 |
|
611 RDebug::Print(_L("CMdaFailVidTest1::LoadImageWithAllocFailureL(%S,%d) failCount=%d"), &aFileName, aZoomFactor, failCount); |
|
612 #endif defined(_DEBUG) |
|
613 __UHEAP_SETFAIL(RHeap::EDeterministic, failCount); |
|
614 __UHEAP_MARK; |
|
615 |
|
616 TRAP(err,LoadImageL(aBitmap,aFileName,aZoomFactor)); |
|
617 if (err != KErrNoMemory && err != KErrNone) |
|
618 iEngine->TestFailed(err); |
|
619 |
|
620 __UHEAP_MARKEND; |
|
621 __UHEAP_SETFAIL(RHeap::ENone, 0); |
|
622 |
|
623 if (err!=KErrNoMemory) |
|
624 break; |
|
625 failCount++; |
|
626 } |
|
627 failCount -= 1; // we are one over |
|
628 |
|
629 TBuf<80> format; |
|
630 format.Zero(); |
|
631 format.AppendFormat(_L(" Completed OK at zoom factor %d with %d memory allocations tested"),aZoomFactor,failCount); |
|
632 iEngine->Print(format); |
|
633 } |
|
634 |
|
635 void CMdaFailVidTest1::StreamImageWithAllocFailureL(CFbsBitmap& aBitmap,const TDesC& aFileName,TInt aZoomFactor,TStreamMethod aStreamMethod) |
|
636 { |
|
637 TInt failCount = 1; |
|
638 TInt err; |
|
639 |
|
640 #if defined(_DEBUG) && 0 |
|
641 RDebug::Print(_L("CMdaFailVidTest1::StreamImageWithAllocFailureL(%S,%d,%d)"), &aFileName, aZoomFactor, aStreamMethod); |
|
642 #endif defined(_DEBUG) |
|
643 |
|
644 __UHEAP_MARK; |
|
645 TRAP(err,StreamImageL(aBitmap,aFileName,aZoomFactor,aStreamMethod)); |
|
646 if (err != KErrNone) |
|
647 iEngine->TestFailed(err); |
|
648 __UHEAP_MARKEND; |
|
649 |
|
650 for(;;) { |
|
651 #if defined(_DEBUG) && 0 |
|
652 RDebug::Print(_L("CMdaFailVidTest1::StreamImageWithAllocFailureL(%S,%d,%d) failCount=%d"), &aFileName, aZoomFactor, aStreamMethod, failCount); |
|
653 #endif defined(_DEBUG) |
|
654 __UHEAP_SETFAIL(RHeap::EDeterministic, failCount); |
|
655 __UHEAP_MARK; |
|
656 |
|
657 TRAP(err,StreamImageL(aBitmap,aFileName,aZoomFactor,aStreamMethod)); |
|
658 if (err != KErrNoMemory && err != KErrNone) |
|
659 iEngine->TestFailed(err); |
|
660 |
|
661 __UHEAP_MARKEND; |
|
662 __UHEAP_SETFAIL(RHeap::ENone, 0); |
|
663 |
|
664 if (err!=KErrNoMemory) |
|
665 break; |
|
666 failCount++; |
|
667 } |
|
668 failCount -= 1; // we are one over |
|
669 |
|
670 TBuf<80> format; |
|
671 format.Zero(); |
|
672 TPtrC method; |
|
673 if (aStreamMethod==EStreamViaDes) |
|
674 method.Set(_L("Desc")); |
|
675 else |
|
676 method.Set(_L("File")); |
|
677 format.AppendFormat(_L(" Completed OK (%S) at zoom factor %d with %d memory allocations tested"),&method,aZoomFactor,failCount); |
|
678 iEngine->Print(format); |
|
679 } |
|
680 |
|
681 void CMdaFailVidTest1::LoadImageL(CFbsBitmap& aBitmap,const TDesC& aFileName,TInt aZoomFactor) |
|
682 { |
|
683 CTestImageIO* testIO = CTestImageIO::NewLC(iFs); |
|
684 testIO->ReadL(aBitmap, aFileName, aZoomFactor); |
|
685 CleanupStack::PopAndDestroy(); // testIO |
|
686 } |
|
687 |
|
688 void CMdaFailVidTest1::StreamImageL(CFbsBitmap& aBitmap,const TDesC& aFileName,TInt aZoomFactor, TStreamMethod aStreamMethod) |
|
689 { |
|
690 CTestImageIO* testIO = CTestImageIO::NewLC(iFs); |
|
691 if (aStreamMethod == EStreamViaDes) |
|
692 testIO->ReadViaDesL(aBitmap, aFileName, aZoomFactor); |
|
693 else |
|
694 { |
|
695 ASSERT(aStreamMethod==EStreamViaFile); |
|
696 testIO->ReadViaFileL(aBitmap, aFileName, aZoomFactor); |
|
697 } |
|
698 CleanupStack::PopAndDestroy(); // testIO |
|
699 } |
|
700 |
|
701 void CMdaFailVidTest1::SaveImageWithAllocFailureL(CFbsBitmap& aBitmap,TMdaClipFormat* aFormat,TMdaPackage* aCodec) |
|
702 { |
|
703 TInt failCount = 1; |
|
704 TInt err; |
|
705 |
|
706 __UHEAP_MARK; |
|
707 TRAP(err,SaveImageL(aBitmap,aFormat,aCodec)); |
|
708 if (err != KErrNone) |
|
709 iEngine->TestFailed(err); |
|
710 __UHEAP_MARKEND; |
|
711 |
|
712 for(;;) { |
|
713 __UHEAP_SETFAIL(RHeap::EDeterministic, failCount); |
|
714 __UHEAP_MARK; |
|
715 |
|
716 TRAP(err,SaveImageL(aBitmap,aFormat,aCodec)); |
|
717 if (err != KErrNoMemory && err != KErrNone) |
|
718 iEngine->TestFailed(err); |
|
719 |
|
720 __UHEAP_MARKEND; |
|
721 __UHEAP_SETFAIL(RHeap::ENone, 0); |
|
722 |
|
723 if (err != KErrNoMemory) |
|
724 break; |
|
725 |
|
726 failCount++; |
|
727 } |
|
728 failCount -= 1; // we are one over |
|
729 |
|
730 TBuf<80> format; |
|
731 format.Zero(); |
|
732 format.AppendFormat(_L(" Completed OK with %d memory allocations tested"),failCount); |
|
733 iEngine->Print(format); |
|
734 } |
|
735 |
|
736 |
|
737 void CMdaFailVidTest1::SaveImageL(CFbsBitmap& aBitmap,TMdaClipFormat* aFormat,TMdaPackage* aCodec) |
|
738 { |
|
739 ASSERT(aFormat); |
|
740 |
|
741 iFs.Delete(KFailVideoTempTestFileName); |
|
742 |
|
743 #if 0 |
|
744 RMdaSourceStreamPort srcPort; |
|
745 srcPort.OpenLC(iSession); |
|
746 TMdaFbsBitmapDevice bmpDev; |
|
747 srcPort.ResourceConfigL(bmpDev); |
|
748 TMdaFbsBitmapHandle bmpHandle; |
|
749 bmpHandle.iBitmapHandle = aBitmap.Handle(); |
|
750 srcPort.PortConfigL(bmpHandle); |
|
751 |
|
752 RMdaDestinationClipPort dstPort; |
|
753 dstPort.OpenLC(iSession); |
|
754 TMdaFileClipLocation location; |
|
755 location.iName = KFailVideoTempTestFileName; |
|
756 dstPort.ResourceConfigL(location); |
|
757 dstPort.ResourceConfigL(*aFormat); |
|
758 if (aCodec) |
|
759 dstPort.ResourceConfigL(*aCodec); |
|
760 |
|
761 RMdaController controller; |
|
762 controller.OpenLC(iSession); |
|
763 TMdaConnection connection(srcPort,dstPort,KUidMdaMediaTypeVideo); |
|
764 controller.ConnectL(connection); |
|
765 controller.PrepareL(); |
|
766 controller.PrimeL(); |
|
767 |
|
768 CleanupStack::PopAndDestroy(3); // controller, dstPort, srcPort |
|
769 #else 0 |
|
770 CTestImageIO* testIO = CTestImageIO::NewLC(iFs); |
|
771 testIO->WriteL(aBitmap, KFailVideoTempTestFileName, aFormat, aCodec); |
|
772 CleanupStack::PopAndDestroy(); // testIO |
|
773 #endif 0 |
|
774 } |
|
775 |
|
776 const TDesC& CMdaFailVidTest1::SaveFileName(TInt aFormatIndex) |
|
777 { |
|
778 switch (aFormatIndex) |
|
779 { |
|
780 case 0: return KVideoTest1BppMonoMbm; |
|
781 case 1: return KVideoTest2BppMonoMbm; |
|
782 case 2: return KVideoTest4BppMonoMbm; |
|
783 case 3: return KVideoTest8BppMonoMbm; |
|
784 case 4: return KVideoTest4BppColorMbm; |
|
785 case 5: return KVideoTest8BppColorMbm; |
|
786 case 6: return KVideoTest12BppColorMbm; |
|
787 case 7: return KVideoTest16BppColorMbm; |
|
788 case 8: return KVideoTest24BppColorMbm; |
|
789 case 9: return KVideoTestMono10Jfif; |
|
790 case 10: return KVideoTestMono30Jfif; |
|
791 case 11: return KVideoTestMono60Jfif; |
|
792 case 12: return KVideoTestMono100Jfif; |
|
793 case 13: return KVideoTest420C10Jfif; |
|
794 case 14: return KVideoTest420C30Jfif; |
|
795 case 15: return KVideoTest420C60Jfif; |
|
796 case 16: return KVideoTest420C100Jfif; |
|
797 case 17: return KVideoTest422C10Jfif; |
|
798 case 18: return KVideoTest422C30Jfif; |
|
799 case 19: return KVideoTest422C60Jfif; |
|
800 case 20: return KVideoTest422C100Jfif; |
|
801 case 21: return KVideoTest444C10Jfif; |
|
802 case 22: return KVideoTest444C30Jfif; |
|
803 case 23: return KVideoTest444C60Jfif; |
|
804 case 24: return KVideoTest444C100Jfif; |
|
805 case 25: return KVideoTest1BppBmp; |
|
806 case 26: return KVideoTest4BppBmp; |
|
807 case 27: return KVideoTest8BppBmp; |
|
808 case 28: return KVideoTest24BppBmp; |
|
809 default: return KNullDesC; |
|
810 } |
|
811 } |
|
812 |
|
813 void CMdaFailVidTest1::ConfigDestPortL(TMdaClipFormat*& aFormat,TMdaPackage*& aCodec,TInt aFormatIndex) |
|
814 { |
|
815 aFormat = NULL; |
|
816 aCodec = NULL; |
|
817 |
|
818 if (aFormatIndex >= 0 && aFormatIndex <= 8) |
|
819 { |
|
820 switch (aFormatIndex) |
|
821 { |
|
822 case 0: iMbmFormat.iDisplayMode = EGray2; break; |
|
823 case 1: iMbmFormat.iDisplayMode = EGray4; break; |
|
824 case 2: iMbmFormat.iDisplayMode = EGray16; break; |
|
825 case 3: iMbmFormat.iDisplayMode = EGray256; break; |
|
826 case 4: iMbmFormat.iDisplayMode = EColor16; break; |
|
827 case 5: iMbmFormat.iDisplayMode = EColor256; break; |
|
828 case 6: iMbmFormat.iDisplayMode = EColor4K; break; |
|
829 case 7: iMbmFormat.iDisplayMode = EColor64K; break; |
|
830 case 8: iMbmFormat.iDisplayMode = EColor16M; break; |
|
831 default: User::Invariant(); |
|
832 } |
|
833 aFormat = &iMbmFormat; |
|
834 } |
|
835 else if (aFormatIndex >= 9 && aFormatIndex <= 24) |
|
836 { |
|
837 switch (aFormatIndex) |
|
838 { |
|
839 case 9: case 10: case 11: case 12: |
|
840 iJfifFormat.iSettings.iSampleScheme = TMdaJpgSettings::EMonochrome; |
|
841 break; |
|
842 case 13: case 14: case 15: case 16: |
|
843 iJfifFormat.iSettings.iSampleScheme = TMdaJpgSettings::EColor420; |
|
844 break; |
|
845 case 17: case 18: case 19: case 20: |
|
846 iJfifFormat.iSettings.iSampleScheme = TMdaJpgSettings::EColor422; |
|
847 break; |
|
848 case 21: case 22: case 23: case 24: |
|
849 iJfifFormat.iSettings.iSampleScheme = TMdaJpgSettings::EColor444; |
|
850 break; |
|
851 default: User::Invariant(); |
|
852 } |
|
853 switch (aFormatIndex) |
|
854 { |
|
855 case 9: case 13: case 17: case 21: |
|
856 iJfifFormat.iSettings.iQualityFactor = 10; |
|
857 break; |
|
858 case 10: case 14: case 18: case 22: |
|
859 iJfifFormat.iSettings.iQualityFactor = 30; |
|
860 break; |
|
861 case 11: case 15: case 19: case 23: |
|
862 iJfifFormat.iSettings.iQualityFactor = 60; |
|
863 break; |
|
864 case 12: case 16: case 20: case 24: |
|
865 iJfifFormat.iSettings.iQualityFactor = 100; |
|
866 break; |
|
867 default: User::Invariant(); |
|
868 } |
|
869 aFormat = &iJfifFormat; |
|
870 } |
|
871 else if (aFormatIndex >= 25 && aFormatIndex <= 28) |
|
872 { |
|
873 switch (aFormatIndex) |
|
874 { |
|
875 case 25: aCodec = &iBmp1BppCodec; break; |
|
876 case 26: aCodec = &iBmp4BppCodec; break; |
|
877 case 27: aCodec = &iBmp8BppCodec; break; |
|
878 case 28: aCodec = &iBmp24BppCodec; break; |
|
879 default: User::Invariant(); |
|
880 } |
|
881 aFormat = &iBmpFormat; |
|
882 } |
|
883 } |
|
884 |