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