|
1 /* |
|
2 * Copyright (c) 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 #include "caserunner.h" |
|
18 #include "executor.h" |
|
19 |
|
20 CExecutor::CExecutor(CCmdParser* aParser,CConsoleBase* aConsole) : |
|
21 iConsole(aConsole),iParser(aParser) |
|
22 { |
|
23 } |
|
24 |
|
25 void CExecutor::ConstructL() |
|
26 { |
|
27 // Create console screen |
|
28 |
|
29 RDebug::Print(_L("Creating module list object")); |
|
30 TRAPD(err, iModuleList = CTestModuleList::NewL(NULL)); |
|
31 if (err != KErrNone) |
|
32 { |
|
33 LogErrorAndLeaveL(_L("CExecutor::ConstructL"), |
|
34 _L("CTestModuleList::NewL"), err); |
|
35 return; |
|
36 } |
|
37 if (!iModuleList) |
|
38 { |
|
39 LogErrorAndLeaveL(_L("CExecutor::ConstructL"), |
|
40 _L("CTestModuleList::NewL - iModuleList is NULL"), |
|
41 KErrGeneral); |
|
42 return; |
|
43 } |
|
44 |
|
45 // Add to module list info about module taken from command line |
|
46 RDebug::Print(_L("Adding command line module to list")); |
|
47 TName moduleName; |
|
48 moduleName.Copy(iParser->TestModule()); |
|
49 moduleName.LowerCase(); |
|
50 RDebug::Print(_L("AddTestModule : '%S'"), &moduleName); |
|
51 err = iModuleList->AddTestModule(moduleName); |
|
52 |
|
53 if (err != KErrNone && err != KErrAlreadyExists) |
|
54 { |
|
55 LogErrorAndLeaveL( |
|
56 _L("CExecutor::ConstructL"), |
|
57 _L("CTestModuleList::AddTestModule - Could not add module to list of modules"), |
|
58 err); |
|
59 return; |
|
60 } |
|
61 |
|
62 //Get added module |
|
63 CTestModuleInfo* moduleInfo = iModuleList->GetModule(moduleName); |
|
64 if (!moduleInfo) |
|
65 { |
|
66 LogErrorAndLeaveL( |
|
67 _L("CExecutor::ConstructL"), |
|
68 _L("CTestModuleList::GetModule - Could not add get module info from list"), |
|
69 KErrGeneral); |
|
70 return; |
|
71 } |
|
72 |
|
73 //Add ini file if given |
|
74 if (iParser->ModuleIniFile().Length() > 0) |
|
75 { |
|
76 TFileName filename; |
|
77 filename.Copy(iParser->ModuleIniFile()); |
|
78 filename.LowerCase(); |
|
79 moduleInfo->SetIniFile(filename); |
|
80 } |
|
81 |
|
82 //Add config file if given |
|
83 if (iParser->ConfigFile().Length() > 0) |
|
84 { |
|
85 TFileName filename; |
|
86 filename.Copy(iParser->ConfigFile()); |
|
87 filename.LowerCase(); |
|
88 moduleInfo->AddCfgFile(filename); |
|
89 } |
|
90 //Now check all config files if there are included modules |
|
91 _LIT(KIncludeModuleStart, "[New_Include_Module]"); |
|
92 _LIT(KIncludeModuleEnd, "[End_Include_Module]"); |
|
93 |
|
94 RDebug::Print(_L("Start parsing included modules")); |
|
95 CTestCaseFileInfo* finfo = iModuleList->GetUncheckedCfgFile(); |
|
96 while (finfo) |
|
97 { |
|
98 TFileName fname; |
|
99 finfo->GetCfgFileName(fname); |
|
100 |
|
101 RDebug::Print(_L("Checking file: '%S'"), &fname); |
|
102 finfo->SetChecked(); |
|
103 |
|
104 CStifParser* parser = NULL; |
|
105 |
|
106 TRAP(err, parser = CStifParser::NewL(_L(""), fname)); |
|
107 if (err != KErrNone) |
|
108 { |
|
109 iConsole->Printf(_L("\n ErrNo: [%d],can't find cfg \n file: [%S] \n in %S module. \n"), err,&fname,&moduleName); |
|
110 LogErrorAndLeaveL(_L("CExecutor::ConstructL"), |
|
111 _L("CStifParser::NewL - Could not create parser"), |
|
112 err); |
|
113 return; |
|
114 } |
|
115 CleanupStack::PushL(parser); |
|
116 |
|
117 ParseTestModulesL(parser, iModuleList, KIncludeModuleStart, |
|
118 KIncludeModuleEnd); |
|
119 |
|
120 CleanupStack::PopAndDestroy(parser); |
|
121 finfo = iModuleList->GetUncheckedCfgFile(); |
|
122 } |
|
123 RDebug::Print(_L("End parsing included modules")); |
|
124 |
|
125 // Create Test Engine |
|
126 RDebug::Print(_L("Creating test engine")); |
|
127 TInt ret = iTestEngine.Connect(); |
|
128 if (ret != KErrNone) |
|
129 { |
|
130 // Log error |
|
131 LogErrorAndLeaveL(_L("CExecutor::ConstructL"), |
|
132 _L("iTestEngine.Connect"), ret); |
|
133 return; |
|
134 } |
|
135 |
|
136 |
|
137 ret = iTestEngine.LoadConfiguration(iParser->EngineIniFile()); |
|
138 |
|
139 if (ret != KErrNone) |
|
140 { |
|
141 iConsole->Printf(_L("\n ErrNo: [%d],can't load engine ini :[%S]. \n"), err,&iParser->EngineIniFile()); |
|
142 |
|
143 // Log error |
|
144 LogErrorAndLeaveL(_L("CExecutor::ConstructL"), |
|
145 _L("iTestEngine.LoadConfiguration"), ret); |
|
146 return; |
|
147 } |
|
148 |
|
149 //update Log Configuration |
|
150 ret = iTestEngine.UpdateLogConfiguration(iParser->LogConfigList()); |
|
151 if (ret != KErrNone) |
|
152 { |
|
153 // Log error |
|
154 LogErrorAndLeaveL(_L("CExecutor::ConstructL"), |
|
155 _L("iTestEngine.UpdateLogConfiguration"), ret); |
|
156 return; |
|
157 } |
|
158 |
|
159 //update Engine Configuration |
|
160 ret = iTestEngine.UpdateEngineConfiguration(iParser->EngineConfigList()); |
|
161 if (ret != KErrNone) |
|
162 { |
|
163 // Log error |
|
164 LogErrorAndLeaveL(_L("CExecutor::ConstructL"), |
|
165 _L("iTestEngine.UpdateEngineConfiguration"), ret); |
|
166 return; |
|
167 } |
|
168 RDebug::Print(_L("End creating test modules")); |
|
169 |
|
170 //Get all test modules loaded via TestFramework.ini |
|
171 //Remove them before load user assiged module. |
|
172 // Enumerate test cases |
|
173 TCaseCount caseCount; |
|
174 TRequestStatus status; |
|
175 iTestEngine.EnumerateTestCases(caseCount, status); |
|
176 User::WaitForRequest(status); |
|
177 |
|
178 // Check that enumerate succeeded |
|
179 if (status != KErrNone) |
|
180 { |
|
181 // Log error |
|
182 LogErrorAndLeaveL(_L("CExecutor::ConstructL"), |
|
183 _L("iTestEngine.EnumerateTestCases"), status.Int()); |
|
184 return; |
|
185 } |
|
186 |
|
187 // Get test cases to buffer |
|
188 CFixedFlatArray<TTestInfo>* casesList = CFixedFlatArray<TTestInfo>::NewL( |
|
189 caseCount()); |
|
190 |
|
191 CleanupStack::PushL(casesList); |
|
192 |
|
193 ret = iTestEngine.GetTestCases(*casesList); |
|
194 if (ret != KErrNone) |
|
195 { |
|
196 // Log error |
|
197 LogErrorAndLeaveL(_L("CExecutor::RunAllTestCasesL"), |
|
198 _L("iTestEngine.GetTestCases"), status.Int()); |
|
199 return; |
|
200 } |
|
201 |
|
202 //remove all exist cases. |
|
203 for(TInt i=0;i<(*casesList).Count();i++) |
|
204 { |
|
205 RDebug::Print((*casesList)[i].iModuleName); |
|
206 iTestEngine.RemoveTestModule((*casesList)[i].iModuleName); |
|
207 iTestEngine.RemoveConfigFile((*casesList)[i].iModuleName, (*casesList)[i].iConfig); |
|
208 } |
|
209 CleanupStack::PopAndDestroy(casesList); |
|
210 |
|
211 |
|
212 // Add all test modules and config files |
|
213 RDebug::Print(_L("Start creating test modules")); |
|
214 moduleInfo = NULL; |
|
215 TInt i; |
|
216 TInt modCnt = iModuleList->Count(); |
|
217 |
|
218 for (i = 0; i < modCnt; i++) |
|
219 { |
|
220 RDebug::Print(_L("Processing module")); |
|
221 // Get module |
|
222 moduleInfo = iModuleList->GetModule(i); |
|
223 if (!moduleInfo) |
|
224 { |
|
225 RDebug::Print(_L("Could not get module info at index %d"), i); |
|
226 continue; |
|
227 } |
|
228 |
|
229 // Get module name |
|
230 TName moduleName; |
|
231 moduleInfo->GetModuleName(moduleName); |
|
232 RDebug::Print(_L("module name: '%S'"), &moduleName); |
|
233 |
|
234 // Get ini file, if exists |
|
235 TFileName ini; |
|
236 moduleInfo->GetIniFileName(ini); |
|
237 if (ini.Length() == 0) |
|
238 { |
|
239 RDebug::Print(_L("ini file not found")); |
|
240 } |
|
241 else |
|
242 { |
|
243 RDebug::Print(_L("ini file: '%S'"), &ini); |
|
244 } |
|
245 |
|
246 // Create test module |
|
247 RDebug::Print(_L("Adding module to test engine")); |
|
248 ret = iTestEngine.AddTestModule(moduleName, ini); |
|
249 if (ret != KErrNone && ret != KErrAlreadyExists) |
|
250 { |
|
251 iConsole->Printf(_L("\n ErrNo: [%d],can't find module: [%S] \n"), ret,&moduleName); |
|
252 LogErrorAndLeaveL(_L("CExecutor::ConstructL"), |
|
253 _L("iTestEngine.AddTestModule"), ret); |
|
254 |
|
255 return; |
|
256 } |
|
257 |
|
258 //Add test case files |
|
259 TInt cfgCnt = moduleInfo->CountCfgFiles(); |
|
260 TInt j; |
|
261 TFileName cfgFile; |
|
262 for (j = 0; j < cfgCnt; j++) |
|
263 { |
|
264 moduleInfo->GetCfgFileName(j, cfgFile); |
|
265 if (cfgFile.Length() > 0) |
|
266 { |
|
267 RDebug::Print(_L("config file: '%S'"), &cfgFile); |
|
268 |
|
269 ret = iTestEngine.AddConfigFile(moduleName, cfgFile); |
|
270 if (ret != KErrNone && ret != KErrAlreadyExists) |
|
271 { |
|
272 |
|
273 // Log error |
|
274 LogErrorAndLeaveL(_L("CExecutor::ConstructL"), |
|
275 _L("RTestEngine::AddConfigFile"), ret); |
|
276 return; |
|
277 } |
|
278 } |
|
279 else |
|
280 { |
|
281 RDebug::Print(_L("Got empty cfg file")); |
|
282 } |
|
283 } |
|
284 if (cfgCnt == 0) |
|
285 { |
|
286 RDebug::Print(_L("cfg file not found")); |
|
287 } |
|
288 |
|
289 RDebug::Print(_L("Module '%S' processed correctly"), &moduleName); |
|
290 } |
|
291 |
|
292 // Enumerate test cases in added module |
|
293 iTestEngine.EnumerateTestCases(caseCount, status); |
|
294 User::WaitForRequest(status); |
|
295 |
|
296 // Check that enumerate succeeded |
|
297 if (status != KErrNone) |
|
298 { |
|
299 // Log error |
|
300 LogErrorAndLeaveL(_L("CExecutor::ConstructL"), |
|
301 _L("iTestEngine.EnumerateTestCases"), status.Int()); |
|
302 return; |
|
303 } |
|
304 |
|
305 iTestCasesList = CFixedFlatArray<TTestInfo>::NewL(caseCount()); |
|
306 ret = iTestEngine.GetTestCases(*iTestCasesList); |
|
307 if (ret != KErrNone) |
|
308 { |
|
309 // Log error |
|
310 LogErrorAndLeaveL(_L("CExecutor::RunAllTestCasesL"), |
|
311 _L("iTestEngine.GetTestCases"), status.Int()); |
|
312 return; |
|
313 } |
|
314 } |
|
315 |
|
316 CExecutor* CExecutor::NewL(CCmdParser* aParser,CConsoleBase* aConsole) |
|
317 { |
|
318 CExecutor* self = new (ELeave) CExecutor(aParser,aConsole); |
|
319 CleanupStack::PushL(self); |
|
320 self->ConstructL(); |
|
321 CleanupStack::Pop(self); |
|
322 return self; |
|
323 } |
|
324 |
|
325 CExecutor::~CExecutor() |
|
326 { |
|
327 iTestEngine.Close(); |
|
328 delete iTestCasesList; |
|
329 delete iModuleList; |
|
330 |
|
331 } |
|
332 |
|
333 void CExecutor::ParseTestModulesL(CStifParser* aParser, |
|
334 CTestModuleList* aModuleList, const TDesC& aSectionStart, |
|
335 const TDesC& aSectionEnd) |
|
336 { |
|
337 //First let's find all modules given in Stif's ini file and store that info in CTestModuleList object |
|
338 CStifSectionParser* sectionParser = NULL; |
|
339 CStifItemParser* item = NULL; |
|
340 |
|
341 sectionParser = aParser->SectionL(aSectionStart, aSectionEnd); |
|
342 |
|
343 while (sectionParser) |
|
344 { |
|
345 RDebug::Print(_L("Found '%S' and '%S' sections"), &aSectionStart, |
|
346 &aSectionEnd); |
|
347 CleanupStack::PushL(sectionParser); |
|
348 RDebug::Print(_L("Starting to read module information")); |
|
349 // Get name of module |
|
350 _LIT(KModuleName, "ModuleName="); |
|
351 item = sectionParser->GetItemLineL(KModuleName); |
|
352 CleanupStack::PushL(item); |
|
353 if (!item) |
|
354 { |
|
355 CleanupStack::PopAndDestroy(item); |
|
356 LogErrorAndLeaveL( |
|
357 _L("CExecutor::ParseTestModulesL"), |
|
358 _L("CStifItemParser::GetItemLineL - line not found from module section"), |
|
359 KErrNotFound); |
|
360 return; |
|
361 } |
|
362 else |
|
363 { |
|
364 RDebug::Print(_L("'%S' found"), &KModuleName); |
|
365 } |
|
366 |
|
367 TPtrC name; |
|
368 TName moduleName; |
|
369 TInt ret(KErrNone); |
|
370 ret = item->GetString(KModuleName, name); |
|
371 if (ret != KErrNone) |
|
372 { |
|
373 CleanupStack::PopAndDestroy(item); |
|
374 LogErrorAndLeaveL( |
|
375 _L("CExecutor::ParseTestModulesL"), |
|
376 _L("CStifItemParser::GetString - Module name parsing left with error"), |
|
377 ret); |
|
378 return; |
|
379 } |
|
380 else |
|
381 { |
|
382 RDebug::Print(_L("Module '%S' found from ini-file"), &name); |
|
383 moduleName.Copy(name); |
|
384 moduleName.LowerCase(); |
|
385 ret = aModuleList->AddTestModule(moduleName); |
|
386 if (ret != KErrNone && ret != KErrAlreadyExists) |
|
387 { |
|
388 LogErrorAndLeaveL( |
|
389 _L("CExecutor::ParseTestModulesL"), |
|
390 _L("CTestModuleList::AddTestModule - Could not add module to list of modules"), |
|
391 ret); |
|
392 return; |
|
393 } |
|
394 } |
|
395 CleanupStack::PopAndDestroy(item); |
|
396 |
|
397 //Get pointer to added module |
|
398 CTestModuleInfo* moduleInfo = aModuleList->GetModule(moduleName); |
|
399 if (!moduleInfo) |
|
400 { |
|
401 LogErrorAndLeaveL( |
|
402 _L("CExecutor::ParseTestModulesL"), |
|
403 _L("CTestModuleList::GetModule - Could not add get module info from list"), |
|
404 KErrNotFound); |
|
405 return; |
|
406 } |
|
407 |
|
408 // Get ini file, if it exists |
|
409 RDebug::Print(_L("Start parsing ini file")); |
|
410 _LIT(KIniFile, "IniFile="); |
|
411 item = sectionParser->GetItemLineL(KIniFile); |
|
412 if (item) |
|
413 { |
|
414 RDebug::Print(_L("'%S' found"), &KIniFile); |
|
415 CleanupStack::PushL(item); |
|
416 TPtrC iniFile; |
|
417 ret = item->GetString(KIniFile, iniFile); |
|
418 if (ret == KErrNone) |
|
419 { |
|
420 RDebug::Print( |
|
421 _L("Initialization file '%S' found, file can be empty"), |
|
422 &iniFile); |
|
423 TFileName filename; |
|
424 filename.Copy(iniFile); |
|
425 filename.LowerCase(); |
|
426 TStifUtil::CorrectFilePathL(filename); |
|
427 moduleInfo->SetIniFile(filename); |
|
428 } |
|
429 else |
|
430 { |
|
431 RDebug::Print(_L("Initialization file not found")); |
|
432 } |
|
433 CleanupStack::PopAndDestroy(item); |
|
434 } |
|
435 else |
|
436 { |
|
437 RDebug::Print(_L("'%S' not found"), &KIniFile); |
|
438 } |
|
439 |
|
440 // Get config (testcase) file |
|
441 RDebug::Print(_L("Start parsing cfg files")); |
|
442 TPtrC cfgTag; |
|
443 for (TInt i = 0; i < 2; i++) |
|
444 { |
|
445 //Set tag for config files |
|
446 if (i == 0) |
|
447 { |
|
448 cfgTag.Set(_L("ConfigFile=")); |
|
449 } |
|
450 else |
|
451 { |
|
452 cfgTag.Set(_L("TestCaseFile=")); |
|
453 } |
|
454 //Read data |
|
455 item = sectionParser->GetItemLineL(cfgTag); |
|
456 while (item) |
|
457 { |
|
458 CleanupStack::PushL(item); |
|
459 RDebug::Print(_L("Item '%S' found"), &cfgTag); |
|
460 TPtrC cfgFile; |
|
461 ret = item->GetString(cfgTag, cfgFile); |
|
462 if (ret == KErrNone) |
|
463 { |
|
464 TFileName ifile; |
|
465 ifile.Copy(cfgFile); |
|
466 ifile.LowerCase(); |
|
467 TStifUtil::CorrectFilePathL(ifile); |
|
468 RDebug::Print(_L("Configuration file '%S' found"), &ifile); |
|
469 moduleInfo->AddCfgFile(ifile); |
|
470 } |
|
471 else |
|
472 { |
|
473 RDebug::Print(_L("Configuration file not found")); |
|
474 } |
|
475 CleanupStack::PopAndDestroy(item); |
|
476 item = sectionParser->GetNextItemLineL(cfgTag); |
|
477 } |
|
478 } |
|
479 |
|
480 RDebug::Print(_L("Module '%S' information read correctly"), |
|
481 &moduleName); |
|
482 |
|
483 // Get next section |
|
484 CleanupStack::PopAndDestroy(sectionParser); |
|
485 sectionParser = aParser->NextSectionL(aSectionStart, aSectionEnd); |
|
486 } |
|
487 } |
|
488 |
|
489 void CExecutor::RunTestsL() |
|
490 { |
|
491 RunAllTestCasesL(); |
|
492 |
|
493 // Remove test module |
|
494 RDebug::Print(_L("Start removing test modules")); |
|
495 CTestModuleInfo* moduleInfo = NULL; |
|
496 TInt i; |
|
497 TInt modCnt = iModuleList->Count(); |
|
498 |
|
499 for (i = 0; i < modCnt; i++) |
|
500 { |
|
501 RDebug::Print(_L("Processing module")); |
|
502 // Get module |
|
503 moduleInfo = iModuleList->GetModule(i); |
|
504 if (!moduleInfo) |
|
505 { |
|
506 RDebug::Print(_L("Could not get module info at index %d"), i); |
|
507 continue; |
|
508 } |
|
509 |
|
510 // Get module name |
|
511 TName moduleName; |
|
512 moduleInfo->GetModuleName(moduleName); |
|
513 RDebug::Print(_L("module name: '%S'"), &moduleName); |
|
514 |
|
515 // Remove test module |
|
516 User::LeaveIfError(iTestEngine.RemoveTestModule(moduleName)); |
|
517 RDebug::Print(_L("Module '%S' removed"), &moduleName); |
|
518 } |
|
519 |
|
520 RDebug::Print(_L("End removing test modules")); |
|
521 } |
|
522 |
|
523 void CExecutor::RunAllTestCasesL() |
|
524 { |
|
525 |
|
526 RArray<TName> testCasesTitleList; |
|
527 CleanupClosePushL(testCasesTitleList); |
|
528 |
|
529 for(TInt i=0;i<iTestCasesList->Count();i++) |
|
530 { |
|
531 TName title; |
|
532 title.Append((*iTestCasesList)[i].iTestCaseInfo.iTitle); |
|
533 testCasesTitleList.Append(title); |
|
534 } |
|
535 |
|
536 |
|
537 for(TInt i=0;i<iParser->TestCaseIndexList().Count();i++) |
|
538 { |
|
539 |
|
540 if(iParser->TestCaseIndexList()[i]>=testCasesTitleList.Count()) |
|
541 { |
|
542 iConsole->Printf(_L("\ncase No.[%d] doesn't exist\n"),iParser->TestCaseIndexList()[i]); |
|
543 } |
|
544 } |
|
545 |
|
546 |
|
547 for(TInt i=0;i<iParser->TestCaseList().Count();i++) |
|
548 { |
|
549 |
|
550 TBool isfound(EFalse); |
|
551 for(TInt j=0;j<testCasesTitleList.Count();j++) |
|
552 { |
|
553 if(iParser->TestCaseList()[i].Compare(testCasesTitleList[j])==KErrNone) |
|
554 { |
|
555 isfound=ETrue; |
|
556 } |
|
557 |
|
558 } |
|
559 if(!isfound) |
|
560 { |
|
561 iConsole->Printf(_L("\ncase [%S] doesn't exist\n"),&iParser->TestCaseList()[i]); |
|
562 } |
|
563 |
|
564 |
|
565 } |
|
566 |
|
567 |
|
568 //variables used to get version of STIF |
|
569 TInt majorV; |
|
570 TInt minorV; |
|
571 TInt buildV; |
|
572 TBuf<30> relDate; |
|
573 TStifUtil::STIFVersion(majorV, minorV, buildV, relDate); |
|
574 |
|
575 TBuf<50> version; |
|
576 version.Format(_L("STF v%d.%d.%d - "), majorV, minorV, buildV); |
|
577 version.Append(relDate); |
|
578 version.Append(_L("\n")); |
|
579 |
|
580 iConsole->Printf(version); //printing STIF version information (version and release date) |
|
581 |
|
582 TInt caseNum = iParser->CaseCount(); |
|
583 if (caseNum == 0) |
|
584 { |
|
585 caseNum = iTestCasesList->Count(); |
|
586 } |
|
587 |
|
588 iConsole->Printf(_L("Test case count: [%d]\n\n"), caseNum); |
|
589 |
|
590 // Loop through all test cases in buffer and run them |
|
591 const TInt count = iTestCasesList->Count(); |
|
592 if (iParser->CaseCount() == 0) |
|
593 { |
|
594 //execute all |
|
595 for (TInt i = 0; i < count; i++) |
|
596 { |
|
597 #ifdef _DEBUG |
|
598 RDebug::Print((*iTestCasesList)[i].iTestCaseInfo.iTitle); |
|
599 #endif |
|
600 iConsole->Printf(_L("Now running test case: [%d] [%S] "), i, |
|
601 &(*iTestCasesList)[i].iTestCaseInfo.iTitle); |
|
602 |
|
603 // Run test case |
|
604 RunTestCaseL((*iTestCasesList)[i]); |
|
605 } |
|
606 } |
|
607 else |
|
608 { |
|
609 for (TInt i = 0; i < count; i++) |
|
610 { |
|
611 if (iParser->CaseContains(i, (*iTestCasesList)[i].iTestCaseInfo.iTitle)) |
|
612 { |
|
613 #ifdef _DEBUG |
|
614 RDebug::Print((*iTestCasesList)[i].iTestCaseInfo.iTitle); |
|
615 #endif |
|
616 iConsole->Printf(_L("Now running test case: [%d] [%S] "), |
|
617 i, &(*iTestCasesList)[i].iTestCaseInfo.iTitle); |
|
618 // Run test case |
|
619 RunTestCaseL((*iTestCasesList)[i]); |
|
620 } |
|
621 } |
|
622 } |
|
623 |
|
624 CleanupStack::PopAndDestroy(&testCasesTitleList); |
|
625 } |
|
626 |
|
627 void CExecutor::RunTestCaseL(TTestInfo& aTestInfo) |
|
628 { |
|
629 TInt testResult(KErrNone); |
|
630 CCaseRunner* runner; |
|
631 // Trap to catch errors from test case executing |
|
632 TRAPD( trapError, runner = CCaseRunner::NewL( this, aTestInfo ); |
|
633 CleanupStack::PushL( runner ); |
|
634 |
|
635 testResult = RunATestCaseL( runner ); |
|
636 |
|
637 CleanupStack::PopAndDestroy( runner ); |
|
638 ); |
|
639 |
|
640 if (trapError != KErrNone) |
|
641 { |
|
642 testResult = trapError; |
|
643 } |
|
644 |
|
645 if (testResult != KErrNone) // Test case is FAILED |
|
646 { |
|
647 // Test case failed, print out the error |
|
648 iConsole->Printf(_L("\nTest case FAILED! err=[%d]\n"), testResult); |
|
649 } |
|
650 |
|
651 else // Test case is PASSED |
|
652 { |
|
653 iConsole->Printf(_L("\nTest case PASSED!\n")); |
|
654 testResult = KErrNone; |
|
655 } |
|
656 } |
|
657 |
|
658 TInt CExecutor::RunATestCaseL(CCaseRunner* aCaseRunner) |
|
659 { |
|
660 iTestCompletedError = KErrNone; |
|
661 |
|
662 // Create timer |
|
663 CActiveTimer* timer = CActiveTimer::NewL(iConsole); |
|
664 CleanupStack::PushL(timer); |
|
665 |
|
666 // Start test case and timer |
|
667 aCaseRunner->StartTestL(); |
|
668 timer->StartL(); |
|
669 |
|
670 // Wait for test case completed |
|
671 CActiveScheduler::Start(); |
|
672 |
|
673 timer->Cancel(); |
|
674 CleanupStack::PopAndDestroy(timer); |
|
675 |
|
676 // test completion error is set in TestCompleted method |
|
677 return iTestCompletedError; |
|
678 } |
|
679 |
|
680 RTestEngine& CExecutor::TestEngine() |
|
681 { |
|
682 return iTestEngine; |
|
683 } |
|
684 |
|
685 void CExecutor::TestCompleted(TInt aError) |
|
686 { |
|
687 iTestCompletedError = aError; |
|
688 CActiveScheduler::Stop(); |
|
689 |
|
690 } |
|
691 |
|
692 void CExecutor::LogErrorAndLeaveL(const TDesC& aFunction, |
|
693 const TDesC& aDescription, const TInt aError) |
|
694 { |
|
695 RDebug::Print(_L("%S: %S [%d]"), &aFunction, &aDescription, aError); |
|
696 User::Leave(aError); |
|
697 } |
|
698 |