os/ossrv/compressionlibs/ziplib/test/rtest/ezfile/ezfile.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "eustd.h"
sl@0
    17
#include <ezcompressor.h>
sl@0
    18
#include <ezdecompressor.h>
sl@0
    19
#include <ezlib.h>
sl@0
    20
#include <ezfilebuffer.h>
sl@0
    21
sl@0
    22
#include <f32file.h>
sl@0
    23
sl@0
    24
/**
sl@0
    25
@SYMTestCaseID          SYSLIB-EZLIB-CT-0819
sl@0
    26
@SYMTestCaseDesc	    Compression and decompression of a file test
sl@0
    27
@SYMTestPriority 	    High
sl@0
    28
@SYMTestActions  	    Read the input file given as the parameter from the command line.
sl@0
    29
                        Compress and decompress the read file.
sl@0
    30
						Leave on error.
sl@0
    31
@SYMTestExpectedResults Test must not fail
sl@0
    32
@SYMREQ                 REQ0000
sl@0
    33
*/
sl@0
    34
sl@0
    35
LOCAL_C void doExampleL()
sl@0
    36
	{
sl@0
    37
	RFs rfs;
sl@0
    38
	rfs.Connect();
sl@0
    39
sl@0
    40
    TInt cmdLineLen = User::CommandLineLength();
sl@0
    41
    
sl@0
    42
	if (cmdLineLen <= 0)
sl@0
    43
		{
sl@0
    44
		_LIT(KUsage,"Usage:ezfile filename\n");
sl@0
    45
		console->Printf(KUsage);
sl@0
    46
		User::Leave(1);
sl@0
    47
		}
sl@0
    48
    //(cmdLineLen > 0) case
sl@0
    49
	HBufC *argv = HBufC::NewLC(cmdLineLen);
sl@0
    50
	TPtr16 argPtr=argv->Des();
sl@0
    51
    User::CommandLine(argPtr);
sl@0
    52
sl@0
    53
	TLex arguments(*argv);
sl@0
    54
	TPtrC inputFile(arguments.NextToken());
sl@0
    55
sl@0
    56
	HBufC *outputFile = HBufC::NewLC(inputFile.Length()+2);
sl@0
    57
	_LIT(KOfl,"%S.z");
sl@0
    58
	outputFile->Des().Format(KOfl,&inputFile);
sl@0
    59
sl@0
    60
	HBufC *uncompressedFile = HBufC::NewLC(inputFile.Length()+1);
sl@0
    61
	_LIT(KUfl,"%S1");
sl@0
    62
	uncompressedFile->Des().Format(KUfl,&inputFile);
sl@0
    63
sl@0
    64
	RFile input;
sl@0
    65
	RFile output;
sl@0
    66
	TInt err;
sl@0
    67
sl@0
    68
	_LIT(KInfo,"Compressing file %S\n");
sl@0
    69
	console->Printf(KInfo,&inputFile);
sl@0
    70
sl@0
    71
	User::LeaveIfError(input.Open(rfs, inputFile,EFileStream | EFileRead | EFileShareAny));
sl@0
    72
	CleanupClosePushL(input);
sl@0
    73
	err = output.Create(rfs, *outputFile,EFileStream | EFileWrite | EFileShareExclusive);
sl@0
    74
	if (err == KErrAlreadyExists)
sl@0
    75
		User::LeaveIfError(output.Open(rfs, *outputFile,EFileStream | EFileWrite | EFileShareExclusive));
sl@0
    76
	else 
sl@0
    77
		User::LeaveIfError(err);
sl@0
    78
	CleanupClosePushL(output);
sl@0
    79
sl@0
    80
	CEZFileBufferManager *fb = CEZFileBufferManager::NewLC(input,output,16384);
sl@0
    81
	CEZCompressor *def = CEZCompressor::NewLC(*fb);
sl@0
    82
sl@0
    83
	while (def->DeflateL()){/*do nothing*/}
sl@0
    84
sl@0
    85
	_LIT(KHoorah,"Hoorah");
sl@0
    86
	console->Printf(KHoorah);
sl@0
    87
sl@0
    88
	CleanupStack::PopAndDestroy(4);
sl@0
    89
sl@0
    90
	User::LeaveIfError(input.Open(rfs, *outputFile,EFileStream | EFileRead | EFileShareAny));
sl@0
    91
	CleanupClosePushL(input);
sl@0
    92
	err = output.Create(rfs, *uncompressedFile,EFileStream | EFileWrite | EFileShareExclusive);
sl@0
    93
	if (err == KErrAlreadyExists)
sl@0
    94
		User::LeaveIfError(output.Open(rfs, *uncompressedFile,EFileStream | EFileWrite | EFileShareExclusive));
sl@0
    95
	else 
sl@0
    96
		User::LeaveIfError(err);
sl@0
    97
	CleanupClosePushL(output);
sl@0
    98
	fb = CEZFileBufferManager::NewLC(input,output,16384);
sl@0
    99
	CEZDecompressor *inf = CEZDecompressor::NewLC(*fb);
sl@0
   100
sl@0
   101
	while (inf->InflateL()){/*do nothing*/}
sl@0
   102
sl@0
   103
	console->Printf(KHoorah);
sl@0
   104
sl@0
   105
	CleanupStack::PopAndDestroy(7);
sl@0
   106
	rfs.Close();
sl@0
   107
	}