sl@0: // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: sl@0: _LIT(KSeparator,"----------------------------------------------------------------\n"); sl@0: sl@0: const TInt KNumberOfTests = 38; sl@0: _LIT(KTest1,"Multistep compression & decompression using buffers smaller than source & destination"); sl@0: _LIT(KTest2,"Multistep compression & decompression using buffers larger than source & destination"); sl@0: _LIT(KTest3,"Test Multistep compression when NeedInput provides no input"); sl@0: _LIT(KTest4,"Test Multistep compression when NeedOutput provides no output"); sl@0: _LIT(KTest5,"Perform multistep compression 2 with the same CEZCompressor, reseting it\n\ sl@0: after the first compression."); sl@0: _LIT(KTest6,"Perform multistep compression 2 with the same CEZCompressor, without reseting it\n\ sl@0: after the first compression."); sl@0: _LIT(KTest7,"Performs multistep compression & decompression using a preset dicitonary."); sl@0: _LIT(KTest8,"Performs multistep compression with compression level of 0."); sl@0: _LIT(KTest9,"Performs multistep compression with compression level of 9."); sl@0: _LIT(KTest10,"Performs multistep compression with invalid compression level."); sl@0: _LIT(KTest11,"Performs multistep compression with window bits of 8."); sl@0: _LIT(KTest12,"Performs multistep compression with an invalid value for window bits."); sl@0: _LIT(KTest13,"Performs multistep compression with memory level = 1."); sl@0: _LIT(KTest14,"Performs multistep compression with an invalid memory level."); sl@0: _LIT(KTest15,"Performs multistep compression using only Huffman encoding."); sl@0: _LIT(KTest16,"Performs multistep compression using Filtered strategy."); sl@0: _LIT(KTest17,"Performs multistep compression when Alloc fails randomly."); sl@0: _LIT(KTest18,"Test Multistep decompression when NeedInput provides no input."); sl@0: _LIT(KTest19,"Test Multistep decompression when NeedOutput provides no output."); sl@0: _LIT(KTest20,"Test Multistep decompression when compressed stream is corrupt."); sl@0: _LIT(KTest21,"Test Multistep decompressor construction when Alloc fails randomly."); sl@0: _LIT(KTest22,"Test Multistep decompression when Alloc fails randomly."); sl@0: _LIT(KTest23,"Test Multistep decompression when a dictionary is required and not provided.\n\ sl@0: This test should panic."); sl@0: _LIT(KTest24,"Test Multistep decompression when a dictionary when the wrong dictionary is provided."); sl@0: _LIT(KTest25,"Perform multistep decompression twice with the same CEZDecompressor, reseting it\n\ sl@0: after the first decompression."); sl@0: _LIT(KTest26,"Perform multistep decompression twice with the same CEZDecompressor, reseting it\n\ sl@0: after the first decompression."); sl@0: _LIT(KTest27,"Perform multistep compression and decompression on unicode data."); sl@0: _LIT(KTest28,"Perform multistep compression and decompression on unicode data using a unicode dictionary."); sl@0: _LIT(KTest29,"Perform multistep compression and decompression on unicode data using an ascii dictionary."); sl@0: _LIT(KTest30,"Test percentage of completion during multistep compression/decompression."); sl@0: _LIT(KTest31,"Test single step compression and decompression."); sl@0: _LIT(KTest32,"Test single step compression when indaquate output buffer is provided."); sl@0: _LIT(KTest33,"Test single step decompression when indaquate output buffer is provided."); sl@0: _LIT(KTest34,"Testing graceful exit for zlib 1.1.3 decompression bug. See: INC022729."); sl@0: _LIT(KTest35,"Testing EZlib decompression performance with enforced compiler optimisation"); sl@0: _LIT(KTest36,"Testing correct memory deallocation for CEZFileBufferManager. See: DEF109756."); sl@0: _LIT(KTest37,"Test CEZZStream functions through CEZCompressor class."); sl@0: _LIT(KTest38,"Test Calls to Zlibapiwrapper.cpp exported API's like inflate, deflate, compress, decompress"); sl@0: sl@0: const TPtrC KTest1Des(KTest1); sl@0: const TPtrC KTest2Des(KTest2); sl@0: const TPtrC KTest3Des(KTest3); sl@0: const TPtrC KTest4Des(KTest4); sl@0: const TPtrC KTest5Des(KTest5); sl@0: const TPtrC KTest6Des(KTest6); sl@0: const TPtrC KTest7Des(KTest7); sl@0: const TPtrC KTest8Des(KTest8); sl@0: const TPtrC KTest9Des(KTest9); sl@0: const TPtrC KTest10Des(KTest10); sl@0: const TPtrC KTest11Des(KTest11); sl@0: const TPtrC KTest12Des(KTest12); sl@0: const TPtrC KTest13Des(KTest13); sl@0: const TPtrC KTest14Des(KTest14); sl@0: const TPtrC KTest15Des(KTest15); sl@0: const TPtrC KTest16Des(KTest16); sl@0: const TPtrC KTest17Des(KTest17); sl@0: const TPtrC KTest18Des(KTest18); sl@0: const TPtrC KTest19Des(KTest19); sl@0: const TPtrC KTest20Des(KTest20); sl@0: const TPtrC KTest21Des(KTest21); sl@0: const TPtrC KTest22Des(KTest22); sl@0: const TPtrC KTest23Des(KTest23); sl@0: const TPtrC KTest24Des(KTest24); sl@0: const TPtrC KTest25Des(KTest25); sl@0: const TPtrC KTest26Des(KTest26); sl@0: const TPtrC KTest27Des(KTest27); sl@0: const TPtrC KTest28Des(KTest28); sl@0: const TPtrC KTest29Des(KTest29); sl@0: const TPtrC KTest30Des(KTest30); sl@0: const TPtrC KTest31Des(KTest31); sl@0: const TPtrC KTest32Des(KTest32); sl@0: const TPtrC KTest33Des(KTest33); sl@0: const TPtrC KTest34Des(KTest34); sl@0: const TPtrC KTest35Des(KTest35); sl@0: const TPtrC KTest36Des(KTest36); sl@0: const TPtrC KTest37Des(KTest37); sl@0: const TPtrC KTest38Des(KTest38); sl@0: sl@0: void Test1L(); sl@0: void Test2L(); sl@0: void Test3(); sl@0: void Test4(); sl@0: void Test5L(); sl@0: void Test6(); sl@0: void Test7L(); sl@0: void Test8L(); sl@0: void Test9L(); sl@0: void Test10(); sl@0: void Test11(); sl@0: void Test12(); sl@0: void Test13L(); sl@0: void Test14(); sl@0: void Test15L(); sl@0: void Test16L(); sl@0: void Test17(); sl@0: void Test18L(); sl@0: void Test19L(); sl@0: void Test20L(); sl@0: void Test21L(); sl@0: void Test22L(); sl@0: void Test23(); sl@0: void Test24L(); sl@0: void Test25L(); sl@0: void Test26L(); sl@0: void Test27L(); sl@0: void Test28L(); sl@0: void Test29L(); sl@0: void Test30L(); sl@0: void Test31L(); sl@0: void Test32(); sl@0: void Test33L(); sl@0: void Test34L(); sl@0: void Test35L(); sl@0: void Test36L(); sl@0: void TestCEZCompressorMethodsL(); sl@0: void TestZlibapiwrapperAPIL(); sl@0: sl@0: typedef void (*TestPtr)(); sl@0: sl@0: struct TTests sl@0: { sl@0: TestPtr iFn; sl@0: const TPtrC *iDescription; sl@0: }; sl@0: sl@0: const TTests testTable[] = { sl@0: {Test1L,&KTest1Des}, sl@0: {Test2L,&KTest2Des}, sl@0: {Test3,&KTest3Des}, sl@0: {Test4,&KTest4Des}, sl@0: {Test5L,&KTest5Des}, sl@0: {Test6,&KTest6Des}, sl@0: {Test7L,&KTest7Des}, sl@0: {Test8L,&KTest8Des}, sl@0: {Test9L,&KTest9Des}, sl@0: {Test10,&KTest10Des}, sl@0: {Test11,&KTest11Des}, sl@0: {Test12,&KTest12Des}, sl@0: {Test13L,&KTest13Des}, sl@0: {Test14,&KTest14Des}, sl@0: {Test15L,&KTest15Des}, sl@0: {Test16L,&KTest16Des}, sl@0: {Test17,&KTest17Des}, sl@0: {Test18L,&KTest18Des}, sl@0: {Test19L,&KTest19Des}, sl@0: {Test20L,&KTest20Des}, sl@0: {Test21L,&KTest21Des}, sl@0: {Test22L,&KTest22Des}, sl@0: {Test23,&KTest23Des}, sl@0: {Test24L,&KTest24Des}, sl@0: {Test25L,&KTest25Des}, sl@0: {Test26L,&KTest26Des}, sl@0: {Test27L,&KTest27Des}, sl@0: {Test28L,&KTest28Des}, sl@0: {Test29L,&KTest29Des}, sl@0: {Test30L,&KTest30Des}, sl@0: {Test31L,&KTest31Des}, sl@0: {Test32,&KTest32Des}, sl@0: {Test33L,&KTest33Des}, sl@0: {Test34L,&KTest34Des}, sl@0: {Test35L,&KTest35Des}, sl@0: {Test36L,&KTest36Des}, sl@0: {TestCEZCompressorMethodsL, &KTest37Des}, sl@0: {TestZlibapiwrapperAPIL, &KTest38Des} sl@0: }; sl@0: sl@0: struct TTestFlags sl@0: { sl@0: enum sl@0: { sl@0: FakeNoInput = 16, sl@0: FakeNoOutput = 32, sl@0: Dictionary = 64, sl@0: AllocFail = 128, sl@0: Corrupt = 256, sl@0: AllocFailInflate = 512, sl@0: Unicode = 1024, sl@0: Percent = 2048 sl@0: }; sl@0: sl@0: sl@0: TTestFlags() : iFlags(0), iBufferSize(0) { Defaults(); } sl@0: TTestFlags(TInt aFlags, TInt aBufferSize) : iFlags(aFlags), iBufferSize(aBufferSize) { Defaults(); } sl@0: void Defaults(); sl@0: sl@0: TInt iFlags; sl@0: TInt iBufferSize; sl@0: TPtrC8 iDictionary; sl@0: TInt iLevel; sl@0: TInt iWindowBits; sl@0: TInt iMemLevel; sl@0: CEZCompressor::TStrategy iStrategy; sl@0: }; sl@0: sl@0: sl@0: void TTestFlags::Defaults() sl@0: { sl@0: iLevel = CEZCompressor::EDefaultCompression; sl@0: iWindowBits = CEZCompressor::EMaxWBits; sl@0: iMemLevel = CEZCompressor::EDefMemLevel; sl@0: iStrategy = CEZCompressor::EDefaultStrategy; sl@0: } sl@0: sl@0: TReal FastCountToMilliseconds(TInt aFastCount) sl@0: { sl@0: TInt freqInHz; sl@0: HAL::Get(HAL::EFastCounterFrequency, freqInHz); sl@0: TReal freqInkHz = freqInHz / 1000; sl@0: return (TReal)aFastCount / freqInkHz; sl@0: } sl@0: sl@0: sl@0: static RTest Test(_L("EZLIB")); sl@0: sl@0: static TUint8 original[] = "compression is a constant source of depression and depression leads to multiple regressions in succession"; sl@0: static TUint8 dictionary[] = "constant source multiple leads compression "; sl@0: static TUint8 badDictionary[] = "I'm not the dictionary"; sl@0: static TUint8 compressed[256]; sl@0: static TInt compressedSize; // length of compressed data in compressed. sl@0: static TUint8 uncompressed[256]; sl@0: static TText output[256]; sl@0: static TText originalU[256]; sl@0: static TText dictionaryU[256]; sl@0: sl@0: static void RunTestL(); sl@0: sl@0: static void CompressBufferL(const TTestFlags &aFlags, RTest &aTest=Test); sl@0: static void DecompressBufferL(const TTestFlags &aFlags, RTest &aTest=Test); sl@0: static void DblDecompressBufferL(TInt aBufferSize, TBool aReset); sl@0: static void CompressDecompressL(const TTestFlags &aFlags); sl@0: static void DblCompressBufferL(TInt aBufferSize, TBool aReset = EFalse); sl@0: sl@0: class CBufferManager : public CBase, public MEZBufferManager sl@0: { sl@0: public: sl@0: ~CBufferManager(); sl@0: sl@0: static CBufferManager *NewLC(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength, TInt aBufferSize); sl@0: static CBufferManager *NewL(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength, TInt aBufferSize); sl@0: sl@0: void InitializeL(CEZZStream &aZStream); sl@0: void NeedInputL(CEZZStream &aZStream); sl@0: void NeedOutputL(CEZZStream &aZStream); sl@0: void FinalizeL(CEZZStream &aZStream); sl@0: sl@0: void FakeNoInput() { iFakeNoInput = ETrue; } sl@0: void FakeNoOutput() { iFakeNoOutput = ETrue; } sl@0: sl@0: private: sl@0: CBufferManager(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength); sl@0: void ConstructL(TInt aBufferSize); sl@0: sl@0: private: sl@0: TUint8 *iInput, *iOutput; sl@0: TUint8 *iInputBuffer, *iOutputBuffer; sl@0: TInt iBufferSize; sl@0: TInt iOutputLength, iInputLength; sl@0: TPtr8 iInputDescriptor; sl@0: TPtr8 iOutputDescriptor; sl@0: TBool iFakeNoInput; sl@0: TBool iFakeNoOutput; sl@0: }; sl@0: sl@0: CBufferManager::CBufferManager(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength) sl@0: : iInput(aInput), sl@0: iOutput(aOutput), sl@0: iOutputLength(aOutputLength), sl@0: iInputLength(aInputLength), sl@0: iInputDescriptor(NULL,0), sl@0: iOutputDescriptor(NULL,0), sl@0: iFakeNoInput(EFalse), sl@0: iFakeNoOutput(EFalse) sl@0: { sl@0: sl@0: } sl@0: sl@0: CBufferManager::~CBufferManager() sl@0: { sl@0: delete[] iInputBuffer; sl@0: delete[] iOutputBuffer; sl@0: } sl@0: sl@0: CBufferManager *CBufferManager::NewLC(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength, TInt aBufferSize) sl@0: { sl@0: CBufferManager *bm = new (ELeave) CBufferManager(aInput,aInputLength,aOutput,aOutputLength); sl@0: CleanupStack::PushL(bm); sl@0: bm->ConstructL(aBufferSize); sl@0: return bm; sl@0: } sl@0: sl@0: CBufferManager *CBufferManager::NewL(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength, TInt aBufferSize) sl@0: { sl@0: CBufferManager *bm = new (ELeave) CBufferManager(aInput,aInputLength,aOutput,aOutputLength); sl@0: CleanupStack::PushL(bm); sl@0: bm->ConstructL(aBufferSize); sl@0: CleanupStack::Pop(); sl@0: return bm; sl@0: } sl@0: sl@0: void CBufferManager::ConstructL(TInt aBufferSize) sl@0: { sl@0: iBufferSize = aBufferSize; sl@0: iInputBuffer = new (ELeave) TUint8[iBufferSize]; sl@0: iOutputBuffer = new (ELeave) TUint8[iBufferSize]; sl@0: sl@0: } sl@0: sl@0: void CBufferManager::InitializeL(CEZZStream &aZStream) sl@0: { sl@0: TInt remaining = iInputLength; sl@0: if (remaining > iBufferSize) sl@0: remaining = iBufferSize; sl@0: Mem::Copy(iInputBuffer,iInput,remaining); sl@0: iInputDescriptor.Set(iInputBuffer,remaining,iBufferSize); sl@0: aZStream.SetInput(iInputDescriptor); sl@0: iOutputDescriptor.Set(iOutputBuffer,0,iBufferSize); sl@0: aZStream.SetOutput(iOutputDescriptor); sl@0: iInput += remaining; sl@0: } sl@0: sl@0: void CBufferManager::NeedInputL(CEZZStream &aZStream) sl@0: { sl@0: TInt remaining; sl@0: if (iFakeNoInput) sl@0: remaining = 0; sl@0: else sl@0: { sl@0: remaining = iInputLength - aZStream.TotalIn(); sl@0: if (remaining > iBufferSize) sl@0: remaining = iBufferSize; sl@0: Mem::Copy(iInputBuffer,iInput,remaining); sl@0: } sl@0: iInputDescriptor.Set(iInputBuffer,remaining,iBufferSize); sl@0: aZStream.SetInput(iInputDescriptor); sl@0: iInput += remaining; sl@0: } sl@0: sl@0: sl@0: void CBufferManager::NeedOutputL(CEZZStream &aZStream) sl@0: { sl@0: TInt remaining; sl@0: if (iFakeNoOutput) sl@0: { sl@0: remaining = 0; sl@0: iOutputDescriptor.Set(iOutputBuffer,remaining,remaining); sl@0: } sl@0: else sl@0: { sl@0: remaining = iOutputLength - aZStream.TotalOut(); sl@0: if (remaining > iBufferSize) sl@0: remaining = iBufferSize; sl@0: } sl@0: TPtrC8 od = aZStream.OutputDescriptor(); sl@0: Mem::Copy(iOutput,iOutputBuffer,od.Size()); sl@0: aZStream.SetOutput(iOutputDescriptor); sl@0: iOutput += iBufferSize; sl@0: } sl@0: sl@0: void CBufferManager::FinalizeL(CEZZStream &aZStream) sl@0: { sl@0: TInt copy = aZStream.OutputDescriptor().Size(); sl@0: sl@0: if (copy > 0) sl@0: Mem::Copy(iOutput,iOutputBuffer,copy); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-1328 sl@0: @SYMTestCaseDesc Decompression of stream test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Compresses and decompresses a buffer and tests to see whether the orginal and decompression streams sl@0: are the same. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: static void CompressDecompressL(const TTestFlags &aFlags) sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-1328 ")); sl@0: CompressBufferL(aFlags); sl@0: DecompressBufferL(aFlags); sl@0: sl@0: if (aFlags.iFlags & TTestFlags::Unicode) sl@0: { sl@0: TPtr s1(REINTERPRET_CAST(TText *, original),sizeof(original)); sl@0: TPtr s2(REINTERPRET_CAST(TText *, uncompressed),sizeof(original)); sl@0: Test(s1.Compare(s2) == 0,__LINE__); sl@0: } sl@0: else sl@0: { sl@0: TPtrC8 s1(original); sl@0: TPtrC8 s2(uncompressed); sl@0: Test(s1.Compare(s2) == 0,__LINE__); sl@0: } sl@0: } sl@0: sl@0: // Compresses the data in original and places it into compressed. sl@0: sl@0: //Need to pass in RTest object as this function is called by a seperate thread sometimes sl@0: static void CompressBufferL(const TTestFlags &aFlags, RTest &aTest) sl@0: { sl@0: _LIT(KMsg,"\nTesting multi-step compresssion with buffer size %d\n"); sl@0: aTest.Printf(KMsg,aFlags.iBufferSize); sl@0: aTest.Printf(KSeparator); sl@0: CBufferManager *bm; sl@0: TInt sourceSize; sl@0: sl@0: if (aFlags.iFlags & TTestFlags::Unicode) sl@0: { sl@0: sourceSize = sizeof(original) * sizeof(TText); sl@0: bm = CBufferManager::NewLC(REINTERPRET_CAST(TUint8*,originalU),sourceSize,compressed,256,aFlags.iBufferSize); sl@0: } sl@0: else sl@0: { sl@0: sourceSize = sizeof(original); sl@0: bm = CBufferManager::NewLC(original,sourceSize,compressed,256,aFlags.iBufferSize); sl@0: } sl@0: sl@0: sl@0: if (aFlags.iFlags & TTestFlags::FakeNoInput) sl@0: bm->FakeNoInput(); sl@0: if (aFlags.iFlags & TTestFlags::FakeNoOutput) sl@0: bm->FakeNoOutput(); sl@0: CEZCompressor *def; sl@0: sl@0: #if defined(_DEBUG) && defined(__WINS__) sl@0: if (aFlags.iFlags & TTestFlags::AllocFail) sl@0: __UHEAP_SETFAIL(RHeap::ETrueRandom,5); sl@0: #endif sl@0: sl@0: if (aFlags.iFlags & TTestFlags::Dictionary) sl@0: def = CEZCompressor::NewLC(*bm,aFlags.iDictionary,aFlags.iLevel,aFlags.iWindowBits, sl@0: aFlags.iMemLevel,aFlags.iStrategy); sl@0: else sl@0: def= CEZCompressor::NewLC(*bm,aFlags.iLevel,aFlags.iWindowBits,aFlags.iMemLevel, sl@0: aFlags.iStrategy); sl@0: sl@0: while (def->DeflateL()) sl@0: { sl@0: if (aFlags.iFlags & TTestFlags::Percent) sl@0: { sl@0: _LIT(KPer,"%d "); sl@0: aTest.Printf(KPer,def->Progress(sourceSize)); sl@0: } sl@0: } sl@0: if (aFlags.iFlags & TTestFlags::Percent) sl@0: aTest.Printf(_L("\n")); sl@0: sl@0: compressedSize = def->TotalOut(); sl@0: _LIT(KUnMsg,"Uncompressed Size %d\n"); sl@0: _LIT(KComMsg,"Compressed Size %d\n"); sl@0: sl@0: if (aFlags.iFlags & TTestFlags::Corrupt) sl@0: compressed[compressedSize >> 1] = 1; sl@0: sl@0: aTest.Printf(KUnMsg,def->TotalIn()); sl@0: aTest.Printf(KComMsg,compressedSize); sl@0: CleanupStack::PopAndDestroy(2); sl@0: } sl@0: sl@0: // Decompresses data stored in compressed and writes it to uncompressed. sl@0: sl@0: //Need to pass in RTest object as this function is called by a seperate thread sometimes sl@0: static void DecompressBufferL(const TTestFlags &aFlags, RTest &aTest) sl@0: { sl@0: _LIT(KMsg,"\nTesting multi-step decompresssion with buffer size %d\n"); sl@0: aTest.Printf(KMsg,aFlags.iBufferSize); sl@0: aTest.Printf(KSeparator); sl@0: CBufferManager *bm = CBufferManager::NewLC(compressed,compressedSize,uncompressed,256,aFlags.iBufferSize); sl@0: sl@0: if (aFlags.iFlags & TTestFlags::FakeNoInput) sl@0: bm->FakeNoInput(); sl@0: if (aFlags.iFlags & TTestFlags::FakeNoOutput) sl@0: bm->FakeNoOutput(); sl@0: sl@0: #if defined(_DEBUG) && defined(__WINS__) sl@0: if (aFlags.iFlags & TTestFlags::AllocFail) sl@0: __UHEAP_SETFAIL(RHeap::ETrueRandom,10); sl@0: #endif sl@0: sl@0: CEZDecompressor *in; sl@0: if (aFlags.iFlags & TTestFlags::Dictionary) sl@0: in = CEZDecompressor::NewLC(*bm,aFlags.iDictionary); sl@0: else sl@0: in = CEZDecompressor::NewLC(*bm); sl@0: sl@0: #if defined(_DEBUG) && defined(__WINS__) sl@0: if (aFlags.iFlags & TTestFlags::AllocFailInflate) sl@0: __UHEAP_SETFAIL(RHeap::ETrueRandom,10); sl@0: #endif sl@0: sl@0: while (in->InflateL()) sl@0: { sl@0: if (aFlags.iFlags & TTestFlags::Percent) sl@0: { sl@0: _LIT(KPer,"%d "); sl@0: aTest.Printf(KPer,in->Progress(compressedSize)); sl@0: } sl@0: } sl@0: if (aFlags.iFlags & TTestFlags::Percent) sl@0: aTest.Printf(_L("\n")); sl@0: sl@0: sl@0: if (aFlags.iFlags & TTestFlags::Unicode) sl@0: { sl@0: TPtrC ptr(REINTERPRET_CAST(TText *,uncompressed),in->TotalOut() / sizeof(TText)); sl@0: aTest.Printf(ptr); sl@0: aTest.Printf(_L("\n")); sl@0: } sl@0: else sl@0: { sl@0: TPtrC8 ptr8(uncompressed); sl@0: TPtr ptr16(output,256); sl@0: ptr16.Copy(ptr8); sl@0: aTest.Printf(ptr16); sl@0: aTest.Printf(_L("\n")); sl@0: } sl@0: CleanupStack::PopAndDestroy(2); sl@0: } sl@0: sl@0: static void DblCompressBufferL(TInt aBufferSize, TBool aReset) sl@0: { sl@0: CEZCompressor *def = NULL; sl@0: sl@0: _LIT(KMsg,"\nTesting multi-step compresssion with buffer size %d\n"); sl@0: _LIT(KUnMsg,"Uncompressed Size %d\n"); sl@0: _LIT(KComMsg,"Compressed Size %d\n"); sl@0: sl@0: Test.Printf(KMsg,aBufferSize); sl@0: Test.Printf(KSeparator,aBufferSize); sl@0: CBufferManager *bm = CBufferManager::NewLC(original,sizeof(original),compressed,256,aBufferSize); sl@0: def = CEZCompressor::NewLC(*bm); sl@0: sl@0: while (def->DeflateL()){} sl@0: sl@0: compressedSize = def->TotalOut(); sl@0: Test.Printf(KUnMsg,sizeof(original)); sl@0: Test.Printf(KComMsg,compressedSize); sl@0: sl@0: CleanupStack::Pop(); sl@0: CleanupStack::PopAndDestroy(); sl@0: CleanupStack::PushL(def); sl@0: sl@0: if (aReset) sl@0: { sl@0: bm = CBufferManager::NewLC(original,sizeof(original),compressed,256,aBufferSize); sl@0: def->ResetL(*bm); sl@0: } sl@0: sl@0: Test.Printf(KMsg,aBufferSize); sl@0: Test.Printf(KSeparator,aBufferSize); sl@0: sl@0: while (def->DeflateL()){} sl@0: sl@0: compressedSize = def->TotalOut(); sl@0: Test.Printf(KUnMsg,sizeof(original)); sl@0: Test.Printf(KComMsg,compressedSize); sl@0: sl@0: CleanupStack::PopAndDestroy(2); sl@0: } sl@0: sl@0: static void DblDecompressBufferL(TInt aBufferSize, TBool aReset) sl@0: { sl@0: CEZDecompressor *def = NULL; sl@0: sl@0: _LIT(KMsg,"\nTesting multi-step decompresssion with buffer size %d\n"); sl@0: Test.Printf(KMsg,aBufferSize); sl@0: Test.Printf(KSeparator); sl@0: CBufferManager *bm = CBufferManager::NewLC(compressed,compressedSize,uncompressed,256,aBufferSize); sl@0: def = CEZDecompressor::NewLC(*bm); sl@0: sl@0: while (def->InflateL()){} sl@0: sl@0: CleanupStack::Pop(); sl@0: CleanupStack::PopAndDestroy(); sl@0: CleanupStack::PushL(def); sl@0: sl@0: if (aReset) sl@0: { sl@0: bm = CBufferManager::NewLC(compressed,compressedSize,uncompressed,256,aBufferSize); sl@0: def->ResetL(*bm); sl@0: } sl@0: sl@0: Test.Printf(KMsg,aBufferSize); sl@0: Test.Printf(KSeparator,aBufferSize); sl@0: sl@0: while (def->InflateL()){} sl@0: sl@0: TPtrC8 ptr8(uncompressed); sl@0: TPtr ptr16(output,256); sl@0: ptr16.Copy(ptr8); sl@0: Test.Printf(ptr16); sl@0: Test.Printf(_L("\n")); sl@0: sl@0: CleanupStack::PopAndDestroy(2); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0785 sl@0: @SYMTestCaseDesc Multistep compression & decompression test using buffers smaller than source & destination sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to 0,buffersize to 8 sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test1L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0785 ")); sl@0: TTestFlags flags(0,8); sl@0: CompressDecompressL(flags); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0786 sl@0: @SYMTestCaseDesc Multistep compression & decompression test using buffers larger than source & destination sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to 0,buffersize to 1024 sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test2L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0786 ")); sl@0: TTestFlags flags(0,1024); sl@0: CompressDecompressL(flags); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0787 sl@0: @SYMTestCaseDesc Multistep compression test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to TTestFlags::FakeNoInput,buffersize to 8 sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test3() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0787 ")); sl@0: TTestFlags flags(TTestFlags::FakeNoInput,8); sl@0: sl@0: TRAPD(err,CompressBufferL(flags)); sl@0: Test (err==KErrNone); // This test should succeed as providing no Input is a valid thing for sl@0: // NeedInputL to do. sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0788 sl@0: @SYMTestCaseDesc Multistep compression test when NeedOutput provides no output sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to TTestFlags::FakeNoOutput,buffersize to 8 sl@0: Check for buffer error. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test4() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0788 ")); sl@0: TTestFlags flags(TTestFlags::FakeNoOutput,8); sl@0: sl@0: TRAPD(err,CompressBufferL(flags)); sl@0: Test (err==KEZlibErrBuf); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0789 sl@0: @SYMTestCaseDesc Multistep compression test with the same CEZCompressor, sl@0: resetting it after the first compression sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the buffersize to 8,reset value to true sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test5L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0789 ")); sl@0: DblCompressBufferL(8,ETrue); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0790 sl@0: @SYMTestCaseDesc Multistep compression test with the same CEZCompressor, sl@0: without resetting it after the first compression sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the buffersize to 8,reset value to false sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test6() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0790 ")); sl@0: //Calling compress twice without reseting (ie passing in EFalse) causes leave sl@0: TRAPD(err,DblCompressBufferL(8,EFalse)); sl@0: Test (err==KEZlibErrDeflateTerminated); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0791 sl@0: @SYMTestCaseDesc Multistep compression & decompression test using a preset dictionary sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to TTestFlags::Dictionary,buffersize to 8 sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test7L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0791 ")); sl@0: TTestFlags flags(TTestFlags::Dictionary,8); sl@0: flags.iDictionary.Set(dictionary,sizeof(dictionary)); sl@0: sl@0: CompressDecompressL(flags); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0792 sl@0: @SYMTestCaseDesc Multistep compression with compression level of 0 test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to 0,buffersize to 8,compression level to 0 sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test8L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0792 ")); sl@0: TTestFlags flags(0,8); sl@0: flags.iLevel = 0; sl@0: sl@0: CompressDecompressL(flags); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0793 sl@0: @SYMTestCaseDesc Multistep compression test with compression level of 9 sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to 0,buffersize to 8,compression level to 9 sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test9L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0793 ")); sl@0: TTestFlags flags(0,8); sl@0: flags.iLevel = 9; sl@0: sl@0: CompressDecompressL(flags); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0794 sl@0: @SYMTestCaseDesc Multistep compression test with invalid compression level sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to 0,buffersize to 8,compression level to 10. sl@0: Check for stream error when compression level is greater than 9 sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test10() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0794 ")); sl@0: TTestFlags flags(0,8); sl@0: flags.iLevel = 10; sl@0: sl@0: TRAPD(err, CompressDecompressL(flags)); sl@0: //CompressL fails with KEZlibErrStream if level is greater than 9 sl@0: Test (err==KEZlibErrStream); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0795 sl@0: @SYMTestCaseDesc Multistep compression test with window bits of 7 sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to 0,buffersize to 7 sl@0: Check for stream error if window bits is less than 8 sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test11() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0795 ")); sl@0: TTestFlags flags(0,7); sl@0: flags.iWindowBits = 7; sl@0: //CompressL fails with KEZlibErrStream if window bits is less than 8 sl@0: TRAPD(err, CompressDecompressL(flags)); sl@0: Test (err==KEZlibErrStream); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0796 sl@0: @SYMTestCaseDesc Multistep compression test with window bits of 7 sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to 0,buffersize to 8 sl@0: Check for stream error if window bits is less than 9 sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test12() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0796 ")); sl@0: TTestFlags flags(0,8); sl@0: flags.iWindowBits = 7; sl@0: //CompressL fails with KEZlibErrStream if window bits is less than 9 sl@0: TRAPD(err, CompressDecompressL(flags)); sl@0: Test (err==KEZlibErrStream); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0797 sl@0: @SYMTestCaseDesc Multistep compression test with memory level = 1 sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to 0,buffersize to 8 sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test13L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0797 ")); sl@0: TTestFlags flags(0,8); sl@0: flags.iMemLevel = 1; sl@0: sl@0: CompressDecompressL(flags); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0798 sl@0: @SYMTestCaseDesc Multistep compression test with memory level = 10 sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to 0,buffersize to 8 sl@0: Check for stream error if memory level is greater than 8. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test14() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0798 ")); sl@0: TTestFlags flags(0,8); sl@0: flags.iMemLevel = 10; sl@0: sl@0: //CompressL fails with KEZlibErrStream if mem level greater than 8 sl@0: TRAPD(err, CompressDecompressL(flags)); sl@0: Test (err==KEZlibErrStream); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0799 sl@0: @SYMTestCaseDesc Multistep compression test using only Huffman encoding sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to 0,buffersize to 8 sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test15L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0799 ")); sl@0: TTestFlags flags(0,8); sl@0: flags.iStrategy = CEZCompressor::EHuffmanOnly; sl@0: sl@0: CompressDecompressL(flags); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0800 sl@0: @SYMTestCaseDesc Multistep compression test using Filtered strategy sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to 0,buffersize to 8 sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test16L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0800 ")); sl@0: TTestFlags flags(0,8); sl@0: flags.iStrategy = CEZCompressor::EFiltered; sl@0: sl@0: CompressDecompressL(flags); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0801 sl@0: @SYMTestCaseDesc Multistep compression test when Alloc fails randomly sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to 0,buffersize to 8 sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test17() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0801 ")); sl@0: TTestFlags flags(TTestFlags::AllocFail,8); sl@0: sl@0: TRAPD(err,CompressBufferL(flags)); sl@0: Test(err == KErrNone||err == KErrNoMemory); //alloc failure is random so no quarantees of failure sl@0: //Need to reset the heap afterwards to avoid problems for next test. sl@0: __UHEAP_RESET; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0802 sl@0: @SYMTestCaseDesc Multistep decompression test when NeedInput provides no input sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to 0,buffersize to 8 sl@0: Check for data error,when no input is given sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test18L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0802 ")); sl@0: TTestFlags flags(0,8); sl@0: CompressBufferL(flags); // make sure we initialize compressed properly sl@0: sl@0: flags.iFlags |= TTestFlags::FakeNoInput; sl@0: TRAPD(err,DecompressBufferL(flags)); sl@0: // CEZDecompressor::InflateL has left with KEZlibErrBuf due to buffer error sl@0: Test (err==KEZlibErrBuf); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0803 sl@0: @SYMTestCaseDesc Multistep decompression test when NeedOutput provides no output sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to 0,buffersize to 8 sl@0: Check for data error,when no output is given sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test19L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0803 ")); sl@0: TTestFlags flags(0,8); sl@0: CompressBufferL(flags); // make sure we initialize compressed properly sl@0: sl@0: flags.iFlags |= TTestFlags::FakeNoOutput; sl@0: TRAPD(err,DecompressBufferL(flags)); sl@0: // CEZDecompressor::InflateL has left with KEZlibErrBuf due to buffer error sl@0: Test (err==KEZlibErrBuf); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0804 sl@0: @SYMTestCaseDesc Multistep decompression test when NeedOutput provides no output sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to TTestFlags::Corrupt, buffersize to 8 sl@0: Check for data error sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test20L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0804 ")); sl@0: TTestFlags flags(TTestFlags::Corrupt,8); sl@0: CompressBufferL(flags); // make sure we initialize compressed properly sl@0: sl@0: flags.iFlags = 0; sl@0: sl@0: TRAPD(err,DecompressBufferL(flags)); sl@0: // CEZDecompressor::InflateL has left with KEZlibErrData due to buffer error sl@0: Test (err==KEZlibErrData); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0805 sl@0: @SYMTestCaseDesc Multistep decompression construction test when Alloc fails randomly sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to 0, buffersize to 8 sl@0: Check for data error sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test21L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0805 ")); sl@0: TTestFlags flags(0,8); sl@0: CompressBufferL(flags); // make sure we initialize compressed properly sl@0: sl@0: flags.iFlags |= TTestFlags::AllocFail; sl@0: sl@0: TRAPD(err,DecompressBufferL(flags)); sl@0: Test (err==KErrNone||err==KErrNoMemory); //Alloc failure is random so no guarantee it will always fail. sl@0: __UHEAP_RESET; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0806 sl@0: @SYMTestCaseDesc Multistep decompression test when Alloc fails randomly sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to 0, buffersize to 8 sl@0: Check for no memory errors. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test22L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0806 ")); sl@0: TTestFlags flags(0,8); sl@0: CompressBufferL(flags); // make sure we initialize compressed properly sl@0: sl@0: flags.iFlags |= TTestFlags::AllocFailInflate; sl@0: sl@0: TRAPD(err,DecompressBufferL(flags)); sl@0: Test (err==KErrNone||err==KErrNoMemory); //Alloc failure is random so no guarentee it will always fail. sl@0: __UHEAP_RESET; sl@0: } sl@0: sl@0: static void ThreadL() sl@0: { sl@0: RTest test2(_L("EZLIB - second thread")); sl@0: test2.Title(); sl@0: _LIT(KStartMsg,"Starting Tests in second thread"); sl@0: test2.Start(KStartMsg); sl@0: sl@0: TTestFlags flags(TTestFlags::Dictionary,8); sl@0: flags.iDictionary.Set(dictionary,sizeof(dictionary)); sl@0: sl@0: TRAPD(err,CompressBufferL(flags, test2)); sl@0: test2 (err == KErrNone); sl@0: flags.iFlags = 0; sl@0: //This code leaves (used to panic before the fix for DEF112672) sl@0: DecompressBufferL(flags, test2); sl@0: User::Panic(_L("TestFailure failure"),0); sl@0: test2.End(); sl@0: test2.Close(); sl@0: } sl@0: sl@0: static TInt TestThread(TAny*) sl@0: { sl@0: User::SetJustInTime(EFalse); // disable debugger panic handling sl@0: CTrapCleanup* cleanup=CTrapCleanup::New(); sl@0: if (!cleanup) sl@0: return KErrNoMemory; sl@0: TRAPD(r,ThreadL()); sl@0: delete cleanup; sl@0: return r; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0807 sl@0: @SYMTestCaseDesc Multistep decompression test when a dictionary is required and not provided. sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test for panic and exit reason. sl@0: @SYMTestExpectedResults This test should pass without panic. sl@0: (Expected to panic before the fix for DEF112672) sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test23() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0807 ")); sl@0: __UHEAP_MARK; sl@0: sl@0: RThread t; sl@0: _LIT(KTestThread,"Panicing thread"); sl@0: Test.Printf(_L("launching thread")); sl@0: Test (t.Create(KTestThread,&TestThread,0x2000,0x10000,0x100000,0,EOwnerThread) == KErrNone); sl@0: TRequestStatus s; sl@0: t.Logon(s); sl@0: Test (s.Int()==KRequestPending); sl@0: t.Resume(); sl@0: Test.Printf(_L("Awaiting completion")); sl@0: User::WaitForRequest(s); sl@0: User::SetJustInTime(ETrue); // enable debugger panic handling sl@0: _LIT(KCategory,"zlib"); sl@0: Test (t.ExitType()==EExitKill); sl@0: Test (t.ExitCategory()!=KCategory); sl@0: Test (t.ExitReason()==KEZlibErrData);// SetDictionaryL() leaving error code should be KEZlibErrData sl@0: t.Close(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0808 sl@0: @SYMTestCaseDesc Multistep decompression test when the wrong dictionary is provided sl@0: @SYMTestPriority High sl@0: @SYMTestActions Check for an error during inflating the dictionary sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test24L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0808 ")); sl@0: TTestFlags flags(TTestFlags::Dictionary,8); sl@0: flags.iDictionary.Set(dictionary,sizeof(dictionary)); sl@0: sl@0: CompressBufferL(flags); sl@0: sl@0: flags.iDictionary.Set(badDictionary,sizeof(badDictionary)); sl@0: sl@0: TRAPD(err,DecompressBufferL(flags)); sl@0: // CEZDecompressor::SetDictionaryL() has left due to bad data sl@0: Test (err==KEZlibErrInflateDictionary); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0809 sl@0: @SYMTestCaseDesc Multistep decompression test twice with the same CEZDecompressor, sl@0: reseting it after the first decompression sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to 0,buffersize to 8,reset value to TRUE sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test25L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0809 ")); sl@0: TTestFlags flags(0,8); sl@0: CompressBufferL(flags); // make sure we initialize compressed properly sl@0: sl@0: DblDecompressBufferL(8,ETrue); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0810 sl@0: @SYMTestCaseDesc Multistep decompression test twice with the same CEZDecompressor, sl@0: resetting it after the first decompression sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to 0,buffersize to 8,reset value to FALSE sl@0: Check for deflation already occured. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test26L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0810 ")); sl@0: TTestFlags flags(0,8); sl@0: CompressBufferL(flags); // make sure we initialize compressed properly sl@0: sl@0: TRAPD(err,DblDecompressBufferL(8,EFalse)); sl@0: //Calling decompress twice without resenting causes leave sl@0: Test (err==KEZlibErrInflateTerminated); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0811 sl@0: @SYMTestCaseDesc Multistep compression and decompression test on unicode data sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to TTestFlags::Unicode,buffersize to 8 sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test27L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0811 ")); sl@0: TPtrC8 ptr8(original); sl@0: TPtr ptr16(originalU,256); sl@0: ptr16.Copy(ptr8); sl@0: sl@0: TTestFlags flags(TTestFlags::Unicode,8); sl@0: TPtrC8(REINTERPRET_CAST(TUint8 *,originalU),ptr16.Size()); sl@0: CompressDecompressL(flags); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0812 sl@0: @SYMTestCaseDesc Multistep compression and decompression test on unicode data using a unicode dictionary sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to TTestFlags::Dictionary|TTestFlags::Unicode,buffersize to 8 sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test28L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0812 ")); sl@0: TPtrC8 ptr8(original); sl@0: TPtr ptr16(originalU,256); sl@0: ptr16.Copy(ptr8); sl@0: sl@0: TPtrC8 dptr8(dictionary); sl@0: TPtr dptr16(dictionaryU,256); sl@0: dptr16.Copy(dptr8); sl@0: sl@0: sl@0: TTestFlags flags(TTestFlags::Dictionary|TTestFlags::Unicode,8); sl@0: flags.iDictionary.Set(REINTERPRET_CAST(TUint8*, dictionaryU),dptr16.Size()); sl@0: sl@0: TPtrC8(REINTERPRET_CAST(TUint8 *,originalU),ptr16.Size()); sl@0: CompressDecompressL(flags); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0813 sl@0: @SYMTestCaseDesc Multistep compression and decompression test on unicode data using an ASCII dictionary sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to TTestFlags::Dictionary|TTestFlags::Unicode,buffersize to 8 sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test29L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0813 ")); sl@0: TPtrC8 ptr8(original); sl@0: TPtr ptr16(originalU,256); sl@0: ptr16.Copy(ptr8); sl@0: sl@0: TTestFlags flags(TTestFlags::Dictionary|TTestFlags::Unicode,8); sl@0: flags.iDictionary.Set(dictionary,sizeof(dictionary)); sl@0: sl@0: TPtrC8(REINTERPRET_CAST(TUint8 *,originalU),ptr16.Size()); sl@0: CompressDecompressL(flags); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0814 sl@0: @SYMTestCaseDesc Tests the percentage of completion during multistep compression/decompression sl@0: @SYMTestPriority High sl@0: @SYMTestActions Set the test flags to TTestFlags::Percent,buffersize to 8 sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test30L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0814 ")); sl@0: TTestFlags flags(TTestFlags::Percent,8); sl@0: sl@0: CompressDecompressL(flags); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0815 sl@0: @SYMTestCaseDesc Single step compression and decompression test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Calls up CEZCompressor::CompressL(),CEZCompressor::DecompressL() test sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test31L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0815 ")); sl@0: TPtrC8 originalD(original,sizeof(original)); sl@0: TPtr8 compressedD(compressed,0,256); sl@0: TPtr8 uncompressedD(uncompressed,0,256); sl@0: CEZCompressor::CompressL(compressedD,originalD); sl@0: CEZDecompressor::DecompressL(uncompressedD,compressedD); sl@0: sl@0: Test.Printf(_L("\n")); sl@0: Test.Printf(KSeparator); sl@0: TPtr ptr16(output,256); sl@0: ptr16.Copy(uncompressedD); sl@0: Test.Printf(ptr16); sl@0: Test.Printf(_L("\n")); sl@0: Test(originalD.Compare(uncompressedD) == 0,__LINE__); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0816 sl@0: @SYMTestCaseDesc Single step compression test when inadequate output buffer is provided sl@0: @SYMTestPriority High sl@0: @SYMTestActions Check for EZlibErrBuf buffer error flag sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test32() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0816 ")); sl@0: TPtrC8 originalD(original,sizeof(original)); sl@0: TPtr8 compressedD(compressed,0,1); sl@0: sl@0: Test.Printf(_L("\n")); sl@0: Test.Printf(KSeparator); sl@0: sl@0: TRAPD(err,CEZCompressor::CompressL(compressedD,originalD)); sl@0: // Buffer error sl@0: Test(err == KEZlibErrBuf); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0817 sl@0: @SYMTestCaseDesc Single step decompression test when inadequate output buffer is provided sl@0: @SYMTestPriority High sl@0: @SYMTestActions Check for EZlibErrBuf buffer error flag sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: void Test33L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0817 ")); sl@0: Test.Printf(_L("\n")); sl@0: Test.Printf(KSeparator); sl@0: TPtrC8 originalD(original,sizeof(original)); sl@0: TPtr8 compressedD(compressed,0,256); sl@0: TPtr8 uncompressedD(uncompressed,0,1); sl@0: CEZCompressor::CompressL(compressedD,originalD); sl@0: TRAPD(err,CEZDecompressor::DecompressL(uncompressedD,compressedD)); sl@0: // Buffer error sl@0: Test(err == KEZlibErrBuf); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0818 sl@0: @SYMTestCaseDesc Testing graceful exit for zlib 1.1.3 decompression bug sl@0: @SYMTestPriority High sl@0: @SYMTestActions Check for buffer error after inflation sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void Test34L() sl@0: { sl@0: Test.Printf(_L("\n")); sl@0: Test.Printf(KSeparator); sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0818 ")); sl@0: // 00000720.png contains specially crafted data block that exposes bug in 1.1.3 sl@0: // decompression algorithm. Causes InflateL() to return Z_BUF_ERROR. sl@0: #if !defined(__WINS__) sl@0: _LIT(KInputFile, "z:\\test\\png\\00000720.png"); sl@0: #else sl@0: _LIT(KInputFile, "c:\\test\\png\\00000720.png"); sl@0: #endif sl@0: _LIT(KTempDirectory, "c:\\test\\temp\\"); sl@0: RFile input, output, tempInput; sl@0: RFs rfs; sl@0: rfs.Connect(); sl@0: rfs.MkDirAll(KTempDirectory); sl@0: sl@0: TInt res = input.Open(rfs, KInputFile, EFileStream | EFileRead | EFileShareAny); sl@0: Test(res==KErrNone); sl@0: CleanupClosePushL(input); sl@0: sl@0: TFileName filename; sl@0: TBuf8<1024> readBuf; sl@0: TInt fileLen; sl@0: input.Size(fileLen); sl@0: res = input.Read(8,readBuf,fileLen); sl@0: Test(res==KErrNone); sl@0: sl@0: res = tempInput.Temp(rfs, KTempDirectory, filename, EFileStream | EFileWrite | EFileShareExclusive); sl@0: Test(res==KErrNone); sl@0: CleanupClosePushL(tempInput); sl@0: res = tempInput.Write(readBuf, fileLen-8); // Create temporary file without the 8 byte PNG header. sl@0: Test(res==KErrNone); sl@0: sl@0: CEZFileBufferManager *fb = CEZFileBufferManager::NewLC(tempInput, output, 4096); sl@0: CEZDecompressor *inf = CEZDecompressor::NewLC(*fb); sl@0: sl@0: TRAPD(err, while (inf->InflateL()){}); sl@0: //CEZDecompressor::InflateL() leaves sl@0: Test (err==KEZlibErrBuf); sl@0: sl@0: tempInput.Close(); sl@0: User::LeaveIfError(rfs.Delete(filename)); sl@0: input.Close(); sl@0: CleanupStack::PopAndDestroy(4); sl@0: } sl@0: sl@0: #if !(defined(__WINSCW__) || defined (_DEBUG)) sl@0: void DecompressFileL(const TDesC& aFilePath, RFs& aFs, TInt aTimingLimit) sl@0: { sl@0: _LIT(KTempDirectory, "c:\\test\\temp\\"); sl@0: aFs.MkDirAll(KTempDirectory); sl@0: sl@0: RFile inputFile, tempFile; sl@0: //open the input compressed file sl@0: TInt res = inputFile.Open(aFs, aFilePath, EFileStream | EFileRead | EFileShareExclusive); sl@0: Test(res==KErrNone); sl@0: CleanupClosePushL(inputFile); sl@0: sl@0: //create a temporary file to be used as an output of the decompressor sl@0: TFileName filename; sl@0: res = tempFile.Temp(aFs, KTempDirectory, filename, EFileStream | EFileWrite | EFileShareExclusive); sl@0: Test(res==KErrNone); sl@0: CleanupClosePushL(tempFile); sl@0: sl@0: //decompress the data from the input file several times sl@0: TInt startTime = User::FastCounter(); sl@0: for (TInt i = 0; i<10; i++) sl@0: { sl@0: TInt position = 0; sl@0: inputFile.Seek(ESeekStart,position); sl@0: CEZFileBufferManager *fb = CEZFileBufferManager::NewLC(inputFile, tempFile, 4096); sl@0: //create a decompressor object based on the file buffer manager sl@0: CEZDecompressor *decompressor = CEZDecompressor::NewLC(*fb); sl@0: TRAP(res, while (decompressor->InflateL()){}); sl@0: Test(res==KErrNone); sl@0: CleanupStack::PopAndDestroy(2); sl@0: } sl@0: TInt endTime = User::FastCounter(); sl@0: sl@0: //close input and temporary file sl@0: CleanupStack::PopAndDestroy(2); sl@0: //delete temporary file sl@0: aFs.Delete(filename); sl@0: sl@0: TReal netTime = FastCountToMilliseconds(endTime-startTime); sl@0: _LIT(KLogLine,"netTime =%f\n"); sl@0: Test.Printf(KLogLine,netTime); sl@0: sl@0: if (aTimingLimit) sl@0: { sl@0: Test(netTime <= aTimingLimit); sl@0: } sl@0: else sl@0: { sl@0: Test.Printf(_L("Timings results are only checked on the RAM configuration of H2 and H4 HRP\n")); sl@0: } sl@0: } sl@0: #endif sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-3426 sl@0: @SYMTestCaseDesc Testing EZlib decompressor performance after enforcing compiler optimisation sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions This test uses several typical pieces of compressed sl@0: image data as an input and inflates them 10 times. sl@0: The total duration of this operation is measured and sl@0: compared against a benchmarking limit. Only performed sl@0: on UREL builds running on H2 and H4 hardware. sl@0: @SYMTestExpectedResults Time spent on decompression should be less than a preset limit. sl@0: @SYMREQ REQ7363 sl@0: */ sl@0: sl@0: void Test35L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-3426 ")); sl@0: #if !(defined(__WINSCW__) || defined (_DEBUG)) sl@0: Test.Printf(_L("\n")); sl@0: Test.Printf(KSeparator); sl@0: _LIT(KInputFile1, "z:\\test\\png\\compressed_data1");//A small-sized picture with sl@0: //transparent background which sl@0: //represents typical UI component sl@0: //icon. sl@0: sl@0: _LIT(KInputFile2, "z:\\test\\png\\compressed_data2");//Medium-sized picture with a sl@0: //single image typical for a UI sl@0: //theme background image sl@0: sl@0: _LIT(KInputFile3, "z:\\test\\png\\compressed_data3");//Medium-sized picture with sl@0: //multiple small images on it sl@0: //typical for a sheet of UI sl@0: //component skins sl@0: sl@0: _LIT(KInputFile4, "z:\\test\\png\\compressed_data4");//Large-sized photo image sl@0: sl@0: RFs rfs; sl@0: rfs.Connect(); sl@0: CleanupClosePushL(rfs); sl@0: sl@0: // determine media type of C drive sl@0: TDriveInfo driveInf; sl@0: TInt res = rfs.Drive(driveInf, EDriveC); sl@0: Test(res==KErrNone); sl@0: sl@0: TInt timingLimit1 = 0; sl@0: TInt timingLimit2 = 0; sl@0: TInt timingLimit3 = 0; sl@0: TInt timingLimit4 = 0; sl@0: // only check benchmarks if running on hardware, with UREL + RAM build (i.e. not NAND) sl@0: if (driveInf.iType == EMediaRam) sl@0: { sl@0: TInt muid = 0; sl@0: res= HAL::Get(HAL::EMachineUid, muid); sl@0: Test(res==KErrNone); sl@0: switch (muid) sl@0: { sl@0: case HAL::EMachineUid_OmapH2: sl@0: timingLimit1 = 350; sl@0: timingLimit2 = 1650; sl@0: timingLimit3 = 2900; sl@0: timingLimit4 = 2750; sl@0: break; sl@0: case HAL::EMachineUid_OmapH4: sl@0: timingLimit1 = 200; sl@0: timingLimit2 = 850; sl@0: timingLimit3 = 1400; sl@0: timingLimit4 = 1500; sl@0: break; sl@0: default: sl@0: break; sl@0: } sl@0: } sl@0: sl@0: DecompressFileL(KInputFile1, rfs, timingLimit1); sl@0: DecompressFileL(KInputFile2, rfs, timingLimit2); sl@0: DecompressFileL(KInputFile3, rfs, timingLimit3); sl@0: DecompressFileL(KInputFile4, rfs, timingLimit4); sl@0: CleanupStack::PopAndDestroy(); sl@0: #else sl@0: Test.Printf(_L("This test is only performed on hardware UREL builds\n")); sl@0: #endif sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-UT-3684 sl@0: @SYMTestCaseDesc Test the memory deallocation of the CEZFileBufferManager object to ensure that sl@0: there is no memory leak on success or failure of file compression and decompression sl@0: @SYMTestPriority High sl@0: @SYMTestActions Compressing and Decompressing a png image using CEZCompressor::InflateL() and sl@0: CEZDecompressor::DeflateL() sl@0: @SYMTestExpectedResults Test must not fail and memory must not leak afterdeallocating CEZFileBufferManager sl@0: object (fb) sl@0: @SYMDEF DEF109756 sl@0: */ sl@0: void Test36L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-3684 ")); sl@0: Test.Printf(_L("\n")); sl@0: Test.Printf(KSeparator); sl@0: //Set the path of input file and output files sl@0: #if !defined(__WINS__) sl@0: _LIT(KInputFile, "z:\\test\\png\\00000720.png"); sl@0: #else sl@0: _LIT(KInputFile, "c:\\test\\png\\00000720.png"); sl@0: #endif sl@0: _LIT(KOutputFile, "c:\\test\\temp\\00000720.z"); sl@0: _LIT(KUncompressedFile, "c:\\test\\temp\\000007201"); sl@0: sl@0: RFs rfs; sl@0: rfs.Connect(); sl@0: CleanupClosePushL(rfs); sl@0: sl@0: TPtrC inputFile(KInputFile); sl@0: TPtrC outputFile(KOutputFile); sl@0: TPtrC uncompressedFile(KUncompressedFile); sl@0: sl@0: RFile input; sl@0: RFile output; sl@0: TInt err; sl@0: //Open the PNG file for compressing sl@0: User::LeaveIfError(input.Open(rfs, inputFile,EFileStream | EFileRead | EFileShareAny)); sl@0: CleanupClosePushL(input); sl@0: sl@0: //Create file to store output of file compressing sl@0: err = output.Create(rfs, outputFile,EFileStream | EFileWrite | EFileShareExclusive); sl@0: if (err == KErrAlreadyExists)//Just in case if the output file already exists then open it. sl@0: User::LeaveIfError(output.Open(rfs, outputFile,EFileStream | EFileWrite | EFileShareExclusive)); sl@0: else sl@0: User::LeaveIfError(err); sl@0: CleanupClosePushL(output); sl@0: sl@0: __UHEAP_MARK; sl@0: //Create and assign the CEZFileBufferManager object 'fb' as the compressor's buffer manager sl@0: CEZFileBufferManager *fb = CEZFileBufferManager::NewLC(input,output,16384); sl@0: CEZCompressor *def = CEZCompressor::NewLC(*fb); sl@0: sl@0: while (def->DeflateL()){/*do nothing*/} sl@0: sl@0: CleanupStack::PopAndDestroy(def); sl@0: CleanupStack::PopAndDestroy(fb); sl@0: __UHEAP_MARKEND; sl@0: sl@0: CleanupStack::PopAndDestroy(&output); sl@0: CleanupStack::PopAndDestroy(&input); sl@0: //Now open the compressed file for decompressing sl@0: User::LeaveIfError(input.Open(rfs, outputFile,EFileStream | EFileRead | EFileShareAny)); sl@0: CleanupClosePushL(input); sl@0: sl@0: //Create file to store output of decompressing sl@0: err = output.Create(rfs, uncompressedFile,EFileStream | EFileWrite | EFileShareExclusive); sl@0: if (err == KErrAlreadyExists)//Just in case if the output file already exists then open it. sl@0: User::LeaveIfError(output.Open(rfs, uncompressedFile,EFileStream | EFileWrite | EFileShareExclusive)); sl@0: else sl@0: User::LeaveIfError(err); sl@0: sl@0: CleanupClosePushL(output); sl@0: sl@0: __UHEAP_MARK; sl@0: //Create and assign the CEZFileBufferManager object 'fb' as the decompressor's buffer manager sl@0: fb = CEZFileBufferManager::NewLC(input,output,16384); sl@0: CEZDecompressor *inf = CEZDecompressor::NewLC(*fb); sl@0: sl@0: while (inf->InflateL()){/*do nothing*/} sl@0: sl@0: CleanupStack::PopAndDestroy(inf); sl@0: CleanupStack::PopAndDestroy(fb); sl@0: __UHEAP_MARKEND; sl@0: input.Close(); sl@0: output.Close(); sl@0: sl@0: CleanupStack::PopAndDestroy(&output); sl@0: CleanupStack::PopAndDestroy(&input); sl@0: CleanupStack::PopAndDestroy(&rfs); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB2-UT-4298 sl@0: @SYMTestCaseDesc Test CEZZStream functions through CEZCompressor class e.g. sl@0: Adler32(), AvailIn(), AvailOut() sl@0: @SYMTestPriority High sl@0: @SYMTestActions 1. Compress stream of data using CEZCompressor::NewLC() & CEZCompressor::DeflateL() sl@0: 2. Call CEZCompressor::Adler32() to get the checksum value of the uncompressed data sl@0: 3. Call CEZCompressor::AvailIn() to get the number of bytes available at the next input byte sl@0: 4. Call CEZCompressor::AvailOut() to get the remaining free space at next output byte target sl@0: @SYMTestExpectedResults The test succeeds with no errors i.e. KErrNone sl@0: @SYMDEF REQ8024 sl@0: */ sl@0: sl@0: void TestCEZCompressorMethodsL() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4298 ")); sl@0: CBufferManager *bm; sl@0: TInt sourceSize; sl@0: sl@0: sourceSize = sizeof(original); sl@0: bm = CBufferManager::NewLC(original,sourceSize,compressed,256,8); sl@0: CEZCompressor *compressor = CEZCompressor::NewLC(*bm); sl@0: sl@0: TInt32 adler32; sl@0: TInt availIn; sl@0: TInt availOut; sl@0: sl@0: while(compressor->DeflateL()){/*do nothing*/} sl@0: sl@0: adler32 = compressor->Adler32(); sl@0: Test(adler32 > 0); sl@0: sl@0: availIn = compressor->AvailIn(); sl@0: Test(availIn == 0); sl@0: sl@0: availOut = compressor->AvailOut(); sl@0: Test(availOut > 0); sl@0: sl@0: CleanupStack::PopAndDestroy(compressor); sl@0: CleanupStack::PopAndDestroy(bm); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB2-UT-4300 sl@0: @SYMTestCaseDesc TTest Zlibapiwrapper.cpp exported API's like inflate, sl@0: deflate, compress, decompress sl@0: @SYMTestPriority High sl@0: @SYMTestActions Call the exported C APIs of Zlibapiwrapper.cpp sl@0: Note: This is done to check if the C APIs of zlib.lib sl@0: are called through ezlib.lib. sl@0: @SYMTestExpectedResults All exported C API's should be called (i.e. run a basic scenario sl@0: of compressing some data) & test must not fail sl@0: @SYMDEF REQ8024 sl@0: */ sl@0: sl@0: void TestZlibapiwrapperAPIL() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4300 ")); sl@0: z_stream deflateStream; sl@0: const char inputData[] = "inputData!"; // data to compress sl@0: uLong inputDataLength = (uLong)sizeof(inputData) + 1; sl@0: Byte *compressedDataBuffer; // output buffer sl@0: //The buffer size is kept as 50 but incase the input data is changed.. sl@0: //...the buffer size also has to be increased accordingly sl@0: TInt compressedDataBufferLength = 50; sl@0: sl@0: // Allocate memory for output buffer sl@0: compressedDataBuffer = (Byte*)User::AllocZ(compressedDataBufferLength); sl@0: Test(compressedDataBuffer != Z_NULL); sl@0: CleanupStack::PushL(compressedDataBuffer); sl@0: sl@0: // Initialise the stream sl@0: deflateStream.zalloc = (alloc_func)0; sl@0: deflateStream.zfree = (free_func)0; sl@0: deflateStream.opaque = (voidpf)0; sl@0: sl@0: int level = Z_DEFAULT_COMPRESSION; sl@0: int err = 0; sl@0: int flush = 0; sl@0: sl@0: err = deflateInit(&deflateStream, level); sl@0: sl@0: if(err != Z_OK) sl@0: { sl@0: deflateEnd(&deflateStream); sl@0: Test(err == Z_OK); sl@0: } sl@0: sl@0: sl@0: // Compress data in the input buffer sl@0: deflateStream.next_in = (Byte*)inputData; sl@0: deflateStream.next_out = compressedDataBuffer; sl@0: sl@0: do sl@0: { sl@0: if (deflateStream.total_in < inputDataLength) sl@0: { sl@0: deflateStream.avail_in = 1; // force small buffer sl@0: } sl@0: sl@0: flush = (deflateStream.total_in == inputDataLength) ? Z_FINISH : Z_NO_FLUSH; sl@0: sl@0: // run deflate() on input until output buffer not full, finish sl@0: // compression if all of source has been read in sl@0: do sl@0: { sl@0: if (deflateStream.total_out < compressedDataBufferLength) sl@0: { sl@0: deflateStream.avail_out = 1; // force small buffer sl@0: } sl@0: sl@0: err = deflate(&deflateStream, flush); sl@0: if(err != Z_OK && err != Z_STREAM_END) sl@0: { sl@0: deflateEnd(&deflateStream); sl@0: Test(err == Z_OK || err == Z_STREAM_END); sl@0: } sl@0: } while(deflateStream.avail_out == 0 && err == Z_OK); sl@0: } while(err != Z_STREAM_END); sl@0: sl@0: deflateEnd(&deflateStream); sl@0: CleanupStack::PopAndDestroy(compressedDataBuffer); sl@0: sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-UT-4001 sl@0: @SYMTestCaseDesc Test for DEF112672 - Panic ZLIB 11 - when installing the sisx file. sl@0: The test attempts to decompress a buffer with the "Dictionary" flag set sl@0: but with NULL dictionary buffer. The test should not cause an assert in the EZLib library. sl@0: @SYMTestPriority Normal sl@0: @SYMTestActions Test for DEF112672 - Panic ZLIB 11 - when installing the sisx file. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF DEF112672 sl@0: */ sl@0: sl@0: void DEF112672L() sl@0: { sl@0: Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-UT-4001 ")); sl@0: TTestFlags flags(TTestFlags::Dictionary, 8); sl@0: flags.iDictionary.Set(dictionary, sizeof(dictionary)); sl@0: CompressBufferL(flags); sl@0: flags.iDictionary.Set(0, 0); sl@0: TRAPD(err, DecompressBufferL(flags)); sl@0: Test(err == KEZlibErrData); sl@0: } sl@0: sl@0: void RunTestL() sl@0: { sl@0: for (TInt testNum=1; testNum buf; sl@0: buf.Format(KTestNum, testNum); sl@0: Test.Next(buf); sl@0: _LIT(KStrMsg,"%S"); sl@0: Test.Printf(KStrMsg, testTable[testNum].iDescription); sl@0: testTable[testNum].iFn(); sl@0: __UHEAP_MARKEND; sl@0: } sl@0: DEF112672L(); sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: CTrapCleanup* cleanup=CTrapCleanup::New(); sl@0: Test.Title(); sl@0: _LIT(KStartMsg,"Starting Tests.."); sl@0: Test.Start(KStartMsg); sl@0: __UHEAP_MARK; sl@0: TRAPD(err,RunTestL()); sl@0: Test (err==KErrNone); sl@0: Test.End(); sl@0: Test.Close(); sl@0: __UHEAP_MARKEND; sl@0: delete cleanup; sl@0: return KErrNone; sl@0: }