os/ossrv/compressionlibs/ziplib/test/rtest/ezlibtest/ezlibtest.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <e32test.h>
    17 #include <bacline.h>
    18 
    19 #include <ezcompressor.h>
    20 #include <ezdecompressor.h>
    21 #include <ezfilebuffer.h>
    22 #include <ezlib.h>
    23 #include <hal.h>
    24 
    25 
    26 _LIT(KSeparator,"----------------------------------------------------------------\n");
    27 
    28 const TInt KNumberOfTests = 38;
    29 _LIT(KTest1,"Multistep compression & decompression using buffers smaller than source & destination");
    30 _LIT(KTest2,"Multistep compression & decompression using buffers larger than source & destination");
    31 _LIT(KTest3,"Test Multistep compression when NeedInput provides no input");
    32 _LIT(KTest4,"Test Multistep compression when NeedOutput provides no output");
    33 _LIT(KTest5,"Perform multistep compression 2 with the same CEZCompressor, reseting it\n\
    34 	 after the first compression.");
    35 _LIT(KTest6,"Perform multistep compression 2 with the same CEZCompressor, without reseting it\n\
    36 	 after the first compression.");
    37 _LIT(KTest7,"Performs multistep compression & decompression using a preset dicitonary.");
    38 _LIT(KTest8,"Performs multistep compression with compression level of 0.");
    39 _LIT(KTest9,"Performs multistep compression with compression level of 9.");
    40 _LIT(KTest10,"Performs multistep compression with invalid compression level.");
    41 _LIT(KTest11,"Performs multistep compression with window bits of 8.");
    42 _LIT(KTest12,"Performs multistep compression with an invalid value for window bits.");
    43 _LIT(KTest13,"Performs multistep compression with memory level = 1.");
    44 _LIT(KTest14,"Performs multistep compression with an invalid memory level.");
    45 _LIT(KTest15,"Performs multistep compression using only Huffman encoding.");
    46 _LIT(KTest16,"Performs multistep compression using Filtered strategy.");
    47 _LIT(KTest17,"Performs multistep compression when Alloc fails randomly.");
    48 _LIT(KTest18,"Test Multistep decompression when NeedInput provides no input.");
    49 _LIT(KTest19,"Test Multistep decompression when NeedOutput provides no output.");
    50 _LIT(KTest20,"Test Multistep decompression when compressed stream is corrupt.");
    51 _LIT(KTest21,"Test Multistep decompressor construction when Alloc fails randomly.");
    52 _LIT(KTest22,"Test Multistep decompression when Alloc fails randomly.");
    53 _LIT(KTest23,"Test Multistep decompression when a dictionary is required and not provided.\n\
    54 	 This test should panic.");
    55 _LIT(KTest24,"Test Multistep decompression when a dictionary when the wrong dictionary is provided.");
    56 _LIT(KTest25,"Perform multistep decompression twice with the same CEZDecompressor, reseting it\n\
    57 	 after the first decompression.");
    58 _LIT(KTest26,"Perform multistep decompression twice with the same CEZDecompressor, reseting it\n\
    59 	 after the first decompression.");
    60 _LIT(KTest27,"Perform multistep compression and decompression on unicode data.");
    61 _LIT(KTest28,"Perform multistep compression and decompression on unicode data using a unicode dictionary.");
    62 _LIT(KTest29,"Perform multistep compression and decompression on unicode data using an ascii dictionary.");
    63 _LIT(KTest30,"Test percentage of completion during multistep compression/decompression.");
    64 _LIT(KTest31,"Test single step compression and decompression.");
    65 _LIT(KTest32,"Test single step compression when indaquate output buffer is provided.");
    66 _LIT(KTest33,"Test single step decompression when indaquate output buffer is provided.");
    67 _LIT(KTest34,"Testing graceful exit for zlib 1.1.3 decompression bug. See: INC022729.");
    68 _LIT(KTest35,"Testing EZlib decompression performance with enforced compiler optimisation");
    69 _LIT(KTest36,"Testing correct memory deallocation for CEZFileBufferManager. See: DEF109756.");
    70 _LIT(KTest37,"Test CEZZStream functions through CEZCompressor class.");
    71 _LIT(KTest38,"Test Calls to Zlibapiwrapper.cpp exported API's like inflate, deflate, compress, decompress");
    72 
    73 const TPtrC KTest1Des(KTest1);
    74 const TPtrC KTest2Des(KTest2);
    75 const TPtrC KTest3Des(KTest3);
    76 const TPtrC KTest4Des(KTest4);
    77 const TPtrC KTest5Des(KTest5);
    78 const TPtrC KTest6Des(KTest6);
    79 const TPtrC KTest7Des(KTest7);
    80 const TPtrC KTest8Des(KTest8);
    81 const TPtrC KTest9Des(KTest9);
    82 const TPtrC KTest10Des(KTest10);
    83 const TPtrC KTest11Des(KTest11);
    84 const TPtrC KTest12Des(KTest12);
    85 const TPtrC KTest13Des(KTest13);
    86 const TPtrC KTest14Des(KTest14);
    87 const TPtrC KTest15Des(KTest15);
    88 const TPtrC KTest16Des(KTest16);
    89 const TPtrC KTest17Des(KTest17);
    90 const TPtrC KTest18Des(KTest18);
    91 const TPtrC KTest19Des(KTest19);
    92 const TPtrC KTest20Des(KTest20);
    93 const TPtrC KTest21Des(KTest21);
    94 const TPtrC KTest22Des(KTest22);
    95 const TPtrC KTest23Des(KTest23);
    96 const TPtrC KTest24Des(KTest24);
    97 const TPtrC KTest25Des(KTest25);
    98 const TPtrC KTest26Des(KTest26);
    99 const TPtrC KTest27Des(KTest27);
   100 const TPtrC KTest28Des(KTest28);
   101 const TPtrC KTest29Des(KTest29);
   102 const TPtrC KTest30Des(KTest30);
   103 const TPtrC KTest31Des(KTest31);
   104 const TPtrC KTest32Des(KTest32);
   105 const TPtrC KTest33Des(KTest33);
   106 const TPtrC KTest34Des(KTest34);
   107 const TPtrC KTest35Des(KTest35);
   108 const TPtrC KTest36Des(KTest36);
   109 const TPtrC KTest37Des(KTest37);
   110 const TPtrC KTest38Des(KTest38);
   111 
   112 void Test1L();
   113 void Test2L();
   114 void Test3();
   115 void Test4();
   116 void Test5L();
   117 void Test6();
   118 void Test7L();
   119 void Test8L();
   120 void Test9L();
   121 void Test10();
   122 void Test11();
   123 void Test12();
   124 void Test13L();
   125 void Test14();
   126 void Test15L();
   127 void Test16L();
   128 void Test17();
   129 void Test18L();
   130 void Test19L();
   131 void Test20L();
   132 void Test21L();
   133 void Test22L();
   134 void Test23();
   135 void Test24L();
   136 void Test25L();
   137 void Test26L();
   138 void Test27L();
   139 void Test28L();
   140 void Test29L();
   141 void Test30L();
   142 void Test31L();
   143 void Test32();
   144 void Test33L();
   145 void Test34L();
   146 void Test35L();
   147 void Test36L();
   148 void TestCEZCompressorMethodsL();
   149 void TestZlibapiwrapperAPIL();
   150 
   151 typedef void (*TestPtr)();
   152 
   153 struct TTests
   154 	{
   155 	TestPtr iFn;
   156 	const TPtrC *iDescription;
   157 	};
   158 
   159 const TTests testTable[] = {
   160 	{Test1L,&KTest1Des},
   161 	{Test2L,&KTest2Des},
   162 	{Test3,&KTest3Des},
   163 	{Test4,&KTest4Des},
   164 	{Test5L,&KTest5Des},
   165 	{Test6,&KTest6Des},
   166 	{Test7L,&KTest7Des},
   167 	{Test8L,&KTest8Des},
   168 	{Test9L,&KTest9Des},
   169 	{Test10,&KTest10Des},
   170 	{Test11,&KTest11Des},
   171 	{Test12,&KTest12Des},
   172 	{Test13L,&KTest13Des},
   173 	{Test14,&KTest14Des},
   174 	{Test15L,&KTest15Des},
   175 	{Test16L,&KTest16Des},
   176 	{Test17,&KTest17Des},
   177 	{Test18L,&KTest18Des},
   178 	{Test19L,&KTest19Des},
   179 	{Test20L,&KTest20Des},
   180 	{Test21L,&KTest21Des},
   181 	{Test22L,&KTest22Des},
   182 	{Test23,&KTest23Des},
   183 	{Test24L,&KTest24Des},
   184 	{Test25L,&KTest25Des},
   185 	{Test26L,&KTest26Des},
   186 	{Test27L,&KTest27Des},
   187 	{Test28L,&KTest28Des},
   188 	{Test29L,&KTest29Des},
   189 	{Test30L,&KTest30Des},
   190 	{Test31L,&KTest31Des},
   191 	{Test32,&KTest32Des},
   192 	{Test33L,&KTest33Des},
   193 	{Test34L,&KTest34Des},
   194 	{Test35L,&KTest35Des},
   195 	{Test36L,&KTest36Des},
   196 	{TestCEZCompressorMethodsL, &KTest37Des},
   197 	{TestZlibapiwrapperAPIL, &KTest38Des}
   198 	};
   199 
   200 struct TTestFlags
   201 	{
   202 	enum 
   203 		{ 
   204 		FakeNoInput = 16,
   205 		FakeNoOutput = 32,
   206 		Dictionary = 64,
   207 		AllocFail = 128,
   208 		Corrupt = 256,
   209 		AllocFailInflate = 512,
   210 		Unicode = 1024,
   211 		Percent = 2048
   212 		};
   213 
   214 
   215 	TTestFlags() : iFlags(0), iBufferSize(0) { Defaults(); }
   216 	TTestFlags(TInt aFlags, TInt aBufferSize) : iFlags(aFlags), iBufferSize(aBufferSize) { Defaults(); }
   217 	void Defaults();
   218 
   219 	TInt iFlags;
   220 	TInt iBufferSize;
   221 	TPtrC8 iDictionary;
   222 	TInt iLevel;
   223 	TInt iWindowBits;
   224 	TInt iMemLevel;
   225 	CEZCompressor::TStrategy iStrategy;
   226 	};
   227 
   228 
   229 void TTestFlags::Defaults()
   230 	{
   231 	iLevel = CEZCompressor::EDefaultCompression;
   232 	iWindowBits = CEZCompressor::EMaxWBits;
   233 	iMemLevel = CEZCompressor::EDefMemLevel;
   234 	iStrategy = CEZCompressor::EDefaultStrategy;
   235 	}
   236 	
   237 TReal FastCountToMilliseconds(TInt aFastCount)
   238    {
   239    TInt freqInHz;
   240    HAL::Get(HAL::EFastCounterFrequency, freqInHz);
   241    TReal freqInkHz = freqInHz / 1000;
   242    return (TReal)aFastCount / freqInkHz;
   243    }
   244     
   245 
   246 static RTest Test(_L("EZLIB"));
   247 
   248 static TUint8 original[] = "compression is a constant source of depression and depression leads to multiple regressions in succession";
   249 static TUint8 dictionary[] = "constant source multiple leads compression ";
   250 static TUint8 badDictionary[] = "I'm not the dictionary";
   251 static TUint8 compressed[256];
   252 static TInt compressedSize; // length of compressed data in compressed.
   253 static TUint8 uncompressed[256];
   254 static TText output[256];
   255 static TText originalU[256];
   256 static TText dictionaryU[256];
   257 
   258 static void RunTestL();
   259 
   260 static void CompressBufferL(const TTestFlags &aFlags, RTest &aTest=Test);
   261 static void DecompressBufferL(const TTestFlags &aFlags, RTest &aTest=Test);
   262 static void DblDecompressBufferL(TInt aBufferSize, TBool aReset);
   263 static void CompressDecompressL(const TTestFlags &aFlags);
   264 static void DblCompressBufferL(TInt aBufferSize, TBool aReset = EFalse);
   265 
   266 class CBufferManager : public CBase, public MEZBufferManager
   267 	{
   268 public:
   269 	~CBufferManager();
   270 
   271 	static CBufferManager *NewLC(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength, TInt aBufferSize);
   272 	static CBufferManager *NewL(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength, TInt aBufferSize);
   273 
   274 	void InitializeL(CEZZStream &aZStream);
   275 	void NeedInputL(CEZZStream &aZStream);
   276 	void NeedOutputL(CEZZStream &aZStream);
   277 	void FinalizeL(CEZZStream &aZStream);
   278 
   279 	void FakeNoInput() { iFakeNoInput = ETrue; }
   280 	void FakeNoOutput() { iFakeNoOutput = ETrue; }
   281 
   282 private:
   283 	CBufferManager(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength);
   284 	void ConstructL(TInt aBufferSize);
   285 
   286 private:
   287 	TUint8 *iInput, *iOutput;
   288 	TUint8 *iInputBuffer, *iOutputBuffer;
   289 	TInt iBufferSize;
   290 	TInt iOutputLength, iInputLength;
   291 	TPtr8 iInputDescriptor;
   292 	TPtr8 iOutputDescriptor;
   293 	TBool iFakeNoInput;
   294 	TBool iFakeNoOutput;
   295 	};
   296 
   297 CBufferManager::CBufferManager(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength)
   298 	:	iInput(aInput), 
   299 		iOutput(aOutput), 
   300 		iOutputLength(aOutputLength), 
   301 		iInputLength(aInputLength),
   302 		iInputDescriptor(NULL,0), 
   303 		iOutputDescriptor(NULL,0), 
   304 		iFakeNoInput(EFalse), 
   305 		iFakeNoOutput(EFalse)
   306 	{
   307 
   308 	}
   309 
   310 CBufferManager::~CBufferManager()
   311 	{
   312 	delete[] iInputBuffer;
   313 	delete[] iOutputBuffer;
   314 	}
   315 
   316 CBufferManager *CBufferManager::NewLC(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength, TInt aBufferSize)
   317 	{
   318 	CBufferManager *bm = new (ELeave) CBufferManager(aInput,aInputLength,aOutput,aOutputLength);
   319 	CleanupStack::PushL(bm);
   320 	bm->ConstructL(aBufferSize);
   321 	return bm;
   322 	}
   323 
   324 CBufferManager *CBufferManager::NewL(TUint8 *aInput, TInt aInputLength, TUint8 *aOutput, TInt aOutputLength, TInt aBufferSize)
   325 	{
   326 	CBufferManager *bm = new (ELeave) CBufferManager(aInput,aInputLength,aOutput,aOutputLength);
   327 	CleanupStack::PushL(bm);
   328 	bm->ConstructL(aBufferSize);
   329 	CleanupStack::Pop();
   330 	return bm;
   331 	}
   332 
   333 void CBufferManager::ConstructL(TInt aBufferSize)
   334 	{
   335 	iBufferSize = aBufferSize;
   336 	iInputBuffer = new (ELeave) TUint8[iBufferSize];
   337 	iOutputBuffer = new (ELeave) TUint8[iBufferSize];
   338 
   339 	}
   340 	
   341 void CBufferManager::InitializeL(CEZZStream &aZStream)
   342 	{
   343 	TInt remaining = iInputLength;
   344 	if (remaining > iBufferSize)
   345 		remaining = iBufferSize;
   346 	Mem::Copy(iInputBuffer,iInput,remaining);
   347 	iInputDescriptor.Set(iInputBuffer,remaining,iBufferSize);
   348 	aZStream.SetInput(iInputDescriptor);
   349 	iOutputDescriptor.Set(iOutputBuffer,0,iBufferSize);
   350 	aZStream.SetOutput(iOutputDescriptor);
   351 	iInput += remaining;
   352 	}
   353 
   354 void CBufferManager::NeedInputL(CEZZStream &aZStream)
   355 	{
   356 	TInt remaining;
   357 	if (iFakeNoInput)
   358 		remaining = 0;
   359 	else
   360 		{
   361 		remaining = iInputLength - aZStream.TotalIn();
   362 		if (remaining > iBufferSize)
   363 			remaining = iBufferSize;
   364 		Mem::Copy(iInputBuffer,iInput,remaining);
   365 		}
   366 	iInputDescriptor.Set(iInputBuffer,remaining,iBufferSize);
   367 	aZStream.SetInput(iInputDescriptor);
   368 	iInput += remaining;
   369 	}
   370 	
   371 
   372 void CBufferManager::NeedOutputL(CEZZStream &aZStream)
   373 	{
   374 	TInt remaining;
   375 	if (iFakeNoOutput)
   376 		{
   377 		remaining = 0;
   378 		iOutputDescriptor.Set(iOutputBuffer,remaining,remaining);
   379 		}
   380 	else
   381 		{
   382 		remaining = iOutputLength - aZStream.TotalOut();
   383 		if (remaining > iBufferSize)
   384 			remaining = iBufferSize;
   385 		}
   386 	TPtrC8 od = aZStream.OutputDescriptor();
   387 	Mem::Copy(iOutput,iOutputBuffer,od.Size());
   388 	aZStream.SetOutput(iOutputDescriptor);
   389 	iOutput += iBufferSize;
   390 	}
   391 
   392 void CBufferManager::FinalizeL(CEZZStream &aZStream)
   393 	{
   394 	TInt copy = aZStream.OutputDescriptor().Size();
   395 	
   396 	if (copy > 0)
   397 		Mem::Copy(iOutput,iOutputBuffer,copy);
   398 	}
   399 
   400 /**
   401 @SYMTestCaseID          SYSLIB-EZLIB-CT-1328
   402 @SYMTestCaseDesc	    Decompression of stream test
   403 @SYMTestPriority 	    High
   404 @SYMTestActions  	    Compresses and decompresses a buffer and tests to see whether the orginal and decompression streams
   405 						are the same.
   406 @SYMTestExpectedResults The test must not fail.
   407 @SYMREQ                 REQ0000
   408 */
   409 
   410 static void CompressDecompressL(const TTestFlags &aFlags)
   411 	{
   412 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-1328 "));
   413 	CompressBufferL(aFlags);
   414 	DecompressBufferL(aFlags);
   415 		
   416 	if (aFlags.iFlags & TTestFlags::Unicode)
   417 		{
   418 		TPtr s1(REINTERPRET_CAST(TText *, original),sizeof(original));
   419 		TPtr s2(REINTERPRET_CAST(TText *, uncompressed),sizeof(original));
   420 		Test(s1.Compare(s2) == 0,__LINE__);
   421 		}
   422 	else
   423 		{
   424 		TPtrC8 s1(original);
   425 		TPtrC8 s2(uncompressed);
   426 		Test(s1.Compare(s2) == 0,__LINE__);
   427 		}
   428 	}
   429 
   430 // Compresses the data in original and places it into compressed.
   431 
   432 //Need to pass in RTest object as this function is called by a seperate thread sometimes
   433 static void CompressBufferL(const TTestFlags &aFlags, RTest &aTest)
   434 	{
   435 	_LIT(KMsg,"\nTesting multi-step compresssion with buffer size %d\n");
   436 	aTest.Printf(KMsg,aFlags.iBufferSize);
   437 	aTest.Printf(KSeparator);
   438 	CBufferManager *bm;
   439 	TInt sourceSize;
   440 	
   441 	if (aFlags.iFlags & TTestFlags::Unicode)
   442 		{
   443 		sourceSize =  sizeof(original) * sizeof(TText);
   444 		bm = CBufferManager::NewLC(REINTERPRET_CAST(TUint8*,originalU),sourceSize,compressed,256,aFlags.iBufferSize);
   445 		}
   446 	else
   447 		{
   448 		sourceSize = sizeof(original);
   449 		bm = CBufferManager::NewLC(original,sourceSize,compressed,256,aFlags.iBufferSize);
   450 		}
   451 		
   452 
   453 	if (aFlags.iFlags & TTestFlags::FakeNoInput)
   454 		bm->FakeNoInput();
   455 	if (aFlags.iFlags & TTestFlags::FakeNoOutput)
   456 		bm->FakeNoOutput();
   457 	CEZCompressor *def;
   458 
   459 #if defined(_DEBUG) && defined(__WINS__)
   460 	if (aFlags.iFlags & TTestFlags::AllocFail)
   461 		__UHEAP_SETFAIL(RHeap::ETrueRandom,5);
   462 #endif
   463 
   464 	if (aFlags.iFlags & TTestFlags::Dictionary)
   465 		def = CEZCompressor::NewLC(*bm,aFlags.iDictionary,aFlags.iLevel,aFlags.iWindowBits,
   466 			aFlags.iMemLevel,aFlags.iStrategy);
   467 	else
   468 		def= CEZCompressor::NewLC(*bm,aFlags.iLevel,aFlags.iWindowBits,aFlags.iMemLevel,
   469 			aFlags.iStrategy);
   470 
   471 	while (def->DeflateL())
   472 		{
   473 		if (aFlags.iFlags & TTestFlags::Percent)
   474 			{
   475 			_LIT(KPer,"%d ");
   476 			aTest.Printf(KPer,def->Progress(sourceSize));
   477 			}
   478 		}
   479 	if (aFlags.iFlags & TTestFlags::Percent)
   480 		aTest.Printf(_L("\n"));
   481 
   482 	compressedSize = def->TotalOut();
   483 	_LIT(KUnMsg,"Uncompressed Size %d\n");
   484 	_LIT(KComMsg,"Compressed Size %d\n");
   485 
   486 	if (aFlags.iFlags & TTestFlags::Corrupt)
   487 		compressed[compressedSize >> 1] = 1;
   488 
   489 	aTest.Printf(KUnMsg,def->TotalIn());
   490 	aTest.Printf(KComMsg,compressedSize);
   491 	CleanupStack::PopAndDestroy(2);
   492 	}
   493 
   494 // Decompresses data stored in compressed and writes it to uncompressed.
   495 
   496 //Need to pass in RTest object as this function is called by a seperate thread sometimes
   497 static void DecompressBufferL(const TTestFlags &aFlags, RTest &aTest)
   498     {
   499 	_LIT(KMsg,"\nTesting multi-step decompresssion with buffer size %d\n");
   500 	aTest.Printf(KMsg,aFlags.iBufferSize);
   501 	aTest.Printf(KSeparator);
   502 	CBufferManager *bm = CBufferManager::NewLC(compressed,compressedSize,uncompressed,256,aFlags.iBufferSize);
   503 	
   504 	if (aFlags.iFlags & TTestFlags::FakeNoInput)
   505 		bm->FakeNoInput();
   506 	if (aFlags.iFlags & TTestFlags::FakeNoOutput)
   507 		bm->FakeNoOutput();
   508 
   509 #if defined(_DEBUG) && defined(__WINS__)
   510 	if (aFlags.iFlags & TTestFlags::AllocFail)
   511 		__UHEAP_SETFAIL(RHeap::ETrueRandom,10);
   512 #endif
   513 
   514 	CEZDecompressor *in;
   515 	if (aFlags.iFlags & TTestFlags::Dictionary)
   516 		in = CEZDecompressor::NewLC(*bm,aFlags.iDictionary);
   517 	else
   518 		in = CEZDecompressor::NewLC(*bm);
   519 
   520 #if defined(_DEBUG) && defined(__WINS__)
   521 	if (aFlags.iFlags & TTestFlags::AllocFailInflate)
   522 		__UHEAP_SETFAIL(RHeap::ETrueRandom,10);
   523 #endif
   524 
   525 	while (in->InflateL())
   526 		{
   527 		if (aFlags.iFlags & TTestFlags::Percent)
   528 			{
   529 			_LIT(KPer,"%d ");
   530 			aTest.Printf(KPer,in->Progress(compressedSize));
   531 			}
   532 		}
   533 	if (aFlags.iFlags & TTestFlags::Percent)
   534 		aTest.Printf(_L("\n"));
   535 
   536 
   537 	if (aFlags.iFlags & TTestFlags::Unicode)
   538 		{
   539 		TPtrC ptr(REINTERPRET_CAST(TText *,uncompressed),in->TotalOut() / sizeof(TText)); 
   540 		aTest.Printf(ptr);
   541 		aTest.Printf(_L("\n"));
   542 		}
   543 		else
   544 		{
   545 		TPtrC8 ptr8(uncompressed);
   546 		TPtr ptr16(output,256);
   547 		ptr16.Copy(ptr8);
   548 		aTest.Printf(ptr16);
   549 		aTest.Printf(_L("\n"));
   550 		}
   551 	CleanupStack::PopAndDestroy(2);
   552 	}
   553 
   554 static void DblCompressBufferL(TInt aBufferSize, TBool aReset)
   555 	{
   556 	CEZCompressor *def = NULL;
   557 
   558 	_LIT(KMsg,"\nTesting multi-step compresssion with buffer size %d\n");
   559 	_LIT(KUnMsg,"Uncompressed Size %d\n");
   560 	_LIT(KComMsg,"Compressed Size %d\n");
   561 
   562 	Test.Printf(KMsg,aBufferSize);
   563 	Test.Printf(KSeparator,aBufferSize);
   564 	CBufferManager *bm = CBufferManager::NewLC(original,sizeof(original),compressed,256,aBufferSize);
   565 	def = CEZCompressor::NewLC(*bm);
   566 			
   567 	while (def->DeflateL()){}
   568 		
   569 	compressedSize = def->TotalOut();
   570 	Test.Printf(KUnMsg,sizeof(original));
   571 	Test.Printf(KComMsg,compressedSize);
   572 
   573 	CleanupStack::Pop();
   574 	CleanupStack::PopAndDestroy();
   575 	CleanupStack::PushL(def);
   576 
   577 	if (aReset)
   578 		{
   579 		bm = CBufferManager::NewLC(original,sizeof(original),compressed,256,aBufferSize);
   580 		def->ResetL(*bm);
   581 		}
   582 
   583 	Test.Printf(KMsg,aBufferSize);
   584 	Test.Printf(KSeparator,aBufferSize);
   585 	
   586 	while (def->DeflateL()){}
   587 		
   588 	compressedSize = def->TotalOut();
   589 	Test.Printf(KUnMsg,sizeof(original));
   590 	Test.Printf(KComMsg,compressedSize);
   591 
   592 	CleanupStack::PopAndDestroy(2);
   593 	}
   594 
   595 static void DblDecompressBufferL(TInt aBufferSize, TBool aReset)
   596 	{
   597 	CEZDecompressor *def = NULL;
   598 
   599 	_LIT(KMsg,"\nTesting multi-step decompresssion with buffer size %d\n");
   600 	Test.Printf(KMsg,aBufferSize);
   601 	Test.Printf(KSeparator);
   602 	CBufferManager *bm = CBufferManager::NewLC(compressed,compressedSize,uncompressed,256,aBufferSize);
   603 	def = CEZDecompressor::NewLC(*bm);
   604 			
   605 	while (def->InflateL()){}
   606 		
   607 	CleanupStack::Pop();
   608 	CleanupStack::PopAndDestroy();
   609 	CleanupStack::PushL(def);
   610 
   611 	if (aReset)
   612 		{
   613 		bm = CBufferManager::NewLC(compressed,compressedSize,uncompressed,256,aBufferSize);
   614 		def->ResetL(*bm);
   615 		}
   616 
   617 	Test.Printf(KMsg,aBufferSize);
   618 	Test.Printf(KSeparator,aBufferSize);
   619 	
   620 	while (def->InflateL()){}
   621 		
   622 	TPtrC8 ptr8(uncompressed);
   623 	TPtr ptr16(output,256);
   624 	ptr16.Copy(ptr8);
   625 	Test.Printf(ptr16);
   626 	Test.Printf(_L("\n"));
   627 
   628 	CleanupStack::PopAndDestroy(2);
   629 	}
   630 
   631 /**
   632 @SYMTestCaseID          SYSLIB-EZLIB-CT-0785
   633 @SYMTestCaseDesc	    Multistep compression & decompression test using buffers smaller than source & destination 
   634 @SYMTestPriority 	    High
   635 @SYMTestActions  	    Set the test flags to 0,buffersize to 8
   636 @SYMTestExpectedResults The test must not fail.
   637 @SYMREQ                 REQ0000
   638 */
   639 
   640 void Test1L()
   641 	{
   642 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0785 "));
   643 	TTestFlags flags(0,8);
   644 	CompressDecompressL(flags);
   645 	}
   646 
   647 /**
   648 @SYMTestCaseID          SYSLIB-EZLIB-CT-0786
   649 @SYMTestCaseDesc	    Multistep compression & decompression test using buffers larger than source & destination 
   650 @SYMTestPriority 	    High
   651 @SYMTestActions  	    Set the test flags to 0,buffersize to 1024
   652 @SYMTestExpectedResults The test must not fail.
   653 @SYMREQ                 REQ0000
   654 */
   655 
   656 void Test2L()
   657 	{
   658 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0786 "));
   659 	TTestFlags flags(0,1024);
   660 	CompressDecompressL(flags);
   661 	}
   662 
   663 /**
   664 @SYMTestCaseID          SYSLIB-EZLIB-CT-0787
   665 @SYMTestCaseDesc	    Multistep compression test
   666 @SYMTestPriority 	    High
   667 @SYMTestActions  	    Set the test flags to TTestFlags::FakeNoInput,buffersize to 8
   668 @SYMTestExpectedResults The test must not fail.
   669 @SYMREQ                 REQ0000
   670 */
   671 
   672 void Test3()
   673 	{
   674 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0787 "));
   675 	TTestFlags flags(TTestFlags::FakeNoInput,8);
   676 
   677 	TRAPD(err,CompressBufferL(flags));
   678 	Test (err==KErrNone);  // This test should succeed as providing no Input is a valid thing for
   679 						   // NeedInputL to do.
   680 	}
   681 
   682 /**
   683 @SYMTestCaseID          SYSLIB-EZLIB-CT-0788
   684 @SYMTestCaseDesc	    Multistep compression test when NeedOutput provides no output
   685 @SYMTestPriority 	    High
   686 @SYMTestActions  	    Set the test flags to TTestFlags::FakeNoOutput,buffersize to 8
   687                         Check for buffer error.
   688 @SYMTestExpectedResults The test must not fail.
   689 @SYMREQ                 REQ0000
   690 */
   691 
   692 void Test4()
   693 	{
   694 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0788 "));
   695 	TTestFlags flags(TTestFlags::FakeNoOutput,8);
   696 
   697 	TRAPD(err,CompressBufferL(flags));
   698 	Test (err==KEZlibErrBuf);  
   699 	}
   700 
   701 /**
   702 @SYMTestCaseID          SYSLIB-EZLIB-CT-0789
   703 @SYMTestCaseDesc	    Multistep compression test with the same CEZCompressor,
   704                         resetting it after the first compression 
   705 @SYMTestPriority 	    High
   706 @SYMTestActions  	    Set the buffersize to 8,reset value to true 
   707 @SYMTestExpectedResults The test must not fail.
   708 @SYMREQ                 REQ0000
   709 */
   710 
   711 void Test5L()
   712 	{
   713 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0789 "));
   714 	DblCompressBufferL(8,ETrue);
   715 	}
   716 
   717 /**
   718 @SYMTestCaseID          SYSLIB-EZLIB-CT-0790
   719 @SYMTestCaseDesc	    Multistep compression test with the same CEZCompressor,
   720                         without resetting it after the first compression 
   721 @SYMTestPriority 	    High
   722 @SYMTestActions  	    Set the buffersize to 8,reset value to false 
   723 @SYMTestExpectedResults The test must not fail.
   724 @SYMREQ                 REQ0000
   725 */
   726 
   727 void Test6()
   728 	{
   729 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0790 "));
   730 	//Calling compress twice without reseting (ie passing in EFalse) causes leave
   731 	TRAPD(err,DblCompressBufferL(8,EFalse));
   732 	Test (err==KEZlibErrDeflateTerminated); 
   733 	}
   734 
   735 /**
   736 @SYMTestCaseID          SYSLIB-EZLIB-CT-0791
   737 @SYMTestCaseDesc	    Multistep compression & decompression test using a preset dictionary 
   738 @SYMTestPriority 	    High
   739 @SYMTestActions  	    Set the test flags to TTestFlags::Dictionary,buffersize to 8 
   740 @SYMTestExpectedResults The test must not fail.
   741 @SYMREQ                 REQ0000
   742 */
   743 
   744 void Test7L()
   745 	{
   746 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0791 "));
   747 	TTestFlags flags(TTestFlags::Dictionary,8);
   748 	flags.iDictionary.Set(dictionary,sizeof(dictionary));
   749 
   750 	CompressDecompressL(flags);
   751 	}
   752 
   753 /**
   754 @SYMTestCaseID          SYSLIB-EZLIB-CT-0792
   755 @SYMTestCaseDesc	    Multistep compression with compression level of 0 test
   756 @SYMTestPriority 	    High
   757 @SYMTestActions  	    Set the test flags to 0,buffersize to 8,compression level to 0  
   758 @SYMTestExpectedResults The test must not fail.
   759 @SYMREQ                 REQ0000
   760 */
   761 
   762 void Test8L()
   763 	{
   764 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0792 "));
   765 	TTestFlags flags(0,8);
   766 	flags.iLevel = 0;
   767 
   768 	CompressDecompressL(flags);
   769 	}
   770 
   771 /**
   772 @SYMTestCaseID          SYSLIB-EZLIB-CT-0793
   773 @SYMTestCaseDesc	    Multistep compression test with compression level of 9 
   774 @SYMTestPriority 	    High
   775 @SYMTestActions  	    Set the test flags to 0,buffersize to 8,compression level to 9  
   776 @SYMTestExpectedResults The test must not fail.
   777 @SYMREQ                 REQ0000
   778 */
   779 
   780 void Test9L()
   781 	{
   782 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0793 "));
   783 	TTestFlags flags(0,8);
   784 	flags.iLevel = 9;
   785 
   786 	CompressDecompressL(flags);
   787 	}
   788 
   789 /**
   790 @SYMTestCaseID          SYSLIB-EZLIB-CT-0794
   791 @SYMTestCaseDesc	    Multistep compression test with invalid compression level 
   792 @SYMTestPriority 	    High
   793 @SYMTestActions  	    Set the test flags to 0,buffersize to 8,compression level to 10.
   794                         Check for stream error when compression level is greater than 9  
   795 @SYMTestExpectedResults The test must not fail.
   796 @SYMREQ                 REQ0000
   797 */
   798 
   799 void Test10()
   800 	{
   801 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0794 "));
   802 	TTestFlags flags(0,8);
   803 	flags.iLevel = 10;
   804 
   805 	TRAPD(err, CompressDecompressL(flags));
   806 	//CompressL fails with KEZlibErrStream if level is greater than 9
   807 	Test (err==KEZlibErrStream);
   808 	}
   809 
   810 /**
   811 @SYMTestCaseID          SYSLIB-EZLIB-CT-0795
   812 @SYMTestCaseDesc	    Multistep compression test with window bits of 7 
   813 @SYMTestPriority 	    High
   814 @SYMTestActions  	    Set the test flags to 0,buffersize to 7
   815                         Check for stream error if window bits is less than 8
   816 @SYMTestExpectedResults The test must not fail.
   817 @SYMREQ                 REQ0000
   818 */
   819 
   820 void Test11()
   821 	{
   822 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0795 "));
   823 	TTestFlags flags(0,7);
   824 	flags.iWindowBits = 7;
   825 	//CompressL fails with KEZlibErrStream if window bits is less than 8
   826 	TRAPD(err, CompressDecompressL(flags));
   827 	Test (err==KEZlibErrStream);
   828 	}
   829 
   830 /**
   831 @SYMTestCaseID          SYSLIB-EZLIB-CT-0796
   832 @SYMTestCaseDesc	    Multistep compression test with window bits of 7 
   833 @SYMTestPriority 	    High
   834 @SYMTestActions  	    Set the test flags to 0,buffersize to 8
   835                         Check for stream error if window bits is less than 9
   836 @SYMTestExpectedResults The test must not fail.
   837 @SYMREQ                 REQ0000
   838 */
   839 
   840 void Test12()
   841 	{
   842 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0796 "));
   843 	TTestFlags flags(0,8);
   844 	flags.iWindowBits = 7;
   845 	//CompressL fails with KEZlibErrStream if window bits is less than 9
   846 	TRAPD(err, CompressDecompressL(flags));
   847 	Test (err==KEZlibErrStream);
   848 	}
   849 
   850 /**
   851 @SYMTestCaseID          SYSLIB-EZLIB-CT-0797
   852 @SYMTestCaseDesc	    Multistep compression test with memory level = 1
   853 @SYMTestPriority 	    High
   854 @SYMTestActions  	    Set the test flags to 0,buffersize to 8
   855 @SYMTestExpectedResults The test must not fail.
   856 @SYMREQ                 REQ0000
   857 */
   858 
   859 void Test13L()
   860 	{
   861 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0797 "));
   862 	TTestFlags flags(0,8);
   863 	flags.iMemLevel = 1;
   864 
   865 	CompressDecompressL(flags);
   866 	}
   867 
   868 /**
   869 @SYMTestCaseID          SYSLIB-EZLIB-CT-0798
   870 @SYMTestCaseDesc	    Multistep compression test with memory level = 10 
   871 @SYMTestPriority 	    High
   872 @SYMTestActions  	    Set the test flags to 0,buffersize to 8
   873                         Check for stream error if memory level is greater than 8.
   874 @SYMTestExpectedResults The test must not fail.
   875 @SYMREQ                 REQ0000
   876 */
   877 
   878 void Test14()
   879 	{
   880 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0798 "));
   881 	TTestFlags flags(0,8);
   882 	flags.iMemLevel = 10;
   883 
   884 	//CompressL fails with KEZlibErrStream if mem level greater than 8
   885 	TRAPD(err, CompressDecompressL(flags));
   886 	Test (err==KEZlibErrStream);
   887 	}
   888 
   889 /**
   890 @SYMTestCaseID          SYSLIB-EZLIB-CT-0799
   891 @SYMTestCaseDesc	    Multistep compression test using only Huffman encoding 
   892 @SYMTestPriority 	    High
   893 @SYMTestActions  	    Set the test flags to 0,buffersize to 8 
   894 @SYMTestExpectedResults The test must not fail.
   895 @SYMREQ                 REQ0000
   896 */
   897 
   898 void Test15L()
   899 	{
   900 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0799 "));
   901 	TTestFlags flags(0,8);
   902 	flags.iStrategy = CEZCompressor::EHuffmanOnly;
   903 
   904 	CompressDecompressL(flags);
   905 	}
   906 
   907 /**
   908 @SYMTestCaseID          SYSLIB-EZLIB-CT-0800
   909 @SYMTestCaseDesc	    Multistep compression test using Filtered strategy 
   910 @SYMTestPriority 	    High
   911 @SYMTestActions  	    Set the test flags to 0,buffersize to 8
   912 @SYMTestExpectedResults The test must not fail.
   913 @SYMREQ                 REQ0000
   914 */
   915 
   916 void Test16L()
   917 	{
   918 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0800 "));
   919 	TTestFlags flags(0,8);
   920 	flags.iStrategy = CEZCompressor::EFiltered;
   921 
   922 	CompressDecompressL(flags);
   923 	}
   924 
   925 /**
   926 @SYMTestCaseID          SYSLIB-EZLIB-CT-0801
   927 @SYMTestCaseDesc	    Multistep compression test when Alloc fails randomly 
   928 @SYMTestPriority 	    High
   929 @SYMTestActions  	    Set the test flags to 0,buffersize to 8
   930 @SYMTestExpectedResults The test must not fail.
   931 @SYMREQ                 REQ0000
   932 */
   933 
   934 void Test17()
   935 	{
   936 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0801 "));
   937 	TTestFlags flags(TTestFlags::AllocFail,8);
   938 
   939 	TRAPD(err,CompressBufferL(flags));
   940 	Test(err == KErrNone||err == KErrNoMemory);  //alloc failure is random so no quarantees of failure
   941 	//Need to reset the heap afterwards to avoid problems for next test.
   942 	__UHEAP_RESET;
   943 	}
   944 
   945 /**
   946 @SYMTestCaseID          SYSLIB-EZLIB-CT-0802
   947 @SYMTestCaseDesc	    Multistep decompression test when NeedInput provides no input 
   948 @SYMTestPriority 	    High
   949 @SYMTestActions  	    Set the test flags to 0,buffersize to 8
   950                         Check for data error,when no input is given
   951 @SYMTestExpectedResults The test must not fail.
   952 @SYMREQ                 REQ0000
   953 */
   954 
   955 void Test18L()
   956 	{
   957 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0802 "));
   958 	TTestFlags flags(0,8);
   959 	CompressBufferL(flags); // make sure we initialize compressed properly
   960 
   961 	flags.iFlags |= TTestFlags::FakeNoInput;
   962 	TRAPD(err,DecompressBufferL(flags));
   963 	// CEZDecompressor::InflateL has left with KEZlibErrBuf due to buffer error
   964 	Test (err==KEZlibErrBuf); 
   965 	}
   966 
   967 /**
   968 @SYMTestCaseID          SYSLIB-EZLIB-CT-0803
   969 @SYMTestCaseDesc	    Multistep decompression test when NeedOutput provides no output 
   970 @SYMTestPriority 	    High
   971 @SYMTestActions  	    Set the test flags to 0,buffersize to 8
   972                         Check for data error,when no output is given
   973 @SYMTestExpectedResults The test must not fail.
   974 @SYMREQ                 REQ0000
   975 */
   976 
   977 void Test19L()
   978 	{
   979 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0803 "));
   980 	TTestFlags flags(0,8);
   981 	CompressBufferL(flags); // make sure we initialize compressed properly
   982 
   983 	flags.iFlags |= TTestFlags::FakeNoOutput;
   984 	TRAPD(err,DecompressBufferL(flags));
   985 	// CEZDecompressor::InflateL has left with KEZlibErrBuf due to buffer error
   986 	Test (err==KEZlibErrBuf); 
   987 	}
   988 
   989 /**
   990 @SYMTestCaseID          SYSLIB-EZLIB-CT-0804
   991 @SYMTestCaseDesc	    Multistep decompression test when NeedOutput provides no output 
   992 @SYMTestPriority 	    High
   993 @SYMTestActions  	    Set the test flags to TTestFlags::Corrupt, buffersize to 8
   994                         Check for data error
   995 @SYMTestExpectedResults The test must not fail.
   996 @SYMREQ                 REQ0000
   997 */
   998 
   999 void Test20L()
  1000 	{
  1001 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0804 "));
  1002 	TTestFlags flags(TTestFlags::Corrupt,8);
  1003 	CompressBufferL(flags); // make sure we initialize compressed properly
  1004 	
  1005 	flags.iFlags = 0;
  1006 
  1007 	TRAPD(err,DecompressBufferL(flags));
  1008 	// CEZDecompressor::InflateL has left with KEZlibErrData due to buffer error
  1009 	Test (err==KEZlibErrData); 
  1010 	}
  1011 
  1012 /**
  1013 @SYMTestCaseID          SYSLIB-EZLIB-CT-0805
  1014 @SYMTestCaseDesc	    Multistep decompression construction test when Alloc fails randomly 
  1015 @SYMTestPriority 	    High
  1016 @SYMTestActions  	    Set the test flags to 0, buffersize to 8
  1017                         Check for data error
  1018 @SYMTestExpectedResults The test must not fail.
  1019 @SYMREQ                 REQ0000
  1020 */
  1021 
  1022 void Test21L()
  1023 	{
  1024 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0805 "));
  1025 	TTestFlags flags(0,8);
  1026 	CompressBufferL(flags); // make sure we initialize compressed properly
  1027 
  1028 	flags.iFlags |= TTestFlags::AllocFail;
  1029 
  1030 	TRAPD(err,DecompressBufferL(flags));
  1031 	Test (err==KErrNone||err==KErrNoMemory); //Alloc failure is random so no guarantee it will always fail.
  1032 	__UHEAP_RESET;
  1033 	}
  1034 
  1035 /**
  1036 @SYMTestCaseID          SYSLIB-EZLIB-CT-0806
  1037 @SYMTestCaseDesc	    Multistep decompression test when Alloc fails randomly
  1038 @SYMTestPriority 	    High
  1039 @SYMTestActions  	    Set the test flags to 0, buffersize to 8
  1040                         Check for no memory errors.
  1041 @SYMTestExpectedResults The test must not fail.
  1042 @SYMREQ                 REQ0000
  1043 */
  1044 
  1045 void Test22L()
  1046 	{
  1047 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0806 "));
  1048 	TTestFlags flags(0,8);
  1049 	CompressBufferL(flags); // make sure we initialize compressed properly
  1050 
  1051 	flags.iFlags |= TTestFlags::AllocFailInflate;
  1052 
  1053 	TRAPD(err,DecompressBufferL(flags));
  1054 	Test (err==KErrNone||err==KErrNoMemory); //Alloc failure is random so no guarentee it will always fail.
  1055 	__UHEAP_RESET;
  1056 	}
  1057 
  1058 static void ThreadL()
  1059 	{
  1060 	RTest test2(_L("EZLIB - second thread"));
  1061 	test2.Title();
  1062 	_LIT(KStartMsg,"Starting Tests in second thread");
  1063 	test2.Start(KStartMsg);
  1064 
  1065 	TTestFlags flags(TTestFlags::Dictionary,8);
  1066 	flags.iDictionary.Set(dictionary,sizeof(dictionary));
  1067 
  1068 	TRAPD(err,CompressBufferL(flags, test2));
  1069 	test2 (err == KErrNone);
  1070 	flags.iFlags = 0;
  1071 	//This code leaves (used to panic before the fix for DEF112672)
  1072 	DecompressBufferL(flags, test2);
  1073 	User::Panic(_L("TestFailure failure"),0);
  1074 	test2.End();
  1075 	test2.Close();
  1076 	}
  1077 
  1078 static TInt TestThread(TAny*)
  1079 	{
  1080 	User::SetJustInTime(EFalse);	// disable debugger panic handling
  1081 	CTrapCleanup* cleanup=CTrapCleanup::New();
  1082 	if (!cleanup)
  1083 		return KErrNoMemory;
  1084 	TRAPD(r,ThreadL());
  1085 	delete cleanup;
  1086 	return r;
  1087 	}
  1088 
  1089 /**
  1090 @SYMTestCaseID          SYSLIB-EZLIB-CT-0807
  1091 @SYMTestCaseDesc	    Multistep decompression test when a dictionary is required and not provided.
  1092 @SYMTestPriority 	    High
  1093 @SYMTestActions  	    Test for panic and exit reason.
  1094 @SYMTestExpectedResults This test should pass without panic.
  1095  						(Expected to panic before the fix for DEF112672)
  1096 @SYMREQ                 REQ0000
  1097 */
  1098 
  1099 void Test23()
  1100 	{
  1101 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0807 "));
  1102 	__UHEAP_MARK;
  1103 
  1104 	RThread t;
  1105 	_LIT(KTestThread,"Panicing thread");
  1106 	Test.Printf(_L("launching thread"));
  1107 	Test (t.Create(KTestThread,&TestThread,0x2000,0x10000,0x100000,0,EOwnerThread) == KErrNone);
  1108 	TRequestStatus s;
  1109 	t.Logon(s);
  1110 	Test (s.Int()==KRequestPending);
  1111 	t.Resume();
  1112 	Test.Printf(_L("Awaiting completion"));
  1113 	User::WaitForRequest(s);
  1114 	User::SetJustInTime(ETrue);	// enable debugger panic handling
  1115 	_LIT(KCategory,"zlib");
  1116 	Test (t.ExitType()==EExitKill);
  1117 	Test (t.ExitCategory()!=KCategory);
  1118 	Test (t.ExitReason()==KEZlibErrData);// SetDictionaryL() leaving error code should be KEZlibErrData
  1119 	t.Close();
  1120 
  1121 	__UHEAP_MARKEND;
  1122 
  1123 	}
  1124 
  1125 /**
  1126 @SYMTestCaseID          SYSLIB-EZLIB-CT-0808
  1127 @SYMTestCaseDesc	    Multistep decompression test when the wrong dictionary is provided 
  1128 @SYMTestPriority 	    High
  1129 @SYMTestActions  	    Check for an error during inflating the dictionary
  1130 @SYMTestExpectedResults Test must not fail
  1131 @SYMREQ                 REQ0000
  1132 */
  1133 
  1134 void Test24L()
  1135 	{
  1136 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0808 "));
  1137 	TTestFlags flags(TTestFlags::Dictionary,8);
  1138 	flags.iDictionary.Set(dictionary,sizeof(dictionary));
  1139 
  1140 	CompressBufferL(flags);
  1141 	
  1142 	flags.iDictionary.Set(badDictionary,sizeof(badDictionary));
  1143 	
  1144 	TRAPD(err,DecompressBufferL(flags));
  1145 	// CEZDecompressor::SetDictionaryL() has left due to bad data
  1146 	Test (err==KEZlibErrInflateDictionary); 
  1147 	}
  1148 
  1149 /**
  1150 @SYMTestCaseID          SYSLIB-EZLIB-CT-0809
  1151 @SYMTestCaseDesc	    Multistep decompression test twice with the same CEZDecompressor,
  1152                         reseting it after the first decompression 
  1153 @SYMTestPriority 	    High
  1154 @SYMTestActions  	    Set the test flags to 0,buffersize to 8,reset value to TRUE 
  1155 @SYMTestExpectedResults Test must not fail
  1156 @SYMREQ                 REQ0000
  1157 */
  1158 
  1159 void Test25L()
  1160 	{
  1161 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0809 "));
  1162 	TTestFlags flags(0,8);
  1163 	CompressBufferL(flags); // make sure we initialize compressed properly
  1164 
  1165 	DblDecompressBufferL(8,ETrue);
  1166 	}
  1167 
  1168 /**
  1169 @SYMTestCaseID          SYSLIB-EZLIB-CT-0810
  1170 @SYMTestCaseDesc	    Multistep decompression test twice with the same CEZDecompressor,
  1171                         resetting it after the first decompression
  1172 @SYMTestPriority 	    High
  1173 @SYMTestActions  	    Set the test flags to 0,buffersize to 8,reset value to FALSE 
  1174                         Check for deflation already occured.
  1175 @SYMTestExpectedResults Test must not fail
  1176 @SYMREQ                 REQ0000
  1177 */
  1178 
  1179 void Test26L()
  1180 	{
  1181 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0810 "));
  1182 	TTestFlags flags(0,8);
  1183 	CompressBufferL(flags); // make sure we initialize compressed properly
  1184 
  1185 	TRAPD(err,DblDecompressBufferL(8,EFalse));
  1186 	//Calling decompress twice without resenting causes leave
  1187 	Test (err==KEZlibErrInflateTerminated); 
  1188 	}
  1189 
  1190 /**
  1191 @SYMTestCaseID          SYSLIB-EZLIB-CT-0811
  1192 @SYMTestCaseDesc	    Multistep compression and decompression test on unicode data 
  1193 @SYMTestPriority 	    High
  1194 @SYMTestActions  	    Set the test flags to TTestFlags::Unicode,buffersize to 8 
  1195 @SYMTestExpectedResults Test must not fail
  1196 @SYMREQ                 REQ0000
  1197 */
  1198 
  1199 void Test27L()
  1200 	{
  1201 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0811 "));
  1202 	TPtrC8 ptr8(original);
  1203 	TPtr ptr16(originalU,256);
  1204 	ptr16.Copy(ptr8);
  1205 
  1206 	TTestFlags flags(TTestFlags::Unicode,8);
  1207 	TPtrC8(REINTERPRET_CAST(TUint8 *,originalU),ptr16.Size());
  1208 	CompressDecompressL(flags);
  1209 	}
  1210 
  1211 /**
  1212 @SYMTestCaseID          SYSLIB-EZLIB-CT-0812
  1213 @SYMTestCaseDesc	    Multistep compression and decompression test on unicode data using a unicode dictionary
  1214 @SYMTestPriority 	    High
  1215 @SYMTestActions  	    Set the test flags to TTestFlags::Dictionary|TTestFlags::Unicode,buffersize to 8 
  1216 @SYMTestExpectedResults Test must not fail
  1217 @SYMREQ                 REQ0000
  1218 */
  1219 
  1220 void Test28L()
  1221 	{
  1222 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0812 "));
  1223 	TPtrC8 ptr8(original);
  1224 	TPtr ptr16(originalU,256);
  1225 	ptr16.Copy(ptr8);
  1226 
  1227 	TPtrC8 dptr8(dictionary);
  1228 	TPtr dptr16(dictionaryU,256);
  1229 	dptr16.Copy(dptr8);
  1230 
  1231 
  1232 	TTestFlags flags(TTestFlags::Dictionary|TTestFlags::Unicode,8);
  1233 	flags.iDictionary.Set(REINTERPRET_CAST(TUint8*, dictionaryU),dptr16.Size());
  1234 
  1235 	TPtrC8(REINTERPRET_CAST(TUint8 *,originalU),ptr16.Size());
  1236 	CompressDecompressL(flags);
  1237 	}
  1238 
  1239 /**
  1240 @SYMTestCaseID          SYSLIB-EZLIB-CT-0813
  1241 @SYMTestCaseDesc	    Multistep compression and decompression test on unicode data using an ASCII dictionary 
  1242 @SYMTestPriority 	    High
  1243 @SYMTestActions  	    Set the test flags to TTestFlags::Dictionary|TTestFlags::Unicode,buffersize to 8 
  1244 @SYMTestExpectedResults Test must not fail
  1245 @SYMREQ                 REQ0000
  1246 */
  1247 
  1248 void Test29L()
  1249 	{
  1250 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0813 "));
  1251 	TPtrC8 ptr8(original);
  1252 	TPtr ptr16(originalU,256);
  1253 	ptr16.Copy(ptr8);
  1254 
  1255 	TTestFlags flags(TTestFlags::Dictionary|TTestFlags::Unicode,8);
  1256 	flags.iDictionary.Set(dictionary,sizeof(dictionary));
  1257 
  1258 	TPtrC8(REINTERPRET_CAST(TUint8 *,originalU),ptr16.Size());
  1259 	CompressDecompressL(flags);
  1260 	}
  1261 
  1262 /**
  1263 @SYMTestCaseID          SYSLIB-EZLIB-CT-0814
  1264 @SYMTestCaseDesc	    Tests the percentage of completion during multistep compression/decompression
  1265 @SYMTestPriority 	    High
  1266 @SYMTestActions  	    Set the test flags to TTestFlags::Percent,buffersize to 8 
  1267 @SYMTestExpectedResults Test must not fail
  1268 @SYMREQ                 REQ0000
  1269 */
  1270 
  1271 void Test30L()
  1272 	{
  1273 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0814 "));
  1274 	TTestFlags flags(TTestFlags::Percent,8);
  1275 
  1276 	CompressDecompressL(flags);
  1277 	}
  1278 
  1279 /**
  1280 @SYMTestCaseID          SYSLIB-EZLIB-CT-0815
  1281 @SYMTestCaseDesc	    Single step compression and decompression test
  1282 @SYMTestPriority 	    High
  1283 @SYMTestActions  	    Calls up CEZCompressor::CompressL(),CEZCompressor::DecompressL() test
  1284 @SYMTestExpectedResults Test must not fail
  1285 @SYMREQ                 REQ0000
  1286 */
  1287 
  1288 void Test31L()
  1289 	{
  1290 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0815 "));
  1291 	TPtrC8 originalD(original,sizeof(original));
  1292 	TPtr8 compressedD(compressed,0,256);
  1293 	TPtr8 uncompressedD(uncompressed,0,256);
  1294 	CEZCompressor::CompressL(compressedD,originalD);
  1295 	CEZDecompressor::DecompressL(uncompressedD,compressedD);
  1296 
  1297 	Test.Printf(_L("\n"));
  1298 	Test.Printf(KSeparator);
  1299 	TPtr ptr16(output,256);
  1300 	ptr16.Copy(uncompressedD);
  1301 	Test.Printf(ptr16);
  1302 	Test.Printf(_L("\n"));
  1303 	Test(originalD.Compare(uncompressedD) == 0,__LINE__);
  1304 	}
  1305 
  1306 /**
  1307 @SYMTestCaseID          SYSLIB-EZLIB-CT-0816
  1308 @SYMTestCaseDesc	    Single step compression test when inadequate output buffer is provided
  1309 @SYMTestPriority 	    High
  1310 @SYMTestActions  	    Check for EZlibErrBuf buffer error flag
  1311 @SYMTestExpectedResults Test must not fail
  1312 @SYMREQ                 REQ0000
  1313 */
  1314 
  1315 void Test32()
  1316 	{
  1317 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0816 "));
  1318 	TPtrC8 originalD(original,sizeof(original));
  1319 	TPtr8 compressedD(compressed,0,1);
  1320 
  1321 	Test.Printf(_L("\n"));
  1322 	Test.Printf(KSeparator);
  1323 
  1324 	TRAPD(err,CEZCompressor::CompressL(compressedD,originalD));
  1325 	// Buffer error
  1326 	Test(err == KEZlibErrBuf);
  1327 	}
  1328 
  1329 /**
  1330 @SYMTestCaseID          SYSLIB-EZLIB-CT-0817
  1331 @SYMTestCaseDesc	    Single step decompression test when inadequate output buffer is provided
  1332 @SYMTestPriority 	    High
  1333 @SYMTestActions  	    Check for EZlibErrBuf buffer error flag
  1334 @SYMTestExpectedResults Test must not fail
  1335 @SYMREQ                 REQ0000
  1336 */
  1337 
  1338 void Test33L()
  1339 	{
  1340 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0817 "));
  1341 	Test.Printf(_L("\n"));
  1342 	Test.Printf(KSeparator);
  1343 	TPtrC8 originalD(original,sizeof(original));
  1344 	TPtr8 compressedD(compressed,0,256);
  1345 	TPtr8 uncompressedD(uncompressed,0,1);
  1346 	CEZCompressor::CompressL(compressedD,originalD);
  1347 	TRAPD(err,CEZDecompressor::DecompressL(uncompressedD,compressedD));
  1348 	// Buffer error
  1349 	Test(err == KEZlibErrBuf);
  1350 	}
  1351 
  1352 /**
  1353 @SYMTestCaseID          SYSLIB-EZLIB-CT-0818
  1354 @SYMTestCaseDesc	    Testing graceful exit for zlib 1.1.3 decompression bug
  1355 @SYMTestPriority 	    High
  1356 @SYMTestActions  	    Check for buffer error after inflation
  1357 @SYMTestExpectedResults Test must not fail
  1358 @SYMREQ                 REQ0000
  1359 */
  1360 void Test34L()
  1361     {
  1362 	Test.Printf(_L("\n"));
  1363 	Test.Printf(KSeparator);	
  1364 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-0818 "));
  1365 	// 00000720.png contains specially crafted data block that exposes bug in 1.1.3 
  1366 	// decompression algorithm.  Causes InflateL() to return Z_BUF_ERROR.
  1367 	#if !defined(__WINS__)
  1368 	_LIT(KInputFile, "z:\\test\\png\\00000720.png");
  1369 	#else
  1370 	_LIT(KInputFile, "c:\\test\\png\\00000720.png");
  1371 	#endif
  1372 	_LIT(KTempDirectory, "c:\\test\\temp\\");	
  1373 	RFile input, output, tempInput;
  1374 	RFs rfs;
  1375 	rfs.Connect();
  1376 	rfs.MkDirAll(KTempDirectory);	
  1377 	
  1378 	TInt res = input.Open(rfs, KInputFile, EFileStream | EFileRead | EFileShareAny);
  1379 	Test(res==KErrNone); 
  1380 	CleanupClosePushL(input);	
  1381 
  1382 	TFileName filename;
  1383 	TBuf8<1024> readBuf;
  1384 	TInt fileLen; 
  1385 	input.Size(fileLen); 
  1386 	res = input.Read(8,readBuf,fileLen);
  1387 	Test(res==KErrNone); 
  1388 
  1389 	res = tempInput.Temp(rfs, KTempDirectory, filename, EFileStream | EFileWrite | EFileShareExclusive);
  1390 	Test(res==KErrNone); 
  1391 	CleanupClosePushL(tempInput);
  1392 	res = tempInput.Write(readBuf, fileLen-8);  // Create temporary file without the 8 byte PNG header.
  1393 	Test(res==KErrNone); 
  1394 	
  1395 	CEZFileBufferManager *fb = CEZFileBufferManager::NewLC(tempInput, output, 4096);
  1396 	CEZDecompressor *inf = CEZDecompressor::NewLC(*fb);
  1397 	
  1398 	TRAPD(err, while (inf->InflateL()){});
  1399 	//CEZDecompressor::InflateL() leaves
  1400 	Test (err==KEZlibErrBuf); 
  1401 
  1402 	tempInput.Close();
  1403 	User::LeaveIfError(rfs.Delete(filename));
  1404 	input.Close();
  1405 	CleanupStack::PopAndDestroy(4);
  1406     }
  1407 
  1408 #if !(defined(__WINSCW__) || defined (_DEBUG))	
  1409 void DecompressFileL(const TDesC& aFilePath, RFs& aFs, TInt aTimingLimit)
  1410 {
  1411    _LIT(KTempDirectory, "c:\\test\\temp\\");      
  1412    aFs.MkDirAll(KTempDirectory);   
  1413     	
  1414    RFile inputFile, tempFile;
  1415    //open the input compressed file
  1416    TInt res = inputFile.Open(aFs, aFilePath, EFileStream | EFileRead | EFileShareExclusive);
  1417    Test(res==KErrNone); 
  1418    CleanupClosePushL(inputFile);         		
  1419    
  1420    //create a temporary file to be used as an output of the decompressor
  1421    TFileName filename;
  1422    res = tempFile.Temp(aFs, KTempDirectory, filename, EFileStream | EFileWrite | EFileShareExclusive);
  1423    Test(res==KErrNone); 
  1424    CleanupClosePushL(tempFile);
  1425    
  1426    //decompress the data from the input file several times            
  1427    TInt startTime = User::FastCounter();
  1428    for (TInt i = 0; i<10; i++)
  1429    {
  1430    		TInt position = 0;
  1431    		inputFile.Seek(ESeekStart,position);		
  1432    		CEZFileBufferManager *fb = CEZFileBufferManager::NewLC(inputFile, tempFile, 4096);
  1433    		//create a decompressor object based on the file buffer manager
  1434    		CEZDecompressor *decompressor = CEZDecompressor::NewLC(*fb);	
  1435 	   	TRAP(res, while (decompressor->InflateL()){});   
  1436    		Test(res==KErrNone);     		   		
  1437    		CleanupStack::PopAndDestroy(2);
  1438    }
  1439    TInt endTime = User::FastCounter();
  1440 
  1441    //close input and temporary file
  1442    CleanupStack::PopAndDestroy(2);      
  1443    //delete temporary file   
  1444    aFs.Delete(filename);
  1445    
  1446    TReal netTime = FastCountToMilliseconds(endTime-startTime); 
  1447    _LIT(KLogLine,"netTime =%f\n");   
  1448    Test.Printf(KLogLine,netTime);   
  1449    
  1450    if (aTimingLimit)
  1451 	   {
  1452 	   Test(netTime <= aTimingLimit);
  1453 	   }
  1454    else
  1455 	   {
  1456 	   Test.Printf(_L("Timings results are only checked on the RAM configuration of H2 and H4 HRP\n"));	
  1457 	   }   
  1458 }
  1459 #endif
  1460 
  1461 /**
  1462 @SYMTestCaseID          SYSLIB-EZLIB-CT-3426
  1463 @SYMTestCaseDesc        Testing EZlib decompressor performance after enforcing compiler optimisation
  1464 @SYMTestPriority        Medium
  1465 @SYMTestActions         This test uses several typical pieces of compressed 
  1466 						image data as an input and inflates them 10 times. 
  1467 						The total duration of this operation is measured and 
  1468 						compared against a benchmarking limit. Only performed
  1469 						on UREL builds running on H2 and H4 hardware. 
  1470 @SYMTestExpectedResults Time spent on decompression should be less than a preset limit.
  1471 @SYMREQ                 REQ7363
  1472 */
  1473 
  1474 void Test35L()
  1475    {	
  1476    Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-3426 "));
  1477 #if !(defined(__WINSCW__) || defined (_DEBUG))	
  1478    Test.Printf(_L("\n"));
  1479    Test.Printf(KSeparator);   
  1480    _LIT(KInputFile1, "z:\\test\\png\\compressed_data1");//A small-sized picture with
  1481    														//transparent background which
  1482    														//represents typical UI component 
  1483    														//icon.
  1484    	
  1485    _LIT(KInputFile2, "z:\\test\\png\\compressed_data2");//Medium-sized picture with a
  1486    													    //single image typical for a UI 
  1487    													    //theme background image
  1488    													    
  1489    _LIT(KInputFile3, "z:\\test\\png\\compressed_data3");//Medium-sized picture with
  1490    														//multiple small images on it 
  1491    														//typical for a sheet of UI 
  1492    														//component skins
  1493    
  1494    _LIT(KInputFile4, "z:\\test\\png\\compressed_data4");//Large-sized photo image 
  1495    														   
  1496    RFs rfs;
  1497    rfs.Connect();
  1498    CleanupClosePushL(rfs);   
  1499    
  1500    // determine media type of C drive
  1501    TDriveInfo driveInf;
  1502    TInt res = rfs.Drive(driveInf, EDriveC);   
  1503    Test(res==KErrNone);
  1504    
  1505    TInt timingLimit1 = 0;
  1506    TInt timingLimit2 = 0;
  1507    TInt timingLimit3 = 0;
  1508    TInt timingLimit4 = 0;
  1509    // only check benchmarks if running on hardware, with UREL + RAM build (i.e. not NAND)   
  1510    if (driveInf.iType == EMediaRam)
  1511 		{
  1512 		TInt muid = 0;   
  1513    		res= HAL::Get(HAL::EMachineUid, muid);
  1514       	Test(res==KErrNone);     		   		 
  1515 	    switch (muid)
  1516 	   		{
  1517 	   		case HAL::EMachineUid_OmapH2:
  1518 	   			timingLimit1 = 350;
  1519 	   			timingLimit2 = 1650;
  1520 	   			timingLimit3 = 2900;
  1521 	   			timingLimit4 = 2750;
  1522 	   			break;
  1523 	   		case HAL::EMachineUid_OmapH4:
  1524 	   			timingLimit1 = 200;
  1525 	   			timingLimit2 = 850;
  1526 	   			timingLimit3 = 1400;
  1527 	   			timingLimit4 = 1500;
  1528 	   			break;
  1529 	   		default:
  1530 	   			break;
  1531 	   		}
  1532    		}
  1533    
  1534    DecompressFileL(KInputFile1, rfs, timingLimit1);
  1535    DecompressFileL(KInputFile2, rfs, timingLimit2);
  1536    DecompressFileL(KInputFile3, rfs, timingLimit3);
  1537    DecompressFileL(KInputFile4, rfs, timingLimit4);   
  1538    CleanupStack::PopAndDestroy();	   
  1539 #else
  1540    Test.Printf(_L("This test is only performed on hardware UREL builds\n"));
  1541 #endif   
  1542    }
  1543     
  1544 /**
  1545 @SYMTestCaseID          SYSLIB-EZLIB-UT-3684
  1546 @SYMTestCaseDesc	    Test the memory deallocation of the CEZFileBufferManager object to ensure that
  1547 						there is no memory leak on success or failure of file compression and decompression
  1548 @SYMTestPriority 	    High
  1549 @SYMTestActions  	    Compressing and Decompressing a png image using CEZCompressor::InflateL() and
  1550 						CEZDecompressor::DeflateL()
  1551 @SYMTestExpectedResults Test must not fail and memory must not leak afterdeallocating CEZFileBufferManager 
  1552 						object (fb)
  1553 @SYMDEF                 DEF109756
  1554 */
  1555 void Test36L()
  1556     {
  1557 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-CT-3684 "));
  1558     Test.Printf(_L("\n"));
  1559 	Test.Printf(KSeparator);		
  1560 	//Set the path of input file and output files
  1561 	#if !defined(__WINS__)
  1562 	_LIT(KInputFile, "z:\\test\\png\\00000720.png");
  1563 	#else
  1564 	_LIT(KInputFile, "c:\\test\\png\\00000720.png");
  1565 	#endif
  1566 	_LIT(KOutputFile, "c:\\test\\temp\\00000720.z");
  1567 	_LIT(KUncompressedFile, "c:\\test\\temp\\000007201");
  1568 	
  1569 	RFs rfs;
  1570 	rfs.Connect();
  1571 	CleanupClosePushL(rfs);
  1572 	
  1573 	TPtrC inputFile(KInputFile);
  1574 	TPtrC outputFile(KOutputFile);
  1575 	TPtrC uncompressedFile(KUncompressedFile);
  1576 
  1577 	RFile input;
  1578 	RFile output;
  1579 	TInt err;
  1580 	//Open the PNG file for compressing
  1581 	User::LeaveIfError(input.Open(rfs, inputFile,EFileStream | EFileRead | EFileShareAny));
  1582 	CleanupClosePushL(input);
  1583 	
  1584 	//Create file to store output of file compressing
  1585 	err = output.Create(rfs, outputFile,EFileStream | EFileWrite | EFileShareExclusive);
  1586 	if (err == KErrAlreadyExists)//Just in case if the output file already exists then open it.
  1587 		User::LeaveIfError(output.Open(rfs, outputFile,EFileStream | EFileWrite | EFileShareExclusive));
  1588 	else 
  1589 		User::LeaveIfError(err);
  1590 	CleanupClosePushL(output);
  1591 
  1592 __UHEAP_MARK;
  1593 	//Create and assign the CEZFileBufferManager object 'fb' as the compressor's buffer manager
  1594 	CEZFileBufferManager *fb = CEZFileBufferManager::NewLC(input,output,16384);
  1595 	CEZCompressor *def = CEZCompressor::NewLC(*fb);
  1596 
  1597 	while (def->DeflateL()){/*do nothing*/}
  1598 
  1599 	CleanupStack::PopAndDestroy(def);
  1600 	CleanupStack::PopAndDestroy(fb);
  1601 __UHEAP_MARKEND;
  1602 
  1603 	CleanupStack::PopAndDestroy(&output);
  1604 	CleanupStack::PopAndDestroy(&input);
  1605 	//Now open the compressed file for decompressing
  1606 	User::LeaveIfError(input.Open(rfs, outputFile,EFileStream | EFileRead | EFileShareAny));
  1607 	CleanupClosePushL(input);
  1608 	
  1609 	//Create file to store output of decompressing
  1610 	err = output.Create(rfs, uncompressedFile,EFileStream | EFileWrite | EFileShareExclusive);
  1611 	if (err == KErrAlreadyExists)//Just in case if the output file already exists then open it.
  1612 		User::LeaveIfError(output.Open(rfs, uncompressedFile,EFileStream | EFileWrite | EFileShareExclusive));
  1613 	else 
  1614 		User::LeaveIfError(err);
  1615 	
  1616 	CleanupClosePushL(output);
  1617 
  1618 __UHEAP_MARK;
  1619 	//Create and assign the CEZFileBufferManager object 'fb' as the decompressor's buffer manager
  1620 	fb = CEZFileBufferManager::NewLC(input,output,16384);
  1621 	CEZDecompressor *inf = CEZDecompressor::NewLC(*fb);
  1622 
  1623 	while (inf->InflateL()){/*do nothing*/}
  1624 
  1625 	CleanupStack::PopAndDestroy(inf);
  1626 	CleanupStack::PopAndDestroy(fb);
  1627 __UHEAP_MARKEND;
  1628 	input.Close();
  1629 	output.Close();
  1630 
  1631 	CleanupStack::PopAndDestroy(&output);
  1632 	CleanupStack::PopAndDestroy(&input);
  1633 	CleanupStack::PopAndDestroy(&rfs);
  1634 	}
  1635 
  1636 /**
  1637 @SYMTestCaseID          SYSLIB-EZLIB2-UT-4298
  1638 @SYMTestCaseDesc	    Test CEZZStream functions through CEZCompressor class e.g. 
  1639 						Adler32(), AvailIn(), AvailOut()
  1640 @SYMTestPriority 	    High
  1641 @SYMTestActions  	    1.	Compress stream of data using CEZCompressor::NewLC() & CEZCompressor::DeflateL()
  1642 						2.	Call CEZCompressor::Adler32() to get the checksum value of the uncompressed data
  1643 						3.	Call CEZCompressor::AvailIn() to get the number of bytes available at the next input byte
  1644 						4.	Call CEZCompressor::AvailOut() to get the remaining free space at next output byte target
  1645 @SYMTestExpectedResults The test succeeds with no errors i.e. KErrNone 
  1646 @SYMDEF                 REQ8024
  1647 */
  1648 
  1649 void TestCEZCompressorMethodsL()
  1650 	{
  1651 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4298 "));
  1652 	CBufferManager *bm;
  1653 	TInt sourceSize;
  1654 	
  1655 	sourceSize = sizeof(original);
  1656 	bm = CBufferManager::NewLC(original,sourceSize,compressed,256,8);
  1657 	CEZCompressor *compressor = CEZCompressor::NewLC(*bm);
  1658 	
  1659 	TInt32 adler32;
  1660 	TInt availIn;
  1661 	TInt availOut;
  1662 	
  1663 	while(compressor->DeflateL()){/*do nothing*/}
  1664 	
  1665 	adler32 = compressor->Adler32();
  1666 	Test(adler32 > 0);
  1667 	
  1668 	availIn = compressor->AvailIn();
  1669 	Test(availIn == 0);
  1670 	
  1671 	availOut = compressor->AvailOut();
  1672 	Test(availOut > 0);
  1673 	
  1674 	CleanupStack::PopAndDestroy(compressor);
  1675 	CleanupStack::PopAndDestroy(bm);
  1676 	}
  1677 
  1678 /**
  1679 @SYMTestCaseID          SYSLIB-EZLIB2-UT-4300
  1680 @SYMTestCaseDesc	    TTest Zlibapiwrapper.cpp exported API's like inflate, 
  1681 						deflate, compress, decompress 
  1682 @SYMTestPriority 	    High
  1683 @SYMTestActions  	    Call the exported C APIs of Zlibapiwrapper.cpp 
  1684 						Note: This is done to check if the C APIs of zlib.lib 
  1685 						are called through ezlib.lib.
  1686 @SYMTestExpectedResults All exported C API's should be called (i.e. run a basic scenario
  1687 						of compressing some data) & test must not fail 
  1688 @SYMDEF                 REQ8024
  1689 */
  1690 
  1691 void TestZlibapiwrapperAPIL()
  1692 	{
  1693 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4300 "));
  1694 	z_stream deflateStream;
  1695 	const char inputData[] = "inputData!"; // data to compress
  1696     uLong inputDataLength = (uLong)sizeof(inputData) + 1;     
  1697     Byte *compressedDataBuffer; // output buffer
  1698     //The buffer size is kept as 50 but incase the input data is changed..
  1699     //...the buffer size also has to be increased accordingly
  1700     TInt compressedDataBufferLength = 50;
  1701 
  1702 	// Allocate memory for output buffer
  1703     compressedDataBuffer = (Byte*)User::AllocZ(compressedDataBufferLength);
  1704     Test(compressedDataBuffer != Z_NULL);
  1705     CleanupStack::PushL(compressedDataBuffer);
  1706     
  1707      // Initialise the stream
  1708 	deflateStream.zalloc = (alloc_func)0;
  1709 	deflateStream.zfree = (free_func)0;
  1710 	deflateStream.opaque = (voidpf)0;
  1711     
  1712     int level = Z_DEFAULT_COMPRESSION;
  1713    	int err = 0;
  1714 	int flush = 0;
  1715 
  1716     err = deflateInit(&deflateStream, level);
  1717 
  1718 	if(err != Z_OK) 
  1719 		{ 
  1720 	    deflateEnd(&deflateStream);
  1721 		Test(err == Z_OK);
  1722 	    }	
  1723 
  1724 	
  1725 	// Compress data in the input buffer
  1726 	deflateStream.next_in  = (Byte*)inputData;
  1727 	deflateStream.next_out = compressedDataBuffer; 
  1728 	
  1729     do 
  1730     	{
  1731     	if (deflateStream.total_in < inputDataLength)
  1732     		{
  1733 			deflateStream.avail_in = 1; // force small buffer
  1734     		}
  1735     	
  1736     	flush = (deflateStream.total_in == inputDataLength) ?  Z_FINISH : Z_NO_FLUSH;
  1737 	
  1738 	    // run deflate() on input until output buffer not full, finish
  1739 	    // compression if all of source has been read in 
  1740 	    do 
  1741 	    	{
  1742 	    	if (deflateStream.total_out < compressedDataBufferLength)
  1743 	    		{
  1744 				deflateStream.avail_out = 1; // force small buffer
  1745 	    		}
  1746 
  1747 	        err = deflate(&deflateStream, flush); 
  1748 	        if(err != Z_OK && err != Z_STREAM_END) 
  1749 	    		{ 
  1750 	    	    deflateEnd(&deflateStream);
  1751 	    		Test(err == Z_OK || err == Z_STREAM_END);
  1752 	    	    } 
  1753 	    	} while(deflateStream.avail_out == 0 && err == Z_OK);
  1754     	} while(err != Z_STREAM_END); 
  1755     	
  1756     deflateEnd(&deflateStream);
  1757 	CleanupStack::PopAndDestroy(compressedDataBuffer);
  1758 
  1759 	}
  1760 	
  1761 /**
  1762 @SYMTestCaseID			SYSLIB-EZLIB-UT-4001
  1763 @SYMTestCaseDesc		Test for DEF112672 - Panic ZLIB 11 - when installing the sisx file.
  1764 						The test attempts to decompress a buffer with the "Dictionary" flag set
  1765 						but with NULL dictionary buffer. The test should not cause an assert in the EZLib library.
  1766 @SYMTestPriority		Normal
  1767 @SYMTestActions			Test for DEF112672 - Panic ZLIB 11 - when installing the sisx file.
  1768 @SYMTestExpectedResults Test must not fail
  1769 @SYMDEF					DEF112672
  1770 */
  1771 
  1772 void DEF112672L()
  1773 	{
  1774 	Test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB-UT-4001 "));
  1775 	TTestFlags flags(TTestFlags::Dictionary, 8);
  1776 	flags.iDictionary.Set(dictionary, sizeof(dictionary));
  1777 	CompressBufferL(flags);
  1778 	flags.iDictionary.Set(0, 0);
  1779 	TRAPD(err, DecompressBufferL(flags));
  1780 	Test(err == KEZlibErrData); 
  1781 	}
  1782 
  1783 void RunTestL()
  1784 	{
  1785 	for (TInt testNum=1; testNum<KNumberOfTests; testNum++)
  1786 		{
  1787 		__UHEAP_MARK;
  1788 		_LIT(KTestNum,"\n\nRunning Test %d\n\n");
  1789 		TBuf<80> buf;
  1790 		buf.Format(KTestNum, testNum);
  1791 		Test.Next(buf);
  1792 		_LIT(KStrMsg,"%S");
  1793 		Test.Printf(KStrMsg, testTable[testNum].iDescription);
  1794 		testTable[testNum].iFn();
  1795 		__UHEAP_MARKEND;
  1796 		}
  1797 	DEF112672L();
  1798 	}	
  1799 
  1800 GLDEF_C TInt E32Main()
  1801 	{
  1802 	CTrapCleanup* cleanup=CTrapCleanup::New();
  1803 	Test.Title();
  1804 	_LIT(KStartMsg,"Starting Tests..");
  1805 	Test.Start(KStartMsg);
  1806 __UHEAP_MARK;
  1807 	TRAPD(err,RunTestL());
  1808 	Test (err==KErrNone);
  1809 	Test.End();
  1810 	Test.Close();
  1811 __UHEAP_MARKEND;
  1812 	delete cleanup;
  1813 	return KErrNone;
  1814 	}