os/kernelhwsrv/baseapitest/basesvs/common/src/TestStepV2.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/baseapitest/basesvs/common/src/TestStepV2.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,214 @@
     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 "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 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "TestStepV2.h"
    1.23 +
    1.24 +/*@{*/
    1.25 +///	Constant Literals used.
    1.26 +_LIT(KIncludeSection,		"include");
    1.27 +_LIT(KFile,					"file%d");
    1.28 +_LIT(KMatch,				"*{*,*}*");
    1.29 +_LIT(KStart,				"{");
    1.30 +_LIT(KSeparator,			",");
    1.31 +_LIT(KEnd,					"}");
    1.32 +_LIT(KDataRead,				"INI READ : %S %S %S");
    1.33 +/*@}*/
    1.34 +
    1.35 +CTestStepV2::CTestStepV2()
    1.36 +:	CTestStep()
    1.37 +	{
    1.38 +	}
    1.39 +
    1.40 +CTestStepV2::~CTestStepV2()
    1.41 +	{
    1.42 +	iInclude.ResetAndDestroy();
    1.43 +	iBuffer.ResetAndDestroy();
    1.44 +	}
    1.45 +
    1.46 +enum TVerdict CTestStepV2::doTestStepPreambleL()
    1.47 +	{
    1.48 +	TBuf<KMaxTestExecuteCommandLength>	tempStore;
    1.49 +
    1.50 +	TVerdict	ret=CTestStep::doTestStepPreambleL();
    1.51 +	TPtrC		fileName;
    1.52 +	TBool		moreData=ETrue;
    1.53 +	TBool		index=0;
    1.54 +	while ( moreData )
    1.55 +		{
    1.56 +		tempStore.Format(KFile(), ++index);
    1.57 +		moreData=GetStringFromConfig(KIncludeSection, tempStore, fileName);
    1.58 +		if ( moreData )
    1.59 +			{
    1.60 +			CIniData*	iniData=CIniData::NewL(fileName);
    1.61 +			CleanupStack::PushL(iniData);
    1.62 +			iInclude.Append(iniData);
    1.63 +			CleanupStack::Pop(iniData);
    1.64 +			}
    1.65 +		}
    1.66 +
    1.67 +	return ret;
    1.68 +	}
    1.69 +
    1.70 +TBool CTestStepV2::GetBoolFromConfig(const TDesC& aSectName,const TDesC& aKeyName,TBool& aResult)
    1.71 +	{
    1.72 +	TPtrC	result;
    1.73 +	TBool	ret=EFalse;
    1.74 +	TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
    1.75 +	if ( err != KErrNone )
    1.76 +		{
    1.77 +		ret=EFalse;
    1.78 +		}
    1.79 +	if ( ret )
    1.80 +		{
    1.81 +		_LIT(KTrue,"true");
    1.82 +		aResult=(result.FindF(KTrue) != KErrNotFound);
    1.83 +		}
    1.84 +	return ret;
    1.85 +	}
    1.86 +
    1.87 +TBool CTestStepV2::GetIntFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult)
    1.88 +	{
    1.89 +	TPtrC	result;
    1.90 +	TBool	ret=EFalse;
    1.91 +	TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
    1.92 +	if ( err != KErrNone )
    1.93 +		{
    1.94 +		ret=EFalse;
    1.95 +		}
    1.96 +	if ( ret )
    1.97 +		{
    1.98 +		TLex	lex(result);
    1.99 +		ret=(lex.Val(aResult)==KErrNone);
   1.100 +		}
   1.101 +
   1.102 +	return ret;
   1.103 +	}
   1.104 +
   1.105 +TBool CTestStepV2::GetStringFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult)
   1.106 +	{
   1.107 +	TBool	ret=EFalse;
   1.108 +	TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, aResult));
   1.109 +	if ( err != KErrNone )
   1.110 +		{
   1.111 +		ret=EFalse;
   1.112 +		}
   1.113 +	return ret;
   1.114 +	}
   1.115 +
   1.116 +TBool CTestStepV2::GetHexFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult)
   1.117 +	{
   1.118 +	TPtrC	result;
   1.119 +	TBool	ret=EFalse;
   1.120 +	TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
   1.121 +	if ( err != KErrNone )
   1.122 +		{
   1.123 +		ret=EFalse;
   1.124 +		}
   1.125 +	if ( ret )
   1.126 +		{
   1.127 +		TLex	lex(result);
   1.128 +		ret=(lex.Val((TUint &)aResult, EHex)==KErrNone);
   1.129 +		}
   1.130 +
   1.131 +	return ret;
   1.132 +	}
   1.133 +
   1.134 +TBool CTestStepV2::GetCommandStringParameterL(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult)
   1.135 +	{
   1.136 +	TBool	ret=CTestStep::GetStringFromConfig(aSectName, aKeyName, aResult);
   1.137 +
   1.138 +	for ( TInt index=iInclude.Count(); (index>0) && (!ret);  )
   1.139 +		{
   1.140 +		ret=iInclude[--index]->FindVar(aSectName, aKeyName, aResult);
   1.141 +		}
   1.142 +
   1.143 +	if ( ret )
   1.144 +		{
   1.145 +		if ( aResult.Match(KMatch)!=KErrNotFound )
   1.146 +			{
   1.147 +			//	We have an entry of the format
   1.148 +			//	entry =*{section,entry}*
   1.149 +			//	where * is one or more characters
   1.150 +			//	We need to construct this from other data in the ini file replacing {*,*}
   1.151 +			//	with the data from
   1.152 +			//	[section]
   1.153 +			//	entry =some_value
   1.154 +			HBufC*	buffer=HBufC::NewLC(aResult.Length());
   1.155 +			buffer->Des().Copy(aResult);
   1.156 +
   1.157 +			TInt	startLength=KStart().Length();
   1.158 +			TInt	sparatorLength=KSeparator().Length();
   1.159 +			TInt	endLength=KEnd().Length();
   1.160 +			TInt	bufferLength;
   1.161 +			TInt	start;
   1.162 +			TInt	sparator;
   1.163 +			TInt	end;
   1.164 +			TPtrC	remaining;
   1.165 +			TLex	lex;
   1.166 +			do
   1.167 +				{
   1.168 +				bufferLength=buffer->Length();
   1.169 +				start=buffer->Find(KStart);
   1.170 +
   1.171 +				remaining.Set(buffer->Des().Right(bufferLength-start-startLength));
   1.172 +				sparator=remaining.Find(KSeparator);
   1.173 +				remaining.Set(remaining.Right(remaining.Length()-sparator-sparatorLength));
   1.174 +				sparator += (start + startLength);
   1.175 +
   1.176 +				end=remaining.Find(KEnd) + sparator + sparatorLength;
   1.177 +
   1.178 +				TPtrC	sectionName(buffer->Ptr()+start+startLength, sparator-start-startLength);
   1.179 +				TPtrC	keyName(buffer->Ptr()+sparator+sparatorLength, end-sparator-sparatorLength);
   1.180 +				sectionName.Set(TLex(sectionName).NextToken());
   1.181 +				keyName.Set(TLex(keyName).NextToken());
   1.182 +
   1.183 +				TInt	entrySize=0;
   1.184 +				TPtrC	entryData;
   1.185 +				TBool	found=CTestStep::GetStringFromConfig(sectionName, keyName, entryData);
   1.186 +				for ( TInt index=iInclude.Count(); (index>0) && (!found);  )
   1.187 +					{
   1.188 +					found=iInclude[--index]->FindVar(sectionName, keyName, entryData);
   1.189 +					}
   1.190 +				if ( found )
   1.191 +					{
   1.192 +					entrySize=entryData.Length();
   1.193 +					}
   1.194 +
   1.195 +				TInt	newLength=start + bufferLength - end - endLength + entrySize;
   1.196 +				HBufC*	bufferNew=HBufC::NewLC(newLength);
   1.197 +				bufferNew->Des().Copy(buffer->Ptr(), start);
   1.198 +				if ( entrySize>0 )
   1.199 +					{
   1.200 +					bufferNew->Des().Append(entryData);
   1.201 +					}
   1.202 +				bufferNew->Des().Append(buffer->Ptr() + end + endLength, bufferLength - end - endLength);
   1.203 +				CleanupStack::Pop(bufferNew);
   1.204 +				CleanupStack::PopAndDestroy(buffer);
   1.205 +				buffer=bufferNew;
   1.206 +				CleanupStack::PushL(buffer);
   1.207 +				}
   1.208 +			while ( buffer->Match(KMatch)!=KErrNotFound );
   1.209 +			iBuffer.Append(buffer);
   1.210 +			CleanupStack::Pop(buffer);
   1.211 +			aResult.Set(*buffer);
   1.212 +			INFO_PRINTF4(KDataRead, &aSectName, &aKeyName , &aResult);
   1.213 +			}
   1.214 +		}
   1.215 +
   1.216 +	return ret;
   1.217 +	}