|
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_cmcestateidle.h" |
|
23 |
|
24 // EXTERNAL INCLUDES |
|
25 #include <digia/eunit/eunitmacros.h> |
|
26 |
|
27 |
|
28 // INTERNAL INCLUDES |
|
29 #include "MCETestHelper.h" |
|
30 |
|
31 #include "mcesipsession.h" |
|
32 #include "mcesipstatemachine.h" |
|
33 #include "mceservercore.h" |
|
34 #include "mcecssession.h" |
|
35 #include "mcecssessionimplementation.h" |
|
36 #include "mcesipconnection.h" |
|
37 #include "mcecomsession.h" |
|
38 #include "mcestateidle.h" |
|
39 #include "mceevent.h" |
|
40 #include "mceserial.h" |
|
41 #include "mcemediamanager.h" |
|
42 #include "mcenatsipsession.h" |
|
43 |
|
44 |
|
45 |
|
46 // CONSTRUCTION |
|
47 UT_CMceStateIdle* UT_CMceStateIdle::NewL() |
|
48 { |
|
49 UT_CMceStateIdle* self = UT_CMceStateIdle::NewLC(); |
|
50 CleanupStack::Pop(); |
|
51 |
|
52 return self; |
|
53 } |
|
54 |
|
55 UT_CMceStateIdle* UT_CMceStateIdle::NewLC() |
|
56 { |
|
57 UT_CMceStateIdle* self = new( ELeave ) UT_CMceStateIdle(); |
|
58 CleanupStack::PushL( self ); |
|
59 |
|
60 self->ConstructL(); |
|
61 |
|
62 return self; |
|
63 } |
|
64 |
|
65 // Destructor (virtual by CBase) |
|
66 UT_CMceStateIdle::~UT_CMceStateIdle() |
|
67 { |
|
68 } |
|
69 |
|
70 // Default constructor |
|
71 UT_CMceStateIdle::UT_CMceStateIdle() |
|
72 { |
|
73 } |
|
74 |
|
75 // Second phase construct |
|
76 void UT_CMceStateIdle::ConstructL() |
|
77 { |
|
78 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
79 // It generates the test case table. |
|
80 CEUnitTestSuiteClass::ConstructL(); |
|
81 } |
|
82 |
|
83 // METHODS |
|
84 |
|
85 void UT_CMceStateIdle::SetupL() |
|
86 { |
|
87 CMCETls::OpenL(); |
|
88 SdpCodecStringPool::OpenL(); |
|
89 |
|
90 |
|
91 //TMceIds ids; |
|
92 iIds.iProfileID = 1; |
|
93 iIds.iManagerType = KMceCSSIPSession; |
|
94 iIds.iDialogType = KMceDlgTypeInvite; |
|
95 iServerCore = CMceServerCore::NewL(); |
|
96 |
|
97 iStorage = CMCETls::Storage(); |
|
98 |
|
99 CDesC8ArrayFlat* params = new (ELeave) CDesC8ArrayFlat( KMceArrayGranularity ); |
|
100 CleanupStack::PushL( params ); |
|
101 params->AppendL( _L8("User <user2@host>") ); |
|
102 params->AppendL( _L8("User <user@host>") ); |
|
103 |
|
104 CMceMsgTextArray* msgParams = new (ELeave) CMceMsgTextArray( *params ); |
|
105 CleanupStack::PushL( msgParams ); |
|
106 iStorage->StoreL( iIds, *msgParams ); |
|
107 CleanupStack::PopAndDestroy( msgParams ); |
|
108 CleanupStack::PopAndDestroy( params ); |
|
109 |
|
110 iSession = CMceCsSession::NewL(*iServerCore); |
|
111 iSession->CreateSubSessionL(iIds, RMessage2()); |
|
112 iSipSession = static_cast<CMceSipSession*>((iSession->Implementation().SubSessions())[0]); |
|
113 iSipSession->NextState( KMceStateIdle ); |
|
114 iState = static_cast<CMceStateIdle*>(&iSipSession->CurrentState()); |
|
115 } |
|
116 |
|
117 void UT_CMceStateIdle::Teardown() |
|
118 { |
|
119 CMCETls::Close(); |
|
120 delete iSession; |
|
121 delete iServerCore; |
|
122 |
|
123 SdpCodecStringPool::Close(); |
|
124 } |
|
125 |
|
126 void UT_CMceStateIdle::UT_CMceStateIdle_AcceptLL() |
|
127 { |
|
128 TMceIds ids; |
|
129 CMceMsgBase* msg = NULL; |
|
130 |
|
131 TMceStateTransitionEvent event1( *iSipSession, EMceItcEstablishSession, ids, *msg ); |
|
132 EUNIT_ASSERT ( iState->AcceptL( event1 ) ); |
|
133 |
|
134 TMceStateTransitionEvent event2( *iSipSession, EMceInvite ); |
|
135 EUNIT_ASSERT ( iState->AcceptL( event2 ) ); |
|
136 |
|
137 TMceStateTransitionEvent event3( *iSipSession, EMceMediaUpdated ); |
|
138 TRAPD( e1, iState->AcceptL( event3 ) ); |
|
139 EUNIT_ASSERT ( e1 == KErrTotalLossOfPrecision ); |
|
140 |
|
141 TMceStateTransitionEvent event4( *iSipSession, EMceItcUpdate, ids, *msg ); |
|
142 TRAPD( e2, iState->AcceptL( event4 ) ); |
|
143 EUNIT_ASSERT ( e2 == KErrTotalLossOfPrecision ); |
|
144 |
|
145 TMceStateTransitionEvent event5( *iSipSession, EMceCancel, KErrNotFound ); |
|
146 TRAPD( e3, iState->AcceptL( event5 ) ); |
|
147 EUNIT_ASSERT ( e3 == KErrTotalLossOfPrecision ); |
|
148 |
|
149 |
|
150 TMceStateTransitionEvent event8( *iSipSession, EMceMediaUpdated ); |
|
151 TRAPD( e6, iState->AcceptL( event8 ) ); |
|
152 EUNIT_ASSERT ( e6 == KErrTotalLossOfPrecision ); |
|
153 } |
|
154 |
|
155 void UT_CMceStateIdle::UT_CMceStateIdle_EntryLL() |
|
156 { |
|
157 //Invite |
|
158 |
|
159 CMceComSession* clientSession = CMceComSession::NewL( CMceComSession::EOutSession ); |
|
160 CleanupStack::PushL( clientSession ); |
|
161 CMceMsgObject<CMceComSession>* clientSessionMsg = |
|
162 new (ELeave) CMceMsgObject<CMceComSession>( *clientSession, EMceItcMsgTypeSession ); |
|
163 CleanupStack::Pop( clientSession ); |
|
164 clientSessionMsg->PushL(); |
|
165 CleanupStack::PushL( clientSessionMsg ); |
|
166 |
|
167 TMceIds ids; |
|
168 |
|
169 iStorage->iMediaManagerUpdateStatus = KMceAsync; |
|
170 TMceStateTransitionEvent event1( *iSipSession, EMceItcEstablishSession, ids, |
|
171 *clientSessionMsg ); |
|
172 |
|
173 iState->EntryL( event1 ); |
|
174 CleanupStack::PopAndDestroy( clientSessionMsg ); |
|
175 |
|
176 EUNIT_ASSERT ( iStorage->iMediaManagerAction == CMCETls::EUpdate ); |
|
177 EUNIT_ASSERT ( iStorage->iMediaManagerSdpAction == CMCETls::ENone ); |
|
178 EUNIT_ASSERT ( iSipSession->Body() == clientSession ); |
|
179 EUNIT_ASSERT ( iSipSession->Body()->iSIPContent == NULL ); |
|
180 EUNIT_ASSERT ( iSipSession->Offer() == NULL ); |
|
181 |
|
182 delete iSipSession->iBody; |
|
183 iSipSession->iBody = NULL; |
|
184 |
|
185 clientSession = CMceComSession::NewL( CMceComSession::EOutSession ); |
|
186 CleanupStack::PushL( clientSession ); |
|
187 clientSessionMsg = |
|
188 new (ELeave) CMceMsgObject<CMceComSession>( *clientSession, EMceItcMsgTypeSession ); |
|
189 CleanupStack::Pop( clientSession ); |
|
190 clientSessionMsg->PushL(); |
|
191 CleanupStack::PushL( clientSessionMsg ); |
|
192 |
|
193 iStorage->iMediaManagerUpdateStatus = KMceReady; |
|
194 TMceStateTransitionEvent event1_1( *iSipSession, EMceItcEstablishSession, ids, |
|
195 *clientSessionMsg ); |
|
196 |
|
197 iState->EntryL( event1_1 ); |
|
198 CleanupStack::PopAndDestroy( clientSessionMsg ); |
|
199 |
|
200 EUNIT_ASSERT ( iStorage->iMediaManagerAction == CMCETls::EUpdate ); |
|
201 EUNIT_ASSERT ( iStorage->iMediaManagerSdpAction == CMCETls::EEncode ); |
|
202 EUNIT_ASSERT ( iSipSession->Body() == clientSession ); |
|
203 EUNIT_ASSERT ( iSipSession->Body()->iSIPContent == NULL ); |
|
204 EUNIT_ASSERT ( iSipSession->Offer() != NULL ); |
|
205 |
|
206 |
|
207 delete iSipSession->iOffer; |
|
208 iSipSession->iOffer = NULL; |
|
209 |
|
210 |
|
211 //Invited |
|
212 |
|
213 iSipSession->Body()->iType = CMceComSession::EInSession; |
|
214 |
|
215 RPointerArray<CSIPHeaderBase> sipHeaders; |
|
216 CSIPHeaderBase::PushLC( &sipHeaders ); |
|
217 |
|
218 // Supported: timer |
|
219 RStringF timerKey = SIPStrings::Pool().OpenFStringL( KMceSipTimer() ); |
|
220 CleanupClosePushL( timerKey ); |
|
221 |
|
222 CSIPSupportedHeader* supportedHeader = CSIPSupportedHeader::NewLC( timerKey ); |
|
223 |
|
224 User::LeaveIfError( sipHeaders.Append( supportedHeader ) ); |
|
225 CleanupStack::Pop( supportedHeader ); |
|
226 CleanupStack::PopAndDestroy();//timerKey |
|
227 |
|
228 // Session-Expires: 10 |
|
229 |
|
230 CSIPExtensionHeader* sessionExpiresHeader = |
|
231 CSIPExtensionHeader::NewLC( KSessionExpires(), _L8("10") ); |
|
232 User::LeaveIfError( sipHeaders.Append( sessionExpiresHeader ) ); |
|
233 CleanupStack::Pop( sessionExpiresHeader ); |
|
234 |
|
235 CSIPServerTransaction* srvtransaction = |
|
236 MCETestHelper::ServerTransactionL( SipStrConsts::EInvite, sipHeaders, ETrue ); |
|
237 CleanupStack::PopAndDestroy( &sipHeaders ); |
|
238 CleanupStack::PushL( srvtransaction ); |
|
239 iSipSession->iPendingReceivedRequests.AppendL( srvtransaction ); |
|
240 CleanupStack::Pop( srvtransaction ); |
|
241 |
|
242 TMceStateTransitionEvent event2( *iSipSession, EMceInvite ); |
|
243 iState->EntryL( event2 ); |
|
244 |
|
245 EUNIT_ASSERT ( iStorage->iMediaManagerAction == CMCETls::EUpdate ); |
|
246 |
|
247 iStorage->iMediaManagerAction = CMCETls::ENone; |
|
248 iStorage->iMediaManagerDecodeStatus = KMceSipWarnMediaTypeNotAvailable; |
|
249 |
|
250 TMceStateTransitionEvent event3( *iSipSession, EMceInvite ); |
|
251 iState->EntryL( event3 ); |
|
252 |
|
253 |
|
254 EUNIT_ASSERT ( iStorage->iMediaManagerAction == CMCETls::ENone ); |
|
255 EUNIT_ASSERT ( iStorage->iSipSentResponse->StatusCode() == KMceSipNotAcceptableHere ); |
|
256 EUNIT_ASSERT ( iSipSession->Body() != NULL ); |
|
257 EUNIT_ASSERT ( iSipSession->BodyCandidate() == NULL ); |
|
258 EUNIT_ASSERT ( iSipSession->Body()->iType == CMceComSession::EInSession ); |
|
259 EUNIT_ASSERT ( iSipSession->Body()->iSIPContent == NULL ); |
|
260 |
|
261 |
|
262 TMceStateTransitionEvent event4( *iSipSession, EMceCancel ); |
|
263 iState->EntryL( event4 ); |
|
264 |
|
265 CSIPServerTransaction& request = iSipSession->Request(); |
|
266 CSIPRequestElements* requestElement = const_cast<CSIPRequestElements*>(request.RequestElements()); |
|
267 requestElement->MessageElements().SetContent( NULL ); |
|
268 |
|
269 TMceStateTransitionEvent event2_2( *iSipSession, EMceInvite ); |
|
270 iState->EntryL( event2_2 ); |
|
271 } |
|
272 |
|
273 void UT_CMceStateIdle::UT_CMceStateIdle_ExitLL() |
|
274 { |
|
275 TMceIds ids; |
|
276 CMceMsgBase* msg = NULL; |
|
277 |
|
278 iSipSession->iBody = CMceComSession::NewL( CMceComSession::EOutSession ); |
|
279 |
|
280 TMceStateTransitionEvent event1( *iSipSession, EMceItcEstablishSession, ids, *msg ); |
|
281 event1.ParamStatus() = KMceAsync; |
|
282 |
|
283 iState->ExitL( event1 ); |
|
284 EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateClientEstablishing ); |
|
285 EUNIT_ASSERT ( iSipSession->iBody->iState == CMceSession::EOffering ); |
|
286 EUNIT_ASSERT ( ids.iState == CMceSession::EOffering ); |
|
287 MCE_SET_STATES( iSipSession /*session*/, |
|
288 CMceSession::EIdle /*clientState*/, |
|
289 KMceStateIdle /*serverState*/ ); |
|
290 |
|
291 |
|
292 TMceStateTransitionEvent event1_1( *iSipSession, EMceItcEstablishSession, ids, *msg ); |
|
293 event1_1.ParamStatus() = KMceReady; |
|
294 |
|
295 iState->ExitL( event1_1 ); |
|
296 EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateOffering ); |
|
297 EUNIT_ASSERT ( iSipSession->iBody->iState == CMceSession::EOffering ); |
|
298 EUNIT_ASSERT ( ids.iState == CMceSession::EOffering ); |
|
299 MCE_SET_STATES( iSipSession /*session*/, |
|
300 CMceSession::EIdle /*clientState*/, |
|
301 KMceStateIdle /*serverState*/ ); |
|
302 |
|
303 EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateIdle ); |
|
304 MCE_TH_SET( iSipSession->iBody, NULL ); |
|
305 iSipSession->iBody = CMceComSession::NewL( CMceComSession::EInSession ); |
|
306 |
|
307 TMceStateTransitionEvent event2( *iSipSession, EMceInvite ); |
|
308 iState->ExitL( event2 ); |
|
309 EUNIT_ASSERT ( iSipSession->CurrentState().Id() == KMceStateServerEstablishing ); |
|
310 EUNIT_ASSERT ( iSipSession->iBody->iState == CMceSession::EIncoming ); |
|
311 |
|
312 MCE_SET_STATES( iSipSession /*session*/, |
|
313 CMceSession::EIdle /*clientState*/, |
|
314 KMceStateIdle /*serverState*/ ); |
|
315 |
|
316 TMceStateTransitionEvent event3( *iSipSession, EMceCancel ); |
|
317 iState->ExitL( event3 ); |
|
318 |
|
319 MCE_SET_STATES( iSipSession /*session*/, |
|
320 CMceSession::EIdle /*clientState*/, |
|
321 KMceStateIdle /*serverState*/ ); |
|
322 } |
|
323 |
|
324 |
|
325 // INVITE received for a NAT session |
|
326 void UT_CMceStateIdle::UT_CMceStateIdle_ExitL_NatSessionL() |
|
327 { |
|
328 |
|
329 CMceSipManager& manager = iServerCore->Manager(); |
|
330 TUint32 profileId = 1; |
|
331 CSIPProfile& profile = manager.ProfileL( profileId ); |
|
332 |
|
333 // Syncronous case |
|
334 CMceNatSipSession* natSession = |
|
335 CMceNatSipSession::NewLC( *iSession, |
|
336 iSipSession->SIPConnection(), |
|
337 *iSipSession->iStateMachine, |
|
338 profile, |
|
339 NULL ); |
|
340 |
|
341 natSession->iBody = CMceComSession::NewL( CMceComSession::EInSession ); |
|
342 |
|
343 TMceIds ids; |
|
344 CMceMsgBase* msg = NULL; |
|
345 |
|
346 CSIPServerTransaction* trx = |
|
347 MCETestHelper::ServerTransactionL( SipStrConsts::EInvite, ETrue ); |
|
348 CleanupStack::PushL(trx); |
|
349 EUNIT_ASSERT( &natSession->Request() == NULL ); |
|
350 natSession->iPendingReceivedRequests.AppendL( trx ); |
|
351 CleanupStack::Pop(trx); |
|
352 EUNIT_ASSERT( &natSession->Request() == trx ); |
|
353 |
|
354 // TODO: remove natSession->iComSession = natSession->iBody; |
|
355 natSession->iType = CMceCsSubSession::EInSession; // make this MT case |
|
356 |
|
357 |
|
358 TMceStateTransitionEvent event( *natSession, EMceInvite ); |
|
359 event.ParamStatus() = KMceReady; |
|
360 |
|
361 iState->ExitL( event ); |
|
362 |
|
363 EUNIT_ASSERT( natSession->CurrentState().Id() == |
|
364 KMceStateServerInitializing ); |
|
365 |
|
366 |
|
367 // Asyncronous case |
|
368 natSession->NextState( KMceStateIdle ); |
|
369 event.ParamStatus() = KMceAsync; |
|
370 |
|
371 iState->ExitL( event ); |
|
372 EUNIT_ASSERT( natSession->CurrentState().Id() == |
|
373 KMceStateServerInitializing ); |
|
374 |
|
375 |
|
376 // Error case |
|
377 natSession->NextState( KMceStateIdle ); |
|
378 event.ParamStatus() = KErrGeneral; |
|
379 |
|
380 iState->ExitL( event ); |
|
381 |
|
382 EUNIT_ASSERT( natSession->CurrentState().Id() == KMceStateTerminated ); |
|
383 |
|
384 CleanupStack::PopAndDestroy( natSession ); |
|
385 } |
|
386 |
|
387 |
|
388 // Pull mode INVITE received for a NAT session |
|
389 void UT_CMceStateIdle::UT_CMceStateIdle_ExitL_NatSession1L() |
|
390 { |
|
391 CMceSipManager& manager = iServerCore->Manager(); |
|
392 TUint32 profileId = 1; |
|
393 CSIPProfile& profile = manager.ProfileL( profileId ); |
|
394 |
|
395 // Syncronous case |
|
396 CMceNatSipSession* natSession = |
|
397 CMceNatSipSession::NewLC( *iSession, |
|
398 iSipSession->SIPConnection(), |
|
399 *iSipSession->iStateMachine, |
|
400 profile, |
|
401 NULL ); |
|
402 TMceStateTransitionEvent event( *natSession, EMceInvite ); |
|
403 event.ParamStatus() = KMceReady; |
|
404 |
|
405 iState->ExitL( event ); |
|
406 |
|
407 EUNIT_ASSERT( natSession->CurrentState().Id() == |
|
408 KMceStateServerEstablishing ); |
|
409 |
|
410 // Error case |
|
411 natSession->NextState( KMceStateIdle ); |
|
412 event.ParamStatus() = KErrGeneral; |
|
413 |
|
414 iState->ExitL( event ); |
|
415 |
|
416 EUNIT_ASSERT( natSession->CurrentState().Id() == KMceStateTerminated ); |
|
417 |
|
418 CleanupStack::PopAndDestroy( natSession ); |
|
419 } |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 // TEST TABLE |
|
425 |
|
426 EUNIT_BEGIN_TEST_TABLE( |
|
427 UT_CMceStateIdle, |
|
428 "UT_CMceStateIdle", |
|
429 "UNIT" ) |
|
430 |
|
431 EUNIT_TEST( |
|
432 "AcceptL - test ", |
|
433 "CMceStateIdle", |
|
434 "AcceptL", |
|
435 "FUNCTIONALITY", |
|
436 SetupL, UT_CMceStateIdle_AcceptLL, Teardown) |
|
437 |
|
438 EUNIT_TEST( |
|
439 "EntryL - test ", |
|
440 "CMceStateIdle", |
|
441 "EntryL", |
|
442 "FUNCTIONALITY", |
|
443 SetupL, UT_CMceStateIdle_EntryLL, Teardown) |
|
444 |
|
445 EUNIT_TEST( |
|
446 "ExitL - test ", |
|
447 "CMceStateIdle", |
|
448 "ExitL", |
|
449 "FUNCTIONALITY", |
|
450 SetupL, UT_CMceStateIdle_ExitLL, Teardown) |
|
451 |
|
452 EUNIT_TEST( |
|
453 "ExitL - NAT session", |
|
454 "CMceStateIdle", |
|
455 "ExitL", |
|
456 "FUNCTIONALITY", |
|
457 SetupL, UT_CMceStateIdle_ExitL_NatSessionL, Teardown) |
|
458 |
|
459 EUNIT_TEST( |
|
460 "ExitL - NAT Pull Mode", |
|
461 "CMceStateIdle", |
|
462 "ExitL", |
|
463 "FUNCTIONALITY", |
|
464 SetupL, UT_CMceStateIdle_ExitL_NatSession1L, Teardown) |
|
465 |
|
466 |
|
467 EUNIT_END_TEST_TABLE |
|
468 |
|
469 // END OF FILE |