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