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 "telephonyaudiorouting.h" |
|
21 #include "ut_musengsession.h" |
|
22 #include "musengstubs.h" |
|
23 #include "musengtestdefs.h" |
|
24 |
|
25 #include "musenglivesession.h" |
|
26 #include "musengtelephoneutils.h" |
|
27 #include "musengmceutils.h" |
|
28 |
|
29 // SYSTEM INCLUDES |
|
30 #include <digia/eunit/eunitmacros.h> |
|
31 #include <centralrepository.h> |
|
32 #include <mcedisplaysink.h> |
|
33 #include <e32property.h> |
|
34 #include <telephonydomainpskeys.h> |
|
35 |
|
36 |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 UT_CMusEngSession* UT_CMusEngSession::NewL() |
|
43 { |
|
44 UT_CMusEngSession* self = UT_CMusEngSession::NewLC(); |
|
45 CleanupStack::Pop( self ); |
|
46 return self; |
|
47 } |
|
48 |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 UT_CMusEngSession* UT_CMusEngSession::NewLC() |
|
55 { |
|
56 UT_CMusEngSession* self = new( ELeave ) UT_CMusEngSession(); |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL(); |
|
59 return self; |
|
60 } |
|
61 |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 UT_CMusEngSession::~UT_CMusEngSession() |
|
68 { |
|
69 // NOP |
|
70 } |
|
71 |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // Default constructor |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 UT_CMusEngSession::UT_CMusEngSession() |
|
78 :iLiveSession( NULL ), |
|
79 iObserver( NULL ) |
|
80 { |
|
81 // NOP |
|
82 } |
|
83 |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // Second phase construct |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 void UT_CMusEngSession::ConstructL() |
|
90 { |
|
91 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
92 // It generates the test case table. |
|
93 CEUnitTestSuiteClass::ConstructL(); |
|
94 } |
|
95 |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 void UT_CMusEngSession::SetupL() |
|
102 { |
|
103 iObserver = new( ELeave ) CMusEngObserverStub; |
|
104 iLiveSession = CMusEngLiveSession::NewL( KNullDesC(), |
|
105 TRect(0,0, 100,100), |
|
106 *iObserver, |
|
107 *iObserver, |
|
108 *iObserver ); |
|
109 } |
|
110 |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 void UT_CMusEngSession::Teardown() |
|
117 { |
|
118 delete iLiveSession; |
|
119 delete iObserver; |
|
120 } |
|
121 |
|
122 |
|
123 |
|
124 // TEST CASES |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 void UT_CMusEngSession::UT_RectL() |
|
135 { |
|
136 TRect rect = iLiveSession->Rect(); |
|
137 |
|
138 // Initial values |
|
139 EUNIT_ASSERT( rect.iTl.iX == 0 ); |
|
140 EUNIT_ASSERT( rect.iTl.iY == 0 ); |
|
141 EUNIT_ASSERT( rect.iBr.iX == 100 ); |
|
142 EUNIT_ASSERT( rect.iBr.iY == 100 ); |
|
143 |
|
144 iLiveSession->iRect.iTl.iX = 100; |
|
145 iLiveSession->iRect.iTl.iY = 200; |
|
146 iLiveSession->iRect.iBr.iX = 300; |
|
147 iLiveSession->iRect.iBr.iY = 400; |
|
148 |
|
149 rect = iLiveSession->Rect(); |
|
150 |
|
151 EUNIT_ASSERT( rect.iTl.iX == 100 ); |
|
152 EUNIT_ASSERT( rect.iTl.iY == 200 ); |
|
153 EUNIT_ASSERT( rect.iBr.iX == 300 ); |
|
154 EUNIT_ASSERT( rect.iBr.iY == 400 ); |
|
155 } |
|
156 |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void UT_CMusEngSession::UT_SetRectLL() |
|
163 { |
|
164 TRect rect; |
|
165 |
|
166 rect.iTl.iX = 100; |
|
167 rect.iTl.iY = 200; |
|
168 rect.iBr.iX = 300; |
|
169 rect.iBr.iY = 400; |
|
170 |
|
171 iLiveSession->SetRectL( rect ); |
|
172 |
|
173 EUNIT_ASSERT( iLiveSession->iRect.iTl.iX == 100 ); |
|
174 EUNIT_ASSERT( iLiveSession->iRect.iTl.iY == 200 ); |
|
175 EUNIT_ASSERT( iLiveSession->iRect.iBr.iX == 300 ); |
|
176 EUNIT_ASSERT( iLiveSession->iRect.iBr.iY == 400 ); |
|
177 |
|
178 ESTABLISH_OUT_SESSION( iLiveSession ); |
|
179 |
|
180 CMceDisplaySink* display = |
|
181 MusEngMceUtils::GetDisplayL( *( iLiveSession->iSession ) ); |
|
182 |
|
183 TRect displayRect = display->DisplayRectL(); |
|
184 |
|
185 EUNIT_ASSERT( displayRect.iTl.iX == 100 ); |
|
186 EUNIT_ASSERT( displayRect.iTl.iY == 200 ); |
|
187 EUNIT_ASSERT( displayRect.iBr.iX == 300 ); |
|
188 EUNIT_ASSERT( displayRect.iBr.iY == 400 ); |
|
189 } |
|
190 |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 void UT_CMusEngSession::UT_AudioRoutingCanBeChangedL() |
|
197 { |
|
198 iLiveSession->iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = |
|
199 CTelephonyAudioRouting::ELoudspeaker; |
|
200 EUNIT_ASSERT( iLiveSession->AudioRoutingCanBeChanged() ); |
|
201 |
|
202 iLiveSession->iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = |
|
203 CTelephonyAudioRouting::EWiredAudioAccessory; |
|
204 EUNIT_ASSERT( !iLiveSession->AudioRoutingCanBeChanged() ); |
|
205 } |
|
206 |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 void UT_CMusEngSession::UT_EnableLoudspeakerLL() |
|
213 { |
|
214 // Almost dummy case is enough, because IsLoudSpeakerEnabled forwards |
|
215 // requests to CMusEngTelephonyUtils and is tested there. So test only |
|
216 // fail handling |
|
217 iLiveSession->EnableLoudspeakerL( EFalse, EFalse ); |
|
218 |
|
219 CMusEngTelephoneUtils* telephone = iLiveSession->iTelephoneUtils; |
|
220 |
|
221 EUNIT_ASSERT( telephone->iTelephonyAudioRouting->iShowNoteMode == EFalse ); |
|
222 EUNIT_ASSERT( telephone->iTelephonyAudioRouting->iCurrentOutput != |
|
223 CTelephonyAudioRouting::ELoudspeaker ); |
|
224 |
|
225 telephone->iTelephonyAudioRouting->iForceFailWithCode = KErrNotSupported; |
|
226 |
|
227 //Must fail in HW, but not in emulator |
|
228 TRAPD( error, iLiveSession->EnableLoudspeakerL( ETrue, ETrue ) ); |
|
229 MUS_TEST_FORWARD_ALLOC_FAILURE( error ); |
|
230 |
|
231 #if (!defined (__WINS__) && !defined(__WINSCW__)) |
|
232 EUNIT_ASSERT( error == KErrNotSupported ); |
|
233 #else |
|
234 EUNIT_ASSERT( error == KErrNone ); |
|
235 #endif |
|
236 |
|
237 EUNIT_ASSERT( telephone->iTelephonyAudioRouting->iCurrentOutput != |
|
238 CTelephonyAudioRouting::ELoudspeaker ); |
|
239 |
|
240 telephone->iTelephonyAudioRouting->iForceFailWithCode = KErrGeneral; |
|
241 |
|
242 // Must fail in all cases |
|
243 TRAP( error, iLiveSession->EnableLoudspeakerL( EFalse, ETrue ) ); |
|
244 MUS_TEST_FORWARD_ALLOC_FAILURE( error ); |
|
245 EUNIT_ASSERT( error == KErrGeneral ); |
|
246 |
|
247 EUNIT_ASSERT( telephone->iTelephonyAudioRouting->iCurrentOutput != |
|
248 CTelephonyAudioRouting::ELoudspeaker ); |
|
249 |
|
250 |
|
251 } |
|
252 |
|
253 |
|
254 // ----------------------------------------------------------------------------- |
|
255 // |
|
256 // ----------------------------------------------------------------------------- |
|
257 // |
|
258 void UT_CMusEngSession::UT_IsLoudSpeakerEnabledL() |
|
259 { |
|
260 // Dummy case is enough, because IsLoudSpeakerEnabled forwards requests |
|
261 // to CMusEngTelephonyUtils and is tested there. |
|
262 |
|
263 // By default loudspeaker is not enabled. |
|
264 EUNIT_ASSERT( !iLiveSession->IsLoudSpeakerEnabled() ); |
|
265 } |
|
266 |
|
267 |
|
268 // ----------------------------------------------------------------------------- |
|
269 // |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 void UT_CMusEngSession::UT_VolumeLL() |
|
273 { |
|
274 // Dummy case is enough, because VolumeL forwards requests |
|
275 // to CMusEngTelephonyUtils and is tested there. |
|
276 |
|
277 iLiveSession->IsLoudSpeakerEnabled(); |
|
278 } |
|
279 |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 void UT_CMusEngSession::UT_MuteMicLL() |
|
286 { |
|
287 // Cannot test since EUnit notices some error leak if |
|
288 // the state of the mute is actually changed. Still, from MusEngine |
|
289 // point of view everything is done identically despite the fact if |
|
290 // real state changes or not. => Problem is in EUnit or leak happens |
|
291 // elsewhere. |
|
292 } |
|
293 |
|
294 |
|
295 // ----------------------------------------------------------------------------- |
|
296 // Almost a dummy test since we cannot write |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 void UT_CMusEngSession::UT_IsMicMutedLL() |
|
300 { |
|
301 // Ignore error (KErrAlreadyExists etc), just make sure this property exists |
|
302 RProperty::Define( KPSUidTelMicrophoneMuteStatus, |
|
303 KTelMicrophoneMuteState, |
|
304 RProperty::EInt, |
|
305 0 ); |
|
306 |
|
307 User::LeaveIfError( RProperty::Set( KPSUidTelMicrophoneMuteStatus, |
|
308 KTelMicrophoneMuteState, |
|
309 EPSTelMicMuteStateUninitialized ) ); |
|
310 |
|
311 EUNIT_ASSERT( !iLiveSession->IsMicMutedL() ) |
|
312 |
|
313 User::LeaveIfError( RProperty::Set( KPSUidTelMicrophoneMuteStatus, |
|
314 KTelMicrophoneMuteState, |
|
315 EPSTelMicMuteOn ) ); |
|
316 |
|
317 EUNIT_ASSERT( iLiveSession->IsMicMutedL() ) |
|
318 |
|
319 User::LeaveIfError( RProperty::Set( KPSUidTelMicrophoneMuteStatus, |
|
320 KTelMicrophoneMuteState, |
|
321 EPSTelMicMuteOff ) ); |
|
322 |
|
323 EUNIT_ASSERT( !iLiveSession->IsMicMutedL() ) |
|
324 } |
|
325 |
|
326 |
|
327 // ----------------------------------------------------------------------------- |
|
328 // |
|
329 // ----------------------------------------------------------------------------- |
|
330 // |
|
331 void UT_CMusEngSession::UT_SetAudioRoutingObserverL() |
|
332 { |
|
333 EUNIT_ASSERT( !iLiveSession->iTelephoneUtils->iAudioRoutingObserver ) |
|
334 |
|
335 iLiveSession->SetAudioRoutingObserver( iObserver ); |
|
336 |
|
337 EUNIT_ASSERT_EQUALS( iLiveSession->iTelephoneUtils->iAudioRoutingObserver, |
|
338 iObserver ) |
|
339 } |
|
340 |
|
341 |
|
342 // ----------------------------------------------------------------------------- |
|
343 // |
|
344 // ----------------------------------------------------------------------------- |
|
345 // |
|
346 void UT_CMusEngSession::UT_VolumeUpLL() |
|
347 { |
|
348 CMusEngTelephoneUtils* telephone = iLiveSession->iTelephoneUtils; |
|
349 |
|
350 // Next ones must leave if runs out of memory, so that test |
|
351 // does not fail when executed with alloc fail simulation |
|
352 User::LeaveIfError( telephone->iRepository->Set( |
|
353 KTelIncallEarVolume, |
|
354 KTelephonyVolumeDefaultValue ) ); |
|
355 User::LeaveIfError( telephone->iRepository->Set( |
|
356 KTelIncallLoudspeakerVolume, |
|
357 KTelephonyVolumeDefaultValue ) ); |
|
358 |
|
359 |
|
360 TInt earVolume = 0; |
|
361 TInt speakerVolume = 0; |
|
362 |
|
363 iLiveSession->CMusEngSession::VolumeUpL(); |
|
364 |
|
365 telephone->iRepository->Get( KTelIncallEarVolume, |
|
366 earVolume ); |
|
367 telephone->iRepository->Get( KTelIncallLoudspeakerVolume, |
|
368 speakerVolume ); |
|
369 |
|
370 EUNIT_ASSERT( earVolume == KTelephonyVolumeDefaultValue + 1 ); |
|
371 EUNIT_ASSERT( speakerVolume == KTelephonyVolumeDefaultValue ); |
|
372 } |
|
373 |
|
374 |
|
375 // ----------------------------------------------------------------------------- |
|
376 // |
|
377 // ----------------------------------------------------------------------------- |
|
378 // |
|
379 void UT_CMusEngSession::UT_VolumeDownLL() |
|
380 { |
|
381 CMusEngTelephoneUtils* telephone = iLiveSession->iTelephoneUtils; |
|
382 |
|
383 // Next ones must leave if runs out of memory, so that test |
|
384 // does not fail when executed with alloc fail simulation |
|
385 User::LeaveIfError( telephone->iRepository->Set( |
|
386 KTelIncallEarVolume, |
|
387 KTelephonyVolumeDefaultValue ) ); |
|
388 User::LeaveIfError( telephone->iRepository->Set( |
|
389 KTelIncallLoudspeakerVolume, |
|
390 KTelephonyVolumeDefaultValue ) ); |
|
391 |
|
392 |
|
393 TInt earVolume = 0; |
|
394 TInt speakerVolume = 0; |
|
395 |
|
396 iLiveSession->CMusEngSession::VolumeDownL(); |
|
397 |
|
398 telephone->iRepository->Get( KTelIncallEarVolume, |
|
399 earVolume ); |
|
400 telephone->iRepository->Get( KTelIncallLoudspeakerVolume, |
|
401 speakerVolume ); |
|
402 |
|
403 EUNIT_ASSERT( earVolume == KTelephonyVolumeDefaultValue - 1 ); |
|
404 EUNIT_ASSERT( speakerVolume == KTelephonyVolumeDefaultValue ); |
|
405 } |
|
406 |
|
407 |
|
408 // ----------------------------------------------------------------------------- |
|
409 // |
|
410 // ----------------------------------------------------------------------------- |
|
411 // |
|
412 void UT_CMusEngSession::UT_SetVolumeLL() |
|
413 { |
|
414 CMusEngTelephoneUtils* telephone = iLiveSession->iTelephoneUtils; |
|
415 |
|
416 // Next ones must leave if runs out of memory, so that test |
|
417 // does not fail when executed with alloc fail simulation |
|
418 User::LeaveIfError( telephone->iRepository->Set( |
|
419 KTelIncallEarVolume, |
|
420 KTelephonyVolumeDefaultValue ) ); |
|
421 User::LeaveIfError( telephone->iRepository->Set( |
|
422 KTelIncallLoudspeakerVolume, |
|
423 KTelephonyVolumeDefaultValue ) ); |
|
424 |
|
425 |
|
426 TInt earVolume = 0; |
|
427 TInt speakerVolume = 0; |
|
428 TInt newVolume = KTelephonyVolumeDefaultValue + 1; |
|
429 |
|
430 iLiveSession->CMusEngSession::SetVolumeL( newVolume ); |
|
431 |
|
432 telephone->iRepository->Get( KTelIncallEarVolume, |
|
433 earVolume ); |
|
434 telephone->iRepository->Get( KTelIncallLoudspeakerVolume, |
|
435 speakerVolume ); |
|
436 |
|
437 EUNIT_ASSERT( earVolume == newVolume ); |
|
438 EUNIT_ASSERT( speakerVolume == KTelephonyVolumeDefaultValue ); |
|
439 } |
|
440 |
|
441 |
|
442 // TEST TABLE |
|
443 |
|
444 EUNIT_BEGIN_TEST_TABLE( |
|
445 UT_CMusEngSession, |
|
446 "UT_CMusEngSesssion", |
|
447 "UNIT" ) |
|
448 |
|
449 EUNIT_TEST( |
|
450 "Rect - test ", |
|
451 "CMusEngSession", |
|
452 "Rect", |
|
453 "FUNCTIONALITY", |
|
454 SetupL, UT_RectL, Teardown) |
|
455 |
|
456 EUNIT_TEST( |
|
457 "SetRectL - test ", |
|
458 "CMusEngSession", |
|
459 "SetRectL", |
|
460 "FUNCTIONALITY", |
|
461 SetupL, UT_SetRectLL, Teardown) |
|
462 |
|
463 EUNIT_TEST( |
|
464 "AudioRoutingCanBeChanged - test ", |
|
465 "CMusEngSession", |
|
466 "AudioRoutingCanBeChanged", |
|
467 "FUNCTIONALITY", |
|
468 SetupL, UT_AudioRoutingCanBeChangedL, Teardown) |
|
469 |
|
470 EUNIT_TEST( |
|
471 "EnableLoudspeakerL - test ", |
|
472 "CMusEngSession", |
|
473 "EnableLoudspeakerL", |
|
474 "FUNCTIONALITY", |
|
475 SetupL, UT_EnableLoudspeakerLL, Teardown) |
|
476 |
|
477 EUNIT_TEST( |
|
478 "IsLoudSpeakerEnabled - test ", |
|
479 "CMusEngSession", |
|
480 "IsLoudSpeakerEnabled", |
|
481 "FUNCTIONALITY", |
|
482 SetupL, UT_IsLoudSpeakerEnabledL, Teardown) |
|
483 |
|
484 EUNIT_TEST( |
|
485 "VolumeL - test ", |
|
486 "CMusEngSession", |
|
487 "VolumeL", |
|
488 "FUNCTIONALITY", |
|
489 SetupL, UT_VolumeLL, Teardown) |
|
490 |
|
491 EUNIT_TEST( |
|
492 "MuteMicL - test ", |
|
493 "CMusEngSession", |
|
494 "MuteMicL", |
|
495 "FUNCTIONALITY", |
|
496 SetupL, UT_MuteMicLL, Teardown) |
|
497 |
|
498 EUNIT_TEST( |
|
499 "IsMicMutedL - test ", |
|
500 "CMusEngSession", |
|
501 "IsMicMutedL", |
|
502 "FUNCTIONALITY", |
|
503 SetupL, UT_IsMicMutedLL, Teardown) |
|
504 |
|
505 EUNIT_TEST( |
|
506 "SetAudioRoutingObserverL - test ", |
|
507 "CMusEngSession", |
|
508 "SetAudioRoutingObserverL", |
|
509 "FUNCTIONALITY", |
|
510 SetupL, UT_SetAudioRoutingObserverL, Teardown) |
|
511 |
|
512 EUNIT_TEST( |
|
513 "VolumeUpL - test ", |
|
514 "CMusEngSession", |
|
515 "VolumeUpL", |
|
516 "FUNCTIONALITY", |
|
517 SetupL, UT_VolumeUpLL, Teardown) |
|
518 |
|
519 EUNIT_TEST( |
|
520 "VolumeDownL - test ", |
|
521 "CMusEngSession", |
|
522 "VolumeDownL", |
|
523 "FUNCTIONALITY", |
|
524 SetupL, UT_VolumeDownLL, Teardown) |
|
525 |
|
526 EUNIT_TEST( |
|
527 "SetVolumeL - test ", |
|
528 "CMusEngSession", |
|
529 "SetVolumeL", |
|
530 "FUNCTIONALITY", |
|
531 SetupL, UT_SetVolumeLL, Teardown) |
|
532 |
|
533 EUNIT_END_TEST_TABLE |
|
534 |
|
535 // END OF FILE |
|