|
1 /* |
|
2 * Copyright (c) 2010 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 ----------------------------------------------------------------------------- |
|
19 This file has been generated with EUnit Pro |
|
20 http://www.digia.com/eunit |
|
21 ----------------------------------------------------------------------------- |
|
22 */ |
|
23 |
|
24 #include <coemain.h> |
|
25 #include <EUnitMacros.h> |
|
26 #include <EUnitDecorators.h> |
|
27 |
|
28 #include <csmcmockcontext.h> |
|
29 #include <msmcmockspecbuilder.h> |
|
30 #include <pevirtualengine.h> |
|
31 |
|
32 #include "ut_cphonegeneralgsmmessageshandler.h" |
|
33 #include "cphonegeneralgsmmessageshandler.h" |
|
34 #include "CPhoneStateMachineGSM.h" |
|
35 #include "mock_cphoneviewcommandhandle.h" |
|
36 #include "cphonemainresourceresolver.h" |
|
37 #include "cphonestate.h" |
|
38 #include "TPhoneCmdParamBoolean.h" |
|
39 #include "TPhoneCmdParamInteger.h" |
|
40 #include "TPhoneCmdParamKeyEvent.h" |
|
41 #include "TPhoneCmdParamGlobalNote.h" |
|
42 #include "TPhoneCmdParamKeyEvent.h" |
|
43 #include "apgtask.h" |
|
44 |
|
45 // needed for mocking CPhoneMainResourceResolver::Instance() |
|
46 class CPhoneMainResourceResolverMock : public CPhoneMainResourceResolver |
|
47 { |
|
48 |
|
49 }; |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // operator for comparing parameter expected and result value. |
|
53 // - |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 // this is set true if there is no need check param id value. |
|
57 TBool doNotCheckParamId( EFalse ); |
|
58 |
|
59 TBool operator==(const TPhoneCommandParam& param1, const TPhoneCommandParam& param2 ) |
|
60 { |
|
61 TBool ret( ETrue ); |
|
62 |
|
63 if ( param1.ParamId() == param2.ParamId() ) |
|
64 { |
|
65 |
|
66 if ( TPhoneCommandParam::EPhoneParamIdInteger == param1.ParamId() ) |
|
67 { |
|
68 const TPhoneCmdParamInteger &value1 = static_cast<const TPhoneCmdParamInteger&> (param1); |
|
69 const TPhoneCmdParamInteger &value2 = static_cast<const TPhoneCmdParamInteger&> (param2); |
|
70 if ( value1.Integer() != value2.Integer() ) |
|
71 { |
|
72 ret = EFalse; |
|
73 } |
|
74 }/* |
|
75 else if ( TPhoneCommandParam::EPhoneParamIdKeyEvent == param1.ParamId() ) |
|
76 { |
|
77 const TPhoneCmdParamKeyEvent &value1 = static_cast<const TPhoneCmdParamKeyEvent&> (param1); |
|
78 const TPhoneCmdParamKeyEvent &value2 = static_cast<const TPhoneCmdParamKeyEvent&> (param2); |
|
79 if ( value1.EventCode() != value2.EventCode() ) |
|
80 { |
|
81 ret = EFalse; |
|
82 } |
|
83 }*/ |
|
84 else if ( TPhoneCommandParam::EPhoneParamIdGlobalNote == param1.ParamId() ) |
|
85 { |
|
86 const TPhoneCmdParamGlobalNote &value1 = static_cast<const TPhoneCmdParamGlobalNote&> (param1); |
|
87 const TPhoneCmdParamGlobalNote &value2 = static_cast<const TPhoneCmdParamGlobalNote&> (param2); |
|
88 if ( value1.Type() != value2.Type() ) |
|
89 { |
|
90 ret = EFalse; |
|
91 } |
|
92 } |
|
93 else if ( TPhoneCommandParam::EPhoneParamIdBoolean == param1.ParamId() && !doNotCheckParamId ) |
|
94 { |
|
95 const TPhoneCmdParamBoolean &value1 = static_cast<const TPhoneCmdParamBoolean&> (param1); |
|
96 const TPhoneCmdParamBoolean &value2 = static_cast<const TPhoneCmdParamBoolean&> (param2); |
|
97 if ( value1.Boolean() != value2.Boolean() ) |
|
98 { |
|
99 ret = EFalse; |
|
100 } |
|
101 } |
|
102 else |
|
103 { |
|
104 ret = ETrue; // just paramiId compared |
|
105 } |
|
106 } |
|
107 return ret; |
|
108 } |
|
109 |
|
110 // - Construction ----------------------------------------------------------- |
|
111 |
|
112 ut_cphonegeneralgsmmessageshandler* ut_cphonegeneralgsmmessageshandler::NewL() |
|
113 { |
|
114 ut_cphonegeneralgsmmessageshandler* self = ut_cphonegeneralgsmmessageshandler::NewLC(); |
|
115 CleanupStack::Pop(); |
|
116 return self; |
|
117 } |
|
118 |
|
119 ut_cphonegeneralgsmmessageshandler* ut_cphonegeneralgsmmessageshandler::NewLC() |
|
120 { |
|
121 ut_cphonegeneralgsmmessageshandler* self = new( ELeave ) ut_cphonegeneralgsmmessageshandler(); |
|
122 CleanupStack::PushL( self ); |
|
123 self->ConstructL(); |
|
124 return self; |
|
125 } |
|
126 |
|
127 ut_cphonegeneralgsmmessageshandler::~ut_cphonegeneralgsmmessageshandler() |
|
128 { |
|
129 CSmcMockContext::Release(); |
|
130 |
|
131 delete iCoeEnvMock; |
|
132 delete iCPhoneMainResourceResolverMock; |
|
133 delete iViewCommandHandleMock; |
|
134 delete iStateMachineMock; |
|
135 } |
|
136 |
|
137 ut_cphonegeneralgsmmessageshandler::ut_cphonegeneralgsmmessageshandler() |
|
138 { |
|
139 } |
|
140 |
|
141 void ut_cphonegeneralgsmmessageshandler::ConstructL() |
|
142 { |
|
143 CEUnitTestSuiteClass::ConstructL(); |
|
144 iMockContext = CSmcMockContext::InstanceL(); |
|
145 } |
|
146 |
|
147 // - Test methods ----------------------------------------------------------- |
|
148 |
|
149 |
|
150 |
|
151 void ut_cphonegeneralgsmmessageshandler::SetupL( ) |
|
152 { |
|
153 iMockContext->InitializeL(); |
|
154 |
|
155 iCoeEnvMock = new ( ELeave ) CCoeEnv(); |
|
156 SmcDefaultValue<CCoeEnv*>::SetL( iCoeEnvMock ); |
|
157 CleanupResetDefaultValuePushL<SmcDefaultValue<CCoeEnv*> >(); |
|
158 |
|
159 iCPhoneMainResourceResolverMock = new ( ELeave ) CPhoneMainResourceResolverMock(); |
|
160 SmcDefaultValue<CPhoneMainResourceResolver*>::SetL( iCPhoneMainResourceResolverMock ); |
|
161 |
|
162 iViewCommandHandleMock = new CPhoneViewCommandHandleMock(); |
|
163 iStateMachineMock = CPhoneStateMachineGSM::NewL( iViewCommandHandleMock ); |
|
164 |
|
165 iMockState = new (ELeave) CPhoneState( iStateMachineMock, NULL, NULL ); |
|
166 |
|
167 iPhoneGeneralGsmMessagesHandler = CPhoneGeneralGsmMessagesHandler::NewL( |
|
168 *iStateMachineMock, *iViewCommandHandleMock, *iMockState ); |
|
169 |
|
170 } |
|
171 |
|
172 void ut_cphonegeneralgsmmessageshandler::Teardown( ) |
|
173 { |
|
174 delete iPhoneGeneralGsmMessagesHandler; |
|
175 iPhoneGeneralGsmMessagesHandler = NULL; |
|
176 delete iMockState; |
|
177 iMockState = NULL; |
|
178 delete iStateMachineMock; |
|
179 iStateMachineMock = NULL; |
|
180 delete iViewCommandHandleMock; |
|
181 iViewCommandHandleMock = NULL; |
|
182 delete iCPhoneMainResourceResolverMock; |
|
183 iCPhoneMainResourceResolverMock = NULL; |
|
184 delete iCoeEnvMock; |
|
185 iCoeEnvMock = NULL; |
|
186 CleanupStack::PopAndDestroy(); |
|
187 SmcDefaultValue<CPhoneMainResourceResolver*>::Reset(); |
|
188 iMockContext->Reset(); |
|
189 } |
|
190 |
|
191 |
|
192 void ut_cphonegeneralgsmmessageshandler::T_ConstructionL() |
|
193 { |
|
194 // SetupL and Teardown does the test. |
|
195 } |
|
196 |
|
197 void ut_cphonegeneralgsmmessageshandler::T_HandlePhoneEngineMessageL_EPEMessageIssuingSSRequest_L() |
|
198 { |
|
199 iMockContext->ExpectCallL("CPhoneStateMachine::SendPhoneEngineMessage").WithL( MPEPhoneModel::EPEMessageEndDTMF ); |
|
200 |
|
201 iMockContext->ExpectCallL("CPhoneViewCommandHandleMock::ExecuteCommandL"). |
|
202 WithL( EPhoneViewRemoveQuery ); |
|
203 |
|
204 iPhoneGeneralGsmMessagesHandler->HandlePhoneEngineMessageL( MEngineMonitor::EPEMessageIssuingSSRequest, -1 ); |
|
205 |
|
206 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
207 } |
|
208 |
|
209 void ut_cphonegeneralgsmmessageshandler::T_HandlePhoneEngineMessageL_EPEMessageIssuedSSRequest_L() |
|
210 { |
|
211 iMockContext->ExpectCallL("CPhoneViewCommandHandleMock::ExecuteCommandL").TimesL(0); |
|
212 |
|
213 iPhoneGeneralGsmMessagesHandler->HandlePhoneEngineMessageL( MEngineMonitor::EPEMessageIssuedSSRequest, -1 ); |
|
214 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
215 } |
|
216 |
|
217 // - EUnit test table ------------------------------------------------------- |
|
218 |
|
219 EUNIT_BEGIN_TEST_TABLE( |
|
220 ut_cphonegeneralgsmmessageshandler, |
|
221 "Add test suite description here.", |
|
222 "UNIT" ) |
|
223 |
|
224 EUNIT_TEST( |
|
225 "Construction", |
|
226 "CPhoneGeneralGsmMessagesHandler", |
|
227 "test1", |
|
228 "FUNCTIONALITY", |
|
229 SetupL, T_ConstructionL, Teardown) |
|
230 |
|
231 EUNIT_TEST( |
|
232 "HandlePhoneEngineMessageL EPEMessageIssuingSSRequest", |
|
233 "CPhoneGeneralGsmMessagesHandler", |
|
234 "test2", |
|
235 "FUNCTIONALITY", |
|
236 SetupL, T_HandlePhoneEngineMessageL_EPEMessageIssuingSSRequest_L, Teardown) |
|
237 |
|
238 EUNIT_TEST( |
|
239 "HandlePhoneEngineMessageL EPEMessageIssuedSSRequest", |
|
240 "CPhoneGeneralGsmMessagesHandler", |
|
241 "test2", |
|
242 "FUNCTIONALITY", |
|
243 SetupL, T_HandlePhoneEngineMessageL_EPEMessageIssuedSSRequest_L, Teardown) |
|
244 |
|
245 EUNIT_END_TEST_TABLE |