os/ossrv/compressionlibs/ziplib/test/rtest/gziptest/gziptest.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <e32test.h>
sl@0
    17
#include <ezgzip.h>
sl@0
    18
sl@0
    19
#if !defined(__WINS__)
sl@0
    20
_LIT(KPath, "Z:\\test\\gzip\\");
sl@0
    21
#else
sl@0
    22
_LIT(KPath, "C:\\test\\gzip\\");
sl@0
    23
#endif
sl@0
    24
sl@0
    25
_LIT(KOutputFilePath, "C:\\test\\gzip\\");
sl@0
    26
sl@0
    27
_LIT(KInputFile, "Hello.txt");
sl@0
    28
_LIT(KCompressFile,"Hello.gz");
sl@0
    29
_LIT(KDecompressFile,"Hello_Decompress.txt");
sl@0
    30
sl@0
    31
sl@0
    32
static RTest				test(_L("gziptest.exe"));
sl@0
    33
static RFs					TheFs;
sl@0
    34
static CTrapCleanup* 		TheTrapCleanup 		= NULL;
sl@0
    35
static TInt 				TheBufferSize		= 500;
sl@0
    36
static TFileName 			TheInputFile(KInputFile);
sl@0
    37
static TFileName 			TheCompressFile(KCompressFile);
sl@0
    38
static TFileName 			TheDecompressFile(KDecompressFile);
sl@0
    39
sl@0
    40
static void CompressFileL(TFileName& aInputFile, TFileName& aCompressFile, TInt aBufferSize = TheBufferSize);
sl@0
    41
static void DecompressFileL(TFileName& aInputFile, TFileName& aDecompressFile, TInt aBufferSize = TheBufferSize);
sl@0
    42
static void CompareFileDataL(TFileName& aSourceFile, TFileName& aDestFile, TInt& aCompare);
sl@0
    43
static void ThreadForPanicTest(TThreadFunction aPanicThreadFunc);
sl@0
    44
sl@0
    45
inline void DeleteFile(TFileName& aFileName, TBool aPathSpecified = EFalse)
sl@0
    46
	{
sl@0
    47
	TFileName deleteFilePath;
sl@0
    48
	if(!aPathSpecified)
sl@0
    49
		{
sl@0
    50
		deleteFilePath.Append(KOutputFilePath);
sl@0
    51
		}
sl@0
    52
	deleteFilePath.Append(aFileName);
sl@0
    53
sl@0
    54
	TRAPD(error, TheFs.Delete(deleteFilePath));
sl@0
    55
	if(error != KErrNone)
sl@0
    56
		test.Printf(_L("File not deleted: %S"), &deleteFilePath);
sl@0
    57
	}
sl@0
    58
	
sl@0
    59
static void CompressFileL(TFileName& aInputFile, TFileName& aCompressFile, TInt aBufferSize)
sl@0
    60
	{
sl@0
    61
	TFileName inputFilePath(KPath);
sl@0
    62
	inputFilePath.Append(aInputFile);
sl@0
    63
	
sl@0
    64
	TFileName compressFilePath(KOutputFilePath);
sl@0
    65
	compressFilePath.Append(aCompressFile);
sl@0
    66
	
sl@0
    67
	RFile input;
sl@0
    68
	User::LeaveIfError(input.Open(TheFs,inputFilePath, EFileStream | EFileRead | EFileShareReadersOnly));
sl@0
    69
	CleanupClosePushL(input);
sl@0
    70
	
sl@0
    71
	CEZFileToGZip *fileToGzip = NULL;
sl@0
    72
	TRAPD(error, fileToGzip = CEZFileToGZip::NewL(TheFs, compressFilePath, input, aBufferSize));
sl@0
    73
	test(error == KErrNone);
sl@0
    74
	CleanupStack::PushL(fileToGzip);
sl@0
    75
	
sl@0
    76
	while(fileToGzip->DeflateL()){/*do nothing*/}
sl@0
    77
	
sl@0
    78
	CleanupStack::PopAndDestroy(2);
sl@0
    79
	}
sl@0
    80
	
sl@0
    81
static void DecompressFileL(TFileName& aCompressFile, TFileName& aDecompressFile, TInt aBufferSize)
sl@0
    82
	{
sl@0
    83
sl@0
    84
	TFileName compressFilePath(KPath);
sl@0
    85
	compressFilePath.Append(aCompressFile);
sl@0
    86
	
sl@0
    87
	TFileName decompressFilePath(KOutputFilePath);
sl@0
    88
	decompressFilePath.Append(aDecompressFile);
sl@0
    89
sl@0
    90
	RFile output;
sl@0
    91
	User::LeaveIfError(output.Replace(TheFs, decompressFilePath, EFileStream | EFileWrite | EFileShareExclusive));
sl@0
    92
	CleanupClosePushL(output);
sl@0
    93
sl@0
    94
	CEZGZipToFile *gzipToFile = NULL;
sl@0
    95
	TRAPD(error, gzipToFile = CEZGZipToFile::NewL(TheFs, compressFilePath, output, aBufferSize));
sl@0
    96
	test(error == KErrNone);
sl@0
    97
	CleanupStack::PushL(gzipToFile);
sl@0
    98
	
sl@0
    99
	while (gzipToFile->InflateL()){/*do nothing*/}
sl@0
   100
sl@0
   101
	CleanupStack::PopAndDestroy(2);
sl@0
   102
	
sl@0
   103
	}
sl@0
   104
	
sl@0
   105
static void CompareFileDataL(TFileName& aSourceFile, TFileName& aDestFile, TInt& aCompare)
sl@0
   106
	{
sl@0
   107
	
sl@0
   108
	TFileName sourceFilePath(KPath);
sl@0
   109
	sourceFilePath.Append(aSourceFile);
sl@0
   110
sl@0
   111
	TFileName destFilePath(KOutputFilePath);
sl@0
   112
	destFilePath.Append(aDestFile);
sl@0
   113
sl@0
   114
	RFile source;
sl@0
   115
	User::LeaveIfError(source.Open(TheFs,sourceFilePath, EFileStream | EFileRead | EFileShareReadersOnly));
sl@0
   116
	CleanupClosePushL(source);
sl@0
   117
		
sl@0
   118
	TInt sourceSize;
sl@0
   119
	source.Size(sourceSize);
sl@0
   120
	test(sourceSize > 0);
sl@0
   121
		
sl@0
   122
	HBufC8* sourceData = NULL;
sl@0
   123
	TRAPD(error, sourceData = HBufC8::NewMaxL(sourceSize));
sl@0
   124
	test(error == KErrNone);
sl@0
   125
	CleanupStack::PushL(sourceData);
sl@0
   126
			
sl@0
   127
	TPtr8 tSourceBufPtr = sourceData->Des();
sl@0
   128
	User::LeaveIfError(source.Read(0, tSourceBufPtr, sourceSize));
sl@0
   129
	
sl@0
   130
	RFile dest;
sl@0
   131
	User::LeaveIfError(dest.Open(TheFs,destFilePath, EFileStream | EFileWrite | EFileShareExclusive));
sl@0
   132
	CleanupClosePushL(dest);
sl@0
   133
sl@0
   134
	TInt destSize;
sl@0
   135
	dest.Size(destSize);
sl@0
   136
	test(destSize > 0);
sl@0
   137
	
sl@0
   138
	HBufC8* destData = NULL;
sl@0
   139
	TRAP(error, destData = HBufC8::NewMaxL(destSize));
sl@0
   140
	test(error == KErrNone);
sl@0
   141
	CleanupStack::PushL(destData);
sl@0
   142
			
sl@0
   143
	TPtr8 tDestBufPtr = destData->Des();
sl@0
   144
	User::LeaveIfError(dest.Read(0, tDestBufPtr, destSize));
sl@0
   145
		
sl@0
   146
	aCompare = sourceData->Compare(*destData);
sl@0
   147
sl@0
   148
	CleanupStack::PopAndDestroy(4);
sl@0
   149
	
sl@0
   150
	}
sl@0
   151
sl@0
   152
static void ThreadForPanicTest(TThreadFunction aPanicThreadFunc)
sl@0
   153
	{
sl@0
   154
   	TRequestStatus threadStatus(KRequestPending);
sl@0
   155
   	TRequestStatus threadStatus1(KRequestPending); 
sl@0
   156
   	
sl@0
   157
   	RThread thread;
sl@0
   158
	TBool justInTime = User::JustInTime();
sl@0
   159
	User::SetJustInTime(EFalse);
sl@0
   160
		
sl@0
   161
	test.Printf(_L("Starting thread for invalid panic test...\n"));
sl@0
   162
	TInt err=thread.Create(	_L("Panic thread"),aPanicThreadFunc,KDefaultStackSize,0x1000,0x1000,NULL,EOwnerThread );
sl@0
   163
	
sl@0
   164
	test.Printf(_L("Thread Creation returned following error code: %d \n"), err);
sl@0
   165
	test(err == KErrNone);
sl@0
   166
sl@0
   167
	thread.Logon(threadStatus);
sl@0
   168
	thread.Resume();
sl@0
   169
	User::WaitForRequest(threadStatus);
sl@0
   170
sl@0
   171
#ifdef _DEBUG
sl@0
   172
	__ASSERT_ALWAYS(thread.ExitType() == EExitPanic,User::Panic(_L("Thread panic mismatch."),KErrGeneral));
sl@0
   173
	test.Printf(_L("Invalid Panic test completed successfully for udeb build.\n"));
sl@0
   174
#else
sl@0
   175
	test.Printf(_L("Invalid Panic test completed successfully for urel build.\n"));
sl@0
   176
#endif
sl@0
   177
	
sl@0
   178
	thread.Logon(threadStatus1);
sl@0
   179
	thread.Kill(KErrNone);
sl@0
   180
	User::WaitForRequest(threadStatus1);
sl@0
   181
	test(threadStatus1 == KErrNone);
sl@0
   182
	
sl@0
   183
    CLOSE_AND_WAIT(thread);
sl@0
   184
    
sl@0
   185
	User::SetJustInTime(justInTime);
sl@0
   186
	}
sl@0
   187
sl@0
   188
/**
sl@0
   189
@SYMTestCaseID          SYSLIB-EZLIB2-UT-4286
sl@0
   190
@SYMTestCaseDesc	    To ensure a file can be compressed to a gzip file and then correctly 
sl@0
   191
						decompressed back to its original state using classes from gzip.cpp.  
sl@0
   192
						Overwrite output file to verify existing file can be re-used.
sl@0
   193
@SYMTestPriority 	    High
sl@0
   194
@SYMTestActions  	    1.	Open existing test file and pass it to CEZFileToGZip::NewL() & 
sl@0
   195
							compress using CEZFileToGZip::DeflateL() function
sl@0
   196
						2.	Create or open output decompressed file and pass compressed file to
sl@0
   197
							CEZGZipToFile::NewL() & decompress using CEZGZipToFile::InflateL() function
sl@0
   198
						3.	Compare original and new file, they should be identical
sl@0
   199
						4.	Repeat Steps 1 - 3 overwriting existing compressed output file
sl@0
   200
@SYMTestExpectedResults Original test file should be the same as the file generated 
sl@0
   201
						after decompressing it & the test must not fail
sl@0
   202
@SYMDEF                 REQ8024
sl@0
   203
*/
sl@0
   204
void TestCompressDecompressGzip()
sl@0
   205
	{
sl@0
   206
	TRAPD(error, CompressFileL(TheInputFile, TheCompressFile));
sl@0
   207
	test(error == KErrNone);
sl@0
   208
	TRAP(error, DecompressFileL(TheCompressFile, TheDecompressFile));
sl@0
   209
	test(error == KErrNone);
sl@0
   210
	
sl@0
   211
	TInt compare;
sl@0
   212
	//compare the files
sl@0
   213
	TRAP(error, CompareFileDataL(TheInputFile, TheDecompressFile, compare));
sl@0
   214
	test(error == KErrNone);
sl@0
   215
	
sl@0
   216
	if(compare == 0)
sl@0
   217
		RDebug::Printf("Input file data is same as the Decompressed file data");
sl@0
   218
	else
sl@0
   219
		RDebug::Printf("Input file data differs from Decompressed file data");
sl@0
   220
	
sl@0
   221
#if !defined(__WINS__)
sl@0
   222
	DeleteFile(TheCompressFile);
sl@0
   223
	DeleteFile(TheDecompressFile);
sl@0
   224
#endif
sl@0
   225
sl@0
   226
	//Compress & decompress the same file again to overwrite the existing file & 
sl@0
   227
	//..to verify that the existing files can be re-used
sl@0
   228
	TRAP(error, CompressFileL(TheInputFile, TheCompressFile));
sl@0
   229
	test(error == KErrNone);
sl@0
   230
	TRAP(error, DecompressFileL(TheCompressFile, TheDecompressFile));
sl@0
   231
	test(error == KErrNone);
sl@0
   232
	
sl@0
   233
#if !defined(__WINS__)
sl@0
   234
	DeleteFile(TheCompressFile);
sl@0
   235
	DeleteFile(TheDecompressFile);
sl@0
   236
#endif
sl@0
   237
	}
sl@0
   238
sl@0
   239
/**
sl@0
   240
@SYMTestCaseID          SYSLIB-EZLIB2-UT-4287
sl@0
   241
@SYMTestCaseDesc	    To ensure a file can be compressed to a gzip file and then correctly 
sl@0
   242
						decompressed back using buffer size as small & big.
sl@0
   243
						
sl@0
   244
@SYMTestPriority 	    High
sl@0
   245
@SYMTestActions  	    1.	Open existing test file and pass it to CEZFileToGZip::NewL() & 
sl@0
   246
							compress using CEZFileToGZip::DeflateL() with buffer size as "11"
sl@0
   247
						2.	Create or open output decompressed file and pass compressed file 
sl@0
   248
							to CEZGZipToFile::NewL() & decompress using CEZGZipToFile::InflateL() 
sl@0
   249
							with buffer size as "10"
sl@0
   250
						3.	Repeat Steps 1 & 2 using buffer size as 10 times the file size
sl@0
   251
@SYMTestExpectedResults Files should be compressed with no errors i.e. KErrNone & the test must not fail 
sl@0
   252
@SYMDEF                 REQ8024
sl@0
   253
*/
sl@0
   254
void TestOutputBuffSize()
sl@0
   255
	{	
sl@0
   256
	
sl@0
   257
	TRAPD(error, CompressFileL(TheInputFile, TheCompressFile, 10));
sl@0
   258
	test(error == KErrNone);
sl@0
   259
sl@0
   260
	TRAP(error, DecompressFileL(TheCompressFile, TheDecompressFile, 10));
sl@0
   261
	test(error == KErrNone);
sl@0
   262
	
sl@0
   263
	TInt bufferSize = 10 * TheBufferSize;
sl@0
   264
	
sl@0
   265
#if !defined(__WINS__)
sl@0
   266
	DeleteFile(TheCompressFile);
sl@0
   267
	DeleteFile(TheDecompressFile);
sl@0
   268
#endif
sl@0
   269
sl@0
   270
	//Compress & decompress the same file again to overwrite the existing file & 
sl@0
   271
	//..to verify that the existing files can be re-used & with buffer size as big
sl@0
   272
	TRAP(error, CompressFileL(TheInputFile, TheCompressFile, bufferSize));
sl@0
   273
	test(error == KErrNone);
sl@0
   274
	
sl@0
   275
	TRAP(error, DecompressFileL(TheCompressFile, TheDecompressFile, bufferSize));
sl@0
   276
	test(error == KErrNone);
sl@0
   277
	
sl@0
   278
#if !defined(__WINS__)
sl@0
   279
	DeleteFile(TheCompressFile);
sl@0
   280
	DeleteFile(TheDecompressFile);
sl@0
   281
#endif
sl@0
   282
sl@0
   283
	}
sl@0
   284
sl@0
   285
TInt RfileInitForCEZFileToGZip(TAny*)
sl@0
   286
	{
sl@0
   287
	RFile rfile;
sl@0
   288
	TFileName compressFilePath(KOutputFilePath);
sl@0
   289
	compressFilePath.Append(TheCompressFile);
sl@0
   290
	
sl@0
   291
	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
   292
	TRAPD(error, CEZFileToGZip::NewL(TheFs, compressFilePath, rfile, TheBufferSize));
sl@0
   293
	delete cleanup;
sl@0
   294
	
sl@0
   295
	return error;
sl@0
   296
	}
sl@0
   297
	
sl@0
   298
TInt RfileInitForCEZGZipToFile(TAny*)
sl@0
   299
	{
sl@0
   300
	RFile rfile;
sl@0
   301
	TFileName compressFilePath(KOutputFilePath);
sl@0
   302
	compressFilePath.Append(TheCompressFile);
sl@0
   303
sl@0
   304
	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
   305
	TRAPD(error, CEZGZipToFile::NewL(TheFs, compressFilePath, rfile, TheBufferSize));
sl@0
   306
	delete cleanup;
sl@0
   307
	
sl@0
   308
	return error;
sl@0
   309
	
sl@0
   310
	}
sl@0
   311
sl@0
   312
/**
sl@0
   313
@SYMTestCaseID          SYSLIB-EZLIB2-UT-4288
sl@0
   314
@SYMTestCaseDesc	    CEZFileToGZip & CEZGZipToFile class initialisation fails when 
sl@0
   315
						invalid input RFile object supplied
sl@0
   316
@SYMTestPriority 	    High
sl@0
   317
@SYMTestActions  	    1.	Pass NULL RFile input parameter to CEZFileToGZip::NewL()
sl@0
   318
						2.	Pass NULL RFile input parameter to CEZGZipToFile::NewL()
sl@0
   319
@SYMTestExpectedResults NewL() method should panic & the test must not fail 
sl@0
   320
@SYMDEF                 REQ8024
sl@0
   321
*/
sl@0
   322
void TestRFileInitialisation()
sl@0
   323
	{
sl@0
   324
	test.Printf(_L("Panic Thread: CEZFileToGzip Class initialisation fails when invalid input rfile supplied"));	
sl@0
   325
	ThreadForPanicTest(RfileInitForCEZFileToGZip);
sl@0
   326
	test.Printf(_L("Panic Thread: CEZGZipToFile Class initialisation fails when invalid input rfile supplied"));
sl@0
   327
	ThreadForPanicTest(RfileInitForCEZGZipToFile);
sl@0
   328
	}
sl@0
   329
	
sl@0
   330
/**
sl@0
   331
@SYMTestCaseID          SYSLIB-EZLIB2-UT-4289
sl@0
   332
@SYMTestCaseDesc	    CEZFileToGZip, CEZGZipToFile class initialisation fails 
sl@0
   333
						when invalid output filename supplied
sl@0
   334
@SYMTestPriority 	    High
sl@0
   335
@SYMTestActions  	    1.	Pass invalid filename output parameter to CEZFileToGZip::NewL()
sl@0
   336
						2.	Pass invalid filename output parameter to CEZGZipToFile::NewL() 
sl@0
   337
						Note: Filename contains invalid characters
sl@0
   338
@SYMTestExpectedResults NewL() method should leave with error message & the test must not fail 
sl@0
   339
@SYMDEF                 REQ8024
sl@0
   340
*/	
sl@0
   341
void TestInvalidFilenameL()
sl@0
   342
	{
sl@0
   343
	
sl@0
   344
	_LIT(KInvalidGzip, "*******.gz");
sl@0
   345
	TFileName invalidGzip(KOutputFilePath);
sl@0
   346
	invalidGzip.Append(KInvalidGzip);
sl@0
   347
sl@0
   348
	_LIT(KInvalidFile, "*******.txt");
sl@0
   349
	TFileName invalidFile(KOutputFilePath);
sl@0
   350
	invalidFile.Append(KInvalidFile);
sl@0
   351
	
sl@0
   352
	TFileName inputFilePath(KPath);
sl@0
   353
	inputFilePath.Append(TheInputFile);
sl@0
   354
sl@0
   355
	RFile input;
sl@0
   356
	User::LeaveIfError(input.Open(TheFs,inputFilePath,EFileStream | EFileRead | EFileShareReadersOnly));
sl@0
   357
	CleanupClosePushL(input);
sl@0
   358
sl@0
   359
	TRAPD(error, CEZFileToGZip::NewL(TheFs, invalidGzip, input, TheBufferSize));
sl@0
   360
	test(error != KErrNone);
sl@0
   361
sl@0
   362
	CleanupStack::PopAndDestroy(1);
sl@0
   363
	
sl@0
   364
	RFile output;
sl@0
   365
	TInt err = output.Create(TheFs, invalidFile,EFileStream | EFileWrite | EFileShareExclusive);
sl@0
   366
	test(error != KErrNone);
sl@0
   367
sl@0
   368
	}
sl@0
   369
sl@0
   370
/**
sl@0
   371
@SYMTestCaseID          SYSLIB-EZLIB2-UT-4290
sl@0
   372
@SYMTestCaseDesc	    Ensure if output file exists and is read only then it cannot be 
sl@0
   373
						overwritten with CEZFileToGZip & CEZGZipToFile class
sl@0
   374
@SYMTestPriority 	    High
sl@0
   375
@SYMTestActions  	    1.	Pass existing read only output filename parameter to CEZFileToGZip::NewL()
sl@0
   376
						2.	Pass existing read only output filename parameter to CEZGZipToFile::NewL() 
sl@0
   377
						& decompress using CEZGZipToFile::InflateL()
sl@0
   378
@SYMTestExpectedResults CEZFileToGZip::NewL() method should leave with error message, CEZGZipToFile::Inflate()
sl@0
   379
						should leave with error message & the test must not fail 
sl@0
   380
@SYMDEF                 REQ8024
sl@0
   381
*/	
sl@0
   382
void TestOverwriteOutputFileL()
sl@0
   383
	{
sl@0
   384
	_LIT(KReadOnlyGzip, "Hello_Read_Only.gz");	
sl@0
   385
	TFileName readOnlyNewGZip(KOutputFilePath);
sl@0
   386
	readOnlyNewGZip.Append(KReadOnlyGzip);
sl@0
   387
	
sl@0
   388
	_LIT(KReadOnlyFile, "Hello_Read_Only.txt");
sl@0
   389
	TFileName readOnlyNewFile(KOutputFilePath);
sl@0
   390
	readOnlyNewFile.Append(KReadOnlyFile);
sl@0
   391
sl@0
   392
	CFileMan* fMan=CFileMan::NewL(TheFs);
sl@0
   393
	test(fMan!=NULL);
sl@0
   394
	CleanupStack::PushL(fMan);
sl@0
   395
	
sl@0
   396
#if !defined(__WINS__)
sl@0
   397
	TFileName readOnlyOldGZip(KPath);
sl@0
   398
	readOnlyOldGZip.Append(KReadOnlyGzip);
sl@0
   399
	TFileName readOnlyOldFile(KPath);
sl@0
   400
	readOnlyOldFile.Append(KReadOnlyFile);
sl@0
   401
sl@0
   402
	RFile source;
sl@0
   403
	User::LeaveIfError(source.Open(TheFs,readOnlyOldGZip, EFileStream | EFileRead | EFileShareReadersOnly));
sl@0
   404
	CleanupClosePushL(source);
sl@0
   405
	TRAPD(error, fMan->Copy(source, readOnlyNewGZip));
sl@0
   406
	test(error == KErrNone);
sl@0
   407
	
sl@0
   408
	RFile source1;
sl@0
   409
	User::LeaveIfError(source1.Open(TheFs,readOnlyOldFile, EFileStream | EFileRead | EFileShareReadersOnly));
sl@0
   410
	CleanupClosePushL(source1);
sl@0
   411
	TRAP(error, fMan->Copy(source1, readOnlyNewFile));
sl@0
   412
	test(error == KErrNone);
sl@0
   413
sl@0
   414
	CleanupStack::PopAndDestroy(2);
sl@0
   415
#endif
sl@0
   416
sl@0
   417
	TFileName inputFilePath(KPath);
sl@0
   418
	inputFilePath.Append(TheInputFile);
sl@0
   419
sl@0
   420
	RFile input;
sl@0
   421
	User::LeaveIfError(input.Open(TheFs,inputFilePath,EFileStream | EFileRead | EFileShareReadersOnly));
sl@0
   422
	CleanupClosePushL(input);
sl@0
   423
sl@0
   424
	//setting attributes to read only for readOnlyGZip & readOnlyFile
sl@0
   425
   	TInt err = fMan->Attribs(readOnlyNewGZip, KEntryAttReadOnly, 0, 0);
sl@0
   426
	test(err == KErrNone);
sl@0
   427
	err = fMan->Attribs(readOnlyNewFile, KEntryAttReadOnly, 0, 0);
sl@0
   428
	test(err == KErrNone);
sl@0
   429
		
sl@0
   430
	TRAP(err, CEZFileToGZip::NewL(TheFs, readOnlyNewGZip, input, TheBufferSize));
sl@0
   431
	test(err != KErrNone);
sl@0
   432
sl@0
   433
	RFile output;
sl@0
   434
	User::LeaveIfError(output.Open(TheFs,readOnlyNewFile,EFileStream | EFileRead | EFileShareReadersOnly));
sl@0
   435
	CleanupClosePushL(output);
sl@0
   436
sl@0
   437
	CEZGZipToFile * gzipToFile = NULL;
sl@0
   438
	TRAP(err, gzipToFile = CEZGZipToFile::NewL(TheFs, readOnlyNewGZip, output, TheBufferSize));
sl@0
   439
	test(err == KErrNone);
sl@0
   440
	CleanupStack::PushL(gzipToFile);
sl@0
   441
	
sl@0
   442
	while (err == KErrNone)
sl@0
   443
	{
sl@0
   444
		TRAP(err, gzipToFile->InflateL());
sl@0
   445
	}
sl@0
   446
	
sl@0
   447
	test(err != KErrNone); 	
sl@0
   448
sl@0
   449
	CleanupStack::PopAndDestroy(4);
sl@0
   450
	
sl@0
   451
	//removing the read only attrib before deleting the file
sl@0
   452
   	fMan=CFileMan::NewL(TheFs);
sl@0
   453
   	test(fMan!=NULL);
sl@0
   454
   	CleanupStack::PushL(fMan);
sl@0
   455
   	err = fMan->Attribs(readOnlyNewGZip, 0, KEntryAttReadOnly, 0);
sl@0
   456
	test(err == KErrNone);
sl@0
   457
	err = fMan->Attribs(readOnlyNewFile, 0, KEntryAttReadOnly, 0);
sl@0
   458
	test(err == KErrNone);
sl@0
   459
	
sl@0
   460
	CleanupStack::PopAndDestroy(1);
sl@0
   461
	
sl@0
   462
#if !defined(__WINS__)
sl@0
   463
	DeleteFile(readOnlyNewGZip, ETrue);
sl@0
   464
	DeleteFile(readOnlyNewFile, ETrue);
sl@0
   465
#endif
sl@0
   466
	}
sl@0
   467
sl@0
   468
TInt RFSInitForCEZFileToGZipL(TAny*)
sl@0
   469
	{
sl@0
   470
	TFileName inputFilePath(KPath);
sl@0
   471
	inputFilePath.Append(TheInputFile);
sl@0
   472
sl@0
   473
	RFile input;
sl@0
   474
	User::LeaveIfError(input.Open(TheFs,inputFilePath,EFileStream | EFileRead | EFileShareReadersOnly));
sl@0
   475
	CleanupClosePushL(input);
sl@0
   476
sl@0
   477
	TFileName compressFilePath(KOutputFilePath);
sl@0
   478
	compressFilePath.Append(TheCompressFile);
sl@0
   479
sl@0
   480
	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
   481
	RFs rfs; 
sl@0
   482
	TRAPD(error, CEZFileToGZip::NewL(rfs, compressFilePath, input, TheBufferSize));
sl@0
   483
	delete cleanup;
sl@0
   484
	
sl@0
   485
	CleanupStack::PopAndDestroy(1);
sl@0
   486
	return error;
sl@0
   487
	
sl@0
   488
	}
sl@0
   489
sl@0
   490
TInt RFSInitForCEZGZipToFileL(TAny*)
sl@0
   491
	{
sl@0
   492
	TFileName compressFilePath(KPath);
sl@0
   493
	compressFilePath.Append(TheCompressFile);
sl@0
   494
	
sl@0
   495
	TFileName decompressFilePath(KOutputFilePath);
sl@0
   496
	decompressFilePath.Append(TheDecompressFile);
sl@0
   497
sl@0
   498
	RFile output;
sl@0
   499
	User::LeaveIfError(output.Replace(TheFs,decompressFilePath,EFileStream | EFileRead | EFileShareReadersOnly));
sl@0
   500
	CleanupClosePushL(output);
sl@0
   501
sl@0
   502
	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
   503
	RFs rfs; 
sl@0
   504
	TRAPD(error, CEZGZipToFile::NewL(rfs, compressFilePath, output, TheBufferSize));
sl@0
   505
	delete cleanup;
sl@0
   506
	
sl@0
   507
	CleanupStack::PopAndDestroy(1);
sl@0
   508
	return error;
sl@0
   509
	
sl@0
   510
	}
sl@0
   511
sl@0
   512
/**
sl@0
   513
@SYMTestCaseID          SYSLIB-EZLIB2-UT-4291
sl@0
   514
@SYMTestCaseDesc	    CEZFileToGZip & CEZGZipToFile class initialisation fails when 
sl@0
   515
						invalid RFs object is passed
sl@0
   516
@SYMTestPriority 	    High
sl@0
   517
@SYMTestActions  	    1.	Pass NULL RFs input parameter to CEZFileToGZip::NewL() 
sl@0
   518
						2.	Pass NULL RFs input parameter to CEZGZipToFile::NewL()
sl@0
   519
@SYMTestExpectedResults NewL() method should panic & the test must not fail 
sl@0
   520
@SYMDEF                 REQ8024
sl@0
   521
*/	
sl@0
   522
void TestRFSInitialisation()
sl@0
   523
	{
sl@0
   524
	test.Printf(_L("Panic Thread: CEZFileToGZip Class initialisation fails when invalid RFS object is passed"));	
sl@0
   525
	ThreadForPanicTest(RFSInitForCEZFileToGZipL);
sl@0
   526
	test.Printf(_L("Panic Thread: CEZGZipToFile Class initialisation fails when invalid RFS object is passed"));
sl@0
   527
	ThreadForPanicTest(RFSInitForCEZGZipToFileL);
sl@0
   528
	}
sl@0
   529
sl@0
   530
TInt BuffForEZFileToGZipAsZeroL(TAny*)
sl@0
   531
	{
sl@0
   532
	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
   533
	CompressFileL(TheInputFile, TheCompressFile, 0);
sl@0
   534
	delete cleanup;
sl@0
   535
	return KErrNone;
sl@0
   536
	}
sl@0
   537
sl@0
   538
TInt BuffForEZFileToGZipAsNegativeL(TAny*)
sl@0
   539
	{
sl@0
   540
	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
   541
	CompressFileL(TheInputFile, TheCompressFile, -1);
sl@0
   542
	delete cleanup;
sl@0
   543
	return KErrNone;
sl@0
   544
	}
sl@0
   545
sl@0
   546
TInt BuffForEZGZipToFileAsZeroL(TAny*)
sl@0
   547
	{
sl@0
   548
	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
   549
	DecompressFileL(TheCompressFile, TheDecompressFile, 0);
sl@0
   550
	delete cleanup;
sl@0
   551
	return KErrNone;
sl@0
   552
	}
sl@0
   553
sl@0
   554
TInt BuffForEZGZipToFileAsNegativeL(TAny*)
sl@0
   555
	{
sl@0
   556
	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
   557
	DecompressFileL(TheCompressFile, TheDecompressFile, -1);
sl@0
   558
	delete cleanup;
sl@0
   559
	return KErrNone;	
sl@0
   560
	}
sl@0
   561
sl@0
   562
/**
sl@0
   563
@SYMTestCaseID          SYSLIB-EZLIB2-UT-4292
sl@0
   564
@SYMTestCaseDesc	    CEZFileToGZip & CEZGZipToFile class initialisation 
sl@0
   565
						fails when invalid buffer size parameter passed in
sl@0
   566
@SYMTestPriority 	    High
sl@0
   567
@SYMTestActions  	    1.	Pass buffer size parameter value as 0 to CEZFileToGZip::NewL()  
sl@0
   568
						2.	Pass buffer size parameter as a negative value to CEZFileToGZip::NewL()
sl@0
   569
						3.	Pass buffer size parameter value as 0 to CEZGZipToFile::NewL()  
sl@0
   570
						4.	Pass buffer size parameter as a negative value to CEZGZipToFile::NewL()
sl@0
   571
@SYMTestExpectedResults NewL() method should panic & the test must not fail 
sl@0
   572
@SYMDEF                 REQ8024
sl@0
   573
*/	
sl@0
   574
void TestInvalidBufferSize()
sl@0
   575
	{
sl@0
   576
	
sl@0
   577
	test.Printf(_L("Panic Thread: CEZFileToGZip Class initialisation fails when buffer size is passed as Zero"));	
sl@0
   578
	ThreadForPanicTest(BuffForEZFileToGZipAsZeroL);
sl@0
   579
	test.Printf(_L("Panic Thread: CEZFileToGZip Class initialisation fails when buffer size is passed as Negative"));
sl@0
   580
	ThreadForPanicTest(BuffForEZFileToGZipAsNegativeL);
sl@0
   581
	test.Printf(_L("Panic Thread: CEZGZipToFile Class initialisation fails when buffer size is passed as Zero"));
sl@0
   582
	ThreadForPanicTest(BuffForEZGZipToFileAsZeroL);
sl@0
   583
	test.Printf(_L("Panic Thread: CEZGZipToFile Class initialisation fails when buffer size is passed as Negative"));
sl@0
   584
	ThreadForPanicTest(BuffForEZGZipToFileAsNegativeL);
sl@0
   585
sl@0
   586
	}
sl@0
   587
sl@0
   588
/**
sl@0
   589
@SYMTestCaseID          SYSLIB-EZLIB2-UT-4293
sl@0
   590
@SYMTestCaseDesc	    Compress & Decompress another file with CEZFileToGZip & CEZGZipToFile 
sl@0
   591
						after calling ResetL method
sl@0
   592
@SYMTestPriority 	    High
sl@0
   593
@SYMTestActions  	    1.	Open existing test file and pass it to CEZFileToGZip::NewL() & compress using CEZFileToGZip::DeflateL function
sl@0
   594
						2.	Call CEZFileToGZip::ResetL() with new file parameters
sl@0
   595
						3.	Compress the new file with CEZFileToGZip::DeflateL()
sl@0
   596
						4.	Create or open output decompressed file and pass compressed file to CEZGZipToFile::NewL() & decompress using CEZGZipToFile::InflateL() function
sl@0
   597
						5.	Call CEZGZipToFile::ResetL() with new compressed file parameters
sl@0
   598
						6.	Decompress the new compressed file with CEZGZipToFile::InflateL()
sl@0
   599
@SYMTestExpectedResults Files should be compressed with no errors i.e. KErrNone & the test must not fail 
sl@0
   600
@SYMDEF                 REQ8024
sl@0
   601
*/	
sl@0
   602
void TestCompressDecompressResetL()
sl@0
   603
	{
sl@0
   604
    
sl@0
   605
	TFileName inputFilePath(KPath);
sl@0
   606
	inputFilePath.Append(TheInputFile);
sl@0
   607
sl@0
   608
	_LIT(KGzipFile,"Hello_Reset.gz");
sl@0
   609
	TFileName gzipFileName(KGzipFile);
sl@0
   610
	TFileName compressfile(KOutputFilePath);
sl@0
   611
	compressfile.Append(gzipFileName);
sl@0
   612
	
sl@0
   613
	RFile input;
sl@0
   614
	User::LeaveIfError(input.Open(TheFs,inputFilePath,EFileStream | EFileRead | EFileShareReadersOnly));
sl@0
   615
	CleanupClosePushL(input);
sl@0
   616
	
sl@0
   617
	CEZFileToGZip *fileToGzip = CEZFileToGZip::NewLC(TheFs, compressfile, input, TheBufferSize);
sl@0
   618
	while(fileToGzip->DeflateL()){/*do nothing*/}
sl@0
   619
	
sl@0
   620
	fileToGzip->ResetL(TheFs, compressfile, input, TheBufferSize);
sl@0
   621
	while(fileToGzip->DeflateL()){/*do nothing*/}
sl@0
   622
	
sl@0
   623
	CleanupStack::PopAndDestroy(2);
sl@0
   624
	
sl@0
   625
#if !defined(__WINS__)
sl@0
   626
	DeleteFile(gzipFileName);
sl@0
   627
#endif
sl@0
   628
sl@0
   629
	TFileName compressFilePath(KPath);
sl@0
   630
	compressFilePath.Append(TheCompressFile);
sl@0
   631
sl@0
   632
	_LIT(KTxtFile,"Hello_Reset.txt");
sl@0
   633
	TFileName txtFileName(KTxtFile);
sl@0
   634
	TFileName decompressfile(KOutputFilePath);
sl@0
   635
	decompressfile.Append(txtFileName);
sl@0
   636
sl@0
   637
	RFile output;
sl@0
   638
	User::LeaveIfError(output.Replace(TheFs, decompressfile,EFileStream | EFileWrite | EFileShareExclusive));
sl@0
   639
	CleanupClosePushL(output);
sl@0
   640
sl@0
   641
	CEZGZipToFile *gzipToFile = CEZGZipToFile::NewLC(TheFs, compressFilePath, output, TheBufferSize);
sl@0
   642
	while(gzipToFile->InflateL()){/*do nothing*/}
sl@0
   643
sl@0
   644
	gzipToFile->ResetL(TheFs, compressFilePath, output, TheBufferSize);
sl@0
   645
	while(gzipToFile->InflateL()){/*do nothing*/}
sl@0
   646
	
sl@0
   647
	CleanupStack::PopAndDestroy(2);
sl@0
   648
	
sl@0
   649
#if !defined(__WINS__)
sl@0
   650
	DeleteFile(txtFileName);
sl@0
   651
#endif
sl@0
   652
sl@0
   653
	}
sl@0
   654
sl@0
   655
/**
sl@0
   656
@SYMTestCaseID          SYSLIB-EZLIB2-UT-4294
sl@0
   657
@SYMTestCaseDesc	    CEZGZipToFile class initialisation fails when source 
sl@0
   658
						gzip file header is malformed: Header is too small
sl@0
   659
@SYMTestPriority 	    High
sl@0
   660
@SYMTestActions  	    Pass corrupted gzip file as an input parameter to CEZGZipToFile::NewL()  
sl@0
   661
						Note: Change the header of existing gzip file by removing few characters
sl@0
   662
@SYMTestExpectedResults NewL() method should leave with error message KEZlibErrBadGZipHeader 
sl@0
   663
						& the test must not fail 
sl@0
   664
@SYMDEF                 REQ8024
sl@0
   665
*/	
sl@0
   666
void TestGzipHeaderSmallL()
sl@0
   667
	{
sl@0
   668
	
sl@0
   669
	_LIT(KGzFile,"Hello_HeaderChanged.gz");	
sl@0
   670
	TFileName compressfile(KPath);
sl@0
   671
	compressfile.Append(KGzFile);
sl@0
   672
sl@0
   673
	TFileName decompressFilePath(KOutputFilePath);
sl@0
   674
	decompressFilePath.Append(TheDecompressFile);
sl@0
   675
sl@0
   676
	RFile output;
sl@0
   677
	User::LeaveIfError(output.Replace(TheFs, decompressFilePath,EFileStream | EFileWrite | EFileShareExclusive));
sl@0
   678
	CleanupClosePushL(output);
sl@0
   679
	
sl@0
   680
	TRAPD(error, CEZGZipToFile::NewL(TheFs, compressfile, output, TheBufferSize));
sl@0
   681
	test(error == KEZlibErrBadGZipHeader);
sl@0
   682
sl@0
   683
	CleanupStack::PopAndDestroy(1);
sl@0
   684
sl@0
   685
	}
sl@0
   686
sl@0
   687
/**
sl@0
   688
@SYMTestCaseID          SYSLIB-EZLIB2-UT-4295
sl@0
   689
@SYMTestCaseDesc	    CEZGZipToFile class initialisation fails when source gzip file 
sl@0
   690
						header is malformed: Header ID number is incorrect
sl@0
   691
@SYMTestPriority 	    High
sl@0
   692
@SYMTestActions  	    Pass corrupted gzip file as an input parameter to CEZGZipToFile::NewL()  
sl@0
   693
						Note: Change the header ID of existing gzip file
sl@0
   694
@SYMTestExpectedResults NewL() method should leave with error message KEZlibErrBadGZipHeader 
sl@0
   695
						& the test must not fail 
sl@0
   696
@SYMDEF                 REQ8024
sl@0
   697
*/	
sl@0
   698
void TestGzipHeaderIdIncorrectL()
sl@0
   699
	{	
sl@0
   700
sl@0
   701
	_LIT(KGzFile,"Hello_HeaderIdChanged.gz");
sl@0
   702
	TFileName compressfile(KPath);
sl@0
   703
	compressfile.Append(KGzFile);
sl@0
   704
sl@0
   705
	TFileName decompressFilePath(KOutputFilePath);
sl@0
   706
	decompressFilePath.Append(TheDecompressFile);
sl@0
   707
sl@0
   708
	RFile output;
sl@0
   709
	User::LeaveIfError(output.Replace(TheFs, decompressFilePath,EFileStream | EFileWrite | EFileShareExclusive));
sl@0
   710
	CleanupClosePushL(output);
sl@0
   711
	
sl@0
   712
	TRAPD(error, CEZGZipToFile::NewL(TheFs, compressfile, output, TheBufferSize));
sl@0
   713
	test(error == KEZlibErrBadGZipHeader);
sl@0
   714
	
sl@0
   715
	CleanupStack::PopAndDestroy(1);
sl@0
   716
	
sl@0
   717
	}
sl@0
   718
sl@0
   719
/**
sl@0
   720
@SYMTestCaseID          SYSLIB-EZLIB2-UT-4296
sl@0
   721
@SYMTestCaseDesc	    CEZGZipToFile class fails while decompressing the gzip 
sl@0
   722
						file with the CRC changed in the trailer
sl@0
   723
@SYMTestPriority 	    High
sl@0
   724
@SYMTestActions  	    Pass corrupted gzip file as an input parameter to CEZGZipToFile::NewL()
sl@0
   725
						Note: Change the CRC within the Trailer of existing gzip file
sl@0
   726
@SYMTestExpectedResults NewL() method should leave with error message KErrNotFound & the test must not fail
sl@0
   727
						Note: KErrNotFound error is fired while opening the corrupted gzip file
sl@0
   728
@SYMDEF                 REQ8024
sl@0
   729
*/	
sl@0
   730
void TestGzipTrailerCRCL()
sl@0
   731
	{
sl@0
   732
sl@0
   733
	_LIT(KGzFile,"Hello_TrailerIdChanged.gz");	
sl@0
   734
	TFileName compressfile(KPath);
sl@0
   735
	compressfile.Append(KGzFile);
sl@0
   736
sl@0
   737
	TFileName decompressFilePath(KOutputFilePath);
sl@0
   738
	decompressFilePath.Append(TheDecompressFile);
sl@0
   739
sl@0
   740
	RFile output;
sl@0
   741
	User::LeaveIfError(output.Replace(TheFs, decompressFilePath,EFileStream | EFileWrite | EFileShareExclusive));
sl@0
   742
	CleanupClosePushL(output);
sl@0
   743
	
sl@0
   744
	TRAPD(error, CEZGZipToFile::NewL(TheFs, compressfile, output, TheBufferSize));
sl@0
   745
	test(error == KErrNotFound);
sl@0
   746
	
sl@0
   747
	CleanupStack::PopAndDestroy(1);
sl@0
   748
sl@0
   749
	}
sl@0
   750
sl@0
   751
void TestCompressDecompressL()
sl@0
   752
	{
sl@0
   753
sl@0
   754
	TFileName inputFilePath(KPath);
sl@0
   755
	inputFilePath.Append(TheInputFile);
sl@0
   756
	
sl@0
   757
	TFileName compressFilePath(KOutputFilePath);
sl@0
   758
	compressFilePath.Append(TheCompressFile);
sl@0
   759
sl@0
   760
	RFile input;
sl@0
   761
	User::LeaveIfError(input.Open(TheFs,inputFilePath,EFileStream | EFileRead | EFileShareReadersOnly));
sl@0
   762
	CleanupClosePushL(input);
sl@0
   763
	
sl@0
   764
	CEZFileToGZip *fileToGzip = CEZFileToGZip::NewLC(TheFs, compressFilePath, input, TheBufferSize);
sl@0
   765
	while(fileToGzip->DeflateL()){/*do nothing*/}
sl@0
   766
	
sl@0
   767
	TFileName decompressFilePath(KOutputFilePath);
sl@0
   768
	decompressFilePath.Append(TheDecompressFile);
sl@0
   769
sl@0
   770
	TFileName compressFilePath1(KPath);
sl@0
   771
	compressFilePath1.Append(TheCompressFile);
sl@0
   772
sl@0
   773
	RFile output;
sl@0
   774
	User::LeaveIfError(output.Replace(TheFs, decompressFilePath,EFileStream | EFileWrite | EFileShareExclusive));
sl@0
   775
	CleanupClosePushL(output);
sl@0
   776
sl@0
   777
	CEZGZipToFile *gzipToFile = CEZGZipToFile::NewLC(TheFs, compressFilePath1, output, TheBufferSize);
sl@0
   778
	while(gzipToFile->InflateL()){/*do nothing*/}
sl@0
   779
sl@0
   780
	CleanupStack::PopAndDestroy(4);
sl@0
   781
	
sl@0
   782
#if !defined(__WINS__)
sl@0
   783
	DeleteFile(TheCompressFile);
sl@0
   784
	DeleteFile(TheDecompressFile);
sl@0
   785
#endif
sl@0
   786
	}
sl@0
   787
	
sl@0
   788
/**
sl@0
   789
@SYMTestCaseID          SYSLIB-EZLIB2-UT-4297
sl@0
   790
@SYMTestCaseDesc	    Out of Memory(OOM) test for CEZFileToGZip &  CEZGZipToFile class
sl@0
   791
@SYMTestPriority 	    High
sl@0
   792
@SYMTestActions  	    1.	Set Heap Failure using the macro as:
sl@0
   793
							__UHEAP_SETFAIL(RHeap::EDeterministic, count)
sl@0
   794
						2.	Mark the heap using macro: __UHEAP_MARK
sl@0
   795
						3.	Open existing test file and pass it to CEZFileToGZip::NewL() compress using CEZFileToGZip::DeflateL() function
sl@0
   796
						4.	Create or open output decompressed file and pass compressed file to CEZGZipToFile::NewL() & decompress using CEZGZipToFile::InflateL() function
sl@0
   797
						5.	Check there is no memory leak using the macro: __UHEAP_MARKEND
sl@0
   798
						6.	Repeat the Steps 1-5 increasing the heap value rate i.e. count
sl@0
   799
@SYMTestExpectedResults The test succeeds with no memory leak on the heap as well as no errors (i.e. KErrNone)
sl@0
   800
						& the test must not fail 
sl@0
   801
@SYMDEF                 REQ8024
sl@0
   802
*/	
sl@0
   803
void TestOOMGzipL()
sl@0
   804
	{
sl@0
   805
   	TInt processHandlesS = 0;
sl@0
   806
	TInt threadHandlesS = 0;
sl@0
   807
	TInt processHandlesE = 0;
sl@0
   808
	TInt threadHandlesE = 0;
sl@0
   809
	TInt err = KErrNone;
sl@0
   810
	RThread().HandleCount(processHandlesS, threadHandlesS);
sl@0
   811
	for(TInt count=1; count<=100; ++count)
sl@0
   812
		{
sl@0
   813
		// Setting Heap failure for OOM test
sl@0
   814
		__UHEAP_SETFAIL(RHeap::EDeterministic, count);
sl@0
   815
		__UHEAP_MARK;
sl@0
   816
		
sl@0
   817
		TRAP(err,TestCompressDecompressL());
sl@0
   818
		__UHEAP_MARKEND;
sl@0
   819
		if(err == KErrNone)
sl@0
   820
			{
sl@0
   821
			RDebug::Print(_L("The test succeeded at heap failure rate=%d.\n"), count);
sl@0
   822
			break;
sl@0
   823
			}
sl@0
   824
		else 
sl@0
   825
			{
sl@0
   826
			test(err == KErrNoMemory);
sl@0
   827
			}
sl@0
   828
		__UHEAP_RESET;
sl@0
   829
		}
sl@0
   830
	
sl@0
   831
	test(err == KErrNone);
sl@0
   832
	__UHEAP_RESET;
sl@0
   833
	
sl@0
   834
	RThread().HandleCount(processHandlesE, threadHandlesE);
sl@0
   835
	
sl@0
   836
	test(processHandlesS == processHandlesE);
sl@0
   837
	test(threadHandlesS == threadHandlesE);
sl@0
   838
sl@0
   839
	}
sl@0
   840
/*
sl@0
   841
 * Helper function for TestDEF117325ToGZipL
sl@0
   842
 * Deflates a file and then calls ResetL()
sl@0
   843
 */
sl@0
   844
void DeflateResetL()
sl@0
   845
	{
sl@0
   846
	_LIT(KGzipFile,"Hello_Reset.gz");
sl@0
   847
	TFileName compressFile(KOutputFilePath);
sl@0
   848
	compressFile.Append(KGzipFile);
sl@0
   849
sl@0
   850
	TFileName inputFilePath(KPath);
sl@0
   851
	inputFilePath.Append(TheInputFile);
sl@0
   852
	
sl@0
   853
	RFile input;	
sl@0
   854
	User::LeaveIfError(input.Open(TheFs, inputFilePath, EFileStream | EFileRead | EFileShareReadersOnly));
sl@0
   855
	CleanupClosePushL(input);
sl@0
   856
		
sl@0
   857
	CEZFileToGZip *fileToGzip = CEZFileToGZip::NewLC(TheFs, compressFile, input, TheBufferSize);
sl@0
   858
	while(fileToGzip->DeflateL()) {/*do nothing*/}
sl@0
   859
	
sl@0
   860
	fileToGzip->ResetL(TheFs, compressFile, input, TheBufferSize);
sl@0
   861
	
sl@0
   862
	CleanupStack::PopAndDestroy(2);
sl@0
   863
	
sl@0
   864
	#if !defined(__WINS__)
sl@0
   865
	DeleteFile(TheInputFile);
sl@0
   866
	#endif
sl@0
   867
	}
sl@0
   868
sl@0
   869
/*
sl@0
   870
 * Helper function for TestDEF117325ToFileL
sl@0
   871
 * Inflates a GZip file and then calls ResetL()
sl@0
   872
 */
sl@0
   873
void InflateResetL()
sl@0
   874
	{
sl@0
   875
	_LIT(KTxtFile, "Hello_Reset.txt");
sl@0
   876
	TFileName decompressFile(KOutputFilePath);
sl@0
   877
	decompressFile.Append(KTxtFile);
sl@0
   878
sl@0
   879
	TFileName compressFilePath(KPath);
sl@0
   880
	compressFilePath.Append(TheCompressFile);
sl@0
   881
		
sl@0
   882
	RFile output;
sl@0
   883
	User::LeaveIfError(output.Replace(TheFs, decompressFile, EFileStream | EFileWrite | EFileShareExclusive));
sl@0
   884
	CleanupClosePushL(output);
sl@0
   885
	
sl@0
   886
	CEZGZipToFile *gzipToFile = CEZGZipToFile::NewLC(TheFs, compressFilePath, output, TheBufferSize);
sl@0
   887
	while(gzipToFile->InflateL()){/*do nothing*/}
sl@0
   888
	
sl@0
   889
	gzipToFile->ResetL(TheFs, compressFilePath, output, TheBufferSize);
sl@0
   890
	
sl@0
   891
	CleanupStack::PopAndDestroy(2);
sl@0
   892
	
sl@0
   893
	#if !defined(__WINS__)
sl@0
   894
	DeleteFile(TheCompressFile);
sl@0
   895
	#endif
sl@0
   896
	}
sl@0
   897
sl@0
   898
/*
sl@0
   899
 * Helper function for TestDEF117325ToGZipL and TestDEF117325ToFileL.
sl@0
   900
 * Checks for memory leaks in OOM situations.
sl@0
   901
 */
sl@0
   902
void DEF117325L(void (*aResetL)())
sl@0
   903
	{
sl@0
   904
	TInt err = KErrNone;
sl@0
   905
	for(TInt count = 0; count <= 100; count++)
sl@0
   906
		{
sl@0
   907
		// Setting Heap failure for OOM test
sl@0
   908
		__UHEAP_SETFAIL(RHeap::EDeterministic, count);
sl@0
   909
		__UHEAP_MARK;	
sl@0
   910
		
sl@0
   911
		TRAP(err, aResetL());
sl@0
   912
		
sl@0
   913
		__UHEAP_MARKEND;
sl@0
   914
		__UHEAP_RESET;
sl@0
   915
		
sl@0
   916
		if(err == KErrNone)
sl@0
   917
			{
sl@0
   918
			RDebug::Print(_L("The test succeeded at heap failure rate = %d.\n"), count);
sl@0
   919
			break;
sl@0
   920
			}
sl@0
   921
		else 
sl@0
   922
			{
sl@0
   923
			test(err == KErrNoMemory);
sl@0
   924
			}
sl@0
   925
		}
sl@0
   926
	}
sl@0
   927
sl@0
   928
/**
sl@0
   929
@SYMTestCaseID          SYSLIB-EZLIB2-UT-4319
sl@0
   930
@SYMTestCaseDesc	    To test that there are no memory leaks when calling ResetL from CEZFileToGZip
sl@0
   931
@SYMTestPriority 	    Medium
sl@0
   932
@SYMTestActions  	    1.	Set Heap Failure using the macro __UHEAP_SETFAIL(RHeap::EDeterministic, count)
sl@0
   933
						2.	Mark the heap using macro __UHEAP_MARK
sl@0
   934
						3.	Open an existing test file and pass it to CEZFileToGZip::NewL() and compress it using CEZFileToGZip::DeflateL function
sl@0
   935
						4.	Call CEZFileToGZip::ResetL() with new file parameters
sl@0
   936
						5.	Check there is no memory leak using the macro __UHEAP_MARKEND
sl@0
   937
						6.	Repeat steps 1 - 5 increasing the heap value rate i.e. count
sl@0
   938
@SYMTestExpectedResults The test succeeds with no memory leak on the heap as well as no errors (i.e. KErrNone) 
sl@0
   939
@SYMDEF                 REQ8024
sl@0
   940
*/	
sl@0
   941
void TestDEF117325ToGZipL()
sl@0
   942
	{		
sl@0
   943
	DEF117325L(&DeflateResetL);
sl@0
   944
	}
sl@0
   945
sl@0
   946
/**
sl@0
   947
@SYMTestCaseID          SYSLIB-EZLIB2-UT-4320
sl@0
   948
@SYMTestCaseDesc	    To test that there are no memory leaks when calling ResetL from CEZGZipToFile
sl@0
   949
@SYMTestPriority 	    Medium
sl@0
   950
@SYMTestActions  	    1.	Open an existing test file and pass it to CEZFileToGZip::NewL() and compress it using CEZFileToGZip::DeflateL 
sl@0
   951
						2.	Set Heap Failure using the macro __UHEAP_SETFAIL(RHeap::EDeterministic, count)
sl@0
   952
						3.	Mark the heap using macro __UHEAP_MARK
sl@0
   953
						4.	Open the compressed test file and pass it to CEZGZipToFile::NewL() and decompress it using CEZGZipToFile::InflateL function
sl@0
   954
						5.	Call CEZGZipToFile::ResetL() with new file parameters
sl@0
   955
						6.	Check there is no memory leak using the macro __UHEAP_MARKEND
sl@0
   956
						7.	Repeat steps 2 - 6 increasing the heap value rate i.e. count
sl@0
   957
@SYMTestExpectedResults The test succeeds with no memory leak on the heap as well as no errors (i.e. KErrNone)
sl@0
   958
@SYMDEF                 REQ8024
sl@0
   959
*/	
sl@0
   960
void TestDEF117325ToFileL()
sl@0
   961
	{	
sl@0
   962
	
sl@0
   963
	// Create a GZip file that can be used by CEZGZipToFile
sl@0
   964
	CompressFileL(TheInputFile, TheCompressFile);
sl@0
   965
	
sl@0
   966
	DEF117325L(&InflateResetL);
sl@0
   967
	
sl@0
   968
	#if !defined(__WINS__)
sl@0
   969
	DeleteFile(TheCompressFile);
sl@0
   970
	#endif
sl@0
   971
	}
sl@0
   972
sl@0
   973
	
sl@0
   974
sl@0
   975
void RunTestL()
sl@0
   976
	{
sl@0
   977
	
sl@0
   978
	User::LeaveIfError(TheFs.Connect()); //Connect to file session
sl@0
   979
	CleanupClosePushL(TheFs);
sl@0
   980
	
sl@0
   981
#if !defined(__WINS__)
sl@0
   982
	TInt err = TheFs.MkDirAll(KOutputFilePath);  
sl@0
   983
	if(err != KErrNone && err != KErrAlreadyExists)
sl@0
   984
		{
sl@0
   985
		test.Printf(_L("Error while creating dir => Error: %d"), err);
sl@0
   986
		User::Leave(err);
sl@0
   987
		}
sl@0
   988
#endif
sl@0
   989
	
sl@0
   990
	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4286 Compression - Decompression of Gzip file "));
sl@0
   991
	TestCompressDecompressGzip();
sl@0
   992
	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4287 Compression - Decompression of Gzip file with big & small buffer size "));
sl@0
   993
	TestOutputBuffSize();
sl@0
   994
	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4288 Class initialisation fails when invalid input rfile supplied "));
sl@0
   995
	TestRFileInitialisation();
sl@0
   996
	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4289 Class initialisation fails when invalid output filename supplied "));
sl@0
   997
	TestInvalidFilenameL();
sl@0
   998
	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4290 Class initialisation fails while overwriting the read only output file "));
sl@0
   999
	TestOverwriteOutputFileL();
sl@0
  1000
	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4291 Class initialisation fails when invalid RFS object is passed "));
sl@0
  1001
	TestRFSInitialisation();
sl@0
  1002
	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4292 Panic Thread: Class initialisation fails when invalid buffer size parameter passed in "));
sl@0
  1003
	TestInvalidBufferSize();
sl@0
  1004
	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4293 Compress another file with CEZFileToGZip & CEZGZipToFile after calling ResetL method "));
sl@0
  1005
	TestCompressDecompressResetL();
sl@0
  1006
	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4294 CEZGZipToFile class initialisation fails when source gzip file header is malformed: Header is too small "));
sl@0
  1007
	TestGzipHeaderSmallL();
sl@0
  1008
	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4295 CEZGZipToFile class initialisation fails when source gzip file header is malformed: Header ID number is incorrect "));
sl@0
  1009
	TestGzipHeaderIdIncorrectL();
sl@0
  1010
	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4296 CEZGZipToFile class fails while decompressing the gzip file with the CRC changed in the trailer "));
sl@0
  1011
	TestGzipTrailerCRCL();
sl@0
  1012
	test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4297 Out of Memory(OOM) test for CEZFileToGZip & CEZGZipToFile class "));
sl@0
  1013
	TestOOMGzipL();
sl@0
  1014
	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) "));
sl@0
  1015
	TestDEF117325ToGZipL();
sl@0
  1016
	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) "));
sl@0
  1017
	TestDEF117325ToFileL();
sl@0
  1018
		
sl@0
  1019
sl@0
  1020
#if !defined(__WINS__)
sl@0
  1021
	CFileMan* fMan=CFileMan::NewL(TheFs);
sl@0
  1022
   	test(fMan!=NULL);
sl@0
  1023
   	CleanupStack::PushL(fMan);
sl@0
  1024
 	err = fMan->RmDir(_L("C:\\test\\gzip"));
sl@0
  1025
 	CleanupStack::PopAndDestroy(1);
sl@0
  1026
#endif
sl@0
  1027
 	
sl@0
  1028
 	CleanupStack::PopAndDestroy(1);
sl@0
  1029
	
sl@0
  1030
	}	
sl@0
  1031
sl@0
  1032
GLDEF_C TInt E32Main()
sl@0
  1033
	{
sl@0
  1034
	
sl@0
  1035
	__UHEAP_MARK;
sl@0
  1036
sl@0
  1037
	test.Printf(_L("\n"));
sl@0
  1038
	test.Title();
sl@0
  1039
	test.Start( _L("Starting Gzip Tests..") );
sl@0
  1040
sl@0
  1041
	TheTrapCleanup=CTrapCleanup::New();
sl@0
  1042
sl@0
  1043
	TRAPD(err,RunTestL());
sl@0
  1044
	test (err==KErrNone);
sl@0
  1045
sl@0
  1046
	test.End();
sl@0
  1047
	test.Close();
sl@0
  1048
	
sl@0
  1049
	delete TheTrapCleanup;
sl@0
  1050
sl@0
  1051
	__UHEAP_MARKEND;
sl@0
  1052
	return KErrNone;
sl@0
  1053
sl@0
  1054
	}