crypto/weakcryptospi/test/thash/hashtestutils.cpp
changeset 8 35751d3474b7
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     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 	TBuf<24> filePath (sysDrive.Name());
       
    59 	filePath.Append(_L("\\thash\\"));
       
    60 	User::LeaveIfError(fs.SetSessionPath(filePath));
       
    61 	CleanupClosePushL(file);
       
    62 	User::LeaveIfError(file.Open(fs,aFilename,EFileShareAny|EFileRead));
       
    63 	// read into iFile
       
    64 	TInt size=0;
       
    65 	file.Size(size);
       
    66 	iFile=HBufC8::NewMaxL(size);
       
    67 	TPtr8 ptr=iFile->Des();
       
    68 	User::LeaveIfError(file.Read(ptr));
       
    69 	CleanupStack::PopAndDestroy(2, &fs);
       
    70 	iCurrentPlace=0;
       
    71 	iLine=HBufC8::NewMaxL(2000);
       
    72 	}
       
    73 	
       
    74 CTestData::TType CTestData::Type(void)
       
    75 
       
    76 	{
       
    77 	TPtr8 ptr=iLine->Des();
       
    78 	if (iCurrentPlace>=iFile->Length())
       
    79 		{
       
    80 		return EFinished;
       
    81 		}
       
    82 	TInt8 ch=(*iFile)[iCurrentPlace++];
       
    83 	ptr.SetLength(0);
       
    84 	while ((ch!='\r')&&(ch!='\n')&&(iCurrentPlace<=iFile->Length()))
       
    85 		{
       
    86 		ptr.Append(ch);
       
    87 		ch=(*iFile)[iCurrentPlace++];
       
    88 		}
       
    89 	if ((iCurrentPlace==iFile->Length())||(iLine->Length()==0))
       
    90 		{
       
    91 		return EFinished;
       
    92 		}
       
    93 	if (((*iFile)[iCurrentPlace]=='\r')||((*iFile)[iCurrentPlace]=='\n'))
       
    94 		{
       
    95 		iCurrentPlace++;
       
    96 		}
       
    97 	if ((*iLine)[0]=='+')
       
    98 		{
       
    99 		switch ((*iLine)[1])
       
   100 			{
       
   101 		case 'M':				// Message
       
   102 			return EMessage;
       
   103 		case 'F':				// File Name
       
   104 			return EFileName;
       
   105 		case 'C':				// Comment
       
   106 			return Type();
       
   107 		default:
       
   108 			return EError;
       
   109 			}
       
   110 		}
       
   111 	return EData;
       
   112 	}
       
   113 
       
   114 HBufC8* CTestData::operator [] (TInt aIndex)
       
   115 
       
   116 	{
       
   117 	TInt i;
       
   118 	TInt count=0;
       
   119 	HBufC8* ret;
       
   120 	ret=HBufC8::New(4000);
       
   121 	for (i=0;(i<iLine->Length())&&(count<aIndex);i++)
       
   122 		{
       
   123 		if ((*iLine)[i]==' ')
       
   124 			{
       
   125 			count++;
       
   126 			}
       
   127 		}
       
   128 	if(ret != NULL)
       
   129 		{
       
   130 		TPtr8 ptr=ret->Des();
       
   131 		for (;(i<iLine->Length()&&(*iLine)[i]!=' ');i++)
       
   132 			{
       
   133 			ptr.Append((*iLine)[i]);
       
   134 			}
       
   135 		}
       
   136 	return ret;
       
   137 	}
       
   138 
       
   139 HBufC* CTestData::Message(void)
       
   140 
       
   141 	{
       
   142 	HBufC* ret=HBufC::NewMax(iLine->Length()-3);
       
   143 	TPtrC8 ptr=iLine->Right(iLine->Length()-3);
       
   144 	if(ret != NULL)
       
   145 		{
       
   146 		TPtr dest=ret->Des();
       
   147 		dest.Copy(ptr);
       
   148 		}
       
   149 	return ret;
       
   150 	}
       
   151 
       
   152 
       
   153 CTestConsole* CTestConsole::NewL(CConsoleBase* aCon)
       
   154 	{
       
   155 	CTestConsole* self;
       
   156 	self=new (ELeave) CTestConsole;
       
   157 	self->iCon=aCon;
       
   158 	self->iFile=NULL;
       
   159 	return self;
       
   160 	}
       
   161 
       
   162 CTestConsole::CTestConsole(void):CConsoleBase()
       
   163 
       
   164 	{
       
   165 	}
       
   166 
       
   167 CTestConsole::~CTestConsole(void)
       
   168 
       
   169 	{
       
   170 	delete iCon;
       
   171 	if (iFile)
       
   172 		{
       
   173 		iFile->Close();
       
   174 		}
       
   175 	}
       
   176 
       
   177 void CTestConsole::Write(const TDesC16& aString)
       
   178 
       
   179 	{
       
   180 	iCon->Write(aString);
       
   181 	if (iFile)
       
   182 		{
       
   183 		TUint8 space[200];
       
   184 		TPtr8 ptr(space,200);
       
   185 		ptr.Copy(aString);
       
   186 		iFile->Write(ptr);
       
   187 		}
       
   188 	}
       
   189 
       
   190 void CTestConsole::SetLogFile(RFile* aFile)
       
   191 
       
   192 	{
       
   193 	iFile=aFile;
       
   194 	}