First public contribution.
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.
18 #include "datawrapperbase.h"
21 /// Constant Literals used.
22 _LIT(KPrefixHex,"0x");
23 _LIT(KPrefixOctal,"0");
24 _LIT(KSuffixBinary, "b");
26 _LIT(KIncludeSection, "include");
27 _LIT(KFile, "file%d");
28 _LIT(KMatch, "*{*,*}*");
30 _LIT(KSeparator, ",");
32 _LIT(KDataRead, "INI READ : %S %S %S");
36 CDataWrapperBase::CDataWrapperBase()
44 CDataWrapperBase::~CDataWrapperBase()
46 iInclude.ResetAndDestroy();
47 iBuffer.ResetAndDestroy();
51 void CDataWrapperBase::InitialiseL()
54 CDataWrapper::InitialiseL();
55 TBuf<KMaxTestExecuteCommandLength> tempStore;
61 tempStore.Format(KFile(), ++index);
62 moreData=GetStringFromConfig(KIncludeSection, tempStore, fileName);
66 CIniData* iniData=CIniData::NewL(fileName);
67 CleanupStack::PushL(iniData);
68 iInclude.Append(iniData);
69 CleanupStack::Pop(iniData);
72 User::LeaveIfError(iFs.Connect());
76 * Reads the value present from the test steps ini file within the mentioned section name and key name
77 * Copies the value to the TBool reference passed in possible values TRUE, FALSE
78 * @param aSectName - Section within the test steps ini file
79 * @param aKeyName - Name of a key within a section
80 * @return aResult - The value of the boolean
81 * @return TBool - ETrue for found, EFalse for not found
83 TBool CDataWrapperBase::GetBoolFromConfig(const TDesC& aSectName,const TDesC& aKeyName,TBool& aResult)
87 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
88 if ( err != KErrNone )
95 aResult=(result.FindF(KTrue) != KErrNotFound);
102 * Reads the value present from the test steps ini file within the mentioned section name and key name
103 * Copies the value to the TInt reference passed in
104 * @param aSectName - Section within the test steps ini file
105 * @param aKeyName - Name of a key within a section
106 * @return aResult - The value of the integer
107 * @return TBool - ETrue for found, EFalse for not found
109 TBool CDataWrapperBase::GetIntFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult)
113 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
114 if ( err != KErrNone )
121 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 TPtrC 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 - Reference to the string on the heap
133 * @return TBool - ETrue for found, EFalse for not found
135 TBool CDataWrapperBase::GetStringFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult)
138 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, aResult));
139 if ( err != KErrNone )
147 * Reads the value present from the test steps ini file within the mentioned section name and key name
148 * Copies the value to the TInt reference passed in. The value can optionally be prefixed with 0x
149 * @param aSectName - Section within the test steps ini file
150 * @param aKeyName - Name of a key within a section
151 * @return aResult - The integer value of the Hex input
152 * @return TBool - ETrue for found, EFalse for not found
154 TBool CDataWrapperBase::GetHexFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult)
158 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
159 if ( err != KErrNone )
166 if( result.FindC(KPrefixHex)==KErrNone )
168 lex=result.Mid(KPrefixHex().Length());
174 ret=(lex.Val((TUint &)aResult, EHex)==KErrNone);
181 * Reads the value present from the test steps ini file within the mentioned section name and key name
182 * Copies the value to the TUint reference passed in.
183 * If the value is prefixed with 0x the value is read as a hexidecimal value
184 * If the value is suffixed with b the value is read as a binary value
185 * If the value is prefixed with a 0 the value is read as an octal value
186 * If it does not match the above it is read in as an integer
187 * @param aSectName - Section within the test steps ini file
188 * @param aKeyName - Name of a key within a section
189 * @return aResult - The integer value of the Hex input
190 * @return TBool - ETrue for found, EFalse for not found
192 TBool CDataWrapperBase::GetUintFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TUint& aResult)
196 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
197 if ( err != KErrNone )
204 if( result.FindC(KPrefixHex)==KErrNone )
206 lex=result.Mid(KPrefixHex().Length());
207 ret=(lex.Val(aResult, EHex)==KErrNone);
211 TInt binarySuffixPosition=result.Length()-KSuffixBinary().Length();
212 if ( result.FindC(KSuffixBinary)==binarySuffixPosition )
214 lex=result.Left(binarySuffixPosition);
215 ret=(lex.Val(aResult, EBinary)==KErrNone);
219 if( result.FindC(KPrefixOctal)==KErrNone )
221 ret=(lex.Val(aResult, EOctal)==KErrNone);
226 ret=(lex.Val(intResult)==KErrNone);
229 aResult=(TUint)intResult;
240 * Return array of string parameters i.e. key=a1,a2,a3 returns array which contains
241 * String a1, a2 and a3.
242 * @return ret - EFalse if can't get a String parameter from Config file. ETrue if KErrNone
244 TBool CDataWrapperBase::GetArrayRectFromConfig(const TDesC& aSectName, const TDesC& aKeyName, RPointerArray<HBufC>& aResult)
249 TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, completeArray));
250 if ( err != KErrNone )
255 TLex16 lex(completeArray); // Here we have the array as a string i.e. "a1,a2,a3"
262 // Check if there was a list separator
263 if ((chr == ',') && (lex.Peek() == '('))
265 HBufC* param = buf.AllocLC();
267 aResult.Append(param);
268 CleanupStack::Pop(param); // pointer to buf is stored in RPointerArray
270 // If not separator character we can store the character into array
276 // Remember to put last token into array (,a3)
277 HBufC* param = buf.AllocLC();
278 aResult.Append(param);
279 CleanupStack::Pop(param);
285 * Reads the parameter asociated to the specified command
286 * @param aSectName Section on ini file
287 * @param aKeyName Name of the parameter
288 * @param aResult descriptor containing parameter
289 * @return TBool ETrue for found, EFalse for not found
291 TBool CDataWrapperBase::GetCommandStringParameterL(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult)
295 if ( aSectName.Length()!=0 )
297 ret=CDataWrapper::GetStringFromConfig(aSectName, aKeyName, aResult);
299 for ( TInt index=iInclude.Count(); (index>0) && (!ret); )
301 ret=iInclude[--index]->FindVar(aSectName, aKeyName, aResult);
307 if ( aResult.Match(KMatch)!=KErrNotFound )
309 // We have an entry of the format
310 // entry =*{section,entry}*
311 // where * is one or more characters
312 // We need to construct this from other data in the ini file replacing {*,*}
313 // with the data from
316 HBufC* buffer=HBufC::NewLC(aResult.Length());
317 buffer->Des().Copy(aResult);
319 TInt startLength=KStart().Length();
320 TInt sparatorLength=KSeparator().Length();
321 TInt endLength=KEnd().Length();
330 bufferLength=buffer->Length();
331 start=buffer->Find(KStart);
333 remaining.Set(buffer->Des().Right(bufferLength-start-startLength));
334 sparator=remaining.Find(KSeparator);
335 remaining.Set(remaining.Right(remaining.Length()-sparator-sparatorLength));
336 sparator += (start + startLength);
338 end=remaining.Find(KEnd) + sparator + sparatorLength;
340 TPtrC sectionName(buffer->Ptr()+start+startLength, sparator-start-startLength);
341 TPtrC keyName(buffer->Ptr()+sparator+sparatorLength, end-sparator-sparatorLength);
342 sectionName.Set(TLex(sectionName).NextToken());
343 keyName.Set(TLex(keyName).NextToken());
347 TBool found=CDataWrapper::GetStringFromConfig(sectionName, keyName, entryData);
348 for ( TInt index=iInclude.Count(); (index>0) && (!found); )
350 found=iInclude[--index]->FindVar(sectionName, keyName, entryData);
354 entrySize=entryData.Length();
357 TInt newLength=start + bufferLength - end - endLength + entrySize;
358 HBufC* bufferNew=HBufC::NewLC(newLength);
359 bufferNew->Des().Copy(buffer->Ptr(), start);
362 bufferNew->Des().Append(entryData);
364 bufferNew->Des().Append(buffer->Ptr() + end + endLength, bufferLength - end - endLength);
365 CleanupStack::Pop(bufferNew);
366 CleanupStack::PopAndDestroy(buffer);
368 CleanupStack::PushL(buffer);
370 while ( buffer->Match(KMatch)!=KErrNotFound );
371 iBuffer.Append(buffer);
372 CleanupStack::Pop(buffer);
373 aResult.Set(*buffer);
374 INFO_PRINTF4(KDataRead, &aSectName, &aKeyName , &aResult);
381 TBool CDataWrapperBase::GetEnumFromConfig(const TDesC& aSectName, const TDesC& aKeyName, const TEnumEntryTable* aTable, TInt& aResult)
384 TBool ret=GetStringFromConfig(aSectName, aKeyName, str);
390 while ( (aTable[index].iValue!=-1) && !found )
392 if ( aTable[index].iString==str )
395 aResult=aTable[index].iValue;
405 ret=GetIntFromConfig(aSectName, aKeyName, aResult);
413 * Utility function to produce time delay
414 * @param aTimeoutInSecs Times in micro seconds
416 void CDataWrapperBase::Timedelay(TInt aTimeoutInSecs)
418 TRequestStatus status;
419 iTimer.After(status, aTimeoutInSecs);
420 User::WaitForRequest(status);