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: CUIEngine: This object executes test cases from STIF |
|
15 * Test Framework. |
|
16 * |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 #include <e32svr.h> |
|
22 #include <stifinternal/UIEngine.h> |
|
23 #include <stifinternal/UIEngineContainer.h> |
|
24 #include "UIEnginePrinter.h" |
|
25 #include "UIEngineRunner.h" |
|
26 #include "UIEngineRemote.h" |
|
27 #include "Logging.h" |
|
28 |
|
29 |
|
30 // EXTERNAL DATA STRUCTURES |
|
31 // None |
|
32 |
|
33 // EXTERNAL FUNCTION PROTOTYPES |
|
34 // None |
|
35 |
|
36 // CONSTANTS |
|
37 // None |
|
38 |
|
39 // MACROS |
|
40 #ifdef LOGGER |
|
41 #undef LOGGER |
|
42 #endif |
|
43 #define LOGGER iUIEngine->iLogger |
|
44 |
|
45 // LOCAL CONSTANTS AND MACROS |
|
46 // None |
|
47 |
|
48 // MODULE DATA STRUCTURES |
|
49 // None |
|
50 |
|
51 // LOCAL FUNCTION PROTOTYPES |
|
52 // None |
|
53 |
|
54 // FORWARD DECLARATIONS |
|
55 // None |
|
56 |
|
57 // ==================== LOCAL FUNCTIONS ======================================= |
|
58 // None |
|
59 |
|
60 // ================= MEMBER FUNCTIONS ========================================= |
|
61 |
|
62 |
|
63 /* |
|
64 ------------------------------------------------------------------------------- |
|
65 |
|
66 Class: CUIEngineContainer |
|
67 |
|
68 Method: CUIEngineContainer |
|
69 |
|
70 Description: Default constructor |
|
71 |
|
72 C++ default constructor can NOT contain any code, that |
|
73 might leave. |
|
74 |
|
75 Parameters: CUIEngine* aUIEngine: in: Pointer to CUIEngine interface |
|
76 TTestInfo& aTestInfo: in: Test information |
|
77 |
|
78 Return Values: None |
|
79 |
|
80 Errors/Exceptions: None |
|
81 |
|
82 Status: Draft |
|
83 |
|
84 ------------------------------------------------------------------------------- |
|
85 */ |
|
86 CUIEngineContainer::CUIEngineContainer( CUIEngine* aUIEngine, |
|
87 const TTestInfo& aTestInfo, |
|
88 RTestEngineServer& aTestEngineServ, |
|
89 RTestEngine& aTestEngine ) : |
|
90 iUIEngine( aUIEngine ), |
|
91 iTestInfo( aTestInfo ), |
|
92 iTestInfoPckg( iTestInfo ), |
|
93 iState( ENotStarted ) |
|
94 { |
|
95 __TRACE( KPrint, ( _L( "CUIEngineContainer::CUIEngineContainer.") ) ); |
|
96 |
|
97 // Get handles to test engine |
|
98 iTestEngineServ = aTestEngineServ; |
|
99 iTestEngine = aTestEngine; |
|
100 |
|
101 __ASSERT_ALWAYS( aUIEngine, User::Panic( _L("Null pointer"), KErrGeneral ) ); |
|
102 |
|
103 } |
|
104 |
|
105 /* |
|
106 ------------------------------------------------------------------------------- |
|
107 |
|
108 Class: CUIEngineContainer |
|
109 |
|
110 Method: ConstructL |
|
111 |
|
112 Description: Symbian OS second phase constructor |
|
113 |
|
114 Symbian OS default constructor can leave |
|
115 |
|
116 Parameters: None |
|
117 |
|
118 Return Values: None |
|
119 |
|
120 Errors/Exceptions: Leaves if called Open method returns error |
|
121 |
|
122 Status: Draft |
|
123 |
|
124 ------------------------------------------------------------------------------- |
|
125 */ |
|
126 void CUIEngineContainer::ConstructL() |
|
127 { |
|
128 __TRACE( KPrint, ( _L( "CUIEngineContainer::ConstructL.") ) ); |
|
129 |
|
130 // Open test case |
|
131 User::LeaveIfError( iTestCase.Open( iTestEngineServ, iTestInfoPckg ) ); |
|
132 } |
|
133 |
|
134 /* |
|
135 ------------------------------------------------------------------------------- |
|
136 |
|
137 Class: CUIEngineContainer |
|
138 |
|
139 Method: NewL |
|
140 |
|
141 Description: Two-phased constructor. |
|
142 |
|
143 Parameters: CUIEngine* aUIEngine: in: pointer to CUIEngine Interface |
|
144 TTestInfo& aTestInfo: in: Test info |
|
145 |
|
146 Return Values: CUIEngineRunner* : pointer to created runner object |
|
147 |
|
148 Errors/Exceptions: Leaves if memory allocation for CUIEngineRunner fails |
|
149 Leaves if ConstructL leaves |
|
150 |
|
151 Status: Draft |
|
152 |
|
153 ------------------------------------------------------------------------------- |
|
154 */ |
|
155 CUIEngineContainer* CUIEngineContainer::NewL( CUIEngine* aUIEngine, |
|
156 const TTestInfo& aTestInfo, |
|
157 RTestEngineServer& aTestEngineServ, |
|
158 RTestEngine& aTestEngine ) |
|
159 { |
|
160 CUIEngineContainer* self = |
|
161 new ( ELeave ) CUIEngineContainer( aUIEngine, |
|
162 aTestInfo, |
|
163 aTestEngineServ, |
|
164 aTestEngine ); |
|
165 CleanupStack::PushL( self ); |
|
166 self->ConstructL(); |
|
167 CleanupStack::Pop(); |
|
168 return self; |
|
169 } |
|
170 |
|
171 /* |
|
172 ------------------------------------------------------------------------------- |
|
173 |
|
174 Class: CUIEngineContainer |
|
175 |
|
176 Method: ~CUIEngineContainer |
|
177 |
|
178 Description: Destructor |
|
179 |
|
180 Parameters: None |
|
181 |
|
182 Return Values: None |
|
183 |
|
184 Errors/Exceptions: None |
|
185 |
|
186 Status: Draft |
|
187 |
|
188 ------------------------------------------------------------------------------- |
|
189 */ |
|
190 CUIEngineContainer::~CUIEngineContainer() |
|
191 { |
|
192 |
|
193 __TRACE( KPrint, ( _L( "CUIEngineContainer::~CUIEngineContainer.") ) ); |
|
194 |
|
195 delete iPrinter; |
|
196 delete iRunner; |
|
197 delete iRemote; |
|
198 |
|
199 // Close test case |
|
200 iTestCase.Close(); |
|
201 |
|
202 } |
|
203 |
|
204 |
|
205 /* |
|
206 ------------------------------------------------------------------------------- |
|
207 |
|
208 Class: CUIEngineContainer |
|
209 |
|
210 Method: StartContinerL |
|
211 |
|
212 Description: StartContinerL call CUIEngineRunner to starting test case execution |
|
213 |
|
214 Parameters: None |
|
215 |
|
216 Return Values: TInt KErrNone: Always returned KErrNone |
|
217 |
|
218 Errors/Exceptions: None |
|
219 |
|
220 Status: Draft |
|
221 |
|
222 ------------------------------------------------------------------------------- |
|
223 */ |
|
224 TInt CUIEngineContainer::StartContainerL() |
|
225 { |
|
226 |
|
227 __TRACE( KPrint, ( _L( "CUIEngineContainer::StartContainerL. Running test case: %S"), |
|
228 &( iTestInfo.iTestCaseInfo.iTitle ) ) ); |
|
229 |
|
230 // Start printer |
|
231 iPrinter = CUIEnginePrinter::NewL( this ); |
|
232 iPrinter->StartL( iTestCase ); |
|
233 |
|
234 // Start remote |
|
235 iRemote = CUIEngineRemote::NewL( this ); |
|
236 iRemote->StartL( iTestCase ); |
|
237 |
|
238 // Start runner |
|
239 iRunner = CUIEngineRunner::NewL( this ); |
|
240 iRunner->StartL( iTestCase ); |
|
241 |
|
242 // Update state of test case |
|
243 iState = ERunning; |
|
244 |
|
245 __TRACE( KPrint, ( _L( "CUIEngineContainer::StartContainerL: started") ) ); |
|
246 |
|
247 return KErrNone; |
|
248 |
|
249 } |
|
250 |
|
251 /* |
|
252 ------------------------------------------------------------------------------- |
|
253 |
|
254 Class: CUIEngineContainer |
|
255 |
|
256 Method: CancelTest |
|
257 |
|
258 Description: CancelTest cancels test case execution |
|
259 |
|
260 Parameters: None |
|
261 |
|
262 Return Values: TInt KErrNone: Always returned KErrNone |
|
263 |
|
264 Errors/Exceptions: None |
|
265 |
|
266 Status: Draft |
|
267 |
|
268 ------------------------------------------------------------------------------- |
|
269 */ |
|
270 EXPORT_C TInt CUIEngineContainer::CancelTest() |
|
271 { |
|
272 |
|
273 if ( iState == ERunning || iState == EPaused ) |
|
274 { |
|
275 __TRACE( KPrint, ( _L( "CUIEngineContainer::CancelTest") ) ); |
|
276 |
|
277 // Cancel test case execution |
|
278 iTestCase.CancelAsyncRequest( ETestCaseRunTestCase ); |
|
279 |
|
280 } |
|
281 |
|
282 return KErrNone; |
|
283 } |
|
284 |
|
285 |
|
286 /* |
|
287 ------------------------------------------------------------------------------- |
|
288 |
|
289 Class: CUIEngineContainer |
|
290 |
|
291 Method: PauseTest |
|
292 |
|
293 Description: PauseTest pauses test case execution |
|
294 |
|
295 Parameters: None |
|
296 |
|
297 Return Values: Symbian OS error: Error code |
|
298 |
|
299 Errors/Exceptions: None |
|
300 |
|
301 Status: Draft |
|
302 |
|
303 ------------------------------------------------------------------------------- |
|
304 */ |
|
305 EXPORT_C TInt CUIEngineContainer::PauseTest() |
|
306 { |
|
307 TInt ret(KErrNone); |
|
308 |
|
309 if ( iState == ERunning ) |
|
310 { |
|
311 ret = iTestCase.Pause(); |
|
312 |
|
313 __TRACE( KPrint, ( _L( "CUIEngineContainer::PauseTest. Ret = %d"), ret ) ); |
|
314 |
|
315 if ( ret == KErrNone) |
|
316 { |
|
317 iState = EPaused; |
|
318 } |
|
319 } |
|
320 |
|
321 return ret; |
|
322 } |
|
323 |
|
324 |
|
325 /* |
|
326 ------------------------------------------------------------------------------- |
|
327 |
|
328 Class: CUIEngineContainer |
|
329 |
|
330 Method: ResumeTest |
|
331 |
|
332 Description: PauseTest resumes test case execution |
|
333 |
|
334 Parameters: None |
|
335 |
|
336 Return Values: Symbian OS error: Error code |
|
337 |
|
338 Errors/Exceptions: None |
|
339 |
|
340 Status: Draft |
|
341 |
|
342 ------------------------------------------------------------------------------- |
|
343 */ |
|
344 EXPORT_C TInt CUIEngineContainer::ResumeTest() |
|
345 { |
|
346 TInt ret(KErrNone); |
|
347 |
|
348 if ( iState == EPaused ) |
|
349 { |
|
350 ret = iTestCase.Resume(); |
|
351 |
|
352 __TRACE( KPrint, ( _L( "CUIEngineContainer::ResumeTest. Ret = %d"), ret ) ); |
|
353 |
|
354 if ( ret == KErrNone) |
|
355 { |
|
356 iState = ERunning; |
|
357 } |
|
358 } |
|
359 |
|
360 return ret; |
|
361 } |
|
362 |
|
363 |
|
364 /* |
|
365 ------------------------------------------------------------------------------- |
|
366 |
|
367 Class: CUIEngineContainer |
|
368 |
|
369 Method: TestCaseExecuted |
|
370 |
|
371 Description: TestCaseExecuted informs that test case is executed |
|
372 |
|
373 Parameters: TFullTestResult& aFullTestResult: in: Full information of |
|
374 test case execution. Includes also test case results |
|
375 |
|
376 Return Values: None |
|
377 |
|
378 Errors/Exceptions: TInt KErrNone: Always returned KErrNone |
|
379 |
|
380 Status: Draft |
|
381 |
|
382 ------------------------------------------------------------------------------- |
|
383 */ |
|
384 void CUIEngineContainer::TestCaseExecuted( TFullTestResult& aFullTestResult, |
|
385 TInt aStatus ) |
|
386 { |
|
387 |
|
388 iState = EExecuted; |
|
389 |
|
390 // Set execution result |
|
391 if( ( KErrNone != aStatus ) && |
|
392 ( aFullTestResult.iCaseExecutionResultCode == KErrNone ) && |
|
393 ( aFullTestResult.iTestResult.iResult == KErrNone ) ) |
|
394 { |
|
395 aFullTestResult.iTestResult.iResultDes.Copy( |
|
396 _L("Completed with error") ); |
|
397 aFullTestResult.iCaseExecutionResultType = |
|
398 TFullTestResult::ECaseErrorFromModule; |
|
399 aFullTestResult.iCaseExecutionResultCode = aStatus; |
|
400 } |
|
401 |
|
402 __TRACE( KPrint, ( _L( "CUIEngineContainer::TestCaseExecuted.") ) ); |
|
403 |
|
404 // Test execution is not completed before all prints are |
|
405 // delivered to UI. |
|
406 if( !iPrinter->IsRunning() || |
|
407 ( aStatus != KErrNone ) || |
|
408 ( aFullTestResult.iCaseExecutionResultCode != KErrNone ) ) |
|
409 { |
|
410 // Call TestExecuted of CUIEngine interface |
|
411 iUIEngine->TestExecuted(this, aFullTestResult); |
|
412 // 1. This method is called from CUIEngineRunner::RunL() and it is |
|
413 // last operation => no other call to CUIEngineContainer class. |
|
414 // 2. TestExecuted() method takes this pointer. Inside TestExecuted() |
|
415 // will be deleted the this pointer => iUIEngine not valid anymore. |
|
416 // 1 and 2 => Do not handle any CUIEngineContainer variable here |
|
417 // because memory is not valid anymore. |
|
418 //e.g. iState = EFinished; // illegal operation here->crash |
|
419 |
|
420 } |
|
421 |
|
422 } |
|
423 |
|
424 |
|
425 /* |
|
426 ------------------------------------------------------------------------------- |
|
427 |
|
428 Class: CUIEngineContainer |
|
429 |
|
430 Method: PrintProgress |
|
431 |
|
432 Description: PrintProgress prints information from test case |
|
433 |
|
434 Parameters: TTestProgress& aProgress: in: Progress info |
|
435 |
|
436 Return Values: None |
|
437 |
|
438 Errors/Exceptions: None |
|
439 |
|
440 Status: Draft |
|
441 |
|
442 ------------------------------------------------------------------------------- |
|
443 */ |
|
444 void CUIEngineContainer::PrintProgress( TTestProgress& aProgress ) |
|
445 { |
|
446 if( iState == ERunning ) |
|
447 { |
|
448 // Only running cases may print |
|
449 iUIEngine->PrintProg( this, aProgress ); |
|
450 } |
|
451 else |
|
452 { |
|
453 __TRACE( KPrint, |
|
454 ( _L("%S: %S"), &aProgress.iDescription, &aProgress.iText ) ); |
|
455 } |
|
456 } |
|
457 |
|
458 /* |
|
459 ------------------------------------------------------------------------------- |
|
460 |
|
461 Class: CUIEngineContainer |
|
462 |
|
463 Method: PrintsDone |
|
464 |
|
465 Description: Signals that printing is completed |
|
466 |
|
467 Parameters: None |
|
468 |
|
469 Return Values: None |
|
470 |
|
471 Errors/Exceptions: None |
|
472 |
|
473 Status: Draft |
|
474 |
|
475 ------------------------------------------------------------------------------- |
|
476 */ |
|
477 void CUIEngineContainer::PrintsDone() |
|
478 { |
|
479 if( iState == EExecuted ) |
|
480 { |
|
481 // Call TestExecuted of CUIEngine interface |
|
482 iUIEngine->TestExecuted(this, iRunner->FullResult() ); |
|
483 } |
|
484 } |
|
485 |
|
486 /* |
|
487 ------------------------------------------------------------------------------- |
|
488 |
|
489 Class: CUIEngineContainer |
|
490 |
|
491 Method: RemoteSend |
|
492 |
|
493 Description: RemoteSend forwards remote protocol messages from master |
|
494 |
|
495 Parameters: |
|
496 |
|
497 Return Values: None |
|
498 |
|
499 Errors/Exceptions: None |
|
500 |
|
501 Status: Draft |
|
502 |
|
503 ------------------------------------------------------------------------------- |
|
504 */ |
|
505 void CUIEngineContainer::RemoteSend( const TDesC& aRemoteMsg, |
|
506 TInt /* aStatus */ ) |
|
507 { |
|
508 |
|
509 __TRACE( KPrint, ( _L( "CUIEngineContainer::RemoteSend.") ) ); |
|
510 |
|
511 // Save master id if doesn't exists already |
|
512 if( iMasterId == 0 ) |
|
513 { |
|
514 CStifTFwIfProt* msg = NULL; |
|
515 TRAPD( err, |
|
516 msg = CStifTFwIfProt::NewL(); |
|
517 msg->SetL( aRemoteMsg ); |
|
518 ); |
|
519 if( err != KErrNone ) |
|
520 { |
|
521 delete msg; |
|
522 // oom |
|
523 return; |
|
524 } |
|
525 iMasterId = msg->SrcId(); |
|
526 delete msg; |
|
527 } |
|
528 |
|
529 // Call AtsSend of CUIEngine interface |
|
530 iUIEngine->RemoteMsg( this, aRemoteMsg ); |
|
531 |
|
532 } |
|
533 |
|
534 /* |
|
535 ------------------------------------------------------------------------------- |
|
536 |
|
537 Class: CUIEngineContainer |
|
538 |
|
539 Method: GoingToReboot |
|
540 |
|
541 Description: Inform UI that phone is going to rebooted |
|
542 |
|
543 Parameters: |
|
544 |
|
545 Return Values: None |
|
546 |
|
547 Errors/Exceptions: None |
|
548 |
|
549 Status: Draft |
|
550 |
|
551 ------------------------------------------------------------------------------- |
|
552 */ |
|
553 TInt CUIEngineContainer::GoingToReboot( TRequestStatus& aStatus ) |
|
554 { |
|
555 |
|
556 __TRACE( KPrint, ( _L( "CUIEngineContainer::GoingToReboot.") ) ); |
|
557 |
|
558 // Forward |
|
559 return iUIEngine->GoingToReboot( this, aStatus ); |
|
560 |
|
561 } |
|
562 |
|
563 /* |
|
564 ------------------------------------------------------------------------------- |
|
565 |
|
566 Class: CUIEngineContainer |
|
567 |
|
568 Method: RemoteReceive |
|
569 |
|
570 Description: RemoteReceive forwards remote protocol messages to master |
|
571 |
|
572 Parameters: |
|
573 |
|
574 Return Values: None |
|
575 |
|
576 Errors/Exceptions: None |
|
577 |
|
578 Status: Draft |
|
579 |
|
580 ------------------------------------------------------------------------------- |
|
581 */ |
|
582 TInt CUIEngineContainer::RemoteReceive( const TDesC& aRemoteMsg ) |
|
583 { |
|
584 |
|
585 __TRACE( KPrint, ( _L( "CUIEngineContainer::RemoteReceive.") ) ); |
|
586 |
|
587 // Check master test case status, FIX110 |
|
588 if( iState != ERunning ) |
|
589 { |
|
590 __TRACE( KError, ( _L( "Master case not running") ) ); |
|
591 |
|
592 return KErrNotFound; |
|
593 } |
|
594 |
|
595 HBufC8* buf = HBufC8::New( aRemoteMsg.Length() ); |
|
596 if( buf == NULL ) |
|
597 { |
|
598 return KErrNoMemory; |
|
599 } |
|
600 |
|
601 TPtr8 tmp = buf->Des(); |
|
602 tmp.Copy( aRemoteMsg ); |
|
603 TInt ret = iTestCase.NotifyRemoteMsg( tmp, EStifCmdReceive ); |
|
604 delete buf; |
|
605 |
|
606 return ret; |
|
607 |
|
608 } |
|
609 |
|
610 // ================= OTHER EXPORTED FUNCTIONS ================================= |
|
611 |
|
612 // End of File |
|