Update contrib.
1 // Copyright (c) 2003-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 #include <ezcompressor.h>
20 #include <ezdecompressor.h>
21 #include <ezfilebuffer.h>
26 _LIT(KSeparator,"----------------------------------------------------------------\n");
28 const TInt KNumberOfTests = 38;
29 _LIT(KTest1,"Multistep compression & decompression using buffers smaller than source & destination");
30 _LIT(KTest2,"Multistep compression & decompression using buffers larger than source & destination");
31 _LIT(KTest3,"Test Multistep compression when NeedInput provides no input");
32 _LIT(KTest4,"Test Multistep compression when NeedOutput provides no output");
33 _LIT(KTest5,"Perform multistep compression 2 with the same CEZCompressor, reseting it\n\
34 after the first compression.");
35 _LIT(KTest6,"Perform multistep compression 2 with the same CEZCompressor, without reseting it\n\
36 after the first compression.");
37 _LIT(KTest7,"Performs multistep compression & decompression using a preset dicitonary.");
38 _LIT(KTest8,"Performs multistep compression with compression level of 0.");
39 _LIT(KTest9,"Performs multistep compression with compression level of 9.");
40 _LIT(KTest10,"Performs multistep compression with invalid compression level.");
41 _LIT(KTest11,"Performs multistep compression with window bits of 8.");
42 _LIT(KTest12,"Performs multistep compression with an invalid value for window bits.");
43 _LIT(KTest13,"Performs multistep compression with memory level = 1.");
44 _LIT(KTest14,"Performs multistep compression with an invalid memory level.");
45 _LIT(KTest15,"Performs multistep compression using only Huffman encoding.");
46 _LIT(KTest16,"Performs multistep compression using Filtered strategy.");
47 _LIT(KTest17,"Performs multistep compression when Alloc fails randomly.");
48 _LIT(KTest18,"Test Multistep decompression when NeedInput provides no input.");
49 _LIT(KTest19,"Test Multistep decompression when NeedOutput provides no output.");
50 _LIT(KTest20,"Test Multistep decompression when compressed stream is corrupt.");
51 _LIT(KTest21,"Test Multistep decompressor construction when Alloc fails randomly.");
52 _LIT(KTest22,"Test Multistep decompression when Alloc fails randomly.");
53 _LIT(KTest23,"Test Multistep decompression when a dictionary is required and not provided.\n\
54 This test should panic.");
55 _LIT(KTest24,"Test Multistep decompression when a dictionary when the wrong dictionary is provided.");
56 _LIT(KTest25,"Perform multistep decompression twice with the same CEZDecompressor, reseting it\n\
57 after the first decompression.");
58 _LIT(KTest26,"Perform multistep decompression twice with the same CEZDecompressor, reseting it\n\
59 after the first decompression.");
60 _LIT(KTest27,"Perform multistep compression and decompression on unicode data.");
61 _LIT(KTest28,"Perform multistep compression and decompression on unicode data using a unicode dictionary.");
62 _LIT(KTest29,"Perform multistep compression and decompression on unicode data using an ascii dictionary.");
63 _LIT(KTest30,"Test percentage of completion during multistep compression/decompression.");
64 _LIT(KTest31,"Test single step compression and decompression.");
65 _LIT(KTest32,"Test single step compression when indaquate output buffer is provided.");
66 _LIT(KTest33,"Test single step decompression when indaquate output buffer is provided.");
67 _LIT(KTest34,"Testing graceful exit for zlib 1.1.3 decompression bug. See: INC022729.");
68 _LIT(KTest35,"Testing EZlib decompression performance with enforced compiler optimisation");
69 _LIT(KTest36,"Testing correct memory deallocation for CEZFileBufferManager. See: DEF109756.");
70 _LIT(KTest37,"Test CEZZStream functions through CEZCompressor class.");
71 _LIT(KTest38,"Test Calls to Zlibapiwrapper.cpp exported API's like inflate, deflate, compress, decompress");
73 const TPtrC KTest1Des(KTest1);
74 const TPtrC KTest2Des(KTest2);
75 const TPtrC KTest3Des(KTest3);
76 const TPtrC KTest4Des(KTest4);
77 const TPtrC KTest5Des(KTest5);
78 const TPtrC KTest6Des(KTest6);
79 const TPtrC KTest7Des(KTest7);
80 const TPtrC KTest8Des(KTest8);
81 const TPtrC KTest9Des(KTest9);
82 const TPtrC KTest10Des(KTest10);
83 const TPtrC KTest11Des(KTest11);
84 const TPtrC KTest12Des(KTest12);
85 const TPtrC KTest13Des(KTest13);
86 const TPtrC KTest14Des(KTest14);
87 const TPtrC KTest15Des(KTest15);
88 const TPtrC KTest16Des(KTest16);
89 const TPtrC KTest17Des(KTest17);
90 const TPtrC KTest18Des(KTest18);
91 const TPtrC KTest19Des(KTest19);
92 const TPtrC KTest20Des(KTest20);
93 const TPtrC KTest21Des(KTest21);
94 const TPtrC KTest22Des(KTest22);
95 const TPtrC KTest23Des(KTest23);
96 const TPtrC KTest24Des(KTest24);
97 const TPtrC KTest25Des(KTest25);
98 const TPtrC KTest26Des(KTest26);
99 const TPtrC KTest27Des(KTest27);
100 const TPtrC KTest28Des(KTest28);
101 const TPtrC KTest29Des(KTest29);
102 const TPtrC KTest30Des(KTest30);
103 const TPtrC KTest31Des(KTest31);
104 const TPtrC KTest32Des(KTest32);
105 const TPtrC KTest33Des(KTest33);
106 const TPtrC KTest34Des(KTest34);
107 const TPtrC KTest35Des(KTest35);
108 const TPtrC KTest36Des(KTest36);
109 const TPtrC KTest37Des(KTest37);
110 const TPtrC KTest38Des(KTest38);
148 void TestCEZCompressorMethodsL();
149 void TestZlibapiwrapperAPIL();
151 typedef void (*TestPtr)();
156 const TPtrC *iDescription;
159 const TTests testTable[] = {
169 {Test10,&KTest10Des},
170 {Test11,&KTest11Des},
171 {Test12,&KTest12Des},
172 {Test13L,&KTest13Des},
173 {Test14,&KTest14Des},
174 {Test15L,&KTest15Des},
175 {Test16L,&KTest16Des},
176 {Test17,&KTest17Des},
177 {Test18L,&KTest18Des},
178 {Test19L,&KTest19Des},
179 {Test20L,&KTest20Des},
180 {Test21L,&KTest21Des},
181 {Test22L,&KTest22Des},
182 {Test23,&KTest23Des},
183 {Test24L,&KTest24Des},
184 {Test25L,&KTest25Des},
185 {Test26L,&KTest26Des},
186 {Test27L,&KTest27Des},
187 {Test28L,&KTest28Des},
188 {Test29L,&KTest29Des},
189 {Test30L,&KTest30Des},
190 {Test31L,&KTest31Des},
191 {Test32,&KTest32Des},
192 {Test33L,&KTest33Des},
193 {Test34L,&KTest34Des},
194 {Test35L,&KTest35Des},
195 {Test36L,&KTest36Des},
196 {TestCEZCompressorMethodsL, &KTest37Des},
197 {TestZlibapiwrapperAPIL, &KTest38Des}
209 AllocFailInflate = 512,
215 TTestFlags() : iFlags(0), iBufferSize(0) { Defaults(); }
216 TTestFlags(TInt aFlags, TInt aBufferSize) : iFlags(aFlags), iBufferSize(aBufferSize) { Defaults(); }
225 CEZCompressor::TStrategy iStrategy;
229 void TTestFlags::Defaults()
231 iLevel = CEZCompressor::EDefaultCompression;
232 iWindowBits = CEZCompressor::EMaxWBits;
233 iMemLevel = CEZCompressor::EDefMemLevel;
234 iStrategy = CEZCompressor::EDefaultStrategy;
237 TReal FastCountToMilliseconds(TInt aFastCount)
240 HAL::Get(HAL::EFastCounterFrequency, freqInHz);
241 TReal freqInkHz = freqInHz / 1000;
242 return (TReal)aFastCount / freqInkHz;
246 static RTest Test(_L("EZLIB"));
248 static TUint8 original[] = "compression is a constant source of depression and depression leads to multiple regressions in succession";
249 static TUint8 dictionary[] = "constant source multiple leads compression ";
250 static TUint8 badDictionary[] = "I'm not the dictionary";
251 static TUint8 compressed[256];
252 static TInt compressedSize; // length of compressed data in compressed.
253 static TUint8 uncompressed[256];
254 static TText output[256];
255 static TText originalU[256];
256 static TText dictionaryU[256];
258 static void RunTestL();
260 static void CompressBufferL(const TTestFlags &aFlags, RTest &aTest=Test);
261 static void DecompressBufferL(const TTestFlags &aFlags, RTest &aTest=Test);
262 static void DblDecompressBufferL(TInt aBufferSize, TBool aReset);
263 static void CompressDecompressL(const TTestFlags &aFlags);
264 static void DblCompressBufferL(TInt aBufferSize, TBool aReset = EFalse);
266 class CBufferManager : public CBase, public MEZBufferManager
271 static CBufferManager *NewLC(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength, TInt aBufferSize);
272 static CBufferManager *NewL(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength, TInt aBufferSize);
274 void InitializeL(CEZZStream &aZStream);
275 void NeedInputL(CEZZStream &aZStream);
276 void NeedOutputL(CEZZStream &aZStream);
277 void FinalizeL(CEZZStream &aZStream);
279 void FakeNoInput() { iFakeNoInput = ETrue; }
280 void FakeNoOutput() { iFakeNoOutput = ETrue; }
283 CBufferManager(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength);
284 void ConstructL(TInt aBufferSize);
287 TUint8 *iInput, *iOutput;
288 TUint8 *iInputBuffer, *iOutputBuffer;
290 TInt iOutputLength, iInputLength;
291 TPtr8 iInputDescriptor;
292 TPtr8 iOutputDescriptor;
297 CBufferManager::CBufferManager(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength)
300 iOutputLength(aOutputLength),
301 iInputLength(aInputLength),
302 iInputDescriptor(NULL,0),
303 iOutputDescriptor(NULL,0),
304 iFakeNoInput(EFalse),
305 iFakeNoOutput(EFalse)
310 CBufferManager::~CBufferManager()
312 delete[] iInputBuffer;
313 delete[] iOutputBuffer;
316 CBufferManager *CBufferManager::NewLC(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength, TInt aBufferSize)
318 CBufferManager *bm = new (ELeave) CBufferManager(aInput,aInputLength,aOutput,aOutputLength);
319 CleanupStack::PushL(bm);
320 bm->ConstructL(aBufferSize);
324 CBufferManager *CBufferManager::NewL(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength, TInt aBufferSize)
326 CBufferManager *bm = new (ELeave) CBufferManager(aInput,aInputLength,aOutput,aOutputLength);
327 CleanupStack::PushL(bm);
328 bm->ConstructL(aBufferSize);
333 void CBufferManager::ConstructL(TInt aBufferSize)
335 iBufferSize = aBufferSize;
336 iInputBuffer = new (ELeave) TUint8[iBufferSize];
337 iOutputBuffer = new (ELeave) TUint8[iBufferSize];
341 void CBufferManager::InitializeL(CEZZStream &aZStream)
343 TInt remaining = iInputLength;
344 if (remaining > iBufferSize)
345 remaining = iBufferSize;
346 Mem::Copy(iInputBuffer,iInput,remaining);
347 iInputDescriptor.Set(iInputBuffer,remaining,iBufferSize);
348 aZStream.SetInput(iInputDescriptor);
349 iOutputDescriptor.Set(iOutputBuffer,0,iBufferSize);
350 aZStream.SetOutput(iOutputDescriptor);
354 void CBufferManager::NeedInputL(CEZZStream &aZStream)
361 remaining = iInputLength - aZStream.TotalIn();
362 if (remaining > iBufferSize)
363 remaining = iBufferSize;
364 Mem::Copy(iInputBuffer,iInput,remaining);
366 iInputDescriptor.Set(iInputBuffer,remaining,iBufferSize);
367 aZStream.SetInput(iInputDescriptor);
372 void CBufferManager::NeedOutputL(CEZZStream &aZStream)
378 iOutputDescriptor.Set(iOutputBuffer,remaining,remaining);
382 remaining = iOutputLength - aZStream.TotalOut();
383 if (remaining > iBufferSize)
384 remaining = iBufferSize;
386 TPtrC8 od = aZStream.OutputDescriptor();
387 Mem::Copy(iOutput,iOutputBuffer,od.Size());
388 aZStream.SetOutput(iOutputDescriptor);
389 iOutput += iBufferSize;
392 void CBufferManager::FinalizeL(CEZZStream &aZStream)
394 TInt copy = aZStream.OutputDescriptor().Size();
397 Mem::Copy(iOutput,iOutputBuffer,copy);
401 @SYMTestCaseID SYSLIB-EZLIB-CT-1328
402 @SYMTestCaseDesc Decompression of stream test
403 @SYMTestPriority High
404 @SYMTestActions Compresses and decompresses a buffer and tests to see whether the orginal and decompression streams
406 @SYMTestExpectedResults The test must not fail.
410 static void CompressDecompressL(const TTestFlags &aFlags)
412 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-1328 "));
413 CompressBufferL(aFlags);
414 DecompressBufferL(aFlags);
416 if (aFlags.iFlags & TTestFlags::Unicode)
418 TPtr s1(REINTERPRET_CAST(TText *, original),sizeof(original));
419 TPtr s2(REINTERPRET_CAST(TText *, uncompressed),sizeof(original));
420 Test(s1.Compare(s2) == 0,__LINE__);
425 TPtrC8 s2(uncompressed);
426 Test(s1.Compare(s2) == 0,__LINE__);
430 // Compresses the data in original and places it into compressed.
432 //Need to pass in RTest object as this function is called by a seperate thread sometimes
433 static void CompressBufferL(const TTestFlags &aFlags, RTest &aTest)
435 _LIT(KMsg,"\nTesting multi-step compresssion with buffer size %d\n");
436 aTest.Printf(KMsg,aFlags.iBufferSize);
437 aTest.Printf(KSeparator);
441 if (aFlags.iFlags & TTestFlags::Unicode)
443 sourceSize = sizeof(original) * sizeof(TText);
444 bm = CBufferManager::NewLC(REINTERPRET_CAST(TUint8*,originalU),sourceSize,compressed,256,aFlags.iBufferSize);
448 sourceSize = sizeof(original);
449 bm = CBufferManager::NewLC(original,sourceSize,compressed,256,aFlags.iBufferSize);
453 if (aFlags.iFlags & TTestFlags::FakeNoInput)
455 if (aFlags.iFlags & TTestFlags::FakeNoOutput)
459 #if defined(_DEBUG) && defined(__WINS__)
460 if (aFlags.iFlags & TTestFlags::AllocFail)
461 __UHEAP_SETFAIL(RHeap::ETrueRandom,5);
464 if (aFlags.iFlags & TTestFlags::Dictionary)
465 def = CEZCompressor::NewLC(*bm,aFlags.iDictionary,aFlags.iLevel,aFlags.iWindowBits,
466 aFlags.iMemLevel,aFlags.iStrategy);
468 def= CEZCompressor::NewLC(*bm,aFlags.iLevel,aFlags.iWindowBits,aFlags.iMemLevel,
471 while (def->DeflateL())
473 if (aFlags.iFlags & TTestFlags::Percent)
476 aTest.Printf(KPer,def->Progress(sourceSize));
479 if (aFlags.iFlags & TTestFlags::Percent)
480 aTest.Printf(_L("\n"));
482 compressedSize = def->TotalOut();
483 _LIT(KUnMsg,"Uncompressed Size %d\n");
484 _LIT(KComMsg,"Compressed Size %d\n");
486 if (aFlags.iFlags & TTestFlags::Corrupt)
487 compressed[compressedSize >> 1] = 1;
489 aTest.Printf(KUnMsg,def->TotalIn());
490 aTest.Printf(KComMsg,compressedSize);
491 CleanupStack::PopAndDestroy(2);
494 // Decompresses data stored in compressed and writes it to uncompressed.
496 //Need to pass in RTest object as this function is called by a seperate thread sometimes
497 static void DecompressBufferL(const TTestFlags &aFlags, RTest &aTest)
499 _LIT(KMsg,"\nTesting multi-step decompresssion with buffer size %d\n");
500 aTest.Printf(KMsg,aFlags.iBufferSize);
501 aTest.Printf(KSeparator);
502 CBufferManager *bm = CBufferManager::NewLC(compressed,compressedSize,uncompressed,256,aFlags.iBufferSize);
504 if (aFlags.iFlags & TTestFlags::FakeNoInput)
506 if (aFlags.iFlags & TTestFlags::FakeNoOutput)
509 #if defined(_DEBUG) && defined(__WINS__)
510 if (aFlags.iFlags & TTestFlags::AllocFail)
511 __UHEAP_SETFAIL(RHeap::ETrueRandom,10);
515 if (aFlags.iFlags & TTestFlags::Dictionary)
516 in = CEZDecompressor::NewLC(*bm,aFlags.iDictionary);
518 in = CEZDecompressor::NewLC(*bm);
520 #if defined(_DEBUG) && defined(__WINS__)
521 if (aFlags.iFlags & TTestFlags::AllocFailInflate)
522 __UHEAP_SETFAIL(RHeap::ETrueRandom,10);
525 while (in->InflateL())
527 if (aFlags.iFlags & TTestFlags::Percent)
530 aTest.Printf(KPer,in->Progress(compressedSize));
533 if (aFlags.iFlags & TTestFlags::Percent)
534 aTest.Printf(_L("\n"));
537 if (aFlags.iFlags & TTestFlags::Unicode)
539 TPtrC ptr(REINTERPRET_CAST(TText *,uncompressed),in->TotalOut() / sizeof(TText));
541 aTest.Printf(_L("\n"));
545 TPtrC8 ptr8(uncompressed);
546 TPtr ptr16(output,256);
549 aTest.Printf(_L("\n"));
551 CleanupStack::PopAndDestroy(2);
554 static void DblCompressBufferL(TInt aBufferSize, TBool aReset)
556 CEZCompressor *def = NULL;
558 _LIT(KMsg,"\nTesting multi-step compresssion with buffer size %d\n");
559 _LIT(KUnMsg,"Uncompressed Size %d\n");
560 _LIT(KComMsg,"Compressed Size %d\n");
562 Test.Printf(KMsg,aBufferSize);
563 Test.Printf(KSeparator,aBufferSize);
564 CBufferManager *bm = CBufferManager::NewLC(original,sizeof(original),compressed,256,aBufferSize);
565 def = CEZCompressor::NewLC(*bm);
567 while (def->DeflateL()){}
569 compressedSize = def->TotalOut();
570 Test.Printf(KUnMsg,sizeof(original));
571 Test.Printf(KComMsg,compressedSize);
574 CleanupStack::PopAndDestroy();
575 CleanupStack::PushL(def);
579 bm = CBufferManager::NewLC(original,sizeof(original),compressed,256,aBufferSize);
583 Test.Printf(KMsg,aBufferSize);
584 Test.Printf(KSeparator,aBufferSize);
586 while (def->DeflateL()){}
588 compressedSize = def->TotalOut();
589 Test.Printf(KUnMsg,sizeof(original));
590 Test.Printf(KComMsg,compressedSize);
592 CleanupStack::PopAndDestroy(2);
595 static void DblDecompressBufferL(TInt aBufferSize, TBool aReset)
597 CEZDecompressor *def = NULL;
599 _LIT(KMsg,"\nTesting multi-step decompresssion with buffer size %d\n");
600 Test.Printf(KMsg,aBufferSize);
601 Test.Printf(KSeparator);
602 CBufferManager *bm = CBufferManager::NewLC(compressed,compressedSize,uncompressed,256,aBufferSize);
603 def = CEZDecompressor::NewLC(*bm);
605 while (def->InflateL()){}
608 CleanupStack::PopAndDestroy();
609 CleanupStack::PushL(def);
613 bm = CBufferManager::NewLC(compressed,compressedSize,uncompressed,256,aBufferSize);
617 Test.Printf(KMsg,aBufferSize);
618 Test.Printf(KSeparator,aBufferSize);
620 while (def->InflateL()){}
622 TPtrC8 ptr8(uncompressed);
623 TPtr ptr16(output,256);
626 Test.Printf(_L("\n"));
628 CleanupStack::PopAndDestroy(2);
632 @SYMTestCaseID SYSLIB-EZLIB-CT-0785
633 @SYMTestCaseDesc Multistep compression & decompression test using buffers smaller than source & destination
634 @SYMTestPriority High
635 @SYMTestActions Set the test flags to 0,buffersize to 8
636 @SYMTestExpectedResults The test must not fail.
642 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0785 "));
643 TTestFlags flags(0,8);
644 CompressDecompressL(flags);
648 @SYMTestCaseID SYSLIB-EZLIB-CT-0786
649 @SYMTestCaseDesc Multistep compression & decompression test using buffers larger than source & destination
650 @SYMTestPriority High
651 @SYMTestActions Set the test flags to 0,buffersize to 1024
652 @SYMTestExpectedResults The test must not fail.
658 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0786 "));
659 TTestFlags flags(0,1024);
660 CompressDecompressL(flags);
664 @SYMTestCaseID SYSLIB-EZLIB-CT-0787
665 @SYMTestCaseDesc Multistep compression test
666 @SYMTestPriority High
667 @SYMTestActions Set the test flags to TTestFlags::FakeNoInput,buffersize to 8
668 @SYMTestExpectedResults The test must not fail.
674 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0787 "));
675 TTestFlags flags(TTestFlags::FakeNoInput,8);
677 TRAPD(err,CompressBufferL(flags));
678 Test (err==KErrNone); // This test should succeed as providing no Input is a valid thing for
683 @SYMTestCaseID SYSLIB-EZLIB-CT-0788
684 @SYMTestCaseDesc Multistep compression test when NeedOutput provides no output
685 @SYMTestPriority High
686 @SYMTestActions Set the test flags to TTestFlags::FakeNoOutput,buffersize to 8
687 Check for buffer error.
688 @SYMTestExpectedResults The test must not fail.
694 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0788 "));
695 TTestFlags flags(TTestFlags::FakeNoOutput,8);
697 TRAPD(err,CompressBufferL(flags));
698 Test (err==KEZlibErrBuf);
702 @SYMTestCaseID SYSLIB-EZLIB-CT-0789
703 @SYMTestCaseDesc Multistep compression test with the same CEZCompressor,
704 resetting it after the first compression
705 @SYMTestPriority High
706 @SYMTestActions Set the buffersize to 8,reset value to true
707 @SYMTestExpectedResults The test must not fail.
713 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0789 "));
714 DblCompressBufferL(8,ETrue);
718 @SYMTestCaseID SYSLIB-EZLIB-CT-0790
719 @SYMTestCaseDesc Multistep compression test with the same CEZCompressor,
720 without resetting it after the first compression
721 @SYMTestPriority High
722 @SYMTestActions Set the buffersize to 8,reset value to false
723 @SYMTestExpectedResults The test must not fail.
729 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0790 "));
730 //Calling compress twice without reseting (ie passing in EFalse) causes leave
731 TRAPD(err,DblCompressBufferL(8,EFalse));
732 Test (err==KEZlibErrDeflateTerminated);
736 @SYMTestCaseID SYSLIB-EZLIB-CT-0791
737 @SYMTestCaseDesc Multistep compression & decompression test using a preset dictionary
738 @SYMTestPriority High
739 @SYMTestActions Set the test flags to TTestFlags::Dictionary,buffersize to 8
740 @SYMTestExpectedResults The test must not fail.
746 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0791 "));
747 TTestFlags flags(TTestFlags::Dictionary,8);
748 flags.iDictionary.Set(dictionary,sizeof(dictionary));
750 CompressDecompressL(flags);
754 @SYMTestCaseID SYSLIB-EZLIB-CT-0792
755 @SYMTestCaseDesc Multistep compression with compression level of 0 test
756 @SYMTestPriority High
757 @SYMTestActions Set the test flags to 0,buffersize to 8,compression level to 0
758 @SYMTestExpectedResults The test must not fail.
764 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0792 "));
765 TTestFlags flags(0,8);
768 CompressDecompressL(flags);
772 @SYMTestCaseID SYSLIB-EZLIB-CT-0793
773 @SYMTestCaseDesc Multistep compression test with compression level of 9
774 @SYMTestPriority High
775 @SYMTestActions Set the test flags to 0,buffersize to 8,compression level to 9
776 @SYMTestExpectedResults The test must not fail.
782 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0793 "));
783 TTestFlags flags(0,8);
786 CompressDecompressL(flags);
790 @SYMTestCaseID SYSLIB-EZLIB-CT-0794
791 @SYMTestCaseDesc Multistep compression test with invalid compression level
792 @SYMTestPriority High
793 @SYMTestActions Set the test flags to 0,buffersize to 8,compression level to 10.
794 Check for stream error when compression level is greater than 9
795 @SYMTestExpectedResults The test must not fail.
801 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0794 "));
802 TTestFlags flags(0,8);
805 TRAPD(err, CompressDecompressL(flags));
806 //CompressL fails with KEZlibErrStream if level is greater than 9
807 Test (err==KEZlibErrStream);
811 @SYMTestCaseID SYSLIB-EZLIB-CT-0795
812 @SYMTestCaseDesc Multistep compression test with window bits of 7
813 @SYMTestPriority High
814 @SYMTestActions Set the test flags to 0,buffersize to 7
815 Check for stream error if window bits is less than 8
816 @SYMTestExpectedResults The test must not fail.
822 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0795 "));
823 TTestFlags flags(0,7);
824 flags.iWindowBits = 7;
825 //CompressL fails with KEZlibErrStream if window bits is less than 8
826 TRAPD(err, CompressDecompressL(flags));
827 Test (err==KEZlibErrStream);
831 @SYMTestCaseID SYSLIB-EZLIB-CT-0796
832 @SYMTestCaseDesc Multistep compression test with window bits of 7
833 @SYMTestPriority High
834 @SYMTestActions Set the test flags to 0,buffersize to 8
835 Check for stream error if window bits is less than 9
836 @SYMTestExpectedResults The test must not fail.
842 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0796 "));
843 TTestFlags flags(0,8);
844 flags.iWindowBits = 7;
845 //CompressL fails with KEZlibErrStream if window bits is less than 9
846 TRAPD(err, CompressDecompressL(flags));
847 Test (err==KEZlibErrStream);
851 @SYMTestCaseID SYSLIB-EZLIB-CT-0797
852 @SYMTestCaseDesc Multistep compression test with memory level = 1
853 @SYMTestPriority High
854 @SYMTestActions Set the test flags to 0,buffersize to 8
855 @SYMTestExpectedResults The test must not fail.
861 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0797 "));
862 TTestFlags flags(0,8);
865 CompressDecompressL(flags);
869 @SYMTestCaseID SYSLIB-EZLIB-CT-0798
870 @SYMTestCaseDesc Multistep compression test with memory level = 10
871 @SYMTestPriority High
872 @SYMTestActions Set the test flags to 0,buffersize to 8
873 Check for stream error if memory level is greater than 8.
874 @SYMTestExpectedResults The test must not fail.
880 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0798 "));
881 TTestFlags flags(0,8);
882 flags.iMemLevel = 10;
884 //CompressL fails with KEZlibErrStream if mem level greater than 8
885 TRAPD(err, CompressDecompressL(flags));
886 Test (err==KEZlibErrStream);
890 @SYMTestCaseID SYSLIB-EZLIB-CT-0799
891 @SYMTestCaseDesc Multistep compression test using only Huffman encoding
892 @SYMTestPriority High
893 @SYMTestActions Set the test flags to 0,buffersize to 8
894 @SYMTestExpectedResults The test must not fail.
900 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0799 "));
901 TTestFlags flags(0,8);
902 flags.iStrategy = CEZCompressor::EHuffmanOnly;
904 CompressDecompressL(flags);
908 @SYMTestCaseID SYSLIB-EZLIB-CT-0800
909 @SYMTestCaseDesc Multistep compression test using Filtered strategy
910 @SYMTestPriority High
911 @SYMTestActions Set the test flags to 0,buffersize to 8
912 @SYMTestExpectedResults The test must not fail.
918 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0800 "));
919 TTestFlags flags(0,8);
920 flags.iStrategy = CEZCompressor::EFiltered;
922 CompressDecompressL(flags);
926 @SYMTestCaseID SYSLIB-EZLIB-CT-0801
927 @SYMTestCaseDesc Multistep compression test when Alloc fails randomly
928 @SYMTestPriority High
929 @SYMTestActions Set the test flags to 0,buffersize to 8
930 @SYMTestExpectedResults The test must not fail.
936 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0801 "));
937 TTestFlags flags(TTestFlags::AllocFail,8);
939 TRAPD(err,CompressBufferL(flags));
940 Test(err == KErrNone||err == KErrNoMemory); //alloc failure is random so no quarantees of failure
941 //Need to reset the heap afterwards to avoid problems for next test.
946 @SYMTestCaseID SYSLIB-EZLIB-CT-0802
947 @SYMTestCaseDesc Multistep decompression test when NeedInput provides no input
948 @SYMTestPriority High
949 @SYMTestActions Set the test flags to 0,buffersize to 8
950 Check for data error,when no input is given
951 @SYMTestExpectedResults The test must not fail.
957 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0802 "));
958 TTestFlags flags(0,8);
959 CompressBufferL(flags); // make sure we initialize compressed properly
961 flags.iFlags |= TTestFlags::FakeNoInput;
962 TRAPD(err,DecompressBufferL(flags));
963 // CEZDecompressor::InflateL has left with KEZlibErrBuf due to buffer error
964 Test (err==KEZlibErrBuf);
968 @SYMTestCaseID SYSLIB-EZLIB-CT-0803
969 @SYMTestCaseDesc Multistep decompression test when NeedOutput provides no output
970 @SYMTestPriority High
971 @SYMTestActions Set the test flags to 0,buffersize to 8
972 Check for data error,when no output is given
973 @SYMTestExpectedResults The test must not fail.
979 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0803 "));
980 TTestFlags flags(0,8);
981 CompressBufferL(flags); // make sure we initialize compressed properly
983 flags.iFlags |= TTestFlags::FakeNoOutput;
984 TRAPD(err,DecompressBufferL(flags));
985 // CEZDecompressor::InflateL has left with KEZlibErrBuf due to buffer error
986 Test (err==KEZlibErrBuf);
990 @SYMTestCaseID SYSLIB-EZLIB-CT-0804
991 @SYMTestCaseDesc Multistep decompression test when NeedOutput provides no output
992 @SYMTestPriority High
993 @SYMTestActions Set the test flags to TTestFlags::Corrupt, buffersize to 8
995 @SYMTestExpectedResults The test must not fail.
1001 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0804 "));
1002 TTestFlags flags(TTestFlags::Corrupt,8);
1003 CompressBufferL(flags); // make sure we initialize compressed properly
1007 TRAPD(err,DecompressBufferL(flags));
1008 // CEZDecompressor::InflateL has left with KEZlibErrData due to buffer error
1009 Test (err==KEZlibErrData);
1013 @SYMTestCaseID SYSLIB-EZLIB-CT-0805
1014 @SYMTestCaseDesc Multistep decompression construction test when Alloc fails randomly
1015 @SYMTestPriority High
1016 @SYMTestActions Set the test flags to 0, buffersize to 8
1017 Check for data error
1018 @SYMTestExpectedResults The test must not fail.
1024 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0805 "));
1025 TTestFlags flags(0,8);
1026 CompressBufferL(flags); // make sure we initialize compressed properly
1028 flags.iFlags |= TTestFlags::AllocFail;
1030 TRAPD(err,DecompressBufferL(flags));
1031 Test (err==KErrNone||err==KErrNoMemory); //Alloc failure is random so no guarantee it will always fail.
1036 @SYMTestCaseID SYSLIB-EZLIB-CT-0806
1037 @SYMTestCaseDesc Multistep decompression test when Alloc fails randomly
1038 @SYMTestPriority High
1039 @SYMTestActions Set the test flags to 0, buffersize to 8
1040 Check for no memory errors.
1041 @SYMTestExpectedResults The test must not fail.
1047 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0806 "));
1048 TTestFlags flags(0,8);
1049 CompressBufferL(flags); // make sure we initialize compressed properly
1051 flags.iFlags |= TTestFlags::AllocFailInflate;
1053 TRAPD(err,DecompressBufferL(flags));
1054 Test (err==KErrNone||err==KErrNoMemory); //Alloc failure is random so no guarentee it will always fail.
1058 static void ThreadL()
1060 RTest test2(_L("EZLIB - second thread"));
1062 _LIT(KStartMsg,"Starting Tests in second thread");
1063 test2.Start(KStartMsg);
1065 TTestFlags flags(TTestFlags::Dictionary,8);
1066 flags.iDictionary.Set(dictionary,sizeof(dictionary));
1068 TRAPD(err,CompressBufferL(flags, test2));
1069 test2 (err == KErrNone);
1071 //This code leaves (used to panic before the fix for DEF112672)
1072 DecompressBufferL(flags, test2);
1073 User::Panic(_L("TestFailure failure"),0);
1078 static TInt TestThread(TAny*)
1080 User::SetJustInTime(EFalse); // disable debugger panic handling
1081 CTrapCleanup* cleanup=CTrapCleanup::New();
1083 return KErrNoMemory;
1090 @SYMTestCaseID SYSLIB-EZLIB-CT-0807
1091 @SYMTestCaseDesc Multistep decompression test when a dictionary is required and not provided.
1092 @SYMTestPriority High
1093 @SYMTestActions Test for panic and exit reason.
1094 @SYMTestExpectedResults This test should pass without panic.
1095 (Expected to panic before the fix for DEF112672)
1101 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0807 "));
1105 _LIT(KTestThread,"Panicing thread");
1106 Test.Printf(_L("launching thread"));
1107 Test (t.Create(KTestThread,&TestThread,0x2000,0x10000,0x100000,0,EOwnerThread) == KErrNone);
1110 Test (s.Int()==KRequestPending);
1112 Test.Printf(_L("Awaiting completion"));
1113 User::WaitForRequest(s);
1114 User::SetJustInTime(ETrue); // enable debugger panic handling
1115 _LIT(KCategory,"zlib");
1116 Test (t.ExitType()==EExitKill);
1117 Test (t.ExitCategory()!=KCategory);
1118 Test (t.ExitReason()==KEZlibErrData);// SetDictionaryL() leaving error code should be KEZlibErrData
1126 @SYMTestCaseID SYSLIB-EZLIB-CT-0808
1127 @SYMTestCaseDesc Multistep decompression test when the wrong dictionary is provided
1128 @SYMTestPriority High
1129 @SYMTestActions Check for an error during inflating the dictionary
1130 @SYMTestExpectedResults Test must not fail
1136 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0808 "));
1137 TTestFlags flags(TTestFlags::Dictionary,8);
1138 flags.iDictionary.Set(dictionary,sizeof(dictionary));
1140 CompressBufferL(flags);
1142 flags.iDictionary.Set(badDictionary,sizeof(badDictionary));
1144 TRAPD(err,DecompressBufferL(flags));
1145 // CEZDecompressor::SetDictionaryL() has left due to bad data
1146 Test (err==KEZlibErrInflateDictionary);
1150 @SYMTestCaseID SYSLIB-EZLIB-CT-0809
1151 @SYMTestCaseDesc Multistep decompression test twice with the same CEZDecompressor,
1152 reseting it after the first decompression
1153 @SYMTestPriority High
1154 @SYMTestActions Set the test flags to 0,buffersize to 8,reset value to TRUE
1155 @SYMTestExpectedResults Test must not fail
1161 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0809 "));
1162 TTestFlags flags(0,8);
1163 CompressBufferL(flags); // make sure we initialize compressed properly
1165 DblDecompressBufferL(8,ETrue);
1169 @SYMTestCaseID SYSLIB-EZLIB-CT-0810
1170 @SYMTestCaseDesc Multistep decompression test twice with the same CEZDecompressor,
1171 resetting it after the first decompression
1172 @SYMTestPriority High
1173 @SYMTestActions Set the test flags to 0,buffersize to 8,reset value to FALSE
1174 Check for deflation already occured.
1175 @SYMTestExpectedResults Test must not fail
1181 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0810 "));
1182 TTestFlags flags(0,8);
1183 CompressBufferL(flags); // make sure we initialize compressed properly
1185 TRAPD(err,DblDecompressBufferL(8,EFalse));
1186 //Calling decompress twice without resenting causes leave
1187 Test (err==KEZlibErrInflateTerminated);
1191 @SYMTestCaseID SYSLIB-EZLIB-CT-0811
1192 @SYMTestCaseDesc Multistep compression and decompression test on unicode data
1193 @SYMTestPriority High
1194 @SYMTestActions Set the test flags to TTestFlags::Unicode,buffersize to 8
1195 @SYMTestExpectedResults Test must not fail
1201 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0811 "));
1202 TPtrC8 ptr8(original);
1203 TPtr ptr16(originalU,256);
1206 TTestFlags flags(TTestFlags::Unicode,8);
1207 TPtrC8(REINTERPRET_CAST(TUint8 *,originalU),ptr16.Size());
1208 CompressDecompressL(flags);
1212 @SYMTestCaseID SYSLIB-EZLIB-CT-0812
1213 @SYMTestCaseDesc Multistep compression and decompression test on unicode data using a unicode dictionary
1214 @SYMTestPriority High
1215 @SYMTestActions Set the test flags to TTestFlags::Dictionary|TTestFlags::Unicode,buffersize to 8
1216 @SYMTestExpectedResults Test must not fail
1222 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0812 "));
1223 TPtrC8 ptr8(original);
1224 TPtr ptr16(originalU,256);
1227 TPtrC8 dptr8(dictionary);
1228 TPtr dptr16(dictionaryU,256);
1232 TTestFlags flags(TTestFlags::Dictionary|TTestFlags::Unicode,8);
1233 flags.iDictionary.Set(REINTERPRET_CAST(TUint8*, dictionaryU),dptr16.Size());
1235 TPtrC8(REINTERPRET_CAST(TUint8 *,originalU),ptr16.Size());
1236 CompressDecompressL(flags);
1240 @SYMTestCaseID SYSLIB-EZLIB-CT-0813
1241 @SYMTestCaseDesc Multistep compression and decompression test on unicode data using an ASCII dictionary
1242 @SYMTestPriority High
1243 @SYMTestActions Set the test flags to TTestFlags::Dictionary|TTestFlags::Unicode,buffersize to 8
1244 @SYMTestExpectedResults Test must not fail
1250 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0813 "));
1251 TPtrC8 ptr8(original);
1252 TPtr ptr16(originalU,256);
1255 TTestFlags flags(TTestFlags::Dictionary|TTestFlags::Unicode,8);
1256 flags.iDictionary.Set(dictionary,sizeof(dictionary));
1258 TPtrC8(REINTERPRET_CAST(TUint8 *,originalU),ptr16.Size());
1259 CompressDecompressL(flags);
1263 @SYMTestCaseID SYSLIB-EZLIB-CT-0814
1264 @SYMTestCaseDesc Tests the percentage of completion during multistep compression/decompression
1265 @SYMTestPriority High
1266 @SYMTestActions Set the test flags to TTestFlags::Percent,buffersize to 8
1267 @SYMTestExpectedResults Test must not fail
1273 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0814 "));
1274 TTestFlags flags(TTestFlags::Percent,8);
1276 CompressDecompressL(flags);
1280 @SYMTestCaseID SYSLIB-EZLIB-CT-0815
1281 @SYMTestCaseDesc Single step compression and decompression test
1282 @SYMTestPriority High
1283 @SYMTestActions Calls up CEZCompressor::CompressL(),CEZCompressor::DecompressL() test
1284 @SYMTestExpectedResults Test must not fail
1290 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0815 "));
1291 TPtrC8 originalD(original,sizeof(original));
1292 TPtr8 compressedD(compressed,0,256);
1293 TPtr8 uncompressedD(uncompressed,0,256);
1294 CEZCompressor::CompressL(compressedD,originalD);
1295 CEZDecompressor::DecompressL(uncompressedD,compressedD);
1297 Test.Printf(_L("\n"));
1298 Test.Printf(KSeparator);
1299 TPtr ptr16(output,256);
1300 ptr16.Copy(uncompressedD);
1302 Test.Printf(_L("\n"));
1303 Test(originalD.Compare(uncompressedD) == 0,__LINE__);
1307 @SYMTestCaseID SYSLIB-EZLIB-CT-0816
1308 @SYMTestCaseDesc Single step compression test when inadequate output buffer is provided
1309 @SYMTestPriority High
1310 @SYMTestActions Check for EZlibErrBuf buffer error flag
1311 @SYMTestExpectedResults Test must not fail
1317 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0816 "));
1318 TPtrC8 originalD(original,sizeof(original));
1319 TPtr8 compressedD(compressed,0,1);
1321 Test.Printf(_L("\n"));
1322 Test.Printf(KSeparator);
1324 TRAPD(err,CEZCompressor::CompressL(compressedD,originalD));
1326 Test(err == KEZlibErrBuf);
1330 @SYMTestCaseID SYSLIB-EZLIB-CT-0817
1331 @SYMTestCaseDesc Single step decompression test when inadequate output buffer is provided
1332 @SYMTestPriority High
1333 @SYMTestActions Check for EZlibErrBuf buffer error flag
1334 @SYMTestExpectedResults Test must not fail
1340 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0817 "));
1341 Test.Printf(_L("\n"));
1342 Test.Printf(KSeparator);
1343 TPtrC8 originalD(original,sizeof(original));
1344 TPtr8 compressedD(compressed,0,256);
1345 TPtr8 uncompressedD(uncompressed,0,1);
1346 CEZCompressor::CompressL(compressedD,originalD);
1347 TRAPD(err,CEZDecompressor::DecompressL(uncompressedD,compressedD));
1349 Test(err == KEZlibErrBuf);
1353 @SYMTestCaseID SYSLIB-EZLIB-CT-0818
1354 @SYMTestCaseDesc Testing graceful exit for zlib 1.1.3 decompression bug
1355 @SYMTestPriority High
1356 @SYMTestActions Check for buffer error after inflation
1357 @SYMTestExpectedResults Test must not fail
1362 Test.Printf(_L("\n"));
1363 Test.Printf(KSeparator);
1364 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0818 "));
1365 // 00000720.png contains specially crafted data block that exposes bug in 1.1.3
1366 // decompression algorithm. Causes InflateL() to return Z_BUF_ERROR.
1367 #if !defined(__WINS__)
1368 _LIT(KInputFile, "z:\\test\\png\\00000720.png");
1370 _LIT(KInputFile, "c:\\test\\png\\00000720.png");
1372 _LIT(KTempDirectory, "c:\\test\\temp\\");
1373 RFile input, output, tempInput;
1376 rfs.MkDirAll(KTempDirectory);
1378 TInt res = input.Open(rfs, KInputFile, EFileStream | EFileRead | EFileShareAny);
1379 Test(res==KErrNone);
1380 CleanupClosePushL(input);
1383 TBuf8<1024> readBuf;
1385 input.Size(fileLen);
1386 res = input.Read(8,readBuf,fileLen);
1387 Test(res==KErrNone);
1389 res = tempInput.Temp(rfs, KTempDirectory, filename, EFileStream | EFileWrite | EFileShareExclusive);
1390 Test(res==KErrNone);
1391 CleanupClosePushL(tempInput);
1392 res = tempInput.Write(readBuf, fileLen-8); // Create temporary file without the 8 byte PNG header.
1393 Test(res==KErrNone);
1395 CEZFileBufferManager *fb = CEZFileBufferManager::NewLC(tempInput, output, 4096);
1396 CEZDecompressor *inf = CEZDecompressor::NewLC(*fb);
1398 TRAPD(err, while (inf->InflateL()){});
1399 //CEZDecompressor::InflateL() leaves
1400 Test (err==KEZlibErrBuf);
1403 User::LeaveIfError(rfs.Delete(filename));
1405 CleanupStack::PopAndDestroy(4);
1408 #if !(defined(__WINSCW__) || defined (_DEBUG))
1409 void DecompressFileL(const TDesC& aFilePath, RFs& aFs, TInt aTimingLimit)
1411 _LIT(KTempDirectory, "c:\\test\\temp\\");
1412 aFs.MkDirAll(KTempDirectory);
1414 RFile inputFile, tempFile;
1415 //open the input compressed file
1416 TInt res = inputFile.Open(aFs, aFilePath, EFileStream | EFileRead | EFileShareExclusive);
1417 Test(res==KErrNone);
1418 CleanupClosePushL(inputFile);
1420 //create a temporary file to be used as an output of the decompressor
1422 res = tempFile.Temp(aFs, KTempDirectory, filename, EFileStream | EFileWrite | EFileShareExclusive);
1423 Test(res==KErrNone);
1424 CleanupClosePushL(tempFile);
1426 //decompress the data from the input file several times
1427 TInt startTime = User::FastCounter();
1428 for (TInt i = 0; i<10; i++)
1431 inputFile.Seek(ESeekStart,position);
1432 CEZFileBufferManager *fb = CEZFileBufferManager::NewLC(inputFile, tempFile, 4096);
1433 //create a decompressor object based on the file buffer manager
1434 CEZDecompressor *decompressor = CEZDecompressor::NewLC(*fb);
1435 TRAP(res, while (decompressor->InflateL()){});
1436 Test(res==KErrNone);
1437 CleanupStack::PopAndDestroy(2);
1439 TInt endTime = User::FastCounter();
1441 //close input and temporary file
1442 CleanupStack::PopAndDestroy(2);
1443 //delete temporary file
1444 aFs.Delete(filename);
1446 TReal netTime = FastCountToMilliseconds(endTime-startTime);
1447 _LIT(KLogLine,"netTime =%f\n");
1448 Test.Printf(KLogLine,netTime);
1452 Test(netTime <= aTimingLimit);
1456 Test.Printf(_L("Timings results are only checked on the RAM configuration of H2 and H4 HRP\n"));
1462 @SYMTestCaseID SYSLIB-EZLIB-CT-3426
1463 @SYMTestCaseDesc Testing EZlib decompressor performance after enforcing compiler optimisation
1464 @SYMTestPriority Medium
1465 @SYMTestActions This test uses several typical pieces of compressed
1466 image data as an input and inflates them 10 times.
1467 The total duration of this operation is measured and
1468 compared against a benchmarking limit. Only performed
1469 on UREL builds running on H2 and H4 hardware.
1470 @SYMTestExpectedResults Time spent on decompression should be less than a preset limit.
1476 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-3426 "));
1477 #if !(defined(__WINSCW__) || defined (_DEBUG))
1478 Test.Printf(_L("\n"));
1479 Test.Printf(KSeparator);
1480 _LIT(KInputFile1, "z:\\test\\png\\compressed_data1");//A small-sized picture with
1481 //transparent background which
1482 //represents typical UI component
1485 _LIT(KInputFile2, "z:\\test\\png\\compressed_data2");//Medium-sized picture with a
1486 //single image typical for a UI
1487 //theme background image
1489 _LIT(KInputFile3, "z:\\test\\png\\compressed_data3");//Medium-sized picture with
1490 //multiple small images on it
1491 //typical for a sheet of UI
1494 _LIT(KInputFile4, "z:\\test\\png\\compressed_data4");//Large-sized photo image
1498 CleanupClosePushL(rfs);
1500 // determine media type of C drive
1501 TDriveInfo driveInf;
1502 TInt res = rfs.Drive(driveInf, EDriveC);
1503 Test(res==KErrNone);
1505 TInt timingLimit1 = 0;
1506 TInt timingLimit2 = 0;
1507 TInt timingLimit3 = 0;
1508 TInt timingLimit4 = 0;
1509 // only check benchmarks if running on hardware, with UREL + RAM build (i.e. not NAND)
1510 if (driveInf.iType == EMediaRam)
1513 res= HAL::Get(HAL::EMachineUid, muid);
1514 Test(res==KErrNone);
1517 case HAL::EMachineUid_OmapH2:
1519 timingLimit2 = 1650;
1520 timingLimit3 = 2900;
1521 timingLimit4 = 2750;
1523 case HAL::EMachineUid_OmapH4:
1526 timingLimit3 = 1400;
1527 timingLimit4 = 1500;
1534 DecompressFileL(KInputFile1, rfs, timingLimit1);
1535 DecompressFileL(KInputFile2, rfs, timingLimit2);
1536 DecompressFileL(KInputFile3, rfs, timingLimit3);
1537 DecompressFileL(KInputFile4, rfs, timingLimit4);
1538 CleanupStack::PopAndDestroy();
1540 Test.Printf(_L("This test is only performed on hardware UREL builds\n"));
1545 @SYMTestCaseID SYSLIB-EZLIB-UT-3684
1546 @SYMTestCaseDesc Test the memory deallocation of the CEZFileBufferManager object to ensure that
1547 there is no memory leak on success or failure of file compression and decompression
1548 @SYMTestPriority High
1549 @SYMTestActions Compressing and Decompressing a png image using CEZCompressor::InflateL() and
1550 CEZDecompressor::DeflateL()
1551 @SYMTestExpectedResults Test must not fail and memory must not leak afterdeallocating CEZFileBufferManager
1557 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-3684 "));
1558 Test.Printf(_L("\n"));
1559 Test.Printf(KSeparator);
1560 //Set the path of input file and output files
1561 #if !defined(__WINS__)
1562 _LIT(KInputFile, "z:\\test\\png\\00000720.png");
1564 _LIT(KInputFile, "c:\\test\\png\\00000720.png");
1566 _LIT(KOutputFile, "c:\\test\\temp\\00000720.z");
1567 _LIT(KUncompressedFile, "c:\\test\\temp\\000007201");
1571 CleanupClosePushL(rfs);
1573 TPtrC inputFile(KInputFile);
1574 TPtrC outputFile(KOutputFile);
1575 TPtrC uncompressedFile(KUncompressedFile);
1580 //Open the PNG file for compressing
1581 User::LeaveIfError(input.Open(rfs, inputFile,EFileStream | EFileRead | EFileShareAny));
1582 CleanupClosePushL(input);
1584 //Create file to store output of file compressing
1585 err = output.Create(rfs, outputFile,EFileStream | EFileWrite | EFileShareExclusive);
1586 if (err == KErrAlreadyExists)//Just in case if the output file already exists then open it.
1587 User::LeaveIfError(output.Open(rfs, outputFile,EFileStream | EFileWrite | EFileShareExclusive));
1589 User::LeaveIfError(err);
1590 CleanupClosePushL(output);
1593 //Create and assign the CEZFileBufferManager object 'fb' as the compressor's buffer manager
1594 CEZFileBufferManager *fb = CEZFileBufferManager::NewLC(input,output,16384);
1595 CEZCompressor *def = CEZCompressor::NewLC(*fb);
1597 while (def->DeflateL()){/*do nothing*/}
1599 CleanupStack::PopAndDestroy(def);
1600 CleanupStack::PopAndDestroy(fb);
1603 CleanupStack::PopAndDestroy(&output);
1604 CleanupStack::PopAndDestroy(&input);
1605 //Now open the compressed file for decompressing
1606 User::LeaveIfError(input.Open(rfs, outputFile,EFileStream | EFileRead | EFileShareAny));
1607 CleanupClosePushL(input);
1609 //Create file to store output of decompressing
1610 err = output.Create(rfs, uncompressedFile,EFileStream | EFileWrite | EFileShareExclusive);
1611 if (err == KErrAlreadyExists)//Just in case if the output file already exists then open it.
1612 User::LeaveIfError(output.Open(rfs, uncompressedFile,EFileStream | EFileWrite | EFileShareExclusive));
1614 User::LeaveIfError(err);
1616 CleanupClosePushL(output);
1619 //Create and assign the CEZFileBufferManager object 'fb' as the decompressor's buffer manager
1620 fb = CEZFileBufferManager::NewLC(input,output,16384);
1621 CEZDecompressor *inf = CEZDecompressor::NewLC(*fb);
1623 while (inf->InflateL()){/*do nothing*/}
1625 CleanupStack::PopAndDestroy(inf);
1626 CleanupStack::PopAndDestroy(fb);
1631 CleanupStack::PopAndDestroy(&output);
1632 CleanupStack::PopAndDestroy(&input);
1633 CleanupStack::PopAndDestroy(&rfs);
1637 @SYMTestCaseID SYSLIB-EZLIB2-UT-4298
1638 @SYMTestCaseDesc Test CEZZStream functions through CEZCompressor class e.g.
1639 Adler32(), AvailIn(), AvailOut()
1640 @SYMTestPriority High
1641 @SYMTestActions 1. Compress stream of data using CEZCompressor::NewLC() & CEZCompressor::DeflateL()
1642 2. Call CEZCompressor::Adler32() to get the checksum value of the uncompressed data
1643 3. Call CEZCompressor::AvailIn() to get the number of bytes available at the next input byte
1644 4. Call CEZCompressor::AvailOut() to get the remaining free space at next output byte target
1645 @SYMTestExpectedResults The test succeeds with no errors i.e. KErrNone
1649 void TestCEZCompressorMethodsL()
1651 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4298 "));
1655 sourceSize = sizeof(original);
1656 bm = CBufferManager::NewLC(original,sourceSize,compressed,256,8);
1657 CEZCompressor *compressor = CEZCompressor::NewLC(*bm);
1663 while(compressor->DeflateL()){/*do nothing*/}
1665 adler32 = compressor->Adler32();
1668 availIn = compressor->AvailIn();
1671 availOut = compressor->AvailOut();
1674 CleanupStack::PopAndDestroy(compressor);
1675 CleanupStack::PopAndDestroy(bm);
1679 @SYMTestCaseID SYSLIB-EZLIB2-UT-4300
1680 @SYMTestCaseDesc TTest Zlibapiwrapper.cpp exported API's like inflate,
1681 deflate, compress, decompress
1682 @SYMTestPriority High
1683 @SYMTestActions Call the exported C APIs of Zlibapiwrapper.cpp
1684 Note: This is done to check if the C APIs of zlib.lib
1685 are called through ezlib.lib.
1686 @SYMTestExpectedResults All exported C API's should be called (i.e. run a basic scenario
1687 of compressing some data) & test must not fail
1691 void TestZlibapiwrapperAPIL()
1693 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4300 "));
1694 z_stream deflateStream;
1695 const char inputData[] = "inputData!"; // data to compress
1696 uLong inputDataLength = (uLong)sizeof(inputData) + 1;
1697 Byte *compressedDataBuffer; // output buffer
1698 //The buffer size is kept as 50 but incase the input data is changed..
1699 //...the buffer size also has to be increased accordingly
1700 TInt compressedDataBufferLength = 50;
1702 // Allocate memory for output buffer
1703 compressedDataBuffer = (Byte*)User::AllocZ(compressedDataBufferLength);
1704 Test(compressedDataBuffer != Z_NULL);
1705 CleanupStack::PushL(compressedDataBuffer);
1707 // Initialise the stream
1708 deflateStream.zalloc = (alloc_func)0;
1709 deflateStream.zfree = (free_func)0;
1710 deflateStream.opaque = (voidpf)0;
1712 int level = Z_DEFAULT_COMPRESSION;
1716 err = deflateInit(&deflateStream, level);
1720 deflateEnd(&deflateStream);
1725 // Compress data in the input buffer
1726 deflateStream.next_in = (Byte*)inputData;
1727 deflateStream.next_out = compressedDataBuffer;
1731 if (deflateStream.total_in < inputDataLength)
1733 deflateStream.avail_in = 1; // force small buffer
1736 flush = (deflateStream.total_in == inputDataLength) ? Z_FINISH : Z_NO_FLUSH;
1738 // run deflate() on input until output buffer not full, finish
1739 // compression if all of source has been read in
1742 if (deflateStream.total_out < compressedDataBufferLength)
1744 deflateStream.avail_out = 1; // force small buffer
1747 err = deflate(&deflateStream, flush);
1748 if(err != Z_OK && err != Z_STREAM_END)
1750 deflateEnd(&deflateStream);
1751 Test(err == Z_OK || err == Z_STREAM_END);
1753 } while(deflateStream.avail_out == 0 && err == Z_OK);
1754 } while(err != Z_STREAM_END);
1756 deflateEnd(&deflateStream);
1757 CleanupStack::PopAndDestroy(compressedDataBuffer);
1762 @SYMTestCaseID SYSLIB-EZLIB-UT-4001
1763 @SYMTestCaseDesc Test for DEF112672 - Panic ZLIB 11 - when installing the sisx file.
1764 The test attempts to decompress a buffer with the "Dictionary" flag set
1765 but with NULL dictionary buffer. The test should not cause an assert in the EZLib library.
1766 @SYMTestPriority Normal
1767 @SYMTestActions Test for DEF112672 - Panic ZLIB 11 - when installing the sisx file.
1768 @SYMTestExpectedResults Test must not fail
1774 Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-UT-4001 "));
1775 TTestFlags flags(TTestFlags::Dictionary, 8);
1776 flags.iDictionary.Set(dictionary, sizeof(dictionary));
1777 CompressBufferL(flags);
1778 flags.iDictionary.Set(0, 0);
1779 TRAPD(err, DecompressBufferL(flags));
1780 Test(err == KEZlibErrData);
1785 for (TInt testNum=1; testNum<KNumberOfTests; testNum++)
1788 _LIT(KTestNum,"\n\nRunning Test %d\n\n");
1790 buf.Format(KTestNum, testNum);
1793 Test.Printf(KStrMsg, testTable[testNum].iDescription);
1794 testTable[testNum].iFn();
1800 GLDEF_C TInt E32Main()
1802 CTrapCleanup* cleanup=CTrapCleanup::New();
1804 _LIT(KStartMsg,"Starting Tests..");
1805 Test.Start(KStartMsg);
1807 TRAPD(err,RunTestL());
1808 Test (err==KErrNone);