|
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: Unit tests for PhoneUIQtButtonsController. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QtTest/QtTest> |
|
19 #include <mockservice.h> |
|
20 #include "qtestmains60.h" |
|
21 #include "phonecallheaderutil.h" |
|
22 #include "pevirtualengine.h" |
|
23 #include "cpeengineinfo.h" |
|
24 #include "tphonecmdparamcallheaderdata.h" |
|
25 #include "cphonemainresourceresolver.h" |
|
26 #include "cphonecenrepproxy.h" |
|
27 #include "phonerssbase.h" |
|
28 #include <StringLoader.h> |
|
29 #include <coemain.h> |
|
30 |
|
31 _LIT(KSimulatedStringLoaderString,"1234567890"); |
|
32 |
|
33 class CPhoneMainResourceResolverMock : public CPhoneMainResourceResolver |
|
34 { |
|
35 }; |
|
36 |
|
37 class CPhoneCenRepProxyMock : public CPhoneCenRepProxy |
|
38 { |
|
39 public: |
|
40 CPhoneCenRepProxyMock() {}; |
|
41 }; |
|
42 |
|
43 void simulateStringLoad(TDes& buf, TInt /*id*/, CCoeEnv* /*coeenv*/) |
|
44 { |
|
45 buf.Append(KSimulatedStringLoaderString()); |
|
46 } |
|
47 |
|
48 class TestPhoneCallHeaderUtil : public QObject, MockService |
|
49 { |
|
50 Q_OBJECT |
|
51 public: |
|
52 TestPhoneCallHeaderUtil(); |
|
53 virtual ~TestPhoneCallHeaderUtil(); |
|
54 |
|
55 public slots: |
|
56 void initTestCase (); |
|
57 void cleanupTestCase (); |
|
58 void init (); |
|
59 void cleanup (); |
|
60 |
|
61 private slots: |
|
62 void testSetIncomingCallHeaderParams(); |
|
63 void testSetOutgoingCallHeaderParams(); |
|
64 void testUpdateCallHeaderInfo(); |
|
65 void testSetCallHeaderType(); |
|
66 void testSetDivertIndication(); |
|
67 void testGetRemoteInfoData(); |
|
68 void testSetCallHeaderTexts(); |
|
69 void testLabelText(); |
|
70 void testEmergencyHeaderText(); |
|
71 void testAttemptingEmergencyText(); |
|
72 void testCallState(); |
|
73 void testLoadResource(); |
|
74 |
|
75 private: |
|
76 CPEEngineInfo* m_engineInfo; |
|
77 PhoneCallHeaderUtil* m_util; |
|
78 CPhoneMainResourceResolverMock* m_resourceResolverMock; |
|
79 CPhoneCenRepProxyMock* m_cenrepProxyMock; |
|
80 }; |
|
81 |
|
82 TestPhoneCallHeaderUtil::TestPhoneCallHeaderUtil () |
|
83 { |
|
84 |
|
85 } |
|
86 |
|
87 TestPhoneCallHeaderUtil::~TestPhoneCallHeaderUtil () |
|
88 { |
|
89 } |
|
90 |
|
91 void TestPhoneCallHeaderUtil::initTestCase () |
|
92 { |
|
93 m_engineInfo = CPEEngineInfo::NewL(); |
|
94 m_util = new PhoneCallHeaderUtil(*m_engineInfo); |
|
95 |
|
96 m_resourceResolverMock = new CPhoneMainResourceResolverMock(); |
|
97 SmcDefaultValue<CPhoneMainResourceResolver*>::SetL( m_resourceResolverMock ); |
|
98 |
|
99 m_cenrepProxyMock = new CPhoneCenRepProxyMock(); |
|
100 SmcDefaultValue<CPhoneCenRepProxy*>::SetL( m_cenrepProxyMock ); |
|
101 } |
|
102 |
|
103 void TestPhoneCallHeaderUtil::cleanupTestCase () |
|
104 { |
|
105 delete m_util; |
|
106 delete m_engineInfo; |
|
107 delete m_resourceResolverMock; |
|
108 } |
|
109 |
|
110 void TestPhoneCallHeaderUtil::init () |
|
111 { |
|
112 initialize(); |
|
113 } |
|
114 |
|
115 void TestPhoneCallHeaderUtil::cleanup () |
|
116 { |
|
117 reset(); |
|
118 } |
|
119 |
|
120 void TestPhoneCallHeaderUtil::testSetIncomingCallHeaderParams() |
|
121 { |
|
122 TPhoneCmdParamCallHeaderData data; |
|
123 |
|
124 const int callId = 1; |
|
125 const int serviceId = 100; |
|
126 _LIT(KPhoneNumber,"123456"); |
|
127 _LIT(KCallerImage,"image.jpg"); |
|
128 |
|
129 m_engineInfo->SetCallState(EPEStateRinging, callId); |
|
130 m_engineInfo->SetCallType(EPECallTypeCSVoice, callId); |
|
131 m_engineInfo->SetCallSecureStatus(EFalse, callId); |
|
132 m_engineInfo->SetSecureSpecified(ETrue); |
|
133 m_engineInfo->SetServiceId(callId, serviceId); |
|
134 m_engineInfo->SetRemotePhoneNumber(KPhoneNumber(), callId); |
|
135 m_engineInfo->SetRemotePhoneNumberType(EPEMobileNumber, callId); |
|
136 m_engineInfo->SetCallerImage(KCallerImage(), callId); |
|
137 m_engineInfo->SetIncomingCallForwarded(ETrue, callId); |
|
138 |
|
139 EXPECT(CPhoneMainResourceResolver,ResolveResourceID).with(EPhoneIncomingCallLabel); |
|
140 m_util->SetIncomingCallHeaderParams(callId,EFalse,EFalse,&data); |
|
141 QVERIFY(verify()); |
|
142 |
|
143 QVERIFY(data.CallState()==EPEStateRinging); |
|
144 QVERIFY(data.CallType()==EPECallTypeCSVoice); |
|
145 QVERIFY(data.Ciphering()==EFalse); |
|
146 QVERIFY(data.CipheringIndicatorAllowed()==ETrue); |
|
147 QVERIFY(data.ServiceId()==serviceId); |
|
148 QVERIFY(data.RemotePhoneNumber()==KPhoneNumber); |
|
149 QVERIFY(data.NumberType()==EPEMobileNumber); |
|
150 QVERIFY(data.Picture()==KCallerImage); |
|
151 QVERIFY(data.Diverted()==ETrue); |
|
152 } |
|
153 |
|
154 void TestPhoneCallHeaderUtil::testSetOutgoingCallHeaderParams() |
|
155 { |
|
156 TPhoneCmdParamCallHeaderData data; |
|
157 |
|
158 const int callId = 1; |
|
159 const int serviceId = 100; |
|
160 _LIT(KPhoneNumber,"123456"); |
|
161 _LIT(KCallerImage,"image.jpg"); |
|
162 |
|
163 m_engineInfo->SetCallState(EPEStateDialing, callId); |
|
164 m_engineInfo->SetCallType(EPECallTypeCSVoice, callId); |
|
165 m_engineInfo->SetCallSecureStatus(EFalse, callId); |
|
166 m_engineInfo->SetSecureSpecified(ETrue); |
|
167 m_engineInfo->SetServiceId(callId, serviceId); |
|
168 m_engineInfo->SetRemotePhoneNumber(KPhoneNumber(), callId); |
|
169 m_engineInfo->SetRemotePhoneNumberType(EPEMobileNumber, callId); |
|
170 m_engineInfo->SetCallerImage(KCallerImage(), callId); |
|
171 |
|
172 EXPECT(CPhoneMainResourceResolver,ResolveResourceID).with(EPhoneOutgoingCallLabel); |
|
173 m_util->SetOutgoingCallHeaderParams(callId,&data); |
|
174 QVERIFY(verify()); |
|
175 |
|
176 QVERIFY(data.CallState()==EPEStateDialing); |
|
177 QVERIFY(data.CallType()==EPECallTypeCSVoice); |
|
178 QVERIFY(data.Ciphering()==EFalse); |
|
179 QVERIFY(data.CipheringIndicatorAllowed()==ETrue); |
|
180 QVERIFY(data.ServiceId()==serviceId); |
|
181 QVERIFY(data.RemotePhoneNumber()==KPhoneNumber); |
|
182 QVERIFY(data.NumberType()==EPEMobileNumber); |
|
183 QVERIFY(data.Picture()==KCallerImage); |
|
184 } |
|
185 |
|
186 void TestPhoneCallHeaderUtil::testUpdateCallHeaderInfo() |
|
187 { |
|
188 TPhoneCmdParamCallHeaderData data; |
|
189 |
|
190 const int callId = 1; |
|
191 const int serviceId = 100; |
|
192 _LIT(KPhoneNumber,"123456"); |
|
193 _LIT(KCallerImage,"image.jpg"); |
|
194 |
|
195 m_engineInfo->SetRemotePhoneNumber(KPhoneNumber(), callId); |
|
196 m_engineInfo->SetRemotePhoneNumberType(EPEMobileNumber, callId); |
|
197 m_engineInfo->SetRemoteIdentity(RMobileCall::ERemoteIdentityAvailable, callId); |
|
198 m_engineInfo->SetCallerImage(KCallerImage(), callId); |
|
199 |
|
200 EXPECT(CPhoneMainResourceResolver,ResolveResourceID).with(EPhoneIncomingCallLabel); |
|
201 m_util->UpdateCallHeaderInfo(1,0,0,&data); |
|
202 QVERIFY(verify()); |
|
203 |
|
204 QVERIFY(data.CLIText()==KPhoneNumber); |
|
205 QVERIFY(data.Picture()==KCallerImage); |
|
206 } |
|
207 |
|
208 void TestPhoneCallHeaderUtil::testSetCallHeaderType() |
|
209 { |
|
210 m_util->SetCallHeaderType(EPECallTypeCSVoice); |
|
211 QVERIFY(m_util->CallHeaderType()==EPECallTypeCSVoice); |
|
212 } |
|
213 |
|
214 void TestPhoneCallHeaderUtil::testSetDivertIndication() |
|
215 { |
|
216 m_util->SetDivertIndication(ETrue); |
|
217 } |
|
218 |
|
219 void TestPhoneCallHeaderUtil::testGetRemoteInfoData() |
|
220 { |
|
221 TBuf<100> buf; |
|
222 const int callId = 1; |
|
223 _LIT(KPhoneNumber,"123456"); |
|
224 |
|
225 m_engineInfo->SetRemotePhoneNumber(KPhoneNumber(), callId); |
|
226 m_engineInfo->SetRemotePhoneNumberType(EPEMobileNumber, callId); |
|
227 m_engineInfo->SetCallDirection(RMobileCall::EMobileTerminated, callId); |
|
228 m_engineInfo->SetRemoteIdentity(RMobileCall::ERemoteIdentityAvailable, callId); |
|
229 |
|
230 m_util->GetRemoteInfoData(callId,buf); |
|
231 QVERIFY(buf==KPhoneNumber()); |
|
232 } |
|
233 |
|
234 void TestPhoneCallHeaderUtil::testSetCallHeaderTexts() |
|
235 { |
|
236 TPhoneCmdParamCallHeaderData data; |
|
237 |
|
238 const int callId = 1; |
|
239 const int serviceId = 100; |
|
240 _LIT(KPhoneNumber,"123456"); |
|
241 |
|
242 m_engineInfo->SetRemotePhoneNumber(KPhoneNumber(), callId); |
|
243 m_engineInfo->SetRemotePhoneNumberType(EPEMobileNumber, callId); |
|
244 m_engineInfo->SetALSLine(CCCECallParameters::ECCELineTypePrimary); |
|
245 |
|
246 EXPECT(CPhoneMainResourceResolver,ResolveResourceID).with(EPhoneIncomingCallLabel); |
|
247 m_util->SetCallHeaderTexts(1,0,0,&data); |
|
248 |
|
249 QVERIFY(verify()); |
|
250 } |
|
251 |
|
252 void TestPhoneCallHeaderUtil::testLabelText() |
|
253 { |
|
254 const int callId = 1; |
|
255 |
|
256 m_engineInfo->SetCallState(EPEStateHeld, callId); |
|
257 m_engineInfo->SetCallType(EPECallTypeCSVoice, callId); |
|
258 |
|
259 TBuf<100> label = m_util->LabelText(1); |
|
260 EXPECT(CPhoneMainResourceResolver,ResolveResourceID).with(EPhoneCallOnHold); |
|
261 } |
|
262 |
|
263 void TestPhoneCallHeaderUtil::testEmergencyHeaderText() |
|
264 { |
|
265 _LIT( KResourceText, "emergency" ); |
|
266 HBufC* text = KResourceText().AllocLC(); |
|
267 EXPECT(StringLoader,LoadL).returns<HBufC*>(0); |
|
268 QVERIFY(m_util->EmergencyHeaderText()==KNullDesC); |
|
269 verify(); |
|
270 EXPECT(StringLoader,LoadL).returns(text); |
|
271 QVERIFY(m_util->EmergencyHeaderText()==text->Des()); |
|
272 verify(); |
|
273 } |
|
274 |
|
275 void TestPhoneCallHeaderUtil::testAttemptingEmergencyText() |
|
276 { |
|
277 _LIT( KResourceText, "attempting" ); |
|
278 HBufC* text = KResourceText().AllocLC(); |
|
279 EXPECT(StringLoader,LoadL).returns<HBufC*>(0); |
|
280 QVERIFY(m_util->AttemptingEmergencyText()==KNullDesC); |
|
281 verify(); |
|
282 EXPECT(StringLoader,LoadL).returns(text); |
|
283 QVERIFY(m_util->AttemptingEmergencyText()==text->Des()); |
|
284 verify(); |
|
285 } |
|
286 |
|
287 void TestPhoneCallHeaderUtil::testCallState() |
|
288 { |
|
289 m_engineInfo->SetCallState(EPEStateDialing,1); |
|
290 QVERIFY(m_util->CallState(1)==EPEStateDialing); |
|
291 } |
|
292 |
|
293 void TestPhoneCallHeaderUtil::testLoadResource() |
|
294 { |
|
295 TBuf<100> buf; |
|
296 |
|
297 EXPECT(CPhoneMainResourceResolver,ResolveResourceID).with(1).returns(1); |
|
298 EXPECT(StringLoader,Load).willOnce(invoke(simulateStringLoad)); |
|
299 m_util->LoadResource(buf,1); |
|
300 QVERIFY(verify()); |
|
301 QVERIFY(buf==KSimulatedStringLoaderString()); |
|
302 |
|
303 _LIT( KResourceText, "resource" ); |
|
304 HBufC* text = KResourceText().AllocLC(); |
|
305 EXPECT(CPhoneMainResourceResolver,ResolveResourceID).with(1).returns(1); |
|
306 EXPECT(StringLoader,LoadL).returns(text); |
|
307 HBufC* ret = m_util->LoadResource(1); |
|
308 QVERIFY(ret==text); |
|
309 delete text; |
|
310 } |
|
311 |
|
312 QTEST_MAIN_S60(TestPhoneCallHeaderUtil) |
|
313 #include "unit_tests.moc" |