1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/compressionlibs/ziplib/test/rtest/ezlibtest/ezlibtest.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1814 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <e32test.h>
1.20 +#include <bacline.h>
1.21 +
1.22 +#include <ezcompressor.h>
1.23 +#include <ezdecompressor.h>
1.24 +#include <ezfilebuffer.h>
1.25 +#include <ezlib.h>
1.26 +#include <hal.h>
1.27 +
1.28 +
1.29 +_LIT(KSeparator,"----------------------------------------------------------------\n");
1.30 +
1.31 +const TInt KNumberOfTests = 38;
1.32 +_LIT(KTest1,"Multistep compression & decompression using buffers smaller than source & destination");
1.33 +_LIT(KTest2,"Multistep compression & decompression using buffers larger than source & destination");
1.34 +_LIT(KTest3,"Test Multistep compression when NeedInput provides no input");
1.35 +_LIT(KTest4,"Test Multistep compression when NeedOutput provides no output");
1.36 +_LIT(KTest5,"Perform multistep compression 2 with the same CEZCompressor, reseting it\n\
1.37 + after the first compression.");
1.38 +_LIT(KTest6,"Perform multistep compression 2 with the same CEZCompressor, without reseting it\n\
1.39 + after the first compression.");
1.40 +_LIT(KTest7,"Performs multistep compression & decompression using a preset dicitonary.");
1.41 +_LIT(KTest8,"Performs multistep compression with compression level of 0.");
1.42 +_LIT(KTest9,"Performs multistep compression with compression level of 9.");
1.43 +_LIT(KTest10,"Performs multistep compression with invalid compression level.");
1.44 +_LIT(KTest11,"Performs multistep compression with window bits of 8.");
1.45 +_LIT(KTest12,"Performs multistep compression with an invalid value for window bits.");
1.46 +_LIT(KTest13,"Performs multistep compression with memory level = 1.");
1.47 +_LIT(KTest14,"Performs multistep compression with an invalid memory level.");
1.48 +_LIT(KTest15,"Performs multistep compression using only Huffman encoding.");
1.49 +_LIT(KTest16,"Performs multistep compression using Filtered strategy.");
1.50 +_LIT(KTest17,"Performs multistep compression when Alloc fails randomly.");
1.51 +_LIT(KTest18,"Test Multistep decompression when NeedInput provides no input.");
1.52 +_LIT(KTest19,"Test Multistep decompression when NeedOutput provides no output.");
1.53 +_LIT(KTest20,"Test Multistep decompression when compressed stream is corrupt.");
1.54 +_LIT(KTest21,"Test Multistep decompressor construction when Alloc fails randomly.");
1.55 +_LIT(KTest22,"Test Multistep decompression when Alloc fails randomly.");
1.56 +_LIT(KTest23,"Test Multistep decompression when a dictionary is required and not provided.\n\
1.57 + This test should panic.");
1.58 +_LIT(KTest24,"Test Multistep decompression when a dictionary when the wrong dictionary is provided.");
1.59 +_LIT(KTest25,"Perform multistep decompression twice with the same CEZDecompressor, reseting it\n\
1.60 + after the first decompression.");
1.61 +_LIT(KTest26,"Perform multistep decompression twice with the same CEZDecompressor, reseting it\n\
1.62 + after the first decompression.");
1.63 +_LIT(KTest27,"Perform multistep compression and decompression on unicode data.");
1.64 +_LIT(KTest28,"Perform multistep compression and decompression on unicode data using a unicode dictionary.");
1.65 +_LIT(KTest29,"Perform multistep compression and decompression on unicode data using an ascii dictionary.");
1.66 +_LIT(KTest30,"Test percentage of completion during multistep compression/decompression.");
1.67 +_LIT(KTest31,"Test single step compression and decompression.");
1.68 +_LIT(KTest32,"Test single step compression when indaquate output buffer is provided.");
1.69 +_LIT(KTest33,"Test single step decompression when indaquate output buffer is provided.");
1.70 +_LIT(KTest34,"Testing graceful exit for zlib 1.1.3 decompression bug. See: INC022729.");
1.71 +_LIT(KTest35,"Testing EZlib decompression performance with enforced compiler optimisation");
1.72 +_LIT(KTest36,"Testing correct memory deallocation for CEZFileBufferManager. See: DEF109756.");
1.73 +_LIT(KTest37,"Test CEZZStream functions through CEZCompressor class.");
1.74 +_LIT(KTest38,"Test Calls to Zlibapiwrapper.cpp exported API's like inflate, deflate, compress, decompress");
1.75 +
1.76 +const TPtrC KTest1Des(KTest1);
1.77 +const TPtrC KTest2Des(KTest2);
1.78 +const TPtrC KTest3Des(KTest3);
1.79 +const TPtrC KTest4Des(KTest4);
1.80 +const TPtrC KTest5Des(KTest5);
1.81 +const TPtrC KTest6Des(KTest6);
1.82 +const TPtrC KTest7Des(KTest7);
1.83 +const TPtrC KTest8Des(KTest8);
1.84 +const TPtrC KTest9Des(KTest9);
1.85 +const TPtrC KTest10Des(KTest10);
1.86 +const TPtrC KTest11Des(KTest11);
1.87 +const TPtrC KTest12Des(KTest12);
1.88 +const TPtrC KTest13Des(KTest13);
1.89 +const TPtrC KTest14Des(KTest14);
1.90 +const TPtrC KTest15Des(KTest15);
1.91 +const TPtrC KTest16Des(KTest16);
1.92 +const TPtrC KTest17Des(KTest17);
1.93 +const TPtrC KTest18Des(KTest18);
1.94 +const TPtrC KTest19Des(KTest19);
1.95 +const TPtrC KTest20Des(KTest20);
1.96 +const TPtrC KTest21Des(KTest21);
1.97 +const TPtrC KTest22Des(KTest22);
1.98 +const TPtrC KTest23Des(KTest23);
1.99 +const TPtrC KTest24Des(KTest24);
1.100 +const TPtrC KTest25Des(KTest25);
1.101 +const TPtrC KTest26Des(KTest26);
1.102 +const TPtrC KTest27Des(KTest27);
1.103 +const TPtrC KTest28Des(KTest28);
1.104 +const TPtrC KTest29Des(KTest29);
1.105 +const TPtrC KTest30Des(KTest30);
1.106 +const TPtrC KTest31Des(KTest31);
1.107 +const TPtrC KTest32Des(KTest32);
1.108 +const TPtrC KTest33Des(KTest33);
1.109 +const TPtrC KTest34Des(KTest34);
1.110 +const TPtrC KTest35Des(KTest35);
1.111 +const TPtrC KTest36Des(KTest36);
1.112 +const TPtrC KTest37Des(KTest37);
1.113 +const TPtrC KTest38Des(KTest38);
1.114 +
1.115 +void Test1L();
1.116 +void Test2L();
1.117 +void Test3();
1.118 +void Test4();
1.119 +void Test5L();
1.120 +void Test6();
1.121 +void Test7L();
1.122 +void Test8L();
1.123 +void Test9L();
1.124 +void Test10();
1.125 +void Test11();
1.126 +void Test12();
1.127 +void Test13L();
1.128 +void Test14();
1.129 +void Test15L();
1.130 +void Test16L();
1.131 +void Test17();
1.132 +void Test18L();
1.133 +void Test19L();
1.134 +void Test20L();
1.135 +void Test21L();
1.136 +void Test22L();
1.137 +void Test23();
1.138 +void Test24L();
1.139 +void Test25L();
1.140 +void Test26L();
1.141 +void Test27L();
1.142 +void Test28L();
1.143 +void Test29L();
1.144 +void Test30L();
1.145 +void Test31L();
1.146 +void Test32();
1.147 +void Test33L();
1.148 +void Test34L();
1.149 +void Test35L();
1.150 +void Test36L();
1.151 +void TestCEZCompressorMethodsL();
1.152 +void TestZlibapiwrapperAPIL();
1.153 +
1.154 +typedef void (*TestPtr)();
1.155 +
1.156 +struct TTests
1.157 + {
1.158 + TestPtr iFn;
1.159 + const TPtrC *iDescription;
1.160 + };
1.161 +
1.162 +const TTests testTable[] = {
1.163 + {Test1L,&KTest1Des},
1.164 + {Test2L,&KTest2Des},
1.165 + {Test3,&KTest3Des},
1.166 + {Test4,&KTest4Des},
1.167 + {Test5L,&KTest5Des},
1.168 + {Test6,&KTest6Des},
1.169 + {Test7L,&KTest7Des},
1.170 + {Test8L,&KTest8Des},
1.171 + {Test9L,&KTest9Des},
1.172 + {Test10,&KTest10Des},
1.173 + {Test11,&KTest11Des},
1.174 + {Test12,&KTest12Des},
1.175 + {Test13L,&KTest13Des},
1.176 + {Test14,&KTest14Des},
1.177 + {Test15L,&KTest15Des},
1.178 + {Test16L,&KTest16Des},
1.179 + {Test17,&KTest17Des},
1.180 + {Test18L,&KTest18Des},
1.181 + {Test19L,&KTest19Des},
1.182 + {Test20L,&KTest20Des},
1.183 + {Test21L,&KTest21Des},
1.184 + {Test22L,&KTest22Des},
1.185 + {Test23,&KTest23Des},
1.186 + {Test24L,&KTest24Des},
1.187 + {Test25L,&KTest25Des},
1.188 + {Test26L,&KTest26Des},
1.189 + {Test27L,&KTest27Des},
1.190 + {Test28L,&KTest28Des},
1.191 + {Test29L,&KTest29Des},
1.192 + {Test30L,&KTest30Des},
1.193 + {Test31L,&KTest31Des},
1.194 + {Test32,&KTest32Des},
1.195 + {Test33L,&KTest33Des},
1.196 + {Test34L,&KTest34Des},
1.197 + {Test35L,&KTest35Des},
1.198 + {Test36L,&KTest36Des},
1.199 + {TestCEZCompressorMethodsL, &KTest37Des},
1.200 + {TestZlibapiwrapperAPIL, &KTest38Des}
1.201 + };
1.202 +
1.203 +struct TTestFlags
1.204 + {
1.205 + enum
1.206 + {
1.207 + FakeNoInput = 16,
1.208 + FakeNoOutput = 32,
1.209 + Dictionary = 64,
1.210 + AllocFail = 128,
1.211 + Corrupt = 256,
1.212 + AllocFailInflate = 512,
1.213 + Unicode = 1024,
1.214 + Percent = 2048
1.215 + };
1.216 +
1.217 +
1.218 + TTestFlags() : iFlags(0), iBufferSize(0) { Defaults(); }
1.219 + TTestFlags(TInt aFlags, TInt aBufferSize) : iFlags(aFlags), iBufferSize(aBufferSize) { Defaults(); }
1.220 + void Defaults();
1.221 +
1.222 + TInt iFlags;
1.223 + TInt iBufferSize;
1.224 + TPtrC8 iDictionary;
1.225 + TInt iLevel;
1.226 + TInt iWindowBits;
1.227 + TInt iMemLevel;
1.228 + CEZCompressor::TStrategy iStrategy;
1.229 + };
1.230 +
1.231 +
1.232 +void TTestFlags::Defaults()
1.233 + {
1.234 + iLevel = CEZCompressor::EDefaultCompression;
1.235 + iWindowBits = CEZCompressor::EMaxWBits;
1.236 + iMemLevel = CEZCompressor::EDefMemLevel;
1.237 + iStrategy = CEZCompressor::EDefaultStrategy;
1.238 + }
1.239 +
1.240 +TReal FastCountToMilliseconds(TInt aFastCount)
1.241 + {
1.242 + TInt freqInHz;
1.243 + HAL::Get(HAL::EFastCounterFrequency, freqInHz);
1.244 + TReal freqInkHz = freqInHz / 1000;
1.245 + return (TReal)aFastCount / freqInkHz;
1.246 + }
1.247 +
1.248 +
1.249 +static RTest Test(_L("EZLIB"));
1.250 +
1.251 +static TUint8 original[] = "compression is a constant source of depression and depression leads to multiple regressions in succession";
1.252 +static TUint8 dictionary[] = "constant source multiple leads compression ";
1.253 +static TUint8 badDictionary[] = "I'm not the dictionary";
1.254 +static TUint8 compressed[256];
1.255 +static TInt compressedSize; // length of compressed data in compressed.
1.256 +static TUint8 uncompressed[256];
1.257 +static TText output[256];
1.258 +static TText originalU[256];
1.259 +static TText dictionaryU[256];
1.260 +
1.261 +static void RunTestL();
1.262 +
1.263 +static void CompressBufferL(const TTestFlags &aFlags, RTest &aTest=Test);
1.264 +static void DecompressBufferL(const TTestFlags &aFlags, RTest &aTest=Test);
1.265 +static void DblDecompressBufferL(TInt aBufferSize, TBool aReset);
1.266 +static void CompressDecompressL(const TTestFlags &aFlags);
1.267 +static void DblCompressBufferL(TInt aBufferSize, TBool aReset = EFalse);
1.268 +
1.269 +class CBufferManager : public CBase, public MEZBufferManager
1.270 + {
1.271 +public:
1.272 + ~CBufferManager();
1.273 +
1.274 + static CBufferManager *NewLC(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength, TInt aBufferSize);
1.275 + static CBufferManager *NewL(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength, TInt aBufferSize);
1.276 +
1.277 + void InitializeL(CEZZStream &aZStream);
1.278 + void NeedInputL(CEZZStream &aZStream);
1.279 + void NeedOutputL(CEZZStream &aZStream);
1.280 + void FinalizeL(CEZZStream &aZStream);
1.281 +
1.282 + void FakeNoInput() { iFakeNoInput = ETrue; }
1.283 + void FakeNoOutput() { iFakeNoOutput = ETrue; }
1.284 +
1.285 +private:
1.286 + CBufferManager(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength);
1.287 + void ConstructL(TInt aBufferSize);
1.288 +
1.289 +private:
1.290 + TUint8 *iInput, *iOutput;
1.291 + TUint8 *iInputBuffer, *iOutputBuffer;
1.292 + TInt iBufferSize;
1.293 + TInt iOutputLength, iInputLength;
1.294 + TPtr8 iInputDescriptor;
1.295 + TPtr8 iOutputDescriptor;
1.296 + TBool iFakeNoInput;
1.297 + TBool iFakeNoOutput;
1.298 + };
1.299 +
1.300 +CBufferManager::CBufferManager(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength)
1.301 + : iInput(aInput),
1.302 + iOutput(aOutput),
1.303 + iOutputLength(aOutputLength),
1.304 + iInputLength(aInputLength),
1.305 + iInputDescriptor(NULL,0),
1.306 + iOutputDescriptor(NULL,0),
1.307 + iFakeNoInput(EFalse),
1.308 + iFakeNoOutput(EFalse)
1.309 + {
1.310 +
1.311 + }
1.312 +
1.313 +CBufferManager::~CBufferManager()
1.314 + {
1.315 + delete[] iInputBuffer;
1.316 + delete[] iOutputBuffer;
1.317 + }
1.318 +
1.319 +CBufferManager *CBufferManager::NewLC(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength, TInt aBufferSize)
1.320 + {
1.321 + CBufferManager *bm = new (ELeave) CBufferManager(aInput,aInputLength,aOutput,aOutputLength);
1.322 + CleanupStack::PushL(bm);
1.323 + bm->ConstructL(aBufferSize);
1.324 + return bm;
1.325 + }
1.326 +
1.327 +CBufferManager *CBufferManager::NewL(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength, TInt aBufferSize)
1.328 + {
1.329 + CBufferManager *bm = new (ELeave) CBufferManager(aInput,aInputLength,aOutput,aOutputLength);
1.330 + CleanupStack::PushL(bm);
1.331 + bm->ConstructL(aBufferSize);
1.332 + CleanupStack::Pop();
1.333 + return bm;
1.334 + }
1.335 +
1.336 +void CBufferManager::ConstructL(TInt aBufferSize)
1.337 + {
1.338 + iBufferSize = aBufferSize;
1.339 + iInputBuffer = new (ELeave) TUint8[iBufferSize];
1.340 + iOutputBuffer = new (ELeave) TUint8[iBufferSize];
1.341 +
1.342 + }
1.343 +
1.344 +void CBufferManager::InitializeL(CEZZStream &aZStream)
1.345 + {
1.346 + TInt remaining = iInputLength;
1.347 + if (remaining > iBufferSize)
1.348 + remaining = iBufferSize;
1.349 + Mem::Copy(iInputBuffer,iInput,remaining);
1.350 + iInputDescriptor.Set(iInputBuffer,remaining,iBufferSize);
1.351 + aZStream.SetInput(iInputDescriptor);
1.352 + iOutputDescriptor.Set(iOutputBuffer,0,iBufferSize);
1.353 + aZStream.SetOutput(iOutputDescriptor);
1.354 + iInput += remaining;
1.355 + }
1.356 +
1.357 +void CBufferManager::NeedInputL(CEZZStream &aZStream)
1.358 + {
1.359 + TInt remaining;
1.360 + if (iFakeNoInput)
1.361 + remaining = 0;
1.362 + else
1.363 + {
1.364 + remaining = iInputLength - aZStream.TotalIn();
1.365 + if (remaining > iBufferSize)
1.366 + remaining = iBufferSize;
1.367 + Mem::Copy(iInputBuffer,iInput,remaining);
1.368 + }
1.369 + iInputDescriptor.Set(iInputBuffer,remaining,iBufferSize);
1.370 + aZStream.SetInput(iInputDescriptor);
1.371 + iInput += remaining;
1.372 + }
1.373 +
1.374 +
1.375 +void CBufferManager::NeedOutputL(CEZZStream &aZStream)
1.376 + {
1.377 + TInt remaining;
1.378 + if (iFakeNoOutput)
1.379 + {
1.380 + remaining = 0;
1.381 + iOutputDescriptor.Set(iOutputBuffer,remaining,remaining);
1.382 + }
1.383 + else
1.384 + {
1.385 + remaining = iOutputLength - aZStream.TotalOut();
1.386 + if (remaining > iBufferSize)
1.387 + remaining = iBufferSize;
1.388 + }
1.389 + TPtrC8 od = aZStream.OutputDescriptor();
1.390 + Mem::Copy(iOutput,iOutputBuffer,od.Size());
1.391 + aZStream.SetOutput(iOutputDescriptor);
1.392 + iOutput += iBufferSize;
1.393 + }
1.394 +
1.395 +void CBufferManager::FinalizeL(CEZZStream &aZStream)
1.396 + {
1.397 + TInt copy = aZStream.OutputDescriptor().Size();
1.398 +
1.399 + if (copy > 0)
1.400 + Mem::Copy(iOutput,iOutputBuffer,copy);
1.401 + }
1.402 +
1.403 +/**
1.404 +@SYMTestCaseID SYSLIB-EZLIB-CT-1328
1.405 +@SYMTestCaseDesc Decompression of stream test
1.406 +@SYMTestPriority High
1.407 +@SYMTestActions Compresses and decompresses a buffer and tests to see whether the orginal and decompression streams
1.408 + are the same.
1.409 +@SYMTestExpectedResults The test must not fail.
1.410 +@SYMREQ REQ0000
1.411 +*/
1.412 +
1.413 +static void CompressDecompressL(const TTestFlags &aFlags)
1.414 + {
1.415 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-1328 "));
1.416 + CompressBufferL(aFlags);
1.417 + DecompressBufferL(aFlags);
1.418 +
1.419 + if (aFlags.iFlags & TTestFlags::Unicode)
1.420 + {
1.421 + TPtr s1(REINTERPRET_CAST(TText *, original),sizeof(original));
1.422 + TPtr s2(REINTERPRET_CAST(TText *, uncompressed),sizeof(original));
1.423 + Test(s1.Compare(s2) == 0,__LINE__);
1.424 + }
1.425 + else
1.426 + {
1.427 + TPtrC8 s1(original);
1.428 + TPtrC8 s2(uncompressed);
1.429 + Test(s1.Compare(s2) == 0,__LINE__);
1.430 + }
1.431 + }
1.432 +
1.433 +// Compresses the data in original and places it into compressed.
1.434 +
1.435 +//Need to pass in RTest object as this function is called by a seperate thread sometimes
1.436 +static void CompressBufferL(const TTestFlags &aFlags, RTest &aTest)
1.437 + {
1.438 + _LIT(KMsg,"\nTesting multi-step compresssion with buffer size %d\n");
1.439 + aTest.Printf(KMsg,aFlags.iBufferSize);
1.440 + aTest.Printf(KSeparator);
1.441 + CBufferManager *bm;
1.442 + TInt sourceSize;
1.443 +
1.444 + if (aFlags.iFlags & TTestFlags::Unicode)
1.445 + {
1.446 + sourceSize = sizeof(original) * sizeof(TText);
1.447 + bm = CBufferManager::NewLC(REINTERPRET_CAST(TUint8*,originalU),sourceSize,compressed,256,aFlags.iBufferSize);
1.448 + }
1.449 + else
1.450 + {
1.451 + sourceSize = sizeof(original);
1.452 + bm = CBufferManager::NewLC(original,sourceSize,compressed,256,aFlags.iBufferSize);
1.453 + }
1.454 +
1.455 +
1.456 + if (aFlags.iFlags & TTestFlags::FakeNoInput)
1.457 + bm->FakeNoInput();
1.458 + if (aFlags.iFlags & TTestFlags::FakeNoOutput)
1.459 + bm->FakeNoOutput();
1.460 + CEZCompressor *def;
1.461 +
1.462 +#if defined(_DEBUG) && defined(__WINS__)
1.463 + if (aFlags.iFlags & TTestFlags::AllocFail)
1.464 + __UHEAP_SETFAIL(RHeap::ETrueRandom,5);
1.465 +#endif
1.466 +
1.467 + if (aFlags.iFlags & TTestFlags::Dictionary)
1.468 + def = CEZCompressor::NewLC(*bm,aFlags.iDictionary,aFlags.iLevel,aFlags.iWindowBits,
1.469 + aFlags.iMemLevel,aFlags.iStrategy);
1.470 + else
1.471 + def= CEZCompressor::NewLC(*bm,aFlags.iLevel,aFlags.iWindowBits,aFlags.iMemLevel,
1.472 + aFlags.iStrategy);
1.473 +
1.474 + while (def->DeflateL())
1.475 + {
1.476 + if (aFlags.iFlags & TTestFlags::Percent)
1.477 + {
1.478 + _LIT(KPer,"%d ");
1.479 + aTest.Printf(KPer,def->Progress(sourceSize));
1.480 + }
1.481 + }
1.482 + if (aFlags.iFlags & TTestFlags::Percent)
1.483 + aTest.Printf(_L("\n"));
1.484 +
1.485 + compressedSize = def->TotalOut();
1.486 + _LIT(KUnMsg,"Uncompressed Size %d\n");
1.487 + _LIT(KComMsg,"Compressed Size %d\n");
1.488 +
1.489 + if (aFlags.iFlags & TTestFlags::Corrupt)
1.490 + compressed[compressedSize >> 1] = 1;
1.491 +
1.492 + aTest.Printf(KUnMsg,def->TotalIn());
1.493 + aTest.Printf(KComMsg,compressedSize);
1.494 + CleanupStack::PopAndDestroy(2);
1.495 + }
1.496 +
1.497 +// Decompresses data stored in compressed and writes it to uncompressed.
1.498 +
1.499 +//Need to pass in RTest object as this function is called by a seperate thread sometimes
1.500 +static void DecompressBufferL(const TTestFlags &aFlags, RTest &aTest)
1.501 + {
1.502 + _LIT(KMsg,"\nTesting multi-step decompresssion with buffer size %d\n");
1.503 + aTest.Printf(KMsg,aFlags.iBufferSize);
1.504 + aTest.Printf(KSeparator);
1.505 + CBufferManager *bm = CBufferManager::NewLC(compressed,compressedSize,uncompressed,256,aFlags.iBufferSize);
1.506 +
1.507 + if (aFlags.iFlags & TTestFlags::FakeNoInput)
1.508 + bm->FakeNoInput();
1.509 + if (aFlags.iFlags & TTestFlags::FakeNoOutput)
1.510 + bm->FakeNoOutput();
1.511 +
1.512 +#if defined(_DEBUG) && defined(__WINS__)
1.513 + if (aFlags.iFlags & TTestFlags::AllocFail)
1.514 + __UHEAP_SETFAIL(RHeap::ETrueRandom,10);
1.515 +#endif
1.516 +
1.517 + CEZDecompressor *in;
1.518 + if (aFlags.iFlags & TTestFlags::Dictionary)
1.519 + in = CEZDecompressor::NewLC(*bm,aFlags.iDictionary);
1.520 + else
1.521 + in = CEZDecompressor::NewLC(*bm);
1.522 +
1.523 +#if defined(_DEBUG) && defined(__WINS__)
1.524 + if (aFlags.iFlags & TTestFlags::AllocFailInflate)
1.525 + __UHEAP_SETFAIL(RHeap::ETrueRandom,10);
1.526 +#endif
1.527 +
1.528 + while (in->InflateL())
1.529 + {
1.530 + if (aFlags.iFlags & TTestFlags::Percent)
1.531 + {
1.532 + _LIT(KPer,"%d ");
1.533 + aTest.Printf(KPer,in->Progress(compressedSize));
1.534 + }
1.535 + }
1.536 + if (aFlags.iFlags & TTestFlags::Percent)
1.537 + aTest.Printf(_L("\n"));
1.538 +
1.539 +
1.540 + if (aFlags.iFlags & TTestFlags::Unicode)
1.541 + {
1.542 + TPtrC ptr(REINTERPRET_CAST(TText *,uncompressed),in->TotalOut() / sizeof(TText));
1.543 + aTest.Printf(ptr);
1.544 + aTest.Printf(_L("\n"));
1.545 + }
1.546 + else
1.547 + {
1.548 + TPtrC8 ptr8(uncompressed);
1.549 + TPtr ptr16(output,256);
1.550 + ptr16.Copy(ptr8);
1.551 + aTest.Printf(ptr16);
1.552 + aTest.Printf(_L("\n"));
1.553 + }
1.554 + CleanupStack::PopAndDestroy(2);
1.555 + }
1.556 +
1.557 +static void DblCompressBufferL(TInt aBufferSize, TBool aReset)
1.558 + {
1.559 + CEZCompressor *def = NULL;
1.560 +
1.561 + _LIT(KMsg,"\nTesting multi-step compresssion with buffer size %d\n");
1.562 + _LIT(KUnMsg,"Uncompressed Size %d\n");
1.563 + _LIT(KComMsg,"Compressed Size %d\n");
1.564 +
1.565 + Test.Printf(KMsg,aBufferSize);
1.566 + Test.Printf(KSeparator,aBufferSize);
1.567 + CBufferManager *bm = CBufferManager::NewLC(original,sizeof(original),compressed,256,aBufferSize);
1.568 + def = CEZCompressor::NewLC(*bm);
1.569 +
1.570 + while (def->DeflateL()){}
1.571 +
1.572 + compressedSize = def->TotalOut();
1.573 + Test.Printf(KUnMsg,sizeof(original));
1.574 + Test.Printf(KComMsg,compressedSize);
1.575 +
1.576 + CleanupStack::Pop();
1.577 + CleanupStack::PopAndDestroy();
1.578 + CleanupStack::PushL(def);
1.579 +
1.580 + if (aReset)
1.581 + {
1.582 + bm = CBufferManager::NewLC(original,sizeof(original),compressed,256,aBufferSize);
1.583 + def->ResetL(*bm);
1.584 + }
1.585 +
1.586 + Test.Printf(KMsg,aBufferSize);
1.587 + Test.Printf(KSeparator,aBufferSize);
1.588 +
1.589 + while (def->DeflateL()){}
1.590 +
1.591 + compressedSize = def->TotalOut();
1.592 + Test.Printf(KUnMsg,sizeof(original));
1.593 + Test.Printf(KComMsg,compressedSize);
1.594 +
1.595 + CleanupStack::PopAndDestroy(2);
1.596 + }
1.597 +
1.598 +static void DblDecompressBufferL(TInt aBufferSize, TBool aReset)
1.599 + {
1.600 + CEZDecompressor *def = NULL;
1.601 +
1.602 + _LIT(KMsg,"\nTesting multi-step decompresssion with buffer size %d\n");
1.603 + Test.Printf(KMsg,aBufferSize);
1.604 + Test.Printf(KSeparator);
1.605 + CBufferManager *bm = CBufferManager::NewLC(compressed,compressedSize,uncompressed,256,aBufferSize);
1.606 + def = CEZDecompressor::NewLC(*bm);
1.607 +
1.608 + while (def->InflateL()){}
1.609 +
1.610 + CleanupStack::Pop();
1.611 + CleanupStack::PopAndDestroy();
1.612 + CleanupStack::PushL(def);
1.613 +
1.614 + if (aReset)
1.615 + {
1.616 + bm = CBufferManager::NewLC(compressed,compressedSize,uncompressed,256,aBufferSize);
1.617 + def->ResetL(*bm);
1.618 + }
1.619 +
1.620 + Test.Printf(KMsg,aBufferSize);
1.621 + Test.Printf(KSeparator,aBufferSize);
1.622 +
1.623 + while (def->InflateL()){}
1.624 +
1.625 + TPtrC8 ptr8(uncompressed);
1.626 + TPtr ptr16(output,256);
1.627 + ptr16.Copy(ptr8);
1.628 + Test.Printf(ptr16);
1.629 + Test.Printf(_L("\n"));
1.630 +
1.631 + CleanupStack::PopAndDestroy(2);
1.632 + }
1.633 +
1.634 +/**
1.635 +@SYMTestCaseID SYSLIB-EZLIB-CT-0785
1.636 +@SYMTestCaseDesc Multistep compression & decompression test using buffers smaller than source & destination
1.637 +@SYMTestPriority High
1.638 +@SYMTestActions Set the test flags to 0,buffersize to 8
1.639 +@SYMTestExpectedResults The test must not fail.
1.640 +@SYMREQ REQ0000
1.641 +*/
1.642 +
1.643 +void Test1L()
1.644 + {
1.645 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0785 "));
1.646 + TTestFlags flags(0,8);
1.647 + CompressDecompressL(flags);
1.648 + }
1.649 +
1.650 +/**
1.651 +@SYMTestCaseID SYSLIB-EZLIB-CT-0786
1.652 +@SYMTestCaseDesc Multistep compression & decompression test using buffers larger than source & destination
1.653 +@SYMTestPriority High
1.654 +@SYMTestActions Set the test flags to 0,buffersize to 1024
1.655 +@SYMTestExpectedResults The test must not fail.
1.656 +@SYMREQ REQ0000
1.657 +*/
1.658 +
1.659 +void Test2L()
1.660 + {
1.661 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0786 "));
1.662 + TTestFlags flags(0,1024);
1.663 + CompressDecompressL(flags);
1.664 + }
1.665 +
1.666 +/**
1.667 +@SYMTestCaseID SYSLIB-EZLIB-CT-0787
1.668 +@SYMTestCaseDesc Multistep compression test
1.669 +@SYMTestPriority High
1.670 +@SYMTestActions Set the test flags to TTestFlags::FakeNoInput,buffersize to 8
1.671 +@SYMTestExpectedResults The test must not fail.
1.672 +@SYMREQ REQ0000
1.673 +*/
1.674 +
1.675 +void Test3()
1.676 + {
1.677 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0787 "));
1.678 + TTestFlags flags(TTestFlags::FakeNoInput,8);
1.679 +
1.680 + TRAPD(err,CompressBufferL(flags));
1.681 + Test (err==KErrNone); // This test should succeed as providing no Input is a valid thing for
1.682 + // NeedInputL to do.
1.683 + }
1.684 +
1.685 +/**
1.686 +@SYMTestCaseID SYSLIB-EZLIB-CT-0788
1.687 +@SYMTestCaseDesc Multistep compression test when NeedOutput provides no output
1.688 +@SYMTestPriority High
1.689 +@SYMTestActions Set the test flags to TTestFlags::FakeNoOutput,buffersize to 8
1.690 + Check for buffer error.
1.691 +@SYMTestExpectedResults The test must not fail.
1.692 +@SYMREQ REQ0000
1.693 +*/
1.694 +
1.695 +void Test4()
1.696 + {
1.697 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0788 "));
1.698 + TTestFlags flags(TTestFlags::FakeNoOutput,8);
1.699 +
1.700 + TRAPD(err,CompressBufferL(flags));
1.701 + Test (err==KEZlibErrBuf);
1.702 + }
1.703 +
1.704 +/**
1.705 +@SYMTestCaseID SYSLIB-EZLIB-CT-0789
1.706 +@SYMTestCaseDesc Multistep compression test with the same CEZCompressor,
1.707 + resetting it after the first compression
1.708 +@SYMTestPriority High
1.709 +@SYMTestActions Set the buffersize to 8,reset value to true
1.710 +@SYMTestExpectedResults The test must not fail.
1.711 +@SYMREQ REQ0000
1.712 +*/
1.713 +
1.714 +void Test5L()
1.715 + {
1.716 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0789 "));
1.717 + DblCompressBufferL(8,ETrue);
1.718 + }
1.719 +
1.720 +/**
1.721 +@SYMTestCaseID SYSLIB-EZLIB-CT-0790
1.722 +@SYMTestCaseDesc Multistep compression test with the same CEZCompressor,
1.723 + without resetting it after the first compression
1.724 +@SYMTestPriority High
1.725 +@SYMTestActions Set the buffersize to 8,reset value to false
1.726 +@SYMTestExpectedResults The test must not fail.
1.727 +@SYMREQ REQ0000
1.728 +*/
1.729 +
1.730 +void Test6()
1.731 + {
1.732 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0790 "));
1.733 + //Calling compress twice without reseting (ie passing in EFalse) causes leave
1.734 + TRAPD(err,DblCompressBufferL(8,EFalse));
1.735 + Test (err==KEZlibErrDeflateTerminated);
1.736 + }
1.737 +
1.738 +/**
1.739 +@SYMTestCaseID SYSLIB-EZLIB-CT-0791
1.740 +@SYMTestCaseDesc Multistep compression & decompression test using a preset dictionary
1.741 +@SYMTestPriority High
1.742 +@SYMTestActions Set the test flags to TTestFlags::Dictionary,buffersize to 8
1.743 +@SYMTestExpectedResults The test must not fail.
1.744 +@SYMREQ REQ0000
1.745 +*/
1.746 +
1.747 +void Test7L()
1.748 + {
1.749 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0791 "));
1.750 + TTestFlags flags(TTestFlags::Dictionary,8);
1.751 + flags.iDictionary.Set(dictionary,sizeof(dictionary));
1.752 +
1.753 + CompressDecompressL(flags);
1.754 + }
1.755 +
1.756 +/**
1.757 +@SYMTestCaseID SYSLIB-EZLIB-CT-0792
1.758 +@SYMTestCaseDesc Multistep compression with compression level of 0 test
1.759 +@SYMTestPriority High
1.760 +@SYMTestActions Set the test flags to 0,buffersize to 8,compression level to 0
1.761 +@SYMTestExpectedResults The test must not fail.
1.762 +@SYMREQ REQ0000
1.763 +*/
1.764 +
1.765 +void Test8L()
1.766 + {
1.767 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0792 "));
1.768 + TTestFlags flags(0,8);
1.769 + flags.iLevel = 0;
1.770 +
1.771 + CompressDecompressL(flags);
1.772 + }
1.773 +
1.774 +/**
1.775 +@SYMTestCaseID SYSLIB-EZLIB-CT-0793
1.776 +@SYMTestCaseDesc Multistep compression test with compression level of 9
1.777 +@SYMTestPriority High
1.778 +@SYMTestActions Set the test flags to 0,buffersize to 8,compression level to 9
1.779 +@SYMTestExpectedResults The test must not fail.
1.780 +@SYMREQ REQ0000
1.781 +*/
1.782 +
1.783 +void Test9L()
1.784 + {
1.785 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0793 "));
1.786 + TTestFlags flags(0,8);
1.787 + flags.iLevel = 9;
1.788 +
1.789 + CompressDecompressL(flags);
1.790 + }
1.791 +
1.792 +/**
1.793 +@SYMTestCaseID SYSLIB-EZLIB-CT-0794
1.794 +@SYMTestCaseDesc Multistep compression test with invalid compression level
1.795 +@SYMTestPriority High
1.796 +@SYMTestActions Set the test flags to 0,buffersize to 8,compression level to 10.
1.797 + Check for stream error when compression level is greater than 9
1.798 +@SYMTestExpectedResults The test must not fail.
1.799 +@SYMREQ REQ0000
1.800 +*/
1.801 +
1.802 +void Test10()
1.803 + {
1.804 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0794 "));
1.805 + TTestFlags flags(0,8);
1.806 + flags.iLevel = 10;
1.807 +
1.808 + TRAPD(err, CompressDecompressL(flags));
1.809 + //CompressL fails with KEZlibErrStream if level is greater than 9
1.810 + Test (err==KEZlibErrStream);
1.811 + }
1.812 +
1.813 +/**
1.814 +@SYMTestCaseID SYSLIB-EZLIB-CT-0795
1.815 +@SYMTestCaseDesc Multistep compression test with window bits of 7
1.816 +@SYMTestPriority High
1.817 +@SYMTestActions Set the test flags to 0,buffersize to 7
1.818 + Check for stream error if window bits is less than 8
1.819 +@SYMTestExpectedResults The test must not fail.
1.820 +@SYMREQ REQ0000
1.821 +*/
1.822 +
1.823 +void Test11()
1.824 + {
1.825 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0795 "));
1.826 + TTestFlags flags(0,7);
1.827 + flags.iWindowBits = 7;
1.828 + //CompressL fails with KEZlibErrStream if window bits is less than 8
1.829 + TRAPD(err, CompressDecompressL(flags));
1.830 + Test (err==KEZlibErrStream);
1.831 + }
1.832 +
1.833 +/**
1.834 +@SYMTestCaseID SYSLIB-EZLIB-CT-0796
1.835 +@SYMTestCaseDesc Multistep compression test with window bits of 7
1.836 +@SYMTestPriority High
1.837 +@SYMTestActions Set the test flags to 0,buffersize to 8
1.838 + Check for stream error if window bits is less than 9
1.839 +@SYMTestExpectedResults The test must not fail.
1.840 +@SYMREQ REQ0000
1.841 +*/
1.842 +
1.843 +void Test12()
1.844 + {
1.845 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0796 "));
1.846 + TTestFlags flags(0,8);
1.847 + flags.iWindowBits = 7;
1.848 + //CompressL fails with KEZlibErrStream if window bits is less than 9
1.849 + TRAPD(err, CompressDecompressL(flags));
1.850 + Test (err==KEZlibErrStream);
1.851 + }
1.852 +
1.853 +/**
1.854 +@SYMTestCaseID SYSLIB-EZLIB-CT-0797
1.855 +@SYMTestCaseDesc Multistep compression test with memory level = 1
1.856 +@SYMTestPriority High
1.857 +@SYMTestActions Set the test flags to 0,buffersize to 8
1.858 +@SYMTestExpectedResults The test must not fail.
1.859 +@SYMREQ REQ0000
1.860 +*/
1.861 +
1.862 +void Test13L()
1.863 + {
1.864 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0797 "));
1.865 + TTestFlags flags(0,8);
1.866 + flags.iMemLevel = 1;
1.867 +
1.868 + CompressDecompressL(flags);
1.869 + }
1.870 +
1.871 +/**
1.872 +@SYMTestCaseID SYSLIB-EZLIB-CT-0798
1.873 +@SYMTestCaseDesc Multistep compression test with memory level = 10
1.874 +@SYMTestPriority High
1.875 +@SYMTestActions Set the test flags to 0,buffersize to 8
1.876 + Check for stream error if memory level is greater than 8.
1.877 +@SYMTestExpectedResults The test must not fail.
1.878 +@SYMREQ REQ0000
1.879 +*/
1.880 +
1.881 +void Test14()
1.882 + {
1.883 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0798 "));
1.884 + TTestFlags flags(0,8);
1.885 + flags.iMemLevel = 10;
1.886 +
1.887 + //CompressL fails with KEZlibErrStream if mem level greater than 8
1.888 + TRAPD(err, CompressDecompressL(flags));
1.889 + Test (err==KEZlibErrStream);
1.890 + }
1.891 +
1.892 +/**
1.893 +@SYMTestCaseID SYSLIB-EZLIB-CT-0799
1.894 +@SYMTestCaseDesc Multistep compression test using only Huffman encoding
1.895 +@SYMTestPriority High
1.896 +@SYMTestActions Set the test flags to 0,buffersize to 8
1.897 +@SYMTestExpectedResults The test must not fail.
1.898 +@SYMREQ REQ0000
1.899 +*/
1.900 +
1.901 +void Test15L()
1.902 + {
1.903 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0799 "));
1.904 + TTestFlags flags(0,8);
1.905 + flags.iStrategy = CEZCompressor::EHuffmanOnly;
1.906 +
1.907 + CompressDecompressL(flags);
1.908 + }
1.909 +
1.910 +/**
1.911 +@SYMTestCaseID SYSLIB-EZLIB-CT-0800
1.912 +@SYMTestCaseDesc Multistep compression test using Filtered strategy
1.913 +@SYMTestPriority High
1.914 +@SYMTestActions Set the test flags to 0,buffersize to 8
1.915 +@SYMTestExpectedResults The test must not fail.
1.916 +@SYMREQ REQ0000
1.917 +*/
1.918 +
1.919 +void Test16L()
1.920 + {
1.921 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0800 "));
1.922 + TTestFlags flags(0,8);
1.923 + flags.iStrategy = CEZCompressor::EFiltered;
1.924 +
1.925 + CompressDecompressL(flags);
1.926 + }
1.927 +
1.928 +/**
1.929 +@SYMTestCaseID SYSLIB-EZLIB-CT-0801
1.930 +@SYMTestCaseDesc Multistep compression test when Alloc fails randomly
1.931 +@SYMTestPriority High
1.932 +@SYMTestActions Set the test flags to 0,buffersize to 8
1.933 +@SYMTestExpectedResults The test must not fail.
1.934 +@SYMREQ REQ0000
1.935 +*/
1.936 +
1.937 +void Test17()
1.938 + {
1.939 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0801 "));
1.940 + TTestFlags flags(TTestFlags::AllocFail,8);
1.941 +
1.942 + TRAPD(err,CompressBufferL(flags));
1.943 + Test(err == KErrNone||err == KErrNoMemory); //alloc failure is random so no quarantees of failure
1.944 + //Need to reset the heap afterwards to avoid problems for next test.
1.945 + __UHEAP_RESET;
1.946 + }
1.947 +
1.948 +/**
1.949 +@SYMTestCaseID SYSLIB-EZLIB-CT-0802
1.950 +@SYMTestCaseDesc Multistep decompression test when NeedInput provides no input
1.951 +@SYMTestPriority High
1.952 +@SYMTestActions Set the test flags to 0,buffersize to 8
1.953 + Check for data error,when no input is given
1.954 +@SYMTestExpectedResults The test must not fail.
1.955 +@SYMREQ REQ0000
1.956 +*/
1.957 +
1.958 +void Test18L()
1.959 + {
1.960 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0802 "));
1.961 + TTestFlags flags(0,8);
1.962 + CompressBufferL(flags); // make sure we initialize compressed properly
1.963 +
1.964 + flags.iFlags |= TTestFlags::FakeNoInput;
1.965 + TRAPD(err,DecompressBufferL(flags));
1.966 + // CEZDecompressor::InflateL has left with KEZlibErrBuf due to buffer error
1.967 + Test (err==KEZlibErrBuf);
1.968 + }
1.969 +
1.970 +/**
1.971 +@SYMTestCaseID SYSLIB-EZLIB-CT-0803
1.972 +@SYMTestCaseDesc Multistep decompression test when NeedOutput provides no output
1.973 +@SYMTestPriority High
1.974 +@SYMTestActions Set the test flags to 0,buffersize to 8
1.975 + Check for data error,when no output is given
1.976 +@SYMTestExpectedResults The test must not fail.
1.977 +@SYMREQ REQ0000
1.978 +*/
1.979 +
1.980 +void Test19L()
1.981 + {
1.982 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0803 "));
1.983 + TTestFlags flags(0,8);
1.984 + CompressBufferL(flags); // make sure we initialize compressed properly
1.985 +
1.986 + flags.iFlags |= TTestFlags::FakeNoOutput;
1.987 + TRAPD(err,DecompressBufferL(flags));
1.988 + // CEZDecompressor::InflateL has left with KEZlibErrBuf due to buffer error
1.989 + Test (err==KEZlibErrBuf);
1.990 + }
1.991 +
1.992 +/**
1.993 +@SYMTestCaseID SYSLIB-EZLIB-CT-0804
1.994 +@SYMTestCaseDesc Multistep decompression test when NeedOutput provides no output
1.995 +@SYMTestPriority High
1.996 +@SYMTestActions Set the test flags to TTestFlags::Corrupt, buffersize to 8
1.997 + Check for data error
1.998 +@SYMTestExpectedResults The test must not fail.
1.999 +@SYMREQ REQ0000
1.1000 +*/
1.1001 +
1.1002 +void Test20L()
1.1003 + {
1.1004 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0804 "));
1.1005 + TTestFlags flags(TTestFlags::Corrupt,8);
1.1006 + CompressBufferL(flags); // make sure we initialize compressed properly
1.1007 +
1.1008 + flags.iFlags = 0;
1.1009 +
1.1010 + TRAPD(err,DecompressBufferL(flags));
1.1011 + // CEZDecompressor::InflateL has left with KEZlibErrData due to buffer error
1.1012 + Test (err==KEZlibErrData);
1.1013 + }
1.1014 +
1.1015 +/**
1.1016 +@SYMTestCaseID SYSLIB-EZLIB-CT-0805
1.1017 +@SYMTestCaseDesc Multistep decompression construction test when Alloc fails randomly
1.1018 +@SYMTestPriority High
1.1019 +@SYMTestActions Set the test flags to 0, buffersize to 8
1.1020 + Check for data error
1.1021 +@SYMTestExpectedResults The test must not fail.
1.1022 +@SYMREQ REQ0000
1.1023 +*/
1.1024 +
1.1025 +void Test21L()
1.1026 + {
1.1027 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0805 "));
1.1028 + TTestFlags flags(0,8);
1.1029 + CompressBufferL(flags); // make sure we initialize compressed properly
1.1030 +
1.1031 + flags.iFlags |= TTestFlags::AllocFail;
1.1032 +
1.1033 + TRAPD(err,DecompressBufferL(flags));
1.1034 + Test (err==KErrNone||err==KErrNoMemory); //Alloc failure is random so no guarantee it will always fail.
1.1035 + __UHEAP_RESET;
1.1036 + }
1.1037 +
1.1038 +/**
1.1039 +@SYMTestCaseID SYSLIB-EZLIB-CT-0806
1.1040 +@SYMTestCaseDesc Multistep decompression test when Alloc fails randomly
1.1041 +@SYMTestPriority High
1.1042 +@SYMTestActions Set the test flags to 0, buffersize to 8
1.1043 + Check for no memory errors.
1.1044 +@SYMTestExpectedResults The test must not fail.
1.1045 +@SYMREQ REQ0000
1.1046 +*/
1.1047 +
1.1048 +void Test22L()
1.1049 + {
1.1050 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0806 "));
1.1051 + TTestFlags flags(0,8);
1.1052 + CompressBufferL(flags); // make sure we initialize compressed properly
1.1053 +
1.1054 + flags.iFlags |= TTestFlags::AllocFailInflate;
1.1055 +
1.1056 + TRAPD(err,DecompressBufferL(flags));
1.1057 + Test (err==KErrNone||err==KErrNoMemory); //Alloc failure is random so no guarentee it will always fail.
1.1058 + __UHEAP_RESET;
1.1059 + }
1.1060 +
1.1061 +static void ThreadL()
1.1062 + {
1.1063 + RTest test2(_L("EZLIB - second thread"));
1.1064 + test2.Title();
1.1065 + _LIT(KStartMsg,"Starting Tests in second thread");
1.1066 + test2.Start(KStartMsg);
1.1067 +
1.1068 + TTestFlags flags(TTestFlags::Dictionary,8);
1.1069 + flags.iDictionary.Set(dictionary,sizeof(dictionary));
1.1070 +
1.1071 + TRAPD(err,CompressBufferL(flags, test2));
1.1072 + test2 (err == KErrNone);
1.1073 + flags.iFlags = 0;
1.1074 + //This code leaves (used to panic before the fix for DEF112672)
1.1075 + DecompressBufferL(flags, test2);
1.1076 + User::Panic(_L("TestFailure failure"),0);
1.1077 + test2.End();
1.1078 + test2.Close();
1.1079 + }
1.1080 +
1.1081 +static TInt TestThread(TAny*)
1.1082 + {
1.1083 + User::SetJustInTime(EFalse); // disable debugger panic handling
1.1084 + CTrapCleanup* cleanup=CTrapCleanup::New();
1.1085 + if (!cleanup)
1.1086 + return KErrNoMemory;
1.1087 + TRAPD(r,ThreadL());
1.1088 + delete cleanup;
1.1089 + return r;
1.1090 + }
1.1091 +
1.1092 +/**
1.1093 +@SYMTestCaseID SYSLIB-EZLIB-CT-0807
1.1094 +@SYMTestCaseDesc Multistep decompression test when a dictionary is required and not provided.
1.1095 +@SYMTestPriority High
1.1096 +@SYMTestActions Test for panic and exit reason.
1.1097 +@SYMTestExpectedResults This test should pass without panic.
1.1098 + (Expected to panic before the fix for DEF112672)
1.1099 +@SYMREQ REQ0000
1.1100 +*/
1.1101 +
1.1102 +void Test23()
1.1103 + {
1.1104 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0807 "));
1.1105 + __UHEAP_MARK;
1.1106 +
1.1107 + RThread t;
1.1108 + _LIT(KTestThread,"Panicing thread");
1.1109 + Test.Printf(_L("launching thread"));
1.1110 + Test (t.Create(KTestThread,&TestThread,0x2000,0x10000,0x100000,0,EOwnerThread) == KErrNone);
1.1111 + TRequestStatus s;
1.1112 + t.Logon(s);
1.1113 + Test (s.Int()==KRequestPending);
1.1114 + t.Resume();
1.1115 + Test.Printf(_L("Awaiting completion"));
1.1116 + User::WaitForRequest(s);
1.1117 + User::SetJustInTime(ETrue); // enable debugger panic handling
1.1118 + _LIT(KCategory,"zlib");
1.1119 + Test (t.ExitType()==EExitKill);
1.1120 + Test (t.ExitCategory()!=KCategory);
1.1121 + Test (t.ExitReason()==KEZlibErrData);// SetDictionaryL() leaving error code should be KEZlibErrData
1.1122 + t.Close();
1.1123 +
1.1124 + __UHEAP_MARKEND;
1.1125 +
1.1126 + }
1.1127 +
1.1128 +/**
1.1129 +@SYMTestCaseID SYSLIB-EZLIB-CT-0808
1.1130 +@SYMTestCaseDesc Multistep decompression test when the wrong dictionary is provided
1.1131 +@SYMTestPriority High
1.1132 +@SYMTestActions Check for an error during inflating the dictionary
1.1133 +@SYMTestExpectedResults Test must not fail
1.1134 +@SYMREQ REQ0000
1.1135 +*/
1.1136 +
1.1137 +void Test24L()
1.1138 + {
1.1139 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0808 "));
1.1140 + TTestFlags flags(TTestFlags::Dictionary,8);
1.1141 + flags.iDictionary.Set(dictionary,sizeof(dictionary));
1.1142 +
1.1143 + CompressBufferL(flags);
1.1144 +
1.1145 + flags.iDictionary.Set(badDictionary,sizeof(badDictionary));
1.1146 +
1.1147 + TRAPD(err,DecompressBufferL(flags));
1.1148 + // CEZDecompressor::SetDictionaryL() has left due to bad data
1.1149 + Test (err==KEZlibErrInflateDictionary);
1.1150 + }
1.1151 +
1.1152 +/**
1.1153 +@SYMTestCaseID SYSLIB-EZLIB-CT-0809
1.1154 +@SYMTestCaseDesc Multistep decompression test twice with the same CEZDecompressor,
1.1155 + reseting it after the first decompression
1.1156 +@SYMTestPriority High
1.1157 +@SYMTestActions Set the test flags to 0,buffersize to 8,reset value to TRUE
1.1158 +@SYMTestExpectedResults Test must not fail
1.1159 +@SYMREQ REQ0000
1.1160 +*/
1.1161 +
1.1162 +void Test25L()
1.1163 + {
1.1164 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0809 "));
1.1165 + TTestFlags flags(0,8);
1.1166 + CompressBufferL(flags); // make sure we initialize compressed properly
1.1167 +
1.1168 + DblDecompressBufferL(8,ETrue);
1.1169 + }
1.1170 +
1.1171 +/**
1.1172 +@SYMTestCaseID SYSLIB-EZLIB-CT-0810
1.1173 +@SYMTestCaseDesc Multistep decompression test twice with the same CEZDecompressor,
1.1174 + resetting it after the first decompression
1.1175 +@SYMTestPriority High
1.1176 +@SYMTestActions Set the test flags to 0,buffersize to 8,reset value to FALSE
1.1177 + Check for deflation already occured.
1.1178 +@SYMTestExpectedResults Test must not fail
1.1179 +@SYMREQ REQ0000
1.1180 +*/
1.1181 +
1.1182 +void Test26L()
1.1183 + {
1.1184 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0810 "));
1.1185 + TTestFlags flags(0,8);
1.1186 + CompressBufferL(flags); // make sure we initialize compressed properly
1.1187 +
1.1188 + TRAPD(err,DblDecompressBufferL(8,EFalse));
1.1189 + //Calling decompress twice without resenting causes leave
1.1190 + Test (err==KEZlibErrInflateTerminated);
1.1191 + }
1.1192 +
1.1193 +/**
1.1194 +@SYMTestCaseID SYSLIB-EZLIB-CT-0811
1.1195 +@SYMTestCaseDesc Multistep compression and decompression test on unicode data
1.1196 +@SYMTestPriority High
1.1197 +@SYMTestActions Set the test flags to TTestFlags::Unicode,buffersize to 8
1.1198 +@SYMTestExpectedResults Test must not fail
1.1199 +@SYMREQ REQ0000
1.1200 +*/
1.1201 +
1.1202 +void Test27L()
1.1203 + {
1.1204 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0811 "));
1.1205 + TPtrC8 ptr8(original);
1.1206 + TPtr ptr16(originalU,256);
1.1207 + ptr16.Copy(ptr8);
1.1208 +
1.1209 + TTestFlags flags(TTestFlags::Unicode,8);
1.1210 + TPtrC8(REINTERPRET_CAST(TUint8 *,originalU),ptr16.Size());
1.1211 + CompressDecompressL(flags);
1.1212 + }
1.1213 +
1.1214 +/**
1.1215 +@SYMTestCaseID SYSLIB-EZLIB-CT-0812
1.1216 +@SYMTestCaseDesc Multistep compression and decompression test on unicode data using a unicode dictionary
1.1217 +@SYMTestPriority High
1.1218 +@SYMTestActions Set the test flags to TTestFlags::Dictionary|TTestFlags::Unicode,buffersize to 8
1.1219 +@SYMTestExpectedResults Test must not fail
1.1220 +@SYMREQ REQ0000
1.1221 +*/
1.1222 +
1.1223 +void Test28L()
1.1224 + {
1.1225 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0812 "));
1.1226 + TPtrC8 ptr8(original);
1.1227 + TPtr ptr16(originalU,256);
1.1228 + ptr16.Copy(ptr8);
1.1229 +
1.1230 + TPtrC8 dptr8(dictionary);
1.1231 + TPtr dptr16(dictionaryU,256);
1.1232 + dptr16.Copy(dptr8);
1.1233 +
1.1234 +
1.1235 + TTestFlags flags(TTestFlags::Dictionary|TTestFlags::Unicode,8);
1.1236 + flags.iDictionary.Set(REINTERPRET_CAST(TUint8*, dictionaryU),dptr16.Size());
1.1237 +
1.1238 + TPtrC8(REINTERPRET_CAST(TUint8 *,originalU),ptr16.Size());
1.1239 + CompressDecompressL(flags);
1.1240 + }
1.1241 +
1.1242 +/**
1.1243 +@SYMTestCaseID SYSLIB-EZLIB-CT-0813
1.1244 +@SYMTestCaseDesc Multistep compression and decompression test on unicode data using an ASCII dictionary
1.1245 +@SYMTestPriority High
1.1246 +@SYMTestActions Set the test flags to TTestFlags::Dictionary|TTestFlags::Unicode,buffersize to 8
1.1247 +@SYMTestExpectedResults Test must not fail
1.1248 +@SYMREQ REQ0000
1.1249 +*/
1.1250 +
1.1251 +void Test29L()
1.1252 + {
1.1253 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0813 "));
1.1254 + TPtrC8 ptr8(original);
1.1255 + TPtr ptr16(originalU,256);
1.1256 + ptr16.Copy(ptr8);
1.1257 +
1.1258 + TTestFlags flags(TTestFlags::Dictionary|TTestFlags::Unicode,8);
1.1259 + flags.iDictionary.Set(dictionary,sizeof(dictionary));
1.1260 +
1.1261 + TPtrC8(REINTERPRET_CAST(TUint8 *,originalU),ptr16.Size());
1.1262 + CompressDecompressL(flags);
1.1263 + }
1.1264 +
1.1265 +/**
1.1266 +@SYMTestCaseID SYSLIB-EZLIB-CT-0814
1.1267 +@SYMTestCaseDesc Tests the percentage of completion during multistep compression/decompression
1.1268 +@SYMTestPriority High
1.1269 +@SYMTestActions Set the test flags to TTestFlags::Percent,buffersize to 8
1.1270 +@SYMTestExpectedResults Test must not fail
1.1271 +@SYMREQ REQ0000
1.1272 +*/
1.1273 +
1.1274 +void Test30L()
1.1275 + {
1.1276 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0814 "));
1.1277 + TTestFlags flags(TTestFlags::Percent,8);
1.1278 +
1.1279 + CompressDecompressL(flags);
1.1280 + }
1.1281 +
1.1282 +/**
1.1283 +@SYMTestCaseID SYSLIB-EZLIB-CT-0815
1.1284 +@SYMTestCaseDesc Single step compression and decompression test
1.1285 +@SYMTestPriority High
1.1286 +@SYMTestActions Calls up CEZCompressor::CompressL(),CEZCompressor::DecompressL() test
1.1287 +@SYMTestExpectedResults Test must not fail
1.1288 +@SYMREQ REQ0000
1.1289 +*/
1.1290 +
1.1291 +void Test31L()
1.1292 + {
1.1293 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0815 "));
1.1294 + TPtrC8 originalD(original,sizeof(original));
1.1295 + TPtr8 compressedD(compressed,0,256);
1.1296 + TPtr8 uncompressedD(uncompressed,0,256);
1.1297 + CEZCompressor::CompressL(compressedD,originalD);
1.1298 + CEZDecompressor::DecompressL(uncompressedD,compressedD);
1.1299 +
1.1300 + Test.Printf(_L("\n"));
1.1301 + Test.Printf(KSeparator);
1.1302 + TPtr ptr16(output,256);
1.1303 + ptr16.Copy(uncompressedD);
1.1304 + Test.Printf(ptr16);
1.1305 + Test.Printf(_L("\n"));
1.1306 + Test(originalD.Compare(uncompressedD) == 0,__LINE__);
1.1307 + }
1.1308 +
1.1309 +/**
1.1310 +@SYMTestCaseID SYSLIB-EZLIB-CT-0816
1.1311 +@SYMTestCaseDesc Single step compression test when inadequate output buffer is provided
1.1312 +@SYMTestPriority High
1.1313 +@SYMTestActions Check for EZlibErrBuf buffer error flag
1.1314 +@SYMTestExpectedResults Test must not fail
1.1315 +@SYMREQ REQ0000
1.1316 +*/
1.1317 +
1.1318 +void Test32()
1.1319 + {
1.1320 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0816 "));
1.1321 + TPtrC8 originalD(original,sizeof(original));
1.1322 + TPtr8 compressedD(compressed,0,1);
1.1323 +
1.1324 + Test.Printf(_L("\n"));
1.1325 + Test.Printf(KSeparator);
1.1326 +
1.1327 + TRAPD(err,CEZCompressor::CompressL(compressedD,originalD));
1.1328 + // Buffer error
1.1329 + Test(err == KEZlibErrBuf);
1.1330 + }
1.1331 +
1.1332 +/**
1.1333 +@SYMTestCaseID SYSLIB-EZLIB-CT-0817
1.1334 +@SYMTestCaseDesc Single step decompression test when inadequate output buffer is provided
1.1335 +@SYMTestPriority High
1.1336 +@SYMTestActions Check for EZlibErrBuf buffer error flag
1.1337 +@SYMTestExpectedResults Test must not fail
1.1338 +@SYMREQ REQ0000
1.1339 +*/
1.1340 +
1.1341 +void Test33L()
1.1342 + {
1.1343 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0817 "));
1.1344 + Test.Printf(_L("\n"));
1.1345 + Test.Printf(KSeparator);
1.1346 + TPtrC8 originalD(original,sizeof(original));
1.1347 + TPtr8 compressedD(compressed,0,256);
1.1348 + TPtr8 uncompressedD(uncompressed,0,1);
1.1349 + CEZCompressor::CompressL(compressedD,originalD);
1.1350 + TRAPD(err,CEZDecompressor::DecompressL(uncompressedD,compressedD));
1.1351 + // Buffer error
1.1352 + Test(err == KEZlibErrBuf);
1.1353 + }
1.1354 +
1.1355 +/**
1.1356 +@SYMTestCaseID SYSLIB-EZLIB-CT-0818
1.1357 +@SYMTestCaseDesc Testing graceful exit for zlib 1.1.3 decompression bug
1.1358 +@SYMTestPriority High
1.1359 +@SYMTestActions Check for buffer error after inflation
1.1360 +@SYMTestExpectedResults Test must not fail
1.1361 +@SYMREQ REQ0000
1.1362 +*/
1.1363 +void Test34L()
1.1364 + {
1.1365 + Test.Printf(_L("\n"));
1.1366 + Test.Printf(KSeparator);
1.1367 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0818 "));
1.1368 + // 00000720.png contains specially crafted data block that exposes bug in 1.1.3
1.1369 + // decompression algorithm. Causes InflateL() to return Z_BUF_ERROR.
1.1370 + #if !defined(__WINS__)
1.1371 + _LIT(KInputFile, "z:\\test\\png\\00000720.png");
1.1372 + #else
1.1373 + _LIT(KInputFile, "c:\\test\\png\\00000720.png");
1.1374 + #endif
1.1375 + _LIT(KTempDirectory, "c:\\test\\temp\\");
1.1376 + RFile input, output, tempInput;
1.1377 + RFs rfs;
1.1378 + rfs.Connect();
1.1379 + rfs.MkDirAll(KTempDirectory);
1.1380 +
1.1381 + TInt res = input.Open(rfs, KInputFile, EFileStream | EFileRead | EFileShareAny);
1.1382 + Test(res==KErrNone);
1.1383 + CleanupClosePushL(input);
1.1384 +
1.1385 + TFileName filename;
1.1386 + TBuf8<1024> readBuf;
1.1387 + TInt fileLen;
1.1388 + input.Size(fileLen);
1.1389 + res = input.Read(8,readBuf,fileLen);
1.1390 + Test(res==KErrNone);
1.1391 +
1.1392 + res = tempInput.Temp(rfs, KTempDirectory, filename, EFileStream | EFileWrite | EFileShareExclusive);
1.1393 + Test(res==KErrNone);
1.1394 + CleanupClosePushL(tempInput);
1.1395 + res = tempInput.Write(readBuf, fileLen-8); // Create temporary file without the 8 byte PNG header.
1.1396 + Test(res==KErrNone);
1.1397 +
1.1398 + CEZFileBufferManager *fb = CEZFileBufferManager::NewLC(tempInput, output, 4096);
1.1399 + CEZDecompressor *inf = CEZDecompressor::NewLC(*fb);
1.1400 +
1.1401 + TRAPD(err, while (inf->InflateL()){});
1.1402 + //CEZDecompressor::InflateL() leaves
1.1403 + Test (err==KEZlibErrBuf);
1.1404 +
1.1405 + tempInput.Close();
1.1406 + User::LeaveIfError(rfs.Delete(filename));
1.1407 + input.Close();
1.1408 + CleanupStack::PopAndDestroy(4);
1.1409 + }
1.1410 +
1.1411 +#if !(defined(__WINSCW__) || defined (_DEBUG))
1.1412 +void DecompressFileL(const TDesC& aFilePath, RFs& aFs, TInt aTimingLimit)
1.1413 +{
1.1414 + _LIT(KTempDirectory, "c:\\test\\temp\\");
1.1415 + aFs.MkDirAll(KTempDirectory);
1.1416 +
1.1417 + RFile inputFile, tempFile;
1.1418 + //open the input compressed file
1.1419 + TInt res = inputFile.Open(aFs, aFilePath, EFileStream | EFileRead | EFileShareExclusive);
1.1420 + Test(res==KErrNone);
1.1421 + CleanupClosePushL(inputFile);
1.1422 +
1.1423 + //create a temporary file to be used as an output of the decompressor
1.1424 + TFileName filename;
1.1425 + res = tempFile.Temp(aFs, KTempDirectory, filename, EFileStream | EFileWrite | EFileShareExclusive);
1.1426 + Test(res==KErrNone);
1.1427 + CleanupClosePushL(tempFile);
1.1428 +
1.1429 + //decompress the data from the input file several times
1.1430 + TInt startTime = User::FastCounter();
1.1431 + for (TInt i = 0; i<10; i++)
1.1432 + {
1.1433 + TInt position = 0;
1.1434 + inputFile.Seek(ESeekStart,position);
1.1435 + CEZFileBufferManager *fb = CEZFileBufferManager::NewLC(inputFile, tempFile, 4096);
1.1436 + //create a decompressor object based on the file buffer manager
1.1437 + CEZDecompressor *decompressor = CEZDecompressor::NewLC(*fb);
1.1438 + TRAP(res, while (decompressor->InflateL()){});
1.1439 + Test(res==KErrNone);
1.1440 + CleanupStack::PopAndDestroy(2);
1.1441 + }
1.1442 + TInt endTime = User::FastCounter();
1.1443 +
1.1444 + //close input and temporary file
1.1445 + CleanupStack::PopAndDestroy(2);
1.1446 + //delete temporary file
1.1447 + aFs.Delete(filename);
1.1448 +
1.1449 + TReal netTime = FastCountToMilliseconds(endTime-startTime);
1.1450 + _LIT(KLogLine,"netTime =%f\n");
1.1451 + Test.Printf(KLogLine,netTime);
1.1452 +
1.1453 + if (aTimingLimit)
1.1454 + {
1.1455 + Test(netTime <= aTimingLimit);
1.1456 + }
1.1457 + else
1.1458 + {
1.1459 + Test.Printf(_L("Timings results are only checked on the RAM configuration of H2 and H4 HRP\n"));
1.1460 + }
1.1461 +}
1.1462 +#endif
1.1463 +
1.1464 +/**
1.1465 +@SYMTestCaseID SYSLIB-EZLIB-CT-3426
1.1466 +@SYMTestCaseDesc Testing EZlib decompressor performance after enforcing compiler optimisation
1.1467 +@SYMTestPriority Medium
1.1468 +@SYMTestActions This test uses several typical pieces of compressed
1.1469 + image data as an input and inflates them 10 times.
1.1470 + The total duration of this operation is measured and
1.1471 + compared against a benchmarking limit. Only performed
1.1472 + on UREL builds running on H2 and H4 hardware.
1.1473 +@SYMTestExpectedResults Time spent on decompression should be less than a preset limit.
1.1474 +@SYMREQ REQ7363
1.1475 +*/
1.1476 +
1.1477 +void Test35L()
1.1478 + {
1.1479 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-3426 "));
1.1480 +#if !(defined(__WINSCW__) || defined (_DEBUG))
1.1481 + Test.Printf(_L("\n"));
1.1482 + Test.Printf(KSeparator);
1.1483 + _LIT(KInputFile1, "z:\\test\\png\\compressed_data1");//A small-sized picture with
1.1484 + //transparent background which
1.1485 + //represents typical UI component
1.1486 + //icon.
1.1487 +
1.1488 + _LIT(KInputFile2, "z:\\test\\png\\compressed_data2");//Medium-sized picture with a
1.1489 + //single image typical for a UI
1.1490 + //theme background image
1.1491 +
1.1492 + _LIT(KInputFile3, "z:\\test\\png\\compressed_data3");//Medium-sized picture with
1.1493 + //multiple small images on it
1.1494 + //typical for a sheet of UI
1.1495 + //component skins
1.1496 +
1.1497 + _LIT(KInputFile4, "z:\\test\\png\\compressed_data4");//Large-sized photo image
1.1498 +
1.1499 + RFs rfs;
1.1500 + rfs.Connect();
1.1501 + CleanupClosePushL(rfs);
1.1502 +
1.1503 + // determine media type of C drive
1.1504 + TDriveInfo driveInf;
1.1505 + TInt res = rfs.Drive(driveInf, EDriveC);
1.1506 + Test(res==KErrNone);
1.1507 +
1.1508 + TInt timingLimit1 = 0;
1.1509 + TInt timingLimit2 = 0;
1.1510 + TInt timingLimit3 = 0;
1.1511 + TInt timingLimit4 = 0;
1.1512 + // only check benchmarks if running on hardware, with UREL + RAM build (i.e. not NAND)
1.1513 + if (driveInf.iType == EMediaRam)
1.1514 + {
1.1515 + TInt muid = 0;
1.1516 + res= HAL::Get(HAL::EMachineUid, muid);
1.1517 + Test(res==KErrNone);
1.1518 + switch (muid)
1.1519 + {
1.1520 + case HAL::EMachineUid_OmapH2:
1.1521 + timingLimit1 = 350;
1.1522 + timingLimit2 = 1650;
1.1523 + timingLimit3 = 2900;
1.1524 + timingLimit4 = 2750;
1.1525 + break;
1.1526 + case HAL::EMachineUid_OmapH4:
1.1527 + timingLimit1 = 200;
1.1528 + timingLimit2 = 850;
1.1529 + timingLimit3 = 1400;
1.1530 + timingLimit4 = 1500;
1.1531 + break;
1.1532 + default:
1.1533 + break;
1.1534 + }
1.1535 + }
1.1536 +
1.1537 + DecompressFileL(KInputFile1, rfs, timingLimit1);
1.1538 + DecompressFileL(KInputFile2, rfs, timingLimit2);
1.1539 + DecompressFileL(KInputFile3, rfs, timingLimit3);
1.1540 + DecompressFileL(KInputFile4, rfs, timingLimit4);
1.1541 + CleanupStack::PopAndDestroy();
1.1542 +#else
1.1543 + Test.Printf(_L("This test is only performed on hardware UREL builds\n"));
1.1544 +#endif
1.1545 + }
1.1546 +
1.1547 +/**
1.1548 +@SYMTestCaseID SYSLIB-EZLIB-UT-3684
1.1549 +@SYMTestCaseDesc Test the memory deallocation of the CEZFileBufferManager object to ensure that
1.1550 + there is no memory leak on success or failure of file compression and decompression
1.1551 +@SYMTestPriority High
1.1552 +@SYMTestActions Compressing and Decompressing a png image using CEZCompressor::InflateL() and
1.1553 + CEZDecompressor::DeflateL()
1.1554 +@SYMTestExpectedResults Test must not fail and memory must not leak afterdeallocating CEZFileBufferManager
1.1555 + object (fb)
1.1556 +@SYMDEF DEF109756
1.1557 +*/
1.1558 +void Test36L()
1.1559 + {
1.1560 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-3684 "));
1.1561 + Test.Printf(_L("\n"));
1.1562 + Test.Printf(KSeparator);
1.1563 + //Set the path of input file and output files
1.1564 + #if !defined(__WINS__)
1.1565 + _LIT(KInputFile, "z:\\test\\png\\00000720.png");
1.1566 + #else
1.1567 + _LIT(KInputFile, "c:\\test\\png\\00000720.png");
1.1568 + #endif
1.1569 + _LIT(KOutputFile, "c:\\test\\temp\\00000720.z");
1.1570 + _LIT(KUncompressedFile, "c:\\test\\temp\\000007201");
1.1571 +
1.1572 + RFs rfs;
1.1573 + rfs.Connect();
1.1574 + CleanupClosePushL(rfs);
1.1575 +
1.1576 + TPtrC inputFile(KInputFile);
1.1577 + TPtrC outputFile(KOutputFile);
1.1578 + TPtrC uncompressedFile(KUncompressedFile);
1.1579 +
1.1580 + RFile input;
1.1581 + RFile output;
1.1582 + TInt err;
1.1583 + //Open the PNG file for compressing
1.1584 + User::LeaveIfError(input.Open(rfs, inputFile,EFileStream | EFileRead | EFileShareAny));
1.1585 + CleanupClosePushL(input);
1.1586 +
1.1587 + //Create file to store output of file compressing
1.1588 + err = output.Create(rfs, outputFile,EFileStream | EFileWrite | EFileShareExclusive);
1.1589 + if (err == KErrAlreadyExists)//Just in case if the output file already exists then open it.
1.1590 + User::LeaveIfError(output.Open(rfs, outputFile,EFileStream | EFileWrite | EFileShareExclusive));
1.1591 + else
1.1592 + User::LeaveIfError(err);
1.1593 + CleanupClosePushL(output);
1.1594 +
1.1595 +__UHEAP_MARK;
1.1596 + //Create and assign the CEZFileBufferManager object 'fb' as the compressor's buffer manager
1.1597 + CEZFileBufferManager *fb = CEZFileBufferManager::NewLC(input,output,16384);
1.1598 + CEZCompressor *def = CEZCompressor::NewLC(*fb);
1.1599 +
1.1600 + while (def->DeflateL()){/*do nothing*/}
1.1601 +
1.1602 + CleanupStack::PopAndDestroy(def);
1.1603 + CleanupStack::PopAndDestroy(fb);
1.1604 +__UHEAP_MARKEND;
1.1605 +
1.1606 + CleanupStack::PopAndDestroy(&output);
1.1607 + CleanupStack::PopAndDestroy(&input);
1.1608 + //Now open the compressed file for decompressing
1.1609 + User::LeaveIfError(input.Open(rfs, outputFile,EFileStream | EFileRead | EFileShareAny));
1.1610 + CleanupClosePushL(input);
1.1611 +
1.1612 + //Create file to store output of decompressing
1.1613 + err = output.Create(rfs, uncompressedFile,EFileStream | EFileWrite | EFileShareExclusive);
1.1614 + if (err == KErrAlreadyExists)//Just in case if the output file already exists then open it.
1.1615 + User::LeaveIfError(output.Open(rfs, uncompressedFile,EFileStream | EFileWrite | EFileShareExclusive));
1.1616 + else
1.1617 + User::LeaveIfError(err);
1.1618 +
1.1619 + CleanupClosePushL(output);
1.1620 +
1.1621 +__UHEAP_MARK;
1.1622 + //Create and assign the CEZFileBufferManager object 'fb' as the decompressor's buffer manager
1.1623 + fb = CEZFileBufferManager::NewLC(input,output,16384);
1.1624 + CEZDecompressor *inf = CEZDecompressor::NewLC(*fb);
1.1625 +
1.1626 + while (inf->InflateL()){/*do nothing*/}
1.1627 +
1.1628 + CleanupStack::PopAndDestroy(inf);
1.1629 + CleanupStack::PopAndDestroy(fb);
1.1630 +__UHEAP_MARKEND;
1.1631 + input.Close();
1.1632 + output.Close();
1.1633 +
1.1634 + CleanupStack::PopAndDestroy(&output);
1.1635 + CleanupStack::PopAndDestroy(&input);
1.1636 + CleanupStack::PopAndDestroy(&rfs);
1.1637 + }
1.1638 +
1.1639 +/**
1.1640 +@SYMTestCaseID SYSLIB-EZLIB2-UT-4298
1.1641 +@SYMTestCaseDesc Test CEZZStream functions through CEZCompressor class e.g.
1.1642 + Adler32(), AvailIn(), AvailOut()
1.1643 +@SYMTestPriority High
1.1644 +@SYMTestActions 1. Compress stream of data using CEZCompressor::NewLC() & CEZCompressor::DeflateL()
1.1645 + 2. Call CEZCompressor::Adler32() to get the checksum value of the uncompressed data
1.1646 + 3. Call CEZCompressor::AvailIn() to get the number of bytes available at the next input byte
1.1647 + 4. Call CEZCompressor::AvailOut() to get the remaining free space at next output byte target
1.1648 +@SYMTestExpectedResults The test succeeds with no errors i.e. KErrNone
1.1649 +@SYMDEF REQ8024
1.1650 +*/
1.1651 +
1.1652 +void TestCEZCompressorMethodsL()
1.1653 + {
1.1654 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4298 "));
1.1655 + CBufferManager *bm;
1.1656 + TInt sourceSize;
1.1657 +
1.1658 + sourceSize = sizeof(original);
1.1659 + bm = CBufferManager::NewLC(original,sourceSize,compressed,256,8);
1.1660 + CEZCompressor *compressor = CEZCompressor::NewLC(*bm);
1.1661 +
1.1662 + TInt32 adler32;
1.1663 + TInt availIn;
1.1664 + TInt availOut;
1.1665 +
1.1666 + while(compressor->DeflateL()){/*do nothing*/}
1.1667 +
1.1668 + adler32 = compressor->Adler32();
1.1669 + Test(adler32 > 0);
1.1670 +
1.1671 + availIn = compressor->AvailIn();
1.1672 + Test(availIn == 0);
1.1673 +
1.1674 + availOut = compressor->AvailOut();
1.1675 + Test(availOut > 0);
1.1676 +
1.1677 + CleanupStack::PopAndDestroy(compressor);
1.1678 + CleanupStack::PopAndDestroy(bm);
1.1679 + }
1.1680 +
1.1681 +/**
1.1682 +@SYMTestCaseID SYSLIB-EZLIB2-UT-4300
1.1683 +@SYMTestCaseDesc TTest Zlibapiwrapper.cpp exported API's like inflate,
1.1684 + deflate, compress, decompress
1.1685 +@SYMTestPriority High
1.1686 +@SYMTestActions Call the exported C APIs of Zlibapiwrapper.cpp
1.1687 + Note: This is done to check if the C APIs of zlib.lib
1.1688 + are called through ezlib.lib.
1.1689 +@SYMTestExpectedResults All exported C API's should be called (i.e. run a basic scenario
1.1690 + of compressing some data) & test must not fail
1.1691 +@SYMDEF REQ8024
1.1692 +*/
1.1693 +
1.1694 +void TestZlibapiwrapperAPIL()
1.1695 + {
1.1696 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4300 "));
1.1697 + z_stream deflateStream;
1.1698 + const char inputData[] = "inputData!"; // data to compress
1.1699 + uLong inputDataLength = (uLong)sizeof(inputData) + 1;
1.1700 + Byte *compressedDataBuffer; // output buffer
1.1701 + //The buffer size is kept as 50 but incase the input data is changed..
1.1702 + //...the buffer size also has to be increased accordingly
1.1703 + TInt compressedDataBufferLength = 50;
1.1704 +
1.1705 + // Allocate memory for output buffer
1.1706 + compressedDataBuffer = (Byte*)User::AllocZ(compressedDataBufferLength);
1.1707 + Test(compressedDataBuffer != Z_NULL);
1.1708 + CleanupStack::PushL(compressedDataBuffer);
1.1709 +
1.1710 + // Initialise the stream
1.1711 + deflateStream.zalloc = (alloc_func)0;
1.1712 + deflateStream.zfree = (free_func)0;
1.1713 + deflateStream.opaque = (voidpf)0;
1.1714 +
1.1715 + int level = Z_DEFAULT_COMPRESSION;
1.1716 + int err = 0;
1.1717 + int flush = 0;
1.1718 +
1.1719 + err = deflateInit(&deflateStream, level);
1.1720 +
1.1721 + if(err != Z_OK)
1.1722 + {
1.1723 + deflateEnd(&deflateStream);
1.1724 + Test(err == Z_OK);
1.1725 + }
1.1726 +
1.1727 +
1.1728 + // Compress data in the input buffer
1.1729 + deflateStream.next_in = (Byte*)inputData;
1.1730 + deflateStream.next_out = compressedDataBuffer;
1.1731 +
1.1732 + do
1.1733 + {
1.1734 + if (deflateStream.total_in < inputDataLength)
1.1735 + {
1.1736 + deflateStream.avail_in = 1; // force small buffer
1.1737 + }
1.1738 +
1.1739 + flush = (deflateStream.total_in == inputDataLength) ? Z_FINISH : Z_NO_FLUSH;
1.1740 +
1.1741 + // run deflate() on input until output buffer not full, finish
1.1742 + // compression if all of source has been read in
1.1743 + do
1.1744 + {
1.1745 + if (deflateStream.total_out < compressedDataBufferLength)
1.1746 + {
1.1747 + deflateStream.avail_out = 1; // force small buffer
1.1748 + }
1.1749 +
1.1750 + err = deflate(&deflateStream, flush);
1.1751 + if(err != Z_OK && err != Z_STREAM_END)
1.1752 + {
1.1753 + deflateEnd(&deflateStream);
1.1754 + Test(err == Z_OK || err == Z_STREAM_END);
1.1755 + }
1.1756 + } while(deflateStream.avail_out == 0 && err == Z_OK);
1.1757 + } while(err != Z_STREAM_END);
1.1758 +
1.1759 + deflateEnd(&deflateStream);
1.1760 + CleanupStack::PopAndDestroy(compressedDataBuffer);
1.1761 +
1.1762 + }
1.1763 +
1.1764 +/**
1.1765 +@SYMTestCaseID SYSLIB-EZLIB-UT-4001
1.1766 +@SYMTestCaseDesc Test for DEF112672 - Panic ZLIB 11 - when installing the sisx file.
1.1767 + The test attempts to decompress a buffer with the "Dictionary" flag set
1.1768 + but with NULL dictionary buffer. The test should not cause an assert in the EZLib library.
1.1769 +@SYMTestPriority Normal
1.1770 +@SYMTestActions Test for DEF112672 - Panic ZLIB 11 - when installing the sisx file.
1.1771 +@SYMTestExpectedResults Test must not fail
1.1772 +@SYMDEF DEF112672
1.1773 +*/
1.1774 +
1.1775 +void DEF112672L()
1.1776 + {
1.1777 + Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-UT-4001 "));
1.1778 + TTestFlags flags(TTestFlags::Dictionary, 8);
1.1779 + flags.iDictionary.Set(dictionary, sizeof(dictionary));
1.1780 + CompressBufferL(flags);
1.1781 + flags.iDictionary.Set(0, 0);
1.1782 + TRAPD(err, DecompressBufferL(flags));
1.1783 + Test(err == KEZlibErrData);
1.1784 + }
1.1785 +
1.1786 +void RunTestL()
1.1787 + {
1.1788 + for (TInt testNum=1; testNum<KNumberOfTests; testNum++)
1.1789 + {
1.1790 + __UHEAP_MARK;
1.1791 + _LIT(KTestNum,"\n\nRunning Test %d\n\n");
1.1792 + TBuf<80> buf;
1.1793 + buf.Format(KTestNum, testNum);
1.1794 + Test.Next(buf);
1.1795 + _LIT(KStrMsg,"%S");
1.1796 + Test.Printf(KStrMsg, testTable[testNum].iDescription);
1.1797 + testTable[testNum].iFn();
1.1798 + __UHEAP_MARKEND;
1.1799 + }
1.1800 + DEF112672L();
1.1801 + }
1.1802 +
1.1803 +GLDEF_C TInt E32Main()
1.1804 + {
1.1805 + CTrapCleanup* cleanup=CTrapCleanup::New();
1.1806 + Test.Title();
1.1807 + _LIT(KStartMsg,"Starting Tests..");
1.1808 + Test.Start(KStartMsg);
1.1809 +__UHEAP_MARK;
1.1810 + TRAPD(err,RunTestL());
1.1811 + Test (err==KErrNone);
1.1812 + Test.End();
1.1813 + Test.Close();
1.1814 +__UHEAP_MARKEND;
1.1815 + delete cleanup;
1.1816 + return KErrNone;
1.1817 + }