1 /* |
|
2 * Copyright (c) 2004-2007 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: Unit tests for CMusAvailabilityPluginManager class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "UT_CMusManagerServerCore.h" |
|
20 #include "musunittesting.h" |
|
21 #include "musmanagerservercore.h" |
|
22 #include "musavailabilitypluginmanager.h" |
|
23 #include "musavaavailability.h" |
|
24 #include "musavaavailabilitystub.h" |
|
25 #include "musavainterface.h" |
|
26 #include "cmusavainterfacestub.h" |
|
27 #include "mussessionproperties.h" |
|
28 #include "mustesthelp.h" |
|
29 #include <e32property.h> |
|
30 #include <apgtask.h> |
|
31 #include <digia/eunit/eunitmacros.h> |
|
32 |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 |
|
37 UT_CMusManagerServerCore* UT_CMusManagerServerCore::NewL() |
|
38 { |
|
39 UT_CMusManagerServerCore* self = UT_CMusManagerServerCore::NewLC(); |
|
40 CleanupStack::Pop(); |
|
41 return self; |
|
42 } |
|
43 |
|
44 |
|
45 UT_CMusManagerServerCore* UT_CMusManagerServerCore::NewLC() |
|
46 { |
|
47 UT_CMusManagerServerCore* self = new( ELeave ) UT_CMusManagerServerCore(); |
|
48 CleanupStack::PushL( self ); |
|
49 self->ConstructL(); |
|
50 return self; |
|
51 } |
|
52 |
|
53 |
|
54 UT_CMusManagerServerCore::~UT_CMusManagerServerCore() |
|
55 { |
|
56 } |
|
57 |
|
58 |
|
59 UT_CMusManagerServerCore::UT_CMusManagerServerCore() |
|
60 { |
|
61 } |
|
62 |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
66 // It generates the test case table. |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 void UT_CMusManagerServerCore::ConstructL() |
|
70 { |
|
71 CEUnitTestSuiteClass::ConstructL(); |
|
72 } |
|
73 |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // From MMusManagerServerCoreObserver. |
|
77 // Stops server. |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 void UT_CMusManagerServerCore::StopServer() |
|
81 { |
|
82 iStopServerCalled = ETrue; |
|
83 } |
|
84 |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // From MMusManagerServerCoreObserver. |
|
88 // Returns count of sessions. |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 TUint UT_CMusManagerServerCore::SessionCount() |
|
92 { |
|
93 return iSessionCount; |
|
94 } |
|
95 |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // From MMusMonitorAvailabilityObserver. |
|
99 // Informs of a change in multimediasharing availability. |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 void UT_CMusManagerServerCore::AvailabilityChangedL( |
|
103 MultimediaSharing::TMusAvailabilityStatus /*aStatus*/ ) |
|
104 { |
|
105 iAvailabilityChangedLCalled = ETrue; |
|
106 } |
|
107 |
|
108 void UT_CMusManagerServerCore::RequestComplete() |
|
109 { |
|
110 |
|
111 } |
|
112 // --------------------------------------------------------------------------- |
|
113 // Setups the test by instantiating tested class. |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 void UT_CMusManagerServerCore::SetupL() |
|
117 { |
|
118 iCore = CMusManagerServerCore::NewL( *this ); |
|
119 iStopServerCalled = EFalse; |
|
120 iAvailabilityChangedLCalled = EFalse; |
|
121 iSessionCount = 0; |
|
122 TApaTask::iApaTaskCalledFunction = TApaTask::ENone; |
|
123 } |
|
124 |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // Finalizes test by deleting instance of tested class. |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 void UT_CMusManagerServerCore::Teardown() |
|
131 { |
|
132 delete iCore; |
|
133 PropertyHelper::Close(); |
|
134 } |
|
135 |
|
136 |
|
137 // ======== TEST METHODS ======== |
|
138 |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // Asserts that instance creation is successful. |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 void UT_CMusManagerServerCore::UT_CMusManagerServerCore_NewLL() |
|
145 { |
|
146 EUNIT_ASSERT( iCore ); |
|
147 } |
|
148 |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // Asserts that instance creation is successful. |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 void UT_CMusManagerServerCore::UT_CMusManagerServerCore_NewLCL() |
|
155 { |
|
156 delete iCore; |
|
157 iCore = NULL; |
|
158 iCore = CMusManagerServerCore::NewLC( *this ); |
|
159 EUNIT_ASSERT( iCore ); |
|
160 CleanupStack::Pop( iCore ); |
|
161 } |
|
162 |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // Availability query should return MMusAvaObserver::EMusAvaStatusNotAvailable |
|
166 // when videosharing is not yet available. |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 void UT_CMusManagerServerCore::UT_CMusManagerServerCore_AvailabilityQueryLL() |
|
170 { |
|
171 EUNIT_ASSERT( iCore->AvailabilityQueryL() |
|
172 == MultimediaSharing::EMultimediaSharingNotAvailable ); |
|
173 } |
|
174 |
|
175 |
|
176 // --------------------------------------------------------------------------- |
|
177 // Dummy test to increase execution coverage. |
|
178 // --------------------------------------------------------------------------- |
|
179 // |
|
180 void UT_CMusManagerServerCore:: |
|
181 UT_CMusManagerServerCore_InvestigateAvailabilityLL() |
|
182 { |
|
183 iCore->InvestigateAvailabilityL(); |
|
184 } |
|
185 |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // Asserts that invitation with inappropriate UID should leave. |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 void UT_CMusManagerServerCore::UT_CMusManagerServerCore_InvitationReceivedLL() |
|
192 { |
|
193 TUid uid = { 0x10101010 }; // Not a valid UID in musmanager.h |
|
194 // since used UID is not in appropriate, this should leave |
|
195 EUNIT_ASSERT_SPECIFIC_LEAVE( |
|
196 iCore->InvitationReceivedL( uid ), KErrNotReady ); |
|
197 |
|
198 uid.iUid = 0x1028238D; // ESipInviteNotDesired from musmanager.h |
|
199 EUNIT_ASSERT_NO_LEAVE( iCore->InvitationReceivedL( uid ) ); |
|
200 |
|
201 uid.iUid = 0x10282391; // ESipInviteDesired from musmanager.h |
|
202 EUNIT_ASSERT_SPECIFIC_LEAVE( |
|
203 iCore->InvitationReceivedL( uid ), KErrNotReady ); |
|
204 } |
|
205 |
|
206 |
|
207 // --------------------------------------------------------------------------- |
|
208 // Dummy test to increase execution coverage. |
|
209 // --------------------------------------------------------------------------- |
|
210 // |
|
211 void UT_CMusManagerServerCore::UT_CMusManagerServerCore_OptionsReceivedLL() |
|
212 { |
|
213 TUid uid = { 0x10101010 }; |
|
214 iCore->OptionsReceivedL( uid ); |
|
215 EUNIT_ASSERT( iCore->iPluginManager->iPluginStarted ); |
|
216 } |
|
217 |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // Asserts that tested method does not leave. In certain case it could leave |
|
221 // with KErrPermissionDenied, but with this this test, used capabilities |
|
222 // and used stubs, tested method shouldn't leave. Checks also that |
|
223 // TApaTask function TaskExists is called. |
|
224 // --------------------------------------------------------------------------- |
|
225 // |
|
226 void UT_CMusManagerServerCore:: |
|
227 UT_CMusManagerServerCore_StartMultimediaSharingLL() |
|
228 { |
|
229 CMusAvaInterface* interface = iCore->iPluginManager->iPlugin; |
|
230 CMusAvaInterface2* interface2 = static_cast<CMusAvaInterface2*>( interface ); |
|
231 CMusAvaAvailabilityStub* abilityStub = |
|
232 static_cast<CMusAvaAvailabilityStub*>( interface2->iAvailabilities[0] ); |
|
233 // ----------------------------------------------------------------------- |
|
234 // Dummy test that shouldn't leave -> |
|
235 // ----------------------------------------------------------------------- |
|
236 MUS_EUNIT_ASSERT_NO_LEAVE( |
|
237 iCore->StartMultimediaSharingL( MultimediaSharing::EMusLiveVideo ) ); |
|
238 // <- Dummy test that shouldn't leave |
|
239 |
|
240 // ----------------------------------------------------------------------- |
|
241 // Test for "if( !iApplicationManager->ApplicationRunning() && |
|
242 // iPluginManager->ApplicationAllowed() ) branch -> |
|
243 // ----------------------------------------------------------------------- |
|
244 |
|
245 // CMusApplicationManager::ApplicationRunning = EFalse |
|
246 TApaTask::iApplicationExist = EFalse; |
|
247 |
|
248 // CMusAvailabilityPluginManager::ApplicationAllowed = ETrue |
|
249 abilityStub->iNameStub = MMusAvaObserver::EMusAvaNameRegistration; |
|
250 abilityStub->iStatusStub = MMusAvaObserver::EMusAvaStatusAvailable; |
|
251 interface2->iCurrentAvailability =MMusAvaObserver::EMusAvaOptionHandler; |
|
252 |
|
253 PropertyHelper::SetErrorCode(KErrGeneral); |
|
254 |
|
255 // Should leave in WriteSessionPropertiesL |
|
256 MUS_EUNIT_ASSERT_SPECIFIC_LEAVE( |
|
257 iCore->StartMultimediaSharingL( MultimediaSharing::EMusLiveVideo ), |
|
258 KErrGeneral ); |
|
259 |
|
260 PropertyHelper::SetErrorCode(KErrNone); |
|
261 |
|
262 // Should go all the way to StartApplicationL |
|
263 MUS_EUNIT_ASSERT_NO_LEAVE( |
|
264 iCore->StartMultimediaSharingL( MultimediaSharing::EMusLiveVideo ) ); |
|
265 EUNIT_ASSERT( PropertyHelper::GetCalledFunction() == RProperty::EDefine ); |
|
266 EUNIT_ASSERT( TApaTask::iApaTaskCalledFunction == TApaTask::EExists ); |
|
267 |
|
268 // <- Test for "if( !iApplicationManager->ApplicationRunning() && |
|
269 // iPluginManager->ApplicationAllowed() ) branch |
|
270 |
|
271 // ----------------------------------------------------------------------- |
|
272 // Test for else branch -> |
|
273 // ----------------------------------------------------------------------- |
|
274 |
|
275 // CMusAvailabilityPluginManager::ApplicationAllowed = EFalse |
|
276 abilityStub->iNameStub = MMusAvaObserver::EMusAvaNameRegistration; |
|
277 abilityStub->iStatusStub = MMusAvaObserver::EMusAvaStatusNotExecuted; |
|
278 interface2->iCurrentAvailability =MMusAvaObserver::EMusAvaNameRegistration; |
|
279 |
|
280 |
|
281 // CMusApplicationManager::ApplicationRunning = EFalse |
|
282 TApaTask::iApplicationExist = EFalse; |
|
283 MUS_EUNIT_ASSERT_NO_LEAVE( |
|
284 iCore->StartMultimediaSharingL( MultimediaSharing::EMusLiveVideo ) ); |
|
285 EUNIT_ASSERT( TApaTask::iApaTaskCalledFunction == TApaTask::EExists ); |
|
286 |
|
287 // <- Test for else branch |
|
288 } |
|
289 |
|
290 |
|
291 // --------------------------------------------------------------------------- |
|
292 // Asserts that tested method checks if task exists and calls |
|
293 // TApaTask::KillTask if task exists. |
|
294 // --------------------------------------------------------------------------- |
|
295 // |
|
296 void UT_CMusManagerServerCore:: |
|
297 UT_CMusManagerServerCore_StopMultimediaSharingLL() |
|
298 { |
|
299 TApaTask::iApplicationExist = EFalse; |
|
300 iCore->StopMultimediaSharingL(); |
|
301 EUNIT_ASSERT( TApaTask::iApaTaskCalledFunction == TApaTask::EExists ) |
|
302 |
|
303 TApaTask::iApplicationExist = ETrue; |
|
304 iCore->StopMultimediaSharingL(); |
|
305 TInt availability = MultimediaSharing::EMultimediaSharingAvailable; |
|
306 TUint key(NMusSessionApi::KStatus); |
|
307 RProperty::Get( key,availability); |
|
308 EUNIT_ASSERT_EQUALS( PropertyHelper::GetCalledFunction(), RProperty::EDefine ) |
|
309 EUNIT_ASSERT_EQUALS( availability, |
|
310 MultimediaSharing::EMultimediaSharingNotAvailable ) |
|
311 } |
|
312 |
|
313 |
|
314 // --------------------------------------------------------------------------- |
|
315 // Asserts that observer method MMusManagerServerCoreObserver::StopServer is |
|
316 // called. |
|
317 // --------------------------------------------------------------------------- |
|
318 // |
|
319 void UT_CMusManagerServerCore::UT_CMusManagerServerCore_EventNoSessionsL() |
|
320 { |
|
321 iCore->EventNoSessions(); |
|
322 EUNIT_ASSERT( iStopServerCalled ); |
|
323 } |
|
324 |
|
325 |
|
326 // --------------------------------------------------------------------------- |
|
327 // Asserts that MMusManagerServerCoreObserver::StopServer is called when it |
|
328 // should. |
|
329 // --------------------------------------------------------------------------- |
|
330 // |
|
331 void UT_CMusManagerServerCore::UT_CMusManagerServerCore_PluginStoppedL() |
|
332 { |
|
333 // Should not call iStopServer when sessions still exists. |
|
334 iSessionCount = 1; |
|
335 iCore->PluginStopped(); |
|
336 EUNIT_ASSERT( !iStopServerCalled ); |
|
337 |
|
338 // Should call iStopServer when sessioncount = 0. |
|
339 iSessionCount = 0; |
|
340 iCore->PluginStopped(); |
|
341 EUNIT_ASSERT( iStopServerCalled ); |
|
342 } |
|
343 |
|
344 |
|
345 // --------------------------------------------------------------------------- |
|
346 // Asserts that KErrNone should be returned. |
|
347 // --------------------------------------------------------------------------- |
|
348 // |
|
349 void UT_CMusManagerServerCore:: |
|
350 UT_CMusManagerServerCore_AvailabilityChangedLL() |
|
351 { |
|
352 MUS_EUNIT_ASSERT_NO_LEAVE( iCore->AvailabilityChangedL( |
|
353 (MultimediaSharing::TMusAvailabilityStatus) KErrNone ) ); |
|
354 |
|
355 EUNIT_ASSERT( iCore->iAvailabilityMonitors.Count() == 0 ); |
|
356 |
|
357 } |
|
358 |
|
359 |
|
360 // --------------------------------------------------------------------------- |
|
361 // Asserts that called method removes *this* monitor. |
|
362 // --------------------------------------------------------------------------- |
|
363 // |
|
364 void UT_CMusManagerServerCore::UT_CMusManagerServerCore_RegisterObserverL() |
|
365 { |
|
366 TInt monitors = iCore->iAvailabilityMonitors.Count(); |
|
367 iCore->RegisterObserverL( this ); |
|
368 EUNIT_ASSERT( iCore->iAvailabilityMonitors.Count() == monitors + 1 ); |
|
369 iCore->RemoveObserver( this ); |
|
370 EUNIT_ASSERT( iCore->iAvailabilityMonitors.Count() == monitors ); |
|
371 } |
|
372 |
|
373 |
|
374 // ======== EUNIT TEST TABLE ======== |
|
375 |
|
376 |
|
377 EUNIT_BEGIN_TEST_TABLE( |
|
378 UT_CMusManagerServerCore, |
|
379 "CMusManagerServerCore", |
|
380 "UNIT" ) |
|
381 |
|
382 EUNIT_TEST( |
|
383 "NewL - test ", |
|
384 "CMusManagerServerCore", |
|
385 "NewL", |
|
386 "FUNCTIONALITY", |
|
387 SetupL, UT_CMusManagerServerCore_NewLL, Teardown) |
|
388 |
|
389 EUNIT_TEST( |
|
390 "NewLC - test ", |
|
391 "CMusManagerServerCore", |
|
392 "NewLC", |
|
393 "FUNCTIONALITY", |
|
394 SetupL, UT_CMusManagerServerCore_NewLCL, Teardown) |
|
395 |
|
396 |
|
397 EUNIT_TEST( |
|
398 "RegisterObserver - test ", |
|
399 "CMusManagerServerCore", |
|
400 "RegisterObserver", |
|
401 "FUNCTIONALITY", |
|
402 SetupL, UT_CMusManagerServerCore_RegisterObserverL, Teardown) |
|
403 |
|
404 EUNIT_TEST( |
|
405 "AvailabilityQueryL - test ", |
|
406 "CMusManagerServerCore", |
|
407 "AvailabilityQueryL", |
|
408 "FUNCTIONALITY", |
|
409 SetupL, UT_CMusManagerServerCore_AvailabilityQueryLL, Teardown) |
|
410 |
|
411 EUNIT_TEST( |
|
412 "InvestigateAvailabilityL - test ", |
|
413 "CMusManagerServerCore", |
|
414 "InvestigateAvailabilityL", |
|
415 "FUNCTIONALITY", |
|
416 SetupL, UT_CMusManagerServerCore_InvestigateAvailabilityLL, Teardown) |
|
417 |
|
418 EUNIT_TEST( |
|
419 "InvitationReceivedL - test ", |
|
420 "CMusManagerServerCore", |
|
421 "InvitationReceivedL", |
|
422 "FUNCTIONALITY", |
|
423 SetupL, UT_CMusManagerServerCore_InvitationReceivedLL, Teardown) |
|
424 |
|
425 EUNIT_TEST( |
|
426 "OptionsReceivedL - test ", |
|
427 "CMusManagerServerCore", |
|
428 "OptionsReceivedL", |
|
429 "FUNCTIONALITY", |
|
430 SetupL, UT_CMusManagerServerCore_OptionsReceivedLL, Teardown) |
|
431 |
|
432 EUNIT_TEST( |
|
433 "StartMultimediaSharingL - test ", |
|
434 "CMusManagerServerCore", |
|
435 "StartMultimediaSharingL", |
|
436 "FUNCTIONALITY", |
|
437 SetupL, UT_CMusManagerServerCore_StartMultimediaSharingLL, Teardown) |
|
438 |
|
439 EUNIT_TEST( |
|
440 "StopMultimediaSharingL - test ", |
|
441 "CMusManagerServerCore", |
|
442 "StopMultimediaSharingL", |
|
443 "FUNCTIONALITY", |
|
444 SetupL, UT_CMusManagerServerCore_StopMultimediaSharingLL, Teardown) |
|
445 |
|
446 EUNIT_TEST( |
|
447 "EventNoSessions - test ", |
|
448 "CMusManagerServerCore", |
|
449 "EventNoSessions", |
|
450 "FUNCTIONALITY", |
|
451 SetupL, UT_CMusManagerServerCore_EventNoSessionsL, Teardown) |
|
452 |
|
453 EUNIT_TEST( |
|
454 "PluginStopped - test ", |
|
455 "CMusManagerServerCore", |
|
456 "PluginStopped", |
|
457 "FUNCTIONALITY", |
|
458 SetupL, UT_CMusManagerServerCore_PluginStoppedL, Teardown) |
|
459 |
|
460 EUNIT_TEST( |
|
461 "AvailabilityChangedL - test ", |
|
462 "CMusManagerServerCore", |
|
463 "AvailabilityChangedL", |
|
464 "FUNCTIONALITY", |
|
465 SetupL, UT_CMusManagerServerCore_AvailabilityChangedLL, Teardown) |
|
466 |
|
467 |
|
468 EUNIT_END_TEST_TABLE |
|