|
1 /* |
|
2 * Copyright (c) 2009 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 // INTERNAL INCLUDES |
|
20 #include "ut_musengsipprofilehandler.h" |
|
21 #include "mussipprofilehandler.h" |
|
22 #include "musengstubs.h" |
|
23 #include "musengtestdefs.h" |
|
24 #include "sipprofilealrcontroller.h" |
|
25 |
|
26 |
|
27 // SYSTEM INCLUDES |
|
28 #include <sipprofile.h> |
|
29 #include <digia/eunit/eunitmacros.h> |
|
30 #include <uri8.h> |
|
31 |
|
32 const TUint KSipProfileId( 1 ); |
|
33 |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 UT_CMusEngSipProfileHandler* UT_CMusEngSipProfileHandler::NewL() |
|
40 { |
|
41 UT_CMusEngSipProfileHandler* self = UT_CMusEngSipProfileHandler::NewLC(); |
|
42 CleanupStack::Pop( self ); |
|
43 return self; |
|
44 } |
|
45 |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 UT_CMusEngSipProfileHandler* UT_CMusEngSipProfileHandler::NewLC() |
|
52 { |
|
53 UT_CMusEngSipProfileHandler* self = new( ELeave ) UT_CMusEngSipProfileHandler(); |
|
54 CleanupStack::PushL( self ); |
|
55 self->ConstructL(); |
|
56 return self; |
|
57 } |
|
58 |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 UT_CMusEngSipProfileHandler::~UT_CMusEngSipProfileHandler() |
|
65 { |
|
66 // NOP |
|
67 } |
|
68 |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // Default constructor |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 UT_CMusEngSipProfileHandler::UT_CMusEngSipProfileHandler() |
|
75 { |
|
76 // NOP |
|
77 } |
|
78 |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // Second phase construct |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 void UT_CMusEngSipProfileHandler::ConstructL() |
|
85 { |
|
86 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
87 // It generates the test case table. |
|
88 CEUnitTestSuiteClass::ConstructL(); |
|
89 } |
|
90 |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // From MMusSipProfileUser |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 TBool UT_CMusEngSipProfileHandler::IsRoamingBetweenAPsAllowed() |
|
97 { |
|
98 return iRoamingBetweenAPsAllowed; |
|
99 } |
|
100 |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 void UT_CMusEngSipProfileHandler::SetupL() |
|
107 { |
|
108 iProfileHandler = CMusSipProfileHandler::NewL( *this ); |
|
109 } |
|
110 |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 void UT_CMusEngSipProfileHandler::Teardown() |
|
117 { |
|
118 delete iProfileHandler; |
|
119 iRoamingBetweenAPsAllowed = EFalse; |
|
120 } |
|
121 |
|
122 |
|
123 |
|
124 // TEST CASES |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 void UT_CMusEngSipProfileHandler::UT_CMusEngSipProfileHandler_CreateSipProfileLL() |
|
131 { |
|
132 // SIP profile ID zero |
|
133 iProfileHandler->CreateProfileL( 0 ); |
|
134 EUNIT_ASSERT( iProfileHandler->iSipProfile != NULL ) |
|
135 EUNIT_ASSERT( iProfileHandler->iSipProfile == iProfileHandler->Profile() ) |
|
136 EUNIT_ASSERT( iProfileHandler->iSipProfile->iIsDefaultProfile ) |
|
137 |
|
138 // SIP profile ID non-zero |
|
139 delete iProfileHandler->iSipProfile; |
|
140 iProfileHandler->iSipProfile = NULL; |
|
141 iProfileHandler->CreateProfileL( KSipProfileId ); |
|
142 EUNIT_ASSERT( iProfileHandler->iSipProfile != NULL ) |
|
143 EUNIT_ASSERT( iProfileHandler->iSipProfile == iProfileHandler->Profile() ) |
|
144 EUNIT_ASSERT( !iProfileHandler->iSipProfile->iIsDefaultProfile ) |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 void UT_CMusEngSipProfileHandler::UT_CMusEngSipProfileHandler_ProfileIdL() |
|
152 { |
|
153 // SIP profile does not yet exist |
|
154 EUNIT_ASSERT_EQUALS( 0, iProfileHandler->ProfileId() ) |
|
155 |
|
156 // SIP profile exists |
|
157 iProfileHandler->CreateProfileL( KSipProfileId ); |
|
158 EUNIT_ASSERT_EQUALS( KSipProfileId, iProfileHandler->ProfileId() ) |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 void UT_CMusEngSipProfileHandler::UT_CMusEngSipProfileHandler_AlrEventL() |
|
166 { |
|
167 const TUint32 KSnapId( 1 ); |
|
168 const TUint32 KIapId( 1 ); |
|
169 |
|
170 // Event is other that EIapAvailable |
|
171 iProfileHandler->AlrEvent( |
|
172 MSipProfileAlrObserver::EMigrationCompleted, |
|
173 KSipProfileId, KSnapId, KIapId ); |
|
174 EUNIT_ASSERT( |
|
175 !iProfileHandler->iProfileAlrController->iAllowMigrationCalled ) |
|
176 EUNIT_ASSERT( |
|
177 !iProfileHandler->iProfileAlrController->iDisallowMigrationCalled ) |
|
178 |
|
179 // Event is EIapAvailable, SIP profile does not exist |
|
180 iProfileHandler->AlrEvent( |
|
181 MSipProfileAlrObserver::EIapAvailable, |
|
182 KSipProfileId, KSnapId, KIapId ); |
|
183 if ( !iProfileHandler->iProfileAlrController->iAllowMigrationCalled ) |
|
184 { |
|
185 User::Leave( KErrNoMemory ); |
|
186 } |
|
187 EUNIT_ASSERT( |
|
188 iProfileHandler->iProfileAlrController->iAllowMigrationCalled ) |
|
189 iProfileHandler->iProfileAlrController->iAllowMigrationCalled = EFalse; |
|
190 EUNIT_ASSERT( |
|
191 !iProfileHandler->iProfileAlrController->iDisallowMigrationCalled ) |
|
192 EUNIT_ASSERT_EQUALS( |
|
193 KIapId, iProfileHandler->iProfileAlrController->iLastUsedIap ) |
|
194 iProfileHandler->iProfileAlrController->iLastUsedIap = 0; |
|
195 |
|
196 // Event is EIapAvailable, SIP profile ID does not match |
|
197 iProfileHandler->CreateProfileL( KSipProfileId ); |
|
198 iProfileHandler->AlrEvent( |
|
199 MSipProfileAlrObserver::EIapAvailable, |
|
200 KSipProfileId+1, KSnapId, KIapId ); |
|
201 if ( !iProfileHandler->iProfileAlrController->iAllowMigrationCalled ) |
|
202 { |
|
203 User::Leave( KErrNoMemory ); |
|
204 } |
|
205 EUNIT_ASSERT( |
|
206 iProfileHandler->iProfileAlrController->iAllowMigrationCalled ) |
|
207 iProfileHandler->iProfileAlrController->iAllowMigrationCalled = EFalse; |
|
208 EUNIT_ASSERT( |
|
209 !iProfileHandler->iProfileAlrController->iDisallowMigrationCalled ) |
|
210 EUNIT_ASSERT_EQUALS( |
|
211 KIapId, iProfileHandler->iProfileAlrController->iLastUsedIap ) |
|
212 iProfileHandler->iProfileAlrController->iLastUsedIap = 0; |
|
213 |
|
214 // Event is EIapAvailable, SIP profile ID matches, roaming not allowed |
|
215 iProfileHandler->AlrEvent( |
|
216 MSipProfileAlrObserver::EIapAvailable, |
|
217 KSipProfileId, KSnapId, KIapId ); |
|
218 if ( !iProfileHandler->iProfileAlrController->iDisallowMigrationCalled ) |
|
219 { |
|
220 User::Leave( KErrNoMemory ); |
|
221 } |
|
222 EUNIT_ASSERT( |
|
223 !iProfileHandler->iProfileAlrController->iAllowMigrationCalled ) |
|
224 EUNIT_ASSERT( |
|
225 iProfileHandler->iProfileAlrController->iDisallowMigrationCalled ) |
|
226 iProfileHandler->iProfileAlrController->iDisallowMigrationCalled = EFalse; |
|
227 EUNIT_ASSERT_EQUALS( |
|
228 KIapId, iProfileHandler->iProfileAlrController->iLastUsedIap ) |
|
229 iProfileHandler->iProfileAlrController->iLastUsedIap = 0; |
|
230 |
|
231 // Event is EIapAvailable, SIP profile ID matches, roaming not allowed |
|
232 iRoamingBetweenAPsAllowed = ETrue; |
|
233 iProfileHandler->AlrEvent( |
|
234 MSipProfileAlrObserver::EIapAvailable, |
|
235 KSipProfileId, KSnapId, KIapId ); |
|
236 if ( !iProfileHandler->iProfileAlrController->iAllowMigrationCalled ) |
|
237 { |
|
238 User::Leave( KErrNoMemory ); |
|
239 } |
|
240 EUNIT_ASSERT( |
|
241 iProfileHandler->iProfileAlrController->iAllowMigrationCalled ) |
|
242 iProfileHandler->iProfileAlrController->iAllowMigrationCalled = EFalse; |
|
243 EUNIT_ASSERT( |
|
244 !iProfileHandler->iProfileAlrController->iDisallowMigrationCalled ) |
|
245 EUNIT_ASSERT_EQUALS( |
|
246 KIapId, iProfileHandler->iProfileAlrController->iLastUsedIap ) |
|
247 iProfileHandler->iProfileAlrController->iLastUsedIap = 0; |
|
248 } |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 void UT_CMusEngSipProfileHandler::UT_CMusEngSipProfileHandler_NullTestsL() |
|
255 { |
|
256 // Dummies |
|
257 CSIPTransactionBase transactionBase; |
|
258 CSIPServerTransaction serverTransaction; |
|
259 CSIPDialog dialog; |
|
260 CSIPClientTransaction clientTransaction; |
|
261 CSIPDialogAssocBase dialogAssocBase; |
|
262 CSIPRegistrationBinding registrationBinding; |
|
263 CSIPRefresh refresh; |
|
264 |
|
265 // Tests |
|
266 iProfileHandler->ProfileRegistryEventOccurred( 0, |
|
267 MSIPProfileRegistryObserver::EProfileCreated ); |
|
268 iProfileHandler->ProfileRegistryErrorOccurred( 0, 0 ); |
|
269 iProfileHandler->IncomingRequest( 0, NULL ); |
|
270 iProfileHandler->TimedOut( serverTransaction ); |
|
271 iProfileHandler->IncomingRequest( NULL ); |
|
272 iProfileHandler->IncomingRequest( NULL, dialog ); |
|
273 iProfileHandler->IncomingResponse( clientTransaction ); |
|
274 iProfileHandler->IncomingResponse( clientTransaction, dialogAssocBase ); |
|
275 iProfileHandler->IncomingResponse( clientTransaction, NULL ); |
|
276 iProfileHandler->IncomingResponse( clientTransaction, registrationBinding ); |
|
277 iProfileHandler->ErrorOccured( 0, transactionBase ); |
|
278 iProfileHandler->ErrorOccured( 0, clientTransaction, registrationBinding ); |
|
279 iProfileHandler->ErrorOccured( 0, transactionBase, dialogAssocBase ); |
|
280 iProfileHandler->ErrorOccured( 0, refresh ); |
|
281 iProfileHandler->ErrorOccured( 0, registrationBinding ); |
|
282 iProfileHandler->ErrorOccured( 0, dialogAssocBase ); |
|
283 iProfileHandler->InviteCompleted( clientTransaction ); |
|
284 iProfileHandler->InviteCanceled( serverTransaction ); |
|
285 iProfileHandler->ConnectionStateChanged( CSIPConnection::EInit ); |
|
286 iProfileHandler->AlrError( KErrGeneral, 0, 0, 0 ); |
|
287 } |
|
288 |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 // ----------------------------------------------------------------------------- |
|
292 // |
|
293 void UT_CMusEngSipProfileHandler::UT_CMusEngSipProfileHandler_UserFromProfileLCL() |
|
294 { |
|
295 iProfileHandler->CreateProfileL( KSipProfileId ); |
|
296 CSIPProfile* profile = iProfileHandler->Profile(); |
|
297 delete profile->iArray; |
|
298 profile->iArray = NULL; |
|
299 |
|
300 // no aors -> leave with KErrArgument |
|
301 TRAPD( err, iProfileHandler->UserFromProfileLC() ) |
|
302 EUNIT_ASSERT_EQUALS( KErrArgument, err ) |
|
303 |
|
304 // create aors -> user found |
|
305 _LIT8( KUserUri, "sip:user@domain.com" ); |
|
306 profile->iArray = new ( ELeave ) CDesC8ArrayFlat( 1 ); |
|
307 profile->iArray->AppendL( KUserUri ); |
|
308 |
|
309 CUri8* user = iProfileHandler->UserFromProfileLC(); |
|
310 |
|
311 EUNIT_ASSERT_EQUALS( KUserUri(), user->Uri().UriDes() ) |
|
312 |
|
313 CleanupStack::PopAndDestroy( user ); |
|
314 } |
|
315 |
|
316 // TEST TABLE |
|
317 |
|
318 EUNIT_BEGIN_TEST_TABLE( |
|
319 UT_CMusEngSipProfileHandler, |
|
320 "UT_CMusEngSipProfileHandler", |
|
321 "UNIT" ) |
|
322 |
|
323 EUNIT_TEST( |
|
324 "CreateSipProfileL - test ", |
|
325 "CMusSipProfileHandler", |
|
326 "CreateSipProfileL", |
|
327 "FUNCTIONALITY", |
|
328 SetupL, UT_CMusEngSipProfileHandler_CreateSipProfileLL, Teardown) |
|
329 |
|
330 EUNIT_TEST( |
|
331 "ProfileId - test ", |
|
332 "CMusSipProfileHandler", |
|
333 "ProfileId", |
|
334 "FUNCTIONALITY", |
|
335 SetupL, UT_CMusEngSipProfileHandler_ProfileIdL, Teardown) |
|
336 |
|
337 EUNIT_TEST( |
|
338 "AlrEventL - test ", |
|
339 "CMusEngSipProfileHandler", |
|
340 "AlrEventL", |
|
341 "FUNCTIONALITY", |
|
342 SetupL, UT_CMusEngSipProfileHandler_AlrEventL, Teardown) |
|
343 |
|
344 EUNIT_TEST( |
|
345 "Null tests for NOP functions", |
|
346 "CMusEngSipProfileHandler", |
|
347 "Several NOP functions", |
|
348 "FUNCTIONALITY", |
|
349 SetupL, UT_CMusEngSipProfileHandler_NullTestsL, Teardown) |
|
350 |
|
351 EUNIT_TEST( |
|
352 "UserFromProfileLC - test ", |
|
353 "CMusEngOutSession", |
|
354 "UserFromProfileLC", |
|
355 "FUNCTIONALITY", |
|
356 SetupL, UT_CMusEngSipProfileHandler_UserFromProfileLCL, Teardown) |
|
357 |
|
358 EUNIT_END_TEST_TABLE |
|
359 |
|
360 // END OF FILE |
|
361 |
|
362 |