os/boardsupport/haitest/bspsvs/suite/common/src/DataWrapperBase.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/boardsupport/haitest/bspsvs/suite/common/src/DataWrapperBase.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,834 @@
     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 +#include "DataWrapperBase.h"
    1.22 +
    1.23 +#define SECS_TO_MICROSEC(x)  (x*1000000)
    1.24 +
    1.25 +/*@{*/
    1.26 +///	Constant Literals used.
    1.27 +_LIT(KPrefixHex,				"0x");
    1.28 +_LIT(KPrefixOctal,				"0");
    1.29 +_LIT(KSuffixBinary,				"b");
    1.30 +
    1.31 +_LIT(KIncludeSection,			"include");
    1.32 +_LIT(KFile,						"file%d");
    1.33 +_LIT(KMatch,					"*{*,*}*");
    1.34 +_LIT(KStart,					"{");
    1.35 +_LIT(KSeparator,				",");
    1.36 +_LIT(KEnd,						"}");
    1.37 +_LIT(KDataRead,					"INI READ : %S %S %S");
    1.38 +_LIT(KTagPointX,				"%S_x");
    1.39 +_LIT(KTagPointY,				"%S_y");
    1.40 +_LIT(KTagRectMinX,				"%S_minX");
    1.41 +_LIT(KTagRectMaxX,				"%S_maxX");
    1.42 +_LIT(KTagRectMinY,				"%S_minY");
    1.43 +_LIT(KTagRectMaxY,				"%S_maxY");
    1.44 +_LIT(KTagSizeHeight,			"%S_height");
    1.45 +_LIT(KTagSizeWidth,				"%S_width");
    1.46 +_LIT(KEnumElements,				"enum_elements");
    1.47 +_LIT(KPrefixHexKey,				"0x%S");
    1.48 +
    1.49 +_LIT(KCmdUtilityPromptMessage,	"utilityPromptMessage");
    1.50 +_LIT(KPromptText,				"message");
    1.51 +_LIT(KDelay,					"delay");
    1.52 +_LIT(KExpectedKey,				"keyCode");
    1.53 +/*@}*/
    1.54 +
    1.55 +const TInt	KDefaultDelay	=	10;
    1.56 +const TInt	KBounceErrKey	=	50000;
    1.57 +
    1.58 +CDataWrapperBase::CDataWrapperBase()
    1.59 +:	CDataWrapper()
    1.60 +	{
    1.61 +	}
    1.62 +
    1.63 +CDataWrapperBase::~CDataWrapperBase()
    1.64 +/**
    1.65 + * Public destructor
    1.66 + */
    1.67 +	{
    1.68 +	iInclude.ResetAndDestroy();
    1.69 +	iBuffer.ResetAndDestroy();
    1.70 +	iFs.Close();
    1.71 +	}
    1.72 +
    1.73 +void CDataWrapperBase::InitialiseL()
    1.74 +	{
    1.75 +	iTimer.CreateLocal();
    1.76 +	CDataWrapper::InitialiseL();
    1.77 +	TBuf<KMaxTestExecuteCommandLength>	tempStore;
    1.78 +	TPtrC		fileName;
    1.79 +	TBool		moreData=ETrue;
    1.80 +	TBool		index=0;
    1.81 +	while ( moreData )
    1.82 +		{
    1.83 +		tempStore.Format(KFile(), ++index);
    1.84 +		moreData=GetStringFromConfig(KIncludeSection, tempStore, fileName);
    1.85 +
    1.86 +		if (moreData)
    1.87 +			{
    1.88 +			CIniData*	iniData=CIniData::NewL(fileName);
    1.89 +			CleanupStack::PushL(iniData);
    1.90 +			iInclude.Append(iniData);
    1.91 +			CleanupStack::Pop(iniData);
    1.92 +			}
    1.93 +		}
    1.94 +	User::LeaveIfError(iFs.Connect());
    1.95 +	}
    1.96 +
    1.97 +TBool CDataWrapperBase::GetBoolFromConfig(const TDesC& aSectName,const TDesC& aKeyName,TBool& aResult)
    1.98 +/**
    1.99 + * Reads the value present from the test steps ini file within the mentioned section name and key name
   1.100 + * Copies the value to the TBool reference passed in possible values TRUE, FALSE
   1.101 + * @param aSectName - Section within the test steps ini file
   1.102 + * @param aKeyName - Name of a key within a section
   1.103 + * @return aResult - The value of the boolean
   1.104 + * @return TBool - ETrue for found, EFalse for not found
   1.105 + */
   1.106 +	{
   1.107 +	TBool	ret=EFalse;
   1.108 +	TPtrC	result;
   1.109 +	TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
   1.110 +	if ( err != KErrNone )
   1.111 +		{
   1.112 +		ret=EFalse;
   1.113 +		}
   1.114 +	if ( ret )
   1.115 +		{
   1.116 +		_LIT(KTrue,"true");
   1.117 +		aResult=(result.FindF(KTrue) != KErrNotFound);
   1.118 +		}
   1.119 +
   1.120 +	return ret;
   1.121 +	}
   1.122 +
   1.123 +TBool CDataWrapperBase::GetIntFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult)
   1.124 +/**
   1.125 + * Reads the value present from the test steps ini file within the mentioned section name and key name
   1.126 + * Copies the value to the TInt reference passed in
   1.127 + * @param aSectName - Section within the test steps ini file
   1.128 + * @param aKeyName - Name of a key within a section
   1.129 + * @return aResult - The value of the integer
   1.130 + * @return TBool - ETrue for found, EFalse for not found
   1.131 + */
   1.132 +	{
   1.133 +	TPtrC	result;
   1.134 +	TBool	ret=EFalse;
   1.135 +	TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
   1.136 +	if ( err != KErrNone )
   1.137 +		{
   1.138 +		ret=EFalse;
   1.139 +		}
   1.140 +	if ( ret )
   1.141 +		{
   1.142 +		TLex	lex(result);
   1.143 +		ret=(lex.Val(aResult)==KErrNone);
   1.144 +		}
   1.145 +
   1.146 +	return ret;
   1.147 +	}
   1.148 +
   1.149 +TBool CDataWrapperBase::GetStringFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult)
   1.150 +/**
   1.151 + * Reads the value present from the test steps ini file within the mentioned section name and key name
   1.152 + * Copies the value to the TPtrC reference passed in
   1.153 + * @param aSectName - Section within the test steps ini file
   1.154 + * @param aKeyName - Name of a key within a section
   1.155 + * @return aResult - Reference to the string on the heap
   1.156 + * @return TBool - ETrue for found, EFalse for not found
   1.157 + */
   1.158 +	{
   1.159 +	TBool	ret=EFalse;
   1.160 +	TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, aResult));
   1.161 +	if ( err != KErrNone )
   1.162 +		{
   1.163 +		ret=EFalse;
   1.164 +		}
   1.165 +	return ret;
   1.166 +	}
   1.167 +
   1.168 +TBool CDataWrapperBase::GetHexFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult)
   1.169 +/**
   1.170 + * Reads the value present from the test steps ini file within the mentioned section name and key name
   1.171 + * Copies the value to the TInt reference passed in. The value can optionally be prefixed with 0x
   1.172 + * @param aSectName - Section within the test steps ini file
   1.173 + * @param aKeyName - Name of a key within a section
   1.174 + * @return aResult - The integer value of the Hex input
   1.175 + * @return TBool - ETrue for found, EFalse for not found
   1.176 + */
   1.177 +	{
   1.178 +	TPtrC	result;
   1.179 +	TBool	ret=EFalse;
   1.180 +	TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
   1.181 +	if ( err != KErrNone )
   1.182 +		{
   1.183 +		ret=EFalse;
   1.184 +		}
   1.185 +	if ( ret )
   1.186 +		{
   1.187 +		TLex	lex;
   1.188 +		if( result.FindC(KPrefixHex)==KErrNone )
   1.189 +			{
   1.190 +			lex=result.Mid(KPrefixHex().Length());
   1.191 +			}
   1.192 +		else
   1.193 +			{
   1.194 +			lex=result;
   1.195 +			}
   1.196 +		ret=(lex.Val((TUint &)aResult, EHex)==KErrNone);
   1.197 +		}
   1.198 +
   1.199 +	return ret;
   1.200 +	}
   1.201 +
   1.202 +TBool CDataWrapperBase::GetUintFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TUint& aResult)
   1.203 +/**
   1.204 + * Reads the value present from the test steps ini file within the mentioned section name and key name
   1.205 + * Copies the value to the TUint reference passed in.
   1.206 + * If the value is prefixed with 0x the value is read as a hexidecimal value
   1.207 + * If the value is suffixed with b the value is read as a binary value
   1.208 + * If the value is prefixed with a 0 the value is read as an octal value
   1.209 + * If it does not match the above it is read in as an integer
   1.210 + * @param aSectName - Section within the test steps ini file
   1.211 + * @param aKeyName - Name of a key within a section
   1.212 + * @return aResult - The integer value of the Hex input
   1.213 + * @return TBool - ETrue for found, EFalse for not found
   1.214 + */
   1.215 +	{
   1.216 +	TPtrC	result;
   1.217 +	TBool	ret=EFalse;
   1.218 +	TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
   1.219 +	if ( err != KErrNone )
   1.220 +		{
   1.221 +		ret=EFalse;
   1.222 +		}
   1.223 +	if ( ret )
   1.224 +		{
   1.225 +		TLex	lex(result);
   1.226 +		if( result.FindC(KPrefixHex)==KErrNone )
   1.227 +			{
   1.228 +			lex=result.Mid(KPrefixHex().Length());
   1.229 +			ret=(lex.Val(aResult, EHex)==KErrNone);
   1.230 +			}
   1.231 +		else
   1.232 +			{
   1.233 +			TInt	binarySuffixPosition=result.Length()-KSuffixBinary().Length();
   1.234 +			if ( result.FindC(KSuffixBinary)==binarySuffixPosition )
   1.235 +				{
   1.236 +				lex=result.Left(binarySuffixPosition);
   1.237 +				ret=(lex.Val(aResult, EBinary)==KErrNone);
   1.238 +				}
   1.239 +			else
   1.240 +				{
   1.241 +				if( result.FindC(KPrefixOctal)==KErrNone )
   1.242 +					{
   1.243 +					ret=(lex.Val(aResult, EOctal)==KErrNone);
   1.244 +					}
   1.245 +				else
   1.246 +					{
   1.247 +					TInt	intResult;
   1.248 +					ret=(lex.Val(intResult)==KErrNone);
   1.249 +					if ( ret )
   1.250 +						{
   1.251 +						aResult=(TUint)intResult;
   1.252 +						}
   1.253 +					}
   1.254 +				}
   1.255 +			}
   1.256 +		}
   1.257 +
   1.258 +	return ret;
   1.259 +	}
   1.260 +
   1.261 +TBool CDataWrapperBase::GetEnumFromConfig(const TDesC& aSectName, const TDesC& aKeyName, const TEnumEntryTable* aTable, TInt& aResult)
   1.262 +	{
   1.263 +	TPtrC	str;
   1.264 +	TBool	ret=GetStringFromConfig(aSectName, aKeyName, str);
   1.265 +
   1.266 +	if ( ret )
   1.267 +		{
   1.268 +		TBool	found=EFalse;
   1.269 +		TInt	index=0;
   1.270 +		while ( (aTable[index].iValue!=-1) && !found )
   1.271 +			{
   1.272 +			if ( aTable[index].iString==str )
   1.273 +				{
   1.274 +				found=ETrue;
   1.275 +				aResult=aTable[index].iValue;
   1.276 +				}
   1.277 +			else
   1.278 +				{
   1.279 +				++index;
   1.280 +				}
   1.281 +			}
   1.282 +
   1.283 +		if ( !found )
   1.284 +			{
   1.285 +			ret=GetIntFromConfig(aSectName, aKeyName, aResult);
   1.286 +			}
   1.287 +		}
   1.288 +
   1.289 +	return ret;
   1.290 +	}
   1.291 +
   1.292 +TBool CDataWrapperBase::GetOrFromConfig(const TDesC& aSectName, const TDesC& aKeyName, const TEnumEntryTable* aTable, TUint& aResult)
   1.293 +	{
   1.294 +	TPtrC 	str;
   1.295 +	TBool	ret=GetStringFromConfig(aSectName, aKeyName, str);
   1.296 +	if ( ret )
   1.297 +		{
   1.298 +		TUint	temp=0;
   1.299 +		ret=ProcessString(str, temp, aTable);
   1.300 +		if ( ret )
   1.301 +			{
   1.302 +			aResult=temp;
   1.303 +			}
   1.304 +		}
   1.305 +
   1.306 +	return ret;
   1.307 +	}
   1.308 +
   1.309 +TBool CDataWrapperBase::ProcessString(const TDesC& aStr, TUint& aResult, const TEnumEntryTable* aTable)
   1.310 +	{
   1.311 +	TBool	ret=ETrue;
   1.312 +	TInt	location=aStr.Match(_L("*|*"));
   1.313 +	if( location!=KErrNotFound )
   1.314 +		{
   1.315 +		// Converting Left part of the data
   1.316 +		TPtrC	tempStr=aStr.Left(location);
   1.317 +		ret=ProcessString(tempStr, aResult, aTable);
   1.318 +
   1.319 +		// Converting right data can be with another "|"
   1.320 +		tempStr.Set(aStr.Mid(location+1));
   1.321 +
   1.322 +		TUint	temp;
   1.323 +		if ( ProcessString(tempStr, temp, aTable) )
   1.324 +			{
   1.325 +			aResult|=temp;
   1.326 +			}
   1.327 +		else
   1.328 +			{
   1.329 +			ret=EFalse;
   1.330 +			}
   1.331 +		}
   1.332 +	else
   1.333 +		{
   1.334 +		ret=ProcessEntry(aStr, aResult, aTable);
   1.335 +		}
   1.336 +
   1.337 +	return ret;
   1.338 +	}
   1.339 +
   1.340 +TBool CDataWrapperBase::ProcessEntry(const TDesC& aStr, TUint& aResult, const TEnumEntryTable* aTable)
   1.341 +	{
   1.342 +	TBool	ret=ETrue;
   1.343 +
   1.344 +	TBool	found=EFalse;
   1.345 +	TInt	index=0;
   1.346 +	while ( (aTable[index].iValue!=-1) && !found )
   1.347 +		{
   1.348 +		if ( aTable[index].iString==aStr )
   1.349 +			{
   1.350 +			found=ETrue;
   1.351 +			aResult=aTable[index].iValue;
   1.352 +			}
   1.353 +		else
   1.354 +			{
   1.355 +			++index;
   1.356 +			}
   1.357 +		}
   1.358 +
   1.359 +	if ( !found )
   1.360 +		{
   1.361 +		TUint	flags;
   1.362 +		TLex	lex(aStr);
   1.363 +		ret=(lex.Val(flags, EHex)==KErrNone);
   1.364 +		if ( ret )
   1.365 +			{
   1.366 +			aResult=flags;
   1.367 +			}
   1.368 +		}
   1.369 +
   1.370 +	return ret;
   1.371 +	}
   1.372 +
   1.373 +TBool CDataWrapperBase::GetCommandStringParameterL(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult)
   1.374 +	{
   1.375 +	TBool	ret=EFalse;
   1.376 +
   1.377 +	if ( aSectName.Length()!=0 )
   1.378 +		{
   1.379 +		ret=CDataWrapper::GetStringFromConfig(aSectName, aKeyName, aResult);
   1.380 +
   1.381 +		for ( TInt index=iInclude.Count(); (index>0) && (!ret); )
   1.382 +			{
   1.383 +			ret=iInclude[--index]->FindVar(aSectName, aKeyName, aResult);
   1.384 +			if ( ret )
   1.385 +				{
   1.386 +				INFO_PRINTF4(KDataRead, &aSectName, &aKeyName, &aResult);
   1.387 +				}
   1.388 +			}
   1.389 +		}
   1.390 +
   1.391 +	if ( ret )
   1.392 +		{
   1.393 +		if ( aResult.Match(KMatch)!=KErrNotFound )
   1.394 +			{
   1.395 +			//	We have an entry of the format
   1.396 +			//	entry =*{section,entry}*
   1.397 +			//	where * is one or more characters
   1.398 +			//	We need to construct this from other data in the ini file replacing {*,*}
   1.399 +			//	with the data from
   1.400 +			//	[section]
   1.401 +			//	entry =some_value
   1.402 +			HBufC*	buffer=HBufC::NewLC(aResult.Length());
   1.403 +			buffer->Des().Copy(aResult);
   1.404 +
   1.405 +			TInt	startLength=KStart().Length();
   1.406 +			TInt	sparatorLength=KSeparator().Length();
   1.407 +			TInt	endLength=KEnd().Length();
   1.408 +			TInt	bufferLength;
   1.409 +			TInt	start;
   1.410 +			TInt	sparator;
   1.411 +			TInt	end;
   1.412 +			TPtrC	remaining;
   1.413 +			TLex	lex;
   1.414 +			do
   1.415 +				{
   1.416 +				bufferLength=buffer->Length();
   1.417 +				start=buffer->Find(KStart);
   1.418 +
   1.419 +				remaining.Set(buffer->Des().Right(bufferLength-start-startLength));
   1.420 +				sparator=remaining.Find(KSeparator);
   1.421 +				remaining.Set(remaining.Right(remaining.Length()-sparator-sparatorLength));
   1.422 +				sparator += (start + startLength);
   1.423 +
   1.424 +				end=remaining.Find(KEnd) + sparator + sparatorLength;
   1.425 +
   1.426 +				TPtrC	sectionName(buffer->Ptr()+start+startLength, sparator-start-startLength);
   1.427 +				TPtrC	keyName(buffer->Ptr()+sparator+sparatorLength, end-sparator-sparatorLength);
   1.428 +				sectionName.Set(TLex(sectionName).NextToken());
   1.429 +				keyName.Set(TLex(keyName).NextToken());
   1.430 +
   1.431 +				TInt	entrySize=0;
   1.432 +				TPtrC	entryData;
   1.433 +				TBool	found=CDataWrapper::GetStringFromConfig(sectionName, keyName, entryData);
   1.434 +				for ( TInt index=iInclude.Count(); (index>0) && (!found);  )
   1.435 +					{
   1.436 +					found=iInclude[--index]->FindVar(sectionName, keyName, entryData);
   1.437 +					}
   1.438 +				if ( found )
   1.439 +					{
   1.440 +					entrySize=entryData.Length();
   1.441 +					}
   1.442 +
   1.443 +				TInt	newLength=start + bufferLength - end - endLength + entrySize;
   1.444 +				HBufC*	bufferNew=HBufC::NewLC(newLength);
   1.445 +				bufferNew->Des().Copy(buffer->Ptr(), start);
   1.446 +				if ( entrySize>0 )
   1.447 +					{
   1.448 +					bufferNew->Des().Append(entryData);
   1.449 +					}
   1.450 +				bufferNew->Des().Append(buffer->Ptr() + end + endLength, bufferLength - end - endLength);
   1.451 +				CleanupStack::Pop(bufferNew);
   1.452 +				CleanupStack::PopAndDestroy(buffer);
   1.453 +				buffer=bufferNew;
   1.454 +				CleanupStack::PushL(buffer);
   1.455 +				}
   1.456 +			while ( buffer->Match(KMatch)!=KErrNotFound );
   1.457 +			iBuffer.Append(buffer);
   1.458 +			CleanupStack::Pop(buffer);
   1.459 +			aResult.Set(*buffer);
   1.460 +			INFO_PRINTF4(KDataRead, &aSectName, &aKeyName, &aResult);
   1.461 +			}
   1.462 +		}
   1.463 +
   1.464 +	return ret;
   1.465 +	}
   1.466 +
   1.467 +TBool CDataWrapperBase::GetCommandStringParameter(const TDesC& aParameterName, const TDesC& aSection, TPtrC& aResult, TText8 *aFileName, TInt aLine, TBool aMandatory)
   1.468 +	{
   1.469 +	TBool	ret = GetStringFromConfig(aSection, aParameterName, aResult);
   1.470 +	if (aMandatory && !ret)
   1.471 +		{
   1.472 +		Logger().LogExtra(aFileName, aLine, ESevrErr, _L("No %S"), &aParameterName);
   1.473 +		SetBlockResult(EFail);
   1.474 +		}
   1.475 +	return ret;
   1.476 +	}
   1.477 +
   1.478 +TBool CDataWrapperBase::GetCommandIntParameter(const TDesC& aParameterName, const TDesC& aSection, TInt& aResult, TText8* aFileName, TInt aLine, TBool aMandatory)
   1.479 +	{
   1.480 +	TBool	ret = GetIntFromConfig(aSection, aParameterName, aResult);
   1.481 +	if (aMandatory && !ret)
   1.482 +		{
   1.483 +		Logger().LogExtra(aFileName, aLine, ESevrErr, _L("No %S"), &aParameterName);
   1.484 +		SetBlockResult(EFail);
   1.485 +		}
   1.486 +	return ret;
   1.487 +	}
   1.488 +
   1.489 +TBool CDataWrapperBase::GetCommandBoolParameter(const TDesC& aParameterName, const TDesC& aSection, TBool& aResult, TText8 *aFileName, TInt aLine, TBool aMandatory)
   1.490 +	{
   1.491 +	TBool	ret = GetBoolFromConfig(aSection, aParameterName, aResult);
   1.492 +	if (aMandatory && !ret)
   1.493 +		{
   1.494 +		Logger().LogExtra(aFileName, aLine, ESevrErr, _L("No %S"), &aParameterName);
   1.495 +		SetBlockResult(EFail);
   1.496 +		}
   1.497 +	return ret;
   1.498 +	}
   1.499 +
   1.500 +TBool CDataWrapperBase::GetPointFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TPoint& aResult)
   1.501 +/**
   1.502 + * Reads the value present from the test steps ini file within the mentioned section name and key name
   1.503 + * Copies the value to the TPoint reference passed in
   1.504 + * @param aSectName - Section within the test steps ini file
   1.505 + * @param aKeyName - Name of a key within a section
   1.506 + * @return aResult - The value of the TPoint
   1.507 + * @return TBool - ETrue for found, EFalse for not found
   1.508 + */
   1.509 +	{
   1.510 +	TBuf<KMaxTestExecuteCommandLength>	tempStore;
   1.511 +
   1.512 +	TInt	x;
   1.513 +	tempStore.Format(KTagPointX, &aKeyName);
   1.514 +	TBool	ret=GetIntFromConfig(aSectName, tempStore, x);
   1.515 +	TInt	y;
   1.516 +	tempStore.Format(KTagPointY, &aKeyName);
   1.517 +	if ( !GetIntFromConfig(aSectName, tempStore, y) )
   1.518 +		{
   1.519 +		ret=EFalse;
   1.520 +		}
   1.521 +	if ( ret )
   1.522 +		{
   1.523 +		aResult.SetXY(x, y);
   1.524 +		}
   1.525 +
   1.526 +	return ret;
   1.527 +	}
   1.528 +
   1.529 +TBool CDataWrapperBase::GetRectFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TRect& aResult)
   1.530 +/**
   1.531 + * Reads the value present from the test steps ini file within the mentioned section name and key name
   1.532 + * Copies the value to the TPoint reference passed in
   1.533 + * @param aSectName - Section within the test steps ini file
   1.534 + * @param aKeyName - Name of a key within a section
   1.535 + * @return aResult - The value of the TRect
   1.536 + * @return TBool - ETrue for found, EFalse for not found
   1.537 + */
   1.538 +	{
   1.539 +	TBuf<KMaxTestExecuteCommandLength>	tempStore;
   1.540 +
   1.541 +	TInt	minX;
   1.542 +	tempStore.Format(KTagRectMinX, &aKeyName);
   1.543 +	TBool	ret=GetIntFromConfig(aSectName, tempStore, minX);
   1.544 +
   1.545 +	TInt	maxX;
   1.546 +	tempStore.Format(KTagRectMaxX, &aKeyName);
   1.547 +	if ( !GetIntFromConfig(aSectName, tempStore, maxX) )
   1.548 +		{
   1.549 +		ret=EFalse;
   1.550 +		}
   1.551 +
   1.552 +	TInt	minY;
   1.553 +	tempStore.Format(KTagRectMinY, &aKeyName);
   1.554 +	if ( !GetIntFromConfig(aSectName, tempStore, minY) )
   1.555 +		{
   1.556 +		ret=EFalse;
   1.557 +		}
   1.558 +
   1.559 +	TInt	maxY;
   1.560 +	tempStore.Format(KTagRectMaxY, &aKeyName);
   1.561 +	if ( !GetIntFromConfig(aSectName, tempStore, maxY) )
   1.562 +		{
   1.563 +		ret=EFalse;
   1.564 +		}
   1.565 +
   1.566 +	if ( ret )
   1.567 +		{
   1.568 +		aResult.SetRect(minX, minY, maxX, maxY);
   1.569 +		}
   1.570 +
   1.571 +	return ret;
   1.572 +	}
   1.573 +
   1.574 +TBool CDataWrapperBase::GetSizeFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TSize& aResult)
   1.575 +/**
   1.576 + * Reads the value present from the test steps ini file within the mentioned section name and key name
   1.577 + * Copies the value to the TPoint reference passed in
   1.578 + * @param aSectName - Section within the test steps ini file
   1.579 + * @param aKeyName - Name of a key within a section
   1.580 + * @return aResult - The value of the TPoint
   1.581 + * @return TBool - ETrue for found, EFalse for not found
   1.582 + */
   1.583 +	{
   1.584 +	TBuf<KMaxTestExecuteCommandLength>	tempStore;
   1.585 +
   1.586 +	TInt	height;
   1.587 +	tempStore.Format(KTagSizeHeight, &aKeyName);
   1.588 +	TBool	ret=GetIntFromConfig(aSectName, tempStore, height);
   1.589 +	TInt	width;
   1.590 +	tempStore.Format(KTagSizeWidth, &aKeyName);
   1.591 +	if ( !GetIntFromConfig(aSectName, tempStore, width) )
   1.592 +		{
   1.593 +		ret=EFalse;
   1.594 +		}
   1.595 +	if ( ret )
   1.596 +		{
   1.597 +		aResult.SetSize(width, height);
   1.598 +		}
   1.599 +
   1.600 +	return ret;
   1.601 +	}
   1.602 +
   1.603 +TBool CDataWrapperBase::GetUint8FromConfig(const TDesC& aSectName, const TDesC& aKeyName, TUint8& aResult)
   1.604 +	{
   1.605 +	TUint	temp;
   1.606 +	TBool	ret=GetUintFromConfig(aSectName, aKeyName,temp);
   1.607 +	if ( ret )
   1.608 +		{
   1.609 +		aResult=(TUint8)temp;
   1.610 +		}
   1.611 +
   1.612 +	return ret;
   1.613 +	}
   1.614 +
   1.615 +void CDataWrapperBase::Timedelay(TInt aTimeoutInSecs)
   1.616 +/*Utility function to produce time delay
   1.617 +@param aTimeoutInSecs Times in micro seconds
   1.618 +*/
   1.619 +	{
   1.620 +	TRequestStatus	status;
   1.621 +	iTimer.After(status, aTimeoutInSecs);
   1.622 +	User::WaitForRequest(status);
   1.623 +	}
   1.624 +
   1.625 +TBool CDataWrapperBase::TranslateEnumToString(CDataWrapper& aDataWrapper,
   1.626 +										const TDesC& aEnum,
   1.627 +										const TInt aValue,
   1.628 +										TDesC& aTranslation)
   1.629 +/* Function translates
   1.630 +*/
   1.631 +	{
   1.632 +	TBool ret = ETrue;
   1.633 +
   1.634 +	RBuf desToWrapInt;
   1.635 +	RBuf desToFormHex;
   1.636 +	TInt intError = desToWrapInt.Create(KMaxFullName);
   1.637 +	TInt hexError = desToFormHex.Create(KMaxFullName);
   1.638 +	if(intError == KErrNone && hexError == KErrNone)
   1.639 +		{
   1.640 +		desToFormHex.NumFixedWidth(aValue, EHex, 8);
   1.641 +		desToWrapInt.Format(KPrefixHexKey, &desToFormHex);
   1.642 +		if (!aDataWrapper.GetStringFromConfig(aEnum, desToWrapInt, static_cast<TPtrC&>(aTranslation)))
   1.643 +			{
   1.644 +			ret = EFalse;
   1.645 +			}
   1.646 +		}
   1.647 +	else
   1.648 +		{
   1.649 +		ret = EFalse;
   1.650 +		}
   1.651 +
   1.652 +	if(hexError == KErrNone)
   1.653 +		{
   1.654 +		desToFormHex.Close();
   1.655 +		}
   1.656 +	if(intError == KErrNone)
   1.657 +		{
   1.658 +		desToWrapInt.Close();
   1.659 +		}
   1.660 +
   1.661 +	return ret;
   1.662 +	}
   1.663 +
   1.664 +TBool CDataWrapperBase::ProcessEnumList(CDataWrapper& aDataWrapper,
   1.665 +									const TDesC& aStr,
   1.666 +									const TDesC& aEnum,
   1.667 +									const TUint& aValue,
   1.668 +									TDes& aTranslation)
   1.669 +	{
   1.670 +	TBool	ret=ETrue;
   1.671 +	TInt	location=aStr.Match(_L("*|*"));
   1.672 +	if( location!=KErrNotFound )
   1.673 +		{
   1.674 +		// Converting Left part of the data
   1.675 +		TPtrC	tempStr=aStr.Left(location);
   1.676 +		ret=ProcessEnumList(aDataWrapper, tempStr, aEnum, aValue, aTranslation);
   1.677 +
   1.678 +		// Converting right data can be with another "|"
   1.679 +		tempStr.Set(aStr.Mid(location+1));
   1.680 +
   1.681 +		if ( !ProcessEnumList(aDataWrapper, tempStr, aEnum, aValue, aTranslation) )
   1.682 +			{
   1.683 +			ret=EFalse;
   1.684 +			}
   1.685 +		}
   1.686 +	else
   1.687 +		{
   1.688 +		TInt value;
   1.689 +		if (aDataWrapper.GetHexFromConfig(aEnum, aStr, value ))
   1.690 +			{
   1.691 +			if (value & aValue)
   1.692 +				{
   1.693 +				if ( aTranslation.Length() )
   1.694 +					{
   1.695 +					aTranslation.Append(_L("|"));
   1.696 +					}
   1.697 +
   1.698 +				aTranslation.Append(aStr);
   1.699 +				}
   1.700 +			}
   1.701 +		else
   1.702 +			{
   1.703 +			ret = EFalse;
   1.704 +			}
   1.705 +		}
   1.706 +
   1.707 +	return ret;
   1.708 +	}
   1.709 +
   1.710 +TBool CDataWrapperBase::TranslateNumberToEnumStringL(CDataWrapper& aDataWrapper,
   1.711 +									   const TDesC& aSection,
   1.712 +									   const TInt aValue,
   1.713 +									   TDes& aTranslation)
   1.714 +	{
   1.715 +	TBool ret = EFalse;
   1.716 +
   1.717 +	TPtrC	enumElements;
   1.718 +	if ( aDataWrapper.GetStringFromConfig(aSection, KEnumElements, enumElements) )
   1.719 +		{
   1.720 +		ret = ProcessEnumList(aDataWrapper, enumElements, aSection, aValue, aTranslation);
   1.721 +		}
   1.722 +
   1.723 +	return ret;
   1.724 +	}
   1.725 +/**
   1.726 + * Function which creates a consoles and writes to and reads from the console
   1.727 + *
   1.728 + * @param aMsg			Message wrote to the console
   1.729 + * @param aDelayMiliSec  	waiting period for user input, read from config file
   1.730 + * @param aKeyCode		specifies key required to be pressed to pass the test
   1.731 + *
   1.732 + * @leave					System wide error
   1.733 + */
   1.734 +
   1.735 +void CDataWrapperBase::PromptMessageL(const TDesC& aMsg,
   1.736 +								const TInt aDelayMiliSec,
   1.737 +								TKeyCode& aKeyCode)
   1.738 +	{
   1.739 +	CConsoleBase* console = GetConsoleL();
   1.740 +	CleanupStack::PushL(console);
   1.741 +
   1.742 +	if( aMsg.Length() != 0 )
   1.743 +		{
   1.744 +		console->Printf(aMsg);
   1.745 +		}
   1.746 +	TRequestStatus keyStatus(KRequestPending);
   1.747 +	TRequestStatus timerStatus(KRequestPending);
   1.748 +	aKeyCode=EKeyNull;
   1.749 +	iTimer.After(timerStatus,SECS_TO_MICROSEC(aDelayMiliSec));
   1.750 +	console->Read(keyStatus);
   1.751 +	User::WaitForRequest(keyStatus,timerStatus);
   1.752 +	if (keyStatus!=KRequestPending)
   1.753 +		{
   1.754 +		//Keypressed
   1.755 +		iTimer.Cancel();
   1.756 +		aKeyCode =console->KeyCode();
   1.757 +		User::WaitForRequest(timerStatus);
   1.758 +		}
   1.759 +	else
   1.760 +		{
   1.761 +		console->ReadCancel();
   1.762 +		SetBlockResult(EFail);
   1.763 +		}
   1.764 +
   1.765 +	CleanupStack::PopAndDestroy(console);
   1.766 +	}
   1.767 +/**
   1.768 + * Process a command read from the script file calling the required function
   1.769 + *
   1.770 + * @param aSection			The section in the ini containing data for the command
   1.771 + * @param aCommand			Command to be called
   1.772 + *
   1.773 + * @leave					System wide error
   1.774 + */
   1.775 +
   1.776 +TBool CDataWrapperBase::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
   1.777 +	{
   1.778 +
   1.779 +	if ( aCommand==KCmdUtilityPromptMessage )
   1.780 +		{
   1.781 +		DoCmdUtilityPromptMessageL(aSection);
   1.782 +		}
   1.783 +	else
   1.784 +		{
   1.785 +		ERR_PRINTF1(_L("No Function Matches Requested Command"));
   1.786 +		SetBlockResult(EFail);
   1.787 +		}
   1.788 +
   1.789 +	return ETrue;
   1.790 +	}
   1.791 +/**
   1.792 + * Functon called through TEF for manual verification which writes a message to the console and reads user input keyboard
   1.793 + *
   1.794 + * @param aSection			The section in the ini containing data for the command
   1.795 + *
   1.796 + * @leave					System wide error
   1.797 + */
   1.798 +
   1.799 +void CDataWrapperBase::DoCmdUtilityPromptMessageL(const TDesC& aSection)
   1.800 +
   1.801 +	{
   1.802 +	INFO_PRINTF1(_L("DoCmdUtilityPromptMessageL called"));
   1.803 +
   1.804 +	TPtrC	message;
   1.805 +	TBool   hasMessage =  GetStringFromConfig(aSection, KPromptText(), message);
   1.806 +
   1.807 +	if( !hasMessage )
   1.808 +		{
   1.809 +		INFO_PRINTF1(_L("Prompt message not specified in the ini file"));
   1.810 +		}
   1.811 +
   1.812 +	// 10 second default delay
   1.813 +	TInt	delay = KDefaultDelay;
   1.814 +	GetIntFromConfig(aSection, KDelay(), delay);
   1.815 +	TKeyCode keyCode;
   1.816 +	do
   1.817 +		{
   1.818 +		PromptMessageL(message, delay, keyCode);
   1.819 +		}while (keyCode>KBounceErrKey);
   1.820 +	INFO_PRINTF2(_L("Key %d pressed"), keyCode);
   1.821 +	TInt expectedKey;
   1.822 +	if( GetIntFromConfig(aSection, KExpectedKey(), expectedKey) )
   1.823 +		{
   1.824 +		// compares key pressed with key in config file
   1.825 +		if(keyCode != (TKeyCode)expectedKey)
   1.826 +			{
   1.827 +			ERR_PRINTF3(_L("expectedKey=%d pressed key=%d"), expectedKey, keyCode);
   1.828 +			SetBlockResult(EFail);
   1.829 +			}
   1.830 +		}
   1.831 +	else
   1.832 +		{
   1.833 +		ERR_PRINTF1(_L("KeyCode not specified in the ini file"));
   1.834 +		SetBlockResult(EFail);
   1.835 +		}
   1.836 +
   1.837 +	}