|
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 <etelmm.h> |
|
19 #include <PsetContainer.h> |
|
20 #include <mpsetcallwaitingobs.h> |
|
21 #include "ut_psetcallwaitingwrapper.h" |
|
22 #include "testutilities.h" |
|
23 #define private public |
|
24 #include "psetcallwaitingwrapper.h" |
|
25 #include "psetcallwaitingwrapper_p.h" |
|
26 |
|
27 class WaitingObserver : public MPsetCallWaitingObserver |
|
28 { |
|
29 void HandleCallWaitingGetStatusL( |
|
30 const MPsetCallWaiting::TGetCallWaitingStatus aStatus, |
|
31 TUint8 aBsc[KPSetNumberOfBsc]) |
|
32 { |
|
33 Q_UNUSED(aStatus); |
|
34 Q_UNUSED(aBsc); |
|
35 } |
|
36 |
|
37 void HandleCallWaitingChangedL( |
|
38 const MPsetCallWaiting::TSetCallWaiting aSetting, |
|
39 const TInt aResult) |
|
40 { |
|
41 Q_UNUSED(aSetting); |
|
42 Q_UNUSED(aResult); |
|
43 } |
|
44 |
|
45 void HandleCWRequestingL( |
|
46 TBool aOngoing, |
|
47 TBool aInterrupted) |
|
48 { |
|
49 Q_UNUSED(aOngoing); |
|
50 Q_UNUSED(aInterrupted); |
|
51 } |
|
52 |
|
53 void HandleCWErrorL( |
|
54 TInt aReason) |
|
55 { |
|
56 Q_UNUSED(aReason); |
|
57 } |
|
58 |
|
59 void SetEngineContact( |
|
60 MPsetCallWaiting& aEngineContact) |
|
61 { |
|
62 Q_UNUSED(aEngineContact); |
|
63 } |
|
64 }; |
|
65 |
|
66 void SimulateLeaveL() |
|
67 { |
|
68 User::Leave(KErrGeneral); |
|
69 } |
|
70 |
|
71 /*! |
|
72 UT_PSetCallWaitingWrapper::UT_PSetCallWaitingWrapper |
|
73 */ |
|
74 UT_PSetCallWaitingWrapper::UT_PSetCallWaitingWrapper() |
|
75 : |
|
76 m_numOfLeaveSimulations(0), |
|
77 m_psetContainerMock(NULL), |
|
78 m_psetCallWaitingMock(NULL), |
|
79 m_wrapper(NULL) |
|
80 { |
|
81 } |
|
82 |
|
83 /*! |
|
84 UT_PSetCallWaitingWrapper::~UT_PSetCallWaitingWrapper |
|
85 */ |
|
86 UT_PSetCallWaitingWrapper::~UT_PSetCallWaitingWrapper() |
|
87 { |
|
88 delete m_psetContainerMock; |
|
89 m_psetCallWaitingMock = NULL; |
|
90 delete m_wrapper; |
|
91 } |
|
92 |
|
93 /*! |
|
94 UT_PSetCallWaitingWrapper::init |
|
95 */ |
|
96 void UT_PSetCallWaitingWrapper::init() |
|
97 { |
|
98 initialize(); |
|
99 m_numOfLeaveSimulations = 0; |
|
100 |
|
101 m_psetContainerMock = new CPsetContainer(); |
|
102 |
|
103 RMobilePhone dummyHandle; |
|
104 WaitingObserver dummyObserver; |
|
105 QT_TRAP_THROWING(m_psetCallWaitingMock = |
|
106 CPsetCallWaiting::NewL(dummyHandle, dummyObserver)); |
|
107 expect("CPsetContainer::CreateCWObjectL").returns(m_psetCallWaitingMock); |
|
108 |
|
109 // wrapper takes ownership of callDivertingMock during successful |
|
110 // construction |
|
111 QScopedPointer<CPsetCallWaiting> callWaitingMockPtr(m_psetCallWaitingMock); |
|
112 m_wrapper = new PSetCallWaitingWrapper(*m_psetContainerMock, NULL); |
|
113 callWaitingMockPtr.take(); |
|
114 } |
|
115 |
|
116 /*! |
|
117 UT_PSetCallWaitingWrapper::cleanup |
|
118 */ |
|
119 void UT_PSetCallWaitingWrapper::cleanup() |
|
120 { |
|
121 reset(); |
|
122 |
|
123 delete m_psetContainerMock; |
|
124 m_psetContainerMock = NULL; |
|
125 m_psetCallWaitingMock = NULL; |
|
126 delete m_wrapper; |
|
127 m_wrapper = NULL; |
|
128 } |
|
129 |
|
130 |
|
131 /*! |
|
132 UT_PSetCallWaitingWrapper::t_construction |
|
133 */ |
|
134 void UT_PSetCallWaitingWrapper::t_construction() |
|
135 { |
|
136 if (qstrcmp(QTest::currentTestFunction(), "t_exceptionSafety") != 0) { |
|
137 expect("CPsetContainer::CreateCWObjectL"). |
|
138 willOnce(invokeWithoutArguments(SimulateLeaveL)); |
|
139 |
|
140 PSetCallWaitingWrapper *wrapper = NULL; |
|
141 EXPECT_EXCEPTION( |
|
142 wrapper = new PSetCallWaitingWrapper(*m_psetContainerMock, NULL); |
|
143 ) |
|
144 delete wrapper; |
|
145 |
|
146 QVERIFY(verify()); |
|
147 } |
|
148 } |
|
149 |
|
150 |
|
151 /*! |
|
152 UT_PSetCallWaitingWrapper::t_setCallWaiting |
|
153 */ |
|
154 void UT_PSetCallWaitingWrapper::t_setCallWaiting() |
|
155 { |
|
156 TBasicServiceGroups basicServiceGroup = EAllTele; |
|
157 expect("CPsetCallWaiting::SetCallWaitingL"). |
|
158 with(MPsetCallWaiting::EActivateCallWaiting, basicServiceGroup); |
|
159 expect("CPsetCallWaiting::SetCallWaitingL"). |
|
160 with(MPsetCallWaiting::EDeactivateCallWaiting, basicServiceGroup); |
|
161 |
|
162 int invalidEnumeration = -1; |
|
163 expect("CPsetCallWaiting::SetCallWaitingL"). |
|
164 with(static_cast<MPsetCallWaiting::TSetCallWaiting>(invalidEnumeration), basicServiceGroup). |
|
165 willOnce(invokeWithoutArguments(this, &SimulateLeaveAtMockMethodCallL)); |
|
166 |
|
167 m_wrapper->setCallWaiting( |
|
168 PSetCallWaitingWrapper::ActivateCallWaiting, |
|
169 basicServiceGroup); |
|
170 m_wrapper->setCallWaiting( |
|
171 PSetCallWaitingWrapper::DeactivateCallWaiting, |
|
172 basicServiceGroup); |
|
173 EXPECT_EXCEPTION( |
|
174 m_wrapper->setCallWaiting( |
|
175 static_cast<PSetCallWaitingWrapper::PsCallWaitingCommand>(invalidEnumeration), |
|
176 basicServiceGroup); |
|
177 ) |
|
178 |
|
179 QVERIFY(1 == m_numOfLeaveSimulations); |
|
180 QVERIFY(true == verify()); |
|
181 } |
|
182 |
|
183 /*! |
|
184 UT_PSetCallWaitingWrapper::t_getCallWaitingStatus |
|
185 */ |
|
186 void UT_PSetCallWaitingWrapper::t_getCallWaitingStatus() |
|
187 { |
|
188 expect("CPsetCallWaiting::GetCallWaitingStatusL"). |
|
189 willOnce(invoke(this, &SimulateLeaveAtMockMethodCallL)); |
|
190 |
|
191 EXPECT_EXCEPTION( |
|
192 m_wrapper->getCallWaitingStatus(); |
|
193 ) |
|
194 |
|
195 QVERIFY(true == verify()); |
|
196 } |
|
197 |
|
198 /*! |
|
199 UT_PSetCallWaitingWrapper::t_cancelProcess |
|
200 */ |
|
201 void UT_PSetCallWaitingWrapper::t_cancelProcess() |
|
202 { |
|
203 expect("CPsetCallWaiting::CancelProcess"); |
|
204 |
|
205 m_wrapper->cancelProcess(); |
|
206 |
|
207 QVERIFY(true == verify()); |
|
208 } |
|
209 |
|
210 /*! |
|
211 UT_PSetCallWaitingWrapper::t_handleCallWaitingGetStatus |
|
212 */ |
|
213 Q_DECLARE_METATYPE(PSetCallWaitingWrapper::PsCallWaitingStatus) |
|
214 Q_DECLARE_METATYPE(QList<unsigned char>) |
|
215 void UT_PSetCallWaitingWrapper::t_handleCallWaitingGetStatus() |
|
216 { |
|
217 qRegisterMetaType<PSetCallWaitingWrapper::PsCallWaitingStatus> |
|
218 ("PSetCallWaitingWrapper::PsCallWaitingStatus"); |
|
219 qRegisterMetaType<QList<unsigned char> >("QList<unsigned char>"); |
|
220 QSignalSpy spy(m_wrapper, SIGNAL(handleCallWaitingGetStatus( |
|
221 PSetCallWaitingWrapper::PsCallWaitingStatus, const QList<unsigned char> &))); |
|
222 |
|
223 MPsetCallWaiting::TGetCallWaitingStatus status = |
|
224 MPsetCallWaiting::EStatusActive; |
|
225 TUint8 bscList[KPSetNumberOfBsc]; |
|
226 bscList[0] = EAllTele; |
|
227 bscList[1] = KPSetUnusedValue; |
|
228 QT_TRAP_THROWING( |
|
229 m_wrapper->m_privateImpl->HandleCallWaitingGetStatusL(status, bscList)); |
|
230 status = MPsetCallWaiting::EStatusDisabled; |
|
231 QT_TRAP_THROWING( |
|
232 m_wrapper->m_privateImpl->HandleCallWaitingGetStatusL(status, bscList)); |
|
233 status = MPsetCallWaiting::EStatusNotAvailable; |
|
234 QT_TRAP_THROWING( |
|
235 m_wrapper->m_privateImpl->HandleCallWaitingGetStatusL(status, bscList)); |
|
236 status = MPsetCallWaiting::EStatusNotProvisioned; |
|
237 QT_TRAP_THROWING( |
|
238 m_wrapper->m_privateImpl->HandleCallWaitingGetStatusL(status, bscList)); |
|
239 status = MPsetCallWaiting::EStatusUnknown; |
|
240 QT_TRAP_THROWING( |
|
241 m_wrapper->m_privateImpl->HandleCallWaitingGetStatusL(status, bscList)); |
|
242 |
|
243 const int expectedNumOfSignalEmissions = 5; |
|
244 QCOMPARE(spy.count(), expectedNumOfSignalEmissions); |
|
245 const QList<QVariant> &arguments = spy.at(0); |
|
246 QVERIFY(PSetCallWaitingWrapper::StatusActive == |
|
247 arguments.at(0).value<PSetCallWaitingWrapper::PsCallWaitingStatus>()); |
|
248 QVERIFY(EAllTele == arguments.at(1).value<QList<unsigned char> >()[0]); |
|
249 QVERIFY(PSetCallWaitingWrapper::StatusDisabled == |
|
250 spy.at(1).at(0).value<PSetCallWaitingWrapper::PsCallWaitingStatus>()); |
|
251 QVERIFY(EAllTele == spy.at(1).at(1).value<QList<unsigned char> >()[0]); |
|
252 QVERIFY(PSetCallWaitingWrapper::StatusNotAvailable == |
|
253 spy.at(2).at(0).value<PSetCallWaitingWrapper::PsCallWaitingStatus>()); |
|
254 QVERIFY(EAllTele == spy.at(2).at(1).value<QList<unsigned char> >()[0]); |
|
255 QVERIFY(PSetCallWaitingWrapper::StatusNotProvisioned == |
|
256 spy.at(3).at(0).value<PSetCallWaitingWrapper::PsCallWaitingStatus>()); |
|
257 QVERIFY(EAllTele == spy.at(3).at(1).value<QList<unsigned char> >()[0]); |
|
258 QVERIFY(PSetCallWaitingWrapper::StatusUnknown == |
|
259 spy.at(4).at(0).value<PSetCallWaitingWrapper::PsCallWaitingStatus>()); |
|
260 QVERIFY(EAllTele == spy.at(4).at(1).value<QList<unsigned char> >()[0]); |
|
261 } |
|
262 |
|
263 /*! |
|
264 UT_PSetCallWaitingWrapper::t_handleCallWaitingChanged |
|
265 */ |
|
266 Q_DECLARE_METATYPE(PSetCallWaitingWrapper::PsCallWaitingCommand) |
|
267 void UT_PSetCallWaitingWrapper::t_handleCallWaitingChanged() |
|
268 { |
|
269 qRegisterMetaType<PSetCallWaitingWrapper::PsCallWaitingCommand> |
|
270 ("PSetCallWaitingWrapper::PsCallWaitingCommand"); |
|
271 QSignalSpy spy(m_wrapper, SIGNAL(handleCallWaitingChanged( |
|
272 PSetCallWaitingWrapper::PsCallWaitingCommand, int))); |
|
273 |
|
274 QT_TRAP_THROWING( |
|
275 m_wrapper->m_privateImpl->HandleCallWaitingChangedL( |
|
276 MPsetCallWaiting::EActivateCallWaiting, KErrNone)); |
|
277 QT_TRAP_THROWING( |
|
278 m_wrapper->m_privateImpl->HandleCallWaitingChangedL( |
|
279 MPsetCallWaiting::EDeactivateCallWaiting, KErrNone)); |
|
280 |
|
281 const int expectedNumOfSignalEmissions = 2; |
|
282 QCOMPARE(spy.count(), expectedNumOfSignalEmissions); |
|
283 QVERIFY(PSetCallWaitingWrapper::ActivateCallWaiting == |
|
284 spy.at(0).at(0).value<PSetCallWaitingWrapper::PsCallWaitingCommand>()); |
|
285 QVERIFY(KErrNone == spy.at(0).at(1).toInt()); |
|
286 QVERIFY(PSetCallWaitingWrapper::DeactivateCallWaiting == |
|
287 spy.at(1).at(0).value<PSetCallWaitingWrapper::PsCallWaitingCommand>()); |
|
288 QVERIFY(KErrNone == spy.at(1).at(1).toInt()); |
|
289 } |
|
290 |
|
291 /*! |
|
292 UT_PSetCallWaitingWrapper::t_handleCallWaitingRequesting |
|
293 */ |
|
294 void UT_PSetCallWaitingWrapper::t_handleCallWaitingRequesting() |
|
295 { |
|
296 QSignalSpy spy(m_wrapper, |
|
297 SIGNAL(handleCallWaitingRequesting(bool, bool))); |
|
298 |
|
299 QT_TRAP_THROWING( |
|
300 m_wrapper->m_privateImpl->HandleCWRequestingL(ETrue, ETrue)); |
|
301 |
|
302 QCOMPARE(spy.count(), 1); |
|
303 const QList<QVariant> &arguments = spy.at(0); |
|
304 QVERIFY(true == arguments.at(0).toBool()); |
|
305 QVERIFY(true == arguments.at(1).toBool()); |
|
306 } |
|
307 |
|
308 /*! |
|
309 UT_PSetCallWaitingWrapper::t_handleCallWaitingError |
|
310 */ |
|
311 void UT_PSetCallWaitingWrapper::t_handleCallWaitingError() |
|
312 { |
|
313 QSignalSpy spy(m_wrapper, SIGNAL(handleCallWaitingError(int))); |
|
314 |
|
315 QT_TRAP_THROWING(m_wrapper->m_privateImpl->HandleCWErrorL(KErrGeneral)); |
|
316 |
|
317 QCOMPARE(spy.count(), 1); |
|
318 const QList<QVariant> &arguments = spy.at(0); |
|
319 QVERIFY(KErrGeneral == arguments.at(0).toInt()); |
|
320 } |
|
321 |
|
322 /*! |
|
323 UT_PSetCallWaitingWrapper::t_setEngineContact |
|
324 */ |
|
325 void UT_PSetCallWaitingWrapper::t_setEngineContact() |
|
326 { |
|
327 // dummy test as no real implementation for the method currently |
|
328 m_wrapper->m_privateImpl->SetEngineContact( |
|
329 reinterpret_cast<MPsetCallWaiting&>(*this)); |
|
330 } |
|
331 |
|
332 /*! |
|
333 UT_PSetCallWaitingWrapper::t_exceptionSafety |
|
334 */ |
|
335 void UT_PSetCallWaitingWrapper::t_exceptionSafety() |
|
336 { |
|
337 cleanup(); |
|
338 |
|
339 OomTestExecuter::runAllTests(*this, "t_exceptionSafety"); |
|
340 } |
|
341 |
|
342 void UT_PSetCallWaitingWrapper::SimulateLeaveAtMockMethodCallL() |
|
343 { |
|
344 m_numOfLeaveSimulations++; |
|
345 User::Leave( KErrGeneral ); |
|
346 } |
|
347 |
|
348 QTEST_MAIN_S60(UT_PSetCallWaitingWrapper) |