|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // CLASS HEADER |
|
22 #include "ut_cstunclient.h" |
|
23 |
|
24 // EXTERNAL INCLUDES |
|
25 #include <digia/eunit/eunitmacros.h> |
|
26 #include <commdbconnpref.h> |
|
27 #include <e32debug.h> |
|
28 |
|
29 // INTERNAL INCLUDES |
|
30 #include "natfwstunclient.h" |
|
31 #include "natfwunsafbindingrequest.h" |
|
32 #include "natfwunittestmacros.h" |
|
33 #include "ut_cstunbinding.h" |
|
34 |
|
35 _LIT8( KServerAddress, "10.32.194.251" ); |
|
36 _LIT8( KUsername, "userAA" ); |
|
37 _LIT8( KPassword,"salasana"); |
|
38 _LIT8( KRealm, "example.realm.com" ); |
|
39 |
|
40 _LIT8(KRealmVal,"\"myrealm\""); |
|
41 |
|
42 const TDesC8& dataDesc4(KRealmVal); |
|
43 |
|
44 // CONSTRUCTION |
|
45 ut_cstunclient* ut_cstunclient::NewL() |
|
46 { |
|
47 ut_cstunclient* self = ut_cstunclient::NewLC(); |
|
48 CleanupStack::Pop(); |
|
49 |
|
50 return self; |
|
51 } |
|
52 |
|
53 ut_cstunclient* ut_cstunclient::NewLC() |
|
54 { |
|
55 ut_cstunclient* self = new( ELeave ) ut_cstunclient(); |
|
56 CleanupStack::PushL( self ); |
|
57 |
|
58 self->ConstructL(); |
|
59 |
|
60 return self; |
|
61 } |
|
62 |
|
63 // Destructor (virtual by CBase) |
|
64 ut_cstunclient::~ut_cstunclient() |
|
65 { |
|
66 } |
|
67 |
|
68 // Default constructor |
|
69 ut_cstunclient::ut_cstunclient() |
|
70 { |
|
71 } |
|
72 |
|
73 // Second phase construct |
|
74 void ut_cstunclient::ConstructL() |
|
75 { |
|
76 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
77 // It generates the test case table. |
|
78 CEUnitTestSuiteClass::ConstructL(); |
|
79 } |
|
80 |
|
81 // METHODS |
|
82 // from mstunclientbserver |
|
83 void ut_cstunclient::STUNClientInitCompleted( const CSTUNClient& /*aClient*/, |
|
84 TInt aCompletionCode ) |
|
85 { |
|
86 iCallbackCalled = ETrue; |
|
87 RDebug::Print( _L("**NATFW STUNClientInitCompleted, code: %d"), aCompletionCode ); |
|
88 if ( ut_cstunbinding::iActiveSchedulerWait.IsStarted() ) |
|
89 { |
|
90 ut_cstunbinding::iActiveSchedulerWait.AsyncStop(); |
|
91 } |
|
92 } |
|
93 |
|
94 |
|
95 void ut_cstunclient::STUNBindingEventOccurredL( TSTUNBindingEvent aEvent, |
|
96 const CBinding& /*aBinding*/ ) |
|
97 { |
|
98 iCallbackCalled = ETrue; |
|
99 RDebug::Print( _L("**NATFW STUNBindingEventOccurredL, code: %d"), aEvent ); |
|
100 if ( ut_cstunbinding::iActiveSchedulerWait.IsStarted() ) |
|
101 { |
|
102 ut_cstunbinding::iActiveSchedulerWait.AsyncStop(); |
|
103 } |
|
104 } |
|
105 |
|
106 |
|
107 void ut_cstunclient::STUNBindingErrorOccurred( const CBinding& /*aBinding*/, |
|
108 TInt aError ) |
|
109 { |
|
110 iCallbackCalled = ETrue; |
|
111 RDebug::Print( _L("**NATFW STUNBindingErrorOccurred, code: %d"), aError ); |
|
112 if ( ut_cstunbinding::iActiveSchedulerWait.IsStarted() ) |
|
113 { |
|
114 ut_cstunbinding::iActiveSchedulerWait.AsyncStop(); |
|
115 } |
|
116 } |
|
117 |
|
118 void ut_cstunclient::Notify( TUint /*aSessionId*/, TUint /*aStreamId*/, |
|
119 TNotifyType /*aType*/, TInt /*aError*/ ) |
|
120 { |
|
121 RDebug::Print( _L("**NATFW Notify") ); |
|
122 } |
|
123 |
|
124 void ut_cstunclient::IcmpError( TUint /*aSessionId*/, TUint /*aStreamId*/, const TInetAddr& /*aAddress*/ ) |
|
125 { |
|
126 RDebug::Print( _L("**NATFW IcmpError") ); |
|
127 } |
|
128 |
|
129 |
|
130 void ut_cstunclient::SetupL( ) |
|
131 { |
|
132 iCallbackCalled = EFalse; |
|
133 TUint iapID( 6 ); |
|
134 TInt retransmitInterval( 10 ); |
|
135 TBufC8<13> serveraddress( KServerAddress ); |
|
136 TUint serverport( 2000 ); |
|
137 TBufC8<4> protocol( KStun ); |
|
138 TBool obtainsharedsecret( EFalse ); |
|
139 TBool failifnoSRVrecordfound( EFalse ); |
|
140 iDeltatimer = CDeltaTimer::NewL( 1 ); |
|
141 User::LeaveIfError( iSocketServ.Connect() ); |
|
142 iStreamId = 1; |
|
143 iSubstreamId = 1; |
|
144 TBool icmpUsed( EFalse ); |
|
145 |
|
146 iMux = CNcmConnectionMultiplexer::NewL( *this ); |
|
147 |
|
148 TCommDbConnPref pref; |
|
149 pref.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); |
|
150 pref.SetIapId( iapID ); |
|
151 |
|
152 User::LeaveIfError( iConnection.Open( iSocketServ ) ); |
|
153 iConnection.Start( pref, iStatus ); |
|
154 User::WaitForRequest( iStatus ); |
|
155 User::LeaveIfError( iStatus.Int() ); |
|
156 |
|
157 iStunclient = CSTUNClient::NewL( retransmitInterval, |
|
158 serveraddress, |
|
159 serverport, |
|
160 protocol, |
|
161 iSocketServ, |
|
162 iConnection, |
|
163 *iDeltatimer, |
|
164 *this, |
|
165 obtainsharedsecret, |
|
166 failifnoSRVrecordfound, |
|
167 icmpUsed, |
|
168 iMux ); |
|
169 |
|
170 if ( ut_cstunbinding::iActiveSchedulerWait.IsStarted() ) |
|
171 { |
|
172 ut_cstunbinding::iActiveSchedulerWait.AsyncStop(); |
|
173 } |
|
174 ut_cstunbinding::iActiveSchedulerWait.Start(); |
|
175 } |
|
176 |
|
177 void ut_cstunclient::Teardown( ) |
|
178 { |
|
179 delete iStunclient; |
|
180 iStunclient = NULL; |
|
181 iSocket.Close(); |
|
182 iConnection.Stop(); |
|
183 iConnection.Close(); |
|
184 iSocketServ.Close(); |
|
185 delete iServeraddress; |
|
186 iServeraddress = NULL; |
|
187 delete iResponse; |
|
188 iResponse = NULL; |
|
189 delete iRespDataIndication; |
|
190 iRespDataIndication = NULL; |
|
191 delete iDeltatimer; |
|
192 iDeltatimer = NULL; |
|
193 delete iMux; |
|
194 iMux = NULL; |
|
195 } |
|
196 |
|
197 void ut_cstunclient::UT_CSTUNClient_NewLL( ) |
|
198 { |
|
199 TUint iapID( 6 ); |
|
200 TInt retransmitInterval( 10 ); |
|
201 TBufC8<13> serveraddress( KServerAddress ); |
|
202 TUint serverport( 2000 ); |
|
203 TBufC8<4> protocol( KStun ); |
|
204 TBool obtainsharedsecret( EFalse ); |
|
205 TBool failifnoSRVrecordfound( EFalse ); |
|
206 iStreamId = 1; |
|
207 iSubstreamId = 1; |
|
208 TBool icmpUsed( EFalse ); |
|
209 |
|
210 TCommDbConnPref pref; |
|
211 pref.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); |
|
212 pref.SetIapId( iapID ); |
|
213 |
|
214 CSTUNClient* stunClient = NULL; |
|
215 |
|
216 NATFW_EUNIT_ASSERT_NO_LEAVE( stunClient = CSTUNClient::NewL( |
|
217 retransmitInterval, |
|
218 serveraddress, |
|
219 serverport, |
|
220 protocol, |
|
221 iSocketServ, |
|
222 iConnection, |
|
223 *iDeltatimer, |
|
224 *this, |
|
225 obtainsharedsecret, |
|
226 failifnoSRVrecordfound, |
|
227 icmpUsed, |
|
228 iMux ) ); |
|
229 |
|
230 if ( ut_cstunbinding::iActiveSchedulerWait.IsStarted() ) |
|
231 { |
|
232 ut_cstunbinding::iActiveSchedulerWait.AsyncStop(); |
|
233 } |
|
234 ut_cstunbinding::iActiveSchedulerWait.Start(); |
|
235 |
|
236 delete stunClient; |
|
237 } |
|
238 |
|
239 void ut_cstunclient::UT_CSTUNClient_NewL_1L( ) |
|
240 { |
|
241 TUint iapID( 6 ); |
|
242 TInt retransmitInterval( 10 ); |
|
243 TBufC8<13> serveraddress( KServerAddress ); |
|
244 TUint serverport( 2000 ); |
|
245 TBufC8<4> protocol( KStun ); |
|
246 TBool obtainsharedsecret( EFalse ); |
|
247 TBool failifnoSRVrecordfound( EFalse ); |
|
248 iStreamId = 1; |
|
249 iSubstreamId = 1; |
|
250 TBool icmpUsed( EFalse ); |
|
251 |
|
252 TCommDbConnPref pref; |
|
253 pref.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); |
|
254 pref.SetIapId( iapID ); |
|
255 |
|
256 CSTUNClient* stunClient = NULL; |
|
257 NATFW_EUNIT_ASSERT_NO_LEAVE( stunClient = CSTUNClient::NewL( retransmitInterval, |
|
258 *iDeltatimer, |
|
259 *this, |
|
260 iMux ) ); |
|
261 |
|
262 delete stunClient; |
|
263 } |
|
264 |
|
265 // STUN Relay case |
|
266 void ut_cstunclient::UT_CSTUNClient_NewL_2L( ) |
|
267 { |
|
268 TUint iapID( 6 ); |
|
269 TInt retransmitInterval( 10 ); |
|
270 TBufC8<13> serveraddress( KServerAddress ); |
|
271 TUint serverport( 2000 ); |
|
272 TBufC8<10> service( KStunRelay ); |
|
273 TBool obtainsharedsecret( ETrue ); |
|
274 TBool failifnoSRVrecordfound( EFalse ); |
|
275 iStreamId = 1; |
|
276 iSubstreamId = 1; |
|
277 TBool icmpUsed( EFalse ); |
|
278 |
|
279 TCommDbConnPref pref; |
|
280 pref.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); |
|
281 pref.SetIapId( iapID ); |
|
282 |
|
283 CSTUNClient* stunClient = NULL; |
|
284 NATFW_EUNIT_ASSERT_NO_LEAVE( stunClient = CSTUNClient::NewL( retransmitInterval, |
|
285 serveraddress, |
|
286 serverport, |
|
287 service, |
|
288 iSocketServ, |
|
289 iConnection, |
|
290 *iDeltatimer, |
|
291 *this, |
|
292 obtainsharedsecret, |
|
293 failifnoSRVrecordfound, |
|
294 icmpUsed, |
|
295 iMux ) ); |
|
296 |
|
297 if ( ut_cstunbinding::iActiveSchedulerWait.IsStarted() ) |
|
298 { |
|
299 ut_cstunbinding::iActiveSchedulerWait.AsyncStop(); |
|
300 } |
|
301 ut_cstunbinding::iActiveSchedulerWait.Start(); |
|
302 |
|
303 delete stunClient; |
|
304 } |
|
305 |
|
306 void ut_cstunclient::UT_CSTUNClient_NewLCL( ) |
|
307 { |
|
308 TUint iapID( 6 ); |
|
309 TInt retransmitInterval( 10 ); |
|
310 TBufC8<13> serveraddress( KServerAddress ); |
|
311 TUint serverport( 2000 ); |
|
312 TBufC8<4> protocol( KStun ); |
|
313 TBool obtainsharedsecret( EFalse ); |
|
314 TBool failifnoSRVrecordfound( EFalse ); |
|
315 iStreamId = 1; |
|
316 iSubstreamId = 1; |
|
317 TBool icmpUsed( EFalse ); |
|
318 |
|
319 TCommDbConnPref pref; |
|
320 pref.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); |
|
321 pref.SetIapId( iapID ); |
|
322 |
|
323 CSTUNClient* stunClient = NULL; |
|
324 stunClient = CSTUNClient::NewLC( retransmitInterval, |
|
325 serveraddress, |
|
326 serverport, |
|
327 protocol, |
|
328 iSocketServ, |
|
329 iConnection, |
|
330 *iDeltatimer, |
|
331 *this, |
|
332 obtainsharedsecret, |
|
333 failifnoSRVrecordfound, |
|
334 icmpUsed, |
|
335 iMux ); |
|
336 |
|
337 if ( ut_cstunbinding::iActiveSchedulerWait.IsStarted() ) |
|
338 { |
|
339 ut_cstunbinding::iActiveSchedulerWait.AsyncStop(); |
|
340 } |
|
341 ut_cstunbinding::iActiveSchedulerWait.Start(); |
|
342 |
|
343 CleanupStack::PopAndDestroy( stunClient ); |
|
344 } |
|
345 |
|
346 void ut_cstunclient::UT_CSTUNClient_NewLC_1L( ) |
|
347 { |
|
348 TUint iapID( 6 ); |
|
349 TInt retransmitInterval( 10 ); |
|
350 TBufC8<13> serveraddress( KServerAddress ); |
|
351 TUint serverport( 2000 ); |
|
352 TBufC8<4> protocol( KStun ); |
|
353 TBool obtainsharedsecret( EFalse ); |
|
354 TBool failifnoSRVrecordfound( EFalse ); |
|
355 iStreamId = 1; |
|
356 iSubstreamId = 1; |
|
357 TBool icmpUsed( EFalse ); |
|
358 |
|
359 TCommDbConnPref pref; |
|
360 pref.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); |
|
361 pref.SetIapId( iapID ); |
|
362 |
|
363 CSTUNClient* stunClient = CSTUNClient::NewLC( retransmitInterval, |
|
364 *iDeltatimer, |
|
365 *this, |
|
366 iMux ); |
|
367 |
|
368 CleanupStack::PopAndDestroy( stunClient ); |
|
369 } |
|
370 |
|
371 void ut_cstunclient::UT_CSTUNClient_IsInitializedL( ) |
|
372 { |
|
373 TBool initialized = iStunclient->IsInitialized(); |
|
374 } |
|
375 |
|
376 void ut_cstunclient::UT_CSTUNClient_STUNServerAddrLL( ) |
|
377 { |
|
378 TInetAddr addr = iStunclient->STUNServerAddrL(); |
|
379 } |
|
380 |
|
381 void ut_cstunclient::UT_CSTUNClient_SetCredentialsLL( ) |
|
382 { |
|
383 TBufC8<16> password( KPassword ); |
|
384 TBufC8<6> usernameA( KUsername ); |
|
385 iStunclient->SetCredentialsL( usernameA, password ); |
|
386 |
|
387 iStunclient->SetCredentialsL( usernameA, password ); |
|
388 } |
|
389 |
|
390 void ut_cstunclient::UT_CSTUNClient_SharedSecretObtainedL( ) |
|
391 { |
|
392 TBool sharedSecretused = iStunclient->SharedSecretObtained(); |
|
393 } |
|
394 |
|
395 /*void ut_cstunclient::UT_CSTUNClient_SetSTUNServerAddrLL( ) |
|
396 { |
|
397 TInetAddr addr; |
|
398 iStunclient->SetSTUNServerAddrL( addr ); |
|
399 }*/ |
|
400 |
|
401 void ut_cstunclient::UT_CSTUNClient_ObtainTransactionIDLL( ) |
|
402 { |
|
403 TNATFWUNSAFTransactionID transactionID; |
|
404 iStunclient->ObtainTransactionIDL( transactionID ); |
|
405 } |
|
406 |
|
407 void ut_cstunclient::UT_CSTUNClient_ImplementationL( ) |
|
408 { |
|
409 CSTUNClientImplementation& impl = iStunclient->Implementation(); |
|
410 } |
|
411 |
|
412 // TEST TABLE |
|
413 |
|
414 EUNIT_BEGIN_TEST_TABLE( |
|
415 ut_cstunclient, |
|
416 "Add test suite description here.", |
|
417 "UNIT" ) |
|
418 |
|
419 EUNIT_TEST( |
|
420 "NewL - test ", |
|
421 "CSTUNClient", |
|
422 "NewL", |
|
423 "FUNCTIONALITY", |
|
424 SetupL, UT_CSTUNClient_NewLL, Teardown) |
|
425 /* |
|
426 EUNIT_TEST( |
|
427 "NewL - test ", |
|
428 "CSTUNClient", |
|
429 "NewL", |
|
430 "FUNCTIONALITY", |
|
431 SetupL, UT_CSTUNClient_NewL_1L, Teardown) |
|
432 |
|
433 EUNIT_TEST( |
|
434 "NewL_2 - test ", |
|
435 "CSTUNClient", |
|
436 "NewL_2", |
|
437 "FUNCTIONALITY", |
|
438 SetupL, UT_CSTUNClient_NewL_2L, Teardown) |
|
439 |
|
440 EUNIT_TEST( |
|
441 "NewLC - test ", |
|
442 "CSTUNClient", |
|
443 "NewLC", |
|
444 "FUNCTIONALITY", |
|
445 SetupL, UT_CSTUNClient_NewLCL, Teardown) |
|
446 |
|
447 EUNIT_TEST( |
|
448 "NewLC - test ", |
|
449 "CSTUNClient", |
|
450 "NewLC", |
|
451 "FUNCTIONALITY", |
|
452 SetupL, UT_CSTUNClient_NewLC_1L, Teardown) |
|
453 |
|
454 EUNIT_TEST( |
|
455 "IsInitialized - test ", |
|
456 "CSTUNClient", |
|
457 "IsInitialized", |
|
458 "FUNCTIONALITY", |
|
459 SetupL, UT_CSTUNClient_IsInitializedL, Teardown) |
|
460 |
|
461 EUNIT_TEST( |
|
462 "STUNServerAddrL - test ", |
|
463 "CSTUNClient", |
|
464 "STUNServerAddrL", |
|
465 "FUNCTIONALITY", |
|
466 SetupL, UT_CSTUNClient_STUNServerAddrLL, Teardown) |
|
467 |
|
468 EUNIT_TEST( |
|
469 "SetCredentialsL - test ", |
|
470 "CSTUNClient", |
|
471 "SetCredentialsL", |
|
472 "FUNCTIONALITY", |
|
473 SetupL, UT_CSTUNClient_SetCredentialsLL, Teardown) |
|
474 |
|
475 EUNIT_TEST( |
|
476 "SharedSecretObtained - test ", |
|
477 "CSTUNClient", |
|
478 "SharedSecretObtained", |
|
479 "FUNCTIONALITY", |
|
480 SetupL, UT_CSTUNClient_SharedSecretObtainedL, Teardown) |
|
481 */ |
|
482 /*EUNIT_TEST( |
|
483 "SetSTUNServerAddrL - test ", |
|
484 "CSTUNClient", |
|
485 "SetSTUNServerAddrL", |
|
486 "FUNCTIONALITY", |
|
487 SetupL, UT_CSTUNClient_SetSTUNServerAddrLL, Teardown)*/ |
|
488 /* |
|
489 EUNIT_TEST( |
|
490 "ObtainTransactionIDL - test ", |
|
491 "CSTUNClient", |
|
492 "ObtainTransactionIDL", |
|
493 "FUNCTIONALITY", |
|
494 SetupL, UT_CSTUNClient_ObtainTransactionIDLL, Teardown) |
|
495 |
|
496 EUNIT_TEST( |
|
497 "Implementation - test ", |
|
498 "CSTUNClient", |
|
499 "Implementation", |
|
500 "FUNCTIONALITY", |
|
501 SetupL, UT_CSTUNClient_ImplementationL, Teardown) |
|
502 |
|
503 */ |
|
504 EUNIT_END_TEST_TABLE |
|
505 |
|
506 // END OF FILE |