|
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 #include <csmcmockcontext.h> |
|
18 #include <smcdefaultvalue.h> |
|
19 #include <msmcmockspecbuilder.h> |
|
20 #include <smcobjecttotypemapper.h> |
|
21 #include <EUnitMacros.h> |
|
22 #include <EUnitDecorators.h> |
|
23 #include <featmgr.h> |
|
24 |
|
25 #include "cphonestatemachinegsm.h" |
|
26 #include "ut_cphonestatestartup.h" |
|
27 #include "cphonestatestartup.h" |
|
28 #include "cphonemainresourceresolver.h" |
|
29 #include "pevirtualengine.h" |
|
30 #include "mphonekeyevents.h" |
|
31 #include "tphonecommandparam.h" |
|
32 #include "tphonecmdparamcallheaderdata.h" |
|
33 #include "tphonecmdparamaudiooutput.h" |
|
34 #include "cpeengineinfo.h" |
|
35 #include "mock_cphoneviewcommandhandle.h" |
|
36 |
|
37 //test |
|
38 #include "TPhoneCmdParamInteger.h" |
|
39 #include "tphonecmdparamboolean.h" |
|
40 |
|
41 // needed for mocking CPhoneMainResourceResolver::Instance() |
|
42 class CPhoneMainResourceResolverMock : public CPhoneMainResourceResolver |
|
43 { |
|
44 }; |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // operator for comparing parameter expected and result value. |
|
48 // - |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 TBool operator==(const TPhoneCommandParam& param1, const TPhoneCommandParam& param2 ) |
|
52 { |
|
53 TBool ret( EFalse ); |
|
54 |
|
55 if ( param1.ParamId() == param2.ParamId() ) |
|
56 { |
|
57 if ( TPhoneCommandParam::EPhoneParamIdBoolean == param1.ParamId() ) |
|
58 { |
|
59 const TPhoneCmdParamBoolean &value1 = static_cast<const TPhoneCmdParamBoolean&> (param1); |
|
60 const TPhoneCmdParamBoolean &value2 = static_cast<const TPhoneCmdParamBoolean&> (param2); |
|
61 if ( value1.Boolean() == value2.Boolean() ) |
|
62 { |
|
63 ret = ETrue; |
|
64 } |
|
65 } |
|
66 else if ( TPhoneCommandParam::EPhoneParamIdCallHeaderData == param1.ParamId() ) |
|
67 { |
|
68 const TPhoneCmdParamCallHeaderData &value1 = static_cast<const TPhoneCmdParamCallHeaderData&> (param1); |
|
69 const TPhoneCmdParamCallHeaderData &value2 = static_cast<const TPhoneCmdParamCallHeaderData&> (param2); |
|
70 if ( value1.CallState() == value2.CallState() ) |
|
71 { |
|
72 ret = ETrue; |
|
73 } |
|
74 } |
|
75 else if ( TPhoneCommandParam::EPhoneParamIdInteger == param1.ParamId() ) |
|
76 { |
|
77 const TPhoneCmdParamInteger &value1 = static_cast<const TPhoneCmdParamInteger&> (param1); |
|
78 const TPhoneCmdParamInteger &value2 = static_cast<const TPhoneCmdParamInteger&> (param2); |
|
79 if ( value1.Integer() == value2.Integer() ) |
|
80 { |
|
81 ret = ETrue; |
|
82 } |
|
83 } |
|
84 else if ( TPhoneCommandParam::EPhoneParamIdAudioOutput == param1.ParamId() ) |
|
85 { |
|
86 const TPhoneCmdParamAudioOutput &value1 = static_cast<const TPhoneCmdParamAudioOutput&> (param1); |
|
87 const TPhoneCmdParamAudioOutput &value2 = static_cast<const TPhoneCmdParamAudioOutput&> (param2); |
|
88 if ( value1.AudioOutput() == value2.AudioOutput() ) |
|
89 { |
|
90 ret = ETrue; |
|
91 } |
|
92 } |
|
93 else |
|
94 { |
|
95 ret = ETrue; // just paramiId compared |
|
96 } |
|
97 } |
|
98 return ret; |
|
99 } |
|
100 |
|
101 // - Construction ----------------------------------------------------------- |
|
102 ut_cphonestatestartup* ut_cphonestatestartup::NewL() |
|
103 { |
|
104 ut_cphonestatestartup* self = ut_cphonestatestartup::NewLC(); |
|
105 CleanupStack::Pop(); |
|
106 return self; |
|
107 } |
|
108 |
|
109 ut_cphonestatestartup* ut_cphonestatestartup::NewLC() |
|
110 { |
|
111 ut_cphonestatestartup* self = new( ELeave ) ut_cphonestatestartup(); |
|
112 CleanupStack::PushL( self ); |
|
113 self->ConstructL(); |
|
114 return self; |
|
115 } |
|
116 |
|
117 ut_cphonestatestartup::~ut_cphonestatestartup() |
|
118 { |
|
119 CSmcMockContext::Release(); |
|
120 } |
|
121 |
|
122 ut_cphonestatestartup::ut_cphonestatestartup() |
|
123 { |
|
124 } |
|
125 |
|
126 void ut_cphonestatestartup::ConstructL() |
|
127 { |
|
128 CEUnitTestSuiteClass::ConstructL(); |
|
129 iMockContext = CSmcMockContext::InstanceL(); |
|
130 } |
|
131 |
|
132 // - Test methods ----------------------------------------------------------- |
|
133 |
|
134 |
|
135 |
|
136 void ut_cphonestatestartup::SetupL( ) |
|
137 { |
|
138 iMockContext->InitializeL(); |
|
139 |
|
140 iCPhoneMainResourceResolverMock = new ( ELeave ) CPhoneMainResourceResolverMock(); |
|
141 SmcDefaultValue<CPhoneMainResourceResolver*>::SetL( iCPhoneMainResourceResolverMock ); |
|
142 |
|
143 iViewCmdHandleMock = new CPhoneViewCommandHandleMock(); |
|
144 |
|
145 iStateMachineMock = CPhoneStateMachineGSM::NewL( iViewCmdHandleMock ); |
|
146 |
|
147 // Have to be here otherwise execution will stop to ASSERT_DEBUG when |
|
148 // construct the CPhoneStateStartup-object. |
|
149 iEngineInfoMock = CPEEngineInfo::NewL(); |
|
150 SmcDefaultValue<MPEEngineInfo*>::SetL( iEngineInfoMock ); |
|
151 |
|
152 iStateStartup = CPhoneStateStartup::NewL( |
|
153 iStateMachineMock, iViewCmdHandleMock, NULL ); |
|
154 |
|
155 SmcDefaultValue<TPESimState>::SetL( EPESimStatusUninitialized ); |
|
156 SmcDefaultValue<const TPEAudioOutput&>::SetL( EPENotActive ); |
|
157 |
|
158 } |
|
159 |
|
160 |
|
161 void ut_cphonestatestartup::Teardown( ) |
|
162 { |
|
163 delete iViewCmdHandleMock; |
|
164 iViewCmdHandleMock = NULL; |
|
165 delete iStateStartup; |
|
166 iStateStartup = NULL; |
|
167 delete iStateMachineMock; |
|
168 iStateMachineMock = NULL; |
|
169 delete iEngineInfoMock; |
|
170 iEngineInfoMock = NULL; |
|
171 delete iCPhoneMainResourceResolverMock; |
|
172 iCPhoneMainResourceResolverMock = NULL; |
|
173 |
|
174 SmcDefaultValue<TPESimState>::Reset(); |
|
175 SmcDefaultValue<const TPEAudioOutput&>::Reset(); |
|
176 |
|
177 iMockContext->Reset(); |
|
178 } |
|
179 |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // ut_cphonestatestartup::T_HandleDtmfKeyToneL |
|
183 // -check commands |
|
184 // ----------------------------------------------------------------------------- |
|
185 // |
|
186 void ut_cphonestatestartup::T_HandleDtmfKeyToneL() |
|
187 { |
|
188 MPhoneState* stateStateStartup= iStateStartup; |
|
189 TKeyEvent keyEvent; |
|
190 TEventCode eventCode; |
|
191 iMockContext->ExpectCallL( "CPhoneState::HandleDtmfKeyToneL" ). |
|
192 TimesL (0); |
|
193 |
|
194 stateStateStartup->HandleDtmfKeyToneL( keyEvent, eventCode ); |
|
195 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
196 } |
|
197 |
|
198 // - EUnit test table ------------------------------------------------------- |
|
199 |
|
200 EUNIT_BEGIN_TEST_TABLE( |
|
201 ut_cphonestatestartup, |
|
202 "Add test suite description here.", |
|
203 "UNIT" ) |
|
204 |
|
205 EUNIT_TEST( |
|
206 "1- Handle Dtmf key tone method override", |
|
207 "CPhoneStateStartup", |
|
208 "Test1", |
|
209 "FUNCTIONALITY", |
|
210 SetupL, T_HandleDtmfKeyToneL, Teardown) |
|
211 |
|
212 |
|
213 EUNIT_END_TEST_TABLE |
|
214 |