|
1 /* |
|
2 * Copyright (c) 2007 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include <e32debug.h> |
|
23 #include "natfwconnectivityapidefs.h" |
|
24 #include "natfwconnectivityapi.h" |
|
25 #include <badesca.h> |
|
26 #include "stunturntests.h" |
|
27 #include "natfwtestconsolestubs.h" |
|
28 #include "testdefinitions.hrh" |
|
29 #include "mnatfwsocketmediaconnwrapper.h" |
|
30 #include "wrongserversettings.h" |
|
31 |
|
32 const TInt KDefaultQos = 46; |
|
33 const TUint32 KIncomingAddr = INET_ADDR( 0,0,0,0 ); |
|
34 const TUint KIncomingPort = 100; |
|
35 const TUint32 KTestAddress = INET_ADDR( 193,65,0,0 ); |
|
36 const TUint KTestServerPort = 6000; |
|
37 const TUint KTestServer2Port = 6100; |
|
38 const TInt KTimeoutTime = 2000000; |
|
39 const TUint KRunningTime = 20000000; |
|
40 const TUint KPluginLoadTime = 1000000; |
|
41 const TInt KDefaultGranularity = 1; |
|
42 |
|
43 |
|
44 // ======== MEMBER FUNCTIONS ================================================= |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // CStunTurnTestsInterface::CStunTurnTestsInterface |
|
48 // C++ default constructor can NOT contain any code, that |
|
49 // might leave. |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 CStunTurnTests::CStunTurnTests( |
|
53 CConsoleBase& aConsole, |
|
54 CNATFWConnectivityApi& aNat, |
|
55 CNATConnFWTestConsoleStubs& aIFStub, |
|
56 TUint aIapId, |
|
57 TUint aProtocol ) : |
|
58 iConsole( aConsole ), iNat( aNat ), iIfStub( aIFStub ), iTestIapId( aIapId ), |
|
59 iProtocol( aProtocol ), iNotificationIsOn( ETrue ) |
|
60 { |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // CStunTurnTests::ConstructL |
|
65 // Symbian 2nd phase constructor can leave. |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 void CStunTurnTests::ConstructL( const TDesC8& aDomain, |
|
69 const CDesC8Array& aPlugins ) |
|
70 { |
|
71 iTestDomain = aDomain.AllocL(); |
|
72 |
|
73 |
|
74 iPlugins = new ( ELeave ) CDesC8ArrayFlat( KDefaultGranularity ); |
|
75 |
|
76 TInt count = aPlugins.Count(); |
|
77 |
|
78 for ( TInt i( 0 ); i < count; i++ ) |
|
79 { |
|
80 iPlugins->AppendL( aPlugins[i] ); |
|
81 } |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // CStunTurnTests::NewL |
|
86 // Static constructor. |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 CStunTurnTests* CStunTurnTests::NewL( CConsoleBase& aConsole, |
|
90 CNATFWConnectivityApi& aNat, CNATConnFWTestConsoleStubs& aIFStub, |
|
91 const TDesC8& aDomain, TUint aIapId, TUint aProtocol, |
|
92 const CDesC8Array& aPlugins ) |
|
93 { |
|
94 CStunTurnTests* self |
|
95 = new ( ELeave ) CStunTurnTests( |
|
96 aConsole, aNat, aIFStub, aIapId, aProtocol ); |
|
97 |
|
98 CleanupStack::PushL( self ); |
|
99 self->ConstructL( aDomain, aPlugins ); |
|
100 CleanupStack::Pop( self ); |
|
101 return self; |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // CStunTurnTests::~CStunTurnTests |
|
106 // Destructor. |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 CStunTurnTests::~CStunTurnTests() |
|
110 { |
|
111 delete iTestDomain; |
|
112 delete iPlugins; |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // CStunTurnTests::DoRunInterfaceTestsL |
|
117 // |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 void CStunTurnTests::DoRunStunTurnTestsL() |
|
121 { |
|
122 TInt err( KErrNone ); |
|
123 |
|
124 iConsole.Printf( _L("Create session test") ); |
|
125 RDebug::Print( _L("\n\nNAT_TEST_START: Create session") ); |
|
126 //__UHEAP_MARK; |
|
127 TRAP( err, TestCreateSessionL() ); |
|
128 //__UHEAP_MARKEND; |
|
129 RDebug::Print( _L("\nNAT_TEST_STOP: Create session, ERR: %d"), err ); |
|
130 PrintTestResult( err ); |
|
131 |
|
132 err = KErrNone; |
|
133 RDebug::Print( _L("\n\nNAT_TEST_START: Create stream") ); |
|
134 iConsole.Printf( _L("Create stream test") ); |
|
135 __UHEAP_MARK; |
|
136 TRAP( err, TestCreateStreamL() ); |
|
137 RDebug::Print( _L("\nNAT_TEST_STOP: Create stream, ERR: %d"), err ); |
|
138 PrintTestResult( err ); |
|
139 __UHEAP_MARKEND; |
|
140 |
|
141 err = KErrNone; |
|
142 RDebug::Print( _L("\n\nNAT_TEST_START: Create wrapper") ); |
|
143 iConsole.Printf( _L("Create wrapper test") ); |
|
144 __UHEAP_MARK; |
|
145 TRAP( err, TestCreateWrapperL() ); |
|
146 RDebug::Print( _L("\nNAT_TEST_STOP: Create wrapper, ERR: %d"), err ); |
|
147 PrintTestResult( err ); |
|
148 __UHEAP_MARKEND; |
|
149 |
|
150 err = KErrNone; |
|
151 RDebug::Print( _L("\n\nNAT_TEST_START: Set incoming Address to wrapper") ); |
|
152 iConsole.Printf( _L("Set Incoming Address to wrapper test") ); |
|
153 __UHEAP_MARK; |
|
154 TRAP( err, SetupTestL() ); |
|
155 if ( !err ) |
|
156 { |
|
157 __UHEAP_MARK; |
|
158 TRAP( err, TestSetIncomingAddrL() ); |
|
159 __UHEAP_MARKEND; |
|
160 TeardownTest(); |
|
161 } |
|
162 else |
|
163 { |
|
164 RDebug::Print( _L("\nTEST PRINT: Setup fails, ERR: %d"), err ); |
|
165 } |
|
166 RDebug::Print( _L("\nNAT_TEST_STOP: Set incoming Address to wrapper, ERR: %d"), err ); |
|
167 PrintTestResult( err ); |
|
168 __UHEAP_MARKEND; |
|
169 |
|
170 err = KErrNone; |
|
171 RDebug::Print( _L("\n\nNAT_TEST_START: Outgoing address") ); |
|
172 iConsole.Printf( _L("Get outgoing address from wrapper test") ); |
|
173 __UHEAP_MARK; |
|
174 TRAP( err, SetupTestL() ); |
|
175 if ( !err ) |
|
176 { |
|
177 __UHEAP_MARK; |
|
178 TRAP( err, TestOutgoingAddrL() ); |
|
179 __UHEAP_MARKEND; |
|
180 TeardownTest(); |
|
181 } |
|
182 else |
|
183 { |
|
184 RDebug::Print( _L("\nTEST PRINT: Setup fails, ERR: %d"), err ); |
|
185 } |
|
186 RDebug::Print( _L("\nNAT_TEST_STOP: Outgoing address, ERR: %d"), err ); |
|
187 PrintTestResult( err ); |
|
188 __UHEAP_MARKEND; |
|
189 |
|
190 err = KErrNone; |
|
191 RDebug::Print( _L("\n\nNAT_TEST_START: Fetch candidate") ); |
|
192 iConsole.Printf( _L("Fetch Candidate test") ); |
|
193 __UHEAP_MARK; |
|
194 TRAP( err, TestFetchCandidateL() ); |
|
195 RDebug::Print( _L("\nNAT_TEST_STOP: Fetch candidate, ERR: %d"), err ); |
|
196 PrintTestResult( err ); |
|
197 __UHEAP_MARKEND; |
|
198 |
|
199 err = KErrNone; |
|
200 RDebug::Print( _L("\n\nNAT_TEST_START: Fetch candidate: wrong server address") ); |
|
201 iConsole.Printf( _L("Fetch Candidate wrong server address test") ); |
|
202 __UHEAP_MARK; |
|
203 TRAP( err, SetupWrongServerAddressTestL() ); |
|
204 if ( !err ) |
|
205 { |
|
206 __UHEAP_MARK; |
|
207 TRAP( err, TestFetchCandidateL() ); |
|
208 __UHEAP_MARKEND; |
|
209 } |
|
210 else |
|
211 { |
|
212 RDebug::Print( _L("\nTEST PRINT: Setup fails, ERR: %d"), err ); |
|
213 } |
|
214 TeardownWrongServerAddressTest(); |
|
215 RDebug::Print( _L("\nNAT_TEST_STOP: Fetch candidate wrong server address, ERR: %d"), err ); |
|
216 PrintTestResult( err ); |
|
217 __UHEAP_MARKEND; |
|
218 |
|
219 |
|
220 err = KErrNone; |
|
221 RDebug::Print( _L("\n\nNAT_TEST_START: Set sending status ") ); |
|
222 iConsole.Printf( _L("Set Sending Status test") ); |
|
223 __UHEAP_MARK; |
|
224 TRAP( err, SetupTest2L() ); |
|
225 if ( !err ) |
|
226 { |
|
227 __UHEAP_MARK; |
|
228 if ( KProtocolInetUdp == iProtocol ) |
|
229 { |
|
230 TRAP( err, TestSetSendingStatusUDPL() ); |
|
231 } |
|
232 else |
|
233 { |
|
234 TRAP( err, TestSetSendingStatusTCPL() ); |
|
235 } |
|
236 __UHEAP_MARKEND; |
|
237 } |
|
238 else |
|
239 { |
|
240 RDebug::Print( _L("\nTEST PRINT: Setup fails, ERR: %d"), err ); |
|
241 } |
|
242 TeardownTest(); |
|
243 RDebug::Print( _L("\nNAT_TEST_STOP: Set sending status, ERR: %d"), err ); |
|
244 PrintTestResult( err ); |
|
245 __UHEAP_MARKEND; |
|
246 |
|
247 err = KErrNone; |
|
248 RDebug::Print( _L("\n\nNAT_TEST_START: Set receiving status") ); |
|
249 iConsole.Printf( _L("Set Receiving Status test") ); |
|
250 __UHEAP_MARK; |
|
251 TRAP( err, SetupTest2L() ); |
|
252 if ( !err ) |
|
253 { |
|
254 __UHEAP_MARK; |
|
255 if ( KProtocolInetUdp == iProtocol ) |
|
256 { |
|
257 TRAP( err, TestSetReceivingStatusUDPL() ); |
|
258 } |
|
259 else |
|
260 { |
|
261 TRAP( err, TestSetReceivingStatusTCPL() ); |
|
262 } |
|
263 __UHEAP_MARKEND; |
|
264 TeardownTest(); |
|
265 } |
|
266 else |
|
267 { |
|
268 RDebug::Print( _L("\nTEST PRINT: Setup fails, ERR: %d"), err ); |
|
269 } |
|
270 |
|
271 RDebug::Print( _L("\nNAT_TEST_STOP: Set receiving status, ERR: %d"), err ); |
|
272 PrintTestResult( err ); |
|
273 __UHEAP_MARKEND; |
|
274 } |
|
275 |
|
276 |
|
277 // --------------------------------------------------------------------------- |
|
278 // CStunTurnTests::SetupTestL |
|
279 // Create session, stream and wrapper |
|
280 // --------------------------------------------------------------------------- |
|
281 // |
|
282 void CStunTurnTests::SetupTestL() |
|
283 { |
|
284 RDebug::Print( _L( "\nTEST PRINT: CStunTurnTests::SetupTest - Start" ) ); |
|
285 |
|
286 TInt loadedPluginInd; |
|
287 |
|
288 iSessionId = 0; |
|
289 iStreamId = 0; |
|
290 |
|
291 iSessionId = iNat.CreateSessionL( iTestIapId, iTestDomain->Des() ); |
|
292 iIfStub.StartActiveSchedulerL(); |
|
293 |
|
294 iNat.LoadPluginL( iSessionId, *iPlugins, loadedPluginInd ); |
|
295 iIfStub.StartActiveSchedulerL( KPluginLoadTime ); |
|
296 |
|
297 iStreamId = iNat.CreateStreamL( iSessionId, iProtocol, KDefaultQos ); |
|
298 |
|
299 iWrapper = &iNat.CreateWrapperL( iSessionId, iStreamId ); |
|
300 |
|
301 RDebug::Print( _L( "\nTEST PRINT: CStunTurnTests::SetupTest - End" ) ); |
|
302 } |
|
303 |
|
304 |
|
305 // --------------------------------------------------------------------------- |
|
306 // CStunTurnTests::SetupTest2L |
|
307 // FetchCandidate |
|
308 // --------------------------------------------------------------------------- |
|
309 // |
|
310 void CStunTurnTests::SetupTest2L() |
|
311 { |
|
312 RDebug::Print( _L( "\nTEST PRINT: CStunTurnTests::SetupTest2 - Start" ) ); |
|
313 TInt error; |
|
314 SetupTestL(); |
|
315 |
|
316 iNat.FetchCandidateL( iSessionId, iStreamId, KAfInet ); |
|
317 error = iIfStub.StartActiveSchedulerL( KRunningTime ); |
|
318 |
|
319 __ASSERT_ALWAYS( !error, User::Leave( error ) ); |
|
320 |
|
321 RDebug::Print( _L( "\nTEST PRINT: CStunTurnTests::SetupTest2 - End" ) ); |
|
322 } |
|
323 |
|
324 |
|
325 // --------------------------------------------------------------------------- |
|
326 // CStunTurnTests::SetupWrongServerAddressTestL |
|
327 // Create session, stream and wrapper |
|
328 // --------------------------------------------------------------------------- |
|
329 // |
|
330 void CStunTurnTests::SetupWrongServerAddressTestL() |
|
331 { |
|
332 iIfStub.SetFailureTest( ETrue ); |
|
333 iWrongServerSettings = CWrongServerSettings::NewL( *iTestDomain ); |
|
334 } |
|
335 |
|
336 |
|
337 // --------------------------------------------------------------------------- |
|
338 // CStunTurnTests::TeardownWrongServerAddressTest |
|
339 // Create session, stream and wrapper |
|
340 // --------------------------------------------------------------------------- |
|
341 // |
|
342 void CStunTurnTests::TeardownWrongServerAddressTest() |
|
343 { |
|
344 delete iWrongServerSettings; |
|
345 iWrongServerSettings = 0; |
|
346 iIfStub.SetFailureTest( EFalse ); |
|
347 } |
|
348 |
|
349 |
|
350 // --------------------------------------------------------------------------- |
|
351 // CStunTurnTests::TeardownTest |
|
352 // Close Session and Stream |
|
353 // --------------------------------------------------------------------------- |
|
354 // |
|
355 void CStunTurnTests::TeardownTest() |
|
356 { |
|
357 RDebug::Print( _L( "\nTEST CASE: CStunTurnTests::TeardownTest" ) ); |
|
358 |
|
359 iNat.CloseStreamL( iSessionId, iStreamId ); |
|
360 iNat.CloseSessionL( iSessionId ); |
|
361 } |
|
362 |
|
363 |
|
364 // --------------------------------------------------------------------------- |
|
365 // CStunTurnTests::TestCreateSessionL |
|
366 // --------------------------------------------------------------------------- |
|
367 // |
|
368 void CStunTurnTests::TestCreateSessionL() |
|
369 { |
|
370 TUint sessionId( 0 ); |
|
371 TUint sessionId2( 0 ); |
|
372 |
|
373 RDebug::Print( |
|
374 _L( "\nTEST CASE: Create session with invalid IapID: 18" ) ); |
|
375 // Creation fails |
|
376 iIfStub.SetFailureTest( ETrue ); |
|
377 |
|
378 sessionId = iNat.CreateSessionL( 18, iTestDomain->Des() ); |
|
379 |
|
380 iIfStub.StartActiveSchedulerL(); |
|
381 |
|
382 iIfStub.SetFailureTest( EFalse ); |
|
383 |
|
384 iNat.CloseSessionL( sessionId ); |
|
385 |
|
386 RDebug::Print( _L( "\nTEST CASE: Create session 1 with IapID: %d" ), |
|
387 iTestIapId ); |
|
388 |
|
389 __UHEAP_MARK; |
|
390 |
|
391 sessionId = iNat.CreateSessionL( iTestIapId, iTestDomain->Des() ); |
|
392 |
|
393 iIfStub.StartActiveSchedulerL(); |
|
394 |
|
395 RDebug::Print( _L( "\nTEST CASE: Create session 2 with IapID: %d" ), |
|
396 iTestIapId ); |
|
397 sessionId2 = iNat.CreateSessionL( iTestIapId, iTestDomain->Des() ); |
|
398 |
|
399 iIfStub.StartActiveSchedulerL(); |
|
400 |
|
401 RDebug::Print( _L( "TEST PRINT: CStunTurnTests::TestCreateSessionL,\ |
|
402 close session 1" ) ); |
|
403 iNat.CloseSessionL( sessionId ); |
|
404 |
|
405 RDebug::Print( _L( "TEST PRINT: CStunTurnTests::TestCreateSessionL, \ |
|
406 close session 2" ) ); |
|
407 iNat.CloseSessionL( sessionId2 ); |
|
408 |
|
409 __UHEAP_MARKEND; |
|
410 |
|
411 RDebug::Print( |
|
412 _L( "\nTEST CASE: Create session without waiting call back" ) ); |
|
413 |
|
414 __UHEAP_MARK; |
|
415 |
|
416 sessionId = iNat.CreateSessionL( iTestIapId, iTestDomain->Des() ); |
|
417 |
|
418 RDebug::Print( _L( "TEST PRINT: CStunTurnTests::TestCreateSessionL, \ |
|
419 close session" ) ); |
|
420 iNat.CloseSessionL( sessionId ); |
|
421 |
|
422 __UHEAP_MARKEND; |
|
423 } |
|
424 |
|
425 |
|
426 // --------------------------------------------------------------------------- |
|
427 // CStunTurnTests::TestCreateStreamL |
|
428 // --------------------------------------------------------------------------- |
|
429 // |
|
430 void CStunTurnTests::TestCreateStreamL() |
|
431 { |
|
432 TUint sessionId( 0 ); |
|
433 TUint sessionId2( 0 ); |
|
434 TUint streamId( 0 ); |
|
435 TUint streamId2( 0 ); |
|
436 |
|
437 sessionId = iNat.CreateSessionL( iTestIapId, iTestDomain->Des() ); |
|
438 |
|
439 iIfStub.StartActiveSchedulerL(); |
|
440 |
|
441 RDebug::Print( _L( "\nTEST CASE: Create stream 1 in the session 1" ) ); |
|
442 streamId = iNat.CreateStreamL( sessionId, iProtocol, KDefaultQos ); |
|
443 |
|
444 RDebug::Print( _L( "\nTEST CASE: Create stream 2 in the session 1" ) ); |
|
445 streamId2 = iNat.CreateStreamL( sessionId, iProtocol, KDefaultQos ); |
|
446 |
|
447 RDebug::Print( _L( "TEST PRINT: CStunTurnTests::TestCreateStreamL, close stream 1" ) ); |
|
448 iNat.CloseStreamL( sessionId, streamId ); |
|
449 |
|
450 sessionId2 = iNat.CreateSessionL( iTestIapId, iTestDomain->Des() ); |
|
451 |
|
452 iIfStub.StartActiveSchedulerL(); |
|
453 |
|
454 RDebug::Print( _L( "\nTEST CASE: Create stream 3 in the session 2" ) ); |
|
455 streamId = iNat.CreateStreamL( sessionId2, iProtocol, KDefaultQos ); |
|
456 |
|
457 RDebug::Print( _L( "TEST PRINT: CStunTurnTests::TestCreateSessionL, close stream 3" ) ); |
|
458 iNat.CloseStreamL( sessionId2, streamId ); |
|
459 |
|
460 RDebug::Print( _L( "TEST PRINT: CStunTurnTests::TestCreateSessionL, close stream 2" ) ); |
|
461 iNat.CloseStreamL( sessionId, streamId2 ); |
|
462 |
|
463 RDebug::Print( _L( "TEST PRINT: CStunTurnTests::TestCreateSessionL, close session 1" ) ); |
|
464 iNat.CloseSessionL( sessionId ); |
|
465 |
|
466 RDebug::Print( _L( "TEST PRINT: CStunTurnTests::TestCreateSessionL, close session 2" ) ); |
|
467 iNat.CloseSessionL( sessionId2 ); |
|
468 } |
|
469 |
|
470 |
|
471 // --------------------------------------------------------------------------- |
|
472 // CStunTurnTests::TestCreateWrapperL |
|
473 // --------------------------------------------------------------------------- |
|
474 // |
|
475 void CStunTurnTests::TestCreateWrapperL() |
|
476 { |
|
477 TUint sessionId( 0 ); |
|
478 TUint streamId( 0 ); |
|
479 |
|
480 MNATFWSocketMediaConnWrapper* wrapperIF; |
|
481 |
|
482 RDebug::Print( _L( "TEST PRINT: Create session and stream" ) ); |
|
483 sessionId = iNat.CreateSessionL( iTestIapId, iTestDomain->Des() ); |
|
484 |
|
485 iIfStub.StartActiveSchedulerL(); |
|
486 |
|
487 streamId = iNat.CreateStreamL( sessionId, iProtocol, KDefaultQos ); |
|
488 |
|
489 RDebug::Print( _L( "\nTEST CASE: Create wrapper" ) ); |
|
490 wrapperIF = &iNat.CreateWrapperL( sessionId, streamId ); |
|
491 |
|
492 if ( wrapperIF->StreamId() != streamId ) |
|
493 { |
|
494 RDebug::Print( _L( "TEST PRINT: CStunTurnTests::TestCreateWrapperL, streamId is not equal" ) ); |
|
495 User::Leave( KErrCompletion ); |
|
496 } |
|
497 RDebug::Print( _L( "TEST PRINT: Close stream and session" ) ); |
|
498 iNat.CloseStreamL( sessionId, streamId ); |
|
499 iNat.CloseSessionL( sessionId ); |
|
500 } |
|
501 |
|
502 |
|
503 // --------------------------------------------------------------------------- |
|
504 // CStunTurnTests::TestSetIncomingAddrL |
|
505 // --------------------------------------------------------------------------- |
|
506 // |
|
507 void CStunTurnTests::TestSetIncomingAddrL() |
|
508 { |
|
509 RDebug::Print( _L( "\nTEST CASE: Set Incoming Address" ) ); |
|
510 |
|
511 if ( KProtocolInetTcp == iProtocol ) |
|
512 { |
|
513 RDebug::Print( _L( "\nTEST CASE: Set Incoming Address - TCP" ) ); |
|
514 iNotificationIsOn = EFalse; |
|
515 CTestServer* server = CTestServer::NewLC( this ); |
|
516 CTestClient* client = CTestClient::NewLC( this ); |
|
517 |
|
518 TInetAddr addr( KInetAddrLoop, KTestServerPort ); |
|
519 server->OpenL( addr, KTimeoutTime ); |
|
520 |
|
521 iWrapper->SetIncomingAddrL( addr ); |
|
522 //iWrapper->SetupTcpConnectionL( ETcpSetupActive, *this ); |
|
523 |
|
524 iIfStub.StartActiveSchedulerL( KRunningTime ); |
|
525 |
|
526 iNotificationIsOn = ETrue; |
|
527 CleanupStack::PopAndDestroy( client ); |
|
528 CleanupStack::PopAndDestroy( server ); |
|
529 } |
|
530 else |
|
531 { |
|
532 RDebug::Print( _L( "\nTEST CASE: Set Incoming Address - UDP" ) ); |
|
533 iWrapper->SetIncomingAddrL( TInetAddr( KIncomingAddr, KIncomingPort ) ); |
|
534 } |
|
535 } |
|
536 |
|
537 |
|
538 // --------------------------------------------------------------------------- |
|
539 // CStunTurnTests::TestOutgoingAddrL |
|
540 // --------------------------------------------------------------------------- |
|
541 // |
|
542 void CStunTurnTests::TestOutgoingAddrL() |
|
543 { |
|
544 TInetAddr inetAddr; |
|
545 TBuf<40> buffer; |
|
546 |
|
547 RDebug::Print( _L( "\nTEST CASE: Get outgoing address" ) ); |
|
548 iWrapper->OutgoingAddr( inetAddr ); |
|
549 |
|
550 inetAddr.Output( buffer ); |
|
551 |
|
552 RDebug::Print( _L("TEST PRINT: CStunTurnTests::TestOutgoingAddrL, wrapper outgoing Address: %S:%d "), &buffer, inetAddr.Port() ); |
|
553 if ( buffer.Length() == 0 ) |
|
554 { |
|
555 User::Leave( KErrCompletion ); |
|
556 } |
|
557 } |
|
558 |
|
559 |
|
560 // --------------------------------------------------------------------------- |
|
561 // CStunTurnTests::TestFetchCandidateL |
|
562 // --------------------------------------------------------------------------- |
|
563 // |
|
564 void CStunTurnTests::TestFetchCandidateL() |
|
565 { |
|
566 TUint sessionId( 0 ); |
|
567 TUint sessionId2( 0 ); |
|
568 |
|
569 TUint streamId( 0 ); |
|
570 TUint streamId2( 0 ); |
|
571 TUint streamId3( 0 ); |
|
572 |
|
573 TInt error; |
|
574 TInt loadedPluginInd( 0 ); |
|
575 |
|
576 RDebug::Print( _L( "TEST PRINT: Create session" ) ); |
|
577 sessionId = iNat.CreateSessionL( iTestIapId, iTestDomain->Des() ); |
|
578 |
|
579 iIfStub.StartActiveSchedulerL(); |
|
580 |
|
581 RDebug::Print( _L( "TEST PRINT: Create stream" ) ); |
|
582 streamId = iNat.CreateStreamL( sessionId, iProtocol, KDefaultQos ); |
|
583 |
|
584 RDebug::Print( _L( "TEST PRINT: Load plugin" ) ); |
|
585 iNat.LoadPluginL( sessionId, *iPlugins, loadedPluginInd ); |
|
586 iIfStub.StartActiveSchedulerL( KPluginLoadTime ); |
|
587 |
|
588 RDebug::Print( _L( "\nTEST CASE: Fetch Candidate to the stream" ) ); |
|
589 TRAPD( err, iNat.FetchCandidateL( sessionId, streamId, KAfInet ) ); |
|
590 if ( err ) |
|
591 { |
|
592 RDebug::Print( _L( "\nTEST PRINT: CNATFWClient::FetchCandidateL LEAVE %d" ), err ); |
|
593 iNat.CloseStreamL( sessionId, streamId ); |
|
594 iNat.CloseSessionL( sessionId ); |
|
595 User::Leave( err ); |
|
596 } |
|
597 |
|
598 error = iIfStub.StartActiveSchedulerL( /*KRunningTime*/ ); |
|
599 |
|
600 RDebug::Print( _L( "TEST PRINT: Close the stream and the session" ) ); |
|
601 iNat.CloseStreamL( sessionId, streamId ); |
|
602 iNat.CloseSessionL( sessionId ); |
|
603 |
|
604 __ASSERT_ALWAYS( !error, User::Leave( error )); |
|
605 |
|
606 RDebug::Print( _L( "TEST PRINT: Create session 1" ) ); |
|
607 sessionId = iNat.CreateSessionL( iTestIapId, iTestDomain->Des() ); |
|
608 |
|
609 iIfStub.StartActiveSchedulerL(); |
|
610 |
|
611 RDebug::Print( _L( "TEST PRINT: Load plugin to session 1" ) ); |
|
612 iNat.LoadPluginL( sessionId, *iPlugins, loadedPluginInd ); |
|
613 iIfStub.StartActiveSchedulerL( KPluginLoadTime ); |
|
614 |
|
615 RDebug::Print( _L( "TEST PRINT: Create stream 1 to the session 1" ) ); |
|
616 streamId = iNat.CreateStreamL( sessionId, iProtocol, KDefaultQos ); |
|
617 |
|
618 RDebug::Print( _L( "\nTEST CASE: Fetch Candidate to the stream 1 in the session 1" ) ); |
|
619 TRAP( err, iNat.FetchCandidateL( sessionId, streamId, KAfInet ) ); |
|
620 if( err ) |
|
621 { |
|
622 RDebug::Print( _L( "\nTEST PRINT: CNATFWClient::FetchCandidateL LEAVE %d" ), err ); |
|
623 iNat.CloseStreamL( sessionId, streamId ); |
|
624 iNat.CloseSessionL( sessionId ); |
|
625 User::Leave( err ); |
|
626 } |
|
627 |
|
628 iIfStub.StartActiveSchedulerL(); |
|
629 |
|
630 RDebug::Print( _L( "TEST PRINT: Create stream 2 to the session 1" ) ); |
|
631 streamId2 = iNat.CreateStreamL( sessionId, iProtocol, KDefaultQos ); |
|
632 |
|
633 RDebug::Print( _L( "\nTEST CASE: Fetch Candidate to the stream 2 in the session 1" ) ); |
|
634 |
|
635 TRAP( err, iNat.FetchCandidateL( sessionId, streamId2, KAfInet ) ); |
|
636 if( err ) |
|
637 { |
|
638 RDebug::Print( _L( "\nTEST PRINT: CNATFWClient::FetchCandidateL LEAVE %d" ), err ); |
|
639 iNat.CloseStreamL( sessionId, streamId ); |
|
640 iNat.CloseStreamL( sessionId, streamId2 ); |
|
641 iNat.CloseSessionL( sessionId ); |
|
642 User::Leave( err ); |
|
643 } |
|
644 |
|
645 error = iIfStub.StartActiveSchedulerL( KRunningTime ); |
|
646 |
|
647 if( !error ) |
|
648 { |
|
649 RDebug::Print( _L( "TEST PRINT: Create session 2" ) ); |
|
650 sessionId2 = iNat.CreateSessionL( iTestIapId, iTestDomain->Des() ); |
|
651 |
|
652 iIfStub.StartActiveSchedulerL(); |
|
653 |
|
654 RDebug::Print( _L( "TEST PRINT: Load plugin to session 2" ) ); |
|
655 iNat.LoadPluginL( sessionId2, *iPlugins, loadedPluginInd ); |
|
656 iIfStub.StartActiveSchedulerL( KPluginLoadTime ); |
|
657 |
|
658 RDebug::Print( _L( "TEST PRINT: Create stream 3 to the session 2" ) ); |
|
659 streamId3 = iNat.CreateStreamL( sessionId2, iProtocol, KDefaultQos ); |
|
660 |
|
661 RDebug::Print( _L( "\nTEST CASE: Fetch Candidate to the stream 3 in the session 2" ) ); |
|
662 |
|
663 TRAP( err, iNat.FetchCandidateL( sessionId2, streamId3, KAfInet ) ); |
|
664 if( err ) |
|
665 { |
|
666 RDebug::Print( _L( "\nTEST PRINT: CNATFWClient::FetchCandidateL LEAVE %d" ), err ); |
|
667 iNat.CloseStreamL( sessionId2, streamId3 ); |
|
668 iNat.CloseSessionL( sessionId2 ); |
|
669 iNat.CloseStreamL( sessionId, streamId ); |
|
670 iNat.CloseStreamL( sessionId, streamId2 ); |
|
671 iNat.CloseSessionL( sessionId ); |
|
672 User::Leave( err ); |
|
673 } |
|
674 |
|
675 iIfStub.StartActiveSchedulerL( KRunningTime ); |
|
676 |
|
677 RDebug::Print( _L( "TEST PRINT: Close stream 3 and session 2" ) ); |
|
678 iNat.CloseStreamL( sessionId2, streamId3 ); |
|
679 iNat.CloseSessionL( sessionId2 ); |
|
680 } |
|
681 |
|
682 RDebug::Print( _L( "TEST PRINT: Close streams 1 & 2 and session 1" ) ); |
|
683 iNat.CloseStreamL( sessionId, streamId ); |
|
684 iNat.CloseStreamL( sessionId, streamId2 ); |
|
685 |
|
686 iNat.CloseSessionL( sessionId ); |
|
687 |
|
688 __ASSERT_ALWAYS( !error, User::Leave( error )); |
|
689 } |
|
690 |
|
691 |
|
692 // --------------------------------------------------------------------------- |
|
693 // CStunTurnTests::TestSetSendingStatusUDPL |
|
694 // --------------------------------------------------------------------------- |
|
695 // |
|
696 void CStunTurnTests::TestSetSendingStatusUDPL() |
|
697 { |
|
698 TInetAddr inetAddr; |
|
699 |
|
700 iWrapper->OutgoingAddr( inetAddr ); |
|
701 iWrapper->SetIncomingAddrL( inetAddr ); |
|
702 |
|
703 TInetAddr destination( KTestAddress, KTestServerPort ); |
|
704 |
|
705 RDebug::Print( _L( "\nTEST CASE: Set Sending Status Active" ) ); |
|
706 |
|
707 iNat.SetSendingStateL( iIfStub.LocalCandidateL(), EStreamingStateActive, |
|
708 destination ); |
|
709 |
|
710 iIfStub.StartActiveSchedulerL( KRunningTime ); |
|
711 |
|
712 RDebug::Print( _L( "\nTEST CASE: Set Sending Status Passive" ) ); |
|
713 |
|
714 iNat.SetSendingStateL( iIfStub.LocalCandidateL(), EStreamingStatePassive, |
|
715 destination ); |
|
716 |
|
717 iIfStub.StartActiveSchedulerL( KRunningTime ); |
|
718 } |
|
719 |
|
720 // --------------------------------------------------------------------------- |
|
721 // CStunTurnTests::TestSetSendingStatusTCPL |
|
722 // --------------------------------------------------------------------------- |
|
723 // |
|
724 void CStunTurnTests::TestSetSendingStatusTCPL() |
|
725 { |
|
726 TInetAddr inetAddr; |
|
727 TBuf<40> buffer; |
|
728 |
|
729 CTestClient* client = CTestClient::NewLC( this ); |
|
730 |
|
731 // testserver to wrapper |
|
732 CTestServer* server = CTestServer::NewLC( this ); |
|
733 |
|
734 TInetAddr addr( KInetAddrAny, KTestServerPort ); |
|
735 |
|
736 // stop scheduler when server timer runs out |
|
737 server->OpenL( addr, KTimeoutTime ); |
|
738 |
|
739 iNotificationIsOn = EFalse; |
|
740 |
|
741 TInetAddr testServerAddr; |
|
742 client->ResolveLocalAddrL( testServerAddr, iTestIapId ); |
|
743 testServerAddr.SetPort( KTestServerPort ); |
|
744 |
|
745 iWrapper->SetIncomingAddrL( testServerAddr ); |
|
746 |
|
747 iIfStub.StartActiveSchedulerL( KRunningTime ); |
|
748 |
|
749 iNotificationIsOn = ETrue; |
|
750 |
|
751 // testserver to natfw |
|
752 CTestServer* server2 = CTestServer::NewLC( this ); |
|
753 |
|
754 TInetAddr addr2( KInetAddrAny, KTestServer2Port ); |
|
755 |
|
756 server2->OpenL( addr2, KTimeoutTime ); |
|
757 |
|
758 TInetAddr destination; |
|
759 client->ResolveLocalAddrL( destination, iTestIapId ); |
|
760 destination.SetPort( KTestServer2Port ); |
|
761 destination.Output( buffer ); |
|
762 |
|
763 RDebug::Print( _L( "CStunTurnTests::TestSetSendingStatusTCPL; ADDR: %S PORT: %d" ), |
|
764 &buffer, destination.Port() ); |
|
765 |
|
766 // set sending status active |
|
767 RDebug::Print( _L( "\nTEST CASE: Set Sending Status Active" ) ); |
|
768 |
|
769 iNat.SetSendingStateL( iIfStub.LocalCandidateL(), EStreamingStateActive, |
|
770 destination ); |
|
771 |
|
772 iIfStub.StartActiveSchedulerL( KRunningTime ); |
|
773 |
|
774 server2->Cancel(); |
|
775 |
|
776 // set sending status passive |
|
777 RDebug::Print( _L( "\nTEST CASE: Set Sending Status Passive" ) ); |
|
778 |
|
779 iNat.SetSendingStateL( iIfStub.LocalCandidateL(), EStreamingStatePassive, |
|
780 destination ); |
|
781 |
|
782 iIfStub.StartActiveSchedulerL( KRunningTime ); |
|
783 |
|
784 CleanupStack::PopAndDestroy( server2 ); |
|
785 CleanupStack::PopAndDestroy( server ); |
|
786 CleanupStack::PopAndDestroy( client ); |
|
787 } |
|
788 |
|
789 // --------------------------------------------------------------------------- |
|
790 // CStunTurnTests::TestSetReceivingStatusUDPL |
|
791 // --------------------------------------------------------------------------- |
|
792 // |
|
793 void CStunTurnTests::TestSetReceivingStatusUDPL() |
|
794 { |
|
795 TInetAddr addr( KTestAddress, KTestServerPort ); |
|
796 |
|
797 iWrapper->SetIncomingAddrL( addr ); |
|
798 |
|
799 RDebug::Print( _L( "\nTEST CASE: Set Receiving Status Active" ) ); |
|
800 |
|
801 iNat.SetReceivingStateL( iIfStub.LocalCandidateL(), |
|
802 EStreamingStateActive ); |
|
803 |
|
804 iIfStub.StartActiveSchedulerL( KRunningTime ); |
|
805 |
|
806 RDebug::Print( _L( "\nTEST CASE: Set Receiving Status Passive" ) ); |
|
807 |
|
808 iNat.SetReceivingStateL( iIfStub.LocalCandidateL(), |
|
809 EStreamingStatePassive ); |
|
810 |
|
811 iIfStub.StartActiveSchedulerL( KRunningTime ); |
|
812 } |
|
813 |
|
814 |
|
815 // --------------------------------------------------------------------------- |
|
816 // CStunTurnTests::TestSetReceivingStatusTCPL |
|
817 // --------------------------------------------------------------------------- |
|
818 // |
|
819 void CStunTurnTests::TestSetReceivingStatusTCPL() |
|
820 { |
|
821 // Connect wrapper to test server |
|
822 CTestServer* server = CTestServer::NewLC( this ); |
|
823 |
|
824 TInetAddr addr( KInetAddrAny, KTestServerPort ); |
|
825 |
|
826 // stop scheduler when clients timer runs out |
|
827 server->OpenL( addr, KTimeoutTime ); |
|
828 |
|
829 iNotificationIsOn = EFalse; |
|
830 |
|
831 CTestClient* client = CTestClient::NewLC( this ); |
|
832 |
|
833 TInetAddr testServerAddr; |
|
834 client->ResolveLocalAddrL( testServerAddr, iTestIapId ); |
|
835 testServerAddr.SetPort( KTestServerPort ); |
|
836 |
|
837 iWrapper->SetIncomingAddrL( testServerAddr ); |
|
838 |
|
839 iIfStub.StartActiveSchedulerL( KRunningTime ); |
|
840 |
|
841 iNotificationIsOn = ETrue; |
|
842 |
|
843 |
|
844 // Set receiving status active |
|
845 RDebug::Print( _L( "\nTEST CASE: Set Receiving Status Active" ) ); |
|
846 |
|
847 iNat.SetReceivingStateL( iIfStub.LocalCandidateL(), |
|
848 EStreamingStateActive ); |
|
849 |
|
850 // connect test client to natfw |
|
851 TInetAddr incomingAddr; |
|
852 |
|
853 client->ResolveLocalAddrL( incomingAddr, iTestIapId ); |
|
854 incomingAddr.SetPort( 5000 ); |
|
855 |
|
856 TBuf<40> buffer; |
|
857 incomingAddr.Output( buffer ); |
|
858 RDebug::Print( |
|
859 _L( "CStunTurnTests::TestSetReceivingStatusTCPL; ADDR: %S PORT: %d" ), |
|
860 &buffer ,incomingAddr.Port() ); |
|
861 |
|
862 client->OpenL( iTestIapId ); |
|
863 |
|
864 iIfStub.StartActiveSchedulerL(); |
|
865 |
|
866 // stop scheduler when clients timer runs out |
|
867 client->ConnectL( incomingAddr, KTimeoutTime ); |
|
868 |
|
869 iNotificationIsOn = EFalse; |
|
870 |
|
871 iIfStub.StartActiveSchedulerL( KRunningTime ); |
|
872 |
|
873 iNotificationIsOn = ETrue; |
|
874 |
|
875 // Set receiving status passive |
|
876 RDebug::Print( _L( "\nTEST CASE: Set Receiving Status Passive" ) ); |
|
877 |
|
878 iNat.SetReceivingStateL( iIfStub.LocalCandidateL(), |
|
879 EStreamingStatePassive ); |
|
880 |
|
881 iIfStub.StartActiveSchedulerL( KRunningTime ); |
|
882 |
|
883 CleanupStack::PopAndDestroy( client ); |
|
884 CleanupStack::PopAndDestroy( server ); |
|
885 } |
|
886 |
|
887 |
|
888 // --------------------------------------------------------------------------- |
|
889 // CStunTurnTests::PrintResult |
|
890 // --------------------------------------------------------------------------- |
|
891 // |
|
892 void CStunTurnTests::PrintTestResult( TInt aError ) |
|
893 { |
|
894 if ( KErrNone == aError ) |
|
895 { |
|
896 iConsole.Printf( _L("...Ready \n") ); |
|
897 } |
|
898 else |
|
899 { |
|
900 iConsole.Printf( _L("...Error: %d\n"), aError ); |
|
901 } |
|
902 } |
|
903 |
|
904 // --------------------------------------------------------------------------- |
|
905 // CStunTurnTests::Notify |
|
906 // from MTestServerObserver |
|
907 // --------------------------------------------------------------------------- |
|
908 // |
|
909 void CStunTurnTests::Notify( MTestServerObserver::TServerNotify aNotify, TInt aError ) |
|
910 { |
|
911 RDebug::Print( _L( "TEST PRINT: CStunTurnTests::Notify, server Notify: %d, Error: %d\n" ), |
|
912 aNotify ,aError ); |
|
913 if ( KErrNone != aError || aNotify == EShutdownTimer ) |
|
914 { |
|
915 if ( iNotificationIsOn ) |
|
916 { |
|
917 iConsole.Printf( _L( "\nServer Notify: %d, Error: %d\n" ),aNotify ,aError ); |
|
918 } |
|
919 iIfStub.StopActiveScheduler(); |
|
920 } |
|
921 } |
|
922 |
|
923 |
|
924 // --------------------------------------------------------------------------- |
|
925 // CStunTurnTests::Notify |
|
926 // from MTestClientNotifier |
|
927 // --------------------------------------------------------------------------- |
|
928 // |
|
929 void CStunTurnTests::Notify( MTestClientNotifier::TClientNotify aNotify, TInt aError ) |
|
930 { |
|
931 RDebug::Print( _L( "TEST PRINT: CStunTurnTests::Notify, client Notify: %d, Error: %d\n" ), |
|
932 aNotify ,aError ); |
|
933 if ( KErrNone != aError || aNotify == MTestClientNotifier::ETimerOccured ) |
|
934 { |
|
935 if ( iNotificationIsOn ) |
|
936 { |
|
937 iConsole.Printf( _L( "\nClient Notify: %d, Error: %d\n" ),aNotify ,aError ); |
|
938 } |
|
939 iIfStub.StopActiveScheduler(); |
|
940 } |
|
941 else if ( MTestClientNotifier::EOpened == aNotify ) |
|
942 { |
|
943 iIfStub.StopActiveScheduler(); |
|
944 } |
|
945 else |
|
946 { |
|
947 } |
|
948 } |
|
949 |