sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "TestStepV2.h"
|
sl@0
|
20 |
|
sl@0
|
21 |
/*@{*/
|
sl@0
|
22 |
/// Constant Literals used.
|
sl@0
|
23 |
_LIT(KIncludeSection, "include");
|
sl@0
|
24 |
_LIT(KFile, "file%d");
|
sl@0
|
25 |
_LIT(KMatch, "*{*,*}*");
|
sl@0
|
26 |
_LIT(KStart, "{");
|
sl@0
|
27 |
_LIT(KSeparator, ",");
|
sl@0
|
28 |
_LIT(KEnd, "}");
|
sl@0
|
29 |
_LIT(KDataRead, "INI READ : %S %S %S");
|
sl@0
|
30 |
/*@}*/
|
sl@0
|
31 |
|
sl@0
|
32 |
CTestStepV2::CTestStepV2()
|
sl@0
|
33 |
: CTestStep()
|
sl@0
|
34 |
{
|
sl@0
|
35 |
}
|
sl@0
|
36 |
|
sl@0
|
37 |
CTestStepV2::~CTestStepV2()
|
sl@0
|
38 |
{
|
sl@0
|
39 |
iInclude.ResetAndDestroy();
|
sl@0
|
40 |
iBuffer.ResetAndDestroy();
|
sl@0
|
41 |
}
|
sl@0
|
42 |
|
sl@0
|
43 |
enum TVerdict CTestStepV2::doTestStepPreambleL()
|
sl@0
|
44 |
{
|
sl@0
|
45 |
TBuf<KMaxTestExecuteCommandLength> tempStore;
|
sl@0
|
46 |
|
sl@0
|
47 |
TVerdict ret=CTestStep::doTestStepPreambleL();
|
sl@0
|
48 |
TPtrC fileName;
|
sl@0
|
49 |
TBool moreData=ETrue;
|
sl@0
|
50 |
TBool index=0;
|
sl@0
|
51 |
while ( moreData )
|
sl@0
|
52 |
{
|
sl@0
|
53 |
tempStore.Format(KFile(), ++index);
|
sl@0
|
54 |
moreData=GetStringFromConfig(KIncludeSection, tempStore, fileName);
|
sl@0
|
55 |
if ( moreData )
|
sl@0
|
56 |
{
|
sl@0
|
57 |
CIniData* iniData=CIniData::NewL(fileName);
|
sl@0
|
58 |
CleanupStack::PushL(iniData);
|
sl@0
|
59 |
iInclude.Append(iniData);
|
sl@0
|
60 |
CleanupStack::Pop(iniData);
|
sl@0
|
61 |
}
|
sl@0
|
62 |
}
|
sl@0
|
63 |
|
sl@0
|
64 |
return ret;
|
sl@0
|
65 |
}
|
sl@0
|
66 |
|
sl@0
|
67 |
TBool CTestStepV2::GetBoolFromConfig(const TDesC& aSectName,const TDesC& aKeyName,TBool& aResult)
|
sl@0
|
68 |
{
|
sl@0
|
69 |
TPtrC result;
|
sl@0
|
70 |
TBool ret=EFalse;
|
sl@0
|
71 |
TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
|
sl@0
|
72 |
if ( err != KErrNone )
|
sl@0
|
73 |
{
|
sl@0
|
74 |
ret=EFalse;
|
sl@0
|
75 |
}
|
sl@0
|
76 |
if ( ret )
|
sl@0
|
77 |
{
|
sl@0
|
78 |
_LIT(KTrue,"true");
|
sl@0
|
79 |
aResult=(result.FindF(KTrue) != KErrNotFound);
|
sl@0
|
80 |
}
|
sl@0
|
81 |
return ret;
|
sl@0
|
82 |
}
|
sl@0
|
83 |
|
sl@0
|
84 |
TBool CTestStepV2::GetIntFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult)
|
sl@0
|
85 |
{
|
sl@0
|
86 |
TPtrC result;
|
sl@0
|
87 |
TBool ret=EFalse;
|
sl@0
|
88 |
TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
|
sl@0
|
89 |
if ( err != KErrNone )
|
sl@0
|
90 |
{
|
sl@0
|
91 |
ret=EFalse;
|
sl@0
|
92 |
}
|
sl@0
|
93 |
if ( ret )
|
sl@0
|
94 |
{
|
sl@0
|
95 |
TLex lex(result);
|
sl@0
|
96 |
ret=(lex.Val(aResult)==KErrNone);
|
sl@0
|
97 |
}
|
sl@0
|
98 |
|
sl@0
|
99 |
return ret;
|
sl@0
|
100 |
}
|
sl@0
|
101 |
|
sl@0
|
102 |
TBool CTestStepV2::GetStringFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult)
|
sl@0
|
103 |
{
|
sl@0
|
104 |
TBool ret=EFalse;
|
sl@0
|
105 |
TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, aResult));
|
sl@0
|
106 |
if ( err != KErrNone )
|
sl@0
|
107 |
{
|
sl@0
|
108 |
ret=EFalse;
|
sl@0
|
109 |
}
|
sl@0
|
110 |
return ret;
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
TBool CTestStepV2::GetHexFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
TPtrC result;
|
sl@0
|
116 |
TBool ret=EFalse;
|
sl@0
|
117 |
TRAPD(err, ret=GetCommandStringParameterL(aSectName, aKeyName, result));
|
sl@0
|
118 |
if ( err != KErrNone )
|
sl@0
|
119 |
{
|
sl@0
|
120 |
ret=EFalse;
|
sl@0
|
121 |
}
|
sl@0
|
122 |
if ( ret )
|
sl@0
|
123 |
{
|
sl@0
|
124 |
TLex lex(result);
|
sl@0
|
125 |
ret=(lex.Val((TUint &)aResult, EHex)==KErrNone);
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
return ret;
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
TBool CTestStepV2::GetCommandStringParameterL(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult)
|
sl@0
|
132 |
{
|
sl@0
|
133 |
TBool ret=CTestStep::GetStringFromConfig(aSectName, aKeyName, aResult);
|
sl@0
|
134 |
|
sl@0
|
135 |
for ( TInt index=iInclude.Count(); (index>0) && (!ret); )
|
sl@0
|
136 |
{
|
sl@0
|
137 |
ret=iInclude[--index]->FindVar(aSectName, aKeyName, aResult);
|
sl@0
|
138 |
}
|
sl@0
|
139 |
|
sl@0
|
140 |
if ( ret )
|
sl@0
|
141 |
{
|
sl@0
|
142 |
if ( aResult.Match(KMatch)!=KErrNotFound )
|
sl@0
|
143 |
{
|
sl@0
|
144 |
// We have an entry of the format
|
sl@0
|
145 |
// entry =*{section,entry}*
|
sl@0
|
146 |
// where * is one or more characters
|
sl@0
|
147 |
// We need to construct this from other data in the ini file replacing {*,*}
|
sl@0
|
148 |
// with the data from
|
sl@0
|
149 |
// [section]
|
sl@0
|
150 |
// entry =some_value
|
sl@0
|
151 |
HBufC* buffer=HBufC::NewLC(aResult.Length());
|
sl@0
|
152 |
buffer->Des().Copy(aResult);
|
sl@0
|
153 |
|
sl@0
|
154 |
TInt startLength=KStart().Length();
|
sl@0
|
155 |
TInt sparatorLength=KSeparator().Length();
|
sl@0
|
156 |
TInt endLength=KEnd().Length();
|
sl@0
|
157 |
TInt bufferLength;
|
sl@0
|
158 |
TInt start;
|
sl@0
|
159 |
TInt sparator;
|
sl@0
|
160 |
TInt end;
|
sl@0
|
161 |
TPtrC remaining;
|
sl@0
|
162 |
TLex lex;
|
sl@0
|
163 |
do
|
sl@0
|
164 |
{
|
sl@0
|
165 |
bufferLength=buffer->Length();
|
sl@0
|
166 |
start=buffer->Find(KStart);
|
sl@0
|
167 |
|
sl@0
|
168 |
remaining.Set(buffer->Des().Right(bufferLength-start-startLength));
|
sl@0
|
169 |
sparator=remaining.Find(KSeparator);
|
sl@0
|
170 |
remaining.Set(remaining.Right(remaining.Length()-sparator-sparatorLength));
|
sl@0
|
171 |
sparator += (start + startLength);
|
sl@0
|
172 |
|
sl@0
|
173 |
end=remaining.Find(KEnd) + sparator + sparatorLength;
|
sl@0
|
174 |
|
sl@0
|
175 |
TPtrC sectionName(buffer->Ptr()+start+startLength, sparator-start-startLength);
|
sl@0
|
176 |
TPtrC keyName(buffer->Ptr()+sparator+sparatorLength, end-sparator-sparatorLength);
|
sl@0
|
177 |
sectionName.Set(TLex(sectionName).NextToken());
|
sl@0
|
178 |
keyName.Set(TLex(keyName).NextToken());
|
sl@0
|
179 |
|
sl@0
|
180 |
TInt entrySize=0;
|
sl@0
|
181 |
TPtrC entryData;
|
sl@0
|
182 |
TBool found=CTestStep::GetStringFromConfig(sectionName, keyName, entryData);
|
sl@0
|
183 |
for ( TInt index=iInclude.Count(); (index>0) && (!found); )
|
sl@0
|
184 |
{
|
sl@0
|
185 |
found=iInclude[--index]->FindVar(sectionName, keyName, entryData);
|
sl@0
|
186 |
}
|
sl@0
|
187 |
if ( found )
|
sl@0
|
188 |
{
|
sl@0
|
189 |
entrySize=entryData.Length();
|
sl@0
|
190 |
}
|
sl@0
|
191 |
|
sl@0
|
192 |
TInt newLength=start + bufferLength - end - endLength + entrySize;
|
sl@0
|
193 |
HBufC* bufferNew=HBufC::NewLC(newLength);
|
sl@0
|
194 |
bufferNew->Des().Copy(buffer->Ptr(), start);
|
sl@0
|
195 |
if ( entrySize>0 )
|
sl@0
|
196 |
{
|
sl@0
|
197 |
bufferNew->Des().Append(entryData);
|
sl@0
|
198 |
}
|
sl@0
|
199 |
bufferNew->Des().Append(buffer->Ptr() + end + endLength, bufferLength - end - endLength);
|
sl@0
|
200 |
CleanupStack::Pop(bufferNew);
|
sl@0
|
201 |
CleanupStack::PopAndDestroy(buffer);
|
sl@0
|
202 |
buffer=bufferNew;
|
sl@0
|
203 |
CleanupStack::PushL(buffer);
|
sl@0
|
204 |
}
|
sl@0
|
205 |
while ( buffer->Match(KMatch)!=KErrNotFound );
|
sl@0
|
206 |
iBuffer.Append(buffer);
|
sl@0
|
207 |
CleanupStack::Pop(buffer);
|
sl@0
|
208 |
aResult.Set(*buffer);
|
sl@0
|
209 |
INFO_PRINTF4(KDataRead, &aSectName, &aKeyName , &aResult);
|
sl@0
|
210 |
}
|
sl@0
|
211 |
}
|
sl@0
|
212 |
|
sl@0
|
213 |
return ret;
|
sl@0
|
214 |
}
|