74
|
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_cphonealerting.h"
|
|
25 |
#include "cphonealerting.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 "cpeengineinfoimpl.h"
|
|
35 |
#include "cphoneidle.h"
|
|
36 |
|
|
37 |
//test
|
|
38 |
#include "TPhoneCmdParamInteger.h"
|
|
39 |
|
|
40 |
// needed for mocking CPhoneMainResourceResolver::Instance()
|
|
41 |
class CPhoneMainResourceResolverMock : public CPhoneMainResourceResolver
|
|
42 |
{
|
|
43 |
};
|
|
44 |
|
|
45 |
// -----------------------------------------------------------------------------
|
|
46 |
// operator for comparing parameter expected and result value.
|
|
47 |
// -
|
|
48 |
// -----------------------------------------------------------------------------
|
|
49 |
//
|
|
50 |
TBool operator==(const TPhoneCommandParam& param1, const TPhoneCommandParam& param2 )
|
|
51 |
{
|
|
52 |
TBool ret( EFalse );
|
|
53 |
|
|
54 |
if ( param1.ParamId() == param2.ParamId() )
|
|
55 |
{
|
|
56 |
if ( TPhoneCommandParam::EPhoneParamIdBoolean == param1.ParamId() )
|
|
57 |
{
|
|
58 |
const TPhoneCmdParamBoolean &value1 = static_cast<const TPhoneCmdParamBoolean&> (param1);
|
|
59 |
const TPhoneCmdParamBoolean &value2 = static_cast<const TPhoneCmdParamBoolean&> (param2);
|
|
60 |
if ( value1.Boolean() == value2.Boolean() )
|
|
61 |
{
|
|
62 |
ret = ETrue;
|
|
63 |
}
|
|
64 |
}
|
|
65 |
else if ( TPhoneCommandParam::EPhoneParamIdCallHeaderData == param1.ParamId() )
|
|
66 |
{
|
|
67 |
const TPhoneCmdParamCallHeaderData &value1 = static_cast<const TPhoneCmdParamCallHeaderData&> (param1);
|
|
68 |
const TPhoneCmdParamCallHeaderData &value2 = static_cast<const TPhoneCmdParamCallHeaderData&> (param2);
|
|
69 |
if ( value1.CallState() == value2.CallState() )
|
|
70 |
{
|
|
71 |
ret = ETrue;
|
|
72 |
}
|
|
73 |
}
|
|
74 |
else if ( TPhoneCommandParam::EPhoneParamIdInteger == param1.ParamId() )
|
|
75 |
{
|
|
76 |
const TPhoneCmdParamInteger &value1 = static_cast<const TPhoneCmdParamInteger&> (param1);
|
|
77 |
const TPhoneCmdParamInteger &value2 = static_cast<const TPhoneCmdParamInteger&> (param2);
|
|
78 |
if ( value1.Integer() == value2.Integer() )
|
|
79 |
{
|
|
80 |
ret = ETrue;
|
|
81 |
}
|
|
82 |
}
|
|
83 |
else if ( TPhoneCommandParam::EPhoneParamIdAudioOutput == param1.ParamId() )
|
|
84 |
{
|
|
85 |
const TPhoneCmdParamAudioOutput &value1 = static_cast<const TPhoneCmdParamAudioOutput&> (param1);
|
|
86 |
const TPhoneCmdParamAudioOutput &value2 = static_cast<const TPhoneCmdParamAudioOutput&> (param2);
|
|
87 |
if ( value1.AudioOutput() == value2.AudioOutput() )
|
|
88 |
{
|
|
89 |
ret = ETrue;
|
|
90 |
}
|
|
91 |
}
|
|
92 |
else
|
|
93 |
{
|
|
94 |
ret = ETrue; // just paramiId compared
|
|
95 |
}
|
|
96 |
}
|
|
97 |
return ret;
|
|
98 |
}
|
|
99 |
|
|
100 |
|
|
101 |
// - Construction -----------------------------------------------------------
|
|
102 |
ut_cphonealerting* ut_cphonealerting::NewL()
|
|
103 |
{
|
|
104 |
ut_cphonealerting* self = ut_cphonealerting::NewLC();
|
|
105 |
CleanupStack::Pop( self );
|
|
106 |
return self;
|
|
107 |
}
|
|
108 |
|
|
109 |
ut_cphonealerting* ut_cphonealerting::NewLC()
|
|
110 |
{
|
|
111 |
ut_cphonealerting* self = new( ELeave ) ut_cphonealerting();
|
|
112 |
CleanupStack::PushL( self );
|
|
113 |
self->ConstructL();
|
|
114 |
return self;
|
|
115 |
}
|
|
116 |
|
|
117 |
|
|
118 |
ut_cphonealerting::~ut_cphonealerting()
|
|
119 |
{
|
|
120 |
CSmcMockContext::Release();
|
|
121 |
}
|
|
122 |
|
|
123 |
|
|
124 |
ut_cphonealerting::ut_cphonealerting()
|
|
125 |
{
|
|
126 |
}
|
|
127 |
|
|
128 |
|
|
129 |
void ut_cphonealerting::ConstructL()
|
|
130 |
{
|
|
131 |
CEUnitTestSuiteClass::ConstructL();
|
|
132 |
iMockContext = CSmcMockContext::InstanceL();
|
|
133 |
}
|
|
134 |
|
|
135 |
|
|
136 |
// - Test methods -----------------------------------------------------------
|
|
137 |
void ut_cphonealerting::SetupL( )
|
|
138 |
{
|
|
139 |
iMockContext->InitializeL();
|
|
140 |
|
|
141 |
iCPhoneMainResourceResolverMock = new ( ELeave ) CPhoneMainResourceResolverMock();
|
|
142 |
SmcDefaultValue<CPhoneMainResourceResolver*>::SetL( iCPhoneMainResourceResolverMock );
|
|
143 |
|
|
144 |
iViewCmdHandleMock = new CPhoneViewCommandHandleMock();
|
|
145 |
|
|
146 |
iStateMachineMock = CPhoneStateMachineGSM::NewL( iViewCmdHandleMock );
|
|
147 |
|
|
148 |
iStateAlerting = CPhoneAlerting::NewL(
|
|
149 |
iStateMachineMock, iViewCmdHandleMock, NULL );
|
|
150 |
|
|
151 |
iEngineInfoMock = CPEEngineInfoImpl::NewL();
|
|
152 |
|
|
153 |
iPhoneIdleMock = CPhoneIdle::NewL(
|
|
154 |
iStateMachineMock, iViewCmdHandleMock, NULL );
|
|
155 |
|
|
156 |
SmcDefaultValue<MPEEngineInfo*>::SetL( iEngineInfoMock );
|
|
157 |
SmcDefaultValue<TPESimState>::SetL( EPESimStatusUninitialized );
|
|
158 |
SmcDefaultValue<const TPEAudioOutput&>::SetL( EPENotActive );
|
|
159 |
SmcDefaultValue<MPhoneState*>::SetL( iPhoneIdleMock );
|
|
160 |
}
|
|
161 |
|
|
162 |
|
|
163 |
void ut_cphonealerting::Teardown( )
|
|
164 |
{
|
|
165 |
delete iViewCmdHandleMock;
|
|
166 |
iViewCmdHandleMock = NULL;
|
|
167 |
delete iStateAlerting;
|
|
168 |
iStateAlerting = NULL;
|
|
169 |
delete iStateMachineMock;
|
|
170 |
iStateMachineMock = NULL;
|
|
171 |
delete iEngineInfoMock;
|
|
172 |
iEngineInfoMock = NULL;
|
|
173 |
delete iCPhoneMainResourceResolverMock;
|
|
174 |
iCPhoneMainResourceResolverMock = NULL;
|
|
175 |
delete iPhoneIdleMock;
|
|
176 |
iPhoneIdleMock = NULL;
|
|
177 |
|
|
178 |
SmcDefaultValue<TPESimState>::Reset();
|
|
179 |
SmcDefaultValue<const TPEAudioOutput&>::Reset();
|
|
180 |
SmcDefaultValue<MPhoneState*>::Reset();
|
|
181 |
|
|
182 |
iMockContext->Reset();
|
|
183 |
}
|
|
184 |
|
|
185 |
// -----------------------------------------------------------------------------
|
|
186 |
// ut_cphonealerting::T_HandlePhoneEngineMessageIncomingL
|
|
187 |
// -----------------------------------------------------------------------------
|
|
188 |
//
|
|
189 |
void ut_cphonealerting::T_HandlePhoneEngineMessageIncomingL()
|
|
190 |
{
|
|
191 |
TInt callIdentifier = 0;
|
|
192 |
iMockContext->ExpectCallL( "CPhoneGsmInCall::HandlePhoneEngineMessageL" ).
|
|
193 |
WithL( MEngineMonitor::EPEMessageIncoming, callIdentifier );
|
|
194 |
|
|
195 |
iStateAlerting->HandlePhoneEngineMessageL(
|
|
196 |
MEngineMonitor::EPEMessageIncoming,
|
|
197 |
callIdentifier );
|
|
198 |
|
|
199 |
EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() );
|
|
200 |
}
|
|
201 |
|
|
202 |
|
|
203 |
// -----------------------------------------------------------------------------
|
|
204 |
// ut_cphonealerting::T_HandlePhoneEngineMessageIdleL
|
|
205 |
// -----------------------------------------------------------------------------
|
|
206 |
//
|
|
207 |
void ut_cphonealerting::T_HandlePhoneEngineMessageIdleL()
|
|
208 |
{
|
|
209 |
TInt callIdentifier = 0;
|
|
210 |
iMockContext->ExpectCallL( "CPhoneGsmInCall::HandlePhoneEngineMessageL" ).
|
|
211 |
WithL( MEngineMonitor::EPEMessageIdle, callIdentifier );
|
|
212 |
|
|
213 |
iStateAlerting->HandlePhoneEngineMessageL(
|
|
214 |
MEngineMonitor::EPEMessageIdle,
|
|
215 |
callIdentifier );
|
|
216 |
|
|
217 |
EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() );
|
|
218 |
}
|
|
219 |
|
|
220 |
|
|
221 |
// -----------------------------------------------------------------------------
|
|
222 |
// ut_cphonealerting::T_HandlePhoneEngineMessageIdleAfterIncomingL
|
|
223 |
// Motivation for the test case: TSW error TKUA-7VJGL5.
|
|
224 |
// Incoming message for a new call may be received in alerting state if
|
|
225 |
// teardown of the alerting call is ongoing.
|
|
226 |
// -----------------------------------------------------------------------------
|
|
227 |
//
|
|
228 |
void ut_cphonealerting::T_HandlePhoneEngineMessageIdleAfterIncomingL()
|
|
229 |
{
|
|
230 |
TInt identifierOfAlertingCall = 0;
|
|
231 |
TInt identifierOfIncomingCall = 1;
|
|
232 |
|
|
233 |
iMockContext->ExpectCallL( "CPhoneGsmInCall::HandlePhoneEngineMessageL" ).
|
|
234 |
WithL( MEngineMonitor::EPEMessageIncoming, identifierOfIncomingCall );
|
|
235 |
iMockContext->ExpectCallL( "CPhoneGsmInCall::HandlePhoneEngineMessageL" ).
|
|
236 |
WithL( MEngineMonitor::EPEMessageIdle, identifierOfAlertingCall );
|
|
237 |
iMockContext->ExpectCallL( "CPhoneIdle::HandlePhoneEngineMessageL" ).
|
|
238 |
WithL( MEngineMonitor::EPEMessageIncoming, identifierOfIncomingCall );
|
|
239 |
|
|
240 |
iStateAlerting->HandlePhoneEngineMessageL(
|
|
241 |
MEngineMonitor::EPEMessageIncoming,
|
|
242 |
identifierOfIncomingCall );
|
|
243 |
iStateAlerting->HandlePhoneEngineMessageL(
|
|
244 |
MEngineMonitor::EPEMessageIdle,
|
|
245 |
identifierOfAlertingCall );
|
|
246 |
|
|
247 |
EUNIT_ASSERT_EQUALS( KErrNone, iMockContext->VerifyExpectations() );
|
|
248 |
}
|
|
249 |
|
|
250 |
|
|
251 |
// - EUnit test table -------------------------------------------------------
|
|
252 |
EUNIT_BEGIN_TEST_TABLE(
|
|
253 |
ut_cphonealerting,
|
|
254 |
"Add test suite description here.",
|
|
255 |
"UNIT" )
|
|
256 |
|
|
257 |
EUNIT_TEST(
|
|
258 |
"T_HandlePhoneEngineMessageIncomingL",
|
|
259 |
"CPhoneAlerting",
|
|
260 |
"T_HandlePhoneEngineMessageIncomingL",
|
|
261 |
"FUNCTIONALITY",
|
|
262 |
SetupL, T_HandlePhoneEngineMessageIncomingL, Teardown)
|
|
263 |
|
|
264 |
EUNIT_TEST(
|
|
265 |
"T_HandlePhoneEngineMessageIdleL",
|
|
266 |
"CPhoneAlerting",
|
|
267 |
"T_HandlePhoneEngineMessageIdleL",
|
|
268 |
"FUNCTIONALITY",
|
|
269 |
SetupL, T_HandlePhoneEngineMessageIdleL, Teardown)
|
|
270 |
|
|
271 |
EUNIT_TEST(
|
|
272 |
"T_HandlePhoneEngineMessageIdleAfterIncomingL",
|
|
273 |
"CPhoneAlerting",
|
|
274 |
"T_HandlePhoneEngineMessageIdleAfterIncomingL",
|
|
275 |
"FUNCTIONALITY",
|
|
276 |
SetupL, T_HandlePhoneEngineMessageIdleAfterIncomingL, Teardown)
|
|
277 |
|
|
278 |
EUNIT_END_TEST_TABLE
|