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