|
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_CPhoneStateIncoming.h" |
|
19 #include <EUnitMacros.h> |
|
20 #include <EUnitDecorators.h> |
|
21 #include <EIKMENUP.H> |
|
22 #include <featmgr.h> |
|
23 #include "cphonemainresourceresolver.h" |
|
24 #include "mock_cphoneviewcommandhandle.h" |
|
25 #include "cphonestatemachinegsm.h" |
|
26 #include "cphonecustomizationvoip.h" |
|
27 #include "cpeengineinfo.h" |
|
28 |
|
29 #include "phoneappcommands.hrh" |
|
30 |
|
31 #include <csmcmockcontext.h> |
|
32 #include <msmcmockspecbuilder.h> |
|
33 |
|
34 // Allow testing of protected methods |
|
35 #define protected public |
|
36 #include "cphonestateincoming.h" |
|
37 // needed for mocking CPhoneMainResourceResolver::Instance() |
|
38 class CPhoneMainResourceResolverMock : public CPhoneMainResourceResolver |
|
39 { |
|
40 |
|
41 }; |
|
42 // ----------------------------------------------------------------------------- |
|
43 // operator for comparing parameter expected and result value. |
|
44 // - |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 TBool operator==(const TPhoneCommandParam& param1, const TPhoneCommandParam& param2 ) |
|
48 { |
|
49 TBool ret( EFalse ); |
|
50 if ( param1.ParamId() == param2.ParamId() ) |
|
51 { |
|
52 /*if ( TPhoneCommandParam::EPhoneParamIdCallHeaderData == param1.ParamId() ) |
|
53 { |
|
54 const TPhoneCmdParamCallHeaderData &value1 = static_cast<const TPhoneCmdParamCallHeaderData&> (param1); |
|
55 const TPhoneCmdParamCallHeaderData &value2 = static_cast<const TPhoneCmdParamCallHeaderData&> (param2); |
|
56 if ( value1.CallState() == value2.CallState() ) |
|
57 { |
|
58 ret = ETrue; |
|
59 } |
|
60 } |
|
61 else |
|
62 {*/ |
|
63 ret = ETrue; // just paramiId compared |
|
64 //} |
|
65 } |
|
66 return ret; |
|
67 } |
|
68 |
|
69 // - Construction ----------------------------------------------------------- |
|
70 |
|
71 UT_CPhoneStateIncoming* UT_CPhoneStateIncoming::NewL() |
|
72 { |
|
73 UT_CPhoneStateIncoming* self = UT_CPhoneStateIncoming::NewLC(); |
|
74 CleanupStack::Pop(); |
|
75 return self; |
|
76 } |
|
77 |
|
78 UT_CPhoneStateIncoming* UT_CPhoneStateIncoming::NewLC() |
|
79 { |
|
80 UT_CPhoneStateIncoming* self = new( ELeave ) UT_CPhoneStateIncoming(); |
|
81 CleanupStack::PushL( self ); |
|
82 self->ConstructL(); |
|
83 return self; |
|
84 } |
|
85 |
|
86 UT_CPhoneStateIncoming::~UT_CPhoneStateIncoming() |
|
87 { |
|
88 CSmcMockContext::Release(); |
|
89 } |
|
90 |
|
91 UT_CPhoneStateIncoming::UT_CPhoneStateIncoming() |
|
92 { |
|
93 } |
|
94 |
|
95 void UT_CPhoneStateIncoming::ConstructL() |
|
96 { |
|
97 CEUnitTestSuiteClass::ConstructL(); |
|
98 iMockContext = CSmcMockContext::InstanceL(); |
|
99 } |
|
100 |
|
101 // - Test methods ----------------------------------------------------------- |
|
102 |
|
103 void UT_CPhoneStateIncoming::SetupL( ) |
|
104 { |
|
105 iMockContext->InitializeL(); |
|
106 |
|
107 iCPhoneMainResourceResolverMock = new ( ELeave ) CPhoneMainResourceResolverMock(); |
|
108 SmcDefaultValue<CPhoneMainResourceResolver*>::SetL( iCPhoneMainResourceResolverMock ); |
|
109 |
|
110 iEngineInfoMock = CPEEngineInfo::NewL(); |
|
111 SmcDefaultValue<MPEEngineInfo*>::SetL( iEngineInfoMock ); |
|
112 |
|
113 iViewCmdHandleMock = new CPhoneViewCommandHandleMock(); |
|
114 iStateMachineMock = CPhoneStateMachineGSM::NewL( iViewCmdHandleMock ); |
|
115 iCustomizationMock = |
|
116 CPhoneCustomizationVoip::NewL( *iStateMachineMock, *iViewCmdHandleMock ); |
|
117 |
|
118 iCPhoneStateIncoming = CPhoneStateIncoming::NewL( |
|
119 iStateMachineMock, iViewCmdHandleMock, iCustomizationMock ); |
|
120 } |
|
121 |
|
122 |
|
123 void UT_CPhoneStateIncoming::Teardown( ) |
|
124 { |
|
125 delete iCPhoneMainResourceResolverMock; |
|
126 iCPhoneMainResourceResolverMock = NULL; |
|
127 SmcDefaultValue<CPhoneMainResourceResolver*>::Reset(); |
|
128 |
|
129 delete iEngineInfoMock; |
|
130 iEngineInfoMock = NULL; |
|
131 |
|
132 delete iCPhoneStateIncoming; |
|
133 iCPhoneStateIncoming = NULL; |
|
134 |
|
135 delete iViewCmdHandleMock; |
|
136 iViewCmdHandleMock = NULL; |
|
137 |
|
138 delete iStateMachineMock; |
|
139 iStateMachineMock = NULL; |
|
140 |
|
141 delete iCustomizationMock; |
|
142 iCustomizationMock = NULL; |
|
143 |
|
144 iMockContext->Reset(); |
|
145 } |
|
146 |
|
147 void UT_CPhoneStateIncoming::T_HandleKeyMessageL( ) |
|
148 { |
|
149 _LIT( KPhoneNumber, "12" ); |
|
150 _LIT( KPhoneNumber2, "123" ); |
|
151 HBufC* phoneNumber = KPhoneNumber().AllocLC(); |
|
152 |
|
153 iMockContext->ExpectCallL( "CPhoneNumberEntryManager::IsNumberEntryVisibleL" ). |
|
154 ReturnsL( ETrue ); |
|
155 |
|
156 iMockContext->ExpectCallL( "CPhoneNumberEntryManager::PhoneNumberFromEntryLC" ). |
|
157 ReturnsL( phoneNumber ); |
|
158 |
|
159 iMockContext->ExpectCallL( "CPEEngineInfoImpl::SetPhoneNumber" ); |
|
160 |
|
161 iMockContext->ExpectCallL( "CPhoneStateMachine::SendPhoneEngineMessage"). |
|
162 WithL( MPEPhoneModel::EPEMessagePhoneNumberEdited ); |
|
163 |
|
164 iMockContext->ExpectCallL( "CPEEngineInfoImpl::PhoneNumberIsServiceCode" ). |
|
165 ReturnsL( EFalse ); |
|
166 |
|
167 iMockContext->ExpectCallL( "CPhoneStateMachine::SendPhoneEngineMessage"). |
|
168 WithL( MPEPhoneModel::EPEMessageCheckEmergencyNumber ); |
|
169 |
|
170 iCPhoneStateIncoming->HandleKeyMessageL( |
|
171 MPhoneKeyEvents::EPhoneKeyShortPress, EKeyYes ); |
|
172 |
|
173 HBufC* phoneNumber2 = KPhoneNumber2().AllocLC(); |
|
174 |
|
175 iMockContext->ExpectCallL( "CPhoneNumberEntryManager::IsNumberEntryVisibleL" ). |
|
176 ReturnsL( ETrue ); |
|
177 |
|
178 iMockContext->ExpectCallL( "CPhoneNumberEntryManager::PhoneNumberFromEntryLC" ). |
|
179 ReturnsL( phoneNumber2 ); |
|
180 |
|
181 iMockContext->ExpectCallL( "CPEEngineInfoImpl::SetPhoneNumber" ); |
|
182 |
|
183 iMockContext->ExpectCallL( "CPhoneStateMachine::SendPhoneEngineMessage"). |
|
184 WithL( MPEPhoneModel::EPEMessagePhoneNumberEdited ); |
|
185 |
|
186 iMockContext->ExpectCallL( "CPhoneStateMachine::SendPhoneEngineMessage"). |
|
187 WithL( MPEPhoneModel::EPEMessageCheckEmergencyNumber ); |
|
188 |
|
189 iCPhoneStateIncoming->HandleKeyMessageL( |
|
190 MPhoneKeyEvents::EPhoneKeyShortPress, EKeyYes ); |
|
191 |
|
192 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
193 |
|
194 CleanupStack::Pop( phoneNumber2 ); |
|
195 CleanupStack::Pop( phoneNumber ); |
|
196 } |
|
197 |
|
198 void UT_CPhoneStateIncoming::T_HandleCommandL( ) |
|
199 { |
|
200 _LIT( KPhoneNumber, "123" ); |
|
201 HBufC* phoneNumber = KPhoneNumber().AllocLC(); |
|
202 |
|
203 iMockContext->ExpectCallL( "CPhoneNumberEntryManager::PhoneNumberFromEntryLC" ). |
|
204 ReturnsL( phoneNumber ); |
|
205 |
|
206 iMockContext->ExpectCallL( "CPEEngineInfoImpl::SetPhoneNumber" ); |
|
207 |
|
208 iMockContext->ExpectCallL( "CPhoneStateMachine::SendPhoneEngineMessage"). |
|
209 WithL( MPEPhoneModel::EPEMessagePhoneNumberEdited ); |
|
210 |
|
211 iMockContext->ExpectCallL( "CPhoneStateMachine::SendPhoneEngineMessage"). |
|
212 WithL( MPEPhoneModel::EPEMessageCheckEmergencyNumber ); |
|
213 |
|
214 iCPhoneStateIncoming->HandleCommandL(EPhoneNumberAcqCmdSendCommand ); |
|
215 |
|
216 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
217 |
|
218 CleanupStack::Pop( phoneNumber ); |
|
219 } |
|
220 |
|
221 void UT_CPhoneStateIncoming::T_HandleAudioPlayStoppedL() |
|
222 { |
|
223 iCPhoneStateIncoming->HandleAudioPlayStoppedL(); |
|
224 } |
|
225 |
|
226 void UT_CPhoneStateIncoming::T_HandleConnectedL() |
|
227 { |
|
228 const TInt callId = 1; |
|
229 iMockContext->ExpectCallL( "CPhoneViewCommandHandleMock::ExecuteCommandL" ). |
|
230 WithL( EPhoneViewStopRingTone ); |
|
231 |
|
232 // HandleConnectedL() is tested through HandlePhoneEngineMessageL() |
|
233 iCPhoneStateIncoming->HandlePhoneEngineMessageL( |
|
234 MEngineMonitor::EPEMessageConnected, callId ); |
|
235 |
|
236 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
237 } |
|
238 |
|
239 void UT_CPhoneStateIncoming::T_HandleSendKeyAnswerL() |
|
240 { |
|
241 _LIT( KPhoneNumber, "p1" ); |
|
242 HBufC* phoneNumber = KPhoneNumber().AllocLC(); |
|
243 |
|
244 iMockContext->ExpectCallL( "CPhoneNumberEntryManager::PhoneNumberFromEntryLC" ). |
|
245 ReturnsL( phoneNumber ); |
|
246 |
|
247 iMockContext->ExpectCallL( "CPEEngineInfoImpl::SetPhoneNumber" ); |
|
248 |
|
249 iMockContext->ExpectCallL( "CPhoneStateMachine::SendPhoneEngineMessage"). |
|
250 WithL( MPEPhoneModel::EPEMessagePhoneNumberEdited ); |
|
251 |
|
252 iMockContext->ExpectCallL( "CPEEngineInfoImpl::PhoneNumberIsServiceCode" ). |
|
253 ReturnsL( EFalse ); |
|
254 |
|
255 iMockContext->ExpectCallL( "CPhoneStateMachine::SendPhoneEngineMessage"). |
|
256 WithL( MPEPhoneModel::EPEMessageCheckEmergencyNumber ); |
|
257 |
|
258 |
|
259 iCPhoneStateIncoming->HandleCommandL( EPhoneNumberAcqCmdSendCommand ); |
|
260 |
|
261 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
262 CleanupStack::Pop( phoneNumber ); |
|
263 } |
|
264 |
|
265 void UT_CPhoneStateIncoming::T_HandleSendKeyRejectL() |
|
266 { |
|
267 _LIT( KPhoneNumber, "0" ); |
|
268 HBufC* phoneNumber = KPhoneNumber().AllocLC(); |
|
269 |
|
270 iMockContext->ExpectCallL( "CPhoneNumberEntryManager::PhoneNumberFromEntryLC" ). |
|
271 ReturnsL( phoneNumber ); |
|
272 |
|
273 iMockContext->ExpectCallL( "CPEEngineInfoImpl::SetPhoneNumber" ); |
|
274 |
|
275 iMockContext->ExpectCallL( "CPhoneStateMachine::SendPhoneEngineMessage"). |
|
276 WithL( MPEPhoneModel::EPEMessagePhoneNumberEdited ); |
|
277 |
|
278 iMockContext->ExpectCallL( "CPEEngineInfoImpl::PhoneNumberIsServiceCode" ). |
|
279 ReturnsL( ETrue ); |
|
280 |
|
281 iMockContext->ExpectCallL( "CPhoneNumberEntryManager::CallFromNumberEntryL" ); |
|
282 |
|
283 iCPhoneStateIncoming->HandleCommandL( EPhoneNumberAcqCmdSendCommand ); |
|
284 |
|
285 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
286 CleanupStack::Pop( phoneNumber ); |
|
287 } |
|
288 |
|
289 // - EUnit test table ------------------------------------------------------- |
|
290 |
|
291 EUNIT_BEGIN_TEST_TABLE( |
|
292 UT_CPhoneStateIncoming, |
|
293 "Add test suite description here.", |
|
294 "UNIT" ) |
|
295 |
|
296 EUNIT_TEST( |
|
297 "HandleKeyMessageL", |
|
298 "CPhoneStateIncoming", |
|
299 "HandleKeyMessageL", |
|
300 "FUNCTIONALITY", |
|
301 SetupL, T_HandleKeyMessageL, Teardown) |
|
302 |
|
303 EUNIT_TEST( |
|
304 "HandleCommandL", |
|
305 "CPhoneStateIncoming", |
|
306 "HanddleCommandL", |
|
307 "FUNCTIONALITY", |
|
308 SetupL, T_HandleCommandL, Teardown) |
|
309 |
|
310 EUNIT_TEST( |
|
311 "HandleAudioPlayStoppedL", |
|
312 "CPhoneStateIncoming", |
|
313 "HandleAudioPlayStoppedL", |
|
314 "FUNCTIONALITY", |
|
315 SetupL, T_HandleAudioPlayStoppedL, Teardown) |
|
316 |
|
317 EUNIT_TEST( |
|
318 "HandleConnectedL", |
|
319 "CPhoneStateIncoming", |
|
320 "HandleConnectedL", |
|
321 "FUNCTIONALITY", |
|
322 SetupL, T_HandleConnectedL, Teardown) |
|
323 |
|
324 EUNIT_TEST( |
|
325 "HandleSendKeyAnswerL", |
|
326 "CPhoneStateIncoming", |
|
327 "HandleSendKeyAnswerL", |
|
328 "FUNCTIONALITY", |
|
329 SetupL, T_HandleSendKeyAnswerL, Teardown) |
|
330 |
|
331 EUNIT_TEST( |
|
332 "HandleSendKeyRejectL", |
|
333 "CPhoneStateIncoming", |
|
334 "HandleSendKeyRejectL", |
|
335 "FUNCTIONALITY", |
|
336 SetupL, T_HandleSendKeyRejectL, Teardown) |
|
337 |
|
338 EUNIT_END_TEST_TABLE |