|
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_CPhoneAccessoryBTHandler.h" |
|
19 #include "FeatMgr.h" |
|
20 #include <EUnitMacros.h> |
|
21 #include <EUnitDecorators.h> |
|
22 #include <btengdomainpskeys.h> |
|
23 #include <e32property.h> |
|
24 |
|
25 #include <csmcmockcontext.h> |
|
26 #include <smcdefaultvalue.h> |
|
27 #include <msmcmockspecbuilder.h> |
|
28 #include <smcobjecttotypemapper.h> |
|
29 |
|
30 #include <coemain.h> |
|
31 |
|
32 #include "cpeengineinfo.h" |
|
33 #include "cpeengineinfoimpl.h" |
|
34 #include "cphonemainresourceresolver.h" |
|
35 #include "tphonecmdparamnote.h" |
|
36 |
|
37 #include "cphonestatemachinegsm.h" |
|
38 #include "mock_cphoneviewcommandhandle.h" |
|
39 #include "cphoneaccessorybthandler.h" |
|
40 |
|
41 |
|
42 // needed for mocking CPhoneMainResourceResolver::Instance() |
|
43 class CPhoneMainResourceResolverMock : public CPhoneMainResourceResolver |
|
44 { |
|
45 }; |
|
46 |
|
47 // - Construction ----------------------------------------------------------- |
|
48 |
|
49 UT_CPhoneAccessoryBTHandler* UT_CPhoneAccessoryBTHandler::NewL() |
|
50 { |
|
51 UT_CPhoneAccessoryBTHandler* self = UT_CPhoneAccessoryBTHandler::NewLC(); |
|
52 CleanupStack::Pop(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 UT_CPhoneAccessoryBTHandler* UT_CPhoneAccessoryBTHandler::NewLC() |
|
57 { |
|
58 UT_CPhoneAccessoryBTHandler* self = new( ELeave ) UT_CPhoneAccessoryBTHandler(); |
|
59 CleanupStack::PushL( self ); |
|
60 self->ConstructL(); |
|
61 return self; |
|
62 } |
|
63 |
|
64 UT_CPhoneAccessoryBTHandler::~UT_CPhoneAccessoryBTHandler() |
|
65 { |
|
66 CSmcMockContext::Release(); |
|
67 } |
|
68 |
|
69 UT_CPhoneAccessoryBTHandler::UT_CPhoneAccessoryBTHandler() |
|
70 { |
|
71 } |
|
72 |
|
73 void UT_CPhoneAccessoryBTHandler::ConstructL() |
|
74 { |
|
75 CEUnitTestSuiteClass::ConstructL(); |
|
76 iMockContext = CSmcMockContext::InstanceL(); |
|
77 } |
|
78 |
|
79 // - Test methods ----------------------------------------------------------- |
|
80 void UT_CPhoneAccessoryBTHandler::SetupL( ) |
|
81 { |
|
82 iEntryCleared = EFalse; |
|
83 iMockContext->InitializeL(); |
|
84 |
|
85 iCPhoneMainResourceResolverMock = new ( ELeave ) CPhoneMainResourceResolverMock(); |
|
86 SmcDefaultValue<CPhoneMainResourceResolver*>::SetL( iCPhoneMainResourceResolverMock ); |
|
87 |
|
88 SmcDefaultValue<const TPEAudioOutput&>::SetL( EPENotActive ); |
|
89 |
|
90 iViewCmdHandleMock = new CPhoneViewCommandHandleMock(); |
|
91 iStateMachineMock = CPhoneStateMachineGSM::NewL( iViewCmdHandleMock ); |
|
92 |
|
93 iCoeEnvMock = new (ELeave ) CCoeEnv(); |
|
94 SmcDefaultValue<CCoeEnv*>::SetL( iCoeEnvMock ); |
|
95 |
|
96 iEngineInfoMock = CPEEngineInfo::NewL(); |
|
97 SmcDefaultValue<MPEEngineInfo*>::SetL( iEngineInfoMock ); |
|
98 |
|
99 iCPhoneAccessoryBTHandler = |
|
100 CPhoneAccessoryBTHandler::NewLC( |
|
101 iViewCmdHandleMock, |
|
102 iStateMachineMock, |
|
103 this ); |
|
104 |
|
105 } |
|
106 |
|
107 void UT_CPhoneAccessoryBTHandler::Teardown( ) |
|
108 { |
|
109 delete iCPhoneMainResourceResolverMock; |
|
110 iCPhoneMainResourceResolverMock = NULL; |
|
111 |
|
112 CleanupStack::PopAndDestroy( iCPhoneAccessoryBTHandler ); |
|
113 iCPhoneAccessoryBTHandler = NULL; |
|
114 |
|
115 delete iViewCmdHandleMock; |
|
116 iViewCmdHandleMock = NULL; |
|
117 |
|
118 delete iStateMachineMock; |
|
119 iStateMachineMock = NULL; |
|
120 |
|
121 delete iCoeEnvMock; |
|
122 iCoeEnvMock = NULL; |
|
123 SmcDefaultValue<CCoeEnv*>::Reset(); |
|
124 |
|
125 delete iEngineInfoMock; |
|
126 iEngineInfoMock = NULL; |
|
127 |
|
128 SmcDefaultValue<const TPEAudioOutput&>::Reset(); |
|
129 |
|
130 iMockContext->Reset(); |
|
131 } |
|
132 |
|
133 void UT_CPhoneAccessoryBTHandler::HandleNumberEntryClearedL() |
|
134 { |
|
135 iEntryCleared = ETrue; |
|
136 } |
|
137 |
|
138 void UT_CPhoneAccessoryBTHandler::UT_SetBTHandsfreeModeL_ONL( ) |
|
139 { |
|
140 iMockContext->ExpectCallL( "CPEEngineInfoImpl::AudioOutput" ); |
|
141 iMockContext->ExpectCallL( "CPEEngineInfoImpl::SetAudioOutputCommand" ). |
|
142 WithL<TPEAudioOutput, TInt>(EPEBTAudioAccessory, ETrue); |
|
143 iCPhoneAccessoryBTHandler->SetBTHandsfreeModeL(ETrue ); |
|
144 |
|
145 EUNIT_ASSERT_EQUALS( ETrue, iCPhoneAccessoryBTHandler->SetBTHandsfreeModeL( ETrue ) ); |
|
146 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
147 } |
|
148 |
|
149 void UT_CPhoneAccessoryBTHandler::UT_SetBTHandsfreeModeL_OFFL( ) |
|
150 { |
|
151 iMockContext->ExpectCallL( "CPEEngineInfoImpl::AudioOutput" ); |
|
152 iMockContext->ExpectCallL( "CPEEngineInfoImpl::SetAudioOutputCommand" ). |
|
153 WithL<TPEAudioOutput, TInt>(EPEHandset, EFalse); |
|
154 |
|
155 EUNIT_ASSERT_EQUALS( ETrue, iCPhoneAccessoryBTHandler->SetBTHandsfreeModeL( EFalse ) ); |
|
156 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
157 } |
|
158 |
|
159 void UT_CPhoneAccessoryBTHandler::UT_SetBTHandsfreeModeL_ON_AudioRoutedToWiredAudioAccessoryL( ) |
|
160 { |
|
161 SmcDefaultValue<const TPEAudioOutput&>::SetL( EPEWiredAudioAccessory ); |
|
162 iMockContext->ExpectCallL( "CPEEngineInfoImpl::AudioOutput" ).TimesL(1); |
|
163 iMockContext->ExpectCallL( "CPEEngineInfoImpl::SetAudioOutputCommand" ).TimesL(0); |
|
164 |
|
165 EUNIT_ASSERT_EQUALS( EFalse, iCPhoneAccessoryBTHandler->SetBTHandsfreeModeL( ETrue ) ); |
|
166 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
167 } |
|
168 |
|
169 void UT_CPhoneAccessoryBTHandler::UT_SetHandsfreeModeL_ONL( ) |
|
170 { |
|
171 iMockContext->ExpectCallL( "CPEEngineInfoImpl::AudioOutput" ). |
|
172 ReturnsL( EPENotActive ); |
|
173 iMockContext->ExpectCallL( "CPEEngineInfoImpl::SetAudioOutputCommand" ). |
|
174 WithL<TPEAudioOutput, TInt>(EPELoudspeaker, ETrue); |
|
175 iCPhoneAccessoryBTHandler->SetBTHandsfreeModeL( ETrue ); |
|
176 |
|
177 EUNIT_ASSERT_EQUALS( ETrue, iCPhoneAccessoryBTHandler->SetHandsfreeModeL( ETrue ) ); |
|
178 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
179 } |
|
180 |
|
181 void UT_CPhoneAccessoryBTHandler::UT_SetHandsfreeModeL_OFFL( ) |
|
182 { |
|
183 iMockContext->ExpectCallL( "CPEEngineInfoImpl::AudioOutput" ). |
|
184 ReturnsL( EPENotActive ); |
|
185 iMockContext->ExpectCallL( "CPEEngineInfoImpl::SetAudioOutputCommand" ). |
|
186 WithL<TPEAudioOutput, TInt>(EPEHandset, EFalse); |
|
187 |
|
188 EUNIT_ASSERT_EQUALS( ETrue, iCPhoneAccessoryBTHandler->SetHandsfreeModeL( EFalse ) ); |
|
189 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
190 } |
|
191 |
|
192 void UT_CPhoneAccessoryBTHandler::UT_SetHandsfreeModeL_ON_AudioRoutedToWiredAudioAccessoryL( ) |
|
193 { |
|
194 SmcDefaultValue<const TPEAudioOutput&>::SetL( EPEWiredAudioAccessory ); |
|
195 iMockContext->ExpectCallL( "CPEEngineInfoImpl::AudioOutput" ).TimesL(1); |
|
196 iMockContext->ExpectCallL( "CPEEngineInfoImpl::SetAudioOutputCommand" ).TimesL(0); |
|
197 |
|
198 EUNIT_ASSERT_EQUALS( EFalse, iCPhoneAccessoryBTHandler->SetHandsfreeModeL( ETrue ) ); |
|
199 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
200 } |
|
201 |
|
202 void UT_CPhoneAccessoryBTHandler::UT_ShowBTAddressLL( ) |
|
203 { |
|
204 // dummy test. |
|
205 iMockContext->ExpectCallL( "CPhoneViewCommandHandleMock::ExecuteCommandL" ). |
|
206 WithL( EPhoneViewClearNumberEntryContent ); |
|
207 |
|
208 TPhoneCmdParamNote noteParam; |
|
209 noteParam.SetType( EPhoneNoteCustom ); |
|
210 iMockContext->ExpectCallL( "CPhoneViewCommandHandleMock::ExecuteCommandL" ). |
|
211 WithL<TPhoneViewCommandId, TPhoneCommandParam&> ( EPhoneViewShowNote, noteParam ); |
|
212 |
|
213 iCPhoneAccessoryBTHandler->ShowBTAddressL(); |
|
214 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
215 } |
|
216 |
|
217 void UT_CPhoneAccessoryBTHandler::UT_ShowBTLoopbackL( ) |
|
218 { |
|
219 // dummy test. |
|
220 iMockContext->ExpectCallL( "CPhoneViewCommandHandleMock::ExecuteCommandL" ). |
|
221 WithL( EPhoneViewClearNumberEntryContent ); |
|
222 |
|
223 TPhoneCmdParamNote noteParam; |
|
224 noteParam.SetType( EPhoneNoteCustom ); |
|
225 iMockContext->ExpectCallL( "CPhoneViewCommandHandleMock::ExecuteCommandL" ). |
|
226 WithL<TPhoneViewCommandId, TPhoneCommandParam&> ( EPhoneViewShowNote, noteParam ); |
|
227 |
|
228 iCPhoneAccessoryBTHandler->ShowBTLoopbackL(); |
|
229 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
230 } |
|
231 |
|
232 void UT_CPhoneAccessoryBTHandler::UT_ShowBTActivatedL( ) |
|
233 { |
|
234 // dummy test. |
|
235 TPhoneCmdParamNote noteParam; |
|
236 noteParam.SetType( EPhoneNoteConfirmation ); |
|
237 iMockContext->ExpectCallL( "CPhoneViewCommandHandleMock::ExecuteCommandL" ). |
|
238 WithL<TPhoneViewCommandId, TPhoneCommandParam&> ( EPhoneViewShowNote, noteParam ); |
|
239 |
|
240 iCPhoneAccessoryBTHandler->ShowBTActivatedL(); |
|
241 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
242 } |
|
243 |
|
244 // - EUnit test table ------------------------------------------------------- |
|
245 |
|
246 EUNIT_BEGIN_TEST_TABLE( |
|
247 UT_CPhoneAccessoryBTHandler, |
|
248 "Add test suite description here.", |
|
249 "UNIT" ) |
|
250 |
|
251 EUNIT_TEST( |
|
252 "SetBTHandsfreeModeL_ONL - test1", |
|
253 "CPhoneAccessoryBTHandler", |
|
254 "SetBTHandsfreeModeL_ONL - test1", |
|
255 "FUNCTIONALITY", |
|
256 SetupL, UT_SetBTHandsfreeModeL_ONL, Teardown) |
|
257 |
|
258 EUNIT_TEST( |
|
259 "SetBTHandsfreeModeL_OFFL - test2", |
|
260 "CPhoneAccessoryBTHandler", |
|
261 "SetBTHandsfreeModeL_OFFL - test2", |
|
262 "FUNCTIONALITY", |
|
263 SetupL, UT_SetBTHandsfreeModeL_OFFL, Teardown) |
|
264 |
|
265 EUNIT_TEST( |
|
266 "SetBTHandsfreeModeL_ON_AudioRoutedToWiredAudioAccessoryL - test3", |
|
267 "CPhoneAccessoryBTHandler", |
|
268 "SetBTHandsfreeModeL_ON_AudioRoutedToWiredAudioAccessoryL - test3", |
|
269 "FUNCTIONALITY", |
|
270 SetupL, UT_SetBTHandsfreeModeL_ON_AudioRoutedToWiredAudioAccessoryL, Teardown) |
|
271 |
|
272 EUNIT_TEST( |
|
273 "SetHandsfreeModeL_ONL - test4", |
|
274 "CPhoneAccessoryBTHandler", |
|
275 "SetHandsfreeModeL_ONL - test4", |
|
276 "FUNCTIONALITY", |
|
277 SetupL, UT_SetHandsfreeModeL_ONL, Teardown) |
|
278 |
|
279 EUNIT_TEST( |
|
280 "SetHandsfreeModeL_OFFL - test5", |
|
281 "CPhoneAccessoryBTHandler", |
|
282 "SetHandsfreeModeL_OFFL - test5", |
|
283 "FUNCTIONALITY", |
|
284 SetupL, UT_SetHandsfreeModeL_OFFL, Teardown) |
|
285 |
|
286 EUNIT_TEST( |
|
287 "SetHandsfreeModeL_ON_AudioRoutedToWiredAudioAccessoryL - test6", |
|
288 "CPhoneAccessoryBTHandler", |
|
289 "SetHandsfreeModeL_ON_AudioRoutedToWiredAudioAccessoryL - test6", |
|
290 "FUNCTIONALITY", |
|
291 SetupL, UT_SetHandsfreeModeL_ON_AudioRoutedToWiredAudioAccessoryL, Teardown) |
|
292 |
|
293 EUNIT_TEST( |
|
294 "ShowBTAddressLL - test7", |
|
295 "CPhoneAccessoryBTHandler", |
|
296 "ShowBTAddressLL - test7", |
|
297 "FUNCTIONALITY", |
|
298 SetupL, UT_ShowBTAddressLL, Teardown) |
|
299 |
|
300 EUNIT_TEST( |
|
301 "ShowBTLoopbackL - test8", |
|
302 "CPhoneAccessoryBTHandler", |
|
303 "ShowBTLoopbackL - test8", |
|
304 "FUNCTIONALITY", |
|
305 SetupL, UT_ShowBTLoopbackL, Teardown) |
|
306 |
|
307 EUNIT_TEST( |
|
308 "ShowBTActivatedL - test9", |
|
309 "CPhoneAccessoryBTHandler", |
|
310 "ShowBTActivatedL - test9", |
|
311 "FUNCTIONALITY", |
|
312 SetupL, UT_ShowBTActivatedL, Teardown) |
|
313 |
|
314 EUNIT_END_TEST_TABLE |