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