os/ossrv/compressionlibs/ziplib/test/rtest/gziptest/gziptest.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/compressionlibs/ziplib/test/rtest/gziptest/gziptest.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1054 @@
     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 <ezgzip.h>
    1.21 +
    1.22 +#if !defined(__WINS__)
    1.23 +_LIT(KPath, "Z:\\test\\gzip\\");
    1.24 +#else
    1.25 +_LIT(KPath, "C:\\test\\gzip\\");
    1.26 +#endif
    1.27 +
    1.28 +_LIT(KOutputFilePath, "C:\\test\\gzip\\");
    1.29 +
    1.30 +_LIT(KInputFile, "Hello.txt");
    1.31 +_LIT(KCompressFile,"Hello.gz");
    1.32 +_LIT(KDecompressFile,"Hello_Decompress.txt");
    1.33 +
    1.34 +
    1.35 +static RTest				test(_L("gziptest.exe"));
    1.36 +static RFs					TheFs;
    1.37 +static CTrapCleanup* 		TheTrapCleanup 		= NULL;
    1.38 +static TInt 				TheBufferSize		= 500;
    1.39 +static TFileName 			TheInputFile(KInputFile);
    1.40 +static TFileName 			TheCompressFile(KCompressFile);
    1.41 +static TFileName 			TheDecompressFile(KDecompressFile);
    1.42 +
    1.43 +static void CompressFileL(TFileName& aInputFile, TFileName& aCompressFile, TInt aBufferSize = TheBufferSize);
    1.44 +static void DecompressFileL(TFileName& aInputFile, TFileName& aDecompressFile, TInt aBufferSize = TheBufferSize);
    1.45 +static void CompareFileDataL(TFileName& aSourceFile, TFileName& aDestFile, TInt& aCompare);
    1.46 +static void ThreadForPanicTest(TThreadFunction aPanicThreadFunc);
    1.47 +
    1.48 +inline void DeleteFile(TFileName& aFileName, TBool aPathSpecified = EFalse)
    1.49 +	{
    1.50 +	TFileName deleteFilePath;
    1.51 +	if(!aPathSpecified)
    1.52 +		{
    1.53 +		deleteFilePath.Append(KOutputFilePath);
    1.54 +		}
    1.55 +	deleteFilePath.Append(aFileName);
    1.56 +
    1.57 +	TRAPD(error, TheFs.Delete(deleteFilePath));
    1.58 +	if(error != KErrNone)
    1.59 +		test.Printf(_L("File not deleted: %S"), &deleteFilePath);
    1.60 +	}
    1.61 +	
    1.62 +static void CompressFileL(TFileName& aInputFile, TFileName& aCompressFile, TInt aBufferSize)
    1.63 +	{
    1.64 +	TFileName inputFilePath(KPath);
    1.65 +	inputFilePath.Append(aInputFile);
    1.66 +	
    1.67 +	TFileName compressFilePath(KOutputFilePath);
    1.68 +	compressFilePath.Append(aCompressFile);
    1.69 +	
    1.70 +	RFile input;
    1.71 +	User::LeaveIfError(input.Open(TheFs,inputFilePath, EFileStream | EFileRead | EFileShareReadersOnly));
    1.72 +	CleanupClosePushL(input);
    1.73 +	
    1.74 +	CEZFileToGZip *fileToGzip = NULL;
    1.75 +	TRAPD(error, fileToGzip = CEZFileToGZip::NewL(TheFs, compressFilePath, input, aBufferSize));
    1.76 +	test(error == KErrNone);
    1.77 +	CleanupStack::PushL(fileToGzip);
    1.78 +	
    1.79 +	while(fileToGzip->DeflateL()){/*do nothing*/}
    1.80 +	
    1.81 +	CleanupStack::PopAndDestroy(2);
    1.82 +	}
    1.83 +	
    1.84 +static void DecompressFileL(TFileName& aCompressFile, TFileName& aDecompressFile, TInt aBufferSize)
    1.85 +	{
    1.86 +
    1.87 +	TFileName compressFilePath(KPath);
    1.88 +	compressFilePath.Append(aCompressFile);
    1.89 +	
    1.90 +	TFileName decompressFilePath(KOutputFilePath);
    1.91 +	decompressFilePath.Append(aDecompressFile);
    1.92 +
    1.93 +	RFile output;
    1.94 +	User::LeaveIfError(output.Replace(TheFs, decompressFilePath, EFileStream | EFileWrite | EFileShareExclusive));
    1.95 +	CleanupClosePushL(output);
    1.96 +
    1.97 +	CEZGZipToFile *gzipToFile = NULL;
    1.98 +	TRAPD(error, gzipToFile = CEZGZipToFile::NewL(TheFs, compressFilePath, output, aBufferSize));
    1.99 +	test(error == KErrNone);
   1.100 +	CleanupStack::PushL(gzipToFile);
   1.101 +	
   1.102 +	while (gzipToFile->InflateL()){/*do nothing*/}
   1.103 +
   1.104 +	CleanupStack::PopAndDestroy(2);
   1.105 +	
   1.106 +	}
   1.107 +	
   1.108 +static void CompareFileDataL(TFileName& aSourceFile, TFileName& aDestFile, TInt& aCompare)
   1.109 +	{
   1.110 +	
   1.111 +	TFileName sourceFilePath(KPath);
   1.112 +	sourceFilePath.Append(aSourceFile);
   1.113 +
   1.114 +	TFileName destFilePath(KOutputFilePath);
   1.115 +	destFilePath.Append(aDestFile);
   1.116 +
   1.117 +	RFile source;
   1.118 +	User::LeaveIfError(source.Open(TheFs,sourceFilePath, EFileStream | EFileRead | EFileShareReadersOnly));
   1.119 +	CleanupClosePushL(source);
   1.120 +		
   1.121 +	TInt sourceSize;
   1.122 +	source.Size(sourceSize);
   1.123 +	test(sourceSize > 0);
   1.124 +		
   1.125 +	HBufC8* sourceData = NULL;
   1.126 +	TRAPD(error, sourceData = HBufC8::NewMaxL(sourceSize));
   1.127 +	test(error == KErrNone);
   1.128 +	CleanupStack::PushL(sourceData);
   1.129 +			
   1.130 +	TPtr8 tSourceBufPtr = sourceData->Des();
   1.131 +	User::LeaveIfError(source.Read(0, tSourceBufPtr, sourceSize));
   1.132 +	
   1.133 +	RFile dest;
   1.134 +	User::LeaveIfError(dest.Open(TheFs,destFilePath, EFileStream | EFileWrite | EFileShareExclusive));
   1.135 +	CleanupClosePushL(dest);
   1.136 +
   1.137 +	TInt destSize;
   1.138 +	dest.Size(destSize);
   1.139 +	test(destSize > 0);
   1.140 +	
   1.141 +	HBufC8* destData = NULL;
   1.142 +	TRAP(error, destData = HBufC8::NewMaxL(destSize));
   1.143 +	test(error == KErrNone);
   1.144 +	CleanupStack::PushL(destData);
   1.145 +			
   1.146 +	TPtr8 tDestBufPtr = destData->Des();
   1.147 +	User::LeaveIfError(dest.Read(0, tDestBufPtr, destSize));
   1.148 +		
   1.149 +	aCompare = sourceData->Compare(*destData);
   1.150 +
   1.151 +	CleanupStack::PopAndDestroy(4);
   1.152 +	
   1.153 +	}
   1.154 +
   1.155 +static void ThreadForPanicTest(TThreadFunction aPanicThreadFunc)
   1.156 +	{
   1.157 +   	TRequestStatus threadStatus(KRequestPending);
   1.158 +   	TRequestStatus threadStatus1(KRequestPending); 
   1.159 +   	
   1.160 +   	RThread thread;
   1.161 +	TBool justInTime = User::JustInTime();
   1.162 +	User::SetJustInTime(EFalse);
   1.163 +		
   1.164 +	test.Printf(_L("Starting thread for invalid panic test...\n"));
   1.165 +	TInt err=thread.Create(	_L("Panic thread"),aPanicThreadFunc,KDefaultStackSize,0x1000,0x1000,NULL,EOwnerThread );
   1.166 +	
   1.167 +	test.Printf(_L("Thread Creation returned following error code: %d \n"), err);
   1.168 +	test(err == KErrNone);
   1.169 +
   1.170 +	thread.Logon(threadStatus);
   1.171 +	thread.Resume();
   1.172 +	User::WaitForRequest(threadStatus);
   1.173 +
   1.174 +#ifdef _DEBUG
   1.175 +	__ASSERT_ALWAYS(thread.ExitType() == EExitPanic,User::Panic(_L("Thread panic mismatch."),KErrGeneral));
   1.176 +	test.Printf(_L("Invalid Panic test completed successfully for udeb build.\n"));
   1.177 +#else
   1.178 +	test.Printf(_L("Invalid Panic test completed successfully for urel build.\n"));
   1.179 +#endif
   1.180 +	
   1.181 +	thread.Logon(threadStatus1);
   1.182 +	thread.Kill(KErrNone);
   1.183 +	User::WaitForRequest(threadStatus1);
   1.184 +	test(threadStatus1 == KErrNone);
   1.185 +	
   1.186 +    CLOSE_AND_WAIT(thread);
   1.187 +    
   1.188 +	User::SetJustInTime(justInTime);
   1.189 +	}
   1.190 +
   1.191 +/**
   1.192 +@SYMTestCaseID          SYSLIB-EZLIB2-UT-4286
   1.193 +@SYMTestCaseDesc	    To ensure a file can be compressed to a gzip file and then correctly 
   1.194 +						decompressed back to its original state using classes from gzip.cpp.  
   1.195 +						Overwrite output file to verify existing file can be re-used.
   1.196 +@SYMTestPriority 	    High
   1.197 +@SYMTestActions  	    1.	Open existing test file and pass it to CEZFileToGZip::NewL() & 
   1.198 +							compress using CEZFileToGZip::DeflateL() function
   1.199 +						2.	Create or open output decompressed file and pass compressed file to
   1.200 +							CEZGZipToFile::NewL() & decompress using CEZGZipToFile::InflateL() function
   1.201 +						3.	Compare original and new file, they should be identical
   1.202 +						4.	Repeat Steps 1 - 3 overwriting existing compressed output file
   1.203 +@SYMTestExpectedResults Original test file should be the same as the file generated 
   1.204 +						after decompressing it & the test must not fail
   1.205 +@SYMDEF                 REQ8024
   1.206 +*/
   1.207 +void TestCompressDecompressGzip()
   1.208 +	{
   1.209 +	TRAPD(error, CompressFileL(TheInputFile, TheCompressFile));
   1.210 +	test(error == KErrNone);
   1.211 +	TRAP(error, DecompressFileL(TheCompressFile, TheDecompressFile));
   1.212 +	test(error == KErrNone);
   1.213 +	
   1.214 +	TInt compare;
   1.215 +	//compare the files
   1.216 +	TRAP(error, CompareFileDataL(TheInputFile, TheDecompressFile, compare));
   1.217 +	test(error == KErrNone);
   1.218 +	
   1.219 +	if(compare == 0)
   1.220 +		RDebug::Printf("Input file data is same as the Decompressed file data");
   1.221 +	else
   1.222 +		RDebug::Printf("Input file data differs from Decompressed file data");
   1.223 +	
   1.224 +#if !defined(__WINS__)
   1.225 +	DeleteFile(TheCompressFile);
   1.226 +	DeleteFile(TheDecompressFile);
   1.227 +#endif
   1.228 +
   1.229 +	//Compress & decompress the same file again to overwrite the existing file & 
   1.230 +	//..to verify that the existing files can be re-used
   1.231 +	TRAP(error, CompressFileL(TheInputFile, TheCompressFile));
   1.232 +	test(error == KErrNone);
   1.233 +	TRAP(error, DecompressFileL(TheCompressFile, TheDecompressFile));
   1.234 +	test(error == KErrNone);
   1.235 +	
   1.236 +#if !defined(__WINS__)
   1.237 +	DeleteFile(TheCompressFile);
   1.238 +	DeleteFile(TheDecompressFile);
   1.239 +#endif
   1.240 +	}
   1.241 +
   1.242 +/**
   1.243 +@SYMTestCaseID          SYSLIB-EZLIB2-UT-4287
   1.244 +@SYMTestCaseDesc	    To ensure a file can be compressed to a gzip file and then correctly 
   1.245 +						decompressed back using buffer size as small & big.
   1.246 +						
   1.247 +@SYMTestPriority 	    High
   1.248 +@SYMTestActions  	    1.	Open existing test file and pass it to CEZFileToGZip::NewL() & 
   1.249 +							compress using CEZFileToGZip::DeflateL() with buffer size as "11"
   1.250 +						2.	Create or open output decompressed file and pass compressed file 
   1.251 +							to CEZGZipToFile::NewL() & decompress using CEZGZipToFile::InflateL() 
   1.252 +							with buffer size as "10"
   1.253 +						3.	Repeat Steps 1 & 2 using buffer size as 10 times the file size
   1.254 +@SYMTestExpectedResults Files should be compressed with no errors i.e. KErrNone & the test must not fail 
   1.255 +@SYMDEF                 REQ8024
   1.256 +*/
   1.257 +void TestOutputBuffSize()
   1.258 +	{	
   1.259 +	
   1.260 +	TRAPD(error, CompressFileL(TheInputFile, TheCompressFile, 10));
   1.261 +	test(error == KErrNone);
   1.262 +
   1.263 +	TRAP(error, DecompressFileL(TheCompressFile, TheDecompressFile, 10));
   1.264 +	test(error == KErrNone);
   1.265 +	
   1.266 +	TInt bufferSize = 10 * TheBufferSize;
   1.267 +	
   1.268 +#if !defined(__WINS__)
   1.269 +	DeleteFile(TheCompressFile);
   1.270 +	DeleteFile(TheDecompressFile);
   1.271 +#endif
   1.272 +
   1.273 +	//Compress & decompress the same file again to overwrite the existing file & 
   1.274 +	//..to verify that the existing files can be re-used & with buffer size as big
   1.275 +	TRAP(error, CompressFileL(TheInputFile, TheCompressFile, bufferSize));
   1.276 +	test(error == KErrNone);
   1.277 +	
   1.278 +	TRAP(error, DecompressFileL(TheCompressFile, TheDecompressFile, bufferSize));
   1.279 +	test(error == KErrNone);
   1.280 +	
   1.281 +#if !defined(__WINS__)
   1.282 +	DeleteFile(TheCompressFile);
   1.283 +	DeleteFile(TheDecompressFile);
   1.284 +#endif
   1.285 +
   1.286 +	}
   1.287 +
   1.288 +TInt RfileInitForCEZFileToGZip(TAny*)
   1.289 +	{
   1.290 +	RFile rfile;
   1.291 +	TFileName compressFilePath(KOutputFilePath);
   1.292 +	compressFilePath.Append(TheCompressFile);
   1.293 +	
   1.294 +	CTrapCleanup* cleanup = CTrapCleanup::New();
   1.295 +	TRAPD(error, CEZFileToGZip::NewL(TheFs, compressFilePath, rfile, TheBufferSize));
   1.296 +	delete cleanup;
   1.297 +	
   1.298 +	return error;
   1.299 +	}
   1.300 +	
   1.301 +TInt RfileInitForCEZGZipToFile(TAny*)
   1.302 +	{
   1.303 +	RFile rfile;
   1.304 +	TFileName compressFilePath(KOutputFilePath);
   1.305 +	compressFilePath.Append(TheCompressFile);
   1.306 +
   1.307 +	CTrapCleanup* cleanup = CTrapCleanup::New();
   1.308 +	TRAPD(error, CEZGZipToFile::NewL(TheFs, compressFilePath, rfile, TheBufferSize));
   1.309 +	delete cleanup;
   1.310 +	
   1.311 +	return error;
   1.312 +	
   1.313 +	}
   1.314 +
   1.315 +/**
   1.316 +@SYMTestCaseID          SYSLIB-EZLIB2-UT-4288
   1.317 +@SYMTestCaseDesc	    CEZFileToGZip & CEZGZipToFile class initialisation fails when 
   1.318 +						invalid input RFile object supplied
   1.319 +@SYMTestPriority 	    High
   1.320 +@SYMTestActions  	    1.	Pass NULL RFile input parameter to CEZFileToGZip::NewL()
   1.321 +						2.	Pass NULL RFile input parameter to CEZGZipToFile::NewL()
   1.322 +@SYMTestExpectedResults NewL() method should panic & the test must not fail 
   1.323 +@SYMDEF                 REQ8024
   1.324 +*/
   1.325 +void TestRFileInitialisation()
   1.326 +	{
   1.327 +	test.Printf(_L("Panic Thread: CEZFileToGzip Class initialisation fails when invalid input rfile supplied"));	
   1.328 +	ThreadForPanicTest(RfileInitForCEZFileToGZip);
   1.329 +	test.Printf(_L("Panic Thread: CEZGZipToFile Class initialisation fails when invalid input rfile supplied"));
   1.330 +	ThreadForPanicTest(RfileInitForCEZGZipToFile);
   1.331 +	}
   1.332 +	
   1.333 +/**
   1.334 +@SYMTestCaseID          SYSLIB-EZLIB2-UT-4289
   1.335 +@SYMTestCaseDesc	    CEZFileToGZip, CEZGZipToFile class initialisation fails 
   1.336 +						when invalid output filename supplied
   1.337 +@SYMTestPriority 	    High
   1.338 +@SYMTestActions  	    1.	Pass invalid filename output parameter to CEZFileToGZip::NewL()
   1.339 +						2.	Pass invalid filename output parameter to CEZGZipToFile::NewL() 
   1.340 +						Note: Filename contains invalid characters
   1.341 +@SYMTestExpectedResults NewL() method should leave with error message & the test must not fail 
   1.342 +@SYMDEF                 REQ8024
   1.343 +*/	
   1.344 +void TestInvalidFilenameL()
   1.345 +	{
   1.346 +	
   1.347 +	_LIT(KInvalidGzip, "*******.gz");
   1.348 +	TFileName invalidGzip(KOutputFilePath);
   1.349 +	invalidGzip.Append(KInvalidGzip);
   1.350 +
   1.351 +	_LIT(KInvalidFile, "*******.txt");
   1.352 +	TFileName invalidFile(KOutputFilePath);
   1.353 +	invalidFile.Append(KInvalidFile);
   1.354 +	
   1.355 +	TFileName inputFilePath(KPath);
   1.356 +	inputFilePath.Append(TheInputFile);
   1.357 +
   1.358 +	RFile input;
   1.359 +	User::LeaveIfError(input.Open(TheFs,inputFilePath,EFileStream | EFileRead | EFileShareReadersOnly));
   1.360 +	CleanupClosePushL(input);
   1.361 +
   1.362 +	TRAPD(error, CEZFileToGZip::NewL(TheFs, invalidGzip, input, TheBufferSize));
   1.363 +	test(error != KErrNone);
   1.364 +
   1.365 +	CleanupStack::PopAndDestroy(1);
   1.366 +	
   1.367 +	RFile output;
   1.368 +	TInt err = output.Create(TheFs, invalidFile,EFileStream | EFileWrite | EFileShareExclusive);
   1.369 +	test(error != KErrNone);
   1.370 +
   1.371 +	}
   1.372 +
   1.373 +/**
   1.374 +@SYMTestCaseID          SYSLIB-EZLIB2-UT-4290
   1.375 +@SYMTestCaseDesc	    Ensure if output file exists and is read only then it cannot be 
   1.376 +						overwritten with CEZFileToGZip & CEZGZipToFile class
   1.377 +@SYMTestPriority 	    High
   1.378 +@SYMTestActions  	    1.	Pass existing read only output filename parameter to CEZFileToGZip::NewL()
   1.379 +						2.	Pass existing read only output filename parameter to CEZGZipToFile::NewL() 
   1.380 +						& decompress using CEZGZipToFile::InflateL()
   1.381 +@SYMTestExpectedResults CEZFileToGZip::NewL() method should leave with error message, CEZGZipToFile::Inflate()
   1.382 +						should leave with error message & the test must not fail 
   1.383 +@SYMDEF                 REQ8024
   1.384 +*/	
   1.385 +void TestOverwriteOutputFileL()
   1.386 +	{
   1.387 +	_LIT(KReadOnlyGzip, "Hello_Read_Only.gz");	
   1.388 +	TFileName readOnlyNewGZip(KOutputFilePath);
   1.389 +	readOnlyNewGZip.Append(KReadOnlyGzip);
   1.390 +	
   1.391 +	_LIT(KReadOnlyFile, "Hello_Read_Only.txt");
   1.392 +	TFileName readOnlyNewFile(KOutputFilePath);
   1.393 +	readOnlyNewFile.Append(KReadOnlyFile);
   1.394 +
   1.395 +	CFileMan* fMan=CFileMan::NewL(TheFs);
   1.396 +	test(fMan!=NULL);
   1.397 +	CleanupStack::PushL(fMan);
   1.398 +	
   1.399 +#if !defined(__WINS__)
   1.400 +	TFileName readOnlyOldGZip(KPath);
   1.401 +	readOnlyOldGZip.Append(KReadOnlyGzip);
   1.402 +	TFileName readOnlyOldFile(KPath);
   1.403 +	readOnlyOldFile.Append(KReadOnlyFile);
   1.404 +
   1.405 +	RFile source;
   1.406 +	User::LeaveIfError(source.Open(TheFs,readOnlyOldGZip, EFileStream | EFileRead | EFileShareReadersOnly));
   1.407 +	CleanupClosePushL(source);
   1.408 +	TRAPD(error, fMan->Copy(source, readOnlyNewGZip));
   1.409 +	test(error == KErrNone);
   1.410 +	
   1.411 +	RFile source1;
   1.412 +	User::LeaveIfError(source1.Open(TheFs,readOnlyOldFile, EFileStream | EFileRead | EFileShareReadersOnly));
   1.413 +	CleanupClosePushL(source1);
   1.414 +	TRAP(error, fMan->Copy(source1, readOnlyNewFile));
   1.415 +	test(error == KErrNone);
   1.416 +
   1.417 +	CleanupStack::PopAndDestroy(2);
   1.418 +#endif
   1.419 +
   1.420 +	TFileName inputFilePath(KPath);
   1.421 +	inputFilePath.Append(TheInputFile);
   1.422 +
   1.423 +	RFile input;
   1.424 +	User::LeaveIfError(input.Open(TheFs,inputFilePath,EFileStream | EFileRead | EFileShareReadersOnly));
   1.425 +	CleanupClosePushL(input);
   1.426 +
   1.427 +	//setting attributes to read only for readOnlyGZip & readOnlyFile
   1.428 +   	TInt err = fMan->Attribs(readOnlyNewGZip, KEntryAttReadOnly, 0, 0);
   1.429 +	test(err == KErrNone);
   1.430 +	err = fMan->Attribs(readOnlyNewFile, KEntryAttReadOnly, 0, 0);
   1.431 +	test(err == KErrNone);
   1.432 +		
   1.433 +	TRAP(err, CEZFileToGZip::NewL(TheFs, readOnlyNewGZip, input, TheBufferSize));
   1.434 +	test(err != KErrNone);
   1.435 +
   1.436 +	RFile output;
   1.437 +	User::LeaveIfError(output.Open(TheFs,readOnlyNewFile,EFileStream | EFileRead | EFileShareReadersOnly));
   1.438 +	CleanupClosePushL(output);
   1.439 +
   1.440 +	CEZGZipToFile * gzipToFile = NULL;
   1.441 +	TRAP(err, gzipToFile = CEZGZipToFile::NewL(TheFs, readOnlyNewGZip, output, TheBufferSize));
   1.442 +	test(err == KErrNone);
   1.443 +	CleanupStack::PushL(gzipToFile);
   1.444 +	
   1.445 +	while (err == KErrNone)
   1.446 +	{
   1.447 +		TRAP(err, gzipToFile->InflateL());
   1.448 +	}
   1.449 +	
   1.450 +	test(err != KErrNone); 	
   1.451 +
   1.452 +	CleanupStack::PopAndDestroy(4);
   1.453 +	
   1.454 +	//removing the read only attrib before deleting the file
   1.455 +   	fMan=CFileMan::NewL(TheFs);
   1.456 +   	test(fMan!=NULL);
   1.457 +   	CleanupStack::PushL(fMan);
   1.458 +   	err = fMan->Attribs(readOnlyNewGZip, 0, KEntryAttReadOnly, 0);
   1.459 +	test(err == KErrNone);
   1.460 +	err = fMan->Attribs(readOnlyNewFile, 0, KEntryAttReadOnly, 0);
   1.461 +	test(err == KErrNone);
   1.462 +	
   1.463 +	CleanupStack::PopAndDestroy(1);
   1.464 +	
   1.465 +#if !defined(__WINS__)
   1.466 +	DeleteFile(readOnlyNewGZip, ETrue);
   1.467 +	DeleteFile(readOnlyNewFile, ETrue);
   1.468 +#endif
   1.469 +	}
   1.470 +
   1.471 +TInt RFSInitForCEZFileToGZipL(TAny*)
   1.472 +	{
   1.473 +	TFileName inputFilePath(KPath);
   1.474 +	inputFilePath.Append(TheInputFile);
   1.475 +
   1.476 +	RFile input;
   1.477 +	User::LeaveIfError(input.Open(TheFs,inputFilePath,EFileStream | EFileRead | EFileShareReadersOnly));
   1.478 +	CleanupClosePushL(input);
   1.479 +
   1.480 +	TFileName compressFilePath(KOutputFilePath);
   1.481 +	compressFilePath.Append(TheCompressFile);
   1.482 +
   1.483 +	CTrapCleanup* cleanup = CTrapCleanup::New();
   1.484 +	RFs rfs; 
   1.485 +	TRAPD(error, CEZFileToGZip::NewL(rfs, compressFilePath, input, TheBufferSize));
   1.486 +	delete cleanup;
   1.487 +	
   1.488 +	CleanupStack::PopAndDestroy(1);
   1.489 +	return error;
   1.490 +	
   1.491 +	}
   1.492 +
   1.493 +TInt RFSInitForCEZGZipToFileL(TAny*)
   1.494 +	{
   1.495 +	TFileName compressFilePath(KPath);
   1.496 +	compressFilePath.Append(TheCompressFile);
   1.497 +	
   1.498 +	TFileName decompressFilePath(KOutputFilePath);
   1.499 +	decompressFilePath.Append(TheDecompressFile);
   1.500 +
   1.501 +	RFile output;
   1.502 +	User::LeaveIfError(output.Replace(TheFs,decompressFilePath,EFileStream | EFileRead | EFileShareReadersOnly));
   1.503 +	CleanupClosePushL(output);
   1.504 +
   1.505 +	CTrapCleanup* cleanup = CTrapCleanup::New();
   1.506 +	RFs rfs; 
   1.507 +	TRAPD(error, CEZGZipToFile::NewL(rfs, compressFilePath, output, TheBufferSize));
   1.508 +	delete cleanup;
   1.509 +	
   1.510 +	CleanupStack::PopAndDestroy(1);
   1.511 +	return error;
   1.512 +	
   1.513 +	}
   1.514 +
   1.515 +/**
   1.516 +@SYMTestCaseID          SYSLIB-EZLIB2-UT-4291
   1.517 +@SYMTestCaseDesc	    CEZFileToGZip & CEZGZipToFile class initialisation fails when 
   1.518 +						invalid RFs object is passed
   1.519 +@SYMTestPriority 	    High
   1.520 +@SYMTestActions  	    1.	Pass NULL RFs input parameter to CEZFileToGZip::NewL() 
   1.521 +						2.	Pass NULL RFs input parameter to CEZGZipToFile::NewL()
   1.522 +@SYMTestExpectedResults NewL() method should panic & the test must not fail 
   1.523 +@SYMDEF                 REQ8024
   1.524 +*/	
   1.525 +void TestRFSInitialisation()
   1.526 +	{
   1.527 +	test.Printf(_L("Panic Thread: CEZFileToGZip Class initialisation fails when invalid RFS object is passed"));	
   1.528 +	ThreadForPanicTest(RFSInitForCEZFileToGZipL);
   1.529 +	test.Printf(_L("Panic Thread: CEZGZipToFile Class initialisation fails when invalid RFS object is passed"));
   1.530 +	ThreadForPanicTest(RFSInitForCEZGZipToFileL);
   1.531 +	}
   1.532 +
   1.533 +TInt BuffForEZFileToGZipAsZeroL(TAny*)
   1.534 +	{
   1.535 +	CTrapCleanup* cleanup = CTrapCleanup::New();
   1.536 +	CompressFileL(TheInputFile, TheCompressFile, 0);
   1.537 +	delete cleanup;
   1.538 +	return KErrNone;
   1.539 +	}
   1.540 +
   1.541 +TInt BuffForEZFileToGZipAsNegativeL(TAny*)
   1.542 +	{
   1.543 +	CTrapCleanup* cleanup = CTrapCleanup::New();
   1.544 +	CompressFileL(TheInputFile, TheCompressFile, -1);
   1.545 +	delete cleanup;
   1.546 +	return KErrNone;
   1.547 +	}
   1.548 +
   1.549 +TInt BuffForEZGZipToFileAsZeroL(TAny*)
   1.550 +	{
   1.551 +	CTrapCleanup* cleanup = CTrapCleanup::New();
   1.552 +	DecompressFileL(TheCompressFile, TheDecompressFile, 0);
   1.553 +	delete cleanup;
   1.554 +	return KErrNone;
   1.555 +	}
   1.556 +
   1.557 +TInt BuffForEZGZipToFileAsNegativeL(TAny*)
   1.558 +	{
   1.559 +	CTrapCleanup* cleanup = CTrapCleanup::New();
   1.560 +	DecompressFileL(TheCompressFile, TheDecompressFile, -1);
   1.561 +	delete cleanup;
   1.562 +	return KErrNone;	
   1.563 +	}
   1.564 +
   1.565 +/**
   1.566 +@SYMTestCaseID          SYSLIB-EZLIB2-UT-4292
   1.567 +@SYMTestCaseDesc	    CEZFileToGZip & CEZGZipToFile class initialisation 
   1.568 +						fails when invalid buffer size parameter passed in
   1.569 +@SYMTestPriority 	    High
   1.570 +@SYMTestActions  	    1.	Pass buffer size parameter value as 0 to CEZFileToGZip::NewL()  
   1.571 +						2.	Pass buffer size parameter as a negative value to CEZFileToGZip::NewL()
   1.572 +						3.	Pass buffer size parameter value as 0 to CEZGZipToFile::NewL()  
   1.573 +						4.	Pass buffer size parameter as a negative value to CEZGZipToFile::NewL()
   1.574 +@SYMTestExpectedResults NewL() method should panic & the test must not fail 
   1.575 +@SYMDEF                 REQ8024
   1.576 +*/	
   1.577 +void TestInvalidBufferSize()
   1.578 +	{
   1.579 +	
   1.580 +	test.Printf(_L("Panic Thread: CEZFileToGZip Class initialisation fails when buffer size is passed as Zero"));	
   1.581 +	ThreadForPanicTest(BuffForEZFileToGZipAsZeroL);
   1.582 +	test.Printf(_L("Panic Thread: CEZFileToGZip Class initialisation fails when buffer size is passed as Negative"));
   1.583 +	ThreadForPanicTest(BuffForEZFileToGZipAsNegativeL);
   1.584 +	test.Printf(_L("Panic Thread: CEZGZipToFile Class initialisation fails when buffer size is passed as Zero"));
   1.585 +	ThreadForPanicTest(BuffForEZGZipToFileAsZeroL);
   1.586 +	test.Printf(_L("Panic Thread: CEZGZipToFile Class initialisation fails when buffer size is passed as Negative"));
   1.587 +	ThreadForPanicTest(BuffForEZGZipToFileAsNegativeL);
   1.588 +
   1.589 +	}
   1.590 +
   1.591 +/**
   1.592 +@SYMTestCaseID          SYSLIB-EZLIB2-UT-4293
   1.593 +@SYMTestCaseDesc	    Compress & Decompress another file with CEZFileToGZip & CEZGZipToFile 
   1.594 +						after calling ResetL method
   1.595 +@SYMTestPriority 	    High
   1.596 +@SYMTestActions  	    1.	Open existing test file and pass it to CEZFileToGZip::NewL() & compress using CEZFileToGZip::DeflateL function
   1.597 +						2.	Call CEZFileToGZip::ResetL() with new file parameters
   1.598 +						3.	Compress the new file with CEZFileToGZip::DeflateL()
   1.599 +						4.	Create or open output decompressed file and pass compressed file to CEZGZipToFile::NewL() & decompress using CEZGZipToFile::InflateL() function
   1.600 +						5.	Call CEZGZipToFile::ResetL() with new compressed file parameters
   1.601 +						6.	Decompress the new compressed file with CEZGZipToFile::InflateL()
   1.602 +@SYMTestExpectedResults Files should be compressed with no errors i.e. KErrNone & the test must not fail 
   1.603 +@SYMDEF                 REQ8024
   1.604 +*/	
   1.605 +void TestCompressDecompressResetL()
   1.606 +	{
   1.607 +    
   1.608 +	TFileName inputFilePath(KPath);
   1.609 +	inputFilePath.Append(TheInputFile);
   1.610 +
   1.611 +	_LIT(KGzipFile,"Hello_Reset.gz");
   1.612 +	TFileName gzipFileName(KGzipFile);
   1.613 +	TFileName compressfile(KOutputFilePath);
   1.614 +	compressfile.Append(gzipFileName);
   1.615 +	
   1.616 +	RFile input;
   1.617 +	User::LeaveIfError(input.Open(TheFs,inputFilePath,EFileStream | EFileRead | EFileShareReadersOnly));
   1.618 +	CleanupClosePushL(input);
   1.619 +	
   1.620 +	CEZFileToGZip *fileToGzip = CEZFileToGZip::NewLC(TheFs, compressfile, input, TheBufferSize);
   1.621 +	while(fileToGzip->DeflateL()){/*do nothing*/}
   1.622 +	
   1.623 +	fileToGzip->ResetL(TheFs, compressfile, input, TheBufferSize);
   1.624 +	while(fileToGzip->DeflateL()){/*do nothing*/}
   1.625 +	
   1.626 +	CleanupStack::PopAndDestroy(2);
   1.627 +	
   1.628 +#if !defined(__WINS__)
   1.629 +	DeleteFile(gzipFileName);
   1.630 +#endif
   1.631 +
   1.632 +	TFileName compressFilePath(KPath);
   1.633 +	compressFilePath.Append(TheCompressFile);
   1.634 +
   1.635 +	_LIT(KTxtFile,"Hello_Reset.txt");
   1.636 +	TFileName txtFileName(KTxtFile);
   1.637 +	TFileName decompressfile(KOutputFilePath);
   1.638 +	decompressfile.Append(txtFileName);
   1.639 +
   1.640 +	RFile output;
   1.641 +	User::LeaveIfError(output.Replace(TheFs, decompressfile,EFileStream | EFileWrite | EFileShareExclusive));
   1.642 +	CleanupClosePushL(output);
   1.643 +
   1.644 +	CEZGZipToFile *gzipToFile = CEZGZipToFile::NewLC(TheFs, compressFilePath, output, TheBufferSize);
   1.645 +	while(gzipToFile->InflateL()){/*do nothing*/}
   1.646 +
   1.647 +	gzipToFile->ResetL(TheFs, compressFilePath, output, TheBufferSize);
   1.648 +	while(gzipToFile->InflateL()){/*do nothing*/}
   1.649 +	
   1.650 +	CleanupStack::PopAndDestroy(2);
   1.651 +	
   1.652 +#if !defined(__WINS__)
   1.653 +	DeleteFile(txtFileName);
   1.654 +#endif
   1.655 +
   1.656 +	}
   1.657 +
   1.658 +/**
   1.659 +@SYMTestCaseID          SYSLIB-EZLIB2-UT-4294
   1.660 +@SYMTestCaseDesc	    CEZGZipToFile class initialisation fails when source 
   1.661 +						gzip file header is malformed: Header is too small
   1.662 +@SYMTestPriority 	    High
   1.663 +@SYMTestActions  	    Pass corrupted gzip file as an input parameter to CEZGZipToFile::NewL()  
   1.664 +						Note: Change the header of existing gzip file by removing few characters
   1.665 +@SYMTestExpectedResults NewL() method should leave with error message KEZlibErrBadGZipHeader 
   1.666 +						& the test must not fail 
   1.667 +@SYMDEF                 REQ8024
   1.668 +*/	
   1.669 +void TestGzipHeaderSmallL()
   1.670 +	{
   1.671 +	
   1.672 +	_LIT(KGzFile,"Hello_HeaderChanged.gz");	
   1.673 +	TFileName compressfile(KPath);
   1.674 +	compressfile.Append(KGzFile);
   1.675 +
   1.676 +	TFileName decompressFilePath(KOutputFilePath);
   1.677 +	decompressFilePath.Append(TheDecompressFile);
   1.678 +
   1.679 +	RFile output;
   1.680 +	User::LeaveIfError(output.Replace(TheFs, decompressFilePath,EFileStream | EFileWrite | EFileShareExclusive));
   1.681 +	CleanupClosePushL(output);
   1.682 +	
   1.683 +	TRAPD(error, CEZGZipToFile::NewL(TheFs, compressfile, output, TheBufferSize));
   1.684 +	test(error == KEZlibErrBadGZipHeader);
   1.685 +
   1.686 +	CleanupStack::PopAndDestroy(1);
   1.687 +
   1.688 +	}
   1.689 +
   1.690 +/**
   1.691 +@SYMTestCaseID          SYSLIB-EZLIB2-UT-4295
   1.692 +@SYMTestCaseDesc	    CEZGZipToFile class initialisation fails when source gzip file 
   1.693 +						header is malformed: Header ID number is incorrect
   1.694 +@SYMTestPriority 	    High
   1.695 +@SYMTestActions  	    Pass corrupted gzip file as an input parameter to CEZGZipToFile::NewL()  
   1.696 +						Note: Change the header ID of existing gzip file
   1.697 +@SYMTestExpectedResults NewL() method should leave with error message KEZlibErrBadGZipHeader 
   1.698 +						& the test must not fail 
   1.699 +@SYMDEF                 REQ8024
   1.700 +*/	
   1.701 +void TestGzipHeaderIdIncorrectL()
   1.702 +	{	
   1.703 +
   1.704 +	_LIT(KGzFile,"Hello_HeaderIdChanged.gz");
   1.705 +	TFileName compressfile(KPath);
   1.706 +	compressfile.Append(KGzFile);
   1.707 +
   1.708 +	TFileName decompressFilePath(KOutputFilePath);
   1.709 +	decompressFilePath.Append(TheDecompressFile);
   1.710 +
   1.711 +	RFile output;
   1.712 +	User::LeaveIfError(output.Replace(TheFs, decompressFilePath,EFileStream | EFileWrite | EFileShareExclusive));
   1.713 +	CleanupClosePushL(output);
   1.714 +	
   1.715 +	TRAPD(error, CEZGZipToFile::NewL(TheFs, compressfile, output, TheBufferSize));
   1.716 +	test(error == KEZlibErrBadGZipHeader);
   1.717 +	
   1.718 +	CleanupStack::PopAndDestroy(1);
   1.719 +	
   1.720 +	}
   1.721 +
   1.722 +/**
   1.723 +@SYMTestCaseID          SYSLIB-EZLIB2-UT-4296
   1.724 +@SYMTestCaseDesc	    CEZGZipToFile class fails while decompressing the gzip 
   1.725 +						file with the CRC changed in the trailer
   1.726 +@SYMTestPriority 	    High
   1.727 +@SYMTestActions  	    Pass corrupted gzip file as an input parameter to CEZGZipToFile::NewL()
   1.728 +						Note: Change the CRC within the Trailer of existing gzip file
   1.729 +@SYMTestExpectedResults NewL() method should leave with error message KErrNotFound & the test must not fail
   1.730 +						Note: KErrNotFound error is fired while opening the corrupted gzip file
   1.731 +@SYMDEF                 REQ8024
   1.732 +*/	
   1.733 +void TestGzipTrailerCRCL()
   1.734 +	{
   1.735 +
   1.736 +	_LIT(KGzFile,"Hello_TrailerIdChanged.gz");	
   1.737 +	TFileName compressfile(KPath);
   1.738 +	compressfile.Append(KGzFile);
   1.739 +
   1.740 +	TFileName decompressFilePath(KOutputFilePath);
   1.741 +	decompressFilePath.Append(TheDecompressFile);
   1.742 +
   1.743 +	RFile output;
   1.744 +	User::LeaveIfError(output.Replace(TheFs, decompressFilePath,EFileStream | EFileWrite | EFileShareExclusive));
   1.745 +	CleanupClosePushL(output);
   1.746 +	
   1.747 +	TRAPD(error, CEZGZipToFile::NewL(TheFs, compressfile, output, TheBufferSize));
   1.748 +	test(error == KErrNotFound);
   1.749 +	
   1.750 +	CleanupStack::PopAndDestroy(1);
   1.751 +
   1.752 +	}
   1.753 +
   1.754 +void TestCompressDecompressL()
   1.755 +	{
   1.756 +
   1.757 +	TFileName inputFilePath(KPath);
   1.758 +	inputFilePath.Append(TheInputFile);
   1.759 +	
   1.760 +	TFileName compressFilePath(KOutputFilePath);
   1.761 +	compressFilePath.Append(TheCompressFile);
   1.762 +
   1.763 +	RFile input;
   1.764 +	User::LeaveIfError(input.Open(TheFs,inputFilePath,EFileStream | EFileRead | EFileShareReadersOnly));
   1.765 +	CleanupClosePushL(input);
   1.766 +	
   1.767 +	CEZFileToGZip *fileToGzip = CEZFileToGZip::NewLC(TheFs, compressFilePath, input, TheBufferSize);
   1.768 +	while(fileToGzip->DeflateL()){/*do nothing*/}
   1.769 +	
   1.770 +	TFileName decompressFilePath(KOutputFilePath);
   1.771 +	decompressFilePath.Append(TheDecompressFile);
   1.772 +
   1.773 +	TFileName compressFilePath1(KPath);
   1.774 +	compressFilePath1.Append(TheCompressFile);
   1.775 +
   1.776 +	RFile output;
   1.777 +	User::LeaveIfError(output.Replace(TheFs, decompressFilePath,EFileStream | EFileWrite | EFileShareExclusive));
   1.778 +	CleanupClosePushL(output);
   1.779 +
   1.780 +	CEZGZipToFile *gzipToFile = CEZGZipToFile::NewLC(TheFs, compressFilePath1, output, TheBufferSize);
   1.781 +	while(gzipToFile->InflateL()){/*do nothing*/}
   1.782 +
   1.783 +	CleanupStack::PopAndDestroy(4);
   1.784 +	
   1.785 +#if !defined(__WINS__)
   1.786 +	DeleteFile(TheCompressFile);
   1.787 +	DeleteFile(TheDecompressFile);
   1.788 +#endif
   1.789 +	}
   1.790 +	
   1.791 +/**
   1.792 +@SYMTestCaseID          SYSLIB-EZLIB2-UT-4297
   1.793 +@SYMTestCaseDesc	    Out of Memory(OOM) test for CEZFileToGZip &  CEZGZipToFile class
   1.794 +@SYMTestPriority 	    High
   1.795 +@SYMTestActions  	    1.	Set Heap Failure using the macro as:
   1.796 +							__UHEAP_SETFAIL(RHeap::EDeterministic, count)
   1.797 +						2.	Mark the heap using macro: __UHEAP_MARK
   1.798 +						3.	Open existing test file and pass it to CEZFileToGZip::NewL() compress using CEZFileToGZip::DeflateL() function
   1.799 +						4.	Create or open output decompressed file and pass compressed file to CEZGZipToFile::NewL() & decompress using CEZGZipToFile::InflateL() function
   1.800 +						5.	Check there is no memory leak using the macro: __UHEAP_MARKEND
   1.801 +						6.	Repeat the Steps 1-5 increasing the heap value rate i.e. count
   1.802 +@SYMTestExpectedResults The test succeeds with no memory leak on the heap as well as no errors (i.e. KErrNone)
   1.803 +						& the test must not fail 
   1.804 +@SYMDEF                 REQ8024
   1.805 +*/	
   1.806 +void TestOOMGzipL()
   1.807 +	{
   1.808 +   	TInt processHandlesS = 0;
   1.809 +	TInt threadHandlesS = 0;
   1.810 +	TInt processHandlesE = 0;
   1.811 +	TInt threadHandlesE = 0;
   1.812 +	TInt err = KErrNone;
   1.813 +	RThread().HandleCount(processHandlesS, threadHandlesS);
   1.814 +	for(TInt count=1; count<=100; ++count)
   1.815 +		{
   1.816 +		// Setting Heap failure for OOM test
   1.817 +		__UHEAP_SETFAIL(RHeap::EDeterministic, count);
   1.818 +		__UHEAP_MARK;
   1.819 +		
   1.820 +		TRAP(err,TestCompressDecompressL());
   1.821 +		__UHEAP_MARKEND;
   1.822 +		if(err == KErrNone)
   1.823 +			{
   1.824 +			RDebug::Print(_L("The test succeeded at heap failure rate=%d.\n"), count);
   1.825 +			break;
   1.826 +			}
   1.827 +		else 
   1.828 +			{
   1.829 +			test(err == KErrNoMemory);
   1.830 +			}
   1.831 +		__UHEAP_RESET;
   1.832 +		}
   1.833 +	
   1.834 +	test(err == KErrNone);
   1.835 +	__UHEAP_RESET;
   1.836 +	
   1.837 +	RThread().HandleCount(processHandlesE, threadHandlesE);
   1.838 +	
   1.839 +	test(processHandlesS == processHandlesE);
   1.840 +	test(threadHandlesS == threadHandlesE);
   1.841 +
   1.842 +	}
   1.843 +/*
   1.844 + * Helper function for TestDEF117325ToGZipL
   1.845 + * Deflates a file and then calls ResetL()
   1.846 + */
   1.847 +void DeflateResetL()
   1.848 +	{
   1.849 +	_LIT(KGzipFile,"Hello_Reset.gz");
   1.850 +	TFileName compressFile(KOutputFilePath);
   1.851 +	compressFile.Append(KGzipFile);
   1.852 +
   1.853 +	TFileName inputFilePath(KPath);
   1.854 +	inputFilePath.Append(TheInputFile);
   1.855 +	
   1.856 +	RFile input;	
   1.857 +	User::LeaveIfError(input.Open(TheFs, inputFilePath, EFileStream | EFileRead | EFileShareReadersOnly));
   1.858 +	CleanupClosePushL(input);
   1.859 +		
   1.860 +	CEZFileToGZip *fileToGzip = CEZFileToGZip::NewLC(TheFs, compressFile, input, TheBufferSize);
   1.861 +	while(fileToGzip->DeflateL()) {/*do nothing*/}
   1.862 +	
   1.863 +	fileToGzip->ResetL(TheFs, compressFile, input, TheBufferSize);
   1.864 +	
   1.865 +	CleanupStack::PopAndDestroy(2);
   1.866 +	
   1.867 +	#if !defined(__WINS__)
   1.868 +	DeleteFile(TheInputFile);
   1.869 +	#endif
   1.870 +	}
   1.871 +
   1.872 +/*
   1.873 + * Helper function for TestDEF117325ToFileL
   1.874 + * Inflates a GZip file and then calls ResetL()
   1.875 + */
   1.876 +void InflateResetL()
   1.877 +	{
   1.878 +	_LIT(KTxtFile, "Hello_Reset.txt");
   1.879 +	TFileName decompressFile(KOutputFilePath);
   1.880 +	decompressFile.Append(KTxtFile);
   1.881 +
   1.882 +	TFileName compressFilePath(KPath);
   1.883 +	compressFilePath.Append(TheCompressFile);
   1.884 +		
   1.885 +	RFile output;
   1.886 +	User::LeaveIfError(output.Replace(TheFs, decompressFile, EFileStream | EFileWrite | EFileShareExclusive));
   1.887 +	CleanupClosePushL(output);
   1.888 +	
   1.889 +	CEZGZipToFile *gzipToFile = CEZGZipToFile::NewLC(TheFs, compressFilePath, output, TheBufferSize);
   1.890 +	while(gzipToFile->InflateL()){/*do nothing*/}
   1.891 +	
   1.892 +	gzipToFile->ResetL(TheFs, compressFilePath, output, TheBufferSize);
   1.893 +	
   1.894 +	CleanupStack::PopAndDestroy(2);
   1.895 +	
   1.896 +	#if !defined(__WINS__)
   1.897 +	DeleteFile(TheCompressFile);
   1.898 +	#endif
   1.899 +	}
   1.900 +
   1.901 +/*
   1.902 + * Helper function for TestDEF117325ToGZipL and TestDEF117325ToFileL.
   1.903 + * Checks for memory leaks in OOM situations.
   1.904 + */
   1.905 +void DEF117325L(void (*aResetL)())
   1.906 +	{
   1.907 +	TInt err = KErrNone;
   1.908 +	for(TInt count = 0; count <= 100; count++)
   1.909 +		{
   1.910 +		// Setting Heap failure for OOM test
   1.911 +		__UHEAP_SETFAIL(RHeap::EDeterministic, count);
   1.912 +		__UHEAP_MARK;	
   1.913 +		
   1.914 +		TRAP(err, aResetL());
   1.915 +		
   1.916 +		__UHEAP_MARKEND;
   1.917 +		__UHEAP_RESET;
   1.918 +		
   1.919 +		if(err == KErrNone)
   1.920 +			{
   1.921 +			RDebug::Print(_L("The test succeeded at heap failure rate = %d.\n"), count);
   1.922 +			break;
   1.923 +			}
   1.924 +		else 
   1.925 +			{
   1.926 +			test(err == KErrNoMemory);
   1.927 +			}
   1.928 +		}
   1.929 +	}
   1.930 +
   1.931 +/**
   1.932 +@SYMTestCaseID          SYSLIB-EZLIB2-UT-4319
   1.933 +@SYMTestCaseDesc	    To test that there are no memory leaks when calling ResetL from CEZFileToGZip
   1.934 +@SYMTestPriority 	    Medium
   1.935 +@SYMTestActions  	    1.	Set Heap Failure using the macro __UHEAP_SETFAIL(RHeap::EDeterministic, count)
   1.936 +						2.	Mark the heap using macro __UHEAP_MARK
   1.937 +						3.	Open an existing test file and pass it to CEZFileToGZip::NewL() and compress it using CEZFileToGZip::DeflateL function
   1.938 +						4.	Call CEZFileToGZip::ResetL() with new file parameters
   1.939 +						5.	Check there is no memory leak using the macro __UHEAP_MARKEND
   1.940 +						6.	Repeat steps 1 - 5 increasing the heap value rate i.e. count
   1.941 +@SYMTestExpectedResults The test succeeds with no memory leak on the heap as well as no errors (i.e. KErrNone) 
   1.942 +@SYMDEF                 REQ8024
   1.943 +*/	
   1.944 +void TestDEF117325ToGZipL()
   1.945 +	{		
   1.946 +	DEF117325L(&DeflateResetL);
   1.947 +	}
   1.948 +
   1.949 +/**
   1.950 +@SYMTestCaseID          SYSLIB-EZLIB2-UT-4320
   1.951 +@SYMTestCaseDesc	    To test that there are no memory leaks when calling ResetL from CEZGZipToFile
   1.952 +@SYMTestPriority 	    Medium
   1.953 +@SYMTestActions  	    1.	Open an existing test file and pass it to CEZFileToGZip::NewL() and compress it using CEZFileToGZip::DeflateL 
   1.954 +						2.	Set Heap Failure using the macro __UHEAP_SETFAIL(RHeap::EDeterministic, count)
   1.955 +						3.	Mark the heap using macro __UHEAP_MARK
   1.956 +						4.	Open the compressed test file and pass it to CEZGZipToFile::NewL() and decompress it using CEZGZipToFile::InflateL function
   1.957 +						5.	Call CEZGZipToFile::ResetL() with new file parameters
   1.958 +						6.	Check there is no memory leak using the macro __UHEAP_MARKEND
   1.959 +						7.	Repeat steps 2 - 6 increasing the heap value rate i.e. count
   1.960 +@SYMTestExpectedResults The test succeeds with no memory leak on the heap as well as no errors (i.e. KErrNone)
   1.961 +@SYMDEF                 REQ8024
   1.962 +*/	
   1.963 +void TestDEF117325ToFileL()
   1.964 +	{	
   1.965 +	
   1.966 +	// Create a GZip file that can be used by CEZGZipToFile
   1.967 +	CompressFileL(TheInputFile, TheCompressFile);
   1.968 +	
   1.969 +	DEF117325L(&InflateResetL);
   1.970 +	
   1.971 +	#if !defined(__WINS__)
   1.972 +	DeleteFile(TheCompressFile);
   1.973 +	#endif
   1.974 +	}
   1.975 +
   1.976 +	
   1.977 +
   1.978 +void RunTestL()
   1.979 +	{
   1.980 +	
   1.981 +	User::LeaveIfError(TheFs.Connect()); //Connect to file session
   1.982 +	CleanupClosePushL(TheFs);
   1.983 +	
   1.984 +#if !defined(__WINS__)
   1.985 +	TInt err = TheFs.MkDirAll(KOutputFilePath);  
   1.986 +	if(err != KErrNone && err != KErrAlreadyExists)
   1.987 +		{
   1.988 +		test.Printf(_L("Error while creating dir => Error: %d"), err);
   1.989 +		User::Leave(err);
   1.990 +		}
   1.991 +#endif
   1.992 +	
   1.993 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4286 Compression - Decompression of Gzip file "));
   1.994 +	TestCompressDecompressGzip();
   1.995 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4287 Compression - Decompression of Gzip file with big & small buffer size "));
   1.996 +	TestOutputBuffSize();
   1.997 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4288 Class initialisation fails when invalid input rfile supplied "));
   1.998 +	TestRFileInitialisation();
   1.999 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4289 Class initialisation fails when invalid output filename supplied "));
  1.1000 +	TestInvalidFilenameL();
  1.1001 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4290 Class initialisation fails while overwriting the read only output file "));
  1.1002 +	TestOverwriteOutputFileL();
  1.1003 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4291 Class initialisation fails when invalid RFS object is passed "));
  1.1004 +	TestRFSInitialisation();
  1.1005 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4292 Panic Thread: Class initialisation fails when invalid buffer size parameter passed in "));
  1.1006 +	TestInvalidBufferSize();
  1.1007 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4293 Compress another file with CEZFileToGZip & CEZGZipToFile after calling ResetL method "));
  1.1008 +	TestCompressDecompressResetL();
  1.1009 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4294 CEZGZipToFile class initialisation fails when source gzip file header is malformed: Header is too small "));
  1.1010 +	TestGzipHeaderSmallL();
  1.1011 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4295 CEZGZipToFile class initialisation fails when source gzip file header is malformed: Header ID number is incorrect "));
  1.1012 +	TestGzipHeaderIdIncorrectL();
  1.1013 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4296 CEZGZipToFile class fails while decompressing the gzip file with the CRC changed in the trailer "));
  1.1014 +	TestGzipTrailerCRCL();
  1.1015 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4297 Out of Memory(OOM) test for CEZFileToGZip & CEZGZipToFile class "));
  1.1016 +	TestOOMGzipL();
  1.1017 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4319 Out of Memory(OOM) test for DEF117325: Ezlib: ResetL() in gzip.cpp - a member variable can be deleted twice (CEZFileToGZip) "));
  1.1018 +	TestDEF117325ToGZipL();
  1.1019 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4320 Out of Memory(OOM) test for DEF117325: Ezlib: ResetL() in gzip.cpp - a member variable can be deleted twice (CEZGZipToFile) "));
  1.1020 +	TestDEF117325ToFileL();
  1.1021 +		
  1.1022 +
  1.1023 +#if !defined(__WINS__)
  1.1024 +	CFileMan* fMan=CFileMan::NewL(TheFs);
  1.1025 +   	test(fMan!=NULL);
  1.1026 +   	CleanupStack::PushL(fMan);
  1.1027 + 	err = fMan->RmDir(_L("C:\\test\\gzip"));
  1.1028 + 	CleanupStack::PopAndDestroy(1);
  1.1029 +#endif
  1.1030 + 	
  1.1031 + 	CleanupStack::PopAndDestroy(1);
  1.1032 +	
  1.1033 +	}	
  1.1034 +
  1.1035 +GLDEF_C TInt E32Main()
  1.1036 +	{
  1.1037 +	
  1.1038 +	__UHEAP_MARK;
  1.1039 +
  1.1040 +	test.Printf(_L("\n"));
  1.1041 +	test.Title();
  1.1042 +	test.Start( _L("Starting Gzip Tests..") );
  1.1043 +
  1.1044 +	TheTrapCleanup=CTrapCleanup::New();
  1.1045 +
  1.1046 +	TRAPD(err,RunTestL());
  1.1047 +	test (err==KErrNone);
  1.1048 +
  1.1049 +	test.End();
  1.1050 +	test.Close();
  1.1051 +	
  1.1052 +	delete TheTrapCleanup;
  1.1053 +
  1.1054 +	__UHEAP_MARKEND;
  1.1055 +	return KErrNone;
  1.1056 +
  1.1057 +	}