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