sl@0: // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "eustd.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-EZLIB-CT-0819 sl@0: @SYMTestCaseDesc Compression and decompression of a file test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Read the input file given as the parameter from the command line. sl@0: Compress and decompress the read file. sl@0: Leave on error. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: sl@0: LOCAL_C void doExampleL() sl@0: { sl@0: RFs rfs; sl@0: rfs.Connect(); sl@0: sl@0: TInt cmdLineLen = User::CommandLineLength(); sl@0: sl@0: if (cmdLineLen <= 0) sl@0: { sl@0: _LIT(KUsage,"Usage:ezfile filename\n"); sl@0: console->Printf(KUsage); sl@0: User::Leave(1); sl@0: } sl@0: //(cmdLineLen > 0) case sl@0: HBufC *argv = HBufC::NewLC(cmdLineLen); sl@0: TPtr16 argPtr=argv->Des(); sl@0: User::CommandLine(argPtr); sl@0: sl@0: TLex arguments(*argv); sl@0: TPtrC inputFile(arguments.NextToken()); sl@0: sl@0: HBufC *outputFile = HBufC::NewLC(inputFile.Length()+2); sl@0: _LIT(KOfl,"%S.z"); sl@0: outputFile->Des().Format(KOfl,&inputFile); sl@0: sl@0: HBufC *uncompressedFile = HBufC::NewLC(inputFile.Length()+1); sl@0: _LIT(KUfl,"%S1"); sl@0: uncompressedFile->Des().Format(KUfl,&inputFile); sl@0: sl@0: RFile input; sl@0: RFile output; sl@0: TInt err; sl@0: sl@0: _LIT(KInfo,"Compressing file %S\n"); sl@0: console->Printf(KInfo,&inputFile); sl@0: sl@0: User::LeaveIfError(input.Open(rfs, inputFile,EFileStream | EFileRead | EFileShareAny)); sl@0: CleanupClosePushL(input); sl@0: err = output.Create(rfs, *outputFile,EFileStream | EFileWrite | EFileShareExclusive); sl@0: if (err == KErrAlreadyExists) sl@0: User::LeaveIfError(output.Open(rfs, *outputFile,EFileStream | EFileWrite | EFileShareExclusive)); sl@0: else sl@0: User::LeaveIfError(err); sl@0: CleanupClosePushL(output); sl@0: sl@0: CEZFileBufferManager *fb = CEZFileBufferManager::NewLC(input,output,16384); sl@0: CEZCompressor *def = CEZCompressor::NewLC(*fb); sl@0: sl@0: while (def->DeflateL()){/*do nothing*/} sl@0: sl@0: _LIT(KHoorah,"Hoorah"); sl@0: console->Printf(KHoorah); sl@0: sl@0: CleanupStack::PopAndDestroy(4); sl@0: sl@0: User::LeaveIfError(input.Open(rfs, *outputFile,EFileStream | EFileRead | EFileShareAny)); sl@0: CleanupClosePushL(input); sl@0: err = output.Create(rfs, *uncompressedFile,EFileStream | EFileWrite | EFileShareExclusive); sl@0: if (err == KErrAlreadyExists) sl@0: User::LeaveIfError(output.Open(rfs, *uncompressedFile,EFileStream | EFileWrite | EFileShareExclusive)); sl@0: else sl@0: User::LeaveIfError(err); sl@0: CleanupClosePushL(output); sl@0: fb = CEZFileBufferManager::NewLC(input,output,16384); sl@0: CEZDecompressor *inf = CEZDecompressor::NewLC(*fb); sl@0: sl@0: while (inf->InflateL()){/*do nothing*/} sl@0: sl@0: console->Printf(KHoorah); sl@0: sl@0: CleanupStack::PopAndDestroy(7); sl@0: rfs.Close(); sl@0: }