|
1 /* |
|
2 * Copyright (c) 2004 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: Part of TestConsole application. |
|
15 ** Methods for the class CTestAppConsole |
|
16 ** |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include <e32std.h> |
|
22 #include <e32base.h> |
|
23 #include "testconsole.h" |
|
24 #include "testdefinitions.hrh" |
|
25 #include "mccteststubs.h" |
|
26 #include "test_interface.h" |
|
27 #include "test_audiocontrol.h" |
|
28 #include "test_dtmf.h" |
|
29 #include "test_rtcp.h" |
|
30 #include "test_async_features.h" |
|
31 #include "test_secure.h" |
|
32 |
|
33 |
|
34 #ifndef __WINSCW__ |
|
35 const TInt KTestIapId = 1; |
|
36 #else |
|
37 const TInt KTestIapId = 6; |
|
38 #endif |
|
39 |
|
40 //******************************************************************************* |
|
41 // Method : CTestAppConsole::NewL() |
|
42 // Purpose : |
|
43 // Parameters : |
|
44 // Return Value: |
|
45 //******************************************************************************* |
|
46 CTestAppConsole* CTestAppConsole::NewLC() |
|
47 { |
|
48 CTestAppConsole* self = new ( ELeave ) CTestAppConsole(); |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL(); |
|
51 return self; |
|
52 } |
|
53 |
|
54 //******************************************************************************* |
|
55 // Method : CTestAppConsole::CTestAppConsole() |
|
56 // Purpose : Constructor |
|
57 // Parameters : |
|
58 // Return Value: |
|
59 //******************************************************************************* |
|
60 CTestAppConsole::CTestAppConsole() |
|
61 : CActive( EPriorityStandard ) |
|
62 { |
|
63 CActiveScheduler::Add( this ); |
|
64 } |
|
65 |
|
66 //******************************************************************************* |
|
67 // Method : CTestAppConsole::ConstructL() |
|
68 // Purpose : |
|
69 // Parameters : |
|
70 // Return Value: |
|
71 //******************************************************************************* |
|
72 void CTestAppConsole::ConstructL() |
|
73 |
|
74 { |
|
75 ResetNetworkSettings(); |
|
76 |
|
77 iConsole = Console::NewL( KMainTitle, TSize(KConsFullScreen, KConsFullScreen) ); |
|
78 this->DisplayConsoleMenuL( KTxtMainInstructions ); |
|
79 } |
|
80 |
|
81 //******************************************************************************* |
|
82 // Method : CTestAppConsole::~CTestAppConsole() |
|
83 // Purpose : Destructor |
|
84 // Parameters : |
|
85 // Return Value: |
|
86 //******************************************************************************* |
|
87 CTestAppConsole::~CTestAppConsole() |
|
88 { |
|
89 Cancel(); |
|
90 delete iConsole; |
|
91 delete iInstruct; |
|
92 delete iMccInterface; |
|
93 delete iMccInterfaceStub; |
|
94 if ( iFeatTest ) |
|
95 { |
|
96 delete iFeatTest; |
|
97 } |
|
98 } |
|
99 |
|
100 //******************************************************************************* |
|
101 // Method : CTestAppConsole::ResetNetworkSettings() |
|
102 // Purpose : |
|
103 // Parameters : |
|
104 // Return Value: |
|
105 //******************************************************************************* |
|
106 void CTestAppConsole::ResetNetworkSettings() |
|
107 { |
|
108 iNetsettings.iRemoteAddress.SetAddress( KInetAddrLoop ); |
|
109 iNetsettings.iRemoteAddress.SetPort( KDefaultRtpPort ); |
|
110 iNetsettings.iRemoteRtcpPort = KDefaultRtcpPort; |
|
111 iNetsettings.iLocalAddress.SetAddress( KInetAddrAny ); |
|
112 iNetsettings.iLocalAddress.SetPort( KDefaultRtpPort ); |
|
113 iNetsettings.iLocalPublicAddress.SetAddress( KInetAddrAny ); |
|
114 iNetsettings.iLocalRtcpPort = KDefaultRtcpPort; |
|
115 iNetsettings.iLocalPublicRtcpPort = KDefaultRtcpPort; |
|
116 iNetsettings.iMediaQosValue = KDefaultMediaQos; |
|
117 iNetsettings.iIapId = KTestIapId; |
|
118 }; |
|
119 |
|
120 //******************************************************************************* |
|
121 // Method : CTestAppConsole::QueryNetworkSettings() |
|
122 // Purpose : |
|
123 // Parameters : |
|
124 // Return Value: |
|
125 //******************************************************************************* |
|
126 void CTestAppConsole::QueryNetworkSettings() |
|
127 { |
|
128 TBuf16<80> line; |
|
129 |
|
130 iConsole->Printf( _L("\nQUERYING NETWORK SETTINGS") ); |
|
131 iConsole->Printf( _L("\nPress enter to use existing value") ); |
|
132 |
|
133 TUint iap( KTestIapId ); |
|
134 TInt inputErr( 0 ); |
|
135 do |
|
136 { |
|
137 iConsole->Printf( _L("\nINPUT IAPID: ") ); |
|
138 GetStringFromConsole( line ); |
|
139 if ( line.Length() != 0 ) |
|
140 { |
|
141 TLex lex( line ); |
|
142 inputErr = lex.Val( iap ); |
|
143 } |
|
144 } while ( inputErr ); |
|
145 |
|
146 iNetsettings.iIapId = iap; |
|
147 } |
|
148 |
|
149 //******************************************************************************* |
|
150 // Method : CTestAppConsole::QueryIPAddress() |
|
151 // Purpose : |
|
152 // Parameters : |
|
153 // Return Value: |
|
154 //******************************************************************************* |
|
155 void CTestAppConsole::QueryIPAddress() |
|
156 { |
|
157 TBuf16<80> line; |
|
158 |
|
159 // Query IP address and parse it |
|
160 TUint32 address; |
|
161 RArray<TUint32> values; |
|
162 TInt inputErr( 0 ); |
|
163 |
|
164 iConsole->Printf( _L("\nINPUT IP (use dot as a separator): ") ); |
|
165 iConsole->Printf( _L("\nPress enter if IP not needed in tests\n\n") ); |
|
166 GetStringFromConsole( line ); |
|
167 |
|
168 if ( line.Length() != 0 ) |
|
169 { |
|
170 TInt dotIndex( 0 ); |
|
171 TBool dotExist = ETrue; |
|
172 |
|
173 while ( dotExist ) |
|
174 { |
|
175 dotIndex = line.Locate( '.' ); |
|
176 |
|
177 // True if last attribute value |
|
178 if( KErrNotFound == dotIndex ) |
|
179 { |
|
180 dotExist = EFalse; |
|
181 dotIndex = line.Length(); |
|
182 } |
|
183 |
|
184 TUint8 number; |
|
185 TLex16 lex = line.Mid( 0, dotIndex ); |
|
186 |
|
187 inputErr = lex.Val( number, EDecimal ); |
|
188 |
|
189 if ( !inputErr ) |
|
190 { |
|
191 values.AppendL( number ); |
|
192 } |
|
193 |
|
194 if( dotExist ) |
|
195 { |
|
196 line.Delete( 0, dotIndex + 1 ); |
|
197 } |
|
198 } |
|
199 |
|
200 if ( !inputErr && values.Count() == 4 ) |
|
201 { |
|
202 address = INET_ADDR( values[0], values[1], values[2], values[3] ); |
|
203 iNetsettings.iRemoteAddress.SetAddress( address ); |
|
204 } |
|
205 } |
|
206 } |
|
207 |
|
208 //******************************************************************************* |
|
209 // Method : CTestAppConsole::StartTesting() |
|
210 // Purpose : start this AO |
|
211 // Parameters : |
|
212 // Return Value: |
|
213 //******************************************************************************* |
|
214 void CTestAppConsole::StartTesting() |
|
215 { |
|
216 DoRead(); |
|
217 } |
|
218 |
|
219 //******************************************************************************* |
|
220 // Method : CTestAppConsole::DoRead() |
|
221 // Purpose : get the user's option and send request to scheduler |
|
222 // Parameters : |
|
223 // Return Value: |
|
224 //******************************************************************************* |
|
225 void CTestAppConsole::DoRead() |
|
226 { |
|
227 iConsole->Read( iStatus ); |
|
228 SetActive(); |
|
229 } |
|
230 |
|
231 //******************************************************************************* |
|
232 // Method : CTestAppConsole::RunL() |
|
233 // Purpose : |
|
234 // Parameters : |
|
235 // Return Value: |
|
236 //******************************************************************************* |
|
237 void CTestAppConsole::RunL() |
|
238 { |
|
239 // According to current test case and direct the user's command |
|
240 // to proper command handler. |
|
241 ProcessMainInput(); |
|
242 } |
|
243 |
|
244 //******************************************************************************* |
|
245 // Method : CTestAppConsole::DoCancel() |
|
246 // Purpose : |
|
247 // Parameters : |
|
248 // Return Value: |
|
249 //******************************************************************************* |
|
250 void CTestAppConsole::DoCancel() |
|
251 { |
|
252 iConsole->ReadCancel(); |
|
253 } |
|
254 |
|
255 |
|
256 //******************************************************************************* |
|
257 // Method : CTestAppConsole::DisplayConsoleMenu() |
|
258 // Purpose : Display main or sub console menus for different test cases |
|
259 // Parameters : TDesc &aInstructions |
|
260 // Return Value: void |
|
261 //******************************************************************************* |
|
262 |
|
263 void CTestAppConsole::DisplayConsoleMenuL( const TDesC &aInstructions ) |
|
264 { |
|
265 if ( iInstruct ) |
|
266 { |
|
267 delete iInstruct; |
|
268 iInstruct = NULL; |
|
269 } |
|
270 |
|
271 iInstruct = aInstructions.AllocL(); |
|
272 iConsole->ClearScreen(); |
|
273 iConsole->Write( *iInstruct ); |
|
274 } |
|
275 |
|
276 |
|
277 //******************************************************************************* |
|
278 // Method : CTestAppConsole::ProcessMainInput() |
|
279 // Purpose : Obtain user's option and decide which test case to run next. |
|
280 // Parameters : |
|
281 // Return Value: |
|
282 //******************************************************************************* |
|
283 void CTestAppConsole::ProcessMainInput() |
|
284 { |
|
285 TBuf<80> line; |
|
286 GetStringFromConsole(line); |
|
287 |
|
288 if ( line.Length() > 0 ) |
|
289 { |
|
290 TChar inputChar = line[0]; |
|
291 |
|
292 TInt err( KErrNone ); |
|
293 TBool testsRun( ETrue ); |
|
294 switch( inputChar ) |
|
295 { |
|
296 case '1': |
|
297 err = RunInterfaceTests(); |
|
298 break; |
|
299 case '2': |
|
300 err = RunAudioControlTests(); |
|
301 break; |
|
302 case '3': |
|
303 err = RunRtcpTests(); |
|
304 break; |
|
305 case '4': |
|
306 err = RunDtmfTests(); |
|
307 break; |
|
308 case '5': |
|
309 err = RunAsyncFeatureTests(); |
|
310 break; |
|
311 case 's': |
|
312 err = RunSecureTests(); |
|
313 break; |
|
314 case '0': |
|
315 testsRun = EFalse; |
|
316 CActiveScheduler::Stop(); |
|
317 break; |
|
318 default: |
|
319 testsRun = EFalse; |
|
320 DisplayMsg( KTxtWrongOption ); |
|
321 break; |
|
322 } |
|
323 |
|
324 if ( err ) |
|
325 { |
|
326 iConsole->Printf( _L("Some tests failed: %d, check logs\n"), err ); |
|
327 RDebug::Print( _L("\nSome tests failed: %d, check logs\n"), err ); |
|
328 } |
|
329 else if ( testsRun ) |
|
330 { |
|
331 iConsole->Printf( _L( "ALL TESTS OK\n" ) ); |
|
332 RDebug::Print( _L( "\nAll tests OK\n" ) ); |
|
333 } |
|
334 else |
|
335 { |
|
336 |
|
337 } |
|
338 } |
|
339 |
|
340 // Ready to get next input option. |
|
341 DoRead(); |
|
342 } |
|
343 |
|
344 |
|
345 //******************************************************************************* |
|
346 // Method : CTestAppConsole::DisplayMsg() |
|
347 // Purpose : Display testing message on screen |
|
348 // Parameters : TDesC & |
|
349 // Return Value: |
|
350 //******************************************************************************* |
|
351 void CTestAppConsole::DisplayMsg(const TDesC &aMsg) |
|
352 { |
|
353 iConsole->ClearScreen(); |
|
354 iConsole->Write( *iInstruct ); |
|
355 iConsole->Printf( KTxtLineBreak ); |
|
356 iConsole->Printf( aMsg ); |
|
357 iConsole->Printf( KTxtLineBreak ); |
|
358 } |
|
359 |
|
360 //******************************************************************************* |
|
361 // Method : CTestAppConsole::GetAddrFromConsole() |
|
362 // Purpose : |
|
363 // Parameters : |
|
364 // Return Value: |
|
365 //******************************************************************************* |
|
366 TKeyCode CTestAppConsole::GetStringFromConsole( TDes &aAddr ) |
|
367 { |
|
368 // Get a line from console |
|
369 TKeyCode input = EKeyNull; |
|
370 const TInt start_pos = iConsole->WhereX(); |
|
371 aAddr.Zero(); |
|
372 |
|
373 // loop until descriptor full or EKeyEnter or EKeyEscape entered |
|
374 do { |
|
375 // get one character |
|
376 input = iConsole->Getch(); |
|
377 // process it |
|
378 if(input == EKeyBackspace || input == EKeyDelete) |
|
379 { |
|
380 // backspace or delete |
|
381 if(iConsole->WhereX() > start_pos) |
|
382 { |
|
383 iConsole->SetPos(iConsole->WhereX() - 1); |
|
384 iConsole->ClearToEndOfLine(); |
|
385 if(aAddr.Length() > 0) |
|
386 { |
|
387 aAddr.SetLength(aAddr.Length() - 1); |
|
388 } |
|
389 } |
|
390 } |
|
391 else |
|
392 { |
|
393 // other than backspace or delete |
|
394 TChar ch(input); |
|
395 if(ch.IsPrint()) |
|
396 { |
|
397 aAddr.Append(ch); |
|
398 iConsole->Printf(_L("%c"), input); |
|
399 } |
|
400 } |
|
401 } |
|
402 while(aAddr.Length() < aAddr.MaxLength() && input != EKeyEnter && input != EKeyEscape); |
|
403 |
|
404 DisplayMsg( KTxtLineBreak ); |
|
405 return input; |
|
406 } |
|
407 |
|
408 //******************************************************************************* |
|
409 // Method : CTestAppConsole::RunAsyncFeatureTests() |
|
410 // Purpose : Test the async Mcc Interface functions |
|
411 // Parameters : |
|
412 // Return Value: System wide error code |
|
413 //******************************************************************************* |
|
414 // |
|
415 TInt CTestAppConsole::RunAsyncFeatureTests() |
|
416 { |
|
417 QueryNetworkSettings(); |
|
418 TRAPD( err, MccInterfacePreambleL() ); |
|
419 |
|
420 if ( err ) |
|
421 { |
|
422 iConsole->Printf( _L("TESTSETUP FAILED: %d\n"), err ); |
|
423 RDebug::Print( _L("TESTSETUP FAILED: %d\n"), err ); |
|
424 return err; |
|
425 } |
|
426 |
|
427 iFeatTest = CTestAsyncFeat::NewL( *iConsole, iNetsettings, |
|
428 *iMccInterface, *iMccInterfaceStub ); |
|
429 TRAP( err, iFeatTest->DoRunAsyncFeatureTestsL() ); |
|
430 |
|
431 //MccInterfacePostamble(); |
|
432 return err; |
|
433 } |
|
434 |
|
435 //******************************************************************************* |
|
436 // Method : CTestAppConsole::RunInterfaceTests() |
|
437 // Purpose : Test the Mcc Interface functions |
|
438 // Parameters : |
|
439 // Return Value: System wide error code |
|
440 //******************************************************************************* |
|
441 // |
|
442 TInt CTestAppConsole::RunInterfaceTests() |
|
443 { |
|
444 TInt err( KErrNone ); |
|
445 |
|
446 QueryNetworkSettings(); |
|
447 QueryIPAddress(); |
|
448 |
|
449 TRAP( err, MccInterfacePreambleL() ); |
|
450 if ( KErrNone != err ) |
|
451 { |
|
452 iConsole->Printf( _L("TESTSETUP FAILED: %d\n"), err ); |
|
453 RDebug::Print( _L("TESTSETUP FAILED: %d\n"), err ); |
|
454 return err; |
|
455 } |
|
456 |
|
457 CTestInterface* intTest = CTestInterface::NewL( *iConsole, iNetsettings, |
|
458 *iMccInterface, *iMccInterfaceStub ); |
|
459 CleanupStack::PushL( intTest ); |
|
460 |
|
461 TRAP( err, intTest->DoRunInterfaceTestsL() ); |
|
462 |
|
463 CleanupStack::PopAndDestroy( intTest ); |
|
464 MccInterfacePostamble(); |
|
465 return err; |
|
466 } |
|
467 |
|
468 //******************************************************************************* |
|
469 // Method : CTestAppConsole::RunAudioControlTests() |
|
470 // Purpose : Test the Mcc audio control functions |
|
471 // Parameters : |
|
472 // Return Value: System wide error code |
|
473 //******************************************************************************* |
|
474 // |
|
475 TInt CTestAppConsole::RunAudioControlTests() |
|
476 { |
|
477 QueryNetworkSettings(); |
|
478 TInt err( KErrNone ); |
|
479 TRAP( err, MccInterfacePreambleL() ); |
|
480 if ( KErrNone != err ) |
|
481 { |
|
482 iConsole->Printf( _L("TESTSETUP FAILED: %d\n"), err ); |
|
483 RDebug::Print( _L("TESTSETUP FAILED: %d\n"), err ); |
|
484 return err; |
|
485 } |
|
486 |
|
487 CTestAudioControl* audio = CTestAudioControl::NewL( *iConsole, iNetsettings, |
|
488 *iMccInterface, *iMccInterfaceStub ); |
|
489 CleanupStack::PushL( audio ); |
|
490 |
|
491 TRAP( err, audio->DoRunAudioControlTestsL() ); |
|
492 |
|
493 CleanupStack::PopAndDestroy( audio ); |
|
494 MccInterfacePostamble(); |
|
495 return err; |
|
496 } |
|
497 |
|
498 |
|
499 //******************************************************************************* |
|
500 // Method : CTestAppConsole::RunDtmfTests() |
|
501 // Purpose : Test the Mcc RTCP sending |
|
502 // Parameters : |
|
503 // Return Value: System wide error code |
|
504 //******************************************************************************* |
|
505 // |
|
506 TInt CTestAppConsole::RunDtmfTests() |
|
507 { |
|
508 TInt err( KErrNone ); |
|
509 |
|
510 QueryNetworkSettings(); |
|
511 |
|
512 CTestDtmf* dtmf = CTestDtmf::NewL( *iConsole, iNetsettings ); |
|
513 CleanupStack::PushL( dtmf ); |
|
514 |
|
515 TRAP( err, dtmf->DoRunDtmfTestsL() ); |
|
516 |
|
517 CleanupStack::PopAndDestroy( dtmf ); |
|
518 return err; |
|
519 } |
|
520 |
|
521 |
|
522 //******************************************************************************* |
|
523 // Method : CTestAppConsole::RunRtcpTests() |
|
524 // Purpose : Test the Mcc DTMF features |
|
525 // Parameters : |
|
526 // Return Value: System wide error code |
|
527 //******************************************************************************* |
|
528 // |
|
529 TInt CTestAppConsole::RunRtcpTests() |
|
530 { |
|
531 TInt err( KErrNone ); |
|
532 |
|
533 QueryNetworkSettings(); |
|
534 |
|
535 CTestRtcp* rtcp = CTestRtcp::NewL( *iConsole, iNetsettings ); |
|
536 CleanupStack::PushL( rtcp ); |
|
537 |
|
538 TRAP( err, rtcp->DoRunRtcpTestsL() ); |
|
539 |
|
540 CleanupStack::PopAndDestroy( rtcp ); |
|
541 return err; |
|
542 } |
|
543 |
|
544 // --------------------------------------------------------------------------- |
|
545 // CTestAppConsole::MccInterfacePreambleL |
|
546 // |
|
547 // --------------------------------------------------------------------------- |
|
548 // |
|
549 void CTestAppConsole::MccInterfacePreambleL() |
|
550 { |
|
551 iMccInterfaceStub = CMccInterfaceStub::NewL(); |
|
552 iMccInterface = CMccInterface::NewL( *iMccInterfaceStub ); |
|
553 }; |
|
554 |
|
555 // --------------------------------------------------------------------------- |
|
556 // CTestAppConsole::MccInterfacePostamble |
|
557 // |
|
558 // --------------------------------------------------------------------------- |
|
559 // |
|
560 void CTestAppConsole::MccInterfacePostamble() |
|
561 { |
|
562 delete iMccInterface; |
|
563 iMccInterface = NULL; |
|
564 delete iMccInterfaceStub; |
|
565 iMccInterfaceStub = NULL; |
|
566 } |
|
567 |
|
568 // --------------------------------------------------------------------------- |
|
569 // |
|
570 // |
|
571 // --------------------------------------------------------------------------- |
|
572 // |
|
573 TInt CTestAppConsole::RunSecureTests() |
|
574 { |
|
575 TInt err( KErrNone ); |
|
576 |
|
577 QueryNetworkSettings(); |
|
578 |
|
579 TRAP( err, MccInterfacePreambleL() ); |
|
580 if ( KErrNone != err ) |
|
581 { |
|
582 iConsole->Printf( _L("TESTSETUP FAILED: %d\n"), err ); |
|
583 RDebug::Print( _L("TESTSETUP FAILED: %d\n"), err ); |
|
584 return err; |
|
585 } |
|
586 |
|
587 CTestSecure* secTest = CTestSecure::NewL( *iConsole, iNetsettings, |
|
588 *iMccInterface, *iMccInterfaceStub ); |
|
589 CleanupStack::PushL( secTest ); |
|
590 |
|
591 TRAP( err, secTest->DoRunSecureTestsL() ); |
|
592 |
|
593 CleanupStack::Pop( secTest ); |
|
594 MccInterfacePostamble(); |
|
595 |
|
596 return err; |
|
597 } |
|
598 |