|
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 <e32debug.h> |
|
24 #include "muxtestconsole.h" |
|
25 #include "testdefinitions.hrh" |
|
26 #include "muxtestconsolestubs.h" |
|
27 #include "multiplexerudptests.h" |
|
28 #include "multiplexertcptests.h" |
|
29 |
|
30 |
|
31 |
|
32 //******************************************************************************* |
|
33 // Method : CTestAppConsole::NewL() |
|
34 // Purpose : |
|
35 // Parameters : |
|
36 // Return Value: |
|
37 //******************************************************************************* |
|
38 CTestAppConsole* CTestAppConsole::NewLC() |
|
39 { |
|
40 CTestAppConsole* self = new ( ELeave ) CTestAppConsole(); |
|
41 CleanupStack::PushL( self ); |
|
42 self->ConstructL(); |
|
43 return self; |
|
44 } |
|
45 |
|
46 //******************************************************************************* |
|
47 // Method : CTestAppConsole::CTestAppConsole() |
|
48 // Purpose : Constructor |
|
49 // Parameters : |
|
50 // Return Value: |
|
51 //******************************************************************************* |
|
52 CTestAppConsole::CTestAppConsole() |
|
53 : CActive( EPriorityStandard ) |
|
54 { |
|
55 CActiveScheduler::Add( this ); |
|
56 } |
|
57 |
|
58 //******************************************************************************* |
|
59 // Method : CTestAppConsole::ConstructL() |
|
60 // Purpose : |
|
61 // Parameters : |
|
62 // Return Value: |
|
63 //******************************************************************************* |
|
64 void CTestAppConsole::ConstructL() |
|
65 |
|
66 { |
|
67 |
|
68 iConsole = Console::NewL( KMainTitle, TSize(KConsFullScreen, KConsFullScreen) ); |
|
69 this->DisplayConsoleMenuL( KTxtMainInstructions ); |
|
70 } |
|
71 |
|
72 //******************************************************************************* |
|
73 // Method : CTestAppConsole::~CTestAppConsole() |
|
74 // Purpose : Destructor |
|
75 // Parameters : |
|
76 // Return Value: |
|
77 //******************************************************************************* |
|
78 CTestAppConsole::~CTestAppConsole() |
|
79 { |
|
80 Cancel(); |
|
81 delete iConsole; |
|
82 delete iInstruct; |
|
83 delete iMux; |
|
84 delete iMuxStub; |
|
85 } |
|
86 |
|
87 |
|
88 |
|
89 //******************************************************************************* |
|
90 // Method : CTestAppConsole::StartTesting() |
|
91 // Purpose : start this AO |
|
92 // Parameters : |
|
93 // Return Value: |
|
94 //******************************************************************************* |
|
95 void CTestAppConsole::StartTesting() |
|
96 { |
|
97 DoRead(); |
|
98 } |
|
99 |
|
100 //******************************************************************************* |
|
101 // Method : CTestAppConsole::DoRead() |
|
102 // Purpose : get the user's option and send request to scheduler |
|
103 // Parameters : |
|
104 // Return Value: |
|
105 //******************************************************************************* |
|
106 void CTestAppConsole::DoRead() |
|
107 { |
|
108 iConsole->Read( iStatus ); |
|
109 SetActive(); |
|
110 } |
|
111 |
|
112 //******************************************************************************* |
|
113 // Method : CTestAppConsole::RunL() |
|
114 // Purpose : |
|
115 // Parameters : |
|
116 // Return Value: |
|
117 //******************************************************************************* |
|
118 void CTestAppConsole::RunL() |
|
119 { |
|
120 // According to current test case and direct the user's command |
|
121 // to proper command handler. |
|
122 ProcessMainInput(); |
|
123 } |
|
124 |
|
125 //******************************************************************************* |
|
126 // Method : CTestAppConsole::DoCancel() |
|
127 // Purpose : |
|
128 // Parameters : |
|
129 // Return Value: |
|
130 //******************************************************************************* |
|
131 void CTestAppConsole::DoCancel() |
|
132 { |
|
133 iConsole->ReadCancel(); |
|
134 } |
|
135 |
|
136 |
|
137 //******************************************************************************* |
|
138 // Method : CTestAppConsole::DisplayConsoleMenu() |
|
139 // Purpose : Display main or sub console menus for different test cases |
|
140 // Parameters : TDesc &aInstructions |
|
141 // Return Value: void |
|
142 //******************************************************************************* |
|
143 |
|
144 void CTestAppConsole::DisplayConsoleMenuL( const TDesC &aInstructions ) |
|
145 { |
|
146 if ( iInstruct ) |
|
147 { |
|
148 delete iInstruct; |
|
149 iInstruct = NULL; |
|
150 } |
|
151 |
|
152 iInstruct = aInstructions.AllocL(); |
|
153 iConsole->ClearScreen(); |
|
154 iConsole->Write( *iInstruct ); |
|
155 } |
|
156 |
|
157 |
|
158 //******************************************************************************* |
|
159 // Method : CTestAppConsole::ProcessMainInput() |
|
160 // Purpose : Obtain user's option and decide which test case to run next. |
|
161 // Parameters : |
|
162 // Return Value: |
|
163 //******************************************************************************* |
|
164 void CTestAppConsole::ProcessMainInput() |
|
165 { |
|
166 TBuf<80> line; |
|
167 GetStringFromConsole(line); |
|
168 |
|
169 if ( line.Length() > 0 ) |
|
170 { |
|
171 TChar inputChar = line[0]; |
|
172 |
|
173 TInt err( KErrNone ); |
|
174 TBool testsRun( ETrue ); |
|
175 switch( inputChar ) |
|
176 { |
|
177 case '1': |
|
178 err = RunMuxUdpTests(); |
|
179 break; |
|
180 case '2': |
|
181 err = RunMuxTcpTests(); |
|
182 break; |
|
183 case '3': |
|
184 RunUdpAudioStreaming(); |
|
185 break; |
|
186 case '4': |
|
187 StopUdpAudioStreaming(); |
|
188 break; |
|
189 case '0': |
|
190 testsRun = EFalse; |
|
191 CActiveScheduler::Stop(); |
|
192 break; |
|
193 default: |
|
194 testsRun = EFalse; |
|
195 DisplayMsg( KTxtWrongOption ); |
|
196 break; |
|
197 } |
|
198 |
|
199 if ( iAudioTest ) |
|
200 { |
|
201 iConsole->Printf( _L( "Audio test ongoing, Press 4 to stop\n" ) ); |
|
202 } |
|
203 else |
|
204 { |
|
205 if ( err ) |
|
206 { |
|
207 iConsole->Printf( _L("Some tests failed: %d, check logs\n"), err ); |
|
208 RDebug::Print( _L("\nSome tests failed: %d, check logs\n"), err ); |
|
209 } |
|
210 else if ( testsRun ) |
|
211 { |
|
212 iConsole->Printf( _L( "ALL TESTS OK\n" ) ); |
|
213 RDebug::Print( _L( "\nAll tests OK\n" ) ); |
|
214 } |
|
215 else |
|
216 { |
|
217 |
|
218 } |
|
219 } |
|
220 |
|
221 } |
|
222 |
|
223 // Ready to get next input option. |
|
224 DoRead(); |
|
225 } |
|
226 |
|
227 |
|
228 //******************************************************************************* |
|
229 // Method : CTestAppConsole::DisplayMsg() |
|
230 // Purpose : Display testing message on screen |
|
231 // Parameters : TDesC & |
|
232 // Return Value: |
|
233 //******************************************************************************* |
|
234 void CTestAppConsole::DisplayMsg(const TDesC &aMsg) |
|
235 { |
|
236 iConsole->ClearScreen(); |
|
237 iConsole->Write( *iInstruct ); |
|
238 iConsole->Printf( KTxtLineBreak ); |
|
239 iConsole->Printf( aMsg ); |
|
240 iConsole->Printf( KTxtLineBreak ); |
|
241 } |
|
242 |
|
243 //******************************************************************************* |
|
244 // Method : CTestAppConsole::GetAddrFromConsole() |
|
245 // Purpose : |
|
246 // Parameters : |
|
247 // Return Value: |
|
248 //******************************************************************************* |
|
249 TKeyCode CTestAppConsole::GetStringFromConsole( TDes &aAddr ) |
|
250 { |
|
251 // Get a line from console |
|
252 TKeyCode input = EKeyNull; |
|
253 const TInt start_pos = iConsole->WhereX(); |
|
254 aAddr.Zero(); |
|
255 |
|
256 // loop until descriptor full or EKeyEnter or EKeyEscape entered |
|
257 do { |
|
258 // get one character |
|
259 input = iConsole->Getch(); |
|
260 // process it |
|
261 if(input == EKeyBackspace || input == EKeyDelete) |
|
262 { |
|
263 // backspace or delete |
|
264 if(iConsole->WhereX() > start_pos) |
|
265 { |
|
266 iConsole->SetPos(iConsole->WhereX() - 1); |
|
267 iConsole->ClearToEndOfLine(); |
|
268 if(aAddr.Length() > 0) |
|
269 { |
|
270 aAddr.SetLength(aAddr.Length() - 1); |
|
271 } |
|
272 } |
|
273 } |
|
274 else |
|
275 { |
|
276 // other than backspace or delete |
|
277 TChar ch(input); |
|
278 if(ch.IsPrint()) |
|
279 { |
|
280 aAddr.Append(ch); |
|
281 iConsole->Printf(_L("%c"), input); |
|
282 } |
|
283 } |
|
284 } |
|
285 while(aAddr.Length() < aAddr.MaxLength() && input != EKeyEnter && input != EKeyEscape); |
|
286 |
|
287 DisplayMsg( KTxtLineBreak ); |
|
288 return input; |
|
289 } |
|
290 |
|
291 |
|
292 //******************************************************************************* |
|
293 // Method : CTestAppConsole::RunInterfaceTests() |
|
294 // Purpose : Test the Mcc Interface functions |
|
295 // Parameters : |
|
296 // Return Value: System wide error code |
|
297 //******************************************************************************* |
|
298 // |
|
299 TInt CTestAppConsole::RunMuxUdpTests() |
|
300 { |
|
301 TInt err( KErrNone ); |
|
302 |
|
303 TRAP( err, MccInterfacePreambleUdpL() ); |
|
304 if ( KErrNone != err ) |
|
305 { |
|
306 iConsole->Printf( _L("TESTSETUP FAILED: %d\n"), err ); |
|
307 RDebug::Print( _L("TESTSETUP FAILED: %d\n"), err ); |
|
308 return err; |
|
309 } |
|
310 |
|
311 CMultiplexerUdpTests* intTest = CMultiplexerUdpTests::NewL( *iConsole, |
|
312 *iMux, *iMuxStub ); |
|
313 CleanupStack::PushL( intTest ); |
|
314 |
|
315 |
|
316 TRAP( err, intTest->DoRunUdpMuxtTests() ); |
|
317 |
|
318 CleanupStack::PopAndDestroy( intTest ); |
|
319 MccInterfacePostamble(); |
|
320 return err; |
|
321 } |
|
322 |
|
323 //******************************************************************************* |
|
324 // Method : CTestAppConsole::RunInterfaceTests() |
|
325 // Purpose : Test the Mcc Interface functions |
|
326 // Parameters : |
|
327 // Return Value: System wide error code |
|
328 //******************************************************************************* |
|
329 // |
|
330 TInt CTestAppConsole::RunMuxTcpTests() |
|
331 { |
|
332 TInt err( KErrNone ); |
|
333 |
|
334 TRAP( err, MccInterfacePreambleTcpL() ); |
|
335 if ( KErrNone != err ) |
|
336 { |
|
337 iConsole->Printf( _L("TESTSETUP FAILED: %d\n"), err ); |
|
338 RDebug::Print( _L("TESTSETUP FAILED: %d\n"), err ); |
|
339 return err; |
|
340 } |
|
341 |
|
342 CMultiplexerTcpTests* intTest = CMultiplexerTcpTests::NewL( *iConsole, |
|
343 *iMux, *iMuxStub ); |
|
344 CleanupStack::PushL( intTest ); |
|
345 |
|
346 |
|
347 TRAP( err, intTest->DoRunTcpMuxTestsL() ); |
|
348 |
|
349 CleanupStack::PopAndDestroy( intTest ); |
|
350 MccInterfacePostamble(); |
|
351 return err; |
|
352 } |
|
353 |
|
354 //******************************************************************************* |
|
355 // Method : CTestAppConsole::RunUdpAudioStreaming() |
|
356 //******************************************************************************* |
|
357 // |
|
358 void CTestAppConsole::RunUdpAudioStreaming() |
|
359 { |
|
360 iAudioTest = ETrue; |
|
361 |
|
362 TInt err( KErrNone ); |
|
363 __UHEAP_MARK; |
|
364 |
|
365 TRAP( err, MccInterfacePreambleUdpL() ); |
|
366 |
|
367 iIntTest = CMultiplexerUdpTests::NewL( *iConsole, |
|
368 *iMux, *iMuxStub ); |
|
369 |
|
370 |
|
371 TRAP( err, iIntTest->TestUdpAudioStreamingL() ); |
|
372 |
|
373 //MccInterfacePostamble(); |
|
374 //return err; |
|
375 } |
|
376 |
|
377 //******************************************************************************* |
|
378 // Method : CTestAppConsole::StopUdpAudioStreaming() |
|
379 //******************************************************************************* |
|
380 // |
|
381 void CTestAppConsole::StopUdpAudioStreaming() |
|
382 { |
|
383 iAudioTest = EFalse; |
|
384 delete iIntTest; |
|
385 MccInterfacePostamble(); |
|
386 __UHEAP_MARKEND; |
|
387 } |
|
388 |
|
389 // --------------------------------------------------------------------------- |
|
390 // CTestAppConsole::MccInterfacePreambleL |
|
391 // |
|
392 // --------------------------------------------------------------------------- |
|
393 // |
|
394 void CTestAppConsole::MccInterfacePreambleUdpL() |
|
395 { |
|
396 iMuxStub = CMuxTestConsoleStubs::NewL(); |
|
397 __UHEAP_MARK; |
|
398 iMux = CNcmConnectionMultiplexer::NewL( *iMuxStub ); |
|
399 }; |
|
400 |
|
401 // --------------------------------------------------------------------------- |
|
402 // CTestAppConsole::MccInterfacePreambleL |
|
403 // |
|
404 // --------------------------------------------------------------------------- |
|
405 // |
|
406 void CTestAppConsole::MccInterfacePreambleTcpL() |
|
407 { |
|
408 iMuxStub = CMuxTestConsoleStubs::NewL(); |
|
409 __UHEAP_MARK; |
|
410 iMux = CNcmConnectionMultiplexer::NewL( *iMuxStub ); |
|
411 }; |
|
412 |
|
413 // --------------------------------------------------------------------------- |
|
414 // CTestAppConsole::MccInterfacePostamble |
|
415 // |
|
416 // --------------------------------------------------------------------------- |
|
417 // |
|
418 void CTestAppConsole::MccInterfacePostamble() |
|
419 { |
|
420 |
|
421 delete iMux; |
|
422 iMux = NULL; |
|
423 __UHEAP_MARKEND; |
|
424 |
|
425 delete iMuxStub; |
|
426 iMuxStub = NULL; |
|
427 } |
|
428 |