Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include "datawrapperbase.h"
22 /// Constant Literals used.
23 _LIT(KPrefixHex, "0x");
24 _LIT(KPrefixOctal, "0");
25 _LIT(KSuffixBinary, "b");
27 _LIT(KIncludeSection, "include");
28 _LIT(KFile, "file%d");
29 _LIT(KMatch, "*{*,*}*");
31 _LIT(KSeparator, ",");
33 _LIT(KDataRead, "INI READ : %S %S %S");
37 CDataWrapperBase::CDataWrapperBase()
45 CDataWrapperBase::~CDataWrapperBase()
47 iInclude.ResetAndDestroy();
48 iBuffer.ResetAndDestroy();
52 void CDataWrapperBase::InitialiseL()
55 CDataWrapper::InitialiseL();
56 TBuf<KMaxTestExecuteCommandLength> tempStore;
62 tempStore.Format(KFile(), ++index);
63 moreData=GetStringFromConfig(KIncludeSection, tempStore, fileName);
67 CIniData* iniData=CIniData::NewL(fileName);
68 CleanupStack::PushL(iniData);
69 iInclude.Append(iniData);
70 CleanupStack::Pop(iniData);
73 User::LeaveIfError(iFs.Connect());
77 * Reads the value present from the test steps ini file within the mentioned section name and key name
78 * Copies the value to the TBool reference passed in possible values TRUE, FALSE
79 * @param aSectName - Section within the test steps ini file
80 * @param aKeyName - Name of a key within a section
81 * @return aResult - The value of the boolean
82 * @return TBool - ETrue for found, EFalse for not found
84 TBool CDataWrapperBase::GetBoolFromConfig(const TDesC& aSectName,const TDesC& aKeyName,TBool& aResult)
88 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
89 if ( err != KErrNone )
96 aResult=(result.FindF(KTrue) != KErrNotFound);
103 * Reads the value present from the test steps ini file within the mentioned section name and key name
104 * Copies the value to the TInt reference passed in
105 * @param aSectName - Section within the test steps ini file
106 * @param aKeyName - Name of a key within a section
107 * @return aResult - The value of the integer
108 * @return TBool - ETrue for found, EFalse for not found
110 TBool CDataWrapperBase::GetIntFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult)
114 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
115 if ( err != KErrNone )
122 ret=(lex.Val(aResult)==KErrNone);
128 * Reads the value present from the test steps ini file within the mentioned section name and key name
129 * Copies the value to the TReal reference passed in
130 * @param aSectName - Section within the test steps ini file
131 * @param aKeyName - Name of a key within a section
132 * @return aResult - The value of the real
133 * @return TBool - ETrue for found, EFalse for not found
135 TBool CDataWrapperBase::GetRealFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TReal& aResult)
139 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
140 if ( err != KErrNone )
147 ret = ( lex.Val(aResult)==KErrNone );
153 * Reads the value present from the test steps ini file within the mentioned section name and key name
154 * Copies the value to the TPtrC reference passed in
155 * @param aSectName - Section within the test steps ini file
156 * @param aKeyName - Name of a key within a section
157 * @return aResult - Reference to the string on the heap
158 * @return TBool - ETrue for found, EFalse for not found
160 TBool CDataWrapperBase::GetStringFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult)
163 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, aResult));
164 if ( err != KErrNone )
172 * Reads the value present from the test steps ini file within the mentioned section name and key name
173 * Copies the value to the TInt reference passed in. The value can optionally be prefixed with 0x
174 * @param aSectName - Section within the test steps ini file
175 * @param aKeyName - Name of a key within a section
176 * @return aResult - The integer value of the Hex input
177 * @return TBool - ETrue for found, EFalse for not found
179 TBool CDataWrapperBase::GetHexFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult)
183 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
184 if ( err != KErrNone )
191 if( result.FindC(KPrefixHex)==KErrNone )
193 lex=result.Mid(KPrefixHex().Length());
199 ret=(lex.Val((TUint &)aResult, EHex)==KErrNone);
206 * Reads the value present from the test steps ini file within the mentioned section name and key name
207 * Copies the value to the TUint reference passed in.
208 * If the value is prefixed with 0x the value is read as a hexidecimal value
209 * If the value is suffixed with b the value is read as a binary value
210 * If the value is prefixed with a 0 the value is read as an octal value
211 * If it does not match the above it is read in as an integer
212 * @param aSectName - Section within the test steps ini file
213 * @param aKeyName - Name of a key within a section
214 * @return aResult - The integer value of the Hex input
215 * @return TBool - ETrue for found, EFalse for not found
217 TBool CDataWrapperBase::GetUintFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TUint& aResult)
221 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
222 if ( err != KErrNone )
229 if( result.FindC(KPrefixHex)==KErrNone )
231 lex=result.Mid(KPrefixHex().Length());
232 ret=(lex.Val(aResult, EHex)==KErrNone);
236 TInt binarySuffixPosition=result.Length()-KSuffixBinary().Length();
237 if ( result.FindC(KSuffixBinary)==binarySuffixPosition )
239 lex=result.Left(binarySuffixPosition);
240 ret=(lex.Val(aResult, EBinary)==KErrNone);
244 if( result.FindC(KPrefixOctal)==KErrNone )
246 ret=(lex.Val(aResult, EOctal)==KErrNone);
251 ret=(lex.Val(intResult)==KErrNone);
254 aResult=(TUint)intResult;
265 * Return array of string parameters i.e. key=a1,a2,a3 returns array which contains
266 * String a1, a2 and a3.
267 * @return ret - EFalse if can't get a String parameter from Config file. ETrue if KErrNone
269 TBool CDataWrapperBase::GetArrayRectFromConfig(const TDesC& aSectName, const TDesC& aKeyName, RPointerArray<HBufC>& aResult)
274 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, completeArray));
275 if ( err != KErrNone )
280 TLex16 lex(completeArray); // Here we have the array as a string i.e. "a1,a2,a3"
287 // Check if there was a list separator
288 if ((chr == ',') && (lex.Peek() == '('))
290 HBufC* param = buf.AllocLC();
292 aResult.Append(param);
293 CleanupStack::Pop(param); // pointer to buf is stored in RPointerArray
295 // If not separator character we can store the character into array
301 // Remember to put last token into array (,a3)
302 HBufC* param = buf.AllocLC();
303 aResult.Append(param);
304 CleanupStack::Pop(param);
310 * Reads the parameter asociated to the specified command
311 * @param aSectName Section on ini file
312 * @param aKeyName Name of the parameter
313 * @param aResult descriptor containing parameter
314 * @return TBool ETrue for found, EFalse for not found
316 TBool CDataWrapperBase::GetCommandStringParameterL(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult)
320 if ( aSectName.Length()!=0 )
322 ret=CDataWrapper::GetStringFromConfig(aSectName, aKeyName, aResult);
324 for ( TInt index=iInclude.Count(); (index>0) && (!ret); )
326 ret=iInclude[--index]->FindVar(aSectName, aKeyName, aResult);
332 if ( aResult.Match(KMatch)!=KErrNotFound )
334 // We have an entry of the format
335 // entry =*{section,entry}*
336 // where * is one or more characters
337 // We need to construct this from other data in the ini file replacing {*,*}
338 // with the data from
341 HBufC* buffer=HBufC::NewLC(aResult.Length());
342 buffer->Des().Copy(aResult);
344 TInt startLength=KStart().Length();
345 TInt sparatorLength=KSeparator().Length();
346 TInt endLength=KEnd().Length();
355 bufferLength=buffer->Length();
356 start=buffer->Find(KStart);
358 remaining.Set(buffer->Des().Right(bufferLength-start-startLength));
359 sparator=remaining.Find(KSeparator);
360 remaining.Set(remaining.Right(remaining.Length()-sparator-sparatorLength));
361 sparator += (start + startLength);
363 end=remaining.Find(KEnd) + sparator + sparatorLength;
365 TPtrC sectionName(buffer->Ptr()+start+startLength, sparator-start-startLength);
366 TPtrC keyName(buffer->Ptr()+sparator+sparatorLength, end-sparator-sparatorLength);
367 sectionName.Set(TLex(sectionName).NextToken());
368 keyName.Set(TLex(keyName).NextToken());
372 TBool found=CDataWrapper::GetStringFromConfig(sectionName, keyName, entryData);
373 for ( TInt index=iInclude.Count(); (index>0) && (!found); )
375 found=iInclude[--index]->FindVar(sectionName, keyName, entryData);
379 entrySize=entryData.Length();
382 TInt newLength=start + bufferLength - end - endLength + entrySize;
383 HBufC* bufferNew=HBufC::NewLC(newLength);
384 bufferNew->Des().Copy(buffer->Ptr(), start);
387 bufferNew->Des().Append(entryData);
389 bufferNew->Des().Append(buffer->Ptr() + end + endLength, bufferLength - end - endLength);
390 CleanupStack::Pop(bufferNew);
391 CleanupStack::PopAndDestroy(buffer);
393 CleanupStack::PushL(buffer);
395 while ( buffer->Match(KMatch)!=KErrNotFound );
396 iBuffer.Append(buffer);
397 CleanupStack::Pop(buffer);
398 aResult.Set(*buffer);
399 INFO_PRINTF4(KDataRead, &aSectName, &aKeyName , &aResult);
407 * Utility function to produce time delay
408 * @param aTimeoutInSecs Times in micro seconds
410 void CDataWrapperBase::Timedelay(TInt aTimeoutInSecs)
412 TRequestStatus status;
413 iTimer.After(status, aTimeoutInSecs);
414 User::WaitForRequest(status);
417 TBool CDataWrapperBase::GetEnumFromConfig(const TDesC& aSectName, const TDesC& aKeyName, const TEnumEntryTable* aTable, TInt& aResult)
420 TBool ret=GetStringFromConfig(aSectName, aKeyName, str);
426 while ( (aTable[index].iValue!=-1) && !found )
428 if ( aTable[index].iString==str )
431 aResult=aTable[index].iValue;
441 ret=GetIntFromConfig(aSectName, aKeyName, aResult);