74
|
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,
|
76
|
102 |
iStateMachineMock );
|
74
|
103 |
|
|
104 |
}
|
|
105 |
|
|
106 |
void UT_CPhoneAccessoryBTHandler::Teardown( )
|
|
107 |
{
|
|
108 |
delete iCPhoneMainResourceResolverMock;
|
|
109 |
iCPhoneMainResourceResolverMock = NULL;
|
|
110 |
|
|
111 |
CleanupStack::PopAndDestroy( iCPhoneAccessoryBTHandler );
|
|
112 |
iCPhoneAccessoryBTHandler = NULL;
|
|
113 |
|
|
114 |
delete iViewCmdHandleMock;
|
|
115 |
iViewCmdHandleMock = NULL;
|
|
116 |
|
|
117 |
delete iStateMachineMock;
|
|
118 |
iStateMachineMock = NULL;
|
|
119 |
|
|
120 |
delete iCoeEnvMock;
|
|
121 |
iCoeEnvMock = NULL;
|
|
122 |
SmcDefaultValue<CCoeEnv*>::Reset();
|
|
123 |
|
|
124 |
delete iEngineInfoMock;
|
|
125 |
iEngineInfoMock = NULL;
|
|
126 |
|
|
127 |
SmcDefaultValue<const TPEAudioOutput&>::Reset();
|
|
128 |
|
|
129 |
iMockContext->Reset();
|
|
130 |
}
|
|
131 |
|
|
132 |
void UT_CPhoneAccessoryBTHandler::HandleNumberEntryClearedL()
|
|
133 |
{
|
|
134 |
iEntryCleared = ETrue;
|
|
135 |
}
|
|
136 |
|
|
137 |
void UT_CPhoneAccessoryBTHandler::UT_SetBTHandsfreeModeL_ONL( )
|
|
138 |
{
|
|
139 |
iMockContext->ExpectCallL( "CPEEngineInfoImpl::AudioOutput" );
|
|
140 |
iMockContext->ExpectCallL( "CPEEngineInfoImpl::SetAudioOutputCommand" ).
|
|
141 |
WithL<TPEAudioOutput, TInt>(EPEBTAudioAccessory, ETrue);
|
|
142 |
iCPhoneAccessoryBTHandler->SetBTHandsfreeModeL(ETrue );
|
|
143 |
|
|
144 |
EUNIT_ASSERT_EQUALS( ETrue, iCPhoneAccessoryBTHandler->SetBTHandsfreeModeL( ETrue ) );
|
|
145 |
EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() );
|
|
146 |
}
|
|
147 |
|
|
148 |
void UT_CPhoneAccessoryBTHandler::UT_SetBTHandsfreeModeL_OFFL( )
|
|
149 |
{
|
|
150 |
iMockContext->ExpectCallL( "CPEEngineInfoImpl::AudioOutput" );
|
|
151 |
iMockContext->ExpectCallL( "CPEEngineInfoImpl::SetAudioOutputCommand" ).
|
|
152 |
WithL<TPEAudioOutput, TInt>(EPEHandset, EFalse);
|
|
153 |
|
|
154 |
EUNIT_ASSERT_EQUALS( ETrue, iCPhoneAccessoryBTHandler->SetBTHandsfreeModeL( EFalse ) );
|
|
155 |
EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() );
|
|
156 |
}
|
|
157 |
|
|
158 |
void UT_CPhoneAccessoryBTHandler::UT_SetBTHandsfreeModeL_ON_AudioRoutedToWiredAudioAccessoryL( )
|
|
159 |
{
|
|
160 |
SmcDefaultValue<const TPEAudioOutput&>::SetL( EPEWiredAudioAccessory );
|
|
161 |
iMockContext->ExpectCallL( "CPEEngineInfoImpl::AudioOutput" ).TimesL(1);
|
|
162 |
iMockContext->ExpectCallL( "CPEEngineInfoImpl::SetAudioOutputCommand" ).TimesL(0);
|
|
163 |
|
|
164 |
EUNIT_ASSERT_EQUALS( EFalse, iCPhoneAccessoryBTHandler->SetBTHandsfreeModeL( ETrue ) );
|
|
165 |
EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() );
|
|
166 |
}
|
|
167 |
|
|
168 |
void UT_CPhoneAccessoryBTHandler::UT_SetHandsfreeModeL_ONL( )
|
|
169 |
{
|
|
170 |
iMockContext->ExpectCallL( "CPEEngineInfoImpl::AudioOutput" ).
|
|
171 |
ReturnsL( EPENotActive );
|
|
172 |
iMockContext->ExpectCallL( "CPEEngineInfoImpl::SetAudioOutputCommand" ).
|
|
173 |
WithL<TPEAudioOutput, TInt>(EPELoudspeaker, ETrue);
|
|
174 |
iCPhoneAccessoryBTHandler->SetBTHandsfreeModeL( ETrue );
|
|
175 |
|
|
176 |
EUNIT_ASSERT_EQUALS( ETrue, iCPhoneAccessoryBTHandler->SetHandsfreeModeL( ETrue ) );
|
|
177 |
EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() );
|
|
178 |
}
|
|
179 |
|
|
180 |
void UT_CPhoneAccessoryBTHandler::UT_SetHandsfreeModeL_OFFL( )
|
|
181 |
{
|
|
182 |
iMockContext->ExpectCallL( "CPEEngineInfoImpl::AudioOutput" ).
|
|
183 |
ReturnsL( EPENotActive );
|
|
184 |
iMockContext->ExpectCallL( "CPEEngineInfoImpl::SetAudioOutputCommand" ).
|
|
185 |
WithL<TPEAudioOutput, TInt>(EPEHandset, EFalse);
|
|
186 |
|
|
187 |
EUNIT_ASSERT_EQUALS( ETrue, iCPhoneAccessoryBTHandler->SetHandsfreeModeL( EFalse ) );
|
|
188 |
EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() );
|
|
189 |
}
|
|
190 |
|
|
191 |
void UT_CPhoneAccessoryBTHandler::UT_SetHandsfreeModeL_ON_AudioRoutedToWiredAudioAccessoryL( )
|
|
192 |
{
|
|
193 |
SmcDefaultValue<const TPEAudioOutput&>::SetL( EPEWiredAudioAccessory );
|
|
194 |
iMockContext->ExpectCallL( "CPEEngineInfoImpl::AudioOutput" ).TimesL(1);
|
|
195 |
iMockContext->ExpectCallL( "CPEEngineInfoImpl::SetAudioOutputCommand" ).TimesL(0);
|
|
196 |
|
|
197 |
EUNIT_ASSERT_EQUALS( EFalse, iCPhoneAccessoryBTHandler->SetHandsfreeModeL( ETrue ) );
|
|
198 |
EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() );
|
|
199 |
}
|
|
200 |
|
|
201 |
void UT_CPhoneAccessoryBTHandler::UT_ShowBTAddressLL( )
|
|
202 |
{
|
|
203 |
// dummy test.
|
|
204 |
iMockContext->ExpectCallL( "CPhoneViewCommandHandleMock::ExecuteCommandL" ).
|
|
205 |
WithL( EPhoneViewClearNumberEntryContent );
|
|
206 |
|
|
207 |
TPhoneCmdParamNote noteParam;
|
|
208 |
noteParam.SetType( EPhoneNoteCustom );
|
|
209 |
iMockContext->ExpectCallL( "CPhoneViewCommandHandleMock::ExecuteCommandL" ).
|
|
210 |
WithL<TPhoneViewCommandId, TPhoneCommandParam&> ( EPhoneViewShowNote, noteParam );
|
|
211 |
|
|
212 |
iCPhoneAccessoryBTHandler->ShowBTAddressL();
|
|
213 |
EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() );
|
|
214 |
}
|
|
215 |
|
|
216 |
void UT_CPhoneAccessoryBTHandler::UT_ShowBTLoopbackL( )
|
|
217 |
{
|
|
218 |
// dummy test.
|
|
219 |
iMockContext->ExpectCallL( "CPhoneViewCommandHandleMock::ExecuteCommandL" ).
|
|
220 |
WithL( EPhoneViewClearNumberEntryContent );
|
|
221 |
|
|
222 |
TPhoneCmdParamNote noteParam;
|
|
223 |
noteParam.SetType( EPhoneNoteCustom );
|
|
224 |
iMockContext->ExpectCallL( "CPhoneViewCommandHandleMock::ExecuteCommandL" ).
|
|
225 |
WithL<TPhoneViewCommandId, TPhoneCommandParam&> ( EPhoneViewShowNote, noteParam );
|
|
226 |
|
|
227 |
iCPhoneAccessoryBTHandler->ShowBTLoopbackL();
|
|
228 |
EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() );
|
|
229 |
}
|
|
230 |
|
|
231 |
void UT_CPhoneAccessoryBTHandler::UT_ShowBTActivatedL( )
|
|
232 |
{
|
|
233 |
// dummy test.
|
|
234 |
TPhoneCmdParamNote noteParam;
|
|
235 |
noteParam.SetType( EPhoneNoteConfirmation );
|
|
236 |
iMockContext->ExpectCallL( "CPhoneViewCommandHandleMock::ExecuteCommandL" ).
|
|
237 |
WithL<TPhoneViewCommandId, TPhoneCommandParam&> ( EPhoneViewShowNote, noteParam );
|
|
238 |
|
|
239 |
iCPhoneAccessoryBTHandler->ShowBTActivatedL();
|
|
240 |
EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() );
|
|
241 |
}
|
|
242 |
|
|
243 |
// - EUnit test table -------------------------------------------------------
|
|
244 |
|
|
245 |
EUNIT_BEGIN_TEST_TABLE(
|
|
246 |
UT_CPhoneAccessoryBTHandler,
|
|
247 |
"Add test suite description here.",
|
|
248 |
"UNIT" )
|
|
249 |
|
|
250 |
EUNIT_TEST(
|
|
251 |
"SetBTHandsfreeModeL_ONL - test1",
|
|
252 |
"CPhoneAccessoryBTHandler",
|
|
253 |
"SetBTHandsfreeModeL_ONL - test1",
|
|
254 |
"FUNCTIONALITY",
|
|
255 |
SetupL, UT_SetBTHandsfreeModeL_ONL, Teardown)
|
|
256 |
|
|
257 |
EUNIT_TEST(
|
|
258 |
"SetBTHandsfreeModeL_OFFL - test2",
|
|
259 |
"CPhoneAccessoryBTHandler",
|
|
260 |
"SetBTHandsfreeModeL_OFFL - test2",
|
|
261 |
"FUNCTIONALITY",
|
|
262 |
SetupL, UT_SetBTHandsfreeModeL_OFFL, Teardown)
|
|
263 |
|
|
264 |
EUNIT_TEST(
|
|
265 |
"SetBTHandsfreeModeL_ON_AudioRoutedToWiredAudioAccessoryL - test3",
|
|
266 |
"CPhoneAccessoryBTHandler",
|
|
267 |
"SetBTHandsfreeModeL_ON_AudioRoutedToWiredAudioAccessoryL - test3",
|
|
268 |
"FUNCTIONALITY",
|
|
269 |
SetupL, UT_SetBTHandsfreeModeL_ON_AudioRoutedToWiredAudioAccessoryL, Teardown)
|
|
270 |
|
|
271 |
EUNIT_TEST(
|
|
272 |
"SetHandsfreeModeL_ONL - test4",
|
|
273 |
"CPhoneAccessoryBTHandler",
|
|
274 |
"SetHandsfreeModeL_ONL - test4",
|
|
275 |
"FUNCTIONALITY",
|
|
276 |
SetupL, UT_SetHandsfreeModeL_ONL, Teardown)
|
|
277 |
|
|
278 |
EUNIT_TEST(
|
|
279 |
"SetHandsfreeModeL_OFFL - test5",
|
|
280 |
"CPhoneAccessoryBTHandler",
|
|
281 |
"SetHandsfreeModeL_OFFL - test5",
|
|
282 |
"FUNCTIONALITY",
|
|
283 |
SetupL, UT_SetHandsfreeModeL_OFFL, Teardown)
|
|
284 |
|
|
285 |
EUNIT_TEST(
|
|
286 |
"SetHandsfreeModeL_ON_AudioRoutedToWiredAudioAccessoryL - test6",
|
|
287 |
"CPhoneAccessoryBTHandler",
|
|
288 |
"SetHandsfreeModeL_ON_AudioRoutedToWiredAudioAccessoryL - test6",
|
|
289 |
"FUNCTIONALITY",
|
|
290 |
SetupL, UT_SetHandsfreeModeL_ON_AudioRoutedToWiredAudioAccessoryL, Teardown)
|
|
291 |
|
|
292 |
EUNIT_TEST(
|
|
293 |
"ShowBTAddressLL - test7",
|
|
294 |
"CPhoneAccessoryBTHandler",
|
|
295 |
"ShowBTAddressLL - test7",
|
|
296 |
"FUNCTIONALITY",
|
|
297 |
SetupL, UT_ShowBTAddressLL, Teardown)
|
|
298 |
|
|
299 |
EUNIT_TEST(
|
|
300 |
"ShowBTLoopbackL - test8",
|
|
301 |
"CPhoneAccessoryBTHandler",
|
|
302 |
"ShowBTLoopbackL - test8",
|
|
303 |
"FUNCTIONALITY",
|
|
304 |
SetupL, UT_ShowBTLoopbackL, Teardown)
|
|
305 |
|
|
306 |
EUNIT_TEST(
|
|
307 |
"ShowBTActivatedL - test9",
|
|
308 |
"CPhoneAccessoryBTHandler",
|
|
309 |
"ShowBTActivatedL - test9",
|
|
310 |
"FUNCTIONALITY",
|
|
311 |
SetupL, UT_ShowBTActivatedL, Teardown)
|
|
312 |
|
|
313 |
EUNIT_END_TEST_TABLE
|