1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/compressionlibs/ziplib/test/rtest/ezfile/ezfile.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,107 @@
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 "eustd.h"
1.20 +#include <ezcompressor.h>
1.21 +#include <ezdecompressor.h>
1.22 +#include <ezlib.h>
1.23 +#include <ezfilebuffer.h>
1.24 +
1.25 +#include <f32file.h>
1.26 +
1.27 +/**
1.28 +@SYMTestCaseID SYSLIB-EZLIB-CT-0819
1.29 +@SYMTestCaseDesc Compression and decompression of a file test
1.30 +@SYMTestPriority High
1.31 +@SYMTestActions Read the input file given as the parameter from the command line.
1.32 + Compress and decompress the read file.
1.33 + Leave on error.
1.34 +@SYMTestExpectedResults Test must not fail
1.35 +@SYMREQ REQ0000
1.36 +*/
1.37 +
1.38 +LOCAL_C void doExampleL()
1.39 + {
1.40 + RFs rfs;
1.41 + rfs.Connect();
1.42 +
1.43 + TInt cmdLineLen = User::CommandLineLength();
1.44 +
1.45 + if (cmdLineLen <= 0)
1.46 + {
1.47 + _LIT(KUsage,"Usage:ezfile filename\n");
1.48 + console->Printf(KUsage);
1.49 + User::Leave(1);
1.50 + }
1.51 + //(cmdLineLen > 0) case
1.52 + HBufC *argv = HBufC::NewLC(cmdLineLen);
1.53 + TPtr16 argPtr=argv->Des();
1.54 + User::CommandLine(argPtr);
1.55 +
1.56 + TLex arguments(*argv);
1.57 + TPtrC inputFile(arguments.NextToken());
1.58 +
1.59 + HBufC *outputFile = HBufC::NewLC(inputFile.Length()+2);
1.60 + _LIT(KOfl,"%S.z");
1.61 + outputFile->Des().Format(KOfl,&inputFile);
1.62 +
1.63 + HBufC *uncompressedFile = HBufC::NewLC(inputFile.Length()+1);
1.64 + _LIT(KUfl,"%S1");
1.65 + uncompressedFile->Des().Format(KUfl,&inputFile);
1.66 +
1.67 + RFile input;
1.68 + RFile output;
1.69 + TInt err;
1.70 +
1.71 + _LIT(KInfo,"Compressing file %S\n");
1.72 + console->Printf(KInfo,&inputFile);
1.73 +
1.74 + User::LeaveIfError(input.Open(rfs, inputFile,EFileStream | EFileRead | EFileShareAny));
1.75 + CleanupClosePushL(input);
1.76 + err = output.Create(rfs, *outputFile,EFileStream | EFileWrite | EFileShareExclusive);
1.77 + if (err == KErrAlreadyExists)
1.78 + User::LeaveIfError(output.Open(rfs, *outputFile,EFileStream | EFileWrite | EFileShareExclusive));
1.79 + else
1.80 + User::LeaveIfError(err);
1.81 + CleanupClosePushL(output);
1.82 +
1.83 + CEZFileBufferManager *fb = CEZFileBufferManager::NewLC(input,output,16384);
1.84 + CEZCompressor *def = CEZCompressor::NewLC(*fb);
1.85 +
1.86 + while (def->DeflateL()){/*do nothing*/}
1.87 +
1.88 + _LIT(KHoorah,"Hoorah");
1.89 + console->Printf(KHoorah);
1.90 +
1.91 + CleanupStack::PopAndDestroy(4);
1.92 +
1.93 + User::LeaveIfError(input.Open(rfs, *outputFile,EFileStream | EFileRead | EFileShareAny));
1.94 + CleanupClosePushL(input);
1.95 + err = output.Create(rfs, *uncompressedFile,EFileStream | EFileWrite | EFileShareExclusive);
1.96 + if (err == KErrAlreadyExists)
1.97 + User::LeaveIfError(output.Open(rfs, *uncompressedFile,EFileStream | EFileWrite | EFileShareExclusive));
1.98 + else
1.99 + User::LeaveIfError(err);
1.100 + CleanupClosePushL(output);
1.101 + fb = CEZFileBufferManager::NewLC(input,output,16384);
1.102 + CEZDecompressor *inf = CEZDecompressor::NewLC(*fb);
1.103 +
1.104 + while (inf->InflateL()){/*do nothing*/}
1.105 +
1.106 + console->Printf(KHoorah);
1.107 +
1.108 + CleanupStack::PopAndDestroy(7);
1.109 + rfs.Close();
1.110 + }