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.
17 #include <ezcompressor.h>
18 #include <ezdecompressor.h>
20 #include <ezfilebuffer.h>
25 @SYMTestCaseID SYSLIB-EZLIB-CT-0819
26 @SYMTestCaseDesc Compression and decompression of a file test
28 @SYMTestActions Read the input file given as the parameter from the command line.
29 Compress and decompress the read file.
31 @SYMTestExpectedResults Test must not fail
35 LOCAL_C void doExampleL()
40 TInt cmdLineLen = User::CommandLineLength();
44 _LIT(KUsage,"Usage:ezfile filename\n");
45 console->Printf(KUsage);
48 //(cmdLineLen > 0) case
49 HBufC *argv = HBufC::NewLC(cmdLineLen);
50 TPtr16 argPtr=argv->Des();
51 User::CommandLine(argPtr);
53 TLex arguments(*argv);
54 TPtrC inputFile(arguments.NextToken());
56 HBufC *outputFile = HBufC::NewLC(inputFile.Length()+2);
58 outputFile->Des().Format(KOfl,&inputFile);
60 HBufC *uncompressedFile = HBufC::NewLC(inputFile.Length()+1);
62 uncompressedFile->Des().Format(KUfl,&inputFile);
68 _LIT(KInfo,"Compressing file %S\n");
69 console->Printf(KInfo,&inputFile);
71 User::LeaveIfError(input.Open(rfs, inputFile,EFileStream | EFileRead | EFileShareAny));
72 CleanupClosePushL(input);
73 err = output.Create(rfs, *outputFile,EFileStream | EFileWrite | EFileShareExclusive);
74 if (err == KErrAlreadyExists)
75 User::LeaveIfError(output.Open(rfs, *outputFile,EFileStream | EFileWrite | EFileShareExclusive));
77 User::LeaveIfError(err);
78 CleanupClosePushL(output);
80 CEZFileBufferManager *fb = CEZFileBufferManager::NewLC(input,output,16384);
81 CEZCompressor *def = CEZCompressor::NewLC(*fb);
83 while (def->DeflateL()){/*do nothing*/}
85 _LIT(KHoorah,"Hoorah");
86 console->Printf(KHoorah);
88 CleanupStack::PopAndDestroy(4);
90 User::LeaveIfError(input.Open(rfs, *outputFile,EFileStream | EFileRead | EFileShareAny));
91 CleanupClosePushL(input);
92 err = output.Create(rfs, *uncompressedFile,EFileStream | EFileWrite | EFileShareExclusive);
93 if (err == KErrAlreadyExists)
94 User::LeaveIfError(output.Open(rfs, *uncompressedFile,EFileStream | EFileWrite | EFileShareExclusive));
96 User::LeaveIfError(err);
97 CleanupClosePushL(output);
98 fb = CEZFileBufferManager::NewLC(input,output,16384);
99 CEZDecompressor *inf = CEZDecompressor::NewLC(*fb);
101 while (inf->InflateL()){/*do nothing*/}
103 console->Printf(KHoorah);
105 CleanupStack::PopAndDestroy(7);