|
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_cmcestateserverinitializing.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 "mcenatsipsession.h" |
|
33 #include "mceservercore.h" |
|
34 #include "mcecssession.h" |
|
35 #include "mcecssessionimplementation.h" |
|
36 #include "mcestateserverinitializing.h" |
|
37 #include "mceevent.h" |
|
38 |
|
39 |
|
40 // CONSTRUCTION |
|
41 UT_CMceStateServerInitializing* UT_CMceStateServerInitializing::NewL() |
|
42 { |
|
43 UT_CMceStateServerInitializing* self = |
|
44 UT_CMceStateServerInitializing::NewLC(); |
|
45 CleanupStack::Pop(); |
|
46 return self; |
|
47 } |
|
48 |
|
49 UT_CMceStateServerInitializing* UT_CMceStateServerInitializing::NewLC() |
|
50 { |
|
51 UT_CMceStateServerInitializing* self = |
|
52 new ( ELeave ) UT_CMceStateServerInitializing(); |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL(); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // Destructor (virtual by CBase) |
|
59 UT_CMceStateServerInitializing::~UT_CMceStateServerInitializing() |
|
60 { |
|
61 } |
|
62 |
|
63 // Default constructor |
|
64 UT_CMceStateServerInitializing::UT_CMceStateServerInitializing() |
|
65 { |
|
66 } |
|
67 |
|
68 // Second phase construct |
|
69 void UT_CMceStateServerInitializing::ConstructL() |
|
70 { |
|
71 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
72 // It generates the test case table. |
|
73 CEUnitTestSuiteClass::ConstructL(); |
|
74 } |
|
75 |
|
76 // METHODS |
|
77 |
|
78 void UT_CMceStateServerInitializing::SetupL() |
|
79 { |
|
80 CMCETls::OpenL(); |
|
81 SdpCodecStringPool::OpenL(); |
|
82 |
|
83 iIds.iProfileID = 1; |
|
84 iIds.iManagerType = KMceCSSIPSession; |
|
85 iIds.iDialogType = KMceDlgTypeInvite; |
|
86 iServerCore = CMceServerCore::NewL(); |
|
87 |
|
88 iStorage = CMCETls::Storage(); |
|
89 |
|
90 CDesC8ArrayFlat* params = new (ELeave) CDesC8ArrayFlat( KMceArrayGranularity ); |
|
91 CleanupStack::PushL( params ); |
|
92 params->AppendL( _L8("User <user2@host>") ); |
|
93 params->AppendL( _L8("User <user@host>") ); |
|
94 |
|
95 CMceMsgTextArray* msgParams = new (ELeave) CMceMsgTextArray( *params ); |
|
96 CleanupStack::PushL( msgParams ); |
|
97 iStorage->StoreL( iIds, *msgParams ); |
|
98 CleanupStack::PopAndDestroy( msgParams ); |
|
99 CleanupStack::PopAndDestroy( params ); |
|
100 |
|
101 iSession = CMceCsSession::NewL(*iServerCore); |
|
102 iSession->CreateSubSessionL(iIds, RMessage2()); |
|
103 iSipSession = static_cast<CMceSipSession*> |
|
104 ((iSession->Implementation().SubSessions())[0]); |
|
105 |
|
106 CMceSipManager& manager = iServerCore->Manager(); |
|
107 CSIPProfile& profile = manager.ProfileL( iIds.iProfileID ); |
|
108 |
|
109 iNatSession = CMceNatSipSession::NewL( *iSession, |
|
110 iSipSession->SIPConnection(), |
|
111 *iSipSession->iStateMachine, |
|
112 profile, |
|
113 NULL ); |
|
114 iNatSession->NextState( KMceStateServerInitializing ); |
|
115 iState = static_cast<CMceStateServerInitializing*> |
|
116 (&iNatSession->CurrentState()); |
|
117 } |
|
118 |
|
119 void UT_CMceStateServerInitializing::Teardown() |
|
120 { |
|
121 CMCETls::Close(); |
|
122 delete iSession; |
|
123 iSession = NULL; |
|
124 delete iNatSession; |
|
125 iNatSession = NULL; |
|
126 delete iServerCore; |
|
127 iServerCore = NULL; |
|
128 |
|
129 SdpCodecStringPool::Close(); |
|
130 } |
|
131 |
|
132 void UT_CMceStateServerInitializing::UT_CMceStateServerInitializing_DoAcceptLL() |
|
133 { |
|
134 EUNIT_ASSERT( IsAcceptedL( EMceServerInitialized ) ); |
|
135 |
|
136 EUNIT_ASSERT( !IsAcceptedL( EMceResponse ) ); |
|
137 EUNIT_ASSERT( !IsAcceptedL( EMceInvite ) ); |
|
138 EUNIT_ASSERT( !IsAcceptedL( EMceCancel ) ); |
|
139 } |
|
140 |
|
141 void UT_CMceStateServerInitializing::UT_CMceStateServerInitializing_EntryLL() |
|
142 { |
|
143 if ( !iNatSession->iBody ) |
|
144 { |
|
145 iNatSession->iBody = CMceComSession::NewL(); |
|
146 } |
|
147 if ( !iNatSession->iOffer ) |
|
148 { |
|
149 iNatSession->iOffer = CSdpDocument::NewL(); |
|
150 } |
|
151 |
|
152 CSIPServerTransaction* sta = |
|
153 CSIPServerTransaction::NewL( |
|
154 SIPStrings::StringF( SipStrConsts::EInvite ) ); |
|
155 CleanupStack::PushL( sta ); |
|
156 |
|
157 |
|
158 TUriParser8 uriParser; |
|
159 User::LeaveIfError( uriParser.Parse( _L8("sip:u1@170.85.90.120") ) ); |
|
160 CUri8* remoteUri = CUri8::NewLC( uriParser ); |
|
161 CSIPRequestElements* elem = CSIPRequestElements::NewL( remoteUri ); |
|
162 CleanupStack::Pop( remoteUri ); |
|
163 CleanupStack::PushL( elem ); |
|
164 |
|
165 CSIPAddress* addr = CSIPAddress::DecodeL( _L8( "sip:58.94.37.21" ) ); |
|
166 CleanupStack::PushL( addr ); |
|
167 CSIPToHeader* to = CSIPToHeader::NewL( addr ); |
|
168 CleanupStack::Pop( addr ); |
|
169 CleanupStack::PushL( to ); |
|
170 elem->SetToHeaderL( to ); |
|
171 CleanupStack::Pop( to ); |
|
172 |
|
173 addr = CSIPAddress::DecodeL( _L8( "sip:58.94.37.21" ) ); |
|
174 CleanupStack::PushL( addr ); |
|
175 CSIPFromHeader* from = CSIPFromHeader::NewL( addr ); |
|
176 CleanupStack::Pop( addr ); |
|
177 CleanupStack::PushL( from ); |
|
178 elem->SetFromHeaderL( from ); |
|
179 CleanupStack::Pop( from ); |
|
180 |
|
181 sta->SetRequestElements( elem ); |
|
182 CleanupStack::Pop( elem ); |
|
183 |
|
184 |
|
185 iNatSession->iDialog = CSIPInviteDialogAssoc::NewL( *sta ); |
|
186 iNatSession->iPendingReceivedRequests.AppendL( sta ); |
|
187 CleanupStack::Pop( sta ); |
|
188 |
|
189 TMceStateTransitionEvent event( *iNatSession, EMceServerInitialized ); |
|
190 iState->EntryL( event ); |
|
191 } |
|
192 |
|
193 void UT_CMceStateServerInitializing::UT_CMceStateServerInitializing_ExitLL() |
|
194 { |
|
195 // No error |
|
196 TMceStateTransitionEvent event( *iNatSession, EMceServerInitialized ); |
|
197 event.ParamStatus() = KErrNone; |
|
198 |
|
199 iState->ExitL( event ); |
|
200 |
|
201 EUNIT_ASSERT( iNatSession->CurrentState().Id() == |
|
202 KMceStateServerEstablishing ); |
|
203 |
|
204 |
|
205 // Error result |
|
206 event.ParamStatus() = KErrGeneral; |
|
207 iNatSession->NextState( KMceStateServerInitializing ); |
|
208 |
|
209 iState->ExitL( event ); |
|
210 |
|
211 EUNIT_ASSERT( iNatSession->CurrentState().Id() == KMceStateTerminated ); |
|
212 } |
|
213 |
|
214 TBool UT_CMceStateServerInitializing::IsAcceptedL( enum TMceSipEventCode aEventCode ) |
|
215 { |
|
216 TMceStateTransitionEvent event( *iNatSession, aEventCode ); |
|
217 return iState->AcceptL( event ); |
|
218 } |
|
219 |
|
220 // TEST TABLE |
|
221 |
|
222 EUNIT_BEGIN_TEST_TABLE( |
|
223 UT_CMceStateServerInitializing, |
|
224 "UT_CMceStateServerInitializing", |
|
225 "UNIT" ) |
|
226 |
|
227 EUNIT_TEST( |
|
228 "DoAcceptL - test ", |
|
229 "CMceStateServerInitializing", |
|
230 "DoAcceptL", |
|
231 "FUNCTIONALITY", |
|
232 SetupL, UT_CMceStateServerInitializing_DoAcceptLL, Teardown) |
|
233 |
|
234 EUNIT_TEST( |
|
235 "EntryL - test ", |
|
236 "CMceStateServerInitializing", |
|
237 "EntryL", |
|
238 "FUNCTIONALITY", |
|
239 SetupL, UT_CMceStateServerInitializing_EntryLL, Teardown) |
|
240 |
|
241 EUNIT_TEST( |
|
242 "ExitL - test ", |
|
243 "CMceStateServerInitializing", |
|
244 "ExitL", |
|
245 "FUNCTIONALITY", |
|
246 SetupL, UT_CMceStateServerInitializing_ExitLL, Teardown) |
|
247 |
|
248 EUNIT_END_TEST_TABLE |
|
249 |
|
250 // END OF FILE |