Update contrib.
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 #if !defined(__WINS__)
20 _LIT(KPath, "Z:\\test\\gzip\\");
22 _LIT(KPath, "C:\\test\\gzip\\");
25 _LIT(KOutputFilePath, "C:\\test\\gzip\\");
27 _LIT(KInputFile, "Hello.txt");
28 _LIT(KCompressFile,"Hello.gz");
29 _LIT(KDecompressFile,"Hello_Decompress.txt");
32 static RTest test(_L("gziptest.exe"));
34 static CTrapCleanup* TheTrapCleanup = NULL;
35 static TInt TheBufferSize = 500;
36 static TFileName TheInputFile(KInputFile);
37 static TFileName TheCompressFile(KCompressFile);
38 static TFileName TheDecompressFile(KDecompressFile);
40 static void CompressFileL(TFileName& aInputFile, TFileName& aCompressFile, TInt aBufferSize = TheBufferSize);
41 static void DecompressFileL(TFileName& aInputFile, TFileName& aDecompressFile, TInt aBufferSize = TheBufferSize);
42 static void CompareFileDataL(TFileName& aSourceFile, TFileName& aDestFile, TInt& aCompare);
43 static void ThreadForPanicTest(TThreadFunction aPanicThreadFunc);
45 inline void DeleteFile(TFileName& aFileName, TBool aPathSpecified = EFalse)
47 TFileName deleteFilePath;
50 deleteFilePath.Append(KOutputFilePath);
52 deleteFilePath.Append(aFileName);
54 TRAPD(error, TheFs.Delete(deleteFilePath));
56 test.Printf(_L("File not deleted: %S"), &deleteFilePath);
59 static void CompressFileL(TFileName& aInputFile, TFileName& aCompressFile, TInt aBufferSize)
61 TFileName inputFilePath(KPath);
62 inputFilePath.Append(aInputFile);
64 TFileName compressFilePath(KOutputFilePath);
65 compressFilePath.Append(aCompressFile);
68 User::LeaveIfError(input.Open(TheFs,inputFilePath, EFileStream | EFileRead | EFileShareReadersOnly));
69 CleanupClosePushL(input);
71 CEZFileToGZip *fileToGzip = NULL;
72 TRAPD(error, fileToGzip = CEZFileToGZip::NewL(TheFs, compressFilePath, input, aBufferSize));
73 test(error == KErrNone);
74 CleanupStack::PushL(fileToGzip);
76 while(fileToGzip->DeflateL()){/*do nothing*/}
78 CleanupStack::PopAndDestroy(2);
81 static void DecompressFileL(TFileName& aCompressFile, TFileName& aDecompressFile, TInt aBufferSize)
84 TFileName compressFilePath(KPath);
85 compressFilePath.Append(aCompressFile);
87 TFileName decompressFilePath(KOutputFilePath);
88 decompressFilePath.Append(aDecompressFile);
91 User::LeaveIfError(output.Replace(TheFs, decompressFilePath, EFileStream | EFileWrite | EFileShareExclusive));
92 CleanupClosePushL(output);
94 CEZGZipToFile *gzipToFile = NULL;
95 TRAPD(error, gzipToFile = CEZGZipToFile::NewL(TheFs, compressFilePath, output, aBufferSize));
96 test(error == KErrNone);
97 CleanupStack::PushL(gzipToFile);
99 while (gzipToFile->InflateL()){/*do nothing*/}
101 CleanupStack::PopAndDestroy(2);
105 static void CompareFileDataL(TFileName& aSourceFile, TFileName& aDestFile, TInt& aCompare)
108 TFileName sourceFilePath(KPath);
109 sourceFilePath.Append(aSourceFile);
111 TFileName destFilePath(KOutputFilePath);
112 destFilePath.Append(aDestFile);
115 User::LeaveIfError(source.Open(TheFs,sourceFilePath, EFileStream | EFileRead | EFileShareReadersOnly));
116 CleanupClosePushL(source);
119 source.Size(sourceSize);
120 test(sourceSize > 0);
122 HBufC8* sourceData = NULL;
123 TRAPD(error, sourceData = HBufC8::NewMaxL(sourceSize));
124 test(error == KErrNone);
125 CleanupStack::PushL(sourceData);
127 TPtr8 tSourceBufPtr = sourceData->Des();
128 User::LeaveIfError(source.Read(0, tSourceBufPtr, sourceSize));
131 User::LeaveIfError(dest.Open(TheFs,destFilePath, EFileStream | EFileWrite | EFileShareExclusive));
132 CleanupClosePushL(dest);
138 HBufC8* destData = NULL;
139 TRAP(error, destData = HBufC8::NewMaxL(destSize));
140 test(error == KErrNone);
141 CleanupStack::PushL(destData);
143 TPtr8 tDestBufPtr = destData->Des();
144 User::LeaveIfError(dest.Read(0, tDestBufPtr, destSize));
146 aCompare = sourceData->Compare(*destData);
148 CleanupStack::PopAndDestroy(4);
152 static void ThreadForPanicTest(TThreadFunction aPanicThreadFunc)
154 TRequestStatus threadStatus(KRequestPending);
155 TRequestStatus threadStatus1(KRequestPending);
158 TBool justInTime = User::JustInTime();
159 User::SetJustInTime(EFalse);
161 test.Printf(_L("Starting thread for invalid panic test...\n"));
162 TInt err=thread.Create( _L("Panic thread"),aPanicThreadFunc,KDefaultStackSize,0x1000,0x1000,NULL,EOwnerThread );
164 test.Printf(_L("Thread Creation returned following error code: %d \n"), err);
165 test(err == KErrNone);
167 thread.Logon(threadStatus);
169 User::WaitForRequest(threadStatus);
172 __ASSERT_ALWAYS(thread.ExitType() == EExitPanic,User::Panic(_L("Thread panic mismatch."),KErrGeneral));
173 test.Printf(_L("Invalid Panic test completed successfully for udeb build.\n"));
175 test.Printf(_L("Invalid Panic test completed successfully for urel build.\n"));
178 thread.Logon(threadStatus1);
179 thread.Kill(KErrNone);
180 User::WaitForRequest(threadStatus1);
181 test(threadStatus1 == KErrNone);
183 CLOSE_AND_WAIT(thread);
185 User::SetJustInTime(justInTime);
189 @SYMTestCaseID SYSLIB-EZLIB2-UT-4286
190 @SYMTestCaseDesc To ensure a file can be compressed to a gzip file and then correctly
191 decompressed back to its original state using classes from gzip.cpp.
192 Overwrite output file to verify existing file can be re-used.
193 @SYMTestPriority High
194 @SYMTestActions 1. Open existing test file and pass it to CEZFileToGZip::NewL() &
195 compress using CEZFileToGZip::DeflateL() function
196 2. Create or open output decompressed file and pass compressed file to
197 CEZGZipToFile::NewL() & decompress using CEZGZipToFile::InflateL() function
198 3. Compare original and new file, they should be identical
199 4. Repeat Steps 1 - 3 overwriting existing compressed output file
200 @SYMTestExpectedResults Original test file should be the same as the file generated
201 after decompressing it & the test must not fail
204 void TestCompressDecompressGzip()
206 TRAPD(error, CompressFileL(TheInputFile, TheCompressFile));
207 test(error == KErrNone);
208 TRAP(error, DecompressFileL(TheCompressFile, TheDecompressFile));
209 test(error == KErrNone);
213 TRAP(error, CompareFileDataL(TheInputFile, TheDecompressFile, compare));
214 test(error == KErrNone);
217 RDebug::Printf("Input file data is same as the Decompressed file data");
219 RDebug::Printf("Input file data differs from Decompressed file data");
221 #if !defined(__WINS__)
222 DeleteFile(TheCompressFile);
223 DeleteFile(TheDecompressFile);
226 //Compress & decompress the same file again to overwrite the existing file &
227 //..to verify that the existing files can be re-used
228 TRAP(error, CompressFileL(TheInputFile, TheCompressFile));
229 test(error == KErrNone);
230 TRAP(error, DecompressFileL(TheCompressFile, TheDecompressFile));
231 test(error == KErrNone);
233 #if !defined(__WINS__)
234 DeleteFile(TheCompressFile);
235 DeleteFile(TheDecompressFile);
240 @SYMTestCaseID SYSLIB-EZLIB2-UT-4287
241 @SYMTestCaseDesc To ensure a file can be compressed to a gzip file and then correctly
242 decompressed back using buffer size as small & big.
244 @SYMTestPriority High
245 @SYMTestActions 1. Open existing test file and pass it to CEZFileToGZip::NewL() &
246 compress using CEZFileToGZip::DeflateL() with buffer size as "11"
247 2. Create or open output decompressed file and pass compressed file
248 to CEZGZipToFile::NewL() & decompress using CEZGZipToFile::InflateL()
249 with buffer size as "10"
250 3. Repeat Steps 1 & 2 using buffer size as 10 times the file size
251 @SYMTestExpectedResults Files should be compressed with no errors i.e. KErrNone & the test must not fail
254 void TestOutputBuffSize()
257 TRAPD(error, CompressFileL(TheInputFile, TheCompressFile, 10));
258 test(error == KErrNone);
260 TRAP(error, DecompressFileL(TheCompressFile, TheDecompressFile, 10));
261 test(error == KErrNone);
263 TInt bufferSize = 10 * TheBufferSize;
265 #if !defined(__WINS__)
266 DeleteFile(TheCompressFile);
267 DeleteFile(TheDecompressFile);
270 //Compress & decompress the same file again to overwrite the existing file &
271 //..to verify that the existing files can be re-used & with buffer size as big
272 TRAP(error, CompressFileL(TheInputFile, TheCompressFile, bufferSize));
273 test(error == KErrNone);
275 TRAP(error, DecompressFileL(TheCompressFile, TheDecompressFile, bufferSize));
276 test(error == KErrNone);
278 #if !defined(__WINS__)
279 DeleteFile(TheCompressFile);
280 DeleteFile(TheDecompressFile);
285 TInt RfileInitForCEZFileToGZip(TAny*)
288 TFileName compressFilePath(KOutputFilePath);
289 compressFilePath.Append(TheCompressFile);
291 CTrapCleanup* cleanup = CTrapCleanup::New();
292 TRAPD(error, CEZFileToGZip::NewL(TheFs, compressFilePath, rfile, TheBufferSize));
298 TInt RfileInitForCEZGZipToFile(TAny*)
301 TFileName compressFilePath(KOutputFilePath);
302 compressFilePath.Append(TheCompressFile);
304 CTrapCleanup* cleanup = CTrapCleanup::New();
305 TRAPD(error, CEZGZipToFile::NewL(TheFs, compressFilePath, rfile, TheBufferSize));
313 @SYMTestCaseID SYSLIB-EZLIB2-UT-4288
314 @SYMTestCaseDesc CEZFileToGZip & CEZGZipToFile class initialisation fails when
315 invalid input RFile object supplied
316 @SYMTestPriority High
317 @SYMTestActions 1. Pass NULL RFile input parameter to CEZFileToGZip::NewL()
318 2. Pass NULL RFile input parameter to CEZGZipToFile::NewL()
319 @SYMTestExpectedResults NewL() method should panic & the test must not fail
322 void TestRFileInitialisation()
324 test.Printf(_L("Panic Thread: CEZFileToGzip Class initialisation fails when invalid input rfile supplied"));
325 ThreadForPanicTest(RfileInitForCEZFileToGZip);
326 test.Printf(_L("Panic Thread: CEZGZipToFile Class initialisation fails when invalid input rfile supplied"));
327 ThreadForPanicTest(RfileInitForCEZGZipToFile);
331 @SYMTestCaseID SYSLIB-EZLIB2-UT-4289
332 @SYMTestCaseDesc CEZFileToGZip, CEZGZipToFile class initialisation fails
333 when invalid output filename supplied
334 @SYMTestPriority High
335 @SYMTestActions 1. Pass invalid filename output parameter to CEZFileToGZip::NewL()
336 2. Pass invalid filename output parameter to CEZGZipToFile::NewL()
337 Note: Filename contains invalid characters
338 @SYMTestExpectedResults NewL() method should leave with error message & the test must not fail
341 void TestInvalidFilenameL()
344 _LIT(KInvalidGzip, "*******.gz");
345 TFileName invalidGzip(KOutputFilePath);
346 invalidGzip.Append(KInvalidGzip);
348 _LIT(KInvalidFile, "*******.txt");
349 TFileName invalidFile(KOutputFilePath);
350 invalidFile.Append(KInvalidFile);
352 TFileName inputFilePath(KPath);
353 inputFilePath.Append(TheInputFile);
356 User::LeaveIfError(input.Open(TheFs,inputFilePath,EFileStream | EFileRead | EFileShareReadersOnly));
357 CleanupClosePushL(input);
359 TRAPD(error, CEZFileToGZip::NewL(TheFs, invalidGzip, input, TheBufferSize));
360 test(error != KErrNone);
362 CleanupStack::PopAndDestroy(1);
365 TInt err = output.Create(TheFs, invalidFile,EFileStream | EFileWrite | EFileShareExclusive);
366 test(error != KErrNone);
371 @SYMTestCaseID SYSLIB-EZLIB2-UT-4290
372 @SYMTestCaseDesc Ensure if output file exists and is read only then it cannot be
373 overwritten with CEZFileToGZip & CEZGZipToFile class
374 @SYMTestPriority High
375 @SYMTestActions 1. Pass existing read only output filename parameter to CEZFileToGZip::NewL()
376 2. Pass existing read only output filename parameter to CEZGZipToFile::NewL()
377 & decompress using CEZGZipToFile::InflateL()
378 @SYMTestExpectedResults CEZFileToGZip::NewL() method should leave with error message, CEZGZipToFile::Inflate()
379 should leave with error message & the test must not fail
382 void TestOverwriteOutputFileL()
384 _LIT(KReadOnlyGzip, "Hello_Read_Only.gz");
385 TFileName readOnlyNewGZip(KOutputFilePath);
386 readOnlyNewGZip.Append(KReadOnlyGzip);
388 _LIT(KReadOnlyFile, "Hello_Read_Only.txt");
389 TFileName readOnlyNewFile(KOutputFilePath);
390 readOnlyNewFile.Append(KReadOnlyFile);
392 CFileMan* fMan=CFileMan::NewL(TheFs);
394 CleanupStack::PushL(fMan);
396 #if !defined(__WINS__)
397 TFileName readOnlyOldGZip(KPath);
398 readOnlyOldGZip.Append(KReadOnlyGzip);
399 TFileName readOnlyOldFile(KPath);
400 readOnlyOldFile.Append(KReadOnlyFile);
403 User::LeaveIfError(source.Open(TheFs,readOnlyOldGZip, EFileStream | EFileRead | EFileShareReadersOnly));
404 CleanupClosePushL(source);
405 TRAPD(error, fMan->Copy(source, readOnlyNewGZip));
406 test(error == KErrNone);
409 User::LeaveIfError(source1.Open(TheFs,readOnlyOldFile, EFileStream | EFileRead | EFileShareReadersOnly));
410 CleanupClosePushL(source1);
411 TRAP(error, fMan->Copy(source1, readOnlyNewFile));
412 test(error == KErrNone);
414 CleanupStack::PopAndDestroy(2);
417 TFileName inputFilePath(KPath);
418 inputFilePath.Append(TheInputFile);
421 User::LeaveIfError(input.Open(TheFs,inputFilePath,EFileStream | EFileRead | EFileShareReadersOnly));
422 CleanupClosePushL(input);
424 //setting attributes to read only for readOnlyGZip & readOnlyFile
425 TInt err = fMan->Attribs(readOnlyNewGZip, KEntryAttReadOnly, 0, 0);
426 test(err == KErrNone);
427 err = fMan->Attribs(readOnlyNewFile, KEntryAttReadOnly, 0, 0);
428 test(err == KErrNone);
430 TRAP(err, CEZFileToGZip::NewL(TheFs, readOnlyNewGZip, input, TheBufferSize));
431 test(err != KErrNone);
434 User::LeaveIfError(output.Open(TheFs,readOnlyNewFile,EFileStream | EFileRead | EFileShareReadersOnly));
435 CleanupClosePushL(output);
437 CEZGZipToFile * gzipToFile = NULL;
438 TRAP(err, gzipToFile = CEZGZipToFile::NewL(TheFs, readOnlyNewGZip, output, TheBufferSize));
439 test(err == KErrNone);
440 CleanupStack::PushL(gzipToFile);
442 while (err == KErrNone)
444 TRAP(err, gzipToFile->InflateL());
447 test(err != KErrNone);
449 CleanupStack::PopAndDestroy(4);
451 //removing the read only attrib before deleting the file
452 fMan=CFileMan::NewL(TheFs);
454 CleanupStack::PushL(fMan);
455 err = fMan->Attribs(readOnlyNewGZip, 0, KEntryAttReadOnly, 0);
456 test(err == KErrNone);
457 err = fMan->Attribs(readOnlyNewFile, 0, KEntryAttReadOnly, 0);
458 test(err == KErrNone);
460 CleanupStack::PopAndDestroy(1);
462 #if !defined(__WINS__)
463 DeleteFile(readOnlyNewGZip, ETrue);
464 DeleteFile(readOnlyNewFile, ETrue);
468 TInt RFSInitForCEZFileToGZipL(TAny*)
470 TFileName inputFilePath(KPath);
471 inputFilePath.Append(TheInputFile);
474 User::LeaveIfError(input.Open(TheFs,inputFilePath,EFileStream | EFileRead | EFileShareReadersOnly));
475 CleanupClosePushL(input);
477 TFileName compressFilePath(KOutputFilePath);
478 compressFilePath.Append(TheCompressFile);
480 CTrapCleanup* cleanup = CTrapCleanup::New();
482 TRAPD(error, CEZFileToGZip::NewL(rfs, compressFilePath, input, TheBufferSize));
485 CleanupStack::PopAndDestroy(1);
490 TInt RFSInitForCEZGZipToFileL(TAny*)
492 TFileName compressFilePath(KPath);
493 compressFilePath.Append(TheCompressFile);
495 TFileName decompressFilePath(KOutputFilePath);
496 decompressFilePath.Append(TheDecompressFile);
499 User::LeaveIfError(output.Replace(TheFs,decompressFilePath,EFileStream | EFileRead | EFileShareReadersOnly));
500 CleanupClosePushL(output);
502 CTrapCleanup* cleanup = CTrapCleanup::New();
504 TRAPD(error, CEZGZipToFile::NewL(rfs, compressFilePath, output, TheBufferSize));
507 CleanupStack::PopAndDestroy(1);
513 @SYMTestCaseID SYSLIB-EZLIB2-UT-4291
514 @SYMTestCaseDesc CEZFileToGZip & CEZGZipToFile class initialisation fails when
515 invalid RFs object is passed
516 @SYMTestPriority High
517 @SYMTestActions 1. Pass NULL RFs input parameter to CEZFileToGZip::NewL()
518 2. Pass NULL RFs input parameter to CEZGZipToFile::NewL()
519 @SYMTestExpectedResults NewL() method should panic & the test must not fail
522 void TestRFSInitialisation()
524 test.Printf(_L("Panic Thread: CEZFileToGZip Class initialisation fails when invalid RFS object is passed"));
525 ThreadForPanicTest(RFSInitForCEZFileToGZipL);
526 test.Printf(_L("Panic Thread: CEZGZipToFile Class initialisation fails when invalid RFS object is passed"));
527 ThreadForPanicTest(RFSInitForCEZGZipToFileL);
530 TInt BuffForEZFileToGZipAsZeroL(TAny*)
532 CTrapCleanup* cleanup = CTrapCleanup::New();
533 CompressFileL(TheInputFile, TheCompressFile, 0);
538 TInt BuffForEZFileToGZipAsNegativeL(TAny*)
540 CTrapCleanup* cleanup = CTrapCleanup::New();
541 CompressFileL(TheInputFile, TheCompressFile, -1);
546 TInt BuffForEZGZipToFileAsZeroL(TAny*)
548 CTrapCleanup* cleanup = CTrapCleanup::New();
549 DecompressFileL(TheCompressFile, TheDecompressFile, 0);
554 TInt BuffForEZGZipToFileAsNegativeL(TAny*)
556 CTrapCleanup* cleanup = CTrapCleanup::New();
557 DecompressFileL(TheCompressFile, TheDecompressFile, -1);
563 @SYMTestCaseID SYSLIB-EZLIB2-UT-4292
564 @SYMTestCaseDesc CEZFileToGZip & CEZGZipToFile class initialisation
565 fails when invalid buffer size parameter passed in
566 @SYMTestPriority High
567 @SYMTestActions 1. Pass buffer size parameter value as 0 to CEZFileToGZip::NewL()
568 2. Pass buffer size parameter as a negative value to CEZFileToGZip::NewL()
569 3. Pass buffer size parameter value as 0 to CEZGZipToFile::NewL()
570 4. Pass buffer size parameter as a negative value to CEZGZipToFile::NewL()
571 @SYMTestExpectedResults NewL() method should panic & the test must not fail
574 void TestInvalidBufferSize()
577 test.Printf(_L("Panic Thread: CEZFileToGZip Class initialisation fails when buffer size is passed as Zero"));
578 ThreadForPanicTest(BuffForEZFileToGZipAsZeroL);
579 test.Printf(_L("Panic Thread: CEZFileToGZip Class initialisation fails when buffer size is passed as Negative"));
580 ThreadForPanicTest(BuffForEZFileToGZipAsNegativeL);
581 test.Printf(_L("Panic Thread: CEZGZipToFile Class initialisation fails when buffer size is passed as Zero"));
582 ThreadForPanicTest(BuffForEZGZipToFileAsZeroL);
583 test.Printf(_L("Panic Thread: CEZGZipToFile Class initialisation fails when buffer size is passed as Negative"));
584 ThreadForPanicTest(BuffForEZGZipToFileAsNegativeL);
589 @SYMTestCaseID SYSLIB-EZLIB2-UT-4293
590 @SYMTestCaseDesc Compress & Decompress another file with CEZFileToGZip & CEZGZipToFile
591 after calling ResetL method
592 @SYMTestPriority High
593 @SYMTestActions 1. Open existing test file and pass it to CEZFileToGZip::NewL() & compress using CEZFileToGZip::DeflateL function
594 2. Call CEZFileToGZip::ResetL() with new file parameters
595 3. Compress the new file with CEZFileToGZip::DeflateL()
596 4. Create or open output decompressed file and pass compressed file to CEZGZipToFile::NewL() & decompress using CEZGZipToFile::InflateL() function
597 5. Call CEZGZipToFile::ResetL() with new compressed file parameters
598 6. Decompress the new compressed file with CEZGZipToFile::InflateL()
599 @SYMTestExpectedResults Files should be compressed with no errors i.e. KErrNone & the test must not fail
602 void TestCompressDecompressResetL()
605 TFileName inputFilePath(KPath);
606 inputFilePath.Append(TheInputFile);
608 _LIT(KGzipFile,"Hello_Reset.gz");
609 TFileName gzipFileName(KGzipFile);
610 TFileName compressfile(KOutputFilePath);
611 compressfile.Append(gzipFileName);
614 User::LeaveIfError(input.Open(TheFs,inputFilePath,EFileStream | EFileRead | EFileShareReadersOnly));
615 CleanupClosePushL(input);
617 CEZFileToGZip *fileToGzip = CEZFileToGZip::NewLC(TheFs, compressfile, input, TheBufferSize);
618 while(fileToGzip->DeflateL()){/*do nothing*/}
620 fileToGzip->ResetL(TheFs, compressfile, input, TheBufferSize);
621 while(fileToGzip->DeflateL()){/*do nothing*/}
623 CleanupStack::PopAndDestroy(2);
625 #if !defined(__WINS__)
626 DeleteFile(gzipFileName);
629 TFileName compressFilePath(KPath);
630 compressFilePath.Append(TheCompressFile);
632 _LIT(KTxtFile,"Hello_Reset.txt");
633 TFileName txtFileName(KTxtFile);
634 TFileName decompressfile(KOutputFilePath);
635 decompressfile.Append(txtFileName);
638 User::LeaveIfError(output.Replace(TheFs, decompressfile,EFileStream | EFileWrite | EFileShareExclusive));
639 CleanupClosePushL(output);
641 CEZGZipToFile *gzipToFile = CEZGZipToFile::NewLC(TheFs, compressFilePath, output, TheBufferSize);
642 while(gzipToFile->InflateL()){/*do nothing*/}
644 gzipToFile->ResetL(TheFs, compressFilePath, output, TheBufferSize);
645 while(gzipToFile->InflateL()){/*do nothing*/}
647 CleanupStack::PopAndDestroy(2);
649 #if !defined(__WINS__)
650 DeleteFile(txtFileName);
656 @SYMTestCaseID SYSLIB-EZLIB2-UT-4294
657 @SYMTestCaseDesc CEZGZipToFile class initialisation fails when source
658 gzip file header is malformed: Header is too small
659 @SYMTestPriority High
660 @SYMTestActions Pass corrupted gzip file as an input parameter to CEZGZipToFile::NewL()
661 Note: Change the header of existing gzip file by removing few characters
662 @SYMTestExpectedResults NewL() method should leave with error message KEZlibErrBadGZipHeader
663 & the test must not fail
666 void TestGzipHeaderSmallL()
669 _LIT(KGzFile,"Hello_HeaderChanged.gz");
670 TFileName compressfile(KPath);
671 compressfile.Append(KGzFile);
673 TFileName decompressFilePath(KOutputFilePath);
674 decompressFilePath.Append(TheDecompressFile);
677 User::LeaveIfError(output.Replace(TheFs, decompressFilePath,EFileStream | EFileWrite | EFileShareExclusive));
678 CleanupClosePushL(output);
680 TRAPD(error, CEZGZipToFile::NewL(TheFs, compressfile, output, TheBufferSize));
681 test(error == KEZlibErrBadGZipHeader);
683 CleanupStack::PopAndDestroy(1);
688 @SYMTestCaseID SYSLIB-EZLIB2-UT-4295
689 @SYMTestCaseDesc CEZGZipToFile class initialisation fails when source gzip file
690 header is malformed: Header ID number is incorrect
691 @SYMTestPriority High
692 @SYMTestActions Pass corrupted gzip file as an input parameter to CEZGZipToFile::NewL()
693 Note: Change the header ID of existing gzip file
694 @SYMTestExpectedResults NewL() method should leave with error message KEZlibErrBadGZipHeader
695 & the test must not fail
698 void TestGzipHeaderIdIncorrectL()
701 _LIT(KGzFile,"Hello_HeaderIdChanged.gz");
702 TFileName compressfile(KPath);
703 compressfile.Append(KGzFile);
705 TFileName decompressFilePath(KOutputFilePath);
706 decompressFilePath.Append(TheDecompressFile);
709 User::LeaveIfError(output.Replace(TheFs, decompressFilePath,EFileStream | EFileWrite | EFileShareExclusive));
710 CleanupClosePushL(output);
712 TRAPD(error, CEZGZipToFile::NewL(TheFs, compressfile, output, TheBufferSize));
713 test(error == KEZlibErrBadGZipHeader);
715 CleanupStack::PopAndDestroy(1);
720 @SYMTestCaseID SYSLIB-EZLIB2-UT-4296
721 @SYMTestCaseDesc CEZGZipToFile class fails while decompressing the gzip
722 file with the CRC changed in the trailer
723 @SYMTestPriority High
724 @SYMTestActions Pass corrupted gzip file as an input parameter to CEZGZipToFile::NewL()
725 Note: Change the CRC within the Trailer of existing gzip file
726 @SYMTestExpectedResults NewL() method should leave with error message KErrNotFound & the test must not fail
727 Note: KErrNotFound error is fired while opening the corrupted gzip file
730 void TestGzipTrailerCRCL()
733 _LIT(KGzFile,"Hello_TrailerIdChanged.gz");
734 TFileName compressfile(KPath);
735 compressfile.Append(KGzFile);
737 TFileName decompressFilePath(KOutputFilePath);
738 decompressFilePath.Append(TheDecompressFile);
741 User::LeaveIfError(output.Replace(TheFs, decompressFilePath,EFileStream | EFileWrite | EFileShareExclusive));
742 CleanupClosePushL(output);
744 TRAPD(error, CEZGZipToFile::NewL(TheFs, compressfile, output, TheBufferSize));
745 test(error == KErrNotFound);
747 CleanupStack::PopAndDestroy(1);
751 void TestCompressDecompressL()
754 TFileName inputFilePath(KPath);
755 inputFilePath.Append(TheInputFile);
757 TFileName compressFilePath(KOutputFilePath);
758 compressFilePath.Append(TheCompressFile);
761 User::LeaveIfError(input.Open(TheFs,inputFilePath,EFileStream | EFileRead | EFileShareReadersOnly));
762 CleanupClosePushL(input);
764 CEZFileToGZip *fileToGzip = CEZFileToGZip::NewLC(TheFs, compressFilePath, input, TheBufferSize);
765 while(fileToGzip->DeflateL()){/*do nothing*/}
767 TFileName decompressFilePath(KOutputFilePath);
768 decompressFilePath.Append(TheDecompressFile);
770 TFileName compressFilePath1(KPath);
771 compressFilePath1.Append(TheCompressFile);
774 User::LeaveIfError(output.Replace(TheFs, decompressFilePath,EFileStream | EFileWrite | EFileShareExclusive));
775 CleanupClosePushL(output);
777 CEZGZipToFile *gzipToFile = CEZGZipToFile::NewLC(TheFs, compressFilePath1, output, TheBufferSize);
778 while(gzipToFile->InflateL()){/*do nothing*/}
780 CleanupStack::PopAndDestroy(4);
782 #if !defined(__WINS__)
783 DeleteFile(TheCompressFile);
784 DeleteFile(TheDecompressFile);
789 @SYMTestCaseID SYSLIB-EZLIB2-UT-4297
790 @SYMTestCaseDesc Out of Memory(OOM) test for CEZFileToGZip & CEZGZipToFile class
791 @SYMTestPriority High
792 @SYMTestActions 1. Set Heap Failure using the macro as:
793 __UHEAP_SETFAIL(RHeap::EDeterministic, count)
794 2. Mark the heap using macro: __UHEAP_MARK
795 3. Open existing test file and pass it to CEZFileToGZip::NewL() compress using CEZFileToGZip::DeflateL() function
796 4. Create or open output decompressed file and pass compressed file to CEZGZipToFile::NewL() & decompress using CEZGZipToFile::InflateL() function
797 5. Check there is no memory leak using the macro: __UHEAP_MARKEND
798 6. Repeat the Steps 1-5 increasing the heap value rate i.e. count
799 @SYMTestExpectedResults The test succeeds with no memory leak on the heap as well as no errors (i.e. KErrNone)
800 & the test must not fail
805 TInt processHandlesS = 0;
806 TInt threadHandlesS = 0;
807 TInt processHandlesE = 0;
808 TInt threadHandlesE = 0;
810 RThread().HandleCount(processHandlesS, threadHandlesS);
811 for(TInt count=1; count<=100; ++count)
813 // Setting Heap failure for OOM test
814 __UHEAP_SETFAIL(RHeap::EDeterministic, count);
817 TRAP(err,TestCompressDecompressL());
821 RDebug::Print(_L("The test succeeded at heap failure rate=%d.\n"), count);
826 test(err == KErrNoMemory);
831 test(err == KErrNone);
834 RThread().HandleCount(processHandlesE, threadHandlesE);
836 test(processHandlesS == processHandlesE);
837 test(threadHandlesS == threadHandlesE);
841 * Helper function for TestDEF117325ToGZipL
842 * Deflates a file and then calls ResetL()
846 _LIT(KGzipFile,"Hello_Reset.gz");
847 TFileName compressFile(KOutputFilePath);
848 compressFile.Append(KGzipFile);
850 TFileName inputFilePath(KPath);
851 inputFilePath.Append(TheInputFile);
854 User::LeaveIfError(input.Open(TheFs, inputFilePath, EFileStream | EFileRead | EFileShareReadersOnly));
855 CleanupClosePushL(input);
857 CEZFileToGZip *fileToGzip = CEZFileToGZip::NewLC(TheFs, compressFile, input, TheBufferSize);
858 while(fileToGzip->DeflateL()) {/*do nothing*/}
860 fileToGzip->ResetL(TheFs, compressFile, input, TheBufferSize);
862 CleanupStack::PopAndDestroy(2);
864 #if !defined(__WINS__)
865 DeleteFile(TheInputFile);
870 * Helper function for TestDEF117325ToFileL
871 * Inflates a GZip file and then calls ResetL()
875 _LIT(KTxtFile, "Hello_Reset.txt");
876 TFileName decompressFile(KOutputFilePath);
877 decompressFile.Append(KTxtFile);
879 TFileName compressFilePath(KPath);
880 compressFilePath.Append(TheCompressFile);
883 User::LeaveIfError(output.Replace(TheFs, decompressFile, EFileStream | EFileWrite | EFileShareExclusive));
884 CleanupClosePushL(output);
886 CEZGZipToFile *gzipToFile = CEZGZipToFile::NewLC(TheFs, compressFilePath, output, TheBufferSize);
887 while(gzipToFile->InflateL()){/*do nothing*/}
889 gzipToFile->ResetL(TheFs, compressFilePath, output, TheBufferSize);
891 CleanupStack::PopAndDestroy(2);
893 #if !defined(__WINS__)
894 DeleteFile(TheCompressFile);
899 * Helper function for TestDEF117325ToGZipL and TestDEF117325ToFileL.
900 * Checks for memory leaks in OOM situations.
902 void DEF117325L(void (*aResetL)())
905 for(TInt count = 0; count <= 100; count++)
907 // Setting Heap failure for OOM test
908 __UHEAP_SETFAIL(RHeap::EDeterministic, count);
911 TRAP(err, aResetL());
918 RDebug::Print(_L("The test succeeded at heap failure rate = %d.\n"), count);
923 test(err == KErrNoMemory);
929 @SYMTestCaseID SYSLIB-EZLIB2-UT-4319
930 @SYMTestCaseDesc To test that there are no memory leaks when calling ResetL from CEZFileToGZip
931 @SYMTestPriority Medium
932 @SYMTestActions 1. Set Heap Failure using the macro __UHEAP_SETFAIL(RHeap::EDeterministic, count)
933 2. Mark the heap using macro __UHEAP_MARK
934 3. Open an existing test file and pass it to CEZFileToGZip::NewL() and compress it using CEZFileToGZip::DeflateL function
935 4. Call CEZFileToGZip::ResetL() with new file parameters
936 5. Check there is no memory leak using the macro __UHEAP_MARKEND
937 6. Repeat steps 1 - 5 increasing the heap value rate i.e. count
938 @SYMTestExpectedResults The test succeeds with no memory leak on the heap as well as no errors (i.e. KErrNone)
941 void TestDEF117325ToGZipL()
943 DEF117325L(&DeflateResetL);
947 @SYMTestCaseID SYSLIB-EZLIB2-UT-4320
948 @SYMTestCaseDesc To test that there are no memory leaks when calling ResetL from CEZGZipToFile
949 @SYMTestPriority Medium
950 @SYMTestActions 1. Open an existing test file and pass it to CEZFileToGZip::NewL() and compress it using CEZFileToGZip::DeflateL
951 2. Set Heap Failure using the macro __UHEAP_SETFAIL(RHeap::EDeterministic, count)
952 3. Mark the heap using macro __UHEAP_MARK
953 4. Open the compressed test file and pass it to CEZGZipToFile::NewL() and decompress it using CEZGZipToFile::InflateL function
954 5. Call CEZGZipToFile::ResetL() with new file parameters
955 6. Check there is no memory leak using the macro __UHEAP_MARKEND
956 7. Repeat steps 2 - 6 increasing the heap value rate i.e. count
957 @SYMTestExpectedResults The test succeeds with no memory leak on the heap as well as no errors (i.e. KErrNone)
960 void TestDEF117325ToFileL()
963 // Create a GZip file that can be used by CEZGZipToFile
964 CompressFileL(TheInputFile, TheCompressFile);
966 DEF117325L(&InflateResetL);
968 #if !defined(__WINS__)
969 DeleteFile(TheCompressFile);
978 User::LeaveIfError(TheFs.Connect()); //Connect to file session
979 CleanupClosePushL(TheFs);
981 #if !defined(__WINS__)
982 TInt err = TheFs.MkDirAll(KOutputFilePath);
983 if(err != KErrNone && err != KErrAlreadyExists)
985 test.Printf(_L("Error while creating dir => Error: %d"), err);
990 test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4286 Compression - Decompression of Gzip file "));
991 TestCompressDecompressGzip();
992 test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4287 Compression - Decompression of Gzip file with big & small buffer size "));
993 TestOutputBuffSize();
994 test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4288 Class initialisation fails when invalid input rfile supplied "));
995 TestRFileInitialisation();
996 test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4289 Class initialisation fails when invalid output filename supplied "));
997 TestInvalidFilenameL();
998 test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4290 Class initialisation fails while overwriting the read only output file "));
999 TestOverwriteOutputFileL();
1000 test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4291 Class initialisation fails when invalid RFS object is passed "));
1001 TestRFSInitialisation();
1002 test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4292 Panic Thread: Class initialisation fails when invalid buffer size parameter passed in "));
1003 TestInvalidBufferSize();
1004 test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4293 Compress another file with CEZFileToGZip & CEZGZipToFile after calling ResetL method "));
1005 TestCompressDecompressResetL();
1006 test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4294 CEZGZipToFile class initialisation fails when source gzip file header is malformed: Header is too small "));
1007 TestGzipHeaderSmallL();
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 "));
1009 TestGzipHeaderIdIncorrectL();
1010 test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4296 CEZGZipToFile class fails while decompressing the gzip file with the CRC changed in the trailer "));
1011 TestGzipTrailerCRCL();
1012 test.Next(_L(" @SYMTestCaseID:SYSLIB-EZLIB2-UT-4297 Out of Memory(OOM) test for CEZFileToGZip & CEZGZipToFile class "));
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) "));
1015 TestDEF117325ToGZipL();
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) "));
1017 TestDEF117325ToFileL();
1020 #if !defined(__WINS__)
1021 CFileMan* fMan=CFileMan::NewL(TheFs);
1023 CleanupStack::PushL(fMan);
1024 err = fMan->RmDir(_L("C:\\test\\gzip"));
1025 CleanupStack::PopAndDestroy(1);
1028 CleanupStack::PopAndDestroy(1);
1032 GLDEF_C TInt E32Main()
1037 test.Printf(_L("\n"));
1039 test.Start( _L("Starting Gzip Tests..") );
1041 TheTrapCleanup=CTrapCleanup::New();
1043 TRAPD(err,RunTestL());
1044 test (err==KErrNone);
1049 delete TheTrapCleanup;