|
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_musengtelephoneutils.h" |
|
22 #include "musengstubs.h" |
|
23 #include "musengtestdefs.h" |
|
24 |
|
25 #include "musengtelephoneutils.h" |
|
26 |
|
27 // SYSTEM INCLUDES |
|
28 #include <digia/eunit/eunitmacros.h> |
|
29 #include <centralrepository.h> |
|
30 #include <e32property.h> |
|
31 |
|
32 |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 UT_CMusEngTelephoneUtils* UT_CMusEngTelephoneUtils::NewL() |
|
39 { |
|
40 UT_CMusEngTelephoneUtils* self = UT_CMusEngTelephoneUtils::NewLC(); |
|
41 CleanupStack::Pop( self ); |
|
42 return self; |
|
43 } |
|
44 |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 UT_CMusEngTelephoneUtils* UT_CMusEngTelephoneUtils::NewLC() |
|
51 { |
|
52 UT_CMusEngTelephoneUtils* self = new( ELeave ) UT_CMusEngTelephoneUtils(); |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL(); |
|
55 return self; |
|
56 } |
|
57 |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 UT_CMusEngTelephoneUtils::~UT_CMusEngTelephoneUtils() |
|
64 { |
|
65 // NOP |
|
66 } |
|
67 |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // Default constructor |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 UT_CMusEngTelephoneUtils::UT_CMusEngTelephoneUtils() |
|
74 { |
|
75 // NOP |
|
76 } |
|
77 |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // Second phase construct |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 void UT_CMusEngTelephoneUtils::ConstructL() |
|
84 { |
|
85 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
86 // It generates the test case table. |
|
87 CEUnitTestSuiteClass::ConstructL(); |
|
88 } |
|
89 |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 void UT_CMusEngTelephoneUtils::SetupL() |
|
96 { |
|
97 iObserver = new( ELeave ) CMusEngObserverStub; |
|
98 iTelephoneUtils = CMusEngTelephoneUtils::NewL( *iObserver ); |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 void UT_CMusEngTelephoneUtils::Teardown() |
|
106 { |
|
107 delete iTelephoneUtils; |
|
108 iTelephoneUtils = NULL; |
|
109 delete iObserver; |
|
110 iObserver = NULL; |
|
111 PropertyHelper::Close(); |
|
112 } |
|
113 |
|
114 |
|
115 // TEST CASES |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 void UT_CMusEngTelephoneUtils::UT_NewLL() |
|
122 { |
|
123 EUNIT_ASSERT( iTelephoneUtils ); |
|
124 } |
|
125 |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 void UT_CMusEngTelephoneUtils::UT_AudioRoutingCanBeChangedL() |
|
132 { |
|
133 iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = |
|
134 CTelephonyAudioRouting::ENotActive; |
|
135 EUNIT_ASSERT( iTelephoneUtils->AudioRoutingCanBeChanged() ); |
|
136 |
|
137 iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = |
|
138 CTelephonyAudioRouting::ENone; |
|
139 EUNIT_ASSERT( iTelephoneUtils->AudioRoutingCanBeChanged() ); |
|
140 |
|
141 iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = |
|
142 CTelephonyAudioRouting::EHandset; |
|
143 EUNIT_ASSERT( iTelephoneUtils->AudioRoutingCanBeChanged() ); |
|
144 |
|
145 iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = |
|
146 CTelephonyAudioRouting::ELoudspeaker; |
|
147 EUNIT_ASSERT( iTelephoneUtils->AudioRoutingCanBeChanged() ); |
|
148 |
|
149 iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = |
|
150 CTelephonyAudioRouting::EWiredAudioAccessory; |
|
151 EUNIT_ASSERT( !iTelephoneUtils->AudioRoutingCanBeChanged() ); |
|
152 |
|
153 iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = |
|
154 CTelephonyAudioRouting::EBTAudioAccessory; |
|
155 EUNIT_ASSERT( !iTelephoneUtils->AudioRoutingCanBeChanged() ); |
|
156 |
|
157 iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = |
|
158 CTelephonyAudioRouting::ETTY; |
|
159 EUNIT_ASSERT( !iTelephoneUtils->AudioRoutingCanBeChanged() ); |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 void UT_CMusEngTelephoneUtils::UT_LoudspeakerLL() |
|
167 { |
|
168 // Precondition of test |
|
169 iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = |
|
170 CTelephonyAudioRouting::EHandset; |
|
171 |
|
172 // Set loudspeaker on, succeeds |
|
173 iTelephoneUtils->LoudspeakerL( ETrue ); |
|
174 EUNIT_ASSERT( iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput == |
|
175 CTelephonyAudioRouting::ELoudspeaker ); |
|
176 EUNIT_ASSERT( iTelephoneUtils->iTelephonyAudioRouting->iShowNoteMode == |
|
177 EFalse ); |
|
178 |
|
179 // Change conditions |
|
180 iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = |
|
181 CTelephonyAudioRouting::EWiredAudioAccessory; |
|
182 |
|
183 // Try to set loudspeaker on, fails because current set is not handset |
|
184 iTelephoneUtils->LoudspeakerL( ETrue ); |
|
185 EUNIT_ASSERT( iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput == |
|
186 CTelephonyAudioRouting::EWiredAudioAccessory ); |
|
187 |
|
188 // Change conditions |
|
189 iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = |
|
190 CTelephonyAudioRouting::ELoudspeaker; |
|
191 iTelephoneUtils->iAudioOutputAtStartup = |
|
192 CTelephonyAudioRouting::ELoudspeaker; |
|
193 |
|
194 // Try to set loudspeaker off, goes to handset |
|
195 iTelephoneUtils->LoudspeakerL( EFalse ); |
|
196 EUNIT_ASSERT( iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput == |
|
197 CTelephonyAudioRouting::EHandset ); |
|
198 |
|
199 // Change conditions |
|
200 iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = |
|
201 CTelephonyAudioRouting::ELoudspeaker; |
|
202 iTelephoneUtils->iAudioOutputAtStartup = |
|
203 CTelephonyAudioRouting::EWiredAudioAccessory; |
|
204 |
|
205 // Try to set loudspeaker off, goes to wired |
|
206 iTelephoneUtils->LoudspeakerL( EFalse ); |
|
207 EUNIT_ASSERT( iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput == |
|
208 CTelephonyAudioRouting::EWiredAudioAccessory ); |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 void UT_CMusEngTelephoneUtils::UT_IsLoudSpeakerEnabledL() |
|
216 { |
|
217 iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = |
|
218 CTelephonyAudioRouting::ELoudspeaker; |
|
219 EUNIT_ASSERT( iTelephoneUtils->IsLoudSpeakerEnabled() ); |
|
220 |
|
221 iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = |
|
222 CTelephonyAudioRouting::EHandset; |
|
223 EUNIT_ASSERT( !iTelephoneUtils->IsLoudSpeakerEnabled() ); |
|
224 } |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 void UT_CMusEngTelephoneUtils::UT_GetVolumeLL() |
|
231 { |
|
232 TInt volume = 0; |
|
233 |
|
234 volume = iTelephoneUtils->GetVolumeL(); |
|
235 EUNIT_ASSERT( volume == 4 ); |
|
236 |
|
237 iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = |
|
238 CTelephonyAudioRouting::ELoudspeaker; |
|
239 iTelephoneUtils->iRepository->Set( KTelIncallLoudspeakerVolume, 8 ); |
|
240 |
|
241 volume = iTelephoneUtils->GetVolumeL(); |
|
242 EUNIT_ASSERT( volume == 8 ); |
|
243 } |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 void UT_CMusEngTelephoneUtils::UT_SetVolumeLL() |
|
250 { |
|
251 TInt handsetVolume = 0; |
|
252 TInt loudSpeakerVolume = 0; |
|
253 |
|
254 // Try with current value, does nothing |
|
255 iTelephoneUtils->SetVolumeL( 4 ); |
|
256 |
|
257 iTelephoneUtils->iRepository->Get( KTelIncallEarVolume, |
|
258 handsetVolume ); |
|
259 EUNIT_ASSERT( handsetVolume == 4 ); |
|
260 |
|
261 // Try to change handset volume |
|
262 iTelephoneUtils->SetVolumeL( 5 ); |
|
263 |
|
264 iTelephoneUtils->iRepository->Get( KTelIncallEarVolume, |
|
265 handsetVolume ); |
|
266 EUNIT_ASSERT( handsetVolume == 5 ); |
|
267 |
|
268 iTelephoneUtils->iRepository->Get( KTelIncallLoudspeakerVolume, |
|
269 loudSpeakerVolume ); |
|
270 EUNIT_ASSERT( loudSpeakerVolume == 4 ); |
|
271 |
|
272 // Try to change loudspeaker volume |
|
273 iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = |
|
274 CTelephonyAudioRouting::ELoudspeaker; |
|
275 |
|
276 iTelephoneUtils->SetVolumeL( 3 ); |
|
277 |
|
278 iTelephoneUtils->iRepository->Get( KTelIncallEarVolume, |
|
279 handsetVolume ); |
|
280 EUNIT_ASSERT( handsetVolume == 5 ); |
|
281 |
|
282 iTelephoneUtils->iRepository->Get( KTelIncallLoudspeakerVolume, |
|
283 loudSpeakerVolume ); |
|
284 EUNIT_ASSERT( loudSpeakerVolume == 3 ); |
|
285 |
|
286 // Check that volume gets validated |
|
287 |
|
288 iTelephoneUtils->SetVolumeL( 100 ); |
|
289 |
|
290 iTelephoneUtils->iRepository->Get( KTelIncallLoudspeakerVolume, |
|
291 loudSpeakerVolume ); |
|
292 EUNIT_ASSERT( loudSpeakerVolume == 10 ); |
|
293 } |
|
294 |
|
295 // ----------------------------------------------------------------------------- |
|
296 // |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 void UT_CMusEngTelephoneUtils::UT_AvailableOutputsChangedL() |
|
300 { |
|
301 // At the monent function is expected to do nothing so just |
|
302 // call it to avoid coverage loss. |
|
303 iTelephoneUtils->AvailableOutputsChanged( |
|
304 *iTelephoneUtils->iTelephonyAudioRouting ); |
|
305 } |
|
306 |
|
307 // ----------------------------------------------------------------------------- |
|
308 // |
|
309 // ----------------------------------------------------------------------------- |
|
310 // |
|
311 void UT_CMusEngTelephoneUtils::UT_OutputChangedL() |
|
312 { |
|
313 // Loudspeaker |
|
314 iTelephoneUtils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset; |
|
315 |
|
316 iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = |
|
317 CTelephonyAudioRouting::ELoudspeaker; |
|
318 |
|
319 iTelephoneUtils->OutputChanged( *iTelephoneUtils->iTelephonyAudioRouting ); |
|
320 |
|
321 EUNIT_ASSERT_EQUALS( iTelephoneUtils->iAudioOutputAtStartup, |
|
322 CTelephonyAudioRouting::ELoudspeaker ) |
|
323 EUNIT_ASSERT( iObserver->iAudioRoutingChangedCalled ) |
|
324 |
|
325 // Handset |
|
326 iTelephoneUtils->iTelephonyAudioRouting->iCurrentOutput = |
|
327 CTelephonyAudioRouting::EHandset; |
|
328 |
|
329 iTelephoneUtils->OutputChanged( *iTelephoneUtils->iTelephonyAudioRouting ); |
|
330 |
|
331 EUNIT_ASSERT_EQUALS( iTelephoneUtils->iAudioOutputAtStartup, |
|
332 CTelephonyAudioRouting::EHandset ) |
|
333 |
|
334 EUNIT_ASSERT( iObserver->iAudioRoutingChangedCalled ) |
|
335 } |
|
336 |
|
337 // ----------------------------------------------------------------------------- |
|
338 // |
|
339 // ----------------------------------------------------------------------------- |
|
340 // |
|
341 void UT_CMusEngTelephoneUtils::UT_SetOutputCompleteL() |
|
342 { |
|
343 // Setoutput fails |
|
344 iTelephoneUtils->SetOutputComplete( |
|
345 *iTelephoneUtils->iTelephonyAudioRouting, |
|
346 KErrGeneral ); |
|
347 EUNIT_ASSERT( !iObserver->iAudioRoutingChangedCalled ) |
|
348 iObserver->Reset(); |
|
349 |
|
350 // Setoutput ok |
|
351 iTelephoneUtils->SetOutputComplete( |
|
352 *iTelephoneUtils->iTelephonyAudioRouting, |
|
353 KErrNone ); |
|
354 EUNIT_ASSERT( iObserver->iAudioRoutingChangedCalled ) |
|
355 } |
|
356 |
|
357 // ----------------------------------------------------------------------------- |
|
358 // |
|
359 // ----------------------------------------------------------------------------- |
|
360 // |
|
361 void UT_CMusEngTelephoneUtils::UT_ValidateVolumeL() |
|
362 { |
|
363 EUNIT_ASSERT( iTelephoneUtils->ValidateVolume( 0 ) == 0 ); |
|
364 EUNIT_ASSERT( iTelephoneUtils->ValidateVolume( 11 ) == 10 ); |
|
365 EUNIT_ASSERT( iTelephoneUtils->ValidateVolume( 5 ) == 5 ); |
|
366 } |
|
367 |
|
368 // ----------------------------------------------------------------------------- |
|
369 // We cannot assert anything after destruction. All we can do is to make |
|
370 // such condition before destruction that coverage will be achieved. |
|
371 // ----------------------------------------------------------------------------- |
|
372 // |
|
373 void UT_CMusEngTelephoneUtils::UT_DestructorL() |
|
374 { |
|
375 // Simulate that 2nd phase construction has not succeeded |
|
376 CMusEngTelephoneUtils* utils = CMusEngTelephoneUtils::NewL( *iObserver ); |
|
377 CleanupStack::PushL( utils ); |
|
378 delete utils->iTelephonyAudioRouting; |
|
379 utils->iTelephonyAudioRouting = NULL; |
|
380 CleanupStack::PopAndDestroy( utils ); |
|
381 |
|
382 // Simulate that current audio output mode is same as original |
|
383 utils = CMusEngTelephoneUtils::NewL( *iObserver ); |
|
384 CleanupStack::PushL( utils ); |
|
385 utils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset; |
|
386 utils->iTelephonyAudioRouting->iCurrentOutput = |
|
387 CTelephonyAudioRouting::EHandset; |
|
388 CleanupStack::PopAndDestroy( utils ); |
|
389 |
|
390 // Simulate that current audio output mode is not the same as original, |
|
391 // Setting fails |
|
392 utils = CMusEngTelephoneUtils::NewL( *iObserver ); |
|
393 CleanupStack::PushL( utils ); |
|
394 utils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset; |
|
395 utils->iTelephonyAudioRouting->iCurrentOutput = |
|
396 CTelephonyAudioRouting::ELoudspeaker; |
|
397 utils->iTelephonyAudioRouting->iForceFailWithCode = KErrGeneral; |
|
398 CleanupStack::PopAndDestroy( utils ); |
|
399 |
|
400 // Simulate that current audio output mode is not the same as original, |
|
401 // Setting succeeds |
|
402 utils = CMusEngTelephoneUtils::NewL( *iObserver ); |
|
403 CleanupStack::PushL( utils ); |
|
404 utils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset; |
|
405 utils->iTelephonyAudioRouting->iCurrentOutput = |
|
406 CTelephonyAudioRouting::ELoudspeaker; |
|
407 CleanupStack::PopAndDestroy( utils ); |
|
408 |
|
409 // Simulate that current audio output mode is not the same as original, |
|
410 // Setting does not succeed as observer does not allow changes anymore |
|
411 utils = CMusEngTelephoneUtils::NewL( *iObserver ); |
|
412 CleanupStack::PushL( utils ); |
|
413 utils->iAudioOutputAtStartup = CTelephonyAudioRouting::EHandset; |
|
414 utils->iTelephonyAudioRouting->iCurrentOutput = |
|
415 CTelephonyAudioRouting::ELoudspeaker; |
|
416 CleanupStack::PopAndDestroy( utils ); |
|
417 // Cannot really assert anything |
|
418 } |
|
419 |
|
420 |
|
421 // TEST TABLE |
|
422 |
|
423 EUNIT_BEGIN_TEST_TABLE( |
|
424 UT_CMusEngTelephoneUtils, |
|
425 "UT_CMusEngTelephoneUtils", |
|
426 "UNIT" ) |
|
427 |
|
428 EUNIT_TEST( |
|
429 "NewL - test ", |
|
430 "CMusEngTelephoneUtils", |
|
431 "NewL", |
|
432 "FUNCTIONALITY", |
|
433 SetupL, UT_NewLL, Teardown) |
|
434 |
|
435 EUNIT_TEST( |
|
436 "AudioRoutingCanBeChanged - test ", |
|
437 "CMusEngTelephoneUtils", |
|
438 "AudioRoutingCanBeChanged", |
|
439 "FUNCTIONALITY", |
|
440 SetupL, UT_AudioRoutingCanBeChangedL, Teardown) |
|
441 |
|
442 EUNIT_TEST( |
|
443 "LoudspeakerL - test ", |
|
444 "CMusEngTelephoneUtils", |
|
445 "LoudspeakerL", |
|
446 "FUNCTIONALITY", |
|
447 SetupL, UT_LoudspeakerLL, Teardown) |
|
448 |
|
449 EUNIT_TEST( |
|
450 "IsLoudSpeakerEnabled - test ", |
|
451 "CMusEngTelephoneUtils", |
|
452 "IsLoudSpeakerEnabled", |
|
453 "FUNCTIONALITY", |
|
454 SetupL, UT_IsLoudSpeakerEnabledL, Teardown) |
|
455 |
|
456 EUNIT_TEST( |
|
457 "GetVolumeL - test ", |
|
458 "CMusEngTelephoneUtils", |
|
459 "GetVolumeL", |
|
460 "FUNCTIONALITY", |
|
461 SetupL, UT_GetVolumeLL, Teardown) |
|
462 |
|
463 EUNIT_TEST( |
|
464 "SetVolumeL - test ", |
|
465 "CMusEngTelephoneUtils", |
|
466 "SetVolumeL", |
|
467 "FUNCTIONALITY", |
|
468 SetupL, UT_SetVolumeLL, Teardown) |
|
469 |
|
470 EUNIT_TEST( |
|
471 "AvailableOutputsChanged - test ", |
|
472 "CMusEngTelephoneUtils", |
|
473 "AvailableOutputsChanged", |
|
474 "FUNCTIONALITY", |
|
475 SetupL, UT_AvailableOutputsChangedL, Teardown) |
|
476 |
|
477 EUNIT_TEST( |
|
478 "OutputChanged - test ", |
|
479 "CMusEngTelephoneUtils", |
|
480 "OutputChanged", |
|
481 "FUNCTIONALITY", |
|
482 SetupL, UT_OutputChangedL, Teardown) |
|
483 |
|
484 EUNIT_TEST( |
|
485 "SetOutputComplete - test ", |
|
486 "CMusEngTelephoneUtils", |
|
487 "SetOutputComplete", |
|
488 "FUNCTIONALITY", |
|
489 SetupL, UT_SetOutputCompleteL, Teardown) |
|
490 |
|
491 EUNIT_TEST( |
|
492 "ValidateVolume - test ", |
|
493 "CMusEngTelephoneUtils", |
|
494 "ValidateVolume", |
|
495 "FUNCTIONALITY", |
|
496 SetupL, UT_ValidateVolumeL, Teardown) |
|
497 |
|
498 EUNIT_TEST( |
|
499 "Destructor - test ", |
|
500 "CMusEngTelephoneUtils", |
|
501 "Destructor", |
|
502 "FUNCTIONALITY", |
|
503 SetupL, UT_DestructorL, Teardown) |
|
504 |
|
505 |
|
506 |
|
507 EUNIT_END_TEST_TABLE |
|
508 |
|
509 // END OF FILE |
|
510 |
|
511 |