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