sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2007-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 the License "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 |
* test tool step implementation
|
sl@0
|
16 |
*
|
sl@0
|
17 |
*/
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
/**
|
sl@0
|
21 |
@file
|
sl@0
|
22 |
*/
|
sl@0
|
23 |
|
sl@0
|
24 |
|
sl@0
|
25 |
#include <e32std.h>
|
sl@0
|
26 |
#include "ttesttoolstep.h"
|
sl@0
|
27 |
|
sl@0
|
28 |
_LIT8(KLabel,"label");
|
sl@0
|
29 |
|
sl@0
|
30 |
const TChar KCarriageReturn = '\r';
|
sl@0
|
31 |
const TChar KLineReturn = '\n';
|
sl@0
|
32 |
const TChar KDelemeter = ':';
|
sl@0
|
33 |
|
sl@0
|
34 |
HBufC8* ParseOutputFileLC(const TPtrC& aFileName);
|
sl@0
|
35 |
TInt ReadWordL(const TDesC8& aBuffer, TInt& aPos, TPtrC8& aLine);
|
sl@0
|
36 |
void ConstuctExpectedArrayL(RPointerArray<HBufC>& aArray, const TDesC8& aBuffer,TBool aCheck, TBool aException = EFalse);
|
sl@0
|
37 |
void ResetAndDestroyHBufCList(TAny* aList);
|
sl@0
|
38 |
|
sl@0
|
39 |
//
|
sl@0
|
40 |
// CTestToolListCertStep
|
sl@0
|
41 |
//
|
sl@0
|
42 |
|
sl@0
|
43 |
CTestToolListCertStep::~CTestToolListCertStep()
|
sl@0
|
44 |
{
|
sl@0
|
45 |
|
sl@0
|
46 |
}
|
sl@0
|
47 |
|
sl@0
|
48 |
|
sl@0
|
49 |
CTestToolListCertStep::CTestToolListCertStep()
|
sl@0
|
50 |
{
|
sl@0
|
51 |
// Call base class method to set up the human readable name for logging
|
sl@0
|
52 |
SetTestStepName(KTestToolListCertStep);
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
/**
|
sl@0
|
56 |
* Override of base class virtual. Prepares for the test run of Filetokens
|
sl@0
|
57 |
* @return TVerdict code
|
sl@0
|
58 |
*/
|
sl@0
|
59 |
TVerdict CTestToolListCertStep::doTestStepPreambleL()
|
sl@0
|
60 |
{
|
sl@0
|
61 |
_LIT(KActualOutput, "actualoutput");
|
sl@0
|
62 |
GetStringFromConfig(ConfigSection(), KActualOutput, iActualOutput);
|
sl@0
|
63 |
|
sl@0
|
64 |
// construct name of the cert
|
sl@0
|
65 |
if (GetStringFromConfig(ConfigSection(), KExpectedOwner, iExpectedOwner))
|
sl@0
|
66 |
{
|
sl@0
|
67 |
iOwnerExist = 1;
|
sl@0
|
68 |
}
|
sl@0
|
69 |
if (!GetIntFromConfig(ConfigSection(), KExpectedListStore, iListStoreExist))
|
sl@0
|
70 |
{
|
sl@0
|
71 |
iListStoreExist = 0;
|
sl@0
|
72 |
}
|
sl@0
|
73 |
if(!GetIntFromConfig(ConfigSection(), KStore, iExpectedStore))
|
sl@0
|
74 |
{
|
sl@0
|
75 |
iExpectedStore = -1;
|
sl@0
|
76 |
}
|
sl@0
|
77 |
if(!GetIntFromConfig(ConfigSection(), KExpectedNumLabel, iExpectedNumLabel))
|
sl@0
|
78 |
{
|
sl@0
|
79 |
iExpectedNumLabel = 1;
|
sl@0
|
80 |
}
|
sl@0
|
81 |
if (GetStringFromConfig(ConfigSection(), KExpectedLabel1, iExpectedLabel1))
|
sl@0
|
82 |
{
|
sl@0
|
83 |
iLabel1Exist = 1;
|
sl@0
|
84 |
}
|
sl@0
|
85 |
if (GetStringFromConfig(ConfigSection(), KExpectedLabel2, iExpectedLabel2))
|
sl@0
|
86 |
{
|
sl@0
|
87 |
iLabel2Exist = 1;
|
sl@0
|
88 |
}
|
sl@0
|
89 |
return TestStepResult();
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
/**
|
sl@0
|
93 |
* Override of base class pure virtual
|
sl@0
|
94 |
* Demonstrates reading configuration parameters from an ini file section
|
sl@0
|
95 |
* @return TVerdict code
|
sl@0
|
96 |
*/
|
sl@0
|
97 |
TVerdict CTestToolListCertStep::doTestStepL()
|
sl@0
|
98 |
{
|
sl@0
|
99 |
if (TestStepResult() != EPass)
|
sl@0
|
100 |
{
|
sl@0
|
101 |
return TestStepResult();
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
CActiveScheduler* sched = NULL;
|
sl@0
|
105 |
sched = new (ELeave) CActiveScheduler;
|
sl@0
|
106 |
CleanupStack::PushL(sched);
|
sl@0
|
107 |
CActiveScheduler::Install(sched);
|
sl@0
|
108 |
CTestToolEngine* activeEngine = CTestToolEngine::NewLC();
|
sl@0
|
109 |
|
sl@0
|
110 |
if (iLabel1Exist && !iLabel2Exist)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
iVerdict = activeEngine->ListCerts(iExpectedLabel1, iExpectedNumLabel);
|
sl@0
|
113 |
}
|
sl@0
|
114 |
else if (iLabel2Exist && iLabel1Exist)
|
sl@0
|
115 |
{
|
sl@0
|
116 |
iVerdict = activeEngine->ListCerts(iExpectedLabel1, iExpectedLabel2, iExpectedNumLabel);
|
sl@0
|
117 |
}
|
sl@0
|
118 |
else
|
sl@0
|
119 |
{
|
sl@0
|
120 |
RPointerArray<HBufC> CertList;
|
sl@0
|
121 |
CleanupStack::PushL(TCleanupItem(ResetAndDestroyHBufCList, &CertList));
|
sl@0
|
122 |
HBufC8* fileContents = ParseOutputFileLC(iActualOutput);
|
sl@0
|
123 |
if (iListStoreExist)
|
sl@0
|
124 |
{
|
sl@0
|
125 |
_LIT8(KLabel1, "label:");
|
sl@0
|
126 |
TLex8 lex(*fileContents);
|
sl@0
|
127 |
while(!lex.Eos())
|
sl@0
|
128 |
{
|
sl@0
|
129 |
TPtrC8 token = lex.NextToken();
|
sl@0
|
130 |
if(token.CompareF(KLabel1) == KErrNone)
|
sl@0
|
131 |
{
|
sl@0
|
132 |
TInt offset = lex.Offset();
|
sl@0
|
133 |
TChar c = lex.Get();
|
sl@0
|
134 |
while(c != KCarriageReturn && c != KLineReturn)
|
sl@0
|
135 |
{
|
sl@0
|
136 |
c = lex.Get();
|
sl@0
|
137 |
}
|
sl@0
|
138 |
TInt end = lex.Offset();
|
sl@0
|
139 |
TPtrC8 newtoken;
|
sl@0
|
140 |
TInt tokenLen = end-offset-1;
|
sl@0
|
141 |
newtoken.Set(&fileContents->Des()[offset], tokenLen);
|
sl@0
|
142 |
|
sl@0
|
143 |
HBufC* tmp = HBufC::NewLC(tokenLen);
|
sl@0
|
144 |
tmp->Des().Copy(newtoken);
|
sl@0
|
145 |
tmp->Des().Trim();
|
sl@0
|
146 |
CertList.Append(tmp);
|
sl@0
|
147 |
CleanupStack::Pop(tmp);
|
sl@0
|
148 |
}
|
sl@0
|
149 |
}
|
sl@0
|
150 |
CleanupStack::PopAndDestroy(fileContents);
|
sl@0
|
151 |
iVerdict = activeEngine->ListStore(CertList);
|
sl@0
|
152 |
}
|
sl@0
|
153 |
else
|
sl@0
|
154 |
{
|
sl@0
|
155 |
ConstuctExpectedArrayL(CertList, fileContents->Des(), ETrue);
|
sl@0
|
156 |
CleanupStack::PopAndDestroy(fileContents);
|
sl@0
|
157 |
if (iOwnerExist)
|
sl@0
|
158 |
{
|
sl@0
|
159 |
iVerdict = activeEngine->ListCerts(CertList, iExpectedOwner);
|
sl@0
|
160 |
}
|
sl@0
|
161 |
else if (iExpectedStore != -1)
|
sl@0
|
162 |
{
|
sl@0
|
163 |
iVerdict = activeEngine->ListCerts(CertList, iExpectedStore);
|
sl@0
|
164 |
}
|
sl@0
|
165 |
else
|
sl@0
|
166 |
{
|
sl@0
|
167 |
iVerdict = activeEngine->ListCerts(CertList);
|
sl@0
|
168 |
}
|
sl@0
|
169 |
}
|
sl@0
|
170 |
CleanupStack::PopAndDestroy(&CertList);
|
sl@0
|
171 |
}
|
sl@0
|
172 |
|
sl@0
|
173 |
|
sl@0
|
174 |
CleanupStack::PopAndDestroy(2, sched);
|
sl@0
|
175 |
|
sl@0
|
176 |
if (iVerdict == EFail)
|
sl@0
|
177 |
{
|
sl@0
|
178 |
INFO_PRINTF1(_L("Expected Certificate does not Exist"));
|
sl@0
|
179 |
}
|
sl@0
|
180 |
SetTestStepResult(iVerdict);
|
sl@0
|
181 |
|
sl@0
|
182 |
return TestStepResult();
|
sl@0
|
183 |
}
|
sl@0
|
184 |
|
sl@0
|
185 |
/**
|
sl@0
|
186 |
* Override of base class virtual
|
sl@0
|
187 |
* @return TVerdict code
|
sl@0
|
188 |
*/
|
sl@0
|
189 |
TVerdict CTestToolListCertStep::doTestStepPostambleL()
|
sl@0
|
190 |
{
|
sl@0
|
191 |
CActiveScheduler::Install(NULL);
|
sl@0
|
192 |
return TestStepResult();
|
sl@0
|
193 |
}
|
sl@0
|
194 |
|
sl@0
|
195 |
|
sl@0
|
196 |
//
|
sl@0
|
197 |
// CTestToolGetTrustAppsStep
|
sl@0
|
198 |
//
|
sl@0
|
199 |
|
sl@0
|
200 |
CTestToolGetTrustAppsStep::~CTestToolGetTrustAppsStep()
|
sl@0
|
201 |
{
|
sl@0
|
202 |
iApps.ResetAndDestroy();
|
sl@0
|
203 |
}
|
sl@0
|
204 |
|
sl@0
|
205 |
|
sl@0
|
206 |
CTestToolGetTrustAppsStep::CTestToolGetTrustAppsStep()
|
sl@0
|
207 |
{
|
sl@0
|
208 |
// Call base class method to set up the human readable name for logging
|
sl@0
|
209 |
SetTestStepName(KTestToolGetTrustAppsStep);
|
sl@0
|
210 |
}
|
sl@0
|
211 |
|
sl@0
|
212 |
/**
|
sl@0
|
213 |
* Override of base class virtual. Prepares for the test run of Filetokens
|
sl@0
|
214 |
* @return TVerdict code
|
sl@0
|
215 |
*/
|
sl@0
|
216 |
TVerdict CTestToolGetTrustAppsStep::doTestStepPreambleL()
|
sl@0
|
217 |
{
|
sl@0
|
218 |
_LIT(KNumApps, "numapps"); // this specifies how many commands to read
|
sl@0
|
219 |
_LIT(KAppsBase, "apps"); // + number (0-based) = file to check for
|
sl@0
|
220 |
|
sl@0
|
221 |
if (!GetStringFromConfig(ConfigSection(), KExpectedLabel1, iExpectedLabel))
|
sl@0
|
222 |
{
|
sl@0
|
223 |
INFO_PRINTF1(_L("label name is missing"));
|
sl@0
|
224 |
SetTestStepResult(EFail);
|
sl@0
|
225 |
}
|
sl@0
|
226 |
TInt numApps = 0;
|
sl@0
|
227 |
if (GetIntFromConfig(ConfigSection(), KNumApps, numApps) && numApps!=0)
|
sl@0
|
228 |
{
|
sl@0
|
229 |
TPtrC appName;
|
sl@0
|
230 |
for (TInt i=0; i<numApps; i++)
|
sl@0
|
231 |
{
|
sl@0
|
232 |
// construct name of the key
|
sl@0
|
233 |
const TInt KKeyBufSize=64;
|
sl@0
|
234 |
TBuf<KKeyBufSize> keyBuf(KAppsBase);
|
sl@0
|
235 |
keyBuf.AppendNum(i);
|
sl@0
|
236 |
|
sl@0
|
237 |
if (GetStringFromConfig(ConfigSection(), keyBuf, appName))
|
sl@0
|
238 |
{
|
sl@0
|
239 |
HBufC* apps = appName.AllocLC();
|
sl@0
|
240 |
iApps.AppendL(apps);
|
sl@0
|
241 |
CleanupStack::Pop(apps);
|
sl@0
|
242 |
}
|
sl@0
|
243 |
else
|
sl@0
|
244 |
{
|
sl@0
|
245 |
SetTestStepResult(EFail);
|
sl@0
|
246 |
// the string must exist, otherwise the config is invalid
|
sl@0
|
247 |
ERR_PRINTF2(_L("Missing apps name for key '%S'"), &keyBuf);
|
sl@0
|
248 |
}
|
sl@0
|
249 |
}
|
sl@0
|
250 |
}
|
sl@0
|
251 |
return TestStepResult();
|
sl@0
|
252 |
}
|
sl@0
|
253 |
|
sl@0
|
254 |
/**
|
sl@0
|
255 |
* Override of base class pure virtual
|
sl@0
|
256 |
* Demonstrates reading configuration parameters from an ini file section
|
sl@0
|
257 |
* @return TVerdict code
|
sl@0
|
258 |
*/
|
sl@0
|
259 |
TVerdict CTestToolGetTrustAppsStep::doTestStepL()
|
sl@0
|
260 |
{
|
sl@0
|
261 |
if (TestStepResult() != EPass)
|
sl@0
|
262 |
{
|
sl@0
|
263 |
return TestStepResult();
|
sl@0
|
264 |
}
|
sl@0
|
265 |
|
sl@0
|
266 |
CActiveScheduler* sched = NULL;
|
sl@0
|
267 |
sched = new (ELeave) CActiveScheduler;
|
sl@0
|
268 |
CleanupStack::PushL(sched);
|
sl@0
|
269 |
CActiveScheduler::Install(sched);
|
sl@0
|
270 |
CTestToolEngine* activeEngine = CTestToolEngine::NewLC();
|
sl@0
|
271 |
iVerdict = activeEngine->CheckApps(iApps, iExpectedLabel);
|
sl@0
|
272 |
|
sl@0
|
273 |
CleanupStack::PopAndDestroy(2, sched);
|
sl@0
|
274 |
if (iVerdict == EFail)
|
sl@0
|
275 |
{
|
sl@0
|
276 |
INFO_PRINTF1(_L("Certificate is not trusted for the applicaion"));
|
sl@0
|
277 |
}
|
sl@0
|
278 |
SetTestStepResult(iVerdict);
|
sl@0
|
279 |
|
sl@0
|
280 |
return TestStepResult();
|
sl@0
|
281 |
}
|
sl@0
|
282 |
|
sl@0
|
283 |
/**
|
sl@0
|
284 |
* Override of base class virtual
|
sl@0
|
285 |
* @return TVerdict code
|
sl@0
|
286 |
*/
|
sl@0
|
287 |
TVerdict CTestToolGetTrustAppsStep::doTestStepPostambleL()
|
sl@0
|
288 |
{
|
sl@0
|
289 |
CActiveScheduler::Install(NULL);
|
sl@0
|
290 |
return TestStepResult();
|
sl@0
|
291 |
}
|
sl@0
|
292 |
|
sl@0
|
293 |
//
|
sl@0
|
294 |
// CTestToolListKeyStep
|
sl@0
|
295 |
//
|
sl@0
|
296 |
|
sl@0
|
297 |
CTestToolListKeyStep::~CTestToolListKeyStep()
|
sl@0
|
298 |
{
|
sl@0
|
299 |
}
|
sl@0
|
300 |
|
sl@0
|
301 |
|
sl@0
|
302 |
CTestToolListKeyStep::CTestToolListKeyStep()
|
sl@0
|
303 |
{
|
sl@0
|
304 |
// Call base class method to set up the human readable name for logging
|
sl@0
|
305 |
SetTestStepName(KTestToolListKeyStep);
|
sl@0
|
306 |
}
|
sl@0
|
307 |
|
sl@0
|
308 |
/**
|
sl@0
|
309 |
* Override of base class virtual. Prepares for the test run of Filetokens
|
sl@0
|
310 |
* @return TVerdict code
|
sl@0
|
311 |
*/
|
sl@0
|
312 |
TVerdict CTestToolListKeyStep::doTestStepPreambleL()
|
sl@0
|
313 |
{
|
sl@0
|
314 |
// construct name of the key
|
sl@0
|
315 |
|
sl@0
|
316 |
GetStringFromConfig(ConfigSection(), KActualOutput, iActualOutput);
|
sl@0
|
317 |
if (!GetIntFromConfig(ConfigSection(), KExpectedListStore, iListStoreExist))
|
sl@0
|
318 |
{
|
sl@0
|
319 |
iListStoreExist = 0;
|
sl@0
|
320 |
}
|
sl@0
|
321 |
if(!GetIntFromConfig(ConfigSection(), KStore, iExpectedStore))
|
sl@0
|
322 |
{
|
sl@0
|
323 |
iExpectedStore = -1;
|
sl@0
|
324 |
}
|
sl@0
|
325 |
if(!GetIntFromConfig(ConfigSection(), KExpectedNumLabel, iExpectedNumLabel))
|
sl@0
|
326 |
{
|
sl@0
|
327 |
iExpectedNumLabel = 1;
|
sl@0
|
328 |
}
|
sl@0
|
329 |
if (GetStringFromConfig(ConfigSection(), KExpectedLabel1, iExpectedLabel1))
|
sl@0
|
330 |
{
|
sl@0
|
331 |
iLabel1Exist = 1;
|
sl@0
|
332 |
}
|
sl@0
|
333 |
if (GetStringFromConfig(ConfigSection(), KExpectedLabel2, iExpectedLabel2))
|
sl@0
|
334 |
{
|
sl@0
|
335 |
iLabel2Exist = 1;
|
sl@0
|
336 |
}
|
sl@0
|
337 |
return TestStepResult();
|
sl@0
|
338 |
}
|
sl@0
|
339 |
|
sl@0
|
340 |
/**
|
sl@0
|
341 |
* Override of base class pure virtual
|
sl@0
|
342 |
* Demonstrates reading configuration parameters from an ini file section
|
sl@0
|
343 |
* @return TVerdict code
|
sl@0
|
344 |
*/
|
sl@0
|
345 |
TVerdict CTestToolListKeyStep::doTestStepL()
|
sl@0
|
346 |
{
|
sl@0
|
347 |
if (TestStepResult() != EPass)
|
sl@0
|
348 |
{
|
sl@0
|
349 |
return TestStepResult();
|
sl@0
|
350 |
}
|
sl@0
|
351 |
|
sl@0
|
352 |
CActiveScheduler* sched = NULL;
|
sl@0
|
353 |
sched = new (ELeave) CActiveScheduler;
|
sl@0
|
354 |
CleanupStack::PushL(sched);
|
sl@0
|
355 |
CActiveScheduler::Install(sched);
|
sl@0
|
356 |
CTestToolEngine* activeEngine = CTestToolEngine::NewLC();
|
sl@0
|
357 |
if (iLabel1Exist && !iLabel2Exist)
|
sl@0
|
358 |
{
|
sl@0
|
359 |
iVerdict = activeEngine->ListKeys(iExpectedLabel1, iExpectedNumLabel);
|
sl@0
|
360 |
}
|
sl@0
|
361 |
else if (iLabel2Exist && iLabel1Exist)
|
sl@0
|
362 |
{
|
sl@0
|
363 |
iVerdict = activeEngine->ListKeys(iExpectedLabel1, iExpectedLabel2, iExpectedNumLabel);
|
sl@0
|
364 |
}
|
sl@0
|
365 |
else
|
sl@0
|
366 |
{
|
sl@0
|
367 |
RPointerArray<HBufC> KeyList;
|
sl@0
|
368 |
CleanupStack::PushL(TCleanupItem(ResetAndDestroyHBufCList, &KeyList));
|
sl@0
|
369 |
HBufC8* fileContents = ParseOutputFileLC(iActualOutput);
|
sl@0
|
370 |
if (iListStoreExist)
|
sl@0
|
371 |
{
|
sl@0
|
372 |
_LIT8(KLabel1, "label:");
|
sl@0
|
373 |
TLex8 lex(*fileContents);
|
sl@0
|
374 |
while(!lex.Eos())
|
sl@0
|
375 |
{
|
sl@0
|
376 |
TPtrC8 token = lex.NextToken();
|
sl@0
|
377 |
if(token.CompareF(KLabel1) == KErrNone)
|
sl@0
|
378 |
{
|
sl@0
|
379 |
TInt offset = lex.Offset();
|
sl@0
|
380 |
TChar c = lex.Get();
|
sl@0
|
381 |
while(c != KCarriageReturn && c != KLineReturn)
|
sl@0
|
382 |
{
|
sl@0
|
383 |
c = lex.Get();
|
sl@0
|
384 |
}
|
sl@0
|
385 |
TInt end = lex.Offset();
|
sl@0
|
386 |
TPtrC8 newtoken;
|
sl@0
|
387 |
TInt tokenLen = end-offset-1;
|
sl@0
|
388 |
newtoken.Set(&fileContents->Des()[offset], tokenLen);
|
sl@0
|
389 |
|
sl@0
|
390 |
HBufC* tmp = HBufC::NewLC(tokenLen);
|
sl@0
|
391 |
tmp->Des().Copy(newtoken);
|
sl@0
|
392 |
tmp->Des().Trim();
|
sl@0
|
393 |
KeyList.Append(tmp);
|
sl@0
|
394 |
CleanupStack::Pop(tmp);
|
sl@0
|
395 |
}
|
sl@0
|
396 |
}
|
sl@0
|
397 |
CleanupStack::PopAndDestroy(fileContents);
|
sl@0
|
398 |
iVerdict = activeEngine->ListStoreKey(KeyList);
|
sl@0
|
399 |
}
|
sl@0
|
400 |
else
|
sl@0
|
401 |
{
|
sl@0
|
402 |
ConstuctExpectedArrayL(KeyList, fileContents->Des(), EFalse);
|
sl@0
|
403 |
CleanupStack::PopAndDestroy(fileContents);
|
sl@0
|
404 |
if (iExpectedStore != -1)
|
sl@0
|
405 |
{
|
sl@0
|
406 |
iVerdict = activeEngine->ListKeys(KeyList, iExpectedStore);
|
sl@0
|
407 |
}
|
sl@0
|
408 |
else
|
sl@0
|
409 |
{
|
sl@0
|
410 |
iVerdict = activeEngine->ListKeys(KeyList);
|
sl@0
|
411 |
}
|
sl@0
|
412 |
}
|
sl@0
|
413 |
CleanupStack::PopAndDestroy(&KeyList);
|
sl@0
|
414 |
}
|
sl@0
|
415 |
|
sl@0
|
416 |
CleanupStack::PopAndDestroy(2, sched);
|
sl@0
|
417 |
|
sl@0
|
418 |
if (iVerdict == EFail)
|
sl@0
|
419 |
{
|
sl@0
|
420 |
INFO_PRINTF1(_L("Expected Keys do not Exist"));
|
sl@0
|
421 |
}
|
sl@0
|
422 |
SetTestStepResult(iVerdict);
|
sl@0
|
423 |
|
sl@0
|
424 |
return TestStepResult();
|
sl@0
|
425 |
}
|
sl@0
|
426 |
|
sl@0
|
427 |
/**
|
sl@0
|
428 |
* Override of base class virtual
|
sl@0
|
429 |
* @return TVerdict code
|
sl@0
|
430 |
*/
|
sl@0
|
431 |
TVerdict CTestToolListKeyStep::doTestStepPostambleL()
|
sl@0
|
432 |
{
|
sl@0
|
433 |
CActiveScheduler::Install(NULL);
|
sl@0
|
434 |
return TestStepResult();
|
sl@0
|
435 |
}
|
sl@0
|
436 |
|
sl@0
|
437 |
|
sl@0
|
438 |
//
|
sl@0
|
439 |
// CTestToolGetPolicyStep
|
sl@0
|
440 |
//
|
sl@0
|
441 |
|
sl@0
|
442 |
CTestToolGetPolicyStep::~CTestToolGetPolicyStep()
|
sl@0
|
443 |
{
|
sl@0
|
444 |
}
|
sl@0
|
445 |
|
sl@0
|
446 |
|
sl@0
|
447 |
CTestToolGetPolicyStep::CTestToolGetPolicyStep()
|
sl@0
|
448 |
{
|
sl@0
|
449 |
// Call base class method to set up the human readable name for logging
|
sl@0
|
450 |
SetTestStepName(KTestToolGetPolicyStep);
|
sl@0
|
451 |
}
|
sl@0
|
452 |
|
sl@0
|
453 |
/**
|
sl@0
|
454 |
* Override of base class virtual. Prepares for the test run of Filetokens
|
sl@0
|
455 |
* @return TVerdict code
|
sl@0
|
456 |
*/
|
sl@0
|
457 |
TVerdict CTestToolGetPolicyStep::doTestStepPreambleL()
|
sl@0
|
458 |
{
|
sl@0
|
459 |
// construct name of the key
|
sl@0
|
460 |
if (GetStringFromConfig(ConfigSection(), KExpectedLabel1, iExpectedLabel))
|
sl@0
|
461 |
{
|
sl@0
|
462 |
iLabelExist = 1;
|
sl@0
|
463 |
}
|
sl@0
|
464 |
if (!GetStringFromConfig(ConfigSection(), KExpectedUser, iExpectedUser))
|
sl@0
|
465 |
{
|
sl@0
|
466 |
INFO_PRINTF1(_L("policy user name is missing"));
|
sl@0
|
467 |
SetTestStepResult(EFail);
|
sl@0
|
468 |
}
|
sl@0
|
469 |
if (!GetIntFromConfig(ConfigSection(), KExpectedUserExist, iExpectedUserExist))
|
sl@0
|
470 |
{
|
sl@0
|
471 |
iExpectedUserExist = 0;
|
sl@0
|
472 |
}
|
sl@0
|
473 |
return TestStepResult();
|
sl@0
|
474 |
}
|
sl@0
|
475 |
|
sl@0
|
476 |
/**
|
sl@0
|
477 |
* Override of base class pure virtual
|
sl@0
|
478 |
* Demonstrates reading configuration parameters from an ini file section
|
sl@0
|
479 |
* @return TVerdict code
|
sl@0
|
480 |
*/
|
sl@0
|
481 |
TVerdict CTestToolGetPolicyStep::doTestStepL()
|
sl@0
|
482 |
{
|
sl@0
|
483 |
if (TestStepResult() != EPass)
|
sl@0
|
484 |
{
|
sl@0
|
485 |
return TestStepResult();
|
sl@0
|
486 |
}
|
sl@0
|
487 |
|
sl@0
|
488 |
CActiveScheduler* sched = NULL;
|
sl@0
|
489 |
sched = new (ELeave) CActiveScheduler;
|
sl@0
|
490 |
CleanupStack::PushL(sched);
|
sl@0
|
491 |
CActiveScheduler::Install(sched);
|
sl@0
|
492 |
CTestToolEngine* activeEngine = CTestToolEngine::NewLC();
|
sl@0
|
493 |
if (iLabelExist)
|
sl@0
|
494 |
{
|
sl@0
|
495 |
iVerdict = activeEngine->GetPolicy(iExpectedLabel, iExpectedUser, iExpectedUserExist);
|
sl@0
|
496 |
}
|
sl@0
|
497 |
|
sl@0
|
498 |
CleanupStack::PopAndDestroy(2, sched);
|
sl@0
|
499 |
if (iVerdict == EFail)
|
sl@0
|
500 |
{
|
sl@0
|
501 |
INFO_PRINTF1(_L("Exptected Keys are not Exist"));
|
sl@0
|
502 |
}
|
sl@0
|
503 |
SetTestStepResult(iVerdict);
|
sl@0
|
504 |
|
sl@0
|
505 |
return TestStepResult();
|
sl@0
|
506 |
}
|
sl@0
|
507 |
|
sl@0
|
508 |
/**
|
sl@0
|
509 |
* Override of base class virtual
|
sl@0
|
510 |
* @return TVerdict code
|
sl@0
|
511 |
*/
|
sl@0
|
512 |
TVerdict CTestToolGetPolicyStep::doTestStepPostambleL()
|
sl@0
|
513 |
{
|
sl@0
|
514 |
CActiveScheduler::Install(NULL);
|
sl@0
|
515 |
return TestStepResult();
|
sl@0
|
516 |
}
|
sl@0
|
517 |
|
sl@0
|
518 |
|
sl@0
|
519 |
|
sl@0
|
520 |
//
|
sl@0
|
521 |
// CTestToolParseFileStep
|
sl@0
|
522 |
//
|
sl@0
|
523 |
|
sl@0
|
524 |
CTestToolParseFileStep::~CTestToolParseFileStep()
|
sl@0
|
525 |
{
|
sl@0
|
526 |
iArgs.ResetAndDestroy();
|
sl@0
|
527 |
}
|
sl@0
|
528 |
|
sl@0
|
529 |
|
sl@0
|
530 |
CTestToolParseFileStep::CTestToolParseFileStep()
|
sl@0
|
531 |
{
|
sl@0
|
532 |
// Call base class method to set up the human readable name for logging
|
sl@0
|
533 |
SetTestStepName(KTestToolParseFileStep);
|
sl@0
|
534 |
}
|
sl@0
|
535 |
|
sl@0
|
536 |
/**
|
sl@0
|
537 |
* Override of base class virtual. Prepares for the test run of Filetokens
|
sl@0
|
538 |
* @return TVerdict code
|
sl@0
|
539 |
*/
|
sl@0
|
540 |
TVerdict CTestToolParseFileStep::doTestStepPreambleL()
|
sl@0
|
541 |
{
|
sl@0
|
542 |
_LIT(KNumLines, "numlines"); // this specifies how many commands to read
|
sl@0
|
543 |
_LIT(KLineBase, "line"); // + number (0-based) = file to check for
|
sl@0
|
544 |
|
sl@0
|
545 |
|
sl@0
|
546 |
TInt numlines = 0;
|
sl@0
|
547 |
if (GetIntFromConfig(ConfigSection(), KNumLines, numlines) && numlines!=0)
|
sl@0
|
548 |
{
|
sl@0
|
549 |
TPtrC lineContent;
|
sl@0
|
550 |
for (TInt i=0; i<numlines; i++)
|
sl@0
|
551 |
{
|
sl@0
|
552 |
// construct name of the key
|
sl@0
|
553 |
const TInt KKeyBufSize=64;
|
sl@0
|
554 |
TBuf<KKeyBufSize> keyBuf(KLineBase);
|
sl@0
|
555 |
keyBuf.AppendNum(i);
|
sl@0
|
556 |
|
sl@0
|
557 |
if (GetStringFromConfig(ConfigSection(), keyBuf, lineContent))
|
sl@0
|
558 |
{
|
sl@0
|
559 |
HBufC* line = lineContent.AllocLC();
|
sl@0
|
560 |
line->Des().Trim();
|
sl@0
|
561 |
iArgs.AppendL(line);
|
sl@0
|
562 |
CleanupStack::Pop(line);
|
sl@0
|
563 |
}
|
sl@0
|
564 |
else
|
sl@0
|
565 |
{
|
sl@0
|
566 |
SetTestStepResult(EFail);
|
sl@0
|
567 |
// the string must exist, otherwise the config is invalid
|
sl@0
|
568 |
ERR_PRINTF2(_L("Missing apps name for key '%S'"), &keyBuf);
|
sl@0
|
569 |
}
|
sl@0
|
570 |
}
|
sl@0
|
571 |
}
|
sl@0
|
572 |
if (!GetStringFromConfig(ConfigSection(), KActualOutput, iActualOutput))
|
sl@0
|
573 |
{
|
sl@0
|
574 |
INFO_PRINTF1(_L("actual output filename is missing"));
|
sl@0
|
575 |
SetTestStepResult(EFail);
|
sl@0
|
576 |
}
|
sl@0
|
577 |
if (numlines == 0)
|
sl@0
|
578 |
{
|
sl@0
|
579 |
if (!GetStringFromConfig(ConfigSection(), KExpectedError, iExpectedError))
|
sl@0
|
580 |
{
|
sl@0
|
581 |
INFO_PRINTF1(_L("error value is missing"));
|
sl@0
|
582 |
SetTestStepResult(EFail);
|
sl@0
|
583 |
}
|
sl@0
|
584 |
}
|
sl@0
|
585 |
return TestStepResult();
|
sl@0
|
586 |
}
|
sl@0
|
587 |
|
sl@0
|
588 |
/**
|
sl@0
|
589 |
* Override of base class pure virtual
|
sl@0
|
590 |
* Demonstrates reading configuration parameters from an ini file section
|
sl@0
|
591 |
* @return TVerdict code
|
sl@0
|
592 |
*/
|
sl@0
|
593 |
TVerdict CTestToolParseFileStep::doTestStepL()
|
sl@0
|
594 |
{
|
sl@0
|
595 |
if (TestStepResult() != EPass)
|
sl@0
|
596 |
{
|
sl@0
|
597 |
return TestStepResult();
|
sl@0
|
598 |
}
|
sl@0
|
599 |
if (iArgs.Count() == 0)
|
sl@0
|
600 |
{
|
sl@0
|
601 |
HBufC8* fileContents = ParseOutputFileLC(iActualOutput);
|
sl@0
|
602 |
HBufC8* actualError = GetErrorFromOutputFileLC(*fileContents);
|
sl@0
|
603 |
if (actualError == NULL)
|
sl@0
|
604 |
{
|
sl@0
|
605 |
INFO_PRINTF1(_L("Failed to parse the output File"));
|
sl@0
|
606 |
SetTestStepResult(EFail);
|
sl@0
|
607 |
}
|
sl@0
|
608 |
|
sl@0
|
609 |
HBufC* actual16 = HBufC::NewLC(actualError->Length());
|
sl@0
|
610 |
actual16->Des().Copy(*actualError);
|
sl@0
|
611 |
|
sl@0
|
612 |
if (iExpectedError.CompareF(*actual16) != KErrNone)
|
sl@0
|
613 |
{
|
sl@0
|
614 |
INFO_PRINTF1(_L("Expected Error is Different from Actual"));
|
sl@0
|
615 |
SetTestStepResult(EFail);
|
sl@0
|
616 |
}
|
sl@0
|
617 |
CleanupStack::PopAndDestroy(3, fileContents); //actual16, actualError, fileContents
|
sl@0
|
618 |
}
|
sl@0
|
619 |
else
|
sl@0
|
620 |
{
|
sl@0
|
621 |
HBufC8* fileContents = ParseOutputFileLC(iActualOutput);
|
sl@0
|
622 |
RPointerArray<HBufC> actualoutput;
|
sl@0
|
623 |
CleanupStack::PushL(TCleanupItem(ResetAndDestroyHBufCList, &actualoutput));
|
sl@0
|
624 |
ConstuctExpectedArrayL(actualoutput, fileContents->Des(), EFalse, ETrue);
|
sl@0
|
625 |
TBool result = EFalse;
|
sl@0
|
626 |
for (TInt i = 0; i < iArgs.Count(); i++)
|
sl@0
|
627 |
{
|
sl@0
|
628 |
result = EFalse;
|
sl@0
|
629 |
for (TInt j = 5; j < actualoutput.Count(); j++)
|
sl@0
|
630 |
{
|
sl@0
|
631 |
if (iArgs[i]->Des().CompareF(actualoutput[j]->Des()) == KErrNone)
|
sl@0
|
632 |
{
|
sl@0
|
633 |
result = ETrue;
|
sl@0
|
634 |
break;
|
sl@0
|
635 |
}
|
sl@0
|
636 |
}
|
sl@0
|
637 |
if (!result)
|
sl@0
|
638 |
{
|
sl@0
|
639 |
break;
|
sl@0
|
640 |
}
|
sl@0
|
641 |
}
|
sl@0
|
642 |
if (!result)
|
sl@0
|
643 |
{
|
sl@0
|
644 |
INFO_PRINTF1(_L("expected output and actual output is not matching"));
|
sl@0
|
645 |
SetTestStepResult(EFail);
|
sl@0
|
646 |
}
|
sl@0
|
647 |
CleanupStack::PopAndDestroy(2, fileContents); // fileContents ,actualoutput
|
sl@0
|
648 |
}
|
sl@0
|
649 |
|
sl@0
|
650 |
return TestStepResult();
|
sl@0
|
651 |
}
|
sl@0
|
652 |
|
sl@0
|
653 |
|
sl@0
|
654 |
HBufC8* CTestToolParseFileStep::GetErrorFromOutputFileLC(const TDesC8& aBuffer)
|
sl@0
|
655 |
{
|
sl@0
|
656 |
_LIT8(KOutput, "output");
|
sl@0
|
657 |
TInt readPos = 0;
|
sl@0
|
658 |
TPtrC8 wordContents;
|
sl@0
|
659 |
|
sl@0
|
660 |
HBufC8* wordBuf = NULL;
|
sl@0
|
661 |
while (!ReadWordL(aBuffer, readPos, wordContents))
|
sl@0
|
662 |
{
|
sl@0
|
663 |
wordBuf = wordContents.AllocLC();
|
sl@0
|
664 |
wordBuf->Des().Trim();
|
sl@0
|
665 |
if (wordBuf->Des().CompareF(KOutput) == KErrNone)
|
sl@0
|
666 |
{
|
sl@0
|
667 |
readPos+=1;
|
sl@0
|
668 |
if (!ReadWordL(aBuffer, readPos, wordContents))
|
sl@0
|
669 |
{
|
sl@0
|
670 |
CleanupStack::PopAndDestroy(wordBuf);
|
sl@0
|
671 |
wordBuf = wordContents.AllocLC();
|
sl@0
|
672 |
wordBuf->Des().Trim();
|
sl@0
|
673 |
break;
|
sl@0
|
674 |
}
|
sl@0
|
675 |
}
|
sl@0
|
676 |
CleanupStack::PopAndDestroy(wordBuf);
|
sl@0
|
677 |
}
|
sl@0
|
678 |
return wordBuf;
|
sl@0
|
679 |
}
|
sl@0
|
680 |
|
sl@0
|
681 |
/**
|
sl@0
|
682 |
* Override of base class virtual
|
sl@0
|
683 |
* @return TVerdict code
|
sl@0
|
684 |
*/
|
sl@0
|
685 |
TVerdict CTestToolParseFileStep::doTestStepPostambleL()
|
sl@0
|
686 |
{
|
sl@0
|
687 |
CActiveScheduler::Install(NULL);
|
sl@0
|
688 |
return TestStepResult();
|
sl@0
|
689 |
}
|
sl@0
|
690 |
|
sl@0
|
691 |
|
sl@0
|
692 |
|
sl@0
|
693 |
//
|
sl@0
|
694 |
// global public methods
|
sl@0
|
695 |
//
|
sl@0
|
696 |
|
sl@0
|
697 |
// Reads the words from the Buffer either ended with : or \n
|
sl@0
|
698 |
// if the word is "label", then read the next word and add to the array
|
sl@0
|
699 |
// if the word is not label read upto the end of the line then go to next loop
|
sl@0
|
700 |
// if exception is on , reads the entire line
|
sl@0
|
701 |
void ConstuctExpectedArrayL(RPointerArray<HBufC>& aArray, const TDesC8& aBuffer,TBool aCheck, TBool aException)
|
sl@0
|
702 |
{
|
sl@0
|
703 |
TInt readPos = 0;
|
sl@0
|
704 |
TPtrC8 wordContents;
|
sl@0
|
705 |
|
sl@0
|
706 |
TInt bufferLength = aBuffer.Length();
|
sl@0
|
707 |
while (!ReadWordL(aBuffer, readPos, wordContents))
|
sl@0
|
708 |
{
|
sl@0
|
709 |
HBufC8* wordBuf = wordContents.AllocLC();
|
sl@0
|
710 |
wordBuf->Des().Trim();
|
sl@0
|
711 |
if (aException)
|
sl@0
|
712 |
{
|
sl@0
|
713 |
HBufC* currentLabel = HBufC::NewLC(wordBuf->Length());
|
sl@0
|
714 |
currentLabel->Des().Copy(*wordBuf);
|
sl@0
|
715 |
currentLabel->Des().Trim();
|
sl@0
|
716 |
aArray.AppendL(currentLabel);
|
sl@0
|
717 |
CleanupStack::Pop(currentLabel);
|
sl@0
|
718 |
}
|
sl@0
|
719 |
else if (wordBuf->Des().CompareF(KLabel) == KErrNone)
|
sl@0
|
720 |
{
|
sl@0
|
721 |
if (!ReadWordL(aBuffer, readPos, wordContents))
|
sl@0
|
722 |
{
|
sl@0
|
723 |
TPtrC8 word;
|
sl@0
|
724 |
TInt len = wordContents.Length();
|
sl@0
|
725 |
// aCheck is on for reading the certool output file,because the output will be like this
|
sl@0
|
726 |
// label: abc format:.... , so we need to exclude format
|
sl@0
|
727 |
if (aCheck) // certdetails
|
sl@0
|
728 |
{
|
sl@0
|
729 |
len = len - 6;
|
sl@0
|
730 |
}
|
sl@0
|
731 |
word.Set(wordContents.Ptr(), len);
|
sl@0
|
732 |
HBufC* currentLabel = HBufC::NewLC(word.Length());
|
sl@0
|
733 |
currentLabel->Des().Copy(word);
|
sl@0
|
734 |
currentLabel->Des().Trim();
|
sl@0
|
735 |
aArray.AppendL(currentLabel);
|
sl@0
|
736 |
CleanupStack::Pop(currentLabel);
|
sl@0
|
737 |
}
|
sl@0
|
738 |
else
|
sl@0
|
739 |
{
|
sl@0
|
740 |
break;
|
sl@0
|
741 |
}
|
sl@0
|
742 |
}
|
sl@0
|
743 |
else
|
sl@0
|
744 |
{
|
sl@0
|
745 |
readPos--;
|
sl@0
|
746 |
while (readPos < bufferLength)
|
sl@0
|
747 |
{
|
sl@0
|
748 |
TChar c = aBuffer[readPos];
|
sl@0
|
749 |
|
sl@0
|
750 |
if (c == KCarriageReturn || c == KLineReturn)
|
sl@0
|
751 |
{
|
sl@0
|
752 |
readPos += 1;
|
sl@0
|
753 |
break;
|
sl@0
|
754 |
}
|
sl@0
|
755 |
readPos++;
|
sl@0
|
756 |
}
|
sl@0
|
757 |
}
|
sl@0
|
758 |
CleanupStack::PopAndDestroy(wordBuf);
|
sl@0
|
759 |
}
|
sl@0
|
760 |
}
|
sl@0
|
761 |
|
sl@0
|
762 |
// Reads the output file and return into the buffer.
|
sl@0
|
763 |
HBufC8* ParseOutputFileLC(const TPtrC& aFileName)
|
sl@0
|
764 |
{
|
sl@0
|
765 |
RFs fs;
|
sl@0
|
766 |
RFile file;
|
sl@0
|
767 |
User::LeaveIfError(fs.Connect());
|
sl@0
|
768 |
CleanupClosePushL(fs);
|
sl@0
|
769 |
User::LeaveIfError(file.Open(fs, aFileName, EFileRead));
|
sl@0
|
770 |
CleanupClosePushL(file);
|
sl@0
|
771 |
TInt fSize;
|
sl@0
|
772 |
file.Size(fSize);
|
sl@0
|
773 |
|
sl@0
|
774 |
HBufC8* fileContents = HBufC8::NewLC(fSize);
|
sl@0
|
775 |
TPtr8 ptr(fileContents->Des());
|
sl@0
|
776 |
ptr.SetLength(fSize);
|
sl@0
|
777 |
|
sl@0
|
778 |
// create file stream and Read the content from the file
|
sl@0
|
779 |
RFileReadStream inputFileStream(file);
|
sl@0
|
780 |
CleanupClosePushL(inputFileStream);
|
sl@0
|
781 |
inputFileStream.ReadL(ptr, fSize);
|
sl@0
|
782 |
CleanupStack::PopAndDestroy(&inputFileStream);
|
sl@0
|
783 |
CleanupStack::Pop(fileContents);
|
sl@0
|
784 |
CleanupStack::PopAndDestroy(2, &fs);
|
sl@0
|
785 |
CleanupStack::PushL(fileContents);
|
sl@0
|
786 |
|
sl@0
|
787 |
return fileContents;
|
sl@0
|
788 |
}
|
sl@0
|
789 |
|
sl@0
|
790 |
// Reads the words from the aBuffer either ended with : or \n or \r
|
sl@0
|
791 |
TInt ReadWordL(const TDesC8& aBuffer, TInt& aPos, TPtrC8& aLine)
|
sl@0
|
792 |
{
|
sl@0
|
793 |
TBool endOfBuffer = EFalse;
|
sl@0
|
794 |
|
sl@0
|
795 |
TInt bufferLength = aBuffer.Length();
|
sl@0
|
796 |
if ( aPos > bufferLength || aPos < 0 )
|
sl@0
|
797 |
{
|
sl@0
|
798 |
return ETrue; // End of buffer
|
sl@0
|
799 |
}
|
sl@0
|
800 |
|
sl@0
|
801 |
TInt endPos = aPos;
|
sl@0
|
802 |
// find the position of the next delimeter
|
sl@0
|
803 |
endPos = aPos;
|
sl@0
|
804 |
while (endPos < bufferLength)
|
sl@0
|
805 |
{
|
sl@0
|
806 |
TChar c = aBuffer[endPos];
|
sl@0
|
807 |
|
sl@0
|
808 |
if (c == KCarriageReturn || c == KLineReturn || c == KDelemeter)
|
sl@0
|
809 |
{
|
sl@0
|
810 |
// exception when comes like c:\filename
|
sl@0
|
811 |
if ((bufferLength > (endPos + 1)) && aBuffer[endPos+1] != '\\')
|
sl@0
|
812 |
{
|
sl@0
|
813 |
break;
|
sl@0
|
814 |
}
|
sl@0
|
815 |
}
|
sl@0
|
816 |
endPos++;
|
sl@0
|
817 |
}
|
sl@0
|
818 |
|
sl@0
|
819 |
if (endPos != aPos)
|
sl@0
|
820 |
{
|
sl@0
|
821 |
TInt tokenLen = endPos - aPos;
|
sl@0
|
822 |
aLine.Set(&aBuffer[aPos], tokenLen);
|
sl@0
|
823 |
endPos += 1;
|
sl@0
|
824 |
}
|
sl@0
|
825 |
else if (endPos == bufferLength)
|
sl@0
|
826 |
{
|
sl@0
|
827 |
return ETrue; // End of buffer
|
sl@0
|
828 |
}
|
sl@0
|
829 |
else
|
sl@0
|
830 |
{
|
sl@0
|
831 |
endPos++;
|
sl@0
|
832 |
}
|
sl@0
|
833 |
aPos = endPos;
|
sl@0
|
834 |
return endOfBuffer;
|
sl@0
|
835 |
}
|
sl@0
|
836 |
|
sl@0
|
837 |
|
sl@0
|
838 |
void ResetAndDestroyHBufCList(TAny* aList)
|
sl@0
|
839 |
{
|
sl@0
|
840 |
RPointerArray<HBufC>* list = static_cast<RPointerArray<HBufC>*>(aList);
|
sl@0
|
841 |
|
sl@0
|
842 |
list->ResetAndDestroy();
|
sl@0
|
843 |
list->Close();
|
sl@0
|
844 |
}
|
sl@0
|
845 |
|
sl@0
|
846 |
|
sl@0
|
847 |
|
sl@0
|
848 |
|
sl@0
|
849 |
|
sl@0
|
850 |
|
sl@0
|
851 |
|
sl@0
|
852 |
|
sl@0
|
853 |
|
sl@0
|
854 |
//
|
sl@0
|
855 |
// CTestToolGetTrustStep
|
sl@0
|
856 |
//
|
sl@0
|
857 |
|
sl@0
|
858 |
CTestToolGetTrustStep::~CTestToolGetTrustStep()
|
sl@0
|
859 |
{
|
sl@0
|
860 |
|
sl@0
|
861 |
}
|
sl@0
|
862 |
|
sl@0
|
863 |
|
sl@0
|
864 |
CTestToolGetTrustStep::CTestToolGetTrustStep()
|
sl@0
|
865 |
{
|
sl@0
|
866 |
// Call base class method to set up the human readable name for logging
|
sl@0
|
867 |
SetTestStepName(KTestToolGetTrustStep);
|
sl@0
|
868 |
}
|
sl@0
|
869 |
|
sl@0
|
870 |
/**
|
sl@0
|
871 |
* Override of base class virtual. Prepares for the test run of Filetokens
|
sl@0
|
872 |
* @return TVerdict code
|
sl@0
|
873 |
*/
|
sl@0
|
874 |
TVerdict CTestToolGetTrustStep::doTestStepPreambleL()
|
sl@0
|
875 |
{
|
sl@0
|
876 |
|
sl@0
|
877 |
if (!GetStringFromConfig(ConfigSection(), KExpectedLabel1, iExpectedLabel))
|
sl@0
|
878 |
{
|
sl@0
|
879 |
INFO_PRINTF1(_L("label name is missing"));
|
sl@0
|
880 |
SetTestStepResult(EFail);
|
sl@0
|
881 |
}
|
sl@0
|
882 |
if (!GetIntFromConfig(ConfigSection(), KExpectedTrust, iExpectedTrust))
|
sl@0
|
883 |
{
|
sl@0
|
884 |
INFO_PRINTF1(_L("Expected trust is missing"));
|
sl@0
|
885 |
SetTestStepResult(EFail);
|
sl@0
|
886 |
}
|
sl@0
|
887 |
return TestStepResult();
|
sl@0
|
888 |
}
|
sl@0
|
889 |
|
sl@0
|
890 |
/**
|
sl@0
|
891 |
* Override of base class pure virtual
|
sl@0
|
892 |
* Demonstrates reading configuration parameters from an ini file section
|
sl@0
|
893 |
* @return TVerdict code
|
sl@0
|
894 |
*/
|
sl@0
|
895 |
TVerdict CTestToolGetTrustStep::doTestStepL()
|
sl@0
|
896 |
{
|
sl@0
|
897 |
if (TestStepResult() != EPass)
|
sl@0
|
898 |
{
|
sl@0
|
899 |
return TestStepResult();
|
sl@0
|
900 |
}
|
sl@0
|
901 |
|
sl@0
|
902 |
CActiveScheduler* sched = NULL;
|
sl@0
|
903 |
sched = new (ELeave) CActiveScheduler;
|
sl@0
|
904 |
CleanupStack::PushL(sched);
|
sl@0
|
905 |
CActiveScheduler::Install(sched);
|
sl@0
|
906 |
CTestToolEngine* activeEngine = CTestToolEngine::NewLC();
|
sl@0
|
907 |
iVerdict = activeEngine->CheckTrust(iExpectedLabel,iExpectedTrust);
|
sl@0
|
908 |
CleanupStack::PopAndDestroy(2, sched);
|
sl@0
|
909 |
if (iVerdict == EFail)
|
sl@0
|
910 |
{
|
sl@0
|
911 |
INFO_PRINTF1(_L("Certificate is not trusted for the applicaion"));
|
sl@0
|
912 |
}
|
sl@0
|
913 |
SetTestStepResult(iVerdict);
|
sl@0
|
914 |
|
sl@0
|
915 |
return TestStepResult();
|
sl@0
|
916 |
}
|
sl@0
|
917 |
|
sl@0
|
918 |
/**
|
sl@0
|
919 |
* Override of base class virtual
|
sl@0
|
920 |
* @return TVerdict code
|
sl@0
|
921 |
*/
|
sl@0
|
922 |
TVerdict CTestToolGetTrustStep::doTestStepPostambleL()
|
sl@0
|
923 |
{
|
sl@0
|
924 |
CActiveScheduler::Install(NULL);
|
sl@0
|
925 |
return TestStepResult();
|
sl@0
|
926 |
}
|
sl@0
|
927 |
|
sl@0
|
928 |
CTestToolCheckFileStep::CTestToolCheckFileStep()
|
sl@0
|
929 |
{}
|
sl@0
|
930 |
|
sl@0
|
931 |
CTestToolCheckFileStep::~CTestToolCheckFileStep()
|
sl@0
|
932 |
{}
|
sl@0
|
933 |
|
sl@0
|
934 |
TVerdict CTestToolCheckFileStep::doTestStepPreambleL()
|
sl@0
|
935 |
{
|
sl@0
|
936 |
if (!GetStringFromConfig(ConfigSection(), KFileName,iFileName))
|
sl@0
|
937 |
{
|
sl@0
|
938 |
INFO_PRINTF1(_L("file name is missing"));
|
sl@0
|
939 |
SetTestStepResult(EFail);
|
sl@0
|
940 |
}
|
sl@0
|
941 |
if (!GetStringFromConfig(ConfigSection(), KCheckType,iCheckType))
|
sl@0
|
942 |
{
|
sl@0
|
943 |
INFO_PRINTF1(_L("chek type for file is missing"));
|
sl@0
|
944 |
SetTestStepResult(EFail);
|
sl@0
|
945 |
}
|
sl@0
|
946 |
return TestStepResult();
|
sl@0
|
947 |
}
|
sl@0
|
948 |
|
sl@0
|
949 |
TVerdict CTestToolCheckFileStep::doTestStepPostambleL()
|
sl@0
|
950 |
{
|
sl@0
|
951 |
return TestStepResult();
|
sl@0
|
952 |
}
|
sl@0
|
953 |
|
sl@0
|
954 |
TVerdict CTestToolCheckFileStep::doTestStepL()
|
sl@0
|
955 |
{
|
sl@0
|
956 |
if (TestStepResult() != EPass)
|
sl@0
|
957 |
{
|
sl@0
|
958 |
return TestStepResult();
|
sl@0
|
959 |
}
|
sl@0
|
960 |
|
sl@0
|
961 |
RFs fs;
|
sl@0
|
962 |
User::LeaveIfError(fs.Connect());
|
sl@0
|
963 |
CleanupClosePushL(fs);
|
sl@0
|
964 |
RFile file;
|
sl@0
|
965 |
CleanupClosePushL(file);
|
sl@0
|
966 |
|
sl@0
|
967 |
TInt error = file.Open(fs,iFileName,EFileRead);
|
sl@0
|
968 |
if( ( iCheckType.Compare(_L("present")) == 0 && error == KErrNone ) ||
|
sl@0
|
969 |
( iCheckType.Compare(_L("absent")) == 0 && error == KErrNotFound )
|
sl@0
|
970 |
)
|
sl@0
|
971 |
{
|
sl@0
|
972 |
SetTestStepResult(EPass);
|
sl@0
|
973 |
}
|
sl@0
|
974 |
else
|
sl@0
|
975 |
{
|
sl@0
|
976 |
SetTestStepResult(EFail);
|
sl@0
|
977 |
}
|
sl@0
|
978 |
|
sl@0
|
979 |
CleanupStack::PopAndDestroy(2,&fs); // file
|
sl@0
|
980 |
return TestStepResult();
|
sl@0
|
981 |
}
|
sl@0
|
982 |
// End of file
|