24
|
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 |
/*@{*/
|
|
21 |
/// Constant Literals used.
|
|
22 |
_LIT(KPrefixHex, "0x");
|
|
23 |
_LIT(KPrefixOctal, "0");
|
|
24 |
_LIT(KSuffixBinary, "b");
|
|
25 |
|
|
26 |
_LIT(KIncludeSection, "include");
|
|
27 |
_LIT(KFile, "file%d");
|
|
28 |
_LIT(KMatch, "*{*,*}*");
|
|
29 |
_LIT(KStart, "{");
|
|
30 |
_LIT(KSeparator, ",");
|
|
31 |
_LIT(KEnd, "}");
|
|
32 |
_LIT(KDataRead, "INI READ : %S %S %S");
|
|
33 |
|
|
34 |
/*@}*/
|
|
35 |
|
|
36 |
CDataWrapperBase::CDataWrapperBase()
|
|
37 |
: CDataWrapper()
|
|
38 |
{
|
|
39 |
}
|
|
40 |
|
|
41 |
/**
|
|
42 |
* Public destructor
|
|
43 |
*/
|
|
44 |
CDataWrapperBase::~CDataWrapperBase()
|
|
45 |
{
|
|
46 |
iInclude.ResetAndDestroy();
|
|
47 |
iBuffer.ResetAndDestroy();
|
|
48 |
iFs.Close();
|
|
49 |
}
|
|
50 |
|
|
51 |
void CDataWrapperBase::InitialiseL()
|
|
52 |
{
|
|
53 |
iTimer.CreateLocal();
|
|
54 |
CDataWrapper::InitialiseL();
|
|
55 |
TBuf<KMaxTestExecuteCommandLength> tempStore;
|
|
56 |
TPtrC fileName;
|
|
57 |
TBool moreData=ETrue;
|
|
58 |
TBool index=0;
|
|
59 |
while ( moreData )
|
|
60 |
{
|
|
61 |
tempStore.Format(KFile(), ++index);
|
|
62 |
moreData=GetStringFromConfig(KIncludeSection, tempStore, fileName);
|
|
63 |
|
|
64 |
if (moreData)
|
|
65 |
{
|
|
66 |
CIniData* iniData=CIniData::NewL(fileName);
|
|
67 |
CleanupStack::PushL(iniData);
|
|
68 |
iInclude.Append(iniData);
|
|
69 |
CleanupStack::Pop(iniData);
|
|
70 |
}
|
|
71 |
}
|
|
72 |
User::LeaveIfError(iFs.Connect());
|
|
73 |
}
|
|
74 |
|
|
75 |
/**
|
|
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
|
|
82 |
*/
|
|
83 |
TBool CDataWrapperBase::GetBoolFromConfig(const TDesC& aSectName,const TDesC& aKeyName,TBool& aResult)
|
|
84 |
{
|
|
85 |
TBool ret=EFalse;
|
|
86 |
TPtrC result;
|
|
87 |
TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
|
|
88 |
if ( err != KErrNone )
|
|
89 |
{
|
|
90 |
ret=EFalse;
|
|
91 |
}
|
|
92 |
if ( ret )
|
|
93 |
{
|
|
94 |
_LIT(KTrue,"true");
|
|
95 |
aResult=(result.FindF(KTrue) != KErrNotFound);
|
|
96 |
}
|
|
97 |
|
|
98 |
return ret;
|
|
99 |
}
|
|
100 |
|
|
101 |
/**
|
|
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
|
|
108 |
*/
|
|
109 |
TBool CDataWrapperBase::GetIntFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult)
|
|
110 |
{
|
|
111 |
TPtrC result;
|
|
112 |
TBool ret=EFalse;
|
|
113 |
TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
|
|
114 |
if ( err != KErrNone )
|
|
115 |
{
|
|
116 |
ret=EFalse;
|
|
117 |
}
|
|
118 |
if ( ret )
|
|
119 |
{
|
|
120 |
TLex lex(result);
|
|
121 |
ret=(lex.Val(aResult)==KErrNone);
|
|
122 |
}
|
|
123 |
|
|
124 |
return ret;
|
|
125 |
}
|
|
126 |
|
|
127 |
/**
|
|
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
|
|
134 |
*/
|
|
135 |
TBool CDataWrapperBase::GetStringFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult)
|
|
136 |
{
|
|
137 |
TBool ret=EFalse;
|
|
138 |
TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, aResult));
|
|
139 |
if ( err != KErrNone )
|
|
140 |
{
|
|
141 |
ret=EFalse;
|
|
142 |
}
|
|
143 |
return ret;
|
|
144 |
}
|
|
145 |
|
|
146 |
/**
|
|
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
|
|
153 |
*/
|
|
154 |
TBool CDataWrapperBase::GetHexFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult)
|
|
155 |
{
|
|
156 |
TPtrC result;
|
|
157 |
TBool ret=EFalse;
|
|
158 |
TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
|
|
159 |
if ( err != KErrNone )
|
|
160 |
{
|
|
161 |
ret=EFalse;
|
|
162 |
}
|
|
163 |
if ( ret )
|
|
164 |
{
|
|
165 |
TLex lex;
|
|
166 |
if( result.FindC(KPrefixHex)==KErrNone )
|
|
167 |
{
|
|
168 |
lex=result.Mid(KPrefixHex().Length());
|
|
169 |
}
|
|
170 |
else
|
|
171 |
{
|
|
172 |
lex=result;
|
|
173 |
}
|
|
174 |
ret=(lex.Val((TUint &)aResult, EHex)==KErrNone);
|
|
175 |
}
|
|
176 |
|
|
177 |
return ret;
|
|
178 |
}
|
|
179 |
|
|
180 |
/**
|
|
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 hexadecimal 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
|
|
191 |
*/
|
|
192 |
TBool CDataWrapperBase::GetUintFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TUint& aResult)
|
|
193 |
{
|
|
194 |
TPtrC result;
|
|
195 |
TBool ret=EFalse;
|
|
196 |
TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
|
|
197 |
if ( err != KErrNone )
|
|
198 |
{
|
|
199 |
ret=EFalse;
|
|
200 |
}
|
|
201 |
if ( ret )
|
|
202 |
{
|
|
203 |
TLex lex(result);
|
|
204 |
if( result.FindC(KPrefixHex)==KErrNone )
|
|
205 |
{
|
|
206 |
lex=result.Mid(KPrefixHex().Length());
|
|
207 |
ret=(lex.Val(aResult, EHex)==KErrNone);
|
|
208 |
}
|
|
209 |
else
|
|
210 |
{
|
|
211 |
TInt binarySuffixPosition=result.Length()-KSuffixBinary().Length();
|
|
212 |
if ( result.FindC(KSuffixBinary)==binarySuffixPosition )
|
|
213 |
{
|
|
214 |
lex=result.Left(binarySuffixPosition);
|
|
215 |
ret=(lex.Val(aResult, EBinary)==KErrNone);
|
|
216 |
}
|
|
217 |
else
|
|
218 |
{
|
|
219 |
if( result.FindC(KPrefixOctal)==KErrNone )
|
|
220 |
{
|
|
221 |
ret=(lex.Val(aResult, EOctal)==KErrNone);
|
|
222 |
}
|
|
223 |
else
|
|
224 |
{
|
|
225 |
TInt intResult;
|
|
226 |
ret=(lex.Val(intResult)==KErrNone);
|
|
227 |
if ( ret )
|
|
228 |
{
|
|
229 |
aResult=(TUint)intResult;
|
|
230 |
}
|
|
231 |
}
|
|
232 |
}
|
|
233 |
}
|
|
234 |
}
|
|
235 |
|
|
236 |
return ret;
|
|
237 |
}
|
|
238 |
|
|
239 |
TBool CDataWrapperBase::GetCommandStringParameterL(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult)
|
|
240 |
{
|
|
241 |
TBool ret=EFalse;
|
|
242 |
|
|
243 |
if ( aSectName.Length()!=0 )
|
|
244 |
{
|
|
245 |
ret=CDataWrapper::GetStringFromConfig(aSectName, aKeyName, aResult);
|
|
246 |
|
|
247 |
for ( TInt index=iInclude.Count(); (index>0) && (!ret); )
|
|
248 |
{
|
|
249 |
ret=iInclude[--index]->FindVar(aSectName, aKeyName, aResult);
|
|
250 |
}
|
|
251 |
}
|
|
252 |
|
|
253 |
if ( ret )
|
|
254 |
{
|
|
255 |
if ( aResult.Match(KMatch)!=KErrNotFound )
|
|
256 |
{
|
|
257 |
// We have an entry of the format
|
|
258 |
// entry =*{section,entry}*
|
|
259 |
// where * is one or more characters
|
|
260 |
// We need to construct this from other data in the ini file replacing {*,*}
|
|
261 |
// with the data from
|
|
262 |
// [section]
|
|
263 |
// entry =some_value
|
|
264 |
HBufC* buffer=HBufC::NewLC(aResult.Length());
|
|
265 |
buffer->Des().Copy(aResult);
|
|
266 |
|
|
267 |
TInt startLength=KStart().Length();
|
|
268 |
TInt sparatorLength=KSeparator().Length();
|
|
269 |
TInt endLength=KEnd().Length();
|
|
270 |
TInt bufferLength;
|
|
271 |
TInt start;
|
|
272 |
TInt sparator;
|
|
273 |
TInt end;
|
|
274 |
TPtrC remaining;
|
|
275 |
TLex lex;
|
|
276 |
do
|
|
277 |
{
|
|
278 |
bufferLength=buffer->Length();
|
|
279 |
start=buffer->Find(KStart);
|
|
280 |
|
|
281 |
remaining.Set(buffer->Des().Right(bufferLength-start-startLength));
|
|
282 |
sparator=remaining.Find(KSeparator);
|
|
283 |
remaining.Set(remaining.Right(remaining.Length()-sparator-sparatorLength));
|
|
284 |
sparator += (start + startLength);
|
|
285 |
|
|
286 |
end=remaining.Find(KEnd) + sparator + sparatorLength;
|
|
287 |
|
|
288 |
TPtrC sectionName(buffer->Ptr()+start+startLength, sparator-start-startLength);
|
|
289 |
TPtrC keyName(buffer->Ptr()+sparator+sparatorLength, end-sparator-sparatorLength);
|
|
290 |
sectionName.Set(TLex(sectionName).NextToken());
|
|
291 |
keyName.Set(TLex(keyName).NextToken());
|
|
292 |
|
|
293 |
TInt entrySize=0;
|
|
294 |
TPtrC entryData;
|
|
295 |
TBool found=CDataWrapper::GetStringFromConfig(sectionName, keyName, entryData);
|
|
296 |
for ( TInt index=iInclude.Count(); (index>0) && (!found); )
|
|
297 |
{
|
|
298 |
found=iInclude[--index]->FindVar(sectionName, keyName, entryData);
|
|
299 |
}
|
|
300 |
if ( found )
|
|
301 |
{
|
|
302 |
entrySize=entryData.Length();
|
|
303 |
}
|
|
304 |
|
|
305 |
TInt newLength=start + bufferLength - end - endLength + entrySize;
|
|
306 |
HBufC* bufferNew=HBufC::NewLC(newLength);
|
|
307 |
bufferNew->Des().Copy(buffer->Ptr(), start);
|
|
308 |
if ( entrySize>0 )
|
|
309 |
{
|
|
310 |
bufferNew->Des().Append(entryData);
|
|
311 |
}
|
|
312 |
bufferNew->Des().Append(buffer->Ptr() + end + endLength, bufferLength - end - endLength);
|
|
313 |
CleanupStack::Pop(bufferNew);
|
|
314 |
CleanupStack::PopAndDestroy(buffer);
|
|
315 |
buffer=bufferNew;
|
|
316 |
CleanupStack::PushL(buffer);
|
|
317 |
}
|
|
318 |
while ( buffer->Match(KMatch)!=KErrNotFound );
|
|
319 |
iBuffer.Append(buffer);
|
|
320 |
CleanupStack::Pop(buffer);
|
|
321 |
aResult.Set(*buffer);
|
|
322 |
INFO_PRINTF4(KDataRead, &aSectName, &aKeyName , &aResult);
|
|
323 |
}
|
|
324 |
}
|
|
325 |
|
|
326 |
return ret;
|
|
327 |
}
|
|
328 |
|
|
329 |
|
|
330 |
/**
|
|
331 |
*Utility function to produce time delay
|
|
332 |
* @param aTimeoutInSecs Times in micro seconds
|
|
333 |
*/
|
|
334 |
void CDataWrapperBase::Timedelay(TInt aTimeoutInSecs)
|
|
335 |
{
|
|
336 |
TRequestStatus status;
|
|
337 |
iTimer.After(status, aTimeoutInSecs);
|
|
338 |
User::WaitForRequest(status);
|
|
339 |
}
|
|
340 |
|
|
341 |
|
|
342 |
/**
|
|
343 |
* Return array of string parameters i.e. key=a1,a2,a3 returns array which contains
|
|
344 |
* String a1, a2 and a3.
|
|
345 |
* @return ret - EFalse if can't get a String parameter from Config file. ETrue if KErrNone
|
|
346 |
*/
|
|
347 |
TBool CDataWrapperBase::GetArrayFromConfig(const TDesC& aSectName, const TDesC& aKeyName, RPointerArray<HBufC>& aResult)
|
|
348 |
{
|
|
349 |
TBool ret=EFalse;
|
|
350 |
TPtrC completeArray;
|
|
351 |
|
|
352 |
TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, completeArray));
|
|
353 |
if ( err != KErrNone )
|
|
354 |
{
|
|
355 |
ret=EFalse;
|
|
356 |
}
|
|
357 |
|
|
358 |
TLex16 lex(completeArray); // Here we have the array as a string i.e. "a1,a2,a3"
|
|
359 |
TBuf<256> buf;
|
|
360 |
TChar chr;
|
|
361 |
|
|
362 |
while(!lex.Eos())
|
|
363 |
{
|
|
364 |
chr = lex.Get();
|
|
365 |
// Check if there was a list separator
|
|
366 |
if (chr == ',')
|
|
367 |
{
|
|
368 |
HBufC* param = buf.AllocLC();
|
|
369 |
buf.Zero();
|
|
370 |
aResult.Append(param);
|
|
371 |
CleanupStack::Pop(param); // pointer to buf is stored in RPointerArray
|
|
372 |
}
|
|
373 |
// If not separator character we can store the character into array
|
|
374 |
else
|
|
375 |
{
|
|
376 |
buf.Append(chr);
|
|
377 |
}
|
|
378 |
}
|
|
379 |
// Remember to put last token into array (,a3)
|
|
380 |
HBufC* param = buf.AllocLC();
|
|
381 |
aResult.Append(param);
|
|
382 |
CleanupStack::Pop(param);
|
|
383 |
|
|
384 |
return ret;
|
|
385 |
}
|
|
386 |
|
|
387 |
|
|
388 |
TBool CDataWrapperBase::GetEnumFromConfig(const TDesC& aSectName, const TDesC& aKeyName, const TEnumEntryTable* aTable, TInt& aResult)
|
|
389 |
{
|
|
390 |
TPtrC str;
|
|
391 |
TBool ret=GetStringFromConfig(aSectName, aKeyName, str);
|
|
392 |
|
|
393 |
if ( ret )
|
|
394 |
{
|
|
395 |
TBool found=EFalse;
|
|
396 |
TInt index=0;
|
|
397 |
while ( (aTable[index].iValue!=-1) && !found )
|
|
398 |
{
|
|
399 |
if ( aTable[index].iString==str )
|
|
400 |
{
|
|
401 |
found=ETrue;
|
|
402 |
aResult=aTable[index].iValue;
|
|
403 |
}
|
|
404 |
else
|
|
405 |
{
|
|
406 |
++index;
|
|
407 |
}
|
|
408 |
}
|
|
409 |
|
|
410 |
if ( !found )
|
|
411 |
{
|
|
412 |
ret=GetIntFromConfig(aSectName, aKeyName, aResult);
|
|
413 |
}
|
|
414 |
}
|
|
415 |
|
|
416 |
return ret;
|
|
417 |
}
|
|
418 |
|