|
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_phonecallutil.h" |
|
19 #include "phonecallutil.h" |
|
20 #include <EUnitMacros.h> |
|
21 #include <EUnitDecorators.h> |
|
22 |
|
23 #include "CPhoneStateMachineGSM.h" |
|
24 #include "mock_cphoneviewcommandhandle.h" |
|
25 #include "CPEEngineInfo.h" |
|
26 #include "cphonestateincall.h" |
|
27 #include "cphonestatehandle.h" |
|
28 #include "CPhoneCenRepProxy.h" |
|
29 #include "CPhoneMainResourceResolver.h" |
|
30 #include <EUnitMacros.h> |
|
31 #include <EUnitDecorators.h> |
|
32 #include "phoneui.hrh" |
|
33 #include <csmcmockcontext.h> |
|
34 #include <msmcmockspecbuilder.h> |
|
35 #include <coemain.h> |
|
36 #include <PhoneUI.rsg> |
|
37 #include "phoneresourceids.h" |
|
38 #include "phonerssbase.h" |
|
39 #include "CPhoneTerminateAllConnectionsCommand.h" |
|
40 |
|
41 // needed for mocking CPhoneMainResourceResolver::Instance() |
|
42 class CPhoneMainResourceResolverMock : public CPhoneMainResourceResolver{}; |
|
43 |
|
44 class CPhoneStateMachineGSMMock : public CPhoneStateMachineGSM{}; |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 // - Construction ----------------------------------------------------------- |
|
50 |
|
51 ut_phonecallutil* ut_phonecallutil::NewL() |
|
52 { |
|
53 ut_phonecallutil* self = ut_phonecallutil::NewLC(); |
|
54 CleanupStack::Pop(); |
|
55 return self; |
|
56 } |
|
57 |
|
58 ut_phonecallutil* ut_phonecallutil::NewLC() |
|
59 { |
|
60 ut_phonecallutil* self = new( ELeave ) ut_phonecallutil(); |
|
61 CleanupStack::PushL( self ); |
|
62 self->ConstructL(); |
|
63 return self; |
|
64 } |
|
65 |
|
66 ut_phonecallutil::~ut_phonecallutil() |
|
67 { |
|
68 CSmcMockContext::Release(); |
|
69 } |
|
70 |
|
71 ut_phonecallutil::ut_phonecallutil() |
|
72 { |
|
73 } |
|
74 |
|
75 void ut_phonecallutil::ConstructL() |
|
76 { |
|
77 CEUnitTestSuiteClass::ConstructL(); |
|
78 iMockContext = CSmcMockContext::InstanceL(); |
|
79 } |
|
80 |
|
81 // - Test methods ----------------------------------------------------------- |
|
82 |
|
83 void ut_phonecallutil::SetupL( ) |
|
84 { |
|
85 iCPhoneMainResourceResolverMock = new ( ELeave ) CPhoneMainResourceResolverMock(); |
|
86 SmcDefaultValue<CPhoneMainResourceResolver*>::SetL( iCPhoneMainResourceResolverMock ); |
|
87 |
|
88 iCoeEnvMock = new (ELeave ) CCoeEnv(); |
|
89 SmcDefaultValue<CCoeEnv*>::SetL( iCoeEnvMock ); |
|
90 |
|
91 iViewCommandHandle = new CPhoneViewCommandHandleMock(); |
|
92 SmcDefaultValue<MPhoneViewCommandHandle*>::SetL( iViewCommandHandle ); |
|
93 |
|
94 iStateMachine = CPhoneStateMachineGSMMock::NewL(iViewCommandHandle); |
|
95 SmcDefaultValue<MPhoneStateMachine*>::SetL( iStateMachine ); |
|
96 |
|
97 iCPhoneStateHandleMock = CPhoneStateHandle:: |
|
98 CreateL(iViewCommandHandle, _L("test"), TUid::Uid(1)); |
|
99 SmcDefaultValue<CPhoneStateHandle*>::SetL( iCPhoneStateHandleMock ); |
|
100 |
|
101 iEngineInfo = CPEEngineInfo::NewL(); |
|
102 SmcDefaultValue<MPEEngineInfo*>::SetL( iEngineInfo ); |
|
103 } |
|
104 |
|
105 void ut_phonecallutil::Teardown( ) |
|
106 { |
|
107 delete iStateMachine; |
|
108 iStateMachine = NULL; |
|
109 SmcDefaultValue<MPhoneStateMachine*>::Reset(); |
|
110 |
|
111 delete iCPhoneStateHandleMock; |
|
112 iCPhoneStateHandleMock = NULL; |
|
113 SmcDefaultValue<CPhoneStateHandle*>::Reset(); |
|
114 |
|
115 delete iViewCommandHandle; |
|
116 iViewCommandHandle = NULL; |
|
117 SmcDefaultValue<MPhoneViewCommandHandle*>::Reset(); |
|
118 |
|
119 delete iEngineInfo; |
|
120 iEngineInfo = NULL; |
|
121 SmcDefaultValue<MPEEngineInfo*>::Reset(); |
|
122 |
|
123 delete iCoeEnvMock; |
|
124 iCoeEnvMock = NULL; |
|
125 SmcDefaultValue<CCoeEnv*>::Reset(); |
|
126 |
|
127 delete iCPhoneMainResourceResolverMock; |
|
128 iCPhoneMainResourceResolverMock = NULL; |
|
129 SmcDefaultValue<CPhoneMainResourceResolver*>::Reset(); |
|
130 |
|
131 iMockContext->Reset(); |
|
132 } |
|
133 |
|
134 void ut_phonecallutil::T_ConstructionL( ) |
|
135 { |
|
136 // SetupL and Teardown does the test. |
|
137 } |
|
138 |
|
139 void ut_phonecallutil::T_DialMultimediaCall( ) |
|
140 { |
|
141 iMockContext->ExpectCallL( "CPhoneStateMachine::SendPhoneEngineMessage" ). |
|
142 WithL(MPEPhoneModel::EPEMessageDial); |
|
143 |
|
144 PhoneCallUtil::DialMultimediaCall(); |
|
145 |
|
146 EUNIT_ASSERT_EQUALS( iEngineInfo->CallTypeCommand(), EPECallTypeVideo ); |
|
147 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
148 } |
|
149 |
|
150 void ut_phonecallutil::T_DialVoiceCall( ) |
|
151 { |
|
152 iMockContext->ExpectCallL( "CPhoneStateMachine::SendPhoneEngineMessage" ). |
|
153 WithL(MPEPhoneModel::EPEMessageDial); |
|
154 |
|
155 PhoneCallUtil::DialVoiceCallL(); |
|
156 |
|
157 EUNIT_ASSERT_EQUALS( iEngineInfo->CallTypeCommand(), EPECallTypeCSVoice ); |
|
158 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
159 } |
|
160 |
|
161 void ut_phonecallutil::T_DisconnectCallL( ) |
|
162 { |
|
163 iMockContext->ExpectCallL( "CPhoneStateMachine::SendPhoneEngineMessage" ). |
|
164 WithL(MPEPhoneModel::EPEMessageRelease); |
|
165 |
|
166 PhoneCallUtil::DisconnectCallL(); |
|
167 |
|
168 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
169 } |
|
170 |
|
171 void ut_phonecallutil::T_TestUtilsL( ) |
|
172 { |
|
173 TInt callId = 1; |
|
174 TInt invalidCallId = -1; |
|
175 |
|
176 iEngineInfo->SetCallType(EPECallTypeCSVoice, callId); |
|
177 EUNIT_ASSERT( EFalse == PhoneCallUtil::IsVideoCall( callId ) ); |
|
178 EUNIT_ASSERT( EFalse == PhoneCallUtil::IsVideoCall( invalidCallId ) ); |
|
179 |
|
180 iEngineInfo->SetCallType(EPECallTypeVideo, callId); |
|
181 EUNIT_ASSERT( PhoneCallUtil::IsVideoCall( callId ) ); |
|
182 |
|
183 EUNIT_ASSERT( -1 == PhoneCallUtil::CallIdByState( EPEStateHeld ) ); |
|
184 EUNIT_ASSERT( EFalse == PhoneCallUtil::CheckIfCallExists( |
|
185 EPEStateHeld, EPECallTypeCSVoice) ); |
|
186 |
|
187 EUNIT_ASSERT( EFalse == PhoneCallUtil::IsAnyConnectedCalls() ); |
|
188 iEngineInfo->SetCallState(EPEStateConnected, callId); |
|
189 EUNIT_ASSERT( PhoneCallUtil::IsAnyConnectedCalls() ); |
|
190 iEngineInfo->SetCallState(EPEStateConnecting, callId); |
|
191 EUNIT_ASSERT( PhoneCallUtil::IsAnyConnectedCalls() ); |
|
192 iEngineInfo->SetCallState(EPEStateConnectedConference, callId); |
|
193 EUNIT_ASSERT( PhoneCallUtil::IsAnyConnectedCalls() ); |
|
194 } |
|
195 |
|
196 // - EUnit test table ------------------------------------------------------- |
|
197 |
|
198 EUNIT_BEGIN_TEST_TABLE( |
|
199 ut_phonecallutil, |
|
200 "Add test suite description here.", |
|
201 "UNIT" ) |
|
202 |
|
203 EUNIT_TEST( |
|
204 "Test0", |
|
205 "T_ConstructionL", |
|
206 "Test0", |
|
207 "FUNCTIONALITY", |
|
208 SetupL, T_ConstructionL, Teardown) |
|
209 |
|
210 EUNIT_TEST( |
|
211 "Test1", |
|
212 "T_DialMultimediaCall", |
|
213 "Test1", |
|
214 "FUNCTIONALITY", |
|
215 SetupL, T_DialMultimediaCall, Teardown) |
|
216 |
|
217 EUNIT_TEST( |
|
218 "Test2", |
|
219 "T_DialVoiceCall", |
|
220 "Test2", |
|
221 "FUNCTIONALITY", |
|
222 SetupL, T_DialVoiceCall, Teardown) |
|
223 |
|
224 EUNIT_TEST( |
|
225 "Test3", |
|
226 "T_DisconnectCallL", |
|
227 "Test3", |
|
228 "FUNCTIONALITY", |
|
229 SetupL, T_DisconnectCallL, Teardown) |
|
230 |
|
231 EUNIT_TEST( |
|
232 "Test4", |
|
233 "T_TestUtilsL", |
|
234 "Test4", |
|
235 "FUNCTIONALITY", |
|
236 SetupL, T_TestUtilsL, Teardown) |
|
237 |
|
238 EUNIT_END_TEST_TABLE |