os/security/crypto/weakcryptospi/test/thash/hashtestutils.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/crypto/weakcryptospi/test/thash/hashtestutils.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,194 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* Mostly obsolete code to manage hash tests
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +/**
    1.24 + @file
    1.25 +*/
    1.26 +
    1.27 +#include "hashtestutils.h"
    1.28 +
    1.29 +
    1.30 +CTestData* CTestData::NewL(const TDesC& aFilename)
    1.31 +
    1.32 +	{
    1.33 +	CTestData* self;
    1.34 +	self=new (ELeave) CTestData;
    1.35 +	CleanupStack::PushL(self);
    1.36 +	self->ConstructL(aFilename);
    1.37 +	CleanupStack::Pop();		// self
    1.38 +	return self;
    1.39 +	}
    1.40 +
    1.41 +CTestData::CTestData(void):CBase()
    1.42 +
    1.43 +	{
    1.44 +	}
    1.45 +
    1.46 +CTestData::~CTestData(void)
    1.47 +
    1.48 +	{
    1.49 +	delete iFile;
    1.50 +	delete iLine;
    1.51 +	}
    1.52 +
    1.53 +void CTestData::ConstructL(const TDesC& aFilename)
    1.54 +
    1.55 +	{
    1.56 +	RFs fs;
    1.57 +	RFile file;
    1.58 +	CleanupClosePushL(fs);
    1.59 +	User::LeaveIfError(fs.Connect());
    1.60 +	TDriveUnit sysDrive(fs.GetSystemDrive());
    1.61 +	TBuf<24> filePath (sysDrive.Name());
    1.62 +	filePath.Append(_L("\\thash\\"));
    1.63 +	User::LeaveIfError(fs.SetSessionPath(filePath));
    1.64 +	CleanupClosePushL(file);
    1.65 +	User::LeaveIfError(file.Open(fs,aFilename,EFileShareAny|EFileRead));
    1.66 +	// read into iFile
    1.67 +	TInt size=0;
    1.68 +	file.Size(size);
    1.69 +	iFile=HBufC8::NewMaxL(size);
    1.70 +	TPtr8 ptr=iFile->Des();
    1.71 +	User::LeaveIfError(file.Read(ptr));
    1.72 +	CleanupStack::PopAndDestroy(2, &fs);
    1.73 +	iCurrentPlace=0;
    1.74 +	iLine=HBufC8::NewMaxL(2000);
    1.75 +	}
    1.76 +	
    1.77 +CTestData::TType CTestData::Type(void)
    1.78 +
    1.79 +	{
    1.80 +	TPtr8 ptr=iLine->Des();
    1.81 +	if (iCurrentPlace>=iFile->Length())
    1.82 +		{
    1.83 +		return EFinished;
    1.84 +		}
    1.85 +	TInt8 ch=(*iFile)[iCurrentPlace++];
    1.86 +	ptr.SetLength(0);
    1.87 +	while ((ch!='\r')&&(ch!='\n')&&(iCurrentPlace<=iFile->Length()))
    1.88 +		{
    1.89 +		ptr.Append(ch);
    1.90 +		ch=(*iFile)[iCurrentPlace++];
    1.91 +		}
    1.92 +	if ((iCurrentPlace==iFile->Length())||(iLine->Length()==0))
    1.93 +		{
    1.94 +		return EFinished;
    1.95 +		}
    1.96 +	if (((*iFile)[iCurrentPlace]=='\r')||((*iFile)[iCurrentPlace]=='\n'))
    1.97 +		{
    1.98 +		iCurrentPlace++;
    1.99 +		}
   1.100 +	if ((*iLine)[0]=='+')
   1.101 +		{
   1.102 +		switch ((*iLine)[1])
   1.103 +			{
   1.104 +		case 'M':				// Message
   1.105 +			return EMessage;
   1.106 +		case 'F':				// File Name
   1.107 +			return EFileName;
   1.108 +		case 'C':				// Comment
   1.109 +			return Type();
   1.110 +		default:
   1.111 +			return EError;
   1.112 +			}
   1.113 +		}
   1.114 +	return EData;
   1.115 +	}
   1.116 +
   1.117 +HBufC8* CTestData::operator [] (TInt aIndex)
   1.118 +
   1.119 +	{
   1.120 +	TInt i;
   1.121 +	TInt count=0;
   1.122 +	HBufC8* ret;
   1.123 +	ret=HBufC8::New(4000);
   1.124 +	for (i=0;(i<iLine->Length())&&(count<aIndex);i++)
   1.125 +		{
   1.126 +		if ((*iLine)[i]==' ')
   1.127 +			{
   1.128 +			count++;
   1.129 +			}
   1.130 +		}
   1.131 +	if(ret != NULL)
   1.132 +		{
   1.133 +		TPtr8 ptr=ret->Des();
   1.134 +		for (;(i<iLine->Length()&&(*iLine)[i]!=' ');i++)
   1.135 +			{
   1.136 +			ptr.Append((*iLine)[i]);
   1.137 +			}
   1.138 +		}
   1.139 +	return ret;
   1.140 +	}
   1.141 +
   1.142 +HBufC* CTestData::Message(void)
   1.143 +
   1.144 +	{
   1.145 +	HBufC* ret=HBufC::NewMax(iLine->Length()-3);
   1.146 +	TPtrC8 ptr=iLine->Right(iLine->Length()-3);
   1.147 +	if(ret != NULL)
   1.148 +		{
   1.149 +		TPtr dest=ret->Des();
   1.150 +		dest.Copy(ptr);
   1.151 +		}
   1.152 +	return ret;
   1.153 +	}
   1.154 +
   1.155 +
   1.156 +CTestConsole* CTestConsole::NewL(CConsoleBase* aCon)
   1.157 +	{
   1.158 +	CTestConsole* self;
   1.159 +	self=new (ELeave) CTestConsole;
   1.160 +	self->iCon=aCon;
   1.161 +	self->iFile=NULL;
   1.162 +	return self;
   1.163 +	}
   1.164 +
   1.165 +CTestConsole::CTestConsole(void):CConsoleBase()
   1.166 +
   1.167 +	{
   1.168 +	}
   1.169 +
   1.170 +CTestConsole::~CTestConsole(void)
   1.171 +
   1.172 +	{
   1.173 +	delete iCon;
   1.174 +	if (iFile)
   1.175 +		{
   1.176 +		iFile->Close();
   1.177 +		}
   1.178 +	}
   1.179 +
   1.180 +void CTestConsole::Write(const TDesC16& aString)
   1.181 +
   1.182 +	{
   1.183 +	iCon->Write(aString);
   1.184 +	if (iFile)
   1.185 +		{
   1.186 +		TUint8 space[200];
   1.187 +		TPtr8 ptr(space,200);
   1.188 +		ptr.Copy(aString);
   1.189 +		iFile->Write(ptr);
   1.190 +		}
   1.191 +	}
   1.192 +
   1.193 +void CTestConsole::SetLogFile(RFile* aFile)
   1.194 +
   1.195 +	{
   1.196 +	iFile=aFile;
   1.197 +	}