crypto/weakcrypto/test/thash/hashtestutils.cpp
branchRCL_3
changeset 61 641f389e9157
equal deleted inserted replaced
60:f18401adf8e1 61:641f389e9157
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * Mostly obsolete code to manage hash tests
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file
       
    22 */
       
    23 
       
    24 #include "hashtestutils.h"
       
    25 
       
    26 
       
    27 CTestData* CTestData::NewL(const TDesC& aFilename)
       
    28 
       
    29 	{
       
    30 	CTestData* self;
       
    31 	self=new (ELeave) CTestData;
       
    32 	CleanupStack::PushL(self);
       
    33 	self->ConstructL(aFilename);
       
    34 	CleanupStack::Pop();		// self
       
    35 	return self;
       
    36 	}
       
    37 
       
    38 CTestData::CTestData(void):CBase()
       
    39 
       
    40 	{
       
    41 	}
       
    42 
       
    43 CTestData::~CTestData(void)
       
    44 
       
    45 	{
       
    46 	delete iFile;
       
    47 	delete iLine;
       
    48 	}
       
    49 
       
    50 void CTestData::ConstructL(const TDesC& aFilename)
       
    51 
       
    52 	{
       
    53 	RFs fs;
       
    54 	RFile file;
       
    55 	CleanupClosePushL(fs);
       
    56 	User::LeaveIfError(fs.Connect());
       
    57 	TDriveUnit sysDrive(fs.GetSystemDrive());
       
    58 	TDriveName driveName(sysDrive.Name());
       
    59 	TBuf<24> filePath (driveName);
       
    60 	filePath.Append(_L("\\thash\\"));
       
    61 	User::LeaveIfError(fs.SetSessionPath(filePath));
       
    62 	CleanupClosePushL(file);
       
    63 	User::LeaveIfError(file.Open(fs,aFilename,EFileShareAny|EFileRead));
       
    64 	// read into iFile
       
    65 	TInt size=0;
       
    66 	file.Size(size);
       
    67 	iFile=HBufC8::NewMaxL(size);
       
    68 	TPtr8 ptr=iFile->Des();
       
    69 	User::LeaveIfError(file.Read(ptr));
       
    70 	CleanupStack::PopAndDestroy(2, &fs);
       
    71 	iCurrentPlace=0;
       
    72 	iLine=HBufC8::NewMaxL(2000);
       
    73 	}
       
    74 	
       
    75 CTestData::TType CTestData::Type(void)
       
    76 
       
    77 	{
       
    78 	TPtr8 ptr=iLine->Des();
       
    79 	if (iCurrentPlace>=iFile->Length())
       
    80 		{
       
    81 		return EFinished;
       
    82 		}
       
    83 	TInt8 ch=(*iFile)[iCurrentPlace++];
       
    84 	ptr.SetLength(0);
       
    85 	while ((ch!='\r')&&(ch!='\n')&&(iCurrentPlace<=iFile->Length()))
       
    86 		{
       
    87 		ptr.Append(ch);
       
    88 		ch=(*iFile)[iCurrentPlace++];
       
    89 		}
       
    90 	if ((iCurrentPlace==iFile->Length())||(iLine->Length()==0))
       
    91 		{
       
    92 		return EFinished;
       
    93 		}
       
    94 	if (((*iFile)[iCurrentPlace]=='\r')||((*iFile)[iCurrentPlace]=='\n'))
       
    95 		{
       
    96 		iCurrentPlace++;
       
    97 		}
       
    98 	if ((*iLine)[0]=='+')
       
    99 		{
       
   100 		switch ((*iLine)[1])
       
   101 			{
       
   102 		case 'M':				// Message
       
   103 			return EMessage;
       
   104 		case 'F':				// File Name
       
   105 			return EFileName;
       
   106 		case 'C':				// Comment
       
   107 			return Type();
       
   108 		default:
       
   109 			return EError;
       
   110 			}
       
   111 		}
       
   112 	return EData;
       
   113 	}
       
   114 
       
   115 HBufC8* CTestData::operator [] (TInt aIndex)
       
   116 
       
   117 	{
       
   118 	TInt i;
       
   119 	TInt count=0;
       
   120 	HBufC8* ret;
       
   121 	ret=HBufC8::New(4000);
       
   122 	for (i=0;(i<iLine->Length())&&(count<aIndex);i++)
       
   123 		{
       
   124 		if ((*iLine)[i]==' ')
       
   125 			{
       
   126 			count++;
       
   127 			}
       
   128 		}
       
   129 	if(ret != NULL)
       
   130         	{
       
   131 	   	TPtr8 ptr=ret->Des();
       
   132 	   	for (;(i<iLine->Length()&&(*iLine)[i]!=' ');i++)
       
   133 			{
       
   134 			ptr.Append((*iLine)[i]);
       
   135 			}
       
   136 	   	}
       
   137 	return ret;
       
   138 	}
       
   139 
       
   140 HBufC* CTestData::Message(void)
       
   141 
       
   142 	{
       
   143 	HBufC* ret=HBufC::NewMax(iLine->Length()-3);
       
   144 	TPtrC8 ptr=iLine->Right(iLine->Length()-3);
       
   145 	if(ret != NULL)
       
   146 		{
       
   147 		TPtr dest=ret->Des();
       
   148 		dest.Copy(ptr);
       
   149 		}
       
   150 	return ret;
       
   151 	}
       
   152 
       
   153 
       
   154 CTestConsole* CTestConsole::NewL(CConsoleBase* aCon)
       
   155 	{
       
   156 	CTestConsole* self;
       
   157 	self=new (ELeave) CTestConsole;
       
   158 	self->iCon=aCon;
       
   159 	self->iFile=NULL;
       
   160 	return self;
       
   161 	}
       
   162 
       
   163 CTestConsole::CTestConsole(void):CConsoleBase()
       
   164 
       
   165 	{
       
   166 	}
       
   167 
       
   168 CTestConsole::~CTestConsole(void)
       
   169 
       
   170 	{
       
   171 	delete iCon;
       
   172 	if (iFile)
       
   173 		{
       
   174 		iFile->Close();
       
   175 		}
       
   176 	}
       
   177 
       
   178 void CTestConsole::Write(const TDesC16& aString)
       
   179 
       
   180 	{
       
   181 	iCon->Write(aString);
       
   182 	if (iFile)
       
   183 		{
       
   184 		TUint8 space[200];
       
   185 		TPtr8 ptr(space,200);
       
   186 		ptr.Copy(aString);
       
   187 		iFile->Write(ptr);
       
   188 		}
       
   189 	}
       
   190 
       
   191 void CTestConsole::SetLogFile(RFile* aFile)
       
   192 
       
   193 	{
       
   194 	iFile=aFile;
       
   195 	}