|
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: This module contains implementation of |
|
15 * CTestModuleController class member functions. |
|
16 * |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32svr.h> |
|
21 #include <stifinternal/TestServerClient.h> |
|
22 #include <StifLogger.h> |
|
23 #include "TestEngine.h" |
|
24 #include "TestModuleController.h" |
|
25 #include "Logging.h" |
|
26 |
|
27 // EXTERNAL DATA STRUCTURES |
|
28 // None |
|
29 |
|
30 // EXTERNAL FUNCTION PROTOTYPES |
|
31 // None |
|
32 |
|
33 // CONSTANTS |
|
34 // None |
|
35 |
|
36 // MACROS |
|
37 // None |
|
38 |
|
39 // LOCAL CONSTANTS AND MACROS |
|
40 // None |
|
41 |
|
42 // MODULE DATA STRUCTURES |
|
43 // None |
|
44 |
|
45 // LOCAL FUNCTION PROTOTYPES |
|
46 // None |
|
47 |
|
48 // FORWARD DECLARATIONS |
|
49 // None |
|
50 |
|
51 // ==================== LOCAL FUNCTIONS ======================================= |
|
52 // None |
|
53 |
|
54 #define LOGGER iEngine->Logger() |
|
55 |
|
56 // ================= MEMBER FUNCTIONS ========================================= |
|
57 |
|
58 /* |
|
59 ------------------------------------------------------------------------------- |
|
60 |
|
61 Class: CTestModuleController |
|
62 |
|
63 Method: CTestModuleController |
|
64 |
|
65 Description: Default constructor |
|
66 |
|
67 C++ default constructor can NOT contain any code, that |
|
68 might leave. |
|
69 |
|
70 Parameters: CTestEngine* aEngine: in: Pointer to CTestEngine |
|
71 |
|
72 Return Values: None |
|
73 |
|
74 Errors/Exceptions: None |
|
75 |
|
76 Status: Approved |
|
77 |
|
78 ------------------------------------------------------------------------------- |
|
79 */ |
|
80 CTestModuleController::CTestModuleController( CTestEngine* aEngine ) : |
|
81 CActive( CActive::EPriorityStandard ), |
|
82 iEngine( aEngine ), |
|
83 iState( ETestModuleIdle ) |
|
84 { |
|
85 CActiveScheduler::Add( this ); |
|
86 iTestScripterController = NULL; |
|
87 |
|
88 } |
|
89 |
|
90 /* |
|
91 ------------------------------------------------------------------------------- |
|
92 |
|
93 Class: CTestModuleController |
|
94 |
|
95 Method: ConstructL |
|
96 |
|
97 Description: Symbian OS second phase constructor |
|
98 |
|
99 Symbian OS default constructor can leave. |
|
100 |
|
101 Parameters: const TName& aName: in: Test module name |
|
102 |
|
103 Return Values: None |
|
104 |
|
105 Errors/Exceptions: Leaves if memory allocation for iConfigFiles fails |
|
106 Leaves if memory allocation for iTestCaseArray fails |
|
107 |
|
108 Status: Approved |
|
109 |
|
110 ------------------------------------------------------------------------------- |
|
111 */ |
|
112 void CTestModuleController::ConstructL( |
|
113 const TName& aName, |
|
114 TBool aAfterReboot, |
|
115 CTestScripterController* aTestScripterController ) |
|
116 { |
|
117 iTestScripterController = aTestScripterController; |
|
118 iTestScripterIndicator = 0; |
|
119 |
|
120 iAfterReboot = aAfterReboot; |
|
121 |
|
122 __TRACE ( KInit, ( _L( "Creating CTestModuleController [%S]" ), &aName ) ); |
|
123 |
|
124 iTestCaseArray = RPointerArray<TTestCaseArray>(); |
|
125 |
|
126 // Check aName length |
|
127 if( aName.Length() <= 0 ) |
|
128 { |
|
129 iEngine->LeaveWithNotifyL( KErrArgument ); |
|
130 } |
|
131 |
|
132 // Remove optional '.DLL' from file name |
|
133 TName name = aName; |
|
134 name.LowerCase(); |
|
135 TParse parse; |
|
136 parse.Set( name, NULL, NULL ); |
|
137 |
|
138 if ( parse.Ext() == _L(".dll") ) |
|
139 { |
|
140 const TInt len = parse.Ext().Length(); |
|
141 name.Delete ( name.Length()-len, len ); |
|
142 } |
|
143 |
|
144 iName = name.AllocL(); |
|
145 |
|
146 // HBufC to TPtrC |
|
147 TPtrC atsName; |
|
148 |
|
149 TFileName newNameBuffer; |
|
150 TInt check = GenerateModuleName( iName->Des(), newNameBuffer ); |
|
151 if( check == KErrNone ) |
|
152 { |
|
153 // Load the module(TestScripter) |
|
154 atsName.Set( newNameBuffer ); |
|
155 } |
|
156 else |
|
157 { |
|
158 // Load the module(Others) |
|
159 atsName.Set( iName->Des() ); |
|
160 } |
|
161 |
|
162 // Moved the implementation to a new function, ConstructASTLoggerL, due to |
|
163 // CW 3.0 compiler error with multiple TRAPDs |
|
164 TRAPD(err, ConstructASTLoggerL( atsName, aAfterReboot)); |
|
165 |
|
166 if( err != KErrNone ) |
|
167 { |
|
168 __TRACE ( KError, ( _L( "CTestModuleController[%S]::ConstructL: Creation of ATS logger failed" ), iName ) ); |
|
169 iEngine->LeaveWithNotifyL( err, _L("Creation of ATS logger failed") ); |
|
170 } |
|
171 |
|
172 } |
|
173 /* |
|
174 ------------------------------------------------------------------------------- |
|
175 |
|
176 Class: CTestModuleController |
|
177 |
|
178 Method: ConstructASTLoggerL |
|
179 |
|
180 Description: Construct ATS logger |
|
181 |
|
182 Parameters: TDesC& atsName, TBool& aAfterReboot |
|
183 |
|
184 Return Values: TInt |
|
185 |
|
186 Errors/Exceptions: Leaves if error got from ATS logger NewL |
|
187 |
|
188 Status: Proposal |
|
189 |
|
190 ------------------------------------------------------------------------------- |
|
191 */ |
|
192 |
|
193 TInt CTestModuleController::ConstructASTLoggerL( TDesC& atsName, TBool& aAfterReboot ) |
|
194 { |
|
195 TRAPD( err, iAtsLogger = CAtsLogger::NewL( atsName, aAfterReboot ); ); |
|
196 if( err == KErrNotFound && aAfterReboot ) |
|
197 { |
|
198 // If file does not exist, create new |
|
199 aAfterReboot = EFalse; |
|
200 iAtsLogger = CAtsLogger::NewL( atsName, aAfterReboot ); |
|
201 } |
|
202 User::LeaveIfError( err ); |
|
203 iAtsLogger->SetFullReporting( ETrue ); |
|
204 if( aAfterReboot ) |
|
205 { |
|
206 iAtsLogger->ContinueAfterRebootL(); |
|
207 } |
|
208 else |
|
209 { |
|
210 // Begin reporting |
|
211 iAtsLogger->BeginTestReportL(); |
|
212 |
|
213 // Begin test set |
|
214 iAtsLogger->BeginTestSetL(); |
|
215 } |
|
216 return KErrNone; |
|
217 } |
|
218 /* |
|
219 ------------------------------------------------------------------------------- |
|
220 |
|
221 Class: CTestModuleController |
|
222 |
|
223 Method: InitL |
|
224 |
|
225 Description: Initialize test module. |
|
226 |
|
227 Parameters: TFileName& aIniFile: in: Initialization file of Test Module |
|
228 const TDesC& aConfigFile: in: Test case(config) file name(Used |
|
229 in TestScripter case). |
|
230 |
|
231 Return Values: None |
|
232 |
|
233 Errors/Exceptions: Leaves if error got from Test Server |
|
234 |
|
235 Status: Proposal |
|
236 |
|
237 ------------------------------------------------------------------------------- |
|
238 */ |
|
239 void CTestModuleController::InitL( TFileName& aIniFile, |
|
240 const TDesC& aConfigFile ) |
|
241 { |
|
242 __TRACE( KInit, (_L( "Initialising test module [%S] with initialization file [%S]" ), |
|
243 iName, &aIniFile ) ); |
|
244 |
|
245 // HBufC to TPtrC |
|
246 TPtrC name( iName->Des() ); |
|
247 |
|
248 // Connect to server |
|
249 TInt r = iServer.Connect( name, aConfigFile ); |
|
250 |
|
251 if ( r != KErrNone ) |
|
252 { |
|
253 __TRACE( KError, ( CStifLogger::ERed, _L( "Can't connect to test module [%S], IniFile [%S]" ), &name, &aIniFile ) ); |
|
254 LeaveWithNotifyL( r, _L( "Can't connect to test module" ) ); |
|
255 } |
|
256 |
|
257 TEngineSettings engineSettings; |
|
258 engineSettings.iUITestingSupport = iEngine->UITesting(); |
|
259 engineSettings.iSeparateProcesses = iEngine->SeparateProcesses(); |
|
260 |
|
261 iServer.PassEngineSessionSettings( engineSettings ); |
|
262 |
|
263 // Open session |
|
264 r = iModule.Open( iServer, aIniFile ); |
|
265 if ( r != KErrNone ) |
|
266 { |
|
267 __TRACE( KError, ( CStifLogger::ERed, _L( "Can't open session to test module [%S], IniFile=[%S]" ), &name, &aIniFile ) ); |
|
268 LeaveWithNotifyL( r, _L( "Can't open session to test module" ) ); |
|
269 } |
|
270 |
|
271 iErrorPrinter = CErrorPrinter::NewL( iEngine ); |
|
272 iErrorPrinter->StartL( iModule ); |
|
273 |
|
274 iServerStateHandler = CServerStateHandler::NewL( iEngine, this ); |
|
275 iServerStateHandler->StartL( iServer ); |
|
276 __TRACE( KInit, (_L( "Initialising test module [%S] with initialization file [%S] done" ), |
|
277 iName, &aIniFile ) ); |
|
278 |
|
279 } |
|
280 |
|
281 /* |
|
282 ------------------------------------------------------------------------------- |
|
283 |
|
284 Class: CTestModuleController |
|
285 |
|
286 Method: NewL |
|
287 |
|
288 Description: Two-phased constructor. |
|
289 |
|
290 Parameters: CTestEngine* aEngine: in: CTestEngine object. |
|
291 const TName& aName: in: module name. |
|
292 TBool aAfterReboot: in: reboot indicator. |
|
293 TBool aCreateTestScripterCont: in: Indications to |
|
294 TestModule or TestScripter creation |
|
295 CTestScripterController* aTestScripterController: in: |
|
296 CTestEngine object. |
|
297 |
|
298 |
|
299 Return Values: CTestModuleController* : pointer to created object |
|
300 |
|
301 Errors/Exceptions: Leaves if called ConstructL method leaves |
|
302 |
|
303 Status: Proposal |
|
304 |
|
305 ------------------------------------------------------------------------------- |
|
306 */ |
|
307 CTestModuleController* CTestModuleController::NewL( |
|
308 CTestEngine* aEngine, |
|
309 const TName& aName, |
|
310 TBool aAfterReboot, |
|
311 TBool aCreateTestScripterCont, |
|
312 CTestScripterController* aTestScripterController ) |
|
313 { |
|
314 // Create CTestScripterController |
|
315 if( aCreateTestScripterCont ) |
|
316 { |
|
317 CTestScripterController* testScripterController = NULL; |
|
318 testScripterController = CTestScripterController::NewL( |
|
319 aEngine, aName, aAfterReboot ); |
|
320 return testScripterController; |
|
321 } |
|
322 |
|
323 |
|
324 CTestModuleController* self = |
|
325 new ( ELeave ) CTestModuleController( aEngine ); |
|
326 CleanupStack::PushL( self ); |
|
327 self->ConstructL( aName, aAfterReboot, aTestScripterController ); |
|
328 CleanupStack::Pop( self ); |
|
329 return self; |
|
330 |
|
331 } |
|
332 |
|
333 /* |
|
334 ------------------------------------------------------------------------------- |
|
335 |
|
336 Class: CTestModuleController |
|
337 |
|
338 Method: ~CTestModuleController |
|
339 |
|
340 Description: Destructor |
|
341 |
|
342 Deallocate all allocated resources |
|
343 |
|
344 Parameters: None |
|
345 |
|
346 Return Values: None |
|
347 |
|
348 Errors/Exceptions: None |
|
349 |
|
350 Status: Proposal |
|
351 |
|
352 ------------------------------------------------------------------------------- |
|
353 */ |
|
354 CTestModuleController::~CTestModuleController() |
|
355 { |
|
356 |
|
357 // If CTestScripterController is created there is deleted base class( |
|
358 // CTestModuleController) also and this has no iName. |
|
359 if( iName ) |
|
360 { |
|
361 __TRACE(KVerbose, (_L( "Deleting CTestModuleController [%S]" ), iName ) ); |
|
362 } |
|
363 |
|
364 Cancel(); |
|
365 |
|
366 // If CTestScripterController is created there is deleted base class( |
|
367 // CTestModuleController) also and this has no iAtsLogger. |
|
368 if( iAtsLogger ) |
|
369 { |
|
370 // End test set |
|
371 TRAPD( err, iAtsLogger->EndTestSetL() ); |
|
372 // End AtsLogger reporting, has to be trapped in destructor |
|
373 TRAPD( err2, iAtsLogger->EndTestReportL() ); |
|
374 if( ( err != KErrNone ) || ( err2 != KErrNone ) ) |
|
375 { |
|
376 // Print error if error got from trap |
|
377 __TRACE( KError, ( |
|
378 _L( "Destructor of CTestModuleController [%S]: XML log closing failed" ), |
|
379 iName ) ); |
|
380 } |
|
381 } |
|
382 |
|
383 // Delete Atslogger |
|
384 delete iAtsLogger; |
|
385 |
|
386 // Stop error printer |
|
387 delete iErrorPrinter; |
|
388 iErrorPrinter = NULL; |
|
389 // Delete server state handler |
|
390 delete iServerStateHandler; |
|
391 iServerStateHandler = NULL; |
|
392 |
|
393 // Close RTestModule session |
|
394 iModule.Close(); |
|
395 // Close RTestServer session |
|
396 iServer.Close(); |
|
397 |
|
398 // Release the test case array |
|
399 iTestCaseArray.Close(); |
|
400 |
|
401 // Release the config file array |
|
402 iConfigFiles.ResetAndDestroy(); |
|
403 iConfigFiles.Close(); |
|
404 |
|
405 // Release the config file array |
|
406 iFailedEnumerateConfig.ResetAndDestroy(); |
|
407 iFailedEnumerateConfig.Close(); |
|
408 |
|
409 // Release the children array |
|
410 iChildrenControllers.ResetAndDestroy(); |
|
411 iChildrenControllers.Close(); |
|
412 |
|
413 delete iName; |
|
414 |
|
415 } |
|
416 |
|
417 /* |
|
418 ------------------------------------------------------------------------------- |
|
419 |
|
420 Class: CTestModuleController |
|
421 |
|
422 Method: AddConfigFileL |
|
423 |
|
424 Description: Add config file |
|
425 |
|
426 Parameters: TFileName& aConfigFile: in: Config file for Test Module |
|
427 |
|
428 Return Values: None |
|
429 |
|
430 Errors/Exceptions: Leaves if AppendL leaves |
|
431 |
|
432 Status: Approved |
|
433 |
|
434 ------------------------------------------------------------------------------- |
|
435 */ |
|
436 void CTestModuleController::AddConfigFileL( TFileName& aConfigFile ) |
|
437 { |
|
438 __TRACE( KInit, |
|
439 ( _L( "CTestModuleController::AddConfigFileL [%S] aConfigFile=[%S]" ), |
|
440 iName, &aConfigFile ) ); |
|
441 // Check that this config file does not already exists |
|
442 for ( TInt i = 0; i < iConfigFiles.Count(); i++ ) |
|
443 { |
|
444 // HBufC to TPtrC |
|
445 TPtrC name( iConfigFiles[i]->Des() ); |
|
446 if ( KErrNone == aConfigFile.CompareF( name ) ) |
|
447 { |
|
448 LeaveWithNotifyL( KErrAlreadyExists, |
|
449 _L( "Adding config file failed: Config file already exists" ) ); |
|
450 } |
|
451 } |
|
452 HBufC* configFile = aConfigFile.AllocLC(); |
|
453 |
|
454 User::LeaveIfError( iConfigFiles.Append( configFile ) ); |
|
455 CleanupStack::Pop( configFile ); |
|
456 |
|
457 } |
|
458 |
|
459 /* |
|
460 ------------------------------------------------------------------------------- |
|
461 |
|
462 Class: CTestModuleController |
|
463 |
|
464 Method: RemoveConfigFileL |
|
465 |
|
466 Description: Remove config file |
|
467 |
|
468 Parameters: TFileName& aConfigFile: in: Config file name |
|
469 |
|
470 Return Values: None |
|
471 |
|
472 Errors/Exceptions: None |
|
473 |
|
474 Status: Approved |
|
475 |
|
476 ------------------------------------------------------------------------------- |
|
477 */ |
|
478 void CTestModuleController::RemoveConfigFileL( TFileName& aConfigFile ) |
|
479 { |
|
480 __TRACE( KInit, ( |
|
481 _L( "CTestModuleController::RemoveConfigFileL [%S] aConfigFile=[%S]" ), |
|
482 iName, &aConfigFile ) ); |
|
483 // Find config file |
|
484 for ( TInt i = 0; i < iConfigFiles.Count(); i++ ) |
|
485 { |
|
486 // HBufC to TPtrC |
|
487 TPtrC name( iConfigFiles[i]->Des() ); |
|
488 if ( KErrNone == aConfigFile.CompareF( name ) ) |
|
489 { |
|
490 HBufC* configFile = iConfigFiles[i]; |
|
491 iConfigFiles.Remove(i); |
|
492 delete configFile; |
|
493 // Cancel enumerate and free test cases |
|
494 Cancel(); |
|
495 FreeTestCases(); |
|
496 return; |
|
497 } |
|
498 } |
|
499 |
|
500 LeaveWithNotifyL( KErrNotFound, |
|
501 _L( "Removing config file failed: Config file not found" ) ); |
|
502 |
|
503 } |
|
504 |
|
505 /* |
|
506 ------------------------------------------------------------------------------- |
|
507 |
|
508 Class: CTestModuleController |
|
509 |
|
510 Method: StartEnumerateL |
|
511 |
|
512 Description: Start test case enumeration |
|
513 |
|
514 Parameters: None |
|
515 |
|
516 Return Values: None |
|
517 |
|
518 Errors/Exceptions: None |
|
519 |
|
520 Status: Approved |
|
521 |
|
522 ------------------------------------------------------------------------------- |
|
523 */ |
|
524 void CTestModuleController::StartEnumerateL() |
|
525 { |
|
526 __TRACE( KVerbose, ( |
|
527 _L( "CTestModuleController::StartEnumerateL [%S]" ), iName ) ); |
|
528 iTestCaseCount = 0; |
|
529 iEnumerateCount = 0; |
|
530 iFailedEnumerateCount = 0; |
|
531 iFailedEnumerateConfig.ResetAndDestroy(); |
|
532 iEnumerateComplete = EFalse; |
|
533 |
|
534 iState = ETestModuleEnumerateCases; |
|
535 |
|
536 if ( iConfigFiles.Count() > 0 ) |
|
537 { |
|
538 // HBufC to TPtrC |
|
539 iEnumConfigFile.Set( iConfigFiles[0]->Des() ); |
|
540 } |
|
541 |
|
542 __TRACE( KInit, ( |
|
543 _L( "Getting testcases from module [%S], test case file [%S]" ), |
|
544 iName, &iEnumConfigFile ) ); |
|
545 |
|
546 SetActive(); |
|
547 iModule.EnumerateTestCases( iEnumConfigFile, iEnumResultPackage, iStatus ); |
|
548 |
|
549 } |
|
550 |
|
551 /* |
|
552 ------------------------------------------------------------------------------- |
|
553 |
|
554 Class: CTestModuleController |
|
555 |
|
556 Method: RunL |
|
557 |
|
558 Description: RunL handles completed requests. |
|
559 |
|
560 Parameters: None |
|
561 |
|
562 Return Values: None |
|
563 |
|
564 Errors/Exceptions: Leaves if iStatus is not KErrNone |
|
565 Leaves if some of called leaving methods leaves |
|
566 |
|
567 Status: Approved |
|
568 |
|
569 ------------------------------------------------------------------------------- |
|
570 */ |
|
571 void CTestModuleController::RunL() |
|
572 { |
|
573 |
|
574 // If CTestScripterController is used then move execution to the |
|
575 // CTestScripterController size |
|
576 if( iTestScripterController ) |
|
577 { |
|
578 iTestScripterController->RunLEmulator( this ); |
|
579 return; |
|
580 } |
|
581 |
|
582 __TRACE( KVerbose, ( _L( "CTestModuleController::RunL [%S] [iStatus = %d]"), |
|
583 iName, iStatus.Int() ) ); |
|
584 |
|
585 // Note: |
|
586 // If test case not found there may be existing cases from previous |
|
587 // enumerations, so those cases are valid. e.g. case: "add test case file", |
|
588 // "add test case file that not exist" and "get test cases". |
|
589 |
|
590 TInt ret( KErrNone ); |
|
591 // Check that request was successful |
|
592 if( iStatus.Int() == KErrNone ) |
|
593 { |
|
594 // Get enumerated test cases and append them to array |
|
595 CFixedFlatArray<TTestCaseInfo>* testCases = |
|
596 CFixedFlatArray<TTestCaseInfo>::NewL( iEnumResultPackage() ); |
|
597 CleanupStack::PushL( testCases ); |
|
598 ret = iModule.GetTestCases( *testCases ); |
|
599 __TRACE( KInit, ( _L( "RunL()'s GetTestCases method returns: %d" ), ret ) ); |
|
600 |
|
601 iTestCaseCount += testCases->Count(); |
|
602 |
|
603 if ( testCases->Count() == 0 ) |
|
604 { |
|
605 |
|
606 if (iConfigFiles.Count() > 0) |
|
607 { |
|
608 __TRACE( KInit, ( CStifLogger::EBold, |
|
609 _L( "Module [%S], test case file [%S] returned 0 cases" ), |
|
610 iName, iConfigFiles[iEnumerateCount] ) ); |
|
611 } |
|
612 else |
|
613 { |
|
614 __TRACE( KInit, ( CStifLogger::EBold, |
|
615 _L( "Module [%S] without test case file, returned 0 cases" ), |
|
616 iName ) ); |
|
617 } |
|
618 iEngine->ErrorPrint( 1, _L("Someone returned 0 test cases. Check testengine log")); |
|
619 iAtsLogger->CommentL( _L("Test module returned 0 test cases") ); |
|
620 } |
|
621 |
|
622 // Store test cases for later use |
|
623 User::LeaveIfError( iTestCaseArray.Append( testCases ) ); |
|
624 CleanupStack::Pop( testCases ); |
|
625 |
|
626 } |
|
627 else |
|
628 { |
|
629 // Calculate failed enumeration count |
|
630 iFailedEnumerateCount++; |
|
631 // Add failed config(test case) file to array for later removing |
|
632 if( iConfigFiles.Count() > 0 ) |
|
633 { |
|
634 __TRACE( KError, ( |
|
635 CStifLogger::ERed, |
|
636 _L( "Test case[%S] enumeration fails with error: %d" ), |
|
637 iConfigFiles[iEnumerateCount], iStatus.Int() ) ); |
|
638 // Append |
|
639 iFailedEnumerateConfig.Append( iConfigFiles[iEnumerateCount] ); |
|
640 } |
|
641 } |
|
642 |
|
643 iEnumerateCount++; |
|
644 |
|
645 if ( iEnumerateCount < iConfigFiles.Count() ) |
|
646 { |
|
647 // Continue enumeration |
|
648 __TRACE( KInit, ( |
|
649 _L( "Getting testcases from module [%S], test case file [%S]" ), |
|
650 iName, iConfigFiles[iEnumerateCount] ) ); |
|
651 SetActive(); |
|
652 iModule.EnumerateTestCases( *iConfigFiles[iEnumerateCount], |
|
653 iEnumResultPackage, iStatus ); |
|
654 } |
|
655 else if( iTestCaseCount == 0 ) |
|
656 { |
|
657 // Total count of succesfully enumerations |
|
658 iEnumerateCount -= iFailedEnumerateCount; |
|
659 User::Leave( KErrNotFound ); |
|
660 } |
|
661 else |
|
662 { |
|
663 // Total count of succesfully enumerations |
|
664 iEnumerateCount -= iFailedEnumerateCount; |
|
665 // Remove faulty config (test case) file(s) |
|
666 for( TInt a= 0; a < iFailedEnumerateConfig.Count(); a++ ) |
|
667 { |
|
668 TInt index( 0 ); |
|
669 // Find removed config(test case) file |
|
670 index = iConfigFiles.Find( iFailedEnumerateConfig[a] ); |
|
671 if( index != KErrNotFound ) |
|
672 { |
|
673 __TRACE( KInit, ( _L( "Removing test case file[%S]" ), |
|
674 iConfigFiles[index] ) ); |
|
675 // Remove |
|
676 iConfigFiles.Remove( index ); |
|
677 } |
|
678 } |
|
679 |
|
680 // All test cases enumerated |
|
681 iState = ETestModuleEnumerateCasesCompleted; |
|
682 iEnumerateComplete = ETrue; |
|
683 |
|
684 iEngine->EnumerationCompleted( iTestCaseCount ); |
|
685 } |
|
686 |
|
687 } |
|
688 |
|
689 /* |
|
690 ------------------------------------------------------------------------------- |
|
691 |
|
692 Class: CTestModuleController |
|
693 |
|
694 Method: TestCasesL |
|
695 |
|
696 Description: Return Test Cases |
|
697 |
|
698 Parameters: None |
|
699 |
|
700 Return Values: CFixedFlatArray<TTestInfo>* :Pointer to created array |
|
701 |
|
702 Errors/Exceptions: Leaves if NewL leaves |
|
703 |
|
704 Status: Approved |
|
705 |
|
706 ------------------------------------------------------------------------------- |
|
707 */ |
|
708 CFixedFlatArray<TTestInfo>* CTestModuleController::TestCasesL() |
|
709 { |
|
710 CFixedFlatArray<TTestInfo>* testCases = |
|
711 CFixedFlatArray<TTestInfo>::NewL( iTestCaseCount ); |
|
712 |
|
713 CleanupStack::PushL( testCases ); |
|
714 |
|
715 // Loop through all test cases from all config files |
|
716 TInt totalCount = 0; |
|
717 // HBufC to TPtrC |
|
718 TPtrC name( iName->Des() ); |
|
719 for ( TInt i = 0; i < iEnumerateCount; i++ ) |
|
720 { |
|
721 TTestInfo tmpInfo; |
|
722 tmpInfo.iModuleName = name; |
|
723 if ( iConfigFiles.Count() > 0 ) |
|
724 { |
|
725 tmpInfo.iConfig = *iConfigFiles[i]; |
|
726 } |
|
727 |
|
728 // Get test cases from iTestCaseArray at [i] |
|
729 //if( (iTestCaseArray)[i] ) |
|
730 if ( iTestCaseArray.Count() > 0) |
|
731 { |
|
732 CFixedFlatArray<TTestCaseInfo>* tempTestCases = (iTestCaseArray)[i]; |
|
733 for ( TInt j = 0; j < tempTestCases->Count(); j++ ) |
|
734 { |
|
735 tmpInfo.iTestCaseInfo = (*tempTestCases)[j]; |
|
736 // Set TestCaseInfo to testCases array |
|
737 testCases->Set( totalCount, tmpInfo ); |
|
738 totalCount++; |
|
739 } |
|
740 } |
|
741 } |
|
742 |
|
743 CleanupStack::Pop( testCases ); |
|
744 |
|
745 return testCases; |
|
746 |
|
747 } |
|
748 |
|
749 /* |
|
750 ------------------------------------------------------------------------------- |
|
751 |
|
752 Class: CTestModuleController |
|
753 |
|
754 Method: FreeTestCases |
|
755 |
|
756 Description: Free memory used for test cases |
|
757 |
|
758 Parameters: None |
|
759 |
|
760 Return Values: None |
|
761 |
|
762 Errors/Exceptions: None |
|
763 |
|
764 Status: Approved |
|
765 |
|
766 ------------------------------------------------------------------------------- |
|
767 */ |
|
768 void CTestModuleController::FreeTestCases() |
|
769 { |
|
770 // Reset and destroy test cases |
|
771 iTestCaseArray.ResetAndDestroy(); |
|
772 iTestCaseArray.Close(); |
|
773 |
|
774 iTestCaseCount = 0; |
|
775 iEnumerateComplete = EFalse; |
|
776 |
|
777 } |
|
778 |
|
779 /* |
|
780 ------------------------------------------------------------------------------- |
|
781 |
|
782 Class: CTestModuleController |
|
783 |
|
784 Method: DoCancel |
|
785 |
|
786 Description: Cancel active request |
|
787 |
|
788 Parameters: None |
|
789 |
|
790 Return Values: None |
|
791 |
|
792 Errors/Exceptions: None |
|
793 |
|
794 Status: Approved |
|
795 |
|
796 ------------------------------------------------------------------------------- |
|
797 */ |
|
798 void CTestModuleController::DoCancel() |
|
799 { |
|
800 |
|
801 // If CTestScripterController is used then move execution to the |
|
802 // CTestScripterController size |
|
803 if( iTestScripterController ) |
|
804 { |
|
805 iTestScripterController->DoCancelEmulator( this ); |
|
806 return; |
|
807 } |
|
808 |
|
809 __TRACE( KVerbose, ( _L( "CTestModuleController::DoCancel [%S]" ), iName ) ); |
|
810 |
|
811 switch ( iState ) |
|
812 { |
|
813 case ETestModuleEnumerateCases: |
|
814 iModule.CancelAsyncRequest( ETestModuleEnumerateTestCases ); |
|
815 iEnumerateComplete = ETrue; |
|
816 // Enumeration canceled, complete with KErrCancel |
|
817 iEngine->EnumerationCompleted( 0, KErrCancel ); |
|
818 |
|
819 // Free allocated test cases because EnumerateTestCases was |
|
820 // canceled |
|
821 FreeTestCases(); |
|
822 break; |
|
823 case ETestModuleIdle: |
|
824 case ETestModuleEnumerateCasesCompleted: |
|
825 default: |
|
826 // DoCancel called in wrong state => Panic |
|
827 _LIT( KTestModuleController, "CTestModuleController" ); |
|
828 User::Panic( KTestModuleController, EDoCancelDisorder ); |
|
829 break; |
|
830 } |
|
831 |
|
832 iAtsLogger->ErrorL( _L("Test case enumeration cancelled") ); |
|
833 |
|
834 iState = ETestModuleIdle; |
|
835 |
|
836 } |
|
837 |
|
838 /* |
|
839 ------------------------------------------------------------------------------- |
|
840 |
|
841 Class: CTestModuleController |
|
842 |
|
843 Method: RunError |
|
844 |
|
845 Description: Handle errors. |
|
846 |
|
847 Parameters: TInt aError: in: Symbian OS error: Error code |
|
848 |
|
849 Return Values: TInt KErrNone: Always returned KErrNone |
|
850 |
|
851 Errors/Exceptions: None |
|
852 |
|
853 Status: Proposal |
|
854 |
|
855 ------------------------------------------------------------------------------- |
|
856 */ |
|
857 TInt CTestModuleController::RunError( TInt aError ) |
|
858 { |
|
859 |
|
860 // If CTestScripterController is used then move execution to the |
|
861 // CTestScripterController size |
|
862 if( iTestScripterController ) |
|
863 { |
|
864 return iTestScripterController->RunErrorEmulator( aError, this ); |
|
865 } |
|
866 |
|
867 __TRACE( KError, ( CStifLogger::ERed, |
|
868 _L( "CTestModuleController::RunError [%S] aError=[%d]" ), |
|
869 iName, aError ) ); |
|
870 if( aError == KErrNoMemory ) |
|
871 { |
|
872 __TRACE( KError, ( CStifLogger::ERed, |
|
873 _L( "No memory available. Test case file's size might be too big." ) ) ); |
|
874 } |
|
875 |
|
876 iEnumerateComplete = ETrue; |
|
877 |
|
878 iAtsLogger->ErrorL( _L("Test module did not return any test cases") ); |
|
879 |
|
880 _LIT( KErrorText, " did not return any test cases [error: "); |
|
881 if( KErrorText().Length() + iName->Length() + 1 < KMaxName ) |
|
882 { |
|
883 // Enumeration failed, print warning and complete with KErrNone |
|
884 TName error( iName->Des() ); |
|
885 error.Append( KErrorText ); |
|
886 error.AppendNum( aError ); |
|
887 error.Append( _L("]") ); |
|
888 iEngine->ErrorPrint ( 0, error ); |
|
889 |
|
890 iEngine->EnumerationCompleted( 0, KErrNone ); |
|
891 } |
|
892 else |
|
893 { |
|
894 // Cannot only print warning, complete with error |
|
895 iEngine->EnumerationCompleted( 0, aError ); |
|
896 } |
|
897 |
|
898 // Free allocated test cases because EnumerateTestCases failed |
|
899 FreeTestCases(); |
|
900 iEnumerateComplete = ETrue; |
|
901 |
|
902 return KErrNone; |
|
903 } |
|
904 |
|
905 /* |
|
906 ------------------------------------------------------------------------------- |
|
907 |
|
908 Class: CTestModuleController |
|
909 |
|
910 Method: Server |
|
911 |
|
912 Description: Return handle to Test Server |
|
913 |
|
914 Parameters: TTestInfo& aTestInfo: in: Test info for this test case |
|
915 |
|
916 Return Values: RTestServer& : Reference to RTestServer |
|
917 |
|
918 Errors/Exceptions: None |
|
919 |
|
920 Status: Proposal |
|
921 |
|
922 ------------------------------------------------------------------------------- |
|
923 */ |
|
924 RTestServer& CTestModuleController::Server( TTestInfo& /*aTestInfo*/ ) |
|
925 { |
|
926 return iServer; |
|
927 |
|
928 } |
|
929 |
|
930 /* |
|
931 ------------------------------------------------------------------------------- |
|
932 |
|
933 Class: CTestModuleController |
|
934 |
|
935 Method: GetFreeOrCreateModuleControllerL |
|
936 |
|
937 Description: Return pointer to module controller. |
|
938 Find module controller which does not run test case |
|
939 and if this is not possible then create new one. |
|
940 (Only for test scripter). |
|
941 |
|
942 Parameters: TTestInfo& aTestInfo: in: Test info for this test case |
|
943 TBool aUITestingSupport: in: Is UI testing mode enabled |
|
944 |
|
945 Return Values: CTestModuleController* : pointer to module controller |
|
946 |
|
947 Errors/Exceptions: None |
|
948 |
|
949 Status: Approved |
|
950 |
|
951 ------------------------------------------------------------------------------- |
|
952 */ |
|
953 CTestModuleController* CTestModuleController::GetFreeOrCreateModuleControllerL(TTestInfo& /*aTestInfo*/, TBool /*aUItestingSupport*/) |
|
954 { |
|
955 return NULL; |
|
956 } |
|
957 |
|
958 /* |
|
959 ------------------------------------------------------------------------------- |
|
960 |
|
961 Class: CTestModuleController |
|
962 |
|
963 Method: ModuleName |
|
964 |
|
965 Description: Return the name of Test Module |
|
966 |
|
967 Parameters: const TDesC& aModuleName: in Modulename |
|
968 |
|
969 Return Values: const TDesC : Name of Test Module |
|
970 |
|
971 Errors/Exceptions: None |
|
972 |
|
973 Status: proposal |
|
974 |
|
975 ------------------------------------------------------------------------------- |
|
976 */ |
|
977 const TDesC& CTestModuleController::ModuleName( const TDesC& /*aModuleName*/ ) |
|
978 { |
|
979 return *iName; |
|
980 |
|
981 } |
|
982 |
|
983 /* |
|
984 ------------------------------------------------------------------------------- |
|
985 |
|
986 Class: CTestModuleController |
|
987 |
|
988 Method: EnumerationComplete |
|
989 |
|
990 Description: Is enumeration of test cases complete. |
|
991 |
|
992 Parameters: None |
|
993 |
|
994 Return Values: TBool ETrue: Enumeration of test cases is complete |
|
995 EFalse: Enumeration is not complete |
|
996 |
|
997 Errors/Exceptions: None |
|
998 |
|
999 Status: Approved |
|
1000 |
|
1001 ------------------------------------------------------------------------------- |
|
1002 */ |
|
1003 TBool CTestModuleController::EnumerationComplete() |
|
1004 { |
|
1005 return iEnumerateComplete; |
|
1006 |
|
1007 } |
|
1008 |
|
1009 /* |
|
1010 ------------------------------------------------------------------------------- |
|
1011 |
|
1012 Class: CTestModuleController |
|
1013 |
|
1014 Method: LeaveWithNotifyL |
|
1015 |
|
1016 Description: Print out info and leave. |
|
1017 |
|
1018 Parameters: TInt aCode: in: Error code |
|
1019 const TDesC& aText: in: Test info |
|
1020 |
|
1021 Return Values: None |
|
1022 |
|
1023 Errors/Exceptions: None |
|
1024 |
|
1025 Status: Proposal |
|
1026 |
|
1027 ------------------------------------------------------------------------------- |
|
1028 */ |
|
1029 void CTestModuleController::LeaveWithNotifyL( TInt aCode, const TDesC& aText ) |
|
1030 { |
|
1031 |
|
1032 __TRACE( KError, ( CStifLogger::ERed, aText ) ); |
|
1033 if( iAtsLogger ) |
|
1034 { |
|
1035 iAtsLogger->ErrorL( aText ); |
|
1036 } |
|
1037 iEngine->LeaveWithNotifyL( aCode ); |
|
1038 |
|
1039 } |
|
1040 |
|
1041 /* |
|
1042 ------------------------------------------------------------------------------- |
|
1043 |
|
1044 Class: CTestModuleController |
|
1045 |
|
1046 Method: CaseCreated |
|
1047 |
|
1048 Description: Increases the value of iTestCaseCounter |
|
1049 |
|
1050 Parameters: None |
|
1051 |
|
1052 Return Values: None |
|
1053 |
|
1054 Errors/Exceptions: None |
|
1055 |
|
1056 Status: Proposal |
|
1057 |
|
1058 ------------------------------------------------------------------------------- |
|
1059 */ |
|
1060 void CTestModuleController::CaseCreated() |
|
1061 { |
|
1062 // Number of ongoing testcases |
|
1063 iTestCaseCounter++; |
|
1064 } |
|
1065 |
|
1066 /* |
|
1067 ------------------------------------------------------------------------------- |
|
1068 |
|
1069 Class: CTestModuleController |
|
1070 |
|
1071 Method: CaseFinished |
|
1072 |
|
1073 Description: Decreases the value of iTestCaseCounter and deletes this pointer |
|
1074 only in test module crash situations (KErrServerTerminated -15) |
|
1075 |
|
1076 Parameters: None: |
|
1077 |
|
1078 Return Values: None |
|
1079 |
|
1080 Errors/Exceptions: None |
|
1081 |
|
1082 Status: Proposal |
|
1083 |
|
1084 ------------------------------------------------------------------------------- |
|
1085 */ |
|
1086 void CTestModuleController::CaseFinished() |
|
1087 { |
|
1088 // Number of ongoing testcases |
|
1089 iTestCaseCounter--; |
|
1090 |
|
1091 // iTestModuleCrashDetected tells is TestModuleController cloned or not |
|
1092 // TestModuleController is cloned only when testmodule is crashed with KErrServerTerminated -15 |
|
1093 if (iTestCaseCounter == 0 && iTestModuleCrashDetected) |
|
1094 { |
|
1095 // Delete this in case where it has been replaced with it clone |
|
1096 // and no one have pointer to this. This happens only when test module |
|
1097 // crashes |
|
1098 delete this; |
|
1099 // Mem::Fill(this, sizeof(CTestModuleController), 0xa1a1a1a1); |
|
1100 } |
|
1101 |
|
1102 } |
|
1103 |
|
1104 /* |
|
1105 ------------------------------------------------------------------------------- |
|
1106 |
|
1107 Class: CTestModuleController |
|
1108 |
|
1109 Method: CloneL |
|
1110 |
|
1111 Description: |
|
1112 |
|
1113 Parameters: |
|
1114 |
|
1115 Return Values: |
|
1116 |
|
1117 Errors/Exceptions: |
|
1118 |
|
1119 Status: |
|
1120 |
|
1121 ------------------------------------------------------------------------------- |
|
1122 */ |
|
1123 CTestModuleController* CTestModuleController::CloneL( |
|
1124 CTestModuleController* aTestModuleController, |
|
1125 TBool aAfterReset, |
|
1126 CTestScripterController* aTestScripterController ) |
|
1127 { |
|
1128 __TRACE( KInit, ( _L( "Cloning CTestModuleController" ) ) ); |
|
1129 |
|
1130 |
|
1131 TName crashModuleName; |
|
1132 crashModuleName = aTestModuleController->ModuleName( crashModuleName ); |
|
1133 |
|
1134 CTestModuleController* clone = CTestModuleController::NewL( iEngine, crashModuleName, aAfterReset, EFalse, aTestScripterController ); |
|
1135 |
|
1136 clone->InitL( aTestModuleController->iInifile, KNullDesC ); |
|
1137 |
|
1138 // Give ATS logger to clone |
|
1139 clone->iAtsLogger = iAtsLogger; |
|
1140 iAtsLogger = NULL; |
|
1141 |
|
1142 for ( TInt i = 0; i < aTestModuleController->iConfigFiles.Count(); i++ ) |
|
1143 { |
|
1144 TPtrC configFile = aTestModuleController->iConfigFiles[i]->Des(); |
|
1145 TFileName config = configFile; |
|
1146 clone->AddConfigFileL( config ); |
|
1147 } |
|
1148 |
|
1149 iTestModuleCrashDetected = ETrue; |
|
1150 |
|
1151 __TRACE( KVerbose, ( _L( "Cloning of CTestModuleController finished " ) ) ); |
|
1152 return clone; |
|
1153 } |
|
1154 |
|
1155 /* |
|
1156 ------------------------------------------------------------------------------- |
|
1157 |
|
1158 Class: CTestModuleController |
|
1159 |
|
1160 Method: DeleteModuleController |
|
1161 |
|
1162 Description: In that class this method does nothing. It is implemented |
|
1163 in CTestScripterController. |
|
1164 |
|
1165 Parameters: CTestModuleController* aRealModuleController: not used |
|
1166 |
|
1167 Return Values: None |
|
1168 |
|
1169 Errors/Exceptions: None |
|
1170 |
|
1171 Status: |
|
1172 |
|
1173 ------------------------------------------------------------------------------- |
|
1174 */ |
|
1175 void CTestModuleController::DeleteModuleController(CTestModuleController* /*aRealModuleController*/) |
|
1176 { |
|
1177 } |
|
1178 |
|
1179 /* |
|
1180 ------------------------------------------------------------------------------- |
|
1181 |
|
1182 Class: CTestModuleController |
|
1183 |
|
1184 Method: RemoveModuleController |
|
1185 |
|
1186 Description: In that class this method does nothing. It is implemented |
|
1187 in CTestScripterController. |
|
1188 |
|
1189 Parameters: CTestModuleController* aRealModuleController: not used |
|
1190 |
|
1191 Return Values: None |
|
1192 |
|
1193 Errors/Exceptions: None |
|
1194 |
|
1195 Status: |
|
1196 |
|
1197 ------------------------------------------------------------------------------- |
|
1198 */ |
|
1199 void CTestModuleController::RemoveModuleController(CTestModuleController* /*aRealModuleController*/) |
|
1200 { |
|
1201 } |
|
1202 |
|
1203 /* |
|
1204 ------------------------------------------------------------------------------- |
|
1205 |
|
1206 Class: CTestModuleController |
|
1207 |
|
1208 Method: EnumerateSynchronously |
|
1209 |
|
1210 Description: Enumerates test module controller. Used only when new |
|
1211 test module controller is created during test case |
|
1212 execution. |
|
1213 |
|
1214 Parameters: None |
|
1215 |
|
1216 Return Values: None |
|
1217 |
|
1218 Errors/Exceptions: None |
|
1219 |
|
1220 Status: |
|
1221 |
|
1222 ------------------------------------------------------------------------------- |
|
1223 */ |
|
1224 void CTestModuleController::EnumerateSynchronously(void) |
|
1225 { |
|
1226 TInt i; |
|
1227 TInt cfgfiles = iConfigFiles.Count(); |
|
1228 __TRACE(KInit, (_L("Module controller will enumerate synchronously [%d] config files"), cfgfiles)); |
|
1229 |
|
1230 for(i = 0; i < cfgfiles; i++) |
|
1231 { |
|
1232 TRequestStatus status; |
|
1233 iModule.EnumerateTestCases(*iConfigFiles[i], |
|
1234 iEnumResultPackage, |
|
1235 status); |
|
1236 User::WaitForRequest(status); |
|
1237 } |
|
1238 } |
|
1239 |
|
1240 /* |
|
1241 ------------------------------------------------------------------------------- |
|
1242 |
|
1243 DESCRIPTION |
|
1244 |
|
1245 This module contains implementation of CTestScripterController class member |
|
1246 functions. |
|
1247 |
|
1248 ------------------------------------------------------------------------------- |
|
1249 */ |
|
1250 #define LOGGER iEngine->Logger() |
|
1251 |
|
1252 // ================= MEMBER FUNCTIONS ========================================= |
|
1253 |
|
1254 /* |
|
1255 ------------------------------------------------------------------------------- |
|
1256 |
|
1257 Class: CTestScripterController |
|
1258 |
|
1259 Method: CTestScripterController |
|
1260 |
|
1261 Description: Default constructor |
|
1262 |
|
1263 C++ default constructor can NOT contain any code, that |
|
1264 might leave. |
|
1265 |
|
1266 Parameters: CTestEngine* aEngine: in: Pointer to CTestEngine |
|
1267 |
|
1268 Return Values: None |
|
1269 |
|
1270 Errors/Exceptions: None |
|
1271 |
|
1272 Status: Approved |
|
1273 |
|
1274 ------------------------------------------------------------------------------- |
|
1275 */ |
|
1276 CTestScripterController::CTestScripterController( CTestEngine* aEngine ) : |
|
1277 CTestModuleController( aEngine ) |
|
1278 { |
|
1279 // None |
|
1280 |
|
1281 } |
|
1282 |
|
1283 /* |
|
1284 ------------------------------------------------------------------------------- |
|
1285 |
|
1286 Class: CTestScripterController |
|
1287 |
|
1288 Method: ConstructL |
|
1289 |
|
1290 Description: Symbian OS second phase constructor |
|
1291 |
|
1292 Symbian OS default constructor can leave. |
|
1293 |
|
1294 Parameters: const TName& aName: in: Test module name |
|
1295 TBool aAfterReboot: in: Reboot indication |
|
1296 |
|
1297 Return Values: None |
|
1298 |
|
1299 Errors/Exceptions: None |
|
1300 |
|
1301 Status: Approved |
|
1302 |
|
1303 ------------------------------------------------------------------------------- |
|
1304 */ |
|
1305 void CTestScripterController::ConstructL( const TName& aName, |
|
1306 TBool aAfterReboot ) |
|
1307 { |
|
1308 __TRACE( KInit, ( |
|
1309 _L( "NOTE: Test module is TestScripter and each test case(config) file(s) will have own server(s)" ) ) ); |
|
1310 |
|
1311 // Remove optional '.DLL' from file name |
|
1312 TName name = aName; |
|
1313 name.LowerCase(); |
|
1314 TParse parse; |
|
1315 parse.Set( name, NULL, NULL ); |
|
1316 |
|
1317 if ( parse.Ext() == _L(".dll") ) |
|
1318 { |
|
1319 const TInt len = parse.Ext().Length(); |
|
1320 name.Delete ( name.Length()-len, len ); |
|
1321 } |
|
1322 |
|
1323 iName = name.AllocL(); |
|
1324 |
|
1325 iAfterReboot = aAfterReboot; |
|
1326 |
|
1327 } |
|
1328 |
|
1329 /* |
|
1330 ------------------------------------------------------------------------------- |
|
1331 |
|
1332 Class: CTestScripterController |
|
1333 |
|
1334 Method: InitL |
|
1335 |
|
1336 Description: Initialize test module. |
|
1337 |
|
1338 Parameters: TFileName& aIniFile: in: Initialization file of Test Module |
|
1339 const TDesC& aConfigFile: in: Test case(config) file name(Used |
|
1340 in TestScripter case). |
|
1341 |
|
1342 Return Values: None |
|
1343 |
|
1344 Errors/Exceptions: None |
|
1345 |
|
1346 Status: Approved |
|
1347 |
|
1348 ------------------------------------------------------------------------------- |
|
1349 */ |
|
1350 void CTestScripterController::InitL( TFileName& aIniFile, |
|
1351 const TDesC& /*aConfigFile*/ ) |
|
1352 { |
|
1353 // Take initialization file of Test Module |
|
1354 iInifile = aIniFile; |
|
1355 |
|
1356 // Just empty, don't create TestServer operations. TestServer |
|
1357 // creation will be do in AddTestCaseFile()-method. |
|
1358 |
|
1359 } |
|
1360 |
|
1361 /* |
|
1362 ------------------------------------------------------------------------------- |
|
1363 |
|
1364 Class: CTestScripterController |
|
1365 |
|
1366 Method: NewL |
|
1367 |
|
1368 Description: Two-phased constructor. |
|
1369 |
|
1370 Parameters: CTestEngine* aEngine: in: CTestEngine object |
|
1371 const TName& aName: in: Test module name |
|
1372 TBool aAfterReboot: in: Reboot indication |
|
1373 |
|
1374 Return Values: CTestScripterController* : pointer to created object |
|
1375 |
|
1376 Errors/Exceptions: Leaves if called ConstructL method leaves |
|
1377 |
|
1378 Status: Approved |
|
1379 |
|
1380 ------------------------------------------------------------------------------- |
|
1381 */ |
|
1382 CTestScripterController* CTestScripterController::NewL( CTestEngine* aEngine, |
|
1383 const TName& aName, |
|
1384 TBool aAfterReboot ) |
|
1385 { |
|
1386 CTestScripterController* self = |
|
1387 new ( ELeave ) CTestScripterController( aEngine ); |
|
1388 CleanupStack::PushL( self ); |
|
1389 self->ConstructL( aName, aAfterReboot ); |
|
1390 CleanupStack::Pop( self ); |
|
1391 return self; |
|
1392 |
|
1393 } |
|
1394 |
|
1395 /* |
|
1396 ------------------------------------------------------------------------------- |
|
1397 |
|
1398 Class: CTestScripterController |
|
1399 |
|
1400 Method: ~CTestScripterController |
|
1401 |
|
1402 Description: Destructor |
|
1403 |
|
1404 Deallocate all allocated resources. Delete CTestScripterController's |
|
1405 CTestModuleController(s). After this is deleted base class also, see: |
|
1406 CTestModuleController::~CTestModuleController(). |
|
1407 |
|
1408 Parameters: None |
|
1409 |
|
1410 Return Values: None |
|
1411 |
|
1412 Errors/Exceptions: None |
|
1413 |
|
1414 Status: Approved |
|
1415 |
|
1416 ------------------------------------------------------------------------------- |
|
1417 */ |
|
1418 CTestScripterController::~CTestScripterController() |
|
1419 { |
|
1420 // Delete CTestScripterController(s). |
|
1421 iTestScripter.ResetAndDestroy(); |
|
1422 iTestScripter.Close(); |
|
1423 |
|
1424 // After this is deleted base class also, see: |
|
1425 // CTestModuleController::~CTestModuleController(). |
|
1426 |
|
1427 } |
|
1428 |
|
1429 /* |
|
1430 ------------------------------------------------------------------------------- |
|
1431 |
|
1432 Class: CTestScripterController |
|
1433 |
|
1434 Method: AddConfigFileL |
|
1435 |
|
1436 Description: Add config file. |
|
1437 - Creates CTestModuleController(Gives test case file name) |
|
1438 - Initializes CTestModuleController( creates a server session) |
|
1439 - Adds config file |
|
1440 |
|
1441 Parameters: TFileName& aConfigFile: in: Config file for TestScripter |
|
1442 |
|
1443 Return Values: None |
|
1444 |
|
1445 Errors/Exceptions: Leaves if AppendL leaves |
|
1446 |
|
1447 Status: Approved |
|
1448 |
|
1449 ------------------------------------------------------------------------------- |
|
1450 */ |
|
1451 void CTestScripterController::AddConfigFileL( TFileName& aConfigFile ) |
|
1452 { |
|
1453 // Check that this config file does not already exists |
|
1454 for( TInt a = 0; a < iTestScripter.Count(); a++ ) |
|
1455 { |
|
1456 for ( TInt i = 0; i < iTestScripter[a]->iConfigFiles.Count(); i++ ) |
|
1457 { |
|
1458 // HBufC to TPtrC |
|
1459 TPtrC name( iTestScripter[a]->iConfigFiles[i]->Des() ); |
|
1460 if ( KErrNone == aConfigFile.CompareF( name ) ) |
|
1461 { |
|
1462 LeaveWithNotifyL( KErrAlreadyExists, |
|
1463 _L( "Adding config file failed: Config file already exists" ) ); |
|
1464 } |
|
1465 } |
|
1466 } |
|
1467 |
|
1468 __TRACE( KInit, ( |
|
1469 _L( "CTestScripterController::AddConfigFileL aConfigFile=[%S]" ) , |
|
1470 &aConfigFile ) ); |
|
1471 |
|
1472 HBufC* testScripterAndTestCaseFile = NULL; // InitL() takes TFileName |
|
1473 testScripterAndTestCaseFile = CreateTestScripterNameL( |
|
1474 aConfigFile, |
|
1475 testScripterAndTestCaseFile ); |
|
1476 // Add to cleanup stack here, because CreateTestScripterNameL needs to be |
|
1477 // trapped in other methods. |
|
1478 CleanupStack::PushL( testScripterAndTestCaseFile ); |
|
1479 |
|
1480 //Create server and active object(This uses CTestModuleController::InitL()) |
|
1481 CTestModuleController* module = CTestModuleController::NewL( |
|
1482 iEngine, |
|
1483 testScripterAndTestCaseFile->Des(), |
|
1484 iAfterReboot, EFalse, this ); |
|
1485 CleanupStack::PopAndDestroy( testScripterAndTestCaseFile ); |
|
1486 CleanupStack::PushL( module ); |
|
1487 |
|
1488 User::LeaveIfError( iTestScripter.Append( module ) ); |
|
1489 |
|
1490 // Now is used TestScripter so give test case file also(used |
|
1491 // in caps modifier cases). |
|
1492 TRAPD ( err, module->InitL( iInifile, aConfigFile ) ); |
|
1493 if( err != KErrNone ) |
|
1494 { |
|
1495 __TRACE( KInit, ( _L( "InitL fails with error: %d" ), err ) ); |
|
1496 User::Leave( err ); |
|
1497 } |
|
1498 |
|
1499 module->AddConfigFileL( aConfigFile ); |
|
1500 |
|
1501 CleanupStack::Pop( module ); |
|
1502 |
|
1503 } |
|
1504 |
|
1505 /* |
|
1506 ------------------------------------------------------------------------------- |
|
1507 |
|
1508 Class: CTestScripterController |
|
1509 |
|
1510 Method: RemoveConfigFileL |
|
1511 |
|
1512 Description: Remove config file |
|
1513 |
|
1514 Parameters: TFileName& aConfigFile: in: Config file name |
|
1515 |
|
1516 Return Values: None |
|
1517 |
|
1518 Errors/Exceptions: None |
|
1519 |
|
1520 Status: Approved |
|
1521 |
|
1522 ------------------------------------------------------------------------------- |
|
1523 */ |
|
1524 void CTestScripterController::RemoveConfigFileL( TFileName& aConfigFile ) |
|
1525 { |
|
1526 __TRACE( KInit, ( _L( "CTestScripterController::RemoveConfigFileL" ) ) ); |
|
1527 |
|
1528 HBufC* testScripterAndTestCaseFile = NULL; |
|
1529 testScripterAndTestCaseFile = CreateTestScripterNameL( aConfigFile, |
|
1530 testScripterAndTestCaseFile ); |
|
1531 // Add to cleanup stack here, because CreateTestScripterNameL needs to be |
|
1532 // trapped in other methods. |
|
1533 CleanupStack::PushL( testScripterAndTestCaseFile ); |
|
1534 |
|
1535 // Get correct iTestScripter |
|
1536 TInt index( -1 ); |
|
1537 for( TInt a = 0; a < iTestScripter.Count(); a++ ) |
|
1538 { |
|
1539 if( ( iTestScripter[a]->iName->CompareF( |
|
1540 testScripterAndTestCaseFile->Des() ) == KErrNone ) ) |
|
1541 { |
|
1542 index = a; |
|
1543 break; |
|
1544 } |
|
1545 } |
|
1546 |
|
1547 CleanupStack::PopAndDestroy( testScripterAndTestCaseFile ); |
|
1548 |
|
1549 if( index == -1 ) |
|
1550 { |
|
1551 LeaveWithNotifyL( KErrNotFound, |
|
1552 _L( "Removing config file failed: Config file not found" ) ); |
|
1553 } |
|
1554 |
|
1555 __TRACE( KInit, ( |
|
1556 _L( "CTestScripterController[%S]::RemoveConfigFileL aConfigFile=[%S]"), |
|
1557 iTestScripter[index]->iName, &aConfigFile ) ); |
|
1558 |
|
1559 // Find config file |
|
1560 for ( TInt i = 0; i < iTestScripter[index]->iConfigFiles.Count(); i++ ) |
|
1561 { |
|
1562 // HBufC to TPtrC |
|
1563 TPtrC name( iTestScripter[index]->iConfigFiles[i]->Des() ); |
|
1564 if ( KErrNone == aConfigFile.CompareF( name ) ) |
|
1565 { |
|
1566 HBufC* configFile = iTestScripter[index]->iConfigFiles[i]; |
|
1567 iTestScripter[index]->iConfigFiles.Remove(i); |
|
1568 delete configFile; |
|
1569 // Cancel enumerate and free test cases |
|
1570 Cancel(); |
|
1571 FreeTestCases(); |
|
1572 // Testcasefile(config) is found, so we can return |
|
1573 return; |
|
1574 } |
|
1575 } |
|
1576 |
|
1577 LeaveWithNotifyL( KErrNotFound, |
|
1578 _L( "Removing config file failed: Config file not found" ) ); |
|
1579 |
|
1580 } |
|
1581 |
|
1582 /* |
|
1583 ------------------------------------------------------------------------------- |
|
1584 |
|
1585 Class: CTestScripterController |
|
1586 |
|
1587 Method: StartEnumerateL |
|
1588 |
|
1589 Description: Start test case enumeration |
|
1590 |
|
1591 Parameters: None |
|
1592 |
|
1593 Return Values: None |
|
1594 |
|
1595 Errors/Exceptions: LeaveWithNotifyL if no test case added. |
|
1596 |
|
1597 Status: Approved |
|
1598 |
|
1599 ------------------------------------------------------------------------------- |
|
1600 */ |
|
1601 void CTestScripterController::StartEnumerateL() |
|
1602 { |
|
1603 if( iTestScripter.Count() <= 0 ) |
|
1604 { |
|
1605 RDebug::Print( |
|
1606 _L( "There is no test case file for TestScripter registered yet. Enumeraton aborted." ) ); |
|
1607 LeaveWithNotifyL( KErrNotFound, |
|
1608 _L( "There is no test case file for TestScripter registered yet. Enumeraton aborted." ) ); |
|
1609 return; |
|
1610 } |
|
1611 |
|
1612 for( TInt a = 0; a < iTestScripter.Count(); a++ ) |
|
1613 { |
|
1614 __TRACE( KVerbose, ( |
|
1615 _L( "CTestScripterController[%S]::StartEnumerateL" ), |
|
1616 iTestScripter[a]->iName ) ); |
|
1617 iTestScripter[a]->iTestCaseCount = 0; |
|
1618 iTestScripter[a]->iEnumerateCount = 0; |
|
1619 iTestScripter[a]->iFailedEnumerateCount = 0; |
|
1620 iTestScripter[a]->iFailedEnumerateConfig.ResetAndDestroy(); |
|
1621 iTestScripter[a]->iEnumerateComplete = EFalse; |
|
1622 |
|
1623 iTestScripter[a]->iState = ETestModuleEnumerateCases; |
|
1624 |
|
1625 if ( iTestScripter[a]->iConfigFiles.Count() > 0 ) |
|
1626 { |
|
1627 // HBufC to TPtrC |
|
1628 iTestScripter[a]->iEnumConfigFile.Set( |
|
1629 iTestScripter[a]->iConfigFiles[0]->Des() ); |
|
1630 } |
|
1631 |
|
1632 __TRACE( KInit, ( |
|
1633 _L( "Getting testcases from module [%S], test case file[%S]" ), |
|
1634 iTestScripter[a]->iName, &iTestScripter[a]->iEnumConfigFile ) ); |
|
1635 |
|
1636 iTestScripter[a]->SetActive(); |
|
1637 iTestScripter[a]->iModule.EnumerateTestCases( |
|
1638 iTestScripter[a]->iEnumConfigFile, |
|
1639 iTestScripter[a]->iEnumResultPackage, |
|
1640 iTestScripter[a]->iStatus ); |
|
1641 } // End of for-loop |
|
1642 |
|
1643 } |
|
1644 |
|
1645 /* |
|
1646 ------------------------------------------------------------------------------- |
|
1647 |
|
1648 Class: CTestScripterController |
|
1649 |
|
1650 Method: GetCurrentIndex |
|
1651 |
|
1652 Description: Get current CTestScripterController. |
|
1653 |
|
1654 Parameters: CTestModuleController* aTestModuleController: in: |
|
1655 Pointer current to CTestModuleController |
|
1656 |
|
1657 Return Values: KErrNotFound returned if CTestModuleController not found |
|
1658 else current index returned. |
|
1659 |
|
1660 Errors/Exceptions: None |
|
1661 |
|
1662 Status: Approved |
|
1663 |
|
1664 ------------------------------------------------------------------------------- |
|
1665 */ |
|
1666 TInt CTestScripterController::GetCurrentIndex( CTestModuleController* |
|
1667 aTestModuleController ) |
|
1668 { |
|
1669 // Get correct iTestScripter |
|
1670 return iTestScripter.Find( aTestModuleController ); |
|
1671 |
|
1672 } |
|
1673 |
|
1674 /* |
|
1675 ------------------------------------------------------------------------------- |
|
1676 |
|
1677 Class: CTestScripterController |
|
1678 |
|
1679 Method: RunL |
|
1680 |
|
1681 Description: RunL handles completed requests. |
|
1682 |
|
1683 Parameters: None |
|
1684 |
|
1685 Return Values: None |
|
1686 |
|
1687 Errors/Exceptions: None |
|
1688 |
|
1689 Status: Approved |
|
1690 |
|
1691 ------------------------------------------------------------------------------- |
|
1692 */ |
|
1693 void CTestScripterController::RunL() |
|
1694 { |
|
1695 // Should never come here because one TestScripter have one test case |
|
1696 // file per server session. |
|
1697 // CTestScripterController's base class is an active object but this class |
|
1698 // not used as an active object. So there not used RunL => Panic. |
|
1699 |
|
1700 User::Panic( _L( "CTestScripterController::RunL()" ), KErrCorrupt ); |
|
1701 |
|
1702 } |
|
1703 |
|
1704 /* |
|
1705 ------------------------------------------------------------------------------- |
|
1706 |
|
1707 Class: CTestScripterController |
|
1708 |
|
1709 Method: RunLEmulator |
|
1710 |
|
1711 Description: RunLEmulator handles completed requests(Emulates RunL()). |
|
1712 This is called from CTestModuleController::RunL. |
|
1713 |
|
1714 Parameters: CTestModuleController* aTestModuleController: in: pointer to |
|
1715 CTestModuleController. |
|
1716 |
|
1717 Return Values: None |
|
1718 |
|
1719 Errors/Exceptions: Leaves if some of called leaving methods leaves |
|
1720 |
|
1721 Status: Approved |
|
1722 |
|
1723 ------------------------------------------------------------------------------- |
|
1724 */ |
|
1725 void CTestScripterController::RunLEmulator( CTestModuleController* |
|
1726 aTestModuleController ) |
|
1727 { |
|
1728 iTestScripterIndicator++; |
|
1729 TInt index = GetCurrentIndex( aTestModuleController ); |
|
1730 if( index < KErrNone ) |
|
1731 { |
|
1732 User::Leave( KErrNotFound ); |
|
1733 } |
|
1734 |
|
1735 __TRACE( KVerbose, ( |
|
1736 _L( "CTestScripterController[%S]::RunLEmulator [iStatus = %d]"), |
|
1737 iTestScripter[index]->iName, iTestScripter[index]->iStatus.Int() ) ); |
|
1738 |
|
1739 // Note: |
|
1740 // If test case not found there may be existing cases from previous |
|
1741 // enumerations, so those cases are valid. e.g. case: "add test case file", |
|
1742 // "add test case file that not exist" and "get test cases". |
|
1743 |
|
1744 TInt ret( KErrNone ); |
|
1745 |
|
1746 // Check that request was successful |
|
1747 if( iTestScripter[index]->iStatus.Int() == KErrNone ) |
|
1748 { |
|
1749 // Get enumerated test cases and append them to array |
|
1750 CFixedFlatArray<TTestCaseInfo>* testCases = |
|
1751 CFixedFlatArray<TTestCaseInfo>::NewL( |
|
1752 iTestScripter[index]->iEnumResultPackage() ); |
|
1753 CleanupStack::PushL( testCases ); |
|
1754 ret = iTestScripter[index]->iModule.GetTestCases( *testCases ); |
|
1755 __TRACE( KInit, ( |
|
1756 _L( "RunL()'s GetTestCases method returns: %d" ), ret ) ); |
|
1757 |
|
1758 iTestScripter[index]->iTestCaseCount += testCases->Count(); |
|
1759 |
|
1760 if ( testCases->Count() == 0 ) |
|
1761 { |
|
1762 |
|
1763 if (iTestScripter[index]->iConfigFiles.Count() > 0) |
|
1764 { |
|
1765 __TRACE( KInit, ( |
|
1766 CStifLogger::EBold, |
|
1767 _L( "Module [%S], test case file[%S] returned 0 cases" ), |
|
1768 iTestScripter[index]->iName, |
|
1769 iTestScripter[index]->iConfigFiles[iTestScripter[index]->iEnumerateCount] ) ); |
|
1770 } |
|
1771 else |
|
1772 { |
|
1773 __TRACE( KInit, ( CStifLogger::EBold, |
|
1774 _L("Module [%S] without test case file, returned 0 cases"), |
|
1775 iTestScripter[index]->iName ) ); |
|
1776 } |
|
1777 iTestScripter[index]->iEngine->ErrorPrint( 1, |
|
1778 _L("Someone returned 0 test cases. Check testengine log")); |
|
1779 iTestScripter[index]->iAtsLogger->CommentL( |
|
1780 _L("Test module returned 0 test cases") ); |
|
1781 } |
|
1782 |
|
1783 // Store test cases for later use |
|
1784 User::LeaveIfError( iTestScripter[index]->iTestCaseArray.Append( |
|
1785 testCases ) ); |
|
1786 CleanupStack::Pop( testCases ); |
|
1787 |
|
1788 } |
|
1789 else |
|
1790 { |
|
1791 // Calculate failed enumeration count |
|
1792 iTestScripter[index]->iFailedEnumerateCount++; |
|
1793 // Add failed config(test case) file to array for later removing |
|
1794 if( iTestScripter[index]->iConfigFiles.Count() != NULL ) |
|
1795 { |
|
1796 __TRACE( KError, ( |
|
1797 CStifLogger::ERed, |
|
1798 _L( "Test case[%S] enumeration fails with error: %d" ), |
|
1799 iTestScripter[index]->iConfigFiles[iTestScripter[index]->iEnumerateCount], |
|
1800 iTestScripter[index]->iStatus.Int() ) ); |
|
1801 // Append |
|
1802 iTestScripter[index]->iFailedEnumerateConfig.Append( |
|
1803 iTestScripter[index]->iConfigFiles[iTestScripter[index]->iEnumerateCount] ); |
|
1804 } |
|
1805 } |
|
1806 |
|
1807 TInt count = iTestScripter.Count(); |
|
1808 |
|
1809 // All TestScripter enumerations is finished for cleaning if necessarily |
|
1810 // and complete request up to engine. |
|
1811 if( count == iTestScripterIndicator ) |
|
1812 { |
|
1813 TInt testCaseCount( 0 ); |
|
1814 for( TInt a = 0; a < count; a++ ) |
|
1815 { |
|
1816 // Remove faulty config (test case) file(s) and |
|
1817 // iEnumerateCount not increased. |
|
1818 if( iTestScripter[a]->iTestCaseCount == 0 ) |
|
1819 { |
|
1820 // Check that test case file is not allready removed. |
|
1821 if( iTestScripter[a]->iConfigFiles.Count() != 0 ) |
|
1822 { |
|
1823 iTestScripter[a]->iConfigFiles.Remove( 0 ); |
|
1824 } |
|
1825 } |
|
1826 else |
|
1827 { |
|
1828 iTestScripter[a]->iEnumerateCount++; |
|
1829 testCaseCount += iTestScripter[a]->iTestCaseCount; |
|
1830 } |
|
1831 |
|
1832 // All test cases enumerated |
|
1833 iTestScripter[a]->iState = ETestModuleEnumerateCasesCompleted; |
|
1834 iTestScripter[a]->iEnumerateComplete = ETrue; |
|
1835 } |
|
1836 |
|
1837 iTestScripterIndicator = 0; // Initialization back to 0, enumerations |
|
1838 // are done at this run. |
|
1839 iEngine->EnumerationCompleted( testCaseCount ); |
|
1840 } |
|
1841 |
|
1842 } |
|
1843 |
|
1844 /* |
|
1845 ------------------------------------------------------------------------------- |
|
1846 |
|
1847 Class: CTestScripterController |
|
1848 |
|
1849 Method: TestCasesL |
|
1850 |
|
1851 Description: Return Test Cases |
|
1852 |
|
1853 Parameters: None |
|
1854 |
|
1855 Return Values: CFixedFlatArray<TTestInfo>*: Pointer to created array |
|
1856 |
|
1857 Errors/Exceptions: Leaves if NewL leaves |
|
1858 |
|
1859 Status: Approved |
|
1860 |
|
1861 ------------------------------------------------------------------------------- |
|
1862 */ |
|
1863 CFixedFlatArray<TTestInfo>* CTestScripterController::TestCasesL() |
|
1864 { |
|
1865 TInt testCaseCount( 0 ); |
|
1866 for( TInt i = 0; i < iTestScripter.Count(); i++ ) |
|
1867 { |
|
1868 testCaseCount += iTestScripter[i]->iTestCaseCount; |
|
1869 } |
|
1870 |
|
1871 CFixedFlatArray<TTestInfo>* testCases = |
|
1872 CFixedFlatArray<TTestInfo>::NewL( testCaseCount ); |
|
1873 |
|
1874 CleanupStack::PushL( testCases ); |
|
1875 |
|
1876 // Loop through all test cases from all config files |
|
1877 TInt totalCount = 0; |
|
1878 // HBufC to TPtrC |
|
1879 for( TInt a = 0; a < iTestScripter.Count(); a++ ) |
|
1880 { |
|
1881 TPtrC name( iTestScripter[a]->iName->Des() ); |
|
1882 for ( TInt i = 0; i < iTestScripter[a]->iEnumerateCount; i++ ) |
|
1883 { |
|
1884 TTestInfo tmpInfo; |
|
1885 tmpInfo.iModuleName = name; |
|
1886 if ( iTestScripter[a]->iConfigFiles.Count() > 0 ) |
|
1887 { |
|
1888 tmpInfo.iConfig = *iTestScripter[a]->iConfigFiles[i]; |
|
1889 } |
|
1890 |
|
1891 // Get test cases from iTestCaseArray at [i] |
|
1892 if( (iTestScripter[a]->iTestCaseArray)[i] ) |
|
1893 { |
|
1894 CFixedFlatArray<TTestCaseInfo>* tempTestCases = |
|
1895 (iTestScripter[a]->iTestCaseArray)[i]; |
|
1896 for ( TInt j = 0; j < tempTestCases->Count(); j++ ) |
|
1897 { |
|
1898 tmpInfo.iTestCaseInfo = (*tempTestCases)[j]; |
|
1899 // Set TestCaseInfo to testCases array |
|
1900 testCases->Set( totalCount, tmpInfo ); |
|
1901 totalCount++; |
|
1902 } |
|
1903 } |
|
1904 } |
|
1905 } |
|
1906 |
|
1907 CleanupStack::Pop( testCases ); |
|
1908 |
|
1909 return testCases; |
|
1910 |
|
1911 } |
|
1912 |
|
1913 /* |
|
1914 ------------------------------------------------------------------------------- |
|
1915 |
|
1916 Class: CTestScripterController |
|
1917 |
|
1918 Method: FreeTestCases |
|
1919 |
|
1920 Description: Free memory used for test cases |
|
1921 |
|
1922 Parameters: None |
|
1923 |
|
1924 Return Values: None |
|
1925 |
|
1926 Errors/Exceptions: None |
|
1927 |
|
1928 Status: Approved |
|
1929 |
|
1930 ------------------------------------------------------------------------------- |
|
1931 */ |
|
1932 void CTestScripterController::FreeTestCases() |
|
1933 { |
|
1934 for( TInt a = 0; a < iTestScripter.Count(); a++ ) |
|
1935 { |
|
1936 // Reset and destroy test cases |
|
1937 iTestScripter[a]->iTestCaseArray.ResetAndDestroy(); |
|
1938 iTestScripter[a]->iTestCaseArray.Close(); |
|
1939 |
|
1940 iTestScripter[a]->iTestCaseCount = 0; |
|
1941 iTestScripter[a]->iEnumerateComplete = EFalse; |
|
1942 } |
|
1943 |
|
1944 } |
|
1945 |
|
1946 /* |
|
1947 ------------------------------------------------------------------------------- |
|
1948 |
|
1949 Class: CTestScripterController |
|
1950 |
|
1951 Method: DoCancel |
|
1952 |
|
1953 Description: Cancel active request |
|
1954 |
|
1955 Parameters: None |
|
1956 |
|
1957 Return Values: None |
|
1958 |
|
1959 Errors/Exceptions: None |
|
1960 |
|
1961 Status: Approved |
|
1962 |
|
1963 ------------------------------------------------------------------------------- |
|
1964 */ |
|
1965 void CTestScripterController::DoCancel() |
|
1966 { |
|
1967 // Should never come here because one TestScripter have one test case |
|
1968 // file per server session. |
|
1969 // CTestScripterController's base class is an active object but this class |
|
1970 // not used as an active object. So there not used DoCancel => Panic. |
|
1971 |
|
1972 User::Panic( _L( "CTestScripterController::DoCancel()" ), KErrCorrupt ); |
|
1973 |
|
1974 } |
|
1975 |
|
1976 /* |
|
1977 ------------------------------------------------------------------------------- |
|
1978 |
|
1979 Class: CTestScripterController |
|
1980 |
|
1981 Method: DoCancelEmulator |
|
1982 |
|
1983 Description: Cancel active request(Emulates DoCancel) |
|
1984 This is called from CTestModuleController::DoCancel. |
|
1985 |
|
1986 Parameters: CTestModuleController* aTestModuleController: in: pointer to |
|
1987 CTestModuleController. |
|
1988 |
|
1989 Return Values: None |
|
1990 |
|
1991 Errors/Exceptions: None |
|
1992 |
|
1993 Status: Approved |
|
1994 |
|
1995 ------------------------------------------------------------------------------- |
|
1996 */ |
|
1997 void CTestScripterController::DoCancelEmulator( |
|
1998 CTestModuleController* aTestModuleController ) |
|
1999 { |
|
2000 TInt index = GetCurrentIndex( aTestModuleController ); |
|
2001 if( index < KErrNone ) |
|
2002 { |
|
2003 User::Leave( KErrNotFound ); |
|
2004 } |
|
2005 |
|
2006 __TRACE( KVerbose, ( |
|
2007 _L( "CTestScripterController[%S]::RunDoCancelEmulator" ), |
|
2008 iTestScripter[index]->iName ) ); |
|
2009 |
|
2010 switch ( iTestScripter[index]->iState ) |
|
2011 { |
|
2012 case ETestModuleEnumerateCases: |
|
2013 iTestScripter[index]->iModule.CancelAsyncRequest( |
|
2014 ETestModuleEnumerateTestCases ); |
|
2015 iTestScripter[index]->iEnumerateComplete = ETrue; |
|
2016 // Enumeration canceled, complete with KErrCancel |
|
2017 iTestScripter[index]->iEngine->EnumerationCompleted( |
|
2018 0, KErrCancel ); |
|
2019 |
|
2020 // Free allocated test cases because EnumerateTestCases was |
|
2021 // canceled |
|
2022 FreeTestCases(); |
|
2023 break; |
|
2024 case ETestModuleIdle: |
|
2025 case ETestModuleEnumerateCasesCompleted: |
|
2026 default: |
|
2027 // DoCancel called in wrong state => Panic |
|
2028 _LIT( KTestModuleController, "CTestModuleController" ); |
|
2029 User::Panic( KTestModuleController, EDoCancelDisorder ); |
|
2030 break; |
|
2031 } |
|
2032 |
|
2033 iTestScripter[index]->iAtsLogger->ErrorL( |
|
2034 _L("Test case enumeration cancelled") ); |
|
2035 iTestScripter[index]->iState = ETestModuleIdle; |
|
2036 |
|
2037 } |
|
2038 |
|
2039 /* |
|
2040 ------------------------------------------------------------------------------- |
|
2041 |
|
2042 Class: CTestScripterController |
|
2043 |
|
2044 Method: RunError |
|
2045 |
|
2046 Description: Handle errors. |
|
2047 |
|
2048 Parameters: TInt aError: in: Symbian OS error: Error code |
|
2049 |
|
2050 Return Values: TInt KErrNone: Always returned KErrNone |
|
2051 |
|
2052 Errors/Exceptions: None |
|
2053 |
|
2054 Status: Approved |
|
2055 |
|
2056 ------------------------------------------------------------------------------- |
|
2057 */ |
|
2058 TInt CTestScripterController::RunError( TInt /*aError*/ ) |
|
2059 { |
|
2060 // Should never come here because one TestScripter have one test case |
|
2061 // file per server session. |
|
2062 // CTestScripterController's base class is an active object but this class |
|
2063 // not used as an active object. So there not used RunError => Panic. |
|
2064 |
|
2065 User::Panic( _L( "CTestScripterController::RunError()" ), KErrCorrupt ); |
|
2066 return KErrNone; |
|
2067 |
|
2068 } |
|
2069 |
|
2070 /* |
|
2071 ------------------------------------------------------------------------------- |
|
2072 |
|
2073 Class: CTestScripterController |
|
2074 |
|
2075 Method: RunErrorEmulator |
|
2076 |
|
2077 Description: Handle errors(Emulates RunError). |
|
2078 This is called from CTestModuleController::RunError. |
|
2079 |
|
2080 Parameters: TInt aError: in: Symbian OS error: Error code. |
|
2081 CTestModuleController* aTestModuleController: in: pointer to |
|
2082 CTestModuleController. |
|
2083 |
|
2084 Return Values: TInt KErrNone: Always returned KErrNone |
|
2085 |
|
2086 Errors/Exceptions: None |
|
2087 |
|
2088 Status: Approved |
|
2089 |
|
2090 ------------------------------------------------------------------------------- |
|
2091 */ |
|
2092 TInt CTestScripterController::RunErrorEmulator( TInt aError, |
|
2093 CTestModuleController* aTestModuleController ) |
|
2094 { |
|
2095 TInt index = GetCurrentIndex( aTestModuleController ); |
|
2096 if( index < KErrNone ) |
|
2097 { |
|
2098 User::Leave( KErrNotFound ); |
|
2099 } |
|
2100 |
|
2101 __TRACE( KError, ( CStifLogger::ERed, |
|
2102 _L( "CTestScripterController[%S]::RunErrorEmulator aError=[%d]" ), |
|
2103 iTestScripter[index]->iName, aError ) ); |
|
2104 if( aError == KErrNoMemory ) |
|
2105 { |
|
2106 __TRACE( KError, ( CStifLogger::ERed, |
|
2107 _L( "No memory available. Test case file's size might be too big." ) ) ); |
|
2108 } |
|
2109 |
|
2110 iTestScripter[index]->iEnumerateComplete = ETrue; |
|
2111 |
|
2112 iTestScripter[index]->iAtsLogger->ErrorL( |
|
2113 _L("Test module did not return any test cases") ); |
|
2114 |
|
2115 _LIT( KErrorText, " did not return any test cases [error: "); |
|
2116 if( KErrorText().Length() + |
|
2117 iTestScripter[index]->iName->Length() + |
|
2118 1 < KMaxName ) |
|
2119 { |
|
2120 // Enumeration failed, print warning and complete with KErrNone |
|
2121 TName error( iTestScripter[index]->iName->Des() ); |
|
2122 error.Append( KErrorText ); |
|
2123 error.AppendNum( aError ); |
|
2124 error.Append( _L("]") ); |
|
2125 iEngine->ErrorPrint ( 0, error ); |
|
2126 |
|
2127 iTestScripter[index]->iEngine->EnumerationCompleted( 0, KErrNone ); |
|
2128 } |
|
2129 else |
|
2130 { |
|
2131 // Cannot only print warning, complete with error |
|
2132 iTestScripter[index]->iEngine->EnumerationCompleted( 0, aError ); |
|
2133 } |
|
2134 |
|
2135 // Free allocated test cases because EnumerateTestCases failed |
|
2136 FreeTestCases(); |
|
2137 iTestScripter[index]->iEnumerateComplete = ETrue; |
|
2138 |
|
2139 return KErrNone; |
|
2140 |
|
2141 } |
|
2142 |
|
2143 /* |
|
2144 ------------------------------------------------------------------------------- |
|
2145 |
|
2146 Class: CTestScripterController |
|
2147 |
|
2148 Method: EnumerationComplete |
|
2149 |
|
2150 Description: Is enumeration of test cases complete. |
|
2151 |
|
2152 Parameters: None |
|
2153 |
|
2154 Return Values: TBool ETrue: Enumeration of test cases is complete |
|
2155 EFalse: Enumeration is not complete |
|
2156 |
|
2157 Errors/Exceptions: None |
|
2158 |
|
2159 Status: Approved |
|
2160 |
|
2161 ------------------------------------------------------------------------------- |
|
2162 */ |
|
2163 TBool CTestScripterController::EnumerationComplete() |
|
2164 { |
|
2165 for( TInt a = 0; a < iTestScripter.Count(); a++ ) |
|
2166 { |
|
2167 if( !iTestScripter[a]->iEnumerateComplete ) |
|
2168 { |
|
2169 return EFalse; |
|
2170 } |
|
2171 } |
|
2172 return ETrue; |
|
2173 |
|
2174 } |
|
2175 |
|
2176 /* |
|
2177 ------------------------------------------------------------------------------- |
|
2178 |
|
2179 Class: CTestScripterController |
|
2180 |
|
2181 Method: Server |
|
2182 |
|
2183 Description: Return handle to Test Server |
|
2184 |
|
2185 Parameters: TTestInfo& aTestInfo: in: Test info for this test case |
|
2186 |
|
2187 Return Values: RTestServer& : Reference to RTestServer |
|
2188 |
|
2189 Errors/Exceptions: None |
|
2190 |
|
2191 Status: Approved |
|
2192 |
|
2193 ------------------------------------------------------------------------------- |
|
2194 */ |
|
2195 RTestServer& CTestScripterController::Server( TTestInfo& aTestInfo ) |
|
2196 { |
|
2197 HBufC* testScripterAndTestCaseFile = NULL; |
|
2198 TRAPD( ret, testScripterAndTestCaseFile = CreateTestScripterNameL( |
|
2199 aTestInfo.iConfig, |
|
2200 testScripterAndTestCaseFile ) ); |
|
2201 // Add to cleanup stack here, because CreateTestScripterNameL needs to be |
|
2202 // trapped in other methods. |
|
2203 CleanupStack::PushL( testScripterAndTestCaseFile ); |
|
2204 if( ret != KErrNone ) |
|
2205 { |
|
2206 User::Panic( |
|
2207 _L( "CTestScripterController::Server(): CreateTestScripterNameL" ), |
|
2208 ret ); |
|
2209 } |
|
2210 |
|
2211 // Get correct handle |
|
2212 TInt index( KErrNotFound ); |
|
2213 for( TInt a = 0; a < iTestScripter.Count(); a++ ) |
|
2214 { |
|
2215 if( testScripterAndTestCaseFile->Des() == |
|
2216 iTestScripter[a]->iName->Des() ) |
|
2217 { |
|
2218 index = a; |
|
2219 break; |
|
2220 } |
|
2221 } |
|
2222 |
|
2223 CleanupStack::PopAndDestroy( testScripterAndTestCaseFile ); |
|
2224 |
|
2225 if( index == KErrNotFound ) |
|
2226 { |
|
2227 User::Panic( |
|
2228 _L( "CTestScripterController::Server(): Index not found" ), |
|
2229 KErrNotFound ); |
|
2230 } |
|
2231 |
|
2232 // Return handle |
|
2233 return iTestScripter[index]->iServer; |
|
2234 } |
|
2235 |
|
2236 /* |
|
2237 ------------------------------------------------------------------------------- |
|
2238 |
|
2239 Class: CTestScripterController |
|
2240 |
|
2241 Method: GetFreeOrCreateModuleControllerL |
|
2242 |
|
2243 Description: Return pointer to test module controller. |
|
2244 Find controller which does not run test case |
|
2245 and if this is not possible then create new one. |
|
2246 |
|
2247 Parameters: TTestInfo& aTestInfo: in: Test info for this test case |
|
2248 TBool aUITestingSupport: in: Is UI testing mode enabled |
|
2249 |
|
2250 Return Values: CTestModuleController* : pointer to controller |
|
2251 |
|
2252 Errors/Exceptions: None |
|
2253 |
|
2254 Status: Approved |
|
2255 |
|
2256 ------------------------------------------------------------------------------- |
|
2257 */ |
|
2258 CTestModuleController* CTestScripterController::GetFreeOrCreateModuleControllerL(TTestInfo& aTestInfo, TBool aUITestingSupport) |
|
2259 { |
|
2260 HBufC* testScripterAndTestCaseFile = NULL; |
|
2261 TRAPD(ret, testScripterAndTestCaseFile = CreateTestScripterNameL(aTestInfo.iConfig, testScripterAndTestCaseFile)); |
|
2262 |
|
2263 // Add to cleanup stack here, because CreateTestScripterNameL needs to be trapped in other methods. |
|
2264 CleanupStack::PushL(testScripterAndTestCaseFile); |
|
2265 if(ret != KErrNone) |
|
2266 { |
|
2267 User::Panic(_L("CTestScripterController::GetFreeOrCreateModuleControllerL(): CreateTestScripterNameL"), ret); |
|
2268 } |
|
2269 |
|
2270 CTestModuleController* resultController = NULL; |
|
2271 CTestModuleController* parentController = NULL; |
|
2272 TInt j; |
|
2273 |
|
2274 __TRACE(KInit, (_L("Find free real module controller (or create new one)"))); |
|
2275 |
|
2276 // Get handle to correct "parent" module controller |
|
2277 __TRACE(KInit, (_L("Searching for parent module controller named [%S]"), testScripterAndTestCaseFile)); |
|
2278 for(TInt a = 0; a < iTestScripter.Count(); a++) |
|
2279 { |
|
2280 //Check if module name matches to given name |
|
2281 if(iTestScripter[a]->iName->Des() == testScripterAndTestCaseFile->Des()) |
|
2282 { |
|
2283 parentController = iTestScripter[a]; |
|
2284 __TRACE(KInit, (_L("Parent module controller [%S] has been found. Checking its %d children"), parentController->iName, parentController->iChildrenControllers.Count())); |
|
2285 //Now check all its children and find free one |
|
2286 //In UI testing mode always create new module controller |
|
2287 if(!aUITestingSupport) |
|
2288 { |
|
2289 for(j = 0; j < parentController->iChildrenControllers.Count(); j++) |
|
2290 { |
|
2291 if(parentController->iChildrenControllers[j]->iTestCaseCounter == 0) |
|
2292 { |
|
2293 resultController = parentController->iChildrenControllers[j]; |
|
2294 __TRACE(KInit, (_L("Free real module controller found [%S]"), resultController->iName)); |
|
2295 break; |
|
2296 } |
|
2297 else |
|
2298 { |
|
2299 __TRACE(KInit, (_L("Module controller found [%S] but is not free (it runs %d test cases)"), parentController->iChildrenControllers[j]->iName, parentController->iChildrenControllers[j]->iTestCaseCounter)); |
|
2300 } |
|
2301 } |
|
2302 } |
|
2303 else |
|
2304 { |
|
2305 __TRACE(KInit, (_L("In UITestingSupport mode new module controller will be always created"))); |
|
2306 } |
|
2307 } |
|
2308 } |
|
2309 |
|
2310 //Append underscore to name |
|
2311 TPtr ptr = testScripterAndTestCaseFile->Des(); |
|
2312 ptr.Append(_L("@")); |
|
2313 |
|
2314 //Create new module controller if free one has not been found |
|
2315 if(!resultController) |
|
2316 { |
|
2317 TBuf<10> ind; |
|
2318 ind.Format(_L("%d"), iEngine->GetIndexForNewTestModuleController()); |
|
2319 TPtr ptr = testScripterAndTestCaseFile->Des(); |
|
2320 ptr.Append(ind); |
|
2321 __TRACE(KInit, (_L("Free real module controller not found. Creating new one [%S]."), testScripterAndTestCaseFile)); |
|
2322 |
|
2323 //Create server and active object (This uses CTestModuleController::InitL()) |
|
2324 CTestModuleController* module = CTestModuleController::NewL( |
|
2325 iEngine, |
|
2326 testScripterAndTestCaseFile->Des(), |
|
2327 iAfterReboot, EFalse, this); |
|
2328 CleanupStack::PushL(module); |
|
2329 parentController->iChildrenControllers.AppendL(module); |
|
2330 __TRACE(KInit, (_L("Child added to [%S] controller. Currently it has %d children:"), parentController->iName, parentController->iChildrenControllers.Count())); |
|
2331 for(j = 0; j < parentController->iChildrenControllers.Count(); j++) |
|
2332 { |
|
2333 __TRACE(KInit, (_L(" %d. [%S]"), j + 1, parentController->iChildrenControllers[j]->iName)); |
|
2334 } |
|
2335 |
|
2336 // Now is used TestScripter so give test case file also(used |
|
2337 // in caps modifier cases). |
|
2338 TRAPD(err, module->InitL(iInifile, aTestInfo.iConfig)); |
|
2339 if(err != KErrNone) |
|
2340 { |
|
2341 __TRACE(KVerbose, (_L("InitL fails with error: %d" ), err)); |
|
2342 User::Leave(err); |
|
2343 } |
|
2344 |
|
2345 module->AddConfigFileL(aTestInfo.iConfig); |
|
2346 |
|
2347 __TRACE(KInit, (_L("New module controller created [%S]."), testScripterAndTestCaseFile)); |
|
2348 |
|
2349 //Enumerate test cases |
|
2350 module->EnumerateSynchronously(); |
|
2351 |
|
2352 CleanupStack::Pop(module); |
|
2353 resultController = module; |
|
2354 } |
|
2355 |
|
2356 CleanupStack::PopAndDestroy(testScripterAndTestCaseFile); |
|
2357 |
|
2358 // Return handle |
|
2359 return resultController; |
|
2360 } |
|
2361 |
|
2362 /* |
|
2363 ------------------------------------------------------------------------------- |
|
2364 |
|
2365 Class: CTestScripterController |
|
2366 |
|
2367 Method: ModuleName |
|
2368 |
|
2369 Description: Return the name of Test Scripter |
|
2370 |
|
2371 Parameters: const TDesC& aModuleName: in: Module name |
|
2372 |
|
2373 Return Values: const TDesC : Name of Test Scripter |
|
2374 |
|
2375 Errors/Exceptions: None |
|
2376 |
|
2377 Status: Approved |
|
2378 |
|
2379 ------------------------------------------------------------------------------- |
|
2380 */ |
|
2381 const TDesC& CTestScripterController::ModuleName( const TDesC& aModuleName ) |
|
2382 { |
|
2383 // If test case file not added yet. |
|
2384 if( iTestScripter.Count() == 0 || aModuleName == KTestScripterName ) |
|
2385 { |
|
2386 return *iName; |
|
2387 } |
|
2388 |
|
2389 // Test case(s) is(are) added. Scan the name from corrent TestScripter |
|
2390 // session |
|
2391 for( TInt a = 0; a < iTestScripter.Count(); a++ ) |
|
2392 { |
|
2393 if( aModuleName == iTestScripter[a]->iName->Des() ) |
|
2394 { |
|
2395 return *iTestScripter[a]->iName; |
|
2396 } |
|
2397 } |
|
2398 |
|
2399 return KNullDesC; |
|
2400 |
|
2401 } |
|
2402 |
|
2403 /* |
|
2404 ------------------------------------------------------------------------------- |
|
2405 |
|
2406 Class: CTestScripterController |
|
2407 |
|
2408 Method: CreateTestScripterNameL |
|
2409 |
|
2410 Description: Create name according to TestScripter and Test case file. |
|
2411 |
|
2412 Parameters: TFileName& aTestCaseFile: in: Test case file with path and name |
|
2413 TFileName& aCreatedName: inout: Created name |
|
2414 |
|
2415 Return Values: None |
|
2416 |
|
2417 Errors/Exceptions: Leaves is test case file is too long |
|
2418 |
|
2419 Status: Approved |
|
2420 |
|
2421 ------------------------------------------------------------------------------- |
|
2422 */ |
|
2423 HBufC* CTestScripterController::CreateTestScripterNameL( |
|
2424 TFileName& aTestCaseFile, |
|
2425 HBufC* aCreatedName ) |
|
2426 { |
|
2427 TParse parse; |
|
2428 parse.Set( aTestCaseFile, NULL, NULL ); |
|
2429 |
|
2430 TInt length( 0 ); |
|
2431 length = parse.Name().Length(); |
|
2432 length += ( KTestScripterNameLength + 1 ); |
|
2433 length += 10; //this will be used to add unique identifier (when run test case in separate process is on) |
|
2434 |
|
2435 // aCreatedName to CleanupStack |
|
2436 aCreatedName = HBufC::NewLC( length ); |
|
2437 TPtr ptr = aCreatedName->Des(); |
|
2438 |
|
2439 // Maximum length of TestScripter's name(Max limitation from |
|
2440 // CTestModuleController creation) |
|
2441 TInt maximumLength = KMaxName - ( KTestScripterNameLength + 1 ); |
|
2442 |
|
2443 // Start create name. Format is testscripter_testcasefile |
|
2444 ptr.Copy( KTestScripterName ); |
|
2445 ptr.Append( _L( "_" ) ); |
|
2446 if( parse.Name().Length() < maximumLength ) |
|
2447 { |
|
2448 ptr.Append( parse.Name() ); |
|
2449 ptr.LowerCase(); |
|
2450 } |
|
2451 else |
|
2452 { |
|
2453 __TRACE( KInit, ( CStifLogger::ERed, |
|
2454 _L( "TestScripter test case file(config)'s name is too long. Current length[%d], allowed max length[%d]. Cannot continue" ), |
|
2455 parse.Name().Length(), maximumLength ) ); |
|
2456 User::Leave( KErrArgument ); |
|
2457 } |
|
2458 |
|
2459 // Pop here because this method can be trapped and trap panics with |
|
2460 // E32USER-CBase if cleap up stack is not empty. |
|
2461 CleanupStack::Pop( aCreatedName ); |
|
2462 |
|
2463 return aCreatedName; |
|
2464 |
|
2465 } |
|
2466 |
|
2467 /* |
|
2468 ------------------------------------------------------------------------------- |
|
2469 |
|
2470 Class: CTestScripterController |
|
2471 |
|
2472 Method: DeleteModuleController |
|
2473 |
|
2474 Description: Finds specified module controller and deletes it. |
|
2475 |
|
2476 Parameters: CTestModuleController* aRealModuleController: module controller |
|
2477 to be deleted. |
|
2478 |
|
2479 Return Values: None |
|
2480 |
|
2481 Errors/Exceptions: None |
|
2482 |
|
2483 Status: |
|
2484 |
|
2485 ------------------------------------------------------------------------------- |
|
2486 */ |
|
2487 void CTestScripterController::DeleteModuleController(CTestModuleController* aRealModuleController) |
|
2488 { |
|
2489 __TRACE(KInit, (_L("Attempting to delete real module controller [%S]"), aRealModuleController->iName)); |
|
2490 |
|
2491 TInt i, j, k; |
|
2492 TInt children; |
|
2493 TInt subcontrollers = iTestScripter.Count(); |
|
2494 |
|
2495 for(k = 0; k < subcontrollers; k++) |
|
2496 { |
|
2497 children = iTestScripter[k]->iChildrenControllers.Count(); |
|
2498 __TRACE(KInit, (_L("...checking controller [%S] which has %d children"), iTestScripter[k]->iName, children)); |
|
2499 |
|
2500 for(i = 0; i < children; i++) |
|
2501 { |
|
2502 if(iTestScripter[k]->iChildrenControllers[i] == aRealModuleController) |
|
2503 { |
|
2504 __TRACE(KInit, (_L("Real module controller found... deleting"))); |
|
2505 delete iTestScripter[k]->iChildrenControllers[i]; |
|
2506 iTestScripter[k]->iChildrenControllers.Remove(i); |
|
2507 |
|
2508 __TRACE(KInit, (_L("Child removed from [%S] controller. Currently it has %d children:"), iTestScripter[k]->iName, iTestScripter[k]->iChildrenControllers.Count())); |
|
2509 for(j = 0; j < iTestScripter[k]->iChildrenControllers.Count(); j++) |
|
2510 { |
|
2511 __TRACE(KInit, (_L(" %d. [%S]"), j + 1, iTestScripter[k]->iChildrenControllers[j]->iName)); |
|
2512 } |
|
2513 |
|
2514 return; |
|
2515 } |
|
2516 } |
|
2517 } |
|
2518 __TRACE(KInit, (_L("Real module controller NOT found... NOT deleting"))); |
|
2519 } |
|
2520 |
|
2521 /* |
|
2522 ------------------------------------------------------------------------------- |
|
2523 |
|
2524 Class: CTestScripterController |
|
2525 |
|
2526 Method: RemoveModuleController |
|
2527 |
|
2528 Description: Finds specified module controller and removes it from children list. |
|
2529 |
|
2530 Parameters: CTestModuleController* aRealModuleController: module controller |
|
2531 to be removed. |
|
2532 |
|
2533 Return Values: None |
|
2534 |
|
2535 Errors/Exceptions: None |
|
2536 |
|
2537 Status: |
|
2538 |
|
2539 ------------------------------------------------------------------------------- |
|
2540 */ |
|
2541 void CTestScripterController::RemoveModuleController(CTestModuleController* aRealModuleController) |
|
2542 { |
|
2543 __TRACE(KInit, (_L("Attempting to remove real module controller [%x]"), aRealModuleController)); |
|
2544 |
|
2545 TInt i, j, k; |
|
2546 TInt children; |
|
2547 TInt subcontrollers = iTestScripter.Count(); |
|
2548 |
|
2549 for(k = 0; k < subcontrollers; k++) |
|
2550 { |
|
2551 children = iTestScripter[k]->iChildrenControllers.Count(); |
|
2552 __TRACE(KInit, (_L("...checking controller [%S] which has %d children"), iTestScripter[k]->iName, children)); |
|
2553 |
|
2554 for(i = 0; i < children; i++) |
|
2555 { |
|
2556 if(iTestScripter[k]->iChildrenControllers[i] == aRealModuleController) |
|
2557 { |
|
2558 __TRACE(KInit, (_L("Real module controller found... removing"))); |
|
2559 iTestScripter[k]->iChildrenControllers.Remove(i); |
|
2560 |
|
2561 __TRACE(KInit, (_L("Child removed from [%S] controller. Currently it has %d children:"), iTestScripter[k]->iName, iTestScripter[k]->iChildrenControllers.Count())); |
|
2562 for(j = 0; j < iTestScripter[k]->iChildrenControllers.Count(); j++) |
|
2563 { |
|
2564 __TRACE(KInit, (_L(" %d. [%S]"), j + 1, iTestScripter[k]->iChildrenControllers[j]->iName)); |
|
2565 } |
|
2566 |
|
2567 return; |
|
2568 } |
|
2569 } |
|
2570 } |
|
2571 __TRACE(KInit, (_L("Real module controller NOT found... NOT removing"))); |
|
2572 } |
|
2573 |
|
2574 /* |
|
2575 ------------------------------------------------------------------------------- |
|
2576 |
|
2577 DESCRIPTION |
|
2578 |
|
2579 This module contains implementation of CErrorPrinter class member |
|
2580 functions. |
|
2581 |
|
2582 ------------------------------------------------------------------------------- |
|
2583 */ |
|
2584 |
|
2585 /* |
|
2586 ------------------------------------------------------------------------------- |
|
2587 |
|
2588 Class: CErrorPrinter |
|
2589 |
|
2590 Method: NewL |
|
2591 |
|
2592 Description: Create a testcase runner. |
|
2593 |
|
2594 Parameters: CTestEngine* aMain: in: Pointer to console main |
|
2595 |
|
2596 Return Values: CErrorPrinter* : pointer to created object |
|
2597 |
|
2598 Errors/Exceptions: Leaves if memory allocation for object fails |
|
2599 Leaves if ConstructL leaves |
|
2600 |
|
2601 Status: Approved |
|
2602 |
|
2603 ------------------------------------------------------------------------------- |
|
2604 */ |
|
2605 CErrorPrinter* CErrorPrinter::NewL( CTestEngine* aTestEngine ) |
|
2606 { |
|
2607 CErrorPrinter* self = new ( ELeave ) CErrorPrinter(); |
|
2608 CleanupStack::PushL( self ); |
|
2609 self->ConstructL( aTestEngine ); |
|
2610 CleanupStack::Pop( self ); |
|
2611 return self; |
|
2612 |
|
2613 } |
|
2614 |
|
2615 /* |
|
2616 ------------------------------------------------------------------------------- |
|
2617 |
|
2618 Class: CErrorPrinter |
|
2619 |
|
2620 Method: ConstructL |
|
2621 |
|
2622 Description: Second level constructor. |
|
2623 |
|
2624 Parameters: CTestEngine* aEngine: in: Pointer to Engine |
|
2625 |
|
2626 Return Values: None |
|
2627 |
|
2628 Errors/Exceptions: None |
|
2629 |
|
2630 Status: Approved |
|
2631 |
|
2632 ------------------------------------------------------------------------------- |
|
2633 */ |
|
2634 void CErrorPrinter::ConstructL( CTestEngine* aEngine ) |
|
2635 { |
|
2636 iEngine = aEngine; |
|
2637 |
|
2638 } |
|
2639 |
|
2640 /* |
|
2641 ------------------------------------------------------------------------------- |
|
2642 |
|
2643 Class: CErrorPrinter |
|
2644 |
|
2645 Method: CErrorPrinter |
|
2646 |
|
2647 Description: Constructor. |
|
2648 |
|
2649 Parameters: None |
|
2650 |
|
2651 Return Values: None |
|
2652 |
|
2653 Errors/Exceptions: None |
|
2654 |
|
2655 Status: Approved |
|
2656 |
|
2657 ------------------------------------------------------------------------------- |
|
2658 */ |
|
2659 CErrorPrinter::CErrorPrinter( ) : CActive( EPriorityStandard ), |
|
2660 iErrorPckg( iError ) |
|
2661 { |
|
2662 |
|
2663 } |
|
2664 |
|
2665 /* |
|
2666 ------------------------------------------------------------------------------- |
|
2667 |
|
2668 Class: CErrorPrinter |
|
2669 |
|
2670 Method: ~CErrorPrinter |
|
2671 |
|
2672 Description: Destructor. |
|
2673 |
|
2674 Parameters: None |
|
2675 |
|
2676 Return Values: None |
|
2677 |
|
2678 Errors/Exceptions: None |
|
2679 |
|
2680 Status: Approved |
|
2681 |
|
2682 ------------------------------------------------------------------------------- |
|
2683 */ |
|
2684 CErrorPrinter::~CErrorPrinter( ) |
|
2685 { |
|
2686 Cancel(); |
|
2687 |
|
2688 } |
|
2689 |
|
2690 /* |
|
2691 ------------------------------------------------------------------------------- |
|
2692 |
|
2693 Class: CErrorPrinter |
|
2694 |
|
2695 Method: StartL |
|
2696 |
|
2697 Description: Starts a test case and sets the active object to active. |
|
2698 |
|
2699 Parameters: RTestModule& aServer: in: Reference to the server object |
|
2700 |
|
2701 Return Values: None |
|
2702 |
|
2703 Errors/Exceptions: TInt: Return KErrNone |
|
2704 |
|
2705 Status: Approved |
|
2706 |
|
2707 ------------------------------------------------------------------------------- |
|
2708 */ |
|
2709 TInt CErrorPrinter::StartL( RTestModule& aServer ) |
|
2710 { |
|
2711 iServer = aServer; |
|
2712 |
|
2713 CActiveScheduler::Add ( this ); |
|
2714 |
|
2715 SetActive(); |
|
2716 aServer.ErrorNotification ( iErrorPckg, iStatus ); |
|
2717 |
|
2718 return KErrNone; |
|
2719 |
|
2720 } |
|
2721 |
|
2722 /* |
|
2723 ------------------------------------------------------------------------------- |
|
2724 |
|
2725 Class: CErrorPrinter |
|
2726 |
|
2727 Method: RunL |
|
2728 |
|
2729 Parameters: None |
|
2730 |
|
2731 Return Values: None |
|
2732 |
|
2733 Errors/Exceptions: None |
|
2734 |
|
2735 Status: Approved |
|
2736 |
|
2737 ------------------------------------------------------------------------------- |
|
2738 */ |
|
2739 void CErrorPrinter::RunL() |
|
2740 { |
|
2741 |
|
2742 if ( iStatus.Int() != KErrNone ) |
|
2743 { |
|
2744 __TRACE( KVerbose, ( _L( "In CErrorPrinter::RunL [iStatus = %d]" ), iStatus.Int() ) ); |
|
2745 } |
|
2746 else |
|
2747 { |
|
2748 // Forward error print to UI and set request again active. |
|
2749 iEngine->ErrorPrint( iErrorPckg ); |
|
2750 SetActive(); |
|
2751 iServer.ErrorNotification ( iErrorPckg, iStatus ); |
|
2752 } |
|
2753 } |
|
2754 |
|
2755 /* |
|
2756 ------------------------------------------------------------------------------- |
|
2757 |
|
2758 Class: CErrorPrinter |
|
2759 |
|
2760 Method: DoCancel |
|
2761 |
|
2762 Description: Cancels the asynchronous request |
|
2763 |
|
2764 Parameters: None |
|
2765 |
|
2766 Return Values: None |
|
2767 |
|
2768 Errors/Exceptions: None |
|
2769 |
|
2770 Status: Approved |
|
2771 |
|
2772 ------------------------------------------------------------------------------- |
|
2773 */ |
|
2774 void CErrorPrinter::DoCancel() |
|
2775 { |
|
2776 iServer.CancelAsyncRequest ( ETestModuleErrorNotification ); |
|
2777 |
|
2778 } |
|
2779 |
|
2780 /* |
|
2781 ------------------------------------------------------------------------------- |
|
2782 |
|
2783 Class: CErrorPrinter |
|
2784 |
|
2785 Method: RunError |
|
2786 |
|
2787 Description: Handles errors. RunL can't leave so just forward error |
|
2788 and let framework handle error. |
|
2789 |
|
2790 Parameters: TInt aError: in: Error code |
|
2791 |
|
2792 Return Values: TInt: Error code |
|
2793 |
|
2794 Errors/Exceptions: None |
|
2795 |
|
2796 Status: Approved |
|
2797 |
|
2798 ------------------------------------------------------------------------------- |
|
2799 */ |
|
2800 TInt CErrorPrinter::RunError( TInt aError ) |
|
2801 { |
|
2802 return aError; |
|
2803 |
|
2804 } |
|
2805 /* |
|
2806 ------------------------------------------------------------------------------- |
|
2807 |
|
2808 Class: CServerStateHandler |
|
2809 |
|
2810 Method: NewL |
|
2811 |
|
2812 Description: Constructs a new CServerStateHandler object. |
|
2813 |
|
2814 Parameters: CTestEngine* aMain |
|
2815 |
|
2816 Return Values: CServerStateHandler*: New undertaker |
|
2817 |
|
2818 Errors/Exceptions: Leaves if memory allocation or ConstructL leaves. |
|
2819 |
|
2820 Status: Proposal |
|
2821 |
|
2822 ------------------------------------------------------------------------------- |
|
2823 */ |
|
2824 CServerStateHandler* CServerStateHandler::NewL( CTestEngine* aTestEngine, |
|
2825 CTestModuleController* aTestModuleController ) |
|
2826 { |
|
2827 |
|
2828 CServerStateHandler* self = |
|
2829 new( ELeave ) CServerStateHandler( aTestEngine, aTestModuleController ); |
|
2830 CleanupStack::PushL( self ); |
|
2831 self->ConstructL(); |
|
2832 CleanupStack::Pop( self ); |
|
2833 return self; |
|
2834 |
|
2835 } |
|
2836 /* |
|
2837 ------------------------------------------------------------------------------- |
|
2838 |
|
2839 Class: CServerStateHandler |
|
2840 |
|
2841 Method: ConstructL |
|
2842 |
|
2843 Description: Second level constructor. |
|
2844 |
|
2845 Parameters: None |
|
2846 |
|
2847 Return Values: None |
|
2848 |
|
2849 Errors/Exceptions: None |
|
2850 |
|
2851 Status: Proposal |
|
2852 |
|
2853 ------------------------------------------------------------------------------- |
|
2854 */ |
|
2855 void CServerStateHandler::ConstructL() |
|
2856 { |
|
2857 |
|
2858 } |
|
2859 |
|
2860 /* |
|
2861 ------------------------------------------------------------------------------- |
|
2862 |
|
2863 Class: CServerStateHandler |
|
2864 |
|
2865 Method: CServerStateHandler |
|
2866 |
|
2867 Description: Constructor |
|
2868 |
|
2869 Parameters: CTestEngine* aMain |
|
2870 |
|
2871 Return Values: None |
|
2872 |
|
2873 Errors/Exceptions: None |
|
2874 |
|
2875 Status: Proposal |
|
2876 |
|
2877 ------------------------------------------------------------------------------- |
|
2878 */ |
|
2879 CServerStateHandler::CServerStateHandler( CTestEngine* aTestEngine, |
|
2880 CTestModuleController* aTestModuleController ) : |
|
2881 CActive( CActive::EPriorityStandard ), |
|
2882 iEngine( aTestEngine ), |
|
2883 iTestModuleController( aTestModuleController ) |
|
2884 { |
|
2885 |
|
2886 } |
|
2887 |
|
2888 /* |
|
2889 ------------------------------------------------------------------------------- |
|
2890 |
|
2891 Class: CServerStateHandler |
|
2892 |
|
2893 Method: ~CServerStateHandler |
|
2894 |
|
2895 Description: Destructor. |
|
2896 Cancels active request. |
|
2897 |
|
2898 Parameters: None |
|
2899 |
|
2900 Return Values: None |
|
2901 |
|
2902 Errors/Exceptions: None |
|
2903 |
|
2904 Status: Proposal |
|
2905 |
|
2906 ------------------------------------------------------------------------------- |
|
2907 */ |
|
2908 CServerStateHandler::~CServerStateHandler() |
|
2909 { |
|
2910 |
|
2911 Cancel(); |
|
2912 |
|
2913 iServerThread.Close(); |
|
2914 |
|
2915 } |
|
2916 /* |
|
2917 ------------------------------------------------------------------------------- |
|
2918 |
|
2919 Class: CServerStateHandler |
|
2920 |
|
2921 Method: StartL |
|
2922 |
|
2923 Description: Starts to monitor server thread. |
|
2924 |
|
2925 Parameters: RTestServer& aServer |
|
2926 |
|
2927 Return Values: TInt: |
|
2928 |
|
2929 Errors/Exceptions: |
|
2930 |
|
2931 Status: Proposal |
|
2932 |
|
2933 ------------------------------------------------------------------------------- |
|
2934 */ |
|
2935 TInt CServerStateHandler::StartL( RTestServer& aServer ) |
|
2936 { |
|
2937 |
|
2938 __TRACE( KVerbose, ( _L( "CServerStateHandler::StartL" ) ) ); |
|
2939 |
|
2940 TThreadId serverThreadId; |
|
2941 |
|
2942 iStatus = KRequestPending; |
|
2943 |
|
2944 // Asks from server its thread ID value |
|
2945 User::LeaveIfError( aServer.GetServerThreadId ( serverThreadId ) ); |
|
2946 |
|
2947 // Opens handle to thread |
|
2948 User::LeaveIfError( iServerThread.Open( serverThreadId ) ); |
|
2949 |
|
2950 CActiveScheduler::Add( this ); |
|
2951 |
|
2952 // Requests notification when this thread dies, normally or otherwise |
|
2953 iServerThread.Logon( iStatus ); // Miten RThread hanska ko serveriin.. |
|
2954 |
|
2955 SetActive(); |
|
2956 |
|
2957 return KErrNone; |
|
2958 |
|
2959 } |
|
2960 /* |
|
2961 ------------------------------------------------------------------------------- |
|
2962 |
|
2963 Class: CServerStateHandler |
|
2964 |
|
2965 Method: RunL |
|
2966 |
|
2967 Description: Handles thread death. |
|
2968 |
|
2969 Parameters: None |
|
2970 |
|
2971 Return Values: None |
|
2972 |
|
2973 Errors/Exceptions: None |
|
2974 |
|
2975 Status: Proposal |
|
2976 |
|
2977 ------------------------------------------------------------------------------- |
|
2978 */ |
|
2979 void CServerStateHandler::RunL() |
|
2980 { |
|
2981 |
|
2982 // something went badly wrong! |
|
2983 __TRACE( KInit, ( CStifLogger::ERed, |
|
2984 _L( "Test case execution fails. Possible reason: KErrServerTerminated" ) ) ); |
|
2985 |
|
2986 RDebug::Print( _L("Test case execution fails. Possible reason: KErrServerTerminated") ); |
|
2987 |
|
2988 // Note: |
|
2989 // More Info about STIF panic with KErrServerTerminated |
|
2990 // will be informed to the user via testengine log and testreport |
|
2991 // in CTestCaseController::RunL() method |
|
2992 |
|
2993 // TestModuleCrash is called for doing all needed recovering operations for enabling STIF |
|
2994 // to continue test case execution |
|
2995 iEngine->TestModuleCrash( iTestModuleController ); |
|
2996 |
|
2997 } |
|
2998 /* |
|
2999 ------------------------------------------------------------------------------- |
|
3000 |
|
3001 Class: CServerStateHandler |
|
3002 |
|
3003 Method: DoCancel |
|
3004 |
|
3005 Description: Stops listening TestServer status. |
|
3006 |
|
3007 Parameters: None |
|
3008 |
|
3009 Return Values: None |
|
3010 |
|
3011 Errors/Exceptions: None |
|
3012 |
|
3013 Status: Proposal |
|
3014 |
|
3015 ------------------------------------------------------------------------------- |
|
3016 */ |
|
3017 void CServerStateHandler::DoCancel() |
|
3018 { |
|
3019 |
|
3020 __TRACE( KVerbose, ( _L( "CServerStateHandler::DoCancel" ) ) ); |
|
3021 |
|
3022 // Cancels an outstanding request for notification of the death of this thread. |
|
3023 iServerThread.LogonCancel( iStatus ); |
|
3024 |
|
3025 } |
|
3026 /* |
|
3027 ------------------------------------------------------------------------------- |
|
3028 |
|
3029 Class: CServerStateHandler |
|
3030 |
|
3031 Method: RunError |
|
3032 |
|
3033 Description: Handle errors. RunL function does not leave, so one should |
|
3034 never come here. |
|
3035 |
|
3036 Print trace and let framework handle error( i.e to do Panic ) |
|
3037 |
|
3038 Parameters: TInt aError: in: Error code |
|
3039 |
|
3040 Return Values: TInt: Error code |
|
3041 |
|
3042 Errors/Exceptions: None |
|
3043 |
|
3044 Status: Proposal |
|
3045 |
|
3046 ------------------------------------------------------------------------------- |
|
3047 */ |
|
3048 TInt CServerStateHandler::RunError( TInt aError ) |
|
3049 { |
|
3050 __TRACE( KError,( _L( "CServerStateHandler::RunError" ) ) ); |
|
3051 return aError; |
|
3052 |
|
3053 } |
|
3054 |
|
3055 /* |
|
3056 ------------------------------------------------------------------------------- |
|
3057 |
|
3058 Class: - |
|
3059 |
|
3060 Method: GenerateModuleName |
|
3061 |
|
3062 Description: Check is module TestScripter. Does parsing and returns new |
|
3063 module name and error codes(Needed operations when creating |
|
3064 server sessions to TestScripter). |
|
3065 |
|
3066 Parameters: const TFileName& aModuleName: in: Module name for checking. |
|
3067 TFileName& aNewModuleName: inout: Parsed module name. |
|
3068 |
|
3069 Return Values: KErrNone if TestScripter releated module. |
|
3070 KErrNotFound if not TestScripter releated module. |
|
3071 |
|
3072 Errors/Exceptions: None |
|
3073 |
|
3074 Status: Proposal |
|
3075 |
|
3076 ------------------------------------------------------------------------------- |
|
3077 */ |
|
3078 |
|
3079 TInt GenerateModuleName(const TDesC& aModuleName, |
|
3080 TDes& aNewModuleName) |
|
3081 { |
|
3082 // Check that length is greated than KTestScripterNameLength |
|
3083 if( aModuleName.Length() < KTestScripterNameLength ) |
|
3084 { |
|
3085 return KErrNotFound; |
|
3086 } |
|
3087 // Check is TestScripter |
|
3088 TPtrC check( aModuleName.Mid( 0, KTestScripterNameLength ) ); |
|
3089 TInt ret = check.CompareF( KTestScripterName ); |
|
3090 if( ret == KErrNone ) |
|
3091 { |
|
3092 aNewModuleName.Copy( aModuleName.Mid( 0, KTestScripterNameLength ) ); |
|
3093 aNewModuleName.LowerCase(); |
|
3094 } |
|
3095 else |
|
3096 { |
|
3097 return KErrNotFound; |
|
3098 } |
|
3099 |
|
3100 return KErrNone; |
|
3101 |
|
3102 } |
|
3103 |
|
3104 // ================= OTHER EXPORTED FUNCTIONS ================================= |
|
3105 |
|
3106 // None |
|
3107 |
|
3108 // End of File |