|
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 #include "ut_phoneaudioutil.h" |
|
19 #include "phoneaudioutil.h" |
|
20 #include "phonenoteutil.h" |
|
21 #include <EUnitMacros.h> |
|
22 #include <EUnitDecorators.h> |
|
23 |
|
24 #include "CPhoneStateMachineGSM.h" |
|
25 #include "mock_cphoneviewcommandhandle.h" |
|
26 #include "CPEEngineInfo.h" |
|
27 #include "cphonestateincall.h" |
|
28 #include "cphonestatehandle.h" |
|
29 #include "CPhoneCenRepProxy.h" |
|
30 #include "CPhoneMainResourceResolver.h" |
|
31 #include <EUnitMacros.h> |
|
32 #include <EUnitDecorators.h> |
|
33 #include "phoneui.hrh" |
|
34 #include <csmcmockcontext.h> |
|
35 #include <msmcmockspecbuilder.h> |
|
36 #include <coemain.h> |
|
37 #include <PhoneUI.rsg> |
|
38 #include "phoneresourceids.h" |
|
39 #include "phonerssbase.h" |
|
40 #include "CPhoneTerminateAllConnectionsCommand.h" |
|
41 |
|
42 // needed for mocking CPhoneMainResourceResolver::Instance() |
|
43 class CPhoneMainResourceResolverMock : public CPhoneMainResourceResolver{}; |
|
44 |
|
45 class CPhoneStateMachineGSMMock : public CPhoneStateMachineGSM{}; |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 // - Construction ----------------------------------------------------------- |
|
51 |
|
52 ut_phoneaudioutil* ut_phoneaudioutil::NewL() |
|
53 { |
|
54 ut_phoneaudioutil* self = ut_phoneaudioutil::NewLC(); |
|
55 CleanupStack::Pop(); |
|
56 return self; |
|
57 } |
|
58 |
|
59 ut_phoneaudioutil* ut_phoneaudioutil::NewLC() |
|
60 { |
|
61 ut_phoneaudioutil* self = new( ELeave ) ut_phoneaudioutil(); |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL(); |
|
64 return self; |
|
65 } |
|
66 |
|
67 ut_phoneaudioutil::~ut_phoneaudioutil() |
|
68 { |
|
69 CSmcMockContext::Release(); |
|
70 } |
|
71 |
|
72 ut_phoneaudioutil::ut_phoneaudioutil() |
|
73 { |
|
74 } |
|
75 |
|
76 void ut_phoneaudioutil::ConstructL() |
|
77 { |
|
78 CEUnitTestSuiteClass::ConstructL(); |
|
79 iMockContext = CSmcMockContext::InstanceL(); |
|
80 } |
|
81 |
|
82 // - Test methods ----------------------------------------------------------- |
|
83 |
|
84 void ut_phoneaudioutil::SetupL( ) |
|
85 { |
|
86 iCPhoneMainResourceResolverMock = new ( ELeave ) CPhoneMainResourceResolverMock(); |
|
87 SmcDefaultValue<CPhoneMainResourceResolver*>::SetL( iCPhoneMainResourceResolverMock ); |
|
88 |
|
89 iCoeEnvMock = new (ELeave ) CCoeEnv(); |
|
90 SmcDefaultValue<CCoeEnv*>::SetL( iCoeEnvMock ); |
|
91 |
|
92 iViewCommandHandle = new CPhoneViewCommandHandleMock(); |
|
93 SmcDefaultValue<MPhoneViewCommandHandle*>::SetL( iViewCommandHandle ); |
|
94 |
|
95 iStateMachine = CPhoneStateMachineGSMMock::NewL(iViewCommandHandle); |
|
96 SmcDefaultValue<MPhoneStateMachine*>::SetL( iStateMachine ); |
|
97 |
|
98 iCPhoneStateHandleMock = CPhoneStateHandle:: |
|
99 CreateL(iViewCommandHandle, _L("test"), TUid::Uid(1)); |
|
100 SmcDefaultValue<CPhoneStateHandle*>::SetL( iCPhoneStateHandleMock ); |
|
101 |
|
102 iEngineInfo = CPEEngineInfo::NewL(); |
|
103 SmcDefaultValue<MPEEngineInfo*>::SetL( iEngineInfo ); |
|
104 } |
|
105 |
|
106 void ut_phoneaudioutil::Teardown( ) |
|
107 { |
|
108 delete iStateMachine; |
|
109 iStateMachine = NULL; |
|
110 SmcDefaultValue<MPhoneStateMachine*>::Reset(); |
|
111 |
|
112 delete iCPhoneStateHandleMock; |
|
113 iCPhoneStateHandleMock = NULL; |
|
114 SmcDefaultValue<CPhoneStateHandle*>::Reset(); |
|
115 |
|
116 delete iViewCommandHandle; |
|
117 iViewCommandHandle = NULL; |
|
118 SmcDefaultValue<MPhoneViewCommandHandle*>::Reset(); |
|
119 |
|
120 delete iEngineInfo; |
|
121 iEngineInfo = NULL; |
|
122 SmcDefaultValue<MPEEngineInfo*>::Reset(); |
|
123 |
|
124 delete iCoeEnvMock; |
|
125 iCoeEnvMock = NULL; |
|
126 SmcDefaultValue<CCoeEnv*>::Reset(); |
|
127 |
|
128 delete iCPhoneMainResourceResolverMock; |
|
129 iCPhoneMainResourceResolverMock = NULL; |
|
130 SmcDefaultValue<CPhoneMainResourceResolver*>::Reset(); |
|
131 |
|
132 iMockContext->Reset(); |
|
133 } |
|
134 |
|
135 void ut_phoneaudioutil::T_ConstructionL( ) |
|
136 { |
|
137 // SetupL and Teardown does the test. |
|
138 } |
|
139 |
|
140 void ut_phoneaudioutil::T_HandleAudioMuteChangedL( ) |
|
141 { |
|
142 iMockContext->ExpectCallL( "CPhoneViewCommandHandleMock::ExecuteCommandL" ); |
|
143 |
|
144 PhoneAudioUtil::HandleAudioMuteChangedL(); |
|
145 |
|
146 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
147 } |
|
148 |
|
149 void ut_phoneaudioutil::T_HandleAudioOutputChangedL( ) |
|
150 { |
|
151 PhoneAudioUtil::HandleAudioOutputChangedL(); |
|
152 |
|
153 iEngineInfo->SetAudioOutput(EPEBTAudioAccessory, EPEHandset, EFalse); |
|
154 RArray<TPEAudioOutput> availableOutputs; |
|
155 availableOutputs.Append(EPEBTAudioAccessory); |
|
156 availableOutputs.Append(EPEHandset); |
|
157 availableOutputs.Append(EPELoudspeaker); |
|
158 iEngineInfo->SetAvailableAudioOutputs(availableOutputs.Array()); |
|
159 |
|
160 iMockContext->ExpectCallL( "CPhoneAccessoryBTHandler::ShowBTActivatedL" ); |
|
161 PhoneAudioUtil::HandleAudioOutputChangedL(); |
|
162 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
163 iMockContext->Reset(); |
|
164 |
|
165 iEngineInfo->SetAudioOutput(EPENotActive, EPEBTAudioAccessory, EFalse); |
|
166 iMockContext->ExpectCallL( "CPhoneBtaaDisconnectHandler::IsQuery" ).ReturnsL(ETrue); |
|
167 iMockContext->ExpectCallL( "CPhoneBtaaDisconnectHandler::Cancel" ); |
|
168 PhoneAudioUtil::HandleAudioOutputChangedL(); |
|
169 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
170 iMockContext->Reset(); |
|
171 |
|
172 iEngineInfo->SetAudioOutput(EPELoudspeaker, EPEHandset, EFalse); |
|
173 iMockContext->ExpectCallL( |
|
174 "CPhoneViewCommandHandleMock::ExecuteCommandL" ).WithL(EPhoneViewPlayHandsFreeActivatedTone); |
|
175 PhoneAudioUtil::HandleAudioOutputChangedL(); |
|
176 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
177 |
|
178 availableOutputs.Close(); |
|
179 } |
|
180 |
|
181 void ut_phoneaudioutil::T_ChangeAudioVolumeL( ) |
|
182 { |
|
183 iEngineInfo->SetAudioOutput(EPETTY, EPENotActive, EFalse); |
|
184 iMockContext->ExpectCallL( "PhoneNoteUtil::SendGlobalInfoNoteL" ); |
|
185 PhoneAudioUtil::DecreaseAudioVolumeL(); |
|
186 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
187 iMockContext->Reset(); |
|
188 |
|
189 iMockContext->ExpectCallL( "PhoneNoteUtil::SendGlobalInfoNoteL" ); |
|
190 PhoneAudioUtil::IncreaseAudioVolumeL(); |
|
191 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
192 iMockContext->Reset(); |
|
193 |
|
194 iEngineInfo->SetAudioOutput(EPEHandset, EPENotActive, EFalse); |
|
195 |
|
196 iMockContext->ExpectCallL( "CPhoneStateMachine::SendPhoneEngineMessage" ). |
|
197 WithL(MPEPhoneModel::EPEMessageSetAudioVolume); |
|
198 PhoneAudioUtil::IncreaseAudioVolumeL(); |
|
199 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
200 iMockContext->Reset(); |
|
201 |
|
202 iMockContext->ExpectCallL( "CPhoneStateMachine::SendPhoneEngineMessage" ). |
|
203 WithL(MPEPhoneModel::EPEMessageSetAudioVolume); |
|
204 PhoneAudioUtil::DecreaseAudioVolumeL(); |
|
205 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
206 iMockContext->Reset(); |
|
207 |
|
208 iMockContext->ExpectCallL( "CPhoneStateMachine::SendPhoneEngineMessage" ).TimesL(0); |
|
209 PhoneAudioUtil::ChangeAudioVolumeL( -1, EFalse ); |
|
210 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
211 |
|
212 PhoneAudioUtil::GetVolumeLevel(); |
|
213 } |
|
214 |
|
215 void ut_phoneaudioutil::T_HandleAudioAvailableOutputChangedL( ) |
|
216 { |
|
217 iEngineInfo->SetAudioOutput(EPEBTAudioAccessory, EPEHandset, EFalse); |
|
218 RArray<TPEAudioOutput> availableOutputs; |
|
219 |
|
220 availableOutputs.Append(EPEHandset); |
|
221 availableOutputs.Append(EPELoudspeaker); |
|
222 iEngineInfo->SetAvailableAudioOutputs(availableOutputs.Array()); |
|
223 |
|
224 iMockContext->ExpectCallL( "CPhoneBtaaDisconnectHandler::Cancel" ).TimesL(0); |
|
225 iMockContext->ExpectCallL( "CPhoneViewCommandHandleMock::ExecuteCommandL" ); |
|
226 PhoneAudioUtil::HandleAudioAvailableOutputChangedL(); |
|
227 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
228 iMockContext->Reset(); |
|
229 |
|
230 availableOutputs.Reset(); |
|
231 availableOutputs.Append(EPEBTAudioAccessory); |
|
232 availableOutputs.Append(EPEHandset); |
|
233 availableOutputs.Append(EPELoudspeaker); |
|
234 iEngineInfo->SetAvailableAudioOutputs(availableOutputs.Array()); |
|
235 iMockContext->ExpectCallL( "CPhoneBtaaDisconnectHandler::Cancel" ); |
|
236 iMockContext->ExpectCallL( "CPhoneViewCommandHandleMock::ExecuteCommandL" ); |
|
237 PhoneAudioUtil::HandleAudioAvailableOutputChangedL(); |
|
238 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
239 iMockContext->Reset(); |
|
240 |
|
241 availableOutputs.Close(); |
|
242 } |
|
243 |
|
244 void ut_phoneaudioutil::T_ToggleMute( ) |
|
245 { |
|
246 iEngineInfo->SetAudioMute(EFalse); |
|
247 |
|
248 iMockContext->ExpectCallL( "CPhoneStateMachine::SendPhoneEngineMessage" ). |
|
249 WithL(MPEPhoneModel::EPEMessageSetAudioMute); |
|
250 PhoneAudioUtil::ToggleMute(); |
|
251 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
252 EUNIT_ASSERT( iEngineInfo->AudioMuteCommand() ); |
|
253 iMockContext->Reset(); |
|
254 |
|
255 iEngineInfo->SetAudioMute(ETrue); |
|
256 |
|
257 iMockContext->ExpectCallL( "CPhoneStateMachine::SendPhoneEngineMessage" ). |
|
258 WithL(MPEPhoneModel::EPEMessageSetAudioMute); |
|
259 PhoneAudioUtil::ToggleMute(); |
|
260 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
261 EUNIT_ASSERT( EFalse == iEngineInfo->AudioMuteCommand() ); |
|
262 iMockContext->Reset(); |
|
263 } |
|
264 |
|
265 void ut_phoneaudioutil::T_SetHandsfreeModeL( ) |
|
266 { |
|
267 iMockContext->ExpectCallL( "CPhoneAccessoryBTHandler::SetHandsfreeModeL" ).ReturnsL(ETrue); |
|
268 iMockContext->ExpectCallL( "PhoneNoteUtil::SendGlobalErrorNoteL" ).TimesL(0); |
|
269 PhoneAudioUtil::SetHandsfreeModeL( ETrue ); |
|
270 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
271 iMockContext->Reset(); |
|
272 |
|
273 iMockContext->ExpectCallL( "CPhoneAccessoryBTHandler::SetHandsfreeModeL" ).ReturnsL(EFalse); |
|
274 iMockContext->ExpectCallL( "PhoneNoteUtil::SendGlobalErrorNoteL" ). |
|
275 WithL(EPhoneNoteTextNotAllowed ,ETrue); |
|
276 PhoneAudioUtil::SetHandsfreeModeL( ETrue ); |
|
277 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
278 iMockContext->Reset(); |
|
279 |
|
280 |
|
281 iMockContext->ExpectCallL( "CPhoneAccessoryBTHandler::SetBTHandsfreeModeL" ).ReturnsL(ETrue); |
|
282 iMockContext->ExpectCallL( "PhoneNoteUtil::SendGlobalErrorNoteL" ).TimesL(0); |
|
283 PhoneAudioUtil::SetBtHandsfreeModeL( ETrue ); |
|
284 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
285 iMockContext->Reset(); |
|
286 |
|
287 iMockContext->ExpectCallL( "CPhoneAccessoryBTHandler::SetBTHandsfreeModeL" ).ReturnsL(EFalse); |
|
288 iMockContext->ExpectCallL( "PhoneNoteUtil::SendGlobalErrorNoteL" ). |
|
289 WithL(EPhoneNoteTextNotAllowed ,ETrue); |
|
290 PhoneAudioUtil::SetBtHandsfreeModeL( ETrue ); |
|
291 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
292 iMockContext->Reset(); |
|
293 } |
|
294 |
|
295 // - EUnit test table ------------------------------------------------------- |
|
296 |
|
297 EUNIT_BEGIN_TEST_TABLE( |
|
298 ut_phoneaudioutil, |
|
299 "Add test suite description here.", |
|
300 "UNIT" ) |
|
301 |
|
302 EUNIT_TEST( |
|
303 "Test0", |
|
304 "T_ConstructionL", |
|
305 "Test0", |
|
306 "FUNCTIONALITY", |
|
307 SetupL, T_ConstructionL, Teardown) |
|
308 |
|
309 EUNIT_TEST( |
|
310 "Test1", |
|
311 "T_HandleAudioMuteChangedL", |
|
312 "Test1", |
|
313 "FUNCTIONALITY", |
|
314 SetupL, T_HandleAudioMuteChangedL, Teardown) |
|
315 |
|
316 EUNIT_TEST( |
|
317 "Test2", |
|
318 "T_HandleAudioOutputChangedL", |
|
319 "Test2", |
|
320 "FUNCTIONALITY", |
|
321 SetupL, T_HandleAudioOutputChangedL, Teardown) |
|
322 |
|
323 EUNIT_TEST( |
|
324 "Test3", |
|
325 "T_ChangeAudioVolumeL", |
|
326 "Test3", |
|
327 "FUNCTIONALITY", |
|
328 SetupL, T_ChangeAudioVolumeL, Teardown) |
|
329 |
|
330 EUNIT_TEST( |
|
331 "Test4", |
|
332 "T_HandleAudioAvailableOutputChangedL", |
|
333 "Test4", |
|
334 "FUNCTIONALITY", |
|
335 SetupL, T_HandleAudioAvailableOutputChangedL, Teardown) |
|
336 |
|
337 EUNIT_TEST( |
|
338 "Test5", |
|
339 "T_ToggleMute", |
|
340 "Test5", |
|
341 "FUNCTIONALITY", |
|
342 SetupL, T_ToggleMute, Teardown) |
|
343 |
|
344 EUNIT_TEST( |
|
345 "Test6", |
|
346 "T_SetHandsfreeModeL", |
|
347 "Test6", |
|
348 "FUNCTIONALITY", |
|
349 SetupL, T_SetHandsfreeModeL, Teardown) |
|
350 |
|
351 EUNIT_END_TEST_TABLE |