haitest/bspsvs/suite/common/src/DataWrapperBase.cpp
changeset 0 cec860690d41
equal deleted inserted replaced
-1:000000000000 0:cec860690d41
       
     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 "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 *
       
    16 */
       
    17 
       
    18 #include "DataWrapperBase.h"
       
    19 
       
    20 #define SECS_TO_MICROSEC(x)  (x*1000000)
       
    21 
       
    22 /*@{*/
       
    23 ///	Constant Literals used.
       
    24 _LIT(KPrefixHex,				"0x");
       
    25 _LIT(KPrefixOctal,				"0");
       
    26 _LIT(KSuffixBinary,				"b");
       
    27 
       
    28 _LIT(KIncludeSection,			"include");
       
    29 _LIT(KFile,						"file%d");
       
    30 _LIT(KMatch,					"*{*,*}*");
       
    31 _LIT(KStart,					"{");
       
    32 _LIT(KSeparator,				",");
       
    33 _LIT(KEnd,						"}");
       
    34 _LIT(KDataRead,					"INI READ : %S %S %S");
       
    35 _LIT(KTagPointX,				"%S_x");
       
    36 _LIT(KTagPointY,				"%S_y");
       
    37 _LIT(KTagRectMinX,				"%S_minX");
       
    38 _LIT(KTagRectMaxX,				"%S_maxX");
       
    39 _LIT(KTagRectMinY,				"%S_minY");
       
    40 _LIT(KTagRectMaxY,				"%S_maxY");
       
    41 _LIT(KTagSizeHeight,			"%S_height");
       
    42 _LIT(KTagSizeWidth,				"%S_width");
       
    43 _LIT(KEnumElements,				"enum_elements");
       
    44 _LIT(KPrefixHexKey,				"0x%S");
       
    45 
       
    46 _LIT(KCmdUtilityPromptMessage,	"utilityPromptMessage");
       
    47 _LIT(KPromptText,				"message");
       
    48 _LIT(KDelay,					"delay");
       
    49 _LIT(KExpectedKey,				"keyCode");
       
    50 /*@}*/
       
    51 
       
    52 const TInt	KDefaultDelay	=	10;
       
    53 const TInt	KBounceErrKey	=	50000;
       
    54 
       
    55 CDataWrapperBase::CDataWrapperBase()
       
    56 :	CDataWrapper()
       
    57 	{
       
    58 	}
       
    59 
       
    60 CDataWrapperBase::~CDataWrapperBase()
       
    61 /**
       
    62  * Public destructor
       
    63  */
       
    64 	{
       
    65 	iInclude.ResetAndDestroy();
       
    66 	iBuffer.ResetAndDestroy();
       
    67 	iFs.Close();
       
    68 	}
       
    69 
       
    70 void CDataWrapperBase::InitialiseL()
       
    71 	{
       
    72 	iTimer.CreateLocal();
       
    73 	CDataWrapper::InitialiseL();
       
    74 	TBuf<KMaxTestExecuteCommandLength>	tempStore;
       
    75 	TPtrC		fileName;
       
    76 	TBool		moreData=ETrue;
       
    77 	TBool		index=0;
       
    78 	while ( moreData )
       
    79 		{
       
    80 		tempStore.Format(KFile(), ++index);
       
    81 		moreData=GetStringFromConfig(KIncludeSection, tempStore, fileName);
       
    82 
       
    83 		if (moreData)
       
    84 			{
       
    85 			CIniData*	iniData=CIniData::NewL(fileName);
       
    86 			CleanupStack::PushL(iniData);
       
    87 			iInclude.Append(iniData);
       
    88 			CleanupStack::Pop(iniData);
       
    89 			}
       
    90 		}
       
    91 	User::LeaveIfError(iFs.Connect());
       
    92 	}
       
    93 
       
    94 TBool CDataWrapperBase::GetBoolFromConfig(const TDesC& aSectName,const TDesC& aKeyName,TBool& aResult)
       
    95 /**
       
    96  * Reads the value present from the test steps ini file within the mentioned section name and key name
       
    97  * Copies the value to the TBool reference passed in possible values TRUE, FALSE
       
    98  * @param aSectName - Section within the test steps ini file
       
    99  * @param aKeyName - Name of a key within a section
       
   100  * @return aResult - The value of the boolean
       
   101  * @return TBool - ETrue for found, EFalse for not found
       
   102  */
       
   103 	{
       
   104 	TBool	ret=EFalse;
       
   105 	TPtrC	result;
       
   106 	TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
       
   107 	if ( err != KErrNone )
       
   108 		{
       
   109 		ret=EFalse;
       
   110 		}
       
   111 	if ( ret )
       
   112 		{
       
   113 		_LIT(KTrue,"true");
       
   114 		aResult=(result.FindF(KTrue) != KErrNotFound);
       
   115 		}
       
   116 
       
   117 	return ret;
       
   118 	}
       
   119 
       
   120 TBool CDataWrapperBase::GetIntFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult)
       
   121 /**
       
   122  * Reads the value present from the test steps ini file within the mentioned section name and key name
       
   123  * Copies the value to the TInt reference passed in
       
   124  * @param aSectName - Section within the test steps ini file
       
   125  * @param aKeyName - Name of a key within a section
       
   126  * @return aResult - The value of the integer
       
   127  * @return TBool - ETrue for found, EFalse for not found
       
   128  */
       
   129 	{
       
   130 	TPtrC	result;
       
   131 	TBool	ret=EFalse;
       
   132 	TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
       
   133 	if ( err != KErrNone )
       
   134 		{
       
   135 		ret=EFalse;
       
   136 		}
       
   137 	if ( ret )
       
   138 		{
       
   139 		TLex	lex(result);
       
   140 		ret=(lex.Val(aResult)==KErrNone);
       
   141 		}
       
   142 
       
   143 	return ret;
       
   144 	}
       
   145 
       
   146 TBool CDataWrapperBase::GetStringFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult)
       
   147 /**
       
   148  * Reads the value present from the test steps ini file within the mentioned section name and key name
       
   149  * Copies the value to the TPtrC reference passed in
       
   150  * @param aSectName - Section within the test steps ini file
       
   151  * @param aKeyName - Name of a key within a section
       
   152  * @return aResult - Reference to the string on the heap
       
   153  * @return TBool - ETrue for found, EFalse for not found
       
   154  */
       
   155 	{
       
   156 	TBool	ret=EFalse;
       
   157 	TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, aResult));
       
   158 	if ( err != KErrNone )
       
   159 		{
       
   160 		ret=EFalse;
       
   161 		}
       
   162 	return ret;
       
   163 	}
       
   164 
       
   165 TBool CDataWrapperBase::GetHexFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult)
       
   166 /**
       
   167  * Reads the value present from the test steps ini file within the mentioned section name and key name
       
   168  * Copies the value to the TInt reference passed in. The value can optionally be prefixed with 0x
       
   169  * @param aSectName - Section within the test steps ini file
       
   170  * @param aKeyName - Name of a key within a section
       
   171  * @return aResult - The integer value of the Hex input
       
   172  * @return TBool - ETrue for found, EFalse for not found
       
   173  */
       
   174 	{
       
   175 	TPtrC	result;
       
   176 	TBool	ret=EFalse;
       
   177 	TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
       
   178 	if ( err != KErrNone )
       
   179 		{
       
   180 		ret=EFalse;
       
   181 		}
       
   182 	if ( ret )
       
   183 		{
       
   184 		TLex	lex;
       
   185 		if( result.FindC(KPrefixHex)==KErrNone )
       
   186 			{
       
   187 			lex=result.Mid(KPrefixHex().Length());
       
   188 			}
       
   189 		else
       
   190 			{
       
   191 			lex=result;
       
   192 			}
       
   193 		ret=(lex.Val((TUint &)aResult, EHex)==KErrNone);
       
   194 		}
       
   195 
       
   196 	return ret;
       
   197 	}
       
   198 
       
   199 TBool CDataWrapperBase::GetUintFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TUint& aResult)
       
   200 /**
       
   201  * Reads the value present from the test steps ini file within the mentioned section name and key name
       
   202  * Copies the value to the TUint reference passed in.
       
   203  * If the value is prefixed with 0x the value is read as a hexidecimal value
       
   204  * If the value is suffixed with b the value is read as a binary value
       
   205  * If the value is prefixed with a 0 the value is read as an octal value
       
   206  * If it does not match the above it is read in as an integer
       
   207  * @param aSectName - Section within the test steps ini file
       
   208  * @param aKeyName - Name of a key within a section
       
   209  * @return aResult - The integer value of the Hex input
       
   210  * @return TBool - ETrue for found, EFalse for not found
       
   211  */
       
   212 	{
       
   213 	TPtrC	result;
       
   214 	TBool	ret=EFalse;
       
   215 	TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
       
   216 	if ( err != KErrNone )
       
   217 		{
       
   218 		ret=EFalse;
       
   219 		}
       
   220 	if ( ret )
       
   221 		{
       
   222 		TLex	lex(result);
       
   223 		if( result.FindC(KPrefixHex)==KErrNone )
       
   224 			{
       
   225 			lex=result.Mid(KPrefixHex().Length());
       
   226 			ret=(lex.Val(aResult, EHex)==KErrNone);
       
   227 			}
       
   228 		else
       
   229 			{
       
   230 			TInt	binarySuffixPosition=result.Length()-KSuffixBinary().Length();
       
   231 			if ( result.FindC(KSuffixBinary)==binarySuffixPosition )
       
   232 				{
       
   233 				lex=result.Left(binarySuffixPosition);
       
   234 				ret=(lex.Val(aResult, EBinary)==KErrNone);
       
   235 				}
       
   236 			else
       
   237 				{
       
   238 				if( result.FindC(KPrefixOctal)==KErrNone )
       
   239 					{
       
   240 					ret=(lex.Val(aResult, EOctal)==KErrNone);
       
   241 					}
       
   242 				else
       
   243 					{
       
   244 					TInt	intResult;
       
   245 					ret=(lex.Val(intResult)==KErrNone);
       
   246 					if ( ret )
       
   247 						{
       
   248 						aResult=(TUint)intResult;
       
   249 						}
       
   250 					}
       
   251 				}
       
   252 			}
       
   253 		}
       
   254 
       
   255 	return ret;
       
   256 	}
       
   257 
       
   258 TBool CDataWrapperBase::GetEnumFromConfig(const TDesC& aSectName, const TDesC& aKeyName, const TEnumEntryTable* aTable, TInt& aResult)
       
   259 	{
       
   260 	TPtrC	str;
       
   261 	TBool	ret=GetStringFromConfig(aSectName, aKeyName, str);
       
   262 
       
   263 	if ( ret )
       
   264 		{
       
   265 		TBool	found=EFalse;
       
   266 		TInt	index=0;
       
   267 		while ( (aTable[index].iValue!=-1) && !found )
       
   268 			{
       
   269 			if ( aTable[index].iString==str )
       
   270 				{
       
   271 				found=ETrue;
       
   272 				aResult=aTable[index].iValue;
       
   273 				}
       
   274 			else
       
   275 				{
       
   276 				++index;
       
   277 				}
       
   278 			}
       
   279 
       
   280 		if ( !found )
       
   281 			{
       
   282 			ret=GetIntFromConfig(aSectName, aKeyName, aResult);
       
   283 			}
       
   284 		}
       
   285 
       
   286 	return ret;
       
   287 	}
       
   288 
       
   289 TBool CDataWrapperBase::GetOrFromConfig(const TDesC& aSectName, const TDesC& aKeyName, const TEnumEntryTable* aTable, TUint& aResult)
       
   290 	{
       
   291 	TPtrC 	str;
       
   292 	TBool	ret=GetStringFromConfig(aSectName, aKeyName, str);
       
   293 	if ( ret )
       
   294 		{
       
   295 		TUint	temp=0;
       
   296 		ret=ProcessString(str, temp, aTable);
       
   297 		if ( ret )
       
   298 			{
       
   299 			aResult=temp;
       
   300 			}
       
   301 		}
       
   302 
       
   303 	return ret;
       
   304 	}
       
   305 
       
   306 TBool CDataWrapperBase::ProcessString(const TDesC& aStr, TUint& aResult, const TEnumEntryTable* aTable)
       
   307 	{
       
   308 	TBool	ret=ETrue;
       
   309 	TInt	location=aStr.Match(_L("*|*"));
       
   310 	if( location!=KErrNotFound )
       
   311 		{
       
   312 		// Converting Left part of the data
       
   313 		TPtrC	tempStr=aStr.Left(location);
       
   314 		ret=ProcessString(tempStr, aResult, aTable);
       
   315 
       
   316 		// Converting right data can be with another "|"
       
   317 		tempStr.Set(aStr.Mid(location+1));
       
   318 
       
   319 		TUint	temp;
       
   320 		if ( ProcessString(tempStr, temp, aTable) )
       
   321 			{
       
   322 			aResult|=temp;
       
   323 			}
       
   324 		else
       
   325 			{
       
   326 			ret=EFalse;
       
   327 			}
       
   328 		}
       
   329 	else
       
   330 		{
       
   331 		ret=ProcessEntry(aStr, aResult, aTable);
       
   332 		}
       
   333 
       
   334 	return ret;
       
   335 	}
       
   336 
       
   337 TBool CDataWrapperBase::ProcessEntry(const TDesC& aStr, TUint& aResult, const TEnumEntryTable* aTable)
       
   338 	{
       
   339 	TBool	ret=ETrue;
       
   340 
       
   341 	TBool	found=EFalse;
       
   342 	TInt	index=0;
       
   343 	while ( (aTable[index].iValue!=-1) && !found )
       
   344 		{
       
   345 		if ( aTable[index].iString==aStr )
       
   346 			{
       
   347 			found=ETrue;
       
   348 			aResult=aTable[index].iValue;
       
   349 			}
       
   350 		else
       
   351 			{
       
   352 			++index;
       
   353 			}
       
   354 		}
       
   355 
       
   356 	if ( !found )
       
   357 		{
       
   358 		TUint	flags;
       
   359 		TLex	lex(aStr);
       
   360 		ret=(lex.Val(flags, EHex)==KErrNone);
       
   361 		if ( ret )
       
   362 			{
       
   363 			aResult=flags;
       
   364 			}
       
   365 		}
       
   366 
       
   367 	return ret;
       
   368 	}
       
   369 
       
   370 TBool CDataWrapperBase::GetCommandStringParameterL(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult)
       
   371 	{
       
   372 	TBool	ret=EFalse;
       
   373 
       
   374 	if ( aSectName.Length()!=0 )
       
   375 		{
       
   376 		ret=CDataWrapper::GetStringFromConfig(aSectName, aKeyName, aResult);
       
   377 
       
   378 		for ( TInt index=iInclude.Count(); (index>0) && (!ret); )
       
   379 			{
       
   380 			ret=iInclude[--index]->FindVar(aSectName, aKeyName, aResult);
       
   381 			if ( ret )
       
   382 				{
       
   383 				INFO_PRINTF4(KDataRead, &aSectName, &aKeyName, &aResult);
       
   384 				}
       
   385 			}
       
   386 		}
       
   387 
       
   388 	if ( ret )
       
   389 		{
       
   390 		if ( aResult.Match(KMatch)!=KErrNotFound )
       
   391 			{
       
   392 			//	We have an entry of the format
       
   393 			//	entry =*{section,entry}*
       
   394 			//	where * is one or more characters
       
   395 			//	We need to construct this from other data in the ini file replacing {*,*}
       
   396 			//	with the data from
       
   397 			//	[section]
       
   398 			//	entry =some_value
       
   399 			HBufC*	buffer=HBufC::NewLC(aResult.Length());
       
   400 			buffer->Des().Copy(aResult);
       
   401 
       
   402 			TInt	startLength=KStart().Length();
       
   403 			TInt	sparatorLength=KSeparator().Length();
       
   404 			TInt	endLength=KEnd().Length();
       
   405 			TInt	bufferLength;
       
   406 			TInt	start;
       
   407 			TInt	sparator;
       
   408 			TInt	end;
       
   409 			TPtrC	remaining;
       
   410 			TLex	lex;
       
   411 			do
       
   412 				{
       
   413 				bufferLength=buffer->Length();
       
   414 				start=buffer->Find(KStart);
       
   415 
       
   416 				remaining.Set(buffer->Des().Right(bufferLength-start-startLength));
       
   417 				sparator=remaining.Find(KSeparator);
       
   418 				remaining.Set(remaining.Right(remaining.Length()-sparator-sparatorLength));
       
   419 				sparator += (start + startLength);
       
   420 
       
   421 				end=remaining.Find(KEnd) + sparator + sparatorLength;
       
   422 
       
   423 				TPtrC	sectionName(buffer->Ptr()+start+startLength, sparator-start-startLength);
       
   424 				TPtrC	keyName(buffer->Ptr()+sparator+sparatorLength, end-sparator-sparatorLength);
       
   425 				sectionName.Set(TLex(sectionName).NextToken());
       
   426 				keyName.Set(TLex(keyName).NextToken());
       
   427 
       
   428 				TInt	entrySize=0;
       
   429 				TPtrC	entryData;
       
   430 				TBool	found=CDataWrapper::GetStringFromConfig(sectionName, keyName, entryData);
       
   431 				for ( TInt index=iInclude.Count(); (index>0) && (!found);  )
       
   432 					{
       
   433 					found=iInclude[--index]->FindVar(sectionName, keyName, entryData);
       
   434 					}
       
   435 				if ( found )
       
   436 					{
       
   437 					entrySize=entryData.Length();
       
   438 					}
       
   439 
       
   440 				TInt	newLength=start + bufferLength - end - endLength + entrySize;
       
   441 				HBufC*	bufferNew=HBufC::NewLC(newLength);
       
   442 				bufferNew->Des().Copy(buffer->Ptr(), start);
       
   443 				if ( entrySize>0 )
       
   444 					{
       
   445 					bufferNew->Des().Append(entryData);
       
   446 					}
       
   447 				bufferNew->Des().Append(buffer->Ptr() + end + endLength, bufferLength - end - endLength);
       
   448 				CleanupStack::Pop(bufferNew);
       
   449 				CleanupStack::PopAndDestroy(buffer);
       
   450 				buffer=bufferNew;
       
   451 				CleanupStack::PushL(buffer);
       
   452 				}
       
   453 			while ( buffer->Match(KMatch)!=KErrNotFound );
       
   454 			iBuffer.Append(buffer);
       
   455 			CleanupStack::Pop(buffer);
       
   456 			aResult.Set(*buffer);
       
   457 			INFO_PRINTF4(KDataRead, &aSectName, &aKeyName, &aResult);
       
   458 			}
       
   459 		}
       
   460 
       
   461 	return ret;
       
   462 	}
       
   463 
       
   464 TBool CDataWrapperBase::GetCommandStringParameter(const TDesC& aParameterName, const TDesC& aSection, TPtrC& aResult, TText8 *aFileName, TInt aLine, TBool aMandatory)
       
   465 	{
       
   466 	TBool	ret = GetStringFromConfig(aSection, aParameterName, aResult);
       
   467 	if (aMandatory && !ret)
       
   468 		{
       
   469 		Logger().LogExtra(aFileName, aLine, ESevrErr, _L("No %S"), &aParameterName);
       
   470 		SetBlockResult(EFail);
       
   471 		}
       
   472 	return ret;
       
   473 	}
       
   474 
       
   475 TBool CDataWrapperBase::GetCommandIntParameter(const TDesC& aParameterName, const TDesC& aSection, TInt& aResult, TText8* aFileName, TInt aLine, TBool aMandatory)
       
   476 	{
       
   477 	TBool	ret = GetIntFromConfig(aSection, aParameterName, aResult);
       
   478 	if (aMandatory && !ret)
       
   479 		{
       
   480 		Logger().LogExtra(aFileName, aLine, ESevrErr, _L("No %S"), &aParameterName);
       
   481 		SetBlockResult(EFail);
       
   482 		}
       
   483 	return ret;
       
   484 	}
       
   485 
       
   486 TBool CDataWrapperBase::GetCommandBoolParameter(const TDesC& aParameterName, const TDesC& aSection, TBool& aResult, TText8 *aFileName, TInt aLine, TBool aMandatory)
       
   487 	{
       
   488 	TBool	ret = GetBoolFromConfig(aSection, aParameterName, aResult);
       
   489 	if (aMandatory && !ret)
       
   490 		{
       
   491 		Logger().LogExtra(aFileName, aLine, ESevrErr, _L("No %S"), &aParameterName);
       
   492 		SetBlockResult(EFail);
       
   493 		}
       
   494 	return ret;
       
   495 	}
       
   496 
       
   497 TBool CDataWrapperBase::GetPointFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TPoint& aResult)
       
   498 /**
       
   499  * Reads the value present from the test steps ini file within the mentioned section name and key name
       
   500  * Copies the value to the TPoint reference passed in
       
   501  * @param aSectName - Section within the test steps ini file
       
   502  * @param aKeyName - Name of a key within a section
       
   503  * @return aResult - The value of the TPoint
       
   504  * @return TBool - ETrue for found, EFalse for not found
       
   505  */
       
   506 	{
       
   507 	TBuf<KMaxTestExecuteCommandLength>	tempStore;
       
   508 
       
   509 	TInt	x;
       
   510 	tempStore.Format(KTagPointX, &aKeyName);
       
   511 	TBool	ret=GetIntFromConfig(aSectName, tempStore, x);
       
   512 	TInt	y;
       
   513 	tempStore.Format(KTagPointY, &aKeyName);
       
   514 	if ( !GetIntFromConfig(aSectName, tempStore, y) )
       
   515 		{
       
   516 		ret=EFalse;
       
   517 		}
       
   518 	if ( ret )
       
   519 		{
       
   520 		aResult.SetXY(x, y);
       
   521 		}
       
   522 
       
   523 	return ret;
       
   524 	}
       
   525 
       
   526 TBool CDataWrapperBase::GetRectFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TRect& aResult)
       
   527 /**
       
   528  * Reads the value present from the test steps ini file within the mentioned section name and key name
       
   529  * Copies the value to the TPoint reference passed in
       
   530  * @param aSectName - Section within the test steps ini file
       
   531  * @param aKeyName - Name of a key within a section
       
   532  * @return aResult - The value of the TRect
       
   533  * @return TBool - ETrue for found, EFalse for not found
       
   534  */
       
   535 	{
       
   536 	TBuf<KMaxTestExecuteCommandLength>	tempStore;
       
   537 
       
   538 	TInt	minX;
       
   539 	tempStore.Format(KTagRectMinX, &aKeyName);
       
   540 	TBool	ret=GetIntFromConfig(aSectName, tempStore, minX);
       
   541 
       
   542 	TInt	maxX;
       
   543 	tempStore.Format(KTagRectMaxX, &aKeyName);
       
   544 	if ( !GetIntFromConfig(aSectName, tempStore, maxX) )
       
   545 		{
       
   546 		ret=EFalse;
       
   547 		}
       
   548 
       
   549 	TInt	minY;
       
   550 	tempStore.Format(KTagRectMinY, &aKeyName);
       
   551 	if ( !GetIntFromConfig(aSectName, tempStore, minY) )
       
   552 		{
       
   553 		ret=EFalse;
       
   554 		}
       
   555 
       
   556 	TInt	maxY;
       
   557 	tempStore.Format(KTagRectMaxY, &aKeyName);
       
   558 	if ( !GetIntFromConfig(aSectName, tempStore, maxY) )
       
   559 		{
       
   560 		ret=EFalse;
       
   561 		}
       
   562 
       
   563 	if ( ret )
       
   564 		{
       
   565 		aResult.SetRect(minX, minY, maxX, maxY);
       
   566 		}
       
   567 
       
   568 	return ret;
       
   569 	}
       
   570 
       
   571 TBool CDataWrapperBase::GetSizeFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TSize& aResult)
       
   572 /**
       
   573  * Reads the value present from the test steps ini file within the mentioned section name and key name
       
   574  * Copies the value to the TPoint reference passed in
       
   575  * @param aSectName - Section within the test steps ini file
       
   576  * @param aKeyName - Name of a key within a section
       
   577  * @return aResult - The value of the TPoint
       
   578  * @return TBool - ETrue for found, EFalse for not found
       
   579  */
       
   580 	{
       
   581 	TBuf<KMaxTestExecuteCommandLength>	tempStore;
       
   582 
       
   583 	TInt	height;
       
   584 	tempStore.Format(KTagSizeHeight, &aKeyName);
       
   585 	TBool	ret=GetIntFromConfig(aSectName, tempStore, height);
       
   586 	TInt	width;
       
   587 	tempStore.Format(KTagSizeWidth, &aKeyName);
       
   588 	if ( !GetIntFromConfig(aSectName, tempStore, width) )
       
   589 		{
       
   590 		ret=EFalse;
       
   591 		}
       
   592 	if ( ret )
       
   593 		{
       
   594 		aResult.SetSize(width, height);
       
   595 		}
       
   596 
       
   597 	return ret;
       
   598 	}
       
   599 
       
   600 TBool CDataWrapperBase::GetUint8FromConfig(const TDesC& aSectName, const TDesC& aKeyName, TUint8& aResult)
       
   601 	{
       
   602 	TUint	temp;
       
   603 	TBool	ret=GetUintFromConfig(aSectName, aKeyName,temp);
       
   604 	if ( ret )
       
   605 		{
       
   606 		aResult=(TUint8)temp;
       
   607 		}
       
   608 
       
   609 	return ret;
       
   610 	}
       
   611 
       
   612 void CDataWrapperBase::Timedelay(TInt aTimeoutInSecs)
       
   613 /*Utility function to produce time delay
       
   614 @param aTimeoutInSecs Times in micro seconds
       
   615 */
       
   616 	{
       
   617 	TRequestStatus	status;
       
   618 	iTimer.After(status, aTimeoutInSecs);
       
   619 	User::WaitForRequest(status);
       
   620 	}
       
   621 
       
   622 TBool CDataWrapperBase::TranslateEnumToString(CDataWrapper& aDataWrapper,
       
   623 										const TDesC& aEnum,
       
   624 										const TInt aValue,
       
   625 										TDesC& aTranslation)
       
   626 /* Function translates
       
   627 */
       
   628 	{
       
   629 	TBool ret = ETrue;
       
   630 
       
   631 	RBuf desToWrapInt;
       
   632 	RBuf desToFormHex;
       
   633 	TInt intError = desToWrapInt.Create(KMaxFullName);
       
   634 	TInt hexError = desToFormHex.Create(KMaxFullName);
       
   635 	if(intError == KErrNone && hexError == KErrNone)
       
   636 		{
       
   637 		desToFormHex.NumFixedWidth(aValue, EHex, 8);
       
   638 		desToWrapInt.Format(KPrefixHexKey, &desToFormHex);
       
   639 		if (!aDataWrapper.GetStringFromConfig(aEnum, desToWrapInt, static_cast<TPtrC&>(aTranslation)))
       
   640 			{
       
   641 			ret = EFalse;
       
   642 			}
       
   643 		}
       
   644 	else
       
   645 		{
       
   646 		ret = EFalse;
       
   647 		}
       
   648 
       
   649 	if(hexError == KErrNone)
       
   650 		{
       
   651 		desToFormHex.Close();
       
   652 		}
       
   653 	if(intError == KErrNone)
       
   654 		{
       
   655 		desToWrapInt.Close();
       
   656 		}
       
   657 
       
   658 	return ret;
       
   659 	}
       
   660 
       
   661 TBool CDataWrapperBase::ProcessEnumList(CDataWrapper& aDataWrapper,
       
   662 									const TDesC& aStr,
       
   663 									const TDesC& aEnum,
       
   664 									const TUint& aValue,
       
   665 									TDes& aTranslation)
       
   666 	{
       
   667 	TBool	ret=ETrue;
       
   668 	TInt	location=aStr.Match(_L("*|*"));
       
   669 	if( location!=KErrNotFound )
       
   670 		{
       
   671 		// Converting Left part of the data
       
   672 		TPtrC	tempStr=aStr.Left(location);
       
   673 		ret=ProcessEnumList(aDataWrapper, tempStr, aEnum, aValue, aTranslation);
       
   674 
       
   675 		// Converting right data can be with another "|"
       
   676 		tempStr.Set(aStr.Mid(location+1));
       
   677 
       
   678 		if ( !ProcessEnumList(aDataWrapper, tempStr, aEnum, aValue, aTranslation) )
       
   679 			{
       
   680 			ret=EFalse;
       
   681 			}
       
   682 		}
       
   683 	else
       
   684 		{
       
   685 		TInt value;
       
   686 		if (aDataWrapper.GetHexFromConfig(aEnum, aStr, value ))
       
   687 			{
       
   688 			if (value & aValue)
       
   689 				{
       
   690 				if ( aTranslation.Length() )
       
   691 					{
       
   692 					aTranslation.Append(_L("|"));
       
   693 					}
       
   694 
       
   695 				aTranslation.Append(aStr);
       
   696 				}
       
   697 			}
       
   698 		else
       
   699 			{
       
   700 			ret = EFalse;
       
   701 			}
       
   702 		}
       
   703 
       
   704 	return ret;
       
   705 	}
       
   706 
       
   707 TBool CDataWrapperBase::TranslateNumberToEnumStringL(CDataWrapper& aDataWrapper,
       
   708 									   const TDesC& aSection,
       
   709 									   const TInt aValue,
       
   710 									   TDes& aTranslation)
       
   711 	{
       
   712 	TBool ret = EFalse;
       
   713 
       
   714 	TPtrC	enumElements;
       
   715 	if ( aDataWrapper.GetStringFromConfig(aSection, KEnumElements, enumElements) )
       
   716 		{
       
   717 		ret = ProcessEnumList(aDataWrapper, enumElements, aSection, aValue, aTranslation);
       
   718 		}
       
   719 
       
   720 	return ret;
       
   721 	}
       
   722 /**
       
   723  * Function which creates a consoles and writes to and reads from the console
       
   724  *
       
   725  * @param aMsg			Message wrote to the console
       
   726  * @param aDelayMiliSec  	waiting period for user input, read from config file
       
   727  * @param aKeyCode		specifies key required to be pressed to pass the test
       
   728  *
       
   729  * @leave					System wide error
       
   730  */
       
   731 
       
   732 void CDataWrapperBase::PromptMessageL(const TDesC& aMsg,
       
   733 								const TInt aDelayMiliSec,
       
   734 								TKeyCode& aKeyCode)
       
   735 	{
       
   736 	CConsoleBase* console = GetConsoleL();
       
   737 	CleanupStack::PushL(console);
       
   738 
       
   739 	if( aMsg.Length() != 0 )
       
   740 		{
       
   741 		console->Printf(aMsg);
       
   742 		}
       
   743 	TRequestStatus keyStatus(KRequestPending);
       
   744 	TRequestStatus timerStatus(KRequestPending);
       
   745 	aKeyCode=EKeyNull;
       
   746 	iTimer.After(timerStatus,SECS_TO_MICROSEC(aDelayMiliSec));
       
   747 	console->Read(keyStatus);
       
   748 	User::WaitForRequest(keyStatus,timerStatus);
       
   749 	if (keyStatus!=KRequestPending)
       
   750 		{
       
   751 		//Keypressed
       
   752 		iTimer.Cancel();
       
   753 		aKeyCode =console->KeyCode();
       
   754 		User::WaitForRequest(timerStatus);
       
   755 		}
       
   756 	else
       
   757 		{
       
   758 		console->ReadCancel();
       
   759 		SetBlockResult(EFail);
       
   760 		}
       
   761 
       
   762 	CleanupStack::PopAndDestroy(console);
       
   763 	}
       
   764 /**
       
   765  * Process a command read from the script file calling the required function
       
   766  *
       
   767  * @param aSection			The section in the ini containing data for the command
       
   768  * @param aCommand			Command to be called
       
   769  *
       
   770  * @leave					System wide error
       
   771  */
       
   772 
       
   773 TBool CDataWrapperBase::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
       
   774 	{
       
   775 
       
   776 	if ( aCommand==KCmdUtilityPromptMessage )
       
   777 		{
       
   778 		DoCmdUtilityPromptMessageL(aSection);
       
   779 		}
       
   780 	else
       
   781 		{
       
   782 		ERR_PRINTF1(_L("No Function Matches Requested Command"));
       
   783 		SetBlockResult(EFail);
       
   784 		}
       
   785 
       
   786 	return ETrue;
       
   787 	}
       
   788 /**
       
   789  * Functon called through TEF for manual verification which writes a message to the console and reads user input keyboard
       
   790  *
       
   791  * @param aSection			The section in the ini containing data for the command
       
   792  *
       
   793  * @leave					System wide error
       
   794  */
       
   795 
       
   796 void CDataWrapperBase::DoCmdUtilityPromptMessageL(const TDesC& aSection)
       
   797 
       
   798 	{
       
   799 	INFO_PRINTF1(_L("DoCmdUtilityPromptMessageL called"));
       
   800 
       
   801 	TPtrC	message;
       
   802 	TBool   hasMessage =  GetStringFromConfig(aSection, KPromptText(), message);
       
   803 
       
   804 	if( !hasMessage )
       
   805 		{
       
   806 		INFO_PRINTF1(_L("Prompt message not specified in the ini file"));
       
   807 		}
       
   808 
       
   809 	// 10 second default delay
       
   810 	TInt	delay = KDefaultDelay;
       
   811 	GetIntFromConfig(aSection, KDelay(), delay);
       
   812 	TKeyCode keyCode;
       
   813 	do
       
   814 		{
       
   815 		PromptMessageL(message, delay, keyCode);
       
   816 		}while (keyCode>KBounceErrKey);
       
   817 	INFO_PRINTF2(_L("Key %d pressed"), keyCode);
       
   818 	TInt expectedKey;
       
   819 	if( GetIntFromConfig(aSection, KExpectedKey(), expectedKey) )
       
   820 		{
       
   821 		// compares key pressed with key in config file
       
   822 		if(keyCode != (TKeyCode)expectedKey)
       
   823 			{
       
   824 			ERR_PRINTF3(_L("expectedKey=%d pressed key=%d"), expectedKey, keyCode);
       
   825 			SetBlockResult(EFail);
       
   826 			}
       
   827 		}
       
   828 	else
       
   829 		{
       
   830 		ERR_PRINTF1(_L("KeyCode not specified in the ini file"));
       
   831 		SetBlockResult(EFail);
       
   832 		}
       
   833 
       
   834 	}