|
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 <csmcmockcontext.h> |
|
19 #include <smcdefaultvalue.h> |
|
20 #include <msmcmockspecbuilder.h> |
|
21 #include <smcobjecttotypemapper.h> |
|
22 #include <EUnitMacros.h> |
|
23 #include <EUnitDecorators.h> |
|
24 #include <featmgr.h> |
|
25 #include "CPhoneMainResourceResolver.h" |
|
26 #include "CPhoneStateMachineGSM.h" |
|
27 #include "mock_cphoneviewcommandhandle.h" |
|
28 #include "PEVirtualEngine.h" |
|
29 #include "MPhoneKeyEvents.h" |
|
30 #include "TPhoneCommandParam.h" |
|
31 #include "TPhoneCmdParamCallHeaderData.h" |
|
32 #include "TPhoneCmdParamAudioOutput.h" |
|
33 #include "cpeengineinfo.h" |
|
34 #include "phonerssbase.h" |
|
35 #include "phonestatedefinitionsgsm.h" |
|
36 #include "TPhoneCmdParamInteger.h" |
|
37 #include "TPhoneCmdParamCallStateData.h" |
|
38 #include "TelephonyVariant.hrh" |
|
39 |
|
40 #include "CPhoneIncoming.h" |
|
41 #include "ut_cphoneincoming.h" |
|
42 |
|
43 // needed for mocking CPhoneMainResourceResolver::Instance() |
|
44 class CPhoneMainResourceResolverMock : public CPhoneMainResourceResolver |
|
45 { |
|
46 }; |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // operator for comparing parameter expected and result value. |
|
50 // - |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 TBool operator==(const TPhoneCommandParam& param1, const TPhoneCommandParam& param2 ) |
|
54 { |
|
55 TBool ret( ETrue ); |
|
56 |
|
57 if ( param1.ParamId() == param2.ParamId() ) |
|
58 { |
|
59 |
|
60 if ( TPhoneCommandParam::EPhoneParamIdInteger == param1.ParamId() ) |
|
61 { |
|
62 const TPhoneCmdParamInteger &value1 = static_cast<const TPhoneCmdParamInteger&> (param1); |
|
63 const TPhoneCmdParamInteger &value2 = static_cast<const TPhoneCmdParamInteger&> (param2); |
|
64 if ( value1.Integer() != value2.Integer() ) |
|
65 { |
|
66 ret = EFalse; |
|
67 } |
|
68 } |
|
69 else |
|
70 { |
|
71 ret = ETrue; // just paramiId compared |
|
72 } |
|
73 } |
|
74 return ret; |
|
75 } |
|
76 |
|
77 |
|
78 // - Construction ----------------------------------------------------------- |
|
79 |
|
80 ut_cphoneincoming* ut_cphoneincoming::NewL() |
|
81 { |
|
82 ut_cphoneincoming* self = ut_cphoneincoming::NewLC(); |
|
83 CleanupStack::Pop(); |
|
84 return self; |
|
85 } |
|
86 |
|
87 ut_cphoneincoming* ut_cphoneincoming::NewLC() |
|
88 { |
|
89 ut_cphoneincoming* self = new( ELeave ) ut_cphoneincoming(); |
|
90 CleanupStack::PushL( self ); |
|
91 self->ConstructL(); |
|
92 return self; |
|
93 } |
|
94 |
|
95 ut_cphoneincoming::~ut_cphoneincoming() |
|
96 { |
|
97 CSmcMockContext::Release(); |
|
98 } |
|
99 |
|
100 ut_cphoneincoming::ut_cphoneincoming() |
|
101 { |
|
102 } |
|
103 |
|
104 void ut_cphoneincoming::ConstructL() |
|
105 { |
|
106 CEUnitTestSuiteClass::ConstructL(); |
|
107 iMockContext = CSmcMockContext::InstanceL(); |
|
108 } |
|
109 |
|
110 // - Test methods ----------------------------------------------------------- |
|
111 |
|
112 |
|
113 |
|
114 void ut_cphoneincoming::SetupL( ) |
|
115 { |
|
116 iMockContext->InitializeL(); |
|
117 |
|
118 iCPhoneMainResourceResolverMock = new ( ELeave ) CPhoneMainResourceResolverMock(); |
|
119 SmcDefaultValue<CPhoneMainResourceResolver*>::SetL( iCPhoneMainResourceResolverMock ); |
|
120 |
|
121 iViewCmdHandleMock = new CPhoneViewCommandHandleMock(); |
|
122 |
|
123 iStateMachineMock = CPhoneStateMachineGSM::NewL( iViewCmdHandleMock ); |
|
124 |
|
125 iStateIncoming = CPhoneIncoming::NewL( |
|
126 iStateMachineMock, iViewCmdHandleMock, NULL ); |
|
127 |
|
128 iEngineInfoMock = CPEEngineInfo::NewL(); |
|
129 SmcDefaultValue<MPEEngineInfo*>::SetL( iEngineInfoMock ); |
|
130 |
|
131 SmcDefaultValue<TPESimState>::SetL( EPESimUsable ); |
|
132 SmcDefaultValue<const TPEAudioOutput&>::SetL( EPENotActive ); |
|
133 |
|
134 } |
|
135 |
|
136 |
|
137 void ut_cphoneincoming::Teardown( ) |
|
138 { |
|
139 delete iViewCmdHandleMock; |
|
140 iViewCmdHandleMock = NULL; |
|
141 delete iStateIncoming; |
|
142 iStateIncoming = NULL; |
|
143 delete iStateMachineMock; |
|
144 iStateMachineMock = NULL; |
|
145 delete iEngineInfoMock; |
|
146 iEngineInfoMock = NULL; |
|
147 delete iCPhoneMainResourceResolverMock; |
|
148 iCPhoneMainResourceResolverMock = NULL; |
|
149 |
|
150 SmcDefaultValue<TPESimState>::Reset(); |
|
151 SmcDefaultValue<const TPEAudioOutput&>::Reset(); |
|
152 |
|
153 iMockContext->Reset(); |
|
154 } |
|
155 |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // Test ss request |
|
159 // -check commands |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void ut_cphoneincoming::T_HandleWaiting() |
|
163 { |
|
164 iMockContext->ExpectCallL( "TPhoneCmdParamCallStateData::CallId" ). |
|
165 ReturnsL( 1 ); |
|
166 iMockContext->ExpectCallL( "CPhoneStateMachine::ChangeState" ). |
|
167 WithL( EPhoneStateWaitingInSingle ); |
|
168 |
|
169 iStateIncoming->HandlePhoneEngineMessageL( MEngineMonitor::EPEMessageIncoming, 2 ); |
|
170 iStateIncoming->HandlePhoneEngineMessageL( MEngineMonitor::EPEMessageConnected,1 ); |
|
171 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
172 |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // Test error handling |
|
177 // -check commands |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 void ut_cphoneincoming::T_HandleError_IsNotForwardedToBaseClassL() |
|
181 { |
|
182 TPEErrorInfo aErrorInfo; |
|
183 aErrorInfo.iErrorCode = ECCPErrorCCUserAlertingNoAnswer; |
|
184 iMockContext->ExpectCallL( "CPhoneState::HandleErrorL" ). |
|
185 TimesL( 0 ); |
|
186 |
|
187 iStateIncoming->HandleErrorL( aErrorInfo ); |
|
188 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // Test error handling |
|
193 // -check commands |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 void ut_cphoneincoming::T_HandleError_ForwardedToBaseClassL() |
|
197 { |
|
198 TPEErrorInfo aErrorInfo; |
|
199 aErrorInfo.iErrorCode = ECCPErrorCCCallRejected; |
|
200 iMockContext->ExpectCallL( "CPhoneState::HandleErrorL" ). |
|
201 TimesL( 1 ); |
|
202 |
|
203 iStateIncoming->HandleErrorL( aErrorInfo ); |
|
204 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
205 } |
|
206 |
|
207 |
|
208 // - EUnit test table ------------------------------------------------------- |
|
209 |
|
210 EUNIT_BEGIN_TEST_TABLE( |
|
211 ut_cphoneincoming, |
|
212 "Add test suite description here.", |
|
213 "UNIT" ) |
|
214 |
|
215 EUNIT_TEST( |
|
216 "1- Test waiting", |
|
217 "", |
|
218 "Test1", |
|
219 "FUNCTIONALITY", |
|
220 SetupL, T_HandleWaiting, Teardown) |
|
221 |
|
222 EUNIT_TEST( |
|
223 "2- Test error", |
|
224 "", |
|
225 "Test2", |
|
226 "FUNCTIONALITY", |
|
227 SetupL, T_HandleError_IsNotForwardedToBaseClassL, Teardown) |
|
228 |
|
229 EUNIT_TEST( |
|
230 "3- Test error", |
|
231 "", |
|
232 "Test3", |
|
233 "FUNCTIONALITY", |
|
234 SetupL, T_HandleError_ForwardedToBaseClassL, Teardown) |
|
235 |
|
236 |
|
237 EUNIT_END_TEST_TABLE |