compressionlibs/ziplib/test/rtest/ezfile/ezfile.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "eustd.h"
       
    17 #include <ezcompressor.h>
       
    18 #include <ezdecompressor.h>
       
    19 #include <ezlib.h>
       
    20 #include <ezfilebuffer.h>
       
    21 
       
    22 #include <f32file.h>
       
    23 
       
    24 /**
       
    25 @SYMTestCaseID          SYSLIB-EZLIB-CT-0819
       
    26 @SYMTestCaseDesc	    Compression and decompression of a file test
       
    27 @SYMTestPriority 	    High
       
    28 @SYMTestActions  	    Read the input file given as the parameter from the command line.
       
    29                         Compress and decompress the read file.
       
    30 						Leave on error.
       
    31 @SYMTestExpectedResults Test must not fail
       
    32 @SYMREQ                 REQ0000
       
    33 */
       
    34 
       
    35 LOCAL_C void doExampleL()
       
    36 	{
       
    37 	RFs rfs;
       
    38 	rfs.Connect();
       
    39 
       
    40     TInt cmdLineLen = User::CommandLineLength();
       
    41     
       
    42 	if (cmdLineLen <= 0)
       
    43 		{
       
    44 		_LIT(KUsage,"Usage:ezfile filename\n");
       
    45 		console->Printf(KUsage);
       
    46 		User::Leave(1);
       
    47 		}
       
    48     //(cmdLineLen > 0) case
       
    49 	HBufC *argv = HBufC::NewLC(cmdLineLen);
       
    50 	TPtr16 argPtr=argv->Des();
       
    51     User::CommandLine(argPtr);
       
    52 
       
    53 	TLex arguments(*argv);
       
    54 	TPtrC inputFile(arguments.NextToken());
       
    55 
       
    56 	HBufC *outputFile = HBufC::NewLC(inputFile.Length()+2);
       
    57 	_LIT(KOfl,"%S.z");
       
    58 	outputFile->Des().Format(KOfl,&inputFile);
       
    59 
       
    60 	HBufC *uncompressedFile = HBufC::NewLC(inputFile.Length()+1);
       
    61 	_LIT(KUfl,"%S1");
       
    62 	uncompressedFile->Des().Format(KUfl,&inputFile);
       
    63 
       
    64 	RFile input;
       
    65 	RFile output;
       
    66 	TInt err;
       
    67 
       
    68 	_LIT(KInfo,"Compressing file %S\n");
       
    69 	console->Printf(KInfo,&inputFile);
       
    70 
       
    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));
       
    76 	else 
       
    77 		User::LeaveIfError(err);
       
    78 	CleanupClosePushL(output);
       
    79 
       
    80 	CEZFileBufferManager *fb = CEZFileBufferManager::NewLC(input,output,16384);
       
    81 	CEZCompressor *def = CEZCompressor::NewLC(*fb);
       
    82 
       
    83 	while (def->DeflateL()){/*do nothing*/}
       
    84 
       
    85 	_LIT(KHoorah,"Hoorah");
       
    86 	console->Printf(KHoorah);
       
    87 
       
    88 	CleanupStack::PopAndDestroy(4);
       
    89 
       
    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));
       
    95 	else 
       
    96 		User::LeaveIfError(err);
       
    97 	CleanupClosePushL(output);
       
    98 	fb = CEZFileBufferManager::NewLC(input,output,16384);
       
    99 	CEZDecompressor *inf = CEZDecompressor::NewLC(*fb);
       
   100 
       
   101 	while (inf->InflateL()){/*do nothing*/}
       
   102 
       
   103 	console->Printf(KHoorah);
       
   104 
       
   105 	CleanupStack::PopAndDestroy(7);
       
   106 	rfs.Close();
       
   107 	}