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: CATSInterface: This object executes test cases from |
|
15 * STIF Test Framework. |
|
16 * |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 #include <e32cons.h> |
|
22 #include <e32svr.h> |
|
23 #include "ATSInterface.h" |
|
24 #include "ATSInterfaceRunner.h" |
|
25 |
|
26 #include "StifTestInterface.h" |
|
27 |
|
28 |
|
29 // EXTERNAL DATA STRUCTURES |
|
30 // None |
|
31 |
|
32 // EXTERNAL FUNCTION PROTOTYPES |
|
33 // None |
|
34 |
|
35 // CONSTANTS |
|
36 // None |
|
37 |
|
38 // MACROS |
|
39 // None |
|
40 |
|
41 // LOCAL CONSTANTS AND MACROS |
|
42 // None |
|
43 |
|
44 // MODULE DATA STRUCTURES |
|
45 // None |
|
46 |
|
47 // LOCAL FUNCTION PROTOTYPES |
|
48 // None |
|
49 |
|
50 // FORWARD DECLARATIONS |
|
51 // None |
|
52 |
|
53 // ==================== LOCAL FUNCTIONS ======================================= |
|
54 // None |
|
55 |
|
56 // ================= MEMBER FUNCTIONS ========================================= |
|
57 |
|
58 |
|
59 // ================= MEMBER FUNCTIONS ========================================= |
|
60 |
|
61 |
|
62 /* |
|
63 ------------------------------------------------------------------------------- |
|
64 |
|
65 Class: CATSInterface |
|
66 |
|
67 Method: CATSInterface |
|
68 |
|
69 Description: Default constructor |
|
70 |
|
71 C++ default constructor can NOT contain any code, that |
|
72 might leave. |
|
73 |
|
74 Parameters: None |
|
75 |
|
76 Return Values: None |
|
77 |
|
78 Errors/Exceptions: None |
|
79 |
|
80 Status: Approved |
|
81 |
|
82 ------------------------------------------------------------------------------- |
|
83 */ |
|
84 CATSInterface::CATSInterface() |
|
85 { |
|
86 // Initialize buffers to zero |
|
87 iEngineIniFile.Zero(); |
|
88 iModuleIniFile.Zero(); |
|
89 iConfigFile.Zero(); |
|
90 iTestModule.Zero(); |
|
91 |
|
92 } |
|
93 |
|
94 |
|
95 /* |
|
96 ------------------------------------------------------------------------------- |
|
97 |
|
98 Class: CATSInterface |
|
99 |
|
100 Method: ConstructL |
|
101 |
|
102 Description: Symbian OS second phase constructor |
|
103 |
|
104 Symbian OS default constructor can leave. |
|
105 |
|
106 Parameters: None |
|
107 |
|
108 Return Values: None |
|
109 |
|
110 Errors/Exceptions: Leaves if some of called leaving functions leaves |
|
111 Leaves each time the LogErrorAndLeaveL is called |
|
112 |
|
113 Status: Proposal |
|
114 |
|
115 ------------------------------------------------------------------------------- |
|
116 */ |
|
117 void CATSInterface::ConstructL() |
|
118 { |
|
119 RDebug::Print(_L("Creating module list object")); |
|
120 TRAPD(err, iModuleList = CTestModuleList::NewL(NULL)); |
|
121 if(err != KErrNone) |
|
122 { |
|
123 LogErrorAndLeaveL(_L("CATSInterface::ConstructL"), _L("CTestModuleList::NewL"), err); |
|
124 return; |
|
125 } |
|
126 if(!iModuleList) |
|
127 { |
|
128 LogErrorAndLeaveL(_L("CATSInterface::ConstructL"), _L("CTestModuleList::NewL - iModuleList is NULL"), KErrGeneral); |
|
129 return; |
|
130 } |
|
131 |
|
132 // Read command line |
|
133 ParseCommandLineL(); |
|
134 |
|
135 // Add to module list info about module taken from command line |
|
136 RDebug::Print(_L("Adding command line module to list")); |
|
137 TName moduleName; |
|
138 moduleName.Copy(iTestModule); |
|
139 moduleName.LowerCase(); |
|
140 err = iModuleList->AddTestModule(moduleName); |
|
141 if(err != KErrNone && err != KErrAlreadyExists) |
|
142 { |
|
143 LogErrorAndLeaveL(_L("CATSInterface::ConstructL"), _L("CTestModuleList::AddTestModule - Could not add module to list of modules"), err); |
|
144 return; |
|
145 } |
|
146 |
|
147 //Get added module |
|
148 CTestModuleInfo* moduleInfo = iModuleList->GetModule(moduleName); |
|
149 if(!moduleInfo) |
|
150 { |
|
151 LogErrorAndLeaveL(_L("CATSInterface::ConstructL"), _L("CTestModuleList::GetModule - Could not add get module info from list"), KErrGeneral); |
|
152 return; |
|
153 } |
|
154 |
|
155 //Add ini file if given |
|
156 if(iModuleIniFile.Length() > 0) |
|
157 { |
|
158 TFileName filename; |
|
159 filename.Copy(iModuleIniFile); |
|
160 filename.LowerCase(); |
|
161 moduleInfo->SetIniFile(filename); |
|
162 } |
|
163 |
|
164 //Add config file if given |
|
165 if(iConfigFile.Length() > 0) |
|
166 { |
|
167 TFileName filename; |
|
168 filename.Copy(iConfigFile); |
|
169 filename.LowerCase(); |
|
170 moduleInfo->AddCfgFile(filename); |
|
171 } |
|
172 |
|
173 //Now check all config files if there are included modules |
|
174 _LIT(KIncludeModuleStart, "[New_Include_Module]"); |
|
175 _LIT(KIncludeModuleEnd, "[End_Include_Module]"); |
|
176 |
|
177 RDebug::Print(_L("Start parsing included modules")); |
|
178 CTestCaseFileInfo* finfo = iModuleList->GetUncheckedCfgFile(); |
|
179 while(finfo) |
|
180 { |
|
181 TFileName fname; |
|
182 finfo->GetCfgFileName(fname); |
|
183 |
|
184 RDebug::Print(_L("Checking file: '%S'"), &fname); |
|
185 finfo->SetChecked(); |
|
186 |
|
187 CStifParser* parser = NULL; |
|
188 |
|
189 TRAP(err, parser = CStifParser::NewL(_L(""), fname)); |
|
190 if(err != KErrNone) |
|
191 { |
|
192 LogErrorAndLeaveL(_L("CATSInterface::ConstructL"), _L("CStifParser::NewL - Could not create parser"), err); |
|
193 return; |
|
194 } |
|
195 CleanupStack::PushL(parser); |
|
196 |
|
197 ParseTestModulesL(parser, iModuleList, KIncludeModuleStart, KIncludeModuleEnd); |
|
198 |
|
199 CleanupStack::PopAndDestroy(parser); |
|
200 finfo = iModuleList->GetUncheckedCfgFile(); |
|
201 } |
|
202 RDebug::Print(_L("End parsing included modules")); |
|
203 |
|
204 // Create Test Engine |
|
205 RDebug::Print(_L("Creating test engine")); |
|
206 TInt ret = iTestEngineServ.Connect(); |
|
207 if ( ret != KErrNone ) |
|
208 { |
|
209 // Log error |
|
210 LogErrorAndLeaveL( _L("CATSInterface::ConstructL"), _L("iTestEngineServ.Connect"), ret ); |
|
211 return; |
|
212 } |
|
213 |
|
214 ret = iTestEngine.Open( iTestEngineServ, iEngineIniFile ); |
|
215 if ( ret != KErrNone ) |
|
216 { |
|
217 // Log error |
|
218 LogErrorAndLeaveL( _L("CATSInterface::ConstructL"), _L("iTestEngine.Open"), ret ); |
|
219 return; |
|
220 } |
|
221 |
|
222 /* |
|
223 // Add test module |
|
224 ret = iTestEngine.AddTestModule( iTestModule, iModuleIniFile ); |
|
225 if ( ret != KErrNone && ret != KErrAlreadyExists ) |
|
226 { |
|
227 // Log error |
|
228 LogErrorAndLeaveL( _L("CATSInterface::ConstructL"), _L("iTestEngine.AddTestModule"), ret ); |
|
229 return; |
|
230 } |
|
231 */ |
|
232 // Add all test modules and config files |
|
233 RDebug::Print(_L("Start creating test modules")); |
|
234 moduleInfo = NULL; |
|
235 TInt i; |
|
236 TInt modCnt = iModuleList->Count(); |
|
237 |
|
238 for(i = 0; i < modCnt; i++) |
|
239 { |
|
240 RDebug::Print(_L("Processing module")); |
|
241 // Get module |
|
242 moduleInfo = iModuleList->GetModule(i); |
|
243 if(!moduleInfo) |
|
244 { |
|
245 RDebug::Print(_L("Could not get module info at index %d"), i); |
|
246 continue; |
|
247 } |
|
248 |
|
249 // Get module name |
|
250 TName moduleName; |
|
251 moduleInfo->GetModuleName(moduleName); |
|
252 RDebug::Print(_L("module name: '%S'"), &moduleName); |
|
253 |
|
254 // Get ini file, if exists |
|
255 TFileName ini; |
|
256 moduleInfo->GetIniFileName(ini); |
|
257 if(ini.Length() == 0) |
|
258 { |
|
259 RDebug::Print(_L("ini file not found")); |
|
260 } |
|
261 else |
|
262 { |
|
263 RDebug::Print(_L("ini file: '%S'"), &ini); |
|
264 } |
|
265 |
|
266 // Create test module |
|
267 RDebug::Print(_L("Adding module to test engine")); |
|
268 ret = iTestEngine.AddTestModule(moduleName, ini); |
|
269 if(ret != KErrNone && ret != KErrAlreadyExists) |
|
270 { |
|
271 LogErrorAndLeaveL(_L("CATSInterface::ConstructL"), _L("iTestEngine.AddTestModule"), ret); |
|
272 return; |
|
273 } |
|
274 |
|
275 //Add test case files |
|
276 TInt cfgCnt = moduleInfo->CountCfgFiles(); |
|
277 TInt j; |
|
278 TFileName cfgFile; |
|
279 for(j = 0; j < cfgCnt; j++) |
|
280 { |
|
281 moduleInfo->GetCfgFileName(j, cfgFile); |
|
282 if(cfgFile.Length() > 0) |
|
283 { |
|
284 RDebug::Print(_L("config file: '%S'"), &cfgFile); |
|
285 |
|
286 ret = iTestEngine.AddConfigFile(moduleName, cfgFile); |
|
287 if(ret != KErrNone && ret != KErrAlreadyExists) |
|
288 { |
|
289 // Log error |
|
290 LogErrorAndLeaveL(_L("CATSInterface::ConstructL"), _L("RTestEngine::AddConfigFile"), ret); |
|
291 return; |
|
292 } |
|
293 } |
|
294 else |
|
295 { |
|
296 RDebug::Print(_L("Got empty cfg file")); |
|
297 } |
|
298 } |
|
299 if(cfgCnt == 0) |
|
300 { |
|
301 RDebug::Print(_L("cfg file not found")); |
|
302 } |
|
303 |
|
304 RDebug::Print(_L("Module '%S' processed correctly"), &moduleName); |
|
305 } |
|
306 |
|
307 RDebug::Print(_L("End creating test modules")); |
|
308 |
|
309 // Create console screen |
|
310 iConsole = Console::NewL( |
|
311 iTestModule, TSize( KConsFullScreen, KConsFullScreen ) ); |
|
312 } |
|
313 |
|
314 |
|
315 /* |
|
316 ------------------------------------------------------------------------------- |
|
317 |
|
318 Class: CATSInterface |
|
319 |
|
320 Method: NewL |
|
321 |
|
322 Description: Two-phased constructor. |
|
323 |
|
324 Parameters: None |
|
325 |
|
326 Return Values: CATSInterface* : pointer to created CATSInterface object |
|
327 |
|
328 Errors/Exceptions: Leaves if memory allocation for CATSInterface fails |
|
329 Leaves if ConstructL leaves |
|
330 |
|
331 Status: Approved |
|
332 |
|
333 ------------------------------------------------------------------------------- |
|
334 */ |
|
335 CATSInterface* CATSInterface::NewL() |
|
336 { |
|
337 // Create CATSInterface and return it |
|
338 CATSInterface* self = new ( ELeave ) CATSInterface(); |
|
339 CleanupStack::PushL( self ); |
|
340 self->ConstructL(); |
|
341 CleanupStack::Pop(); |
|
342 return self; |
|
343 } |
|
344 |
|
345 |
|
346 /* |
|
347 ------------------------------------------------------------------------------- |
|
348 |
|
349 Class: CATSInterface |
|
350 |
|
351 Method: ~CATSInterface |
|
352 |
|
353 Description: Destructor |
|
354 |
|
355 Parameters: None |
|
356 |
|
357 Return Values: None |
|
358 |
|
359 Errors/Exceptions: None |
|
360 |
|
361 Status: Approved |
|
362 |
|
363 ------------------------------------------------------------------------------- |
|
364 */ |
|
365 CATSInterface::~CATSInterface() |
|
366 { |
|
367 // Close Test Engine |
|
368 iTestEngine.Close(); |
|
369 iTestEngineServ.Close(); |
|
370 |
|
371 delete iModuleList; |
|
372 delete iConsole; |
|
373 |
|
374 } |
|
375 |
|
376 /* |
|
377 ------------------------------------------------------------------------------- |
|
378 |
|
379 Class: CATSInterface |
|
380 |
|
381 Method: ParseTestModulesL |
|
382 |
|
383 Description: Parse and search for module info and fill list of modules. |
|
384 |
|
385 Parameters: CStifParser* aParser: in: CStifParser object |
|
386 CTestModuleList* aModuleList: in: list of modules |
|
387 TPtrC& aSectionStart: in: descriptor with start of section string |
|
388 TPTrC& aSectionEnd: in: descriptor with end of section string |
|
389 |
|
390 Return Values: None |
|
391 |
|
392 Errors/Exceptions: Leaves if some of called leaving methods leaves |
|
393 |
|
394 Status: Approved |
|
395 |
|
396 ------------------------------------------------------------------------------- |
|
397 */ |
|
398 void CATSInterface::ParseTestModulesL(CStifParser* aParser, CTestModuleList* aModuleList, const TDesC& aSectionStart, const TDesC& aSectionEnd) |
|
399 { |
|
400 //First let's find all modules given in Stif's ini file and store that info in CTestModuleList object |
|
401 CStifSectionParser* sectionParser = NULL; |
|
402 CStifItemParser* item = NULL; |
|
403 |
|
404 sectionParser = aParser->SectionL(aSectionStart, aSectionEnd); |
|
405 |
|
406 while(sectionParser) |
|
407 { |
|
408 RDebug::Print(_L("Found '%S' and '%S' sections"), &aSectionStart, &aSectionEnd); |
|
409 CleanupStack::PushL(sectionParser); |
|
410 RDebug::Print(_L("Starting to read module information")); |
|
411 |
|
412 // Get name of module |
|
413 _LIT(KModuleName, "ModuleName="); |
|
414 item = sectionParser->GetItemLineL(KModuleName); |
|
415 CleanupStack::PushL(item); |
|
416 if(!item) |
|
417 { |
|
418 CleanupStack::PopAndDestroy(item); |
|
419 LogErrorAndLeaveL(_L("CATSInterface::ParseTestModulesL"), _L("CStifItemParser::GetItemLineL - line not found from module section"), KErrNotFound); |
|
420 return; |
|
421 } |
|
422 else |
|
423 { |
|
424 RDebug::Print(_L("'%S' found"), &KModuleName); |
|
425 } |
|
426 |
|
427 TPtrC name; |
|
428 TName moduleName; |
|
429 TInt ret(KErrNone); |
|
430 ret = item->GetString(KModuleName, name); |
|
431 if(ret != KErrNone) |
|
432 { |
|
433 CleanupStack::PopAndDestroy(item); |
|
434 LogErrorAndLeaveL(_L("CATSInterface::ParseTestModulesL"), _L("CStifItemParser::GetString - Module name parsing left with error"), ret); |
|
435 return; |
|
436 } |
|
437 else |
|
438 { |
|
439 RDebug::Print(_L("Module '%S' found from ini-file"), &name); |
|
440 moduleName.Copy(name); |
|
441 moduleName.LowerCase(); |
|
442 ret = aModuleList->AddTestModule(moduleName); |
|
443 if(ret != KErrNone && ret != KErrAlreadyExists) |
|
444 { |
|
445 LogErrorAndLeaveL(_L("CATSInterface::ParseTestModulesL"), _L("CTestModuleList::AddTestModule - Could not add module to list of modules"), ret); |
|
446 return; |
|
447 } |
|
448 } |
|
449 CleanupStack::PopAndDestroy(item); |
|
450 |
|
451 //Get pointer to added module |
|
452 CTestModuleInfo* moduleInfo = aModuleList->GetModule(moduleName); |
|
453 if(!moduleInfo) |
|
454 { |
|
455 LogErrorAndLeaveL(_L("CATSInterface::ParseTestModulesL"), _L("CTestModuleList::GetModule - Could not add get module info from list"), KErrNotFound); |
|
456 return; |
|
457 } |
|
458 |
|
459 // Get ini file, if it exists |
|
460 RDebug::Print(_L("Start parsing ini file")); |
|
461 _LIT(KIniFile, "IniFile="); |
|
462 item = sectionParser->GetItemLineL(KIniFile); |
|
463 if(item) |
|
464 { |
|
465 RDebug::Print(_L("'%S' found"), &KIniFile); |
|
466 CleanupStack::PushL(item); |
|
467 TPtrC iniFile; |
|
468 ret = item->GetString(KIniFile, iniFile); |
|
469 if(ret == KErrNone) |
|
470 { |
|
471 RDebug::Print(_L("Initialization file '%S' found, file can be empty"), &iniFile); |
|
472 TFileName filename; |
|
473 filename.Copy(iniFile); |
|
474 filename.LowerCase(); |
|
475 TStifUtil::CorrectFilePathL( filename ); |
|
476 moduleInfo->SetIniFile(filename); |
|
477 } |
|
478 else |
|
479 { |
|
480 RDebug::Print(_L("Initialization file not found")); |
|
481 } |
|
482 CleanupStack::PopAndDestroy(item); |
|
483 } |
|
484 else |
|
485 { |
|
486 RDebug::Print(_L("'%S' not found"), &KIniFile); |
|
487 } |
|
488 |
|
489 // Get config (testcase) file |
|
490 RDebug::Print(_L("Start parsing cfg files")); |
|
491 TPtrC cfgTag; |
|
492 for(TInt i = 0; i < 2; i++) |
|
493 { |
|
494 //Set tag for config files |
|
495 if(i == 0) |
|
496 { |
|
497 cfgTag.Set(_L("ConfigFile=")); |
|
498 } |
|
499 else |
|
500 { |
|
501 cfgTag.Set(_L("TestCaseFile=")); |
|
502 } |
|
503 //Read data |
|
504 item = sectionParser->GetItemLineL(cfgTag); |
|
505 while(item) |
|
506 { |
|
507 CleanupStack::PushL(item); |
|
508 RDebug::Print(_L("Item '%S' found"), &cfgTag); |
|
509 TPtrC cfgFile; |
|
510 ret = item->GetString(cfgTag, cfgFile); |
|
511 if(ret == KErrNone) |
|
512 { |
|
513 TFileName ifile; |
|
514 ifile.Copy(cfgFile); |
|
515 ifile.LowerCase(); |
|
516 TStifUtil::CorrectFilePathL( ifile ); |
|
517 RDebug::Print(_L("Configuration file '%S' found"), &ifile); |
|
518 moduleInfo->AddCfgFile(ifile); |
|
519 } |
|
520 else |
|
521 { |
|
522 RDebug::Print(_L("Configuration file not found")); |
|
523 } |
|
524 CleanupStack::PopAndDestroy(item); |
|
525 item = sectionParser->GetNextItemLineL(cfgTag); |
|
526 } |
|
527 } |
|
528 |
|
529 RDebug::Print(_L("Module '%S' information read correctly"), &moduleName); |
|
530 |
|
531 // Get next section |
|
532 CleanupStack::PopAndDestroy(sectionParser); |
|
533 sectionParser = aParser->NextSectionL(aSectionStart, aSectionEnd); |
|
534 } |
|
535 } |
|
536 |
|
537 /* |
|
538 ------------------------------------------------------------------------------- |
|
539 |
|
540 Class: CATSInterface |
|
541 |
|
542 Method: ParseCommandLineL |
|
543 |
|
544 Description: Parse command line parameters |
|
545 |
|
546 Parameters: None |
|
547 |
|
548 Return Values: None |
|
549 |
|
550 Errors/Exceptions: Leaves if module name not found from command line |
|
551 |
|
552 Status: Approved |
|
553 |
|
554 ------------------------------------------------------------------------------- |
|
555 */ |
|
556 void CATSInterface::ParseCommandLineL() |
|
557 { |
|
558 // Command line params |
|
559 _LIT( KTestModule, "-testmodule" ); |
|
560 _LIT( KConfigFile, "-config" ); |
|
561 _LIT( KEngineIniFile, "-engineini" ); |
|
562 _LIT( KModuleIniFile, "-moduleini" ); |
|
563 |
|
564 const TInt length = User::CommandLineLength(); |
|
565 |
|
566 HBufC* cmdLine = HBufC::NewLC( length ); |
|
567 TPtr ptr = cmdLine->Des(); |
|
568 |
|
569 User::CommandLine( ptr ); |
|
570 |
|
571 TBool moduleFound( EFalse ); |
|
572 TLex lex( ptr ); |
|
573 // Parse the command line |
|
574 while ( !lex.Eos() ) |
|
575 { |
|
576 TPtrC tmpPtr = lex.NextToken(); |
|
577 // Check the test module name |
|
578 if ( tmpPtr == KTestModule ) |
|
579 { |
|
580 TPtrC module = lex.NextToken(); |
|
581 if ( module.Ptr() ) |
|
582 { |
|
583 iTestModule.Copy( module ); |
|
584 moduleFound = ETrue; |
|
585 } |
|
586 } |
|
587 // Check the module's config file |
|
588 else if ( tmpPtr == KConfigFile ) |
|
589 { |
|
590 TPtrC config = lex.NextToken(); |
|
591 if ( config.Ptr() ) |
|
592 { |
|
593 iConfigFile.Copy( config ); |
|
594 TStifUtil::CorrectFilePathL( iConfigFile ); |
|
595 } |
|
596 } |
|
597 // Check the engine's ini file |
|
598 else if ( tmpPtr == KEngineIniFile ) |
|
599 { |
|
600 TPtrC iniFile = lex.NextToken(); |
|
601 if ( iniFile.Ptr() ) |
|
602 { |
|
603 iEngineIniFile.Copy( iniFile ); |
|
604 TStifUtil::CorrectFilePathL( iEngineIniFile ); |
|
605 } |
|
606 } |
|
607 // Check the module's ini file |
|
608 else if ( tmpPtr == KModuleIniFile ) |
|
609 { |
|
610 TPtrC iniFile = lex.NextToken(); |
|
611 if ( iniFile.Ptr() ) |
|
612 { |
|
613 iModuleIniFile.Copy( iniFile ); |
|
614 TStifUtil::CorrectFilePathL( iModuleIniFile ); |
|
615 } |
|
616 } |
|
617 else |
|
618 { |
|
619 // Skip unknown commands |
|
620 } |
|
621 } // while |
|
622 |
|
623 // Destroy command line buffer |
|
624 CleanupStack::PopAndDestroy( cmdLine ); |
|
625 |
|
626 // Module name has to exists |
|
627 if ( !moduleFound ) |
|
628 { |
|
629 User::Leave( KErrArgument ); |
|
630 } |
|
631 } |
|
632 |
|
633 |
|
634 /* |
|
635 ------------------------------------------------------------------------------- |
|
636 |
|
637 Class: CATSInterface |
|
638 |
|
639 Method: RunTestsL |
|
640 |
|
641 Description: Starts testing |
|
642 |
|
643 Parameters: None |
|
644 |
|
645 Return Values: None |
|
646 |
|
647 Errors/Exceptions: Leaves if RunAllTestCasesL leaves |
|
648 Leaves if RemoveTestModule returns error |
|
649 |
|
650 Status: Approved |
|
651 |
|
652 ------------------------------------------------------------------------------- |
|
653 */ |
|
654 void CATSInterface::RunTestsL() |
|
655 { |
|
656 // Run all test cases |
|
657 RunAllTestCasesL(); |
|
658 |
|
659 /* |
|
660 // Remove test module |
|
661 User::LeaveIfError( iTestEngine.RemoveTestModule( iTestModule ) ); |
|
662 */ |
|
663 RDebug::Print(_L("Start removing test modules")); |
|
664 CTestModuleInfo* moduleInfo = NULL; |
|
665 TInt i; |
|
666 TInt modCnt = iModuleList->Count(); |
|
667 |
|
668 for(i = 0; i < modCnt; i++) |
|
669 { |
|
670 RDebug::Print(_L("Processing module")); |
|
671 // Get module |
|
672 moduleInfo = iModuleList->GetModule(i); |
|
673 if(!moduleInfo) |
|
674 { |
|
675 RDebug::Print(_L("Could not get module info at index %d"), i); |
|
676 continue; |
|
677 } |
|
678 |
|
679 // Get module name |
|
680 TName moduleName; |
|
681 moduleInfo->GetModuleName(moduleName); |
|
682 RDebug::Print(_L("module name: '%S'"), &moduleName); |
|
683 |
|
684 // Remove test module |
|
685 User::LeaveIfError(iTestEngine.RemoveTestModule(moduleName)); |
|
686 RDebug::Print(_L("Module '%S' removed"), &moduleName); |
|
687 } |
|
688 |
|
689 RDebug::Print(_L("End removing test modules")); |
|
690 } |
|
691 |
|
692 /* |
|
693 ------------------------------------------------------------------------------- |
|
694 |
|
695 Class: CATSInterface |
|
696 |
|
697 Method: RunAllTestCasesL |
|
698 |
|
699 Description: Run all test cases from test module. |
|
700 |
|
701 Parameters: None |
|
702 |
|
703 Return Values: None |
|
704 |
|
705 Errors/Exceptions: Leaves if some of called leaving methods leaves |
|
706 |
|
707 Status: Proposal |
|
708 |
|
709 ------------------------------------------------------------------------------- |
|
710 */ |
|
711 void CATSInterface::RunAllTestCasesL() |
|
712 { |
|
713 TInt ret( KErrNone ); |
|
714 |
|
715 /* |
|
716 // Add given config file to test module |
|
717 if ( iConfigFile.Length() > 0 ) |
|
718 { |
|
719 ret = iTestEngine.AddConfigFile( iTestModule, iConfigFile ); |
|
720 if ( ret != KErrNone && ret != KErrAlreadyExists ) |
|
721 { |
|
722 // Log error |
|
723 LogErrorAndLeaveL( _L("CATSInterface::RunAllTestCasesL"), _L("iTestEngine.AddConfigFile"), ret ); |
|
724 return; |
|
725 } |
|
726 } |
|
727 */ |
|
728 |
|
729 // Enumerate test cases |
|
730 TCaseCount caseCount; |
|
731 TRequestStatus status; |
|
732 iTestEngine.EnumerateTestCases( caseCount, status ); |
|
733 User::WaitForRequest( status ); |
|
734 |
|
735 // Check that enumerate succeeded |
|
736 if ( status != KErrNone ) |
|
737 { |
|
738 // Log error |
|
739 LogErrorAndLeaveL( _L("CATSInterface::RunAllTestCasesL"), _L("iTestEngine.EnumerateTestCases"), status.Int() ); |
|
740 return; |
|
741 } |
|
742 |
|
743 // Get test cases to buffer |
|
744 CFixedFlatArray<TTestInfo>* testCases = |
|
745 CFixedFlatArray<TTestInfo>::NewL( caseCount() ); |
|
746 CleanupStack::PushL( testCases ); |
|
747 |
|
748 ret = iTestEngine.GetTestCases( *testCases ); |
|
749 if ( ret != KErrNone ) |
|
750 { |
|
751 // Log error |
|
752 LogErrorAndLeaveL( _L("CATSInterface::RunAllTestCasesL"), _L("iTestEngine.GetTestCases"), status.Int() ); |
|
753 return; |
|
754 } |
|
755 |
|
756 //variables used to get version of STIF |
|
757 TInt majorV; |
|
758 TInt minorV; |
|
759 TInt buildV; |
|
760 TBuf<30> relDate; |
|
761 TStifUtil::STIFVersion(majorV, minorV, buildV, relDate); |
|
762 |
|
763 TBuf<50> version; |
|
764 version.Format(_L("STIF v%d.%d.%d - "), majorV, minorV, buildV); |
|
765 version.Append(relDate); |
|
766 version.Append(_L("\n")); |
|
767 |
|
768 iConsole->Printf(version); //printing STIF version information (version and release date) |
|
769 iConsole->Printf( _L("Test case count: [%d]\n\n"), testCases->Count() ); |
|
770 |
|
771 // Loop through all test cases in buffer and run them |
|
772 const TInt count = testCases->Count(); |
|
773 for ( TInt i = 0; i < count; i++ ) |
|
774 { |
|
775 #ifdef _DEBUG |
|
776 RDebug::Print( ( *testCases)[i].iTestCaseInfo.iTitle ); |
|
777 #endif |
|
778 iConsole->Printf( _L("Now running test case: [%d] [%S] "), i+1, |
|
779 &( *testCases )[i].iTestCaseInfo.iTitle ); |
|
780 |
|
781 // Run test case |
|
782 RunTestCaseL( ( *testCases )[i] ); |
|
783 } |
|
784 |
|
785 // End test set |
|
786 CleanupStack::PopAndDestroy( testCases ); |
|
787 |
|
788 } |
|
789 |
|
790 |
|
791 /* |
|
792 ------------------------------------------------------------------------------- |
|
793 |
|
794 Class: CATSInterface |
|
795 |
|
796 Method: RunTestCaseL |
|
797 |
|
798 Description: Run test case |
|
799 |
|
800 Parameters: TTestInfo& aTestInfo: in: TTestInfo: Test info |
|
801 |
|
802 Return Values: None |
|
803 |
|
804 Errors/Exceptions: Leaves if some of called leaving methods leaves |
|
805 |
|
806 Status: Proposal |
|
807 |
|
808 ------------------------------------------------------------------------------- |
|
809 */ |
|
810 void CATSInterface::RunTestCaseL( TTestInfo& aTestInfo ) |
|
811 { |
|
812 TInt testResult( KErrNone ); |
|
813 CATSInterfaceRunner* runner; |
|
814 |
|
815 // Trap to catch errors from test case executing |
|
816 TRAPD( trapError, |
|
817 runner = CATSInterfaceRunner::NewL( this, aTestInfo ); |
|
818 CleanupStack::PushL( runner ); |
|
819 |
|
820 testResult = RunATestCaseL( runner ); |
|
821 |
|
822 CleanupStack::PopAndDestroy( runner ); |
|
823 ); |
|
824 |
|
825 if ( trapError != KErrNone ) |
|
826 { |
|
827 testResult = trapError; |
|
828 } |
|
829 |
|
830 if ( testResult != KErrNone ) // Test case is FAILED |
|
831 { |
|
832 // Test case failed, print out the error |
|
833 iConsole->Printf( _L("\nTest case FAILED! err=[%d]\n"), testResult ); |
|
834 } |
|
835 |
|
836 else // Test case is PASSED |
|
837 { |
|
838 iConsole->Printf( _L("\nTest case PASSED!\n") ); |
|
839 testResult = KErrNone; |
|
840 } |
|
841 } |
|
842 |
|
843 |
|
844 /* |
|
845 ------------------------------------------------------------------------------- |
|
846 |
|
847 Class: CATSInterface |
|
848 |
|
849 Method: RunATestCaseL |
|
850 |
|
851 Description: Run a test case |
|
852 |
|
853 Parameters: CATSInterfaceRunner* aTestCase: in: Pointer to test case runner |
|
854 |
|
855 Return Values: TInt KErrNone: Test case passed |
|
856 other error code: Test case failed or cannot be executed |
|
857 |
|
858 Errors/Exceptions: None |
|
859 |
|
860 Status: Approved |
|
861 |
|
862 ------------------------------------------------------------------------------- |
|
863 */ |
|
864 TInt CATSInterface::RunATestCaseL( CATSInterfaceRunner* aTestCase ) |
|
865 { |
|
866 iTestCompletedError = KErrNone; |
|
867 |
|
868 // Create timer |
|
869 CActiveTimer* timer = CActiveTimer::NewL( iConsole ); |
|
870 CleanupStack::PushL( timer ); |
|
871 |
|
872 // Start test case and timer |
|
873 aTestCase->StartTestL(); |
|
874 timer->StartL(); |
|
875 |
|
876 // Wait for test case completed |
|
877 CActiveScheduler::Start(); |
|
878 |
|
879 timer->Cancel(); |
|
880 CleanupStack::PopAndDestroy( timer ); |
|
881 |
|
882 // test completion error is set in TestCompleted method |
|
883 return iTestCompletedError; |
|
884 } |
|
885 |
|
886 |
|
887 /* |
|
888 ------------------------------------------------------------------------------- |
|
889 |
|
890 Class: CATSInterface |
|
891 |
|
892 Method: TestEngineServer |
|
893 |
|
894 Description: Return handle to Test Engine Server. |
|
895 |
|
896 Parameters: None |
|
897 |
|
898 Return Values: RTestEngineServer&: Reference to RTestEngineServer handle |
|
899 |
|
900 Errors/Exceptions: None |
|
901 |
|
902 Status: Approved |
|
903 |
|
904 ------------------------------------------------------------------------------- |
|
905 */ |
|
906 RTestEngineServer& CATSInterface::TestEngineServer() |
|
907 { |
|
908 return iTestEngineServ; |
|
909 |
|
910 } |
|
911 |
|
912 |
|
913 /* |
|
914 ------------------------------------------------------------------------------- |
|
915 |
|
916 Class: CATSInterface |
|
917 |
|
918 Method: TestEngine |
|
919 |
|
920 Description: Return handle to Test Engine. |
|
921 |
|
922 Parameters: None |
|
923 |
|
924 Return Values: RTestEngine&: reference to RTestEngine handle |
|
925 |
|
926 Errors/Exceptions: None |
|
927 |
|
928 Status: Approved |
|
929 |
|
930 ------------------------------------------------------------------------------- |
|
931 */ |
|
932 RTestEngine& CATSInterface::TestEngine() |
|
933 { |
|
934 return iTestEngine; |
|
935 |
|
936 } |
|
937 |
|
938 |
|
939 /* |
|
940 ------------------------------------------------------------------------------- |
|
941 |
|
942 Class: CATSInterface |
|
943 |
|
944 Method: TestCompleted |
|
945 |
|
946 Description: Test case completed |
|
947 |
|
948 This method is called when test case is completed or error occurred |
|
949 during the test. |
|
950 |
|
951 Parameters: TInt aError: in: Symbian OS error: Test result |
|
952 |
|
953 Return Values: None |
|
954 |
|
955 Errors/Exceptions: None |
|
956 |
|
957 Status: Approved |
|
958 |
|
959 ------------------------------------------------------------------------------- |
|
960 */ |
|
961 void CATSInterface::TestCompleted( TInt aError ) |
|
962 { |
|
963 // Store completion error |
|
964 iTestCompletedError = aError; |
|
965 |
|
966 // Stop the scheduler |
|
967 CActiveScheduler::Stop(); |
|
968 |
|
969 } |
|
970 |
|
971 /* |
|
972 ------------------------------------------------------------------------------- |
|
973 |
|
974 Class: CATSInterface |
|
975 |
|
976 Method: LogErrorAndLeaveL |
|
977 |
|
978 Description: Write error Logger and leave. |
|
979 |
|
980 This function is called if some function returns error and the error cannot |
|
981 be logged another way Logger, e.g. RTestEngineServer and |
|
982 RTestEngine methods. |
|
983 |
|
984 Parameters: const TDesC& aFunction: in: any string: Function where the error |
|
985 occurred |
|
986 const TDesC& aDescription: in: any string: Description for error |
|
987 const TInt aError: in: Symbian OS error: Test result |
|
988 |
|
989 Return Values: None |
|
990 |
|
991 Errors/Exceptions: None |
|
992 |
|
993 Status: Proposal |
|
994 |
|
995 ------------------------------------------------------------------------------- |
|
996 */ |
|
997 void CATSInterface::LogErrorAndLeaveL( const TDesC& aFunction, |
|
998 const TDesC& aDescription, |
|
999 const TInt aError ) |
|
1000 { |
|
1001 |
|
1002 RDebug::Print( _L("%S: %S [%d]"), &aFunction, &aDescription, aError ); |
|
1003 User::Leave( aError ); |
|
1004 |
|
1005 } |
|
1006 |
|
1007 // ================= OTHER EXPORTED FUNCTIONS ================================= |
|
1008 |
|
1009 /* |
|
1010 ------------------------------------------------------------------------------- |
|
1011 |
|
1012 Function: E32Main |
|
1013 |
|
1014 Description: Main function called by E32. |
|
1015 |
|
1016 Parameters: None |
|
1017 |
|
1018 Return Values: TInt: KErrNone :No errors occurred |
|
1019 TInt: Other Symbian OS Error :Error catch by TRAP |
|
1020 |
|
1021 Errors/Exceptions: TRAP is used to catch errors from leaving methods. |
|
1022 |
|
1023 Status: Approved |
|
1024 |
|
1025 ------------------------------------------------------------------------------- |
|
1026 */ |
|
1027 GLDEF_C TInt E32Main() |
|
1028 { |
|
1029 |
|
1030 TInt processHandleCountBefore; |
|
1031 TInt threadHandleCountBefore; |
|
1032 RThread().HandleCount( processHandleCountBefore, threadHandleCountBefore ); |
|
1033 TInt reqsBefore = RThread().RequestCount(); |
|
1034 |
|
1035 TInt processHandleCountAfter; |
|
1036 TInt threadHandleCountAfter; |
|
1037 TInt reqsAfter; |
|
1038 |
|
1039 __UHEAP_MARK; |
|
1040 |
|
1041 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
1042 if ( cleanup == NULL ) |
|
1043 { |
|
1044 __UHEAP_MARKEND; |
|
1045 return KErrNoMemory; |
|
1046 } |
|
1047 |
|
1048 CActiveScheduler* activeScheduler = new CActiveScheduler; |
|
1049 if ( activeScheduler == NULL ) |
|
1050 { |
|
1051 delete cleanup; |
|
1052 __UHEAP_MARKEND; |
|
1053 return KErrNoMemory; |
|
1054 } |
|
1055 CActiveScheduler::Install( activeScheduler ); |
|
1056 |
|
1057 // Construct the test client |
|
1058 CATSInterface* test = NULL; |
|
1059 TRAPD( err, test = CATSInterface::NewL() ); |
|
1060 if ( err != KErrNone ) |
|
1061 { |
|
1062 #ifdef _DEBUG |
|
1063 RDebug::Print(_L("ATSInterface construction failed %d: "), err ); |
|
1064 #endif |
|
1065 delete cleanup; |
|
1066 delete activeScheduler; |
|
1067 __UHEAP_MARKEND; |
|
1068 return err; |
|
1069 } |
|
1070 |
|
1071 // Run tests |
|
1072 TRAP( err, test->RunTestsL() ); |
|
1073 if ( err != KErrNone ) |
|
1074 { |
|
1075 #ifdef _DEBUG |
|
1076 RDebug::Print(_L("RunTestsL left with %d: "), err ); |
|
1077 #endif |
|
1078 } |
|
1079 |
|
1080 |
|
1081 // Deallocate resources |
|
1082 delete test; |
|
1083 delete activeScheduler; |
|
1084 delete cleanup; |
|
1085 |
|
1086 reqsAfter = RThread().RequestCount(); |
|
1087 RThread().HandleCount( processHandleCountAfter, threadHandleCountAfter ); |
|
1088 |
|
1089 if ( reqsAfter != reqsBefore ) |
|
1090 { |
|
1091 #ifdef _DEBUG |
|
1092 RDebug::Print(_L("Request count not matching! %d vs. %d: "), |
|
1093 reqsBefore, reqsAfter ); |
|
1094 #endif |
|
1095 } |
|
1096 if ( threadHandleCountAfter != threadHandleCountBefore ) |
|
1097 { |
|
1098 #ifdef _DEBUG |
|
1099 RDebug::Print(_L("Handle count not matching! %d vs. %d: "), |
|
1100 threadHandleCountBefore, threadHandleCountAfter ); |
|
1101 #endif |
|
1102 } |
|
1103 |
|
1104 __UHEAP_MARKEND; |
|
1105 |
|
1106 return err; |
|
1107 } |
|
1108 |
|
1109 // End of File |
|