|
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_cphonestateincall.h" |
|
19 #include <EUnitMacros.h> |
|
20 #include <EUnitDecorators.h> |
|
21 |
|
22 #include "CPhoneStateMachineGSM.h" |
|
23 #include "mock_cphoneviewcommandhandle.h" |
|
24 #include "CPEEngineInfo.h" |
|
25 #include "cphonestateincall.h" |
|
26 #include "CPhoneCenRepProxy.h" |
|
27 #include "CPhoneMainResourceResolver.h" |
|
28 #include <EUnitMacros.h> |
|
29 #include <EUnitDecorators.h> |
|
30 #include "phoneui.hrh" |
|
31 #include <csmcmockcontext.h> |
|
32 #include <msmcmockspecbuilder.h> |
|
33 #include <coemain.h> |
|
34 #include <PhoneUI.rsg> |
|
35 #include "phoneresourceids.h" |
|
36 #include "phonerssbase.h" |
|
37 #include "CPhoneTerminateAllConnectionsCommand.h" |
|
38 |
|
39 // needed for mocking CPhoneMainResourceResolver::Instance() |
|
40 class CPhoneMainResourceResolverMock : public CPhoneMainResourceResolver{}; |
|
41 CPhoneCenRepProxy* GlobalCPhoneCenRepProxy; |
|
42 HBufC* GlobalHBufC; |
|
43 |
|
44 // - Construction ----------------------------------------------------------- |
|
45 |
|
46 ut_cphonestateincall* ut_cphonestateincall::NewL() |
|
47 { |
|
48 ut_cphonestateincall* self = ut_cphonestateincall::NewLC(); |
|
49 CleanupStack::Pop(); |
|
50 return self; |
|
51 } |
|
52 |
|
53 ut_cphonestateincall* ut_cphonestateincall::NewLC() |
|
54 { |
|
55 ut_cphonestateincall* self = new( ELeave ) ut_cphonestateincall(); |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL(); |
|
58 return self; |
|
59 } |
|
60 |
|
61 ut_cphonestateincall::~ut_cphonestateincall() |
|
62 { |
|
63 CSmcMockContext::Release(); |
|
64 } |
|
65 |
|
66 ut_cphonestateincall::ut_cphonestateincall() |
|
67 { |
|
68 } |
|
69 |
|
70 void ut_cphonestateincall::ConstructL() |
|
71 { |
|
72 CEUnitTestSuiteClass::ConstructL(); |
|
73 iMockContext = CSmcMockContext::InstanceL(); |
|
74 } |
|
75 |
|
76 // - Test methods ----------------------------------------------------------- |
|
77 |
|
78 void ut_cphonestateincall::SetupL( ) |
|
79 { |
|
80 GlobalCPhoneCenRepProxy = NULL; |
|
81 GlobalHBufC = NULL; |
|
82 iCPhoneMainResourceResolverMock = new ( ELeave ) CPhoneMainResourceResolverMock(); |
|
83 SmcDefaultValue<CPhoneMainResourceResolver*>::SetL( iCPhoneMainResourceResolverMock ); |
|
84 |
|
85 iCoeEnvMock = new (ELeave ) CCoeEnv(); |
|
86 SmcDefaultValue<CCoeEnv*>::SetL( iCoeEnvMock ); |
|
87 |
|
88 iViewCommandHandle = new CPhoneViewCommandHandleMock(); |
|
89 |
|
90 iStateMachine = CPhoneStateMachineGSM::NewL( iViewCommandHandle ); |
|
91 |
|
92 iEngineInfoMock = CPEEngineInfo::NewL(); |
|
93 SmcDefaultValue<MPEEngineInfo*>::SetL( iEngineInfoMock ); |
|
94 |
|
95 iStateInCall = CPhoneStateInCall::NewL( iStateMachine, iViewCommandHandle, NULL ); |
|
96 } |
|
97 |
|
98 void ut_cphonestateincall::Teardown( ) |
|
99 { |
|
100 delete iStateInCall; |
|
101 iStateInCall = NULL; |
|
102 delete iStateMachine; |
|
103 iStateMachine = NULL; |
|
104 delete iViewCommandHandle; |
|
105 iViewCommandHandle = NULL; |
|
106 |
|
107 delete iEngineInfoMock; |
|
108 iEngineInfoMock = NULL; |
|
109 SmcDefaultValue<MPEEngineInfo*>::Reset(); |
|
110 |
|
111 delete iCoeEnvMock; |
|
112 iCoeEnvMock = NULL; |
|
113 SmcDefaultValue<CCoeEnv*>::Reset(); |
|
114 |
|
115 delete GlobalCPhoneCenRepProxy; |
|
116 GlobalCPhoneCenRepProxy = NULL; |
|
117 |
|
118 delete GlobalHBufC; |
|
119 GlobalHBufC = NULL; |
|
120 delete iCPhoneMainResourceResolverMock; |
|
121 iCPhoneMainResourceResolverMock = NULL; |
|
122 SmcDefaultValue<CPhoneMainResourceResolver*>::Reset(); |
|
123 |
|
124 iMockContext->Reset(); |
|
125 } |
|
126 |
|
127 void ut_cphonestateincall::T_ConstructionL( ) |
|
128 { |
|
129 // SetupL and Teardown does the test. |
|
130 } |
|
131 |
|
132 void ut_cphonestateincall::T_NumberAcqCmdVideoCall( ) |
|
133 { |
|
134 _LIT( KPhoneNumber, "12345" ); |
|
135 HBufC* phoneNumber = KPhoneNumber().AllocL(); |
|
136 |
|
137 iMockContext->ExpectCallL( "CPhoneNumberEntryManager::PhoneNumberFromEntryLC" ). |
|
138 ReturnsL(phoneNumber); |
|
139 |
|
140 iStateInCall->HandleCommandL( EPhoneNumberAcqCmdVideoCall ); |
|
141 |
|
142 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
143 } |
|
144 |
|
145 void ut_cphonestateincall::T_HandleStoppedDTMFL( ) |
|
146 { |
|
147 iMockContext->ExpectCallL( "CPEEngineInfoImpl::DtmfString" ). |
|
148 ReturnsL(KNullDesC); |
|
149 |
|
150 iMockContext->ExpectCallL( "CPhoneMainResourceResolver::ResolveResourceID" ). |
|
151 WithL( EPhoneDtmfNumberQuery ). |
|
152 ReturnsL(R_PHONEUI_SEND_DTMF_QUERY); |
|
153 |
|
154 iMockContext->ExpectCallL( "CPhoneMainResourceResolver::ResolveResourceID" ). |
|
155 WithL( EPhoneSendDtmfEmptyEditBoxCBA ). |
|
156 ReturnsL(R_PHONEUI_SEND_DTMF_EMPTY_EDIT_BOX_CBA); |
|
157 |
|
158 iMockContext->ExpectCallL( "CPhoneMainResourceResolver::ResolveResourceID" ). |
|
159 WithL( EPhoneSendDtmfNormalEditBoxCBA ). |
|
160 ReturnsL(R_PHONEUI_SEND_DTMF_NORMAL_EDIT_BOX_CBA); |
|
161 |
|
162 iStateInCall->HandlePhoneEngineMessageL( MEngineMonitor::EPEMessageStoppedDTMF, -1 ); |
|
163 |
|
164 EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() ); |
|
165 } |
|
166 |
|
167 // - EUnit test table ------------------------------------------------------- |
|
168 |
|
169 EUNIT_BEGIN_TEST_TABLE( |
|
170 ut_cphonestateincall, |
|
171 "Add test suite description here.", |
|
172 "UNIT" ) |
|
173 |
|
174 EUNIT_TEST( |
|
175 "Test0", |
|
176 "T_ConstructionL", |
|
177 "Test0", |
|
178 "FUNCTIONALITY", |
|
179 SetupL, T_ConstructionL, Teardown) |
|
180 |
|
181 EUNIT_TEST( |
|
182 "Test1", |
|
183 "EPhoneNumberAcqCmdVideoCall", |
|
184 "Test1", |
|
185 "FUNCTIONALITY", |
|
186 SetupL, T_NumberAcqCmdVideoCall, Teardown) |
|
187 |
|
188 EUNIT_TEST( |
|
189 "Test2", |
|
190 "T_HandleStoppedDTMFL", |
|
191 "Test2", |
|
192 "FUNCTIONALITY", |
|
193 SetupL, T_HandleStoppedDTMFL, Teardown) |
|
194 |
|
195 EUNIT_END_TEST_TABLE |