|
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 #include "ut_cphonesingleandwaiting.h" |
|
25 #include "CPhoneEmergency.h" |
|
26 #include "CPhoneMainResourceResolver.h" |
|
27 #include "CPhoneStateMachineGSM.h" |
|
28 #include "mock_cphoneviewcommandhandle.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 "phonerssbase.h" |
|
36 #include "phonestatedefinitionsgsm.h" |
|
37 #include "TPhoneCmdParamInteger.h" |
|
38 |
|
39 #include "TPhoneCmdParamCallHeaderData.h" |
|
40 #include "TPhoneCmdParamCallStateData.h" |
|
41 |
|
42 // needed for mocking CPhoneMainResourceResolver::Instance() |
|
43 class CPhoneMainResourceResolverMock : public CPhoneMainResourceResolver |
|
44 { |
|
45 }; |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // operator for comparing parameter expected and result value. |
|
49 // - |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 TBool operator==(const TPhoneCommandParam& param1, const TPhoneCommandParam& param2 ) |
|
53 { |
|
54 TBool ret( ETrue ); |
|
55 |
|
56 if ( param1.ParamId() == param2.ParamId() ) |
|
57 { |
|
58 if ( TPhoneCommandParam::EPhoneParamIdBoolean == param1.ParamId() ) |
|
59 { |
|
60 const TPhoneCmdParamBoolean &value1 = static_cast<const TPhoneCmdParamBoolean&> (param1); |
|
61 const TPhoneCmdParamBoolean &value2 = static_cast<const TPhoneCmdParamBoolean&> (param2); |
|
62 if ( value1.Boolean() != value2.Boolean() ) |
|
63 { |
|
64 ret = EFalse; |
|
65 } |
|
66 } |
|
67 else if ( TPhoneCommandParam::EPhoneParamIdInteger == param1.ParamId() ) |
|
68 { |
|
69 const TPhoneCmdParamInteger &value1 = static_cast<const TPhoneCmdParamInteger&> (param1); |
|
70 const TPhoneCmdParamInteger &value2 = static_cast<const TPhoneCmdParamInteger&> (param2); |
|
71 if ( value1.Integer() != value2.Integer() ) |
|
72 { |
|
73 ret = EFalse; |
|
74 } |
|
75 } |
|
76 else |
|
77 { |
|
78 ret = ETrue; // just paramiId compared |
|
79 } |
|
80 } |
|
81 return ret; |
|
82 } |
|
83 |
|
84 // - Construction ----------------------------------------------------------- |
|
85 |
|
86 ut_cphonesingleandwaiting* ut_cphonesingleandwaiting::NewL() |
|
87 { |
|
88 ut_cphonesingleandwaiting* self = ut_cphonesingleandwaiting::NewLC(); |
|
89 CleanupStack::Pop(); |
|
90 return self; |
|
91 } |
|
92 |
|
93 ut_cphonesingleandwaiting* ut_cphonesingleandwaiting::NewLC() |
|
94 { |
|
95 ut_cphonesingleandwaiting* self = new( ELeave ) ut_cphonesingleandwaiting(); |
|
96 CleanupStack::PushL( self ); |
|
97 self->ConstructL(); |
|
98 return self; |
|
99 } |
|
100 |
|
101 ut_cphonesingleandwaiting::~ut_cphonesingleandwaiting() |
|
102 { |
|
103 CSmcMockContext::Release(); |
|
104 } |
|
105 |
|
106 ut_cphonesingleandwaiting::ut_cphonesingleandwaiting() |
|
107 { |
|
108 } |
|
109 |
|
110 void ut_cphonesingleandwaiting::ConstructL() |
|
111 { |
|
112 CEUnitTestSuiteClass::ConstructL(); |
|
113 iMockContext = CSmcMockContext::InstanceL(); |
|
114 } |
|
115 |
|
116 // - Test methods ----------------------------------------------------------- |
|
117 |
|
118 |
|
119 |
|
120 void ut_cphonesingleandwaiting::SetupL( ) |
|
121 { |
|
122 iMockContext->InitializeL(); |
|
123 |
|
124 iCPhoneMainResourceResolverMock = new ( ELeave ) CPhoneMainResourceResolverMock(); |
|
125 SmcDefaultValue<CPhoneMainResourceResolver*>::SetL( iCPhoneMainResourceResolverMock ); |
|
126 |
|
127 iViewCmdHandleMock = new CPhoneViewCommandHandleMock(); |
|
128 |
|
129 iStateMachineMock = CPhoneStateMachineGSM::NewL( iViewCmdHandleMock ); |
|
130 |
|
131 |
|
132 iState = CPhoneSingleAndWaiting::NewL( |
|
133 iStateMachineMock, iViewCmdHandleMock, NULL ); |
|
134 |
|
135 iEngineInfoMock = CPEEngineInfo::NewL(); |
|
136 SmcDefaultValue<MPEEngineInfo*>::SetL( iEngineInfoMock ); |
|
137 |
|
138 SmcDefaultValue<TPESimState>::SetL( EPESimUsable ); |
|
139 SmcDefaultValue<const TPEAudioOutput&>::SetL( EPENotActive ); |
|
140 |
|
141 } |
|
142 |
|
143 |
|
144 void ut_cphonesingleandwaiting::Teardown( ) |
|
145 { |
|
146 delete iState; |
|
147 iState = NULL; |
|
148 delete iViewCmdHandleMock; |
|
149 iViewCmdHandleMock = NULL; |
|
150 delete iStateMachineMock; |
|
151 iStateMachineMock = NULL; |
|
152 delete iEngineInfoMock; |
|
153 iEngineInfoMock = NULL; |
|
154 delete iCPhoneMainResourceResolverMock; |
|
155 iCPhoneMainResourceResolverMock = NULL; |
|
156 |
|
157 SmcDefaultValue<TPESimState>::Reset(); |
|
158 SmcDefaultValue<const TPEAudioOutput&>::Reset(); |
|
159 |
|
160 iMockContext->Reset(); |
|
161 } |
|
162 |
|
163 |
|
164 // - Test methods ----------------------------------------------------------- |
|
165 |
|
166 void ut_cphonesingleandwaiting::TestBubbleAndUICommandsAreUpdatedWhenCallIsPutToHoldL() |
|
167 { |
|
168 TInt callId( 1 ); |
|
169 iMockContext->ExpectCallL("CPhoneState::UpdateUiCommands"); |
|
170 iMockContext->ExpectCallL("CPhoneViewCommandHandleMock::ExecuteCommandL"). |
|
171 WithL<TPhoneViewCommandId,TInt>(EPhoneViewUpdateBubble, callId); |
|
172 |
|
173 iState->HandlePhoneEngineMessageL( MEngineMonitor::EPEMessageHeld, callId ); |
|
174 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
175 } |
|
176 |
|
177 void ut_cphonesingleandwaiting::TestBubbleAndUICommandsAreUpdatedWhenCallIsResumedL() |
|
178 { |
|
179 TInt callId( 0 ); |
|
180 iMockContext->ExpectCallL("CPhoneState::UpdateUiCommands"); |
|
181 iMockContext->ExpectCallL("CPhoneViewCommandHandleMock::ExecuteCommandL"). |
|
182 WithL<TPhoneViewCommandId,TInt>(EPhoneViewUpdateBubble, callId); |
|
183 |
|
184 iState->HandlePhoneEngineMessageL( MEngineMonitor::EPEMessageConnected, callId ); |
|
185 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
186 } |
|
187 |
|
188 // - EUnit test table ------------------------------------------------------- |
|
189 |
|
190 EUNIT_BEGIN_TEST_TABLE( |
|
191 ut_cphonesingleandwaiting, |
|
192 "Add test suite description here.", |
|
193 "UNIT" ) |
|
194 |
|
195 EUNIT_TEST( |
|
196 "Test bubble and ui commands are updated when call is put to hold", |
|
197 "", |
|
198 "", |
|
199 "FUNCTIONALITY", |
|
200 SetupL, TestBubbleAndUICommandsAreUpdatedWhenCallIsPutToHoldL, Teardown) |
|
201 |
|
202 EUNIT_TEST( |
|
203 "Test bubble and ui commands are updated when call is resumed", |
|
204 "", |
|
205 "", |
|
206 "FUNCTIONALITY", |
|
207 SetupL, TestBubbleAndUICommandsAreUpdatedWhenCallIsResumedL, Teardown) |
|
208 |
|
209 |
|
210 EUNIT_END_TEST_TABLE |