1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcrypto/test/thash/hashtestutils.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,195 @@
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 + TDriveName driveName(sysDrive.Name());
1.62 + TBuf<24> filePath (driveName);
1.63 + filePath.Append(_L("\\thash\\"));
1.64 + User::LeaveIfError(fs.SetSessionPath(filePath));
1.65 + CleanupClosePushL(file);
1.66 + User::LeaveIfError(file.Open(fs,aFilename,EFileShareAny|EFileRead));
1.67 + // read into iFile
1.68 + TInt size=0;
1.69 + file.Size(size);
1.70 + iFile=HBufC8::NewMaxL(size);
1.71 + TPtr8 ptr=iFile->Des();
1.72 + User::LeaveIfError(file.Read(ptr));
1.73 + CleanupStack::PopAndDestroy(2, &fs);
1.74 + iCurrentPlace=0;
1.75 + iLine=HBufC8::NewMaxL(2000);
1.76 + }
1.77 +
1.78 +CTestData::TType CTestData::Type(void)
1.79 +
1.80 + {
1.81 + TPtr8 ptr=iLine->Des();
1.82 + if (iCurrentPlace>=iFile->Length())
1.83 + {
1.84 + return EFinished;
1.85 + }
1.86 + TInt8 ch=(*iFile)[iCurrentPlace++];
1.87 + ptr.SetLength(0);
1.88 + while ((ch!='\r')&&(ch!='\n')&&(iCurrentPlace<=iFile->Length()))
1.89 + {
1.90 + ptr.Append(ch);
1.91 + ch=(*iFile)[iCurrentPlace++];
1.92 + }
1.93 + if ((iCurrentPlace==iFile->Length())||(iLine->Length()==0))
1.94 + {
1.95 + return EFinished;
1.96 + }
1.97 + if (((*iFile)[iCurrentPlace]=='\r')||((*iFile)[iCurrentPlace]=='\n'))
1.98 + {
1.99 + iCurrentPlace++;
1.100 + }
1.101 + if ((*iLine)[0]=='+')
1.102 + {
1.103 + switch ((*iLine)[1])
1.104 + {
1.105 + case 'M': // Message
1.106 + return EMessage;
1.107 + case 'F': // File Name
1.108 + return EFileName;
1.109 + case 'C': // Comment
1.110 + return Type();
1.111 + default:
1.112 + return EError;
1.113 + }
1.114 + }
1.115 + return EData;
1.116 + }
1.117 +
1.118 +HBufC8* CTestData::operator [] (TInt aIndex)
1.119 +
1.120 + {
1.121 + TInt i;
1.122 + TInt count=0;
1.123 + HBufC8* ret;
1.124 + ret=HBufC8::New(4000);
1.125 + for (i=0;(i<iLine->Length())&&(count<aIndex);i++)
1.126 + {
1.127 + if ((*iLine)[i]==' ')
1.128 + {
1.129 + count++;
1.130 + }
1.131 + }
1.132 + if(ret != NULL)
1.133 + {
1.134 + TPtr8 ptr=ret->Des();
1.135 + for (;(i<iLine->Length()&&(*iLine)[i]!=' ');i++)
1.136 + {
1.137 + ptr.Append((*iLine)[i]);
1.138 + }
1.139 + }
1.140 + return ret;
1.141 + }
1.142 +
1.143 +HBufC* CTestData::Message(void)
1.144 +
1.145 + {
1.146 + HBufC* ret=HBufC::NewMax(iLine->Length()-3);
1.147 + TPtrC8 ptr=iLine->Right(iLine->Length()-3);
1.148 + if(ret != NULL)
1.149 + {
1.150 + TPtr dest=ret->Des();
1.151 + dest.Copy(ptr);
1.152 + }
1.153 + return ret;
1.154 + }
1.155 +
1.156 +
1.157 +CTestConsole* CTestConsole::NewL(CConsoleBase* aCon)
1.158 + {
1.159 + CTestConsole* self;
1.160 + self=new (ELeave) CTestConsole;
1.161 + self->iCon=aCon;
1.162 + self->iFile=NULL;
1.163 + return self;
1.164 + }
1.165 +
1.166 +CTestConsole::CTestConsole(void):CConsoleBase()
1.167 +
1.168 + {
1.169 + }
1.170 +
1.171 +CTestConsole::~CTestConsole(void)
1.172 +
1.173 + {
1.174 + delete iCon;
1.175 + if (iFile)
1.176 + {
1.177 + iFile->Close();
1.178 + }
1.179 + }
1.180 +
1.181 +void CTestConsole::Write(const TDesC16& aString)
1.182 +
1.183 + {
1.184 + iCon->Write(aString);
1.185 + if (iFile)
1.186 + {
1.187 + TUint8 space[200];
1.188 + TPtr8 ptr(space,200);
1.189 + ptr.Copy(aString);
1.190 + iFile->Write(ptr);
1.191 + }
1.192 + }
1.193 +
1.194 +void CTestConsole::SetLogFile(RFile* aFile)
1.195 +
1.196 + {
1.197 + iFile=aFile;
1.198 + }