|
1 /* |
|
2 * Copyright (c) 2008-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 |
|
19 #include "mt_cntactions.h" |
|
20 |
|
21 #include <QtTest/QtTest> |
|
22 |
|
23 #define QTRY_COMPARE(__expr, __expected) \ |
|
24 do { \ |
|
25 const int __step = 50; \ |
|
26 const int __timeout = 1000; \ |
|
27 QTest::qWait(10); \ |
|
28 for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \ |
|
29 QTest::qWait(__step); \ |
|
30 } \ |
|
31 QCOMPARE(__expr, __expected); \ |
|
32 } while(0) |
|
33 |
|
34 |
|
35 void TestCntActions::initTestCase() |
|
36 { |
|
37 int error = qRegisterMetaType<QContactAction::State>(); |
|
38 //create manager |
|
39 m_manager = new QContactManager("symbian"); |
|
40 |
|
41 } |
|
42 |
|
43 void TestCntActions::cleanupTestCase() |
|
44 { |
|
45 delete m_manager; |
|
46 } |
|
47 |
|
48 void TestCntActions::init() |
|
49 { |
|
50 //delete all contacts from the database |
|
51 QList<QContactLocalId> contacts = m_manager->contactIds(); |
|
52 QMap<int, QContactManager::Error> errorMap; |
|
53 m_manager->removeContacts(contacts, &errorMap); |
|
54 } |
|
55 |
|
56 void TestCntActions::cleanup() |
|
57 {} |
|
58 |
|
59 void TestCntActions::emptyContactNoActionSupport() |
|
60 { |
|
61 QContact contact; |
|
62 m_manager->saveContact(&contact); |
|
63 |
|
64 //expected no actions found |
|
65 QList<QContactActionDescriptor> actions = contact.availableActions(); |
|
66 QVERIFY(actions.count() == 0); |
|
67 } |
|
68 |
|
69 void TestCntActions::phonenumberCallSupport() |
|
70 { |
|
71 QContact contact; |
|
72 |
|
73 //Add phonenumber to contact |
|
74 QContactPhoneNumber number; |
|
75 number.setSubTypes(QContactPhoneNumber::SubTypeMobile); |
|
76 number.setNumber("555111222"); |
|
77 contact.saveDetail(&number); |
|
78 m_manager->saveContact(&contact); |
|
79 |
|
80 //verify that the contact has a phonenumber |
|
81 QList<QContactPhoneNumber> numberList = contact.details<QContactPhoneNumber>(); |
|
82 QVERIFY(numberList.count() > 0); |
|
83 |
|
84 //get the actions |
|
85 QList<QContactActionDescriptor> actionDescriptors = contact.availableActions(); |
|
86 QStringList actions; |
|
87 for (int i = 0;i < actionDescriptors.count();i++) |
|
88 { |
|
89 QString action = actionDescriptors.at(i).actionName(); |
|
90 actions << action; |
|
91 } |
|
92 |
|
93 //verify that it includes the actiosn |
|
94 QVERIFY(actions.contains("call", Qt::CaseInsensitive)); |
|
95 |
|
96 //verify that the action works |
|
97 QList<QContactActionDescriptor> callActionDescriptors = QContactAction::actionDescriptors("call", "symbian"); |
|
98 QVERIFY(callActionDescriptors.count() == 1); |
|
99 QContactAction *callAction = QContactAction::action(callActionDescriptors.at(0)); |
|
100 QVERIFY(callAction != 0); |
|
101 QVERIFY(callAction->isDetailSupported(numberList.at(0)) == true); |
|
102 QVariantMap variantMap = callAction->metaData(); |
|
103 QVERIFY(variantMap.count() == 0); |
|
104 variantMap = callAction->results(); |
|
105 QVERIFY(variantMap.count() == 0); |
|
106 QSignalSpy spyCallAction(callAction, SIGNAL(stateChanged(QContactAction::State))); |
|
107 callAction->invokeAction(contact, numberList.at(0)); |
|
108 callAction->invokeAction(contact); |
|
109 QTRY_COMPARE(spyCallAction.count(), 2); // make sure the signal was emitted exactly one time |
|
110 delete callAction; |
|
111 } |
|
112 |
|
113 void TestCntActions::phonenumberNoCallSupport() |
|
114 { |
|
115 QContact contact; |
|
116 m_manager->saveContact(&contact); |
|
117 |
|
118 //no actions expected |
|
119 QList<QContactActionDescriptor> actionDescriptors = contact.availableActions(); |
|
120 QStringList actions; |
|
121 for (int i = 0;i < actionDescriptors.count();i++) |
|
122 { |
|
123 QString action = actionDescriptors.at(i).actionName(); |
|
124 actions << action; |
|
125 } |
|
126 |
|
127 QVERIFY(actions.contains("call", Qt::CaseInsensitive) == false); |
|
128 } |
|
129 |
|
130 void TestCntActions::phonenumberMessageSupport() |
|
131 { |
|
132 QContact contact; |
|
133 |
|
134 //Add phonenumber to contact |
|
135 QContactPhoneNumber number; |
|
136 number.setSubTypes(QContactPhoneNumber::SubTypeMobile); |
|
137 number.setNumber("555111222"); |
|
138 contact.saveDetail(&number); |
|
139 m_manager->saveContact(&contact); |
|
140 |
|
141 //verify that the contact has a phonenumber |
|
142 QList<QContactPhoneNumber> numberList = contact.details<QContactPhoneNumber>(); |
|
143 QVERIFY(numberList.count() > 0); |
|
144 |
|
145 //get the actions |
|
146 QList<QContactActionDescriptor> actionDescriptors = contact.availableActions(); |
|
147 QStringList actions; |
|
148 for (int i = 0;i < actionDescriptors.count();i++) |
|
149 { |
|
150 QString action = actionDescriptors.at(i).actionName(); |
|
151 actions << action; |
|
152 } |
|
153 |
|
154 //verify that it includes the actiosn |
|
155 QVERIFY(actions.contains("message", Qt::CaseInsensitive)); |
|
156 |
|
157 QList<QContactActionDescriptor> messageActionDescriptors = QContactAction::actionDescriptors("message", "symbian"); |
|
158 QVERIFY(messageActionDescriptors.count() == 1); |
|
159 QContactAction *messageAction = QContactAction::action(messageActionDescriptors.at(0)); |
|
160 QVERIFY(messageAction != 0); |
|
161 QVERIFY(messageAction->isDetailSupported(numberList.at(0)) == true); |
|
162 QVariantMap variantMap = messageAction->metaData(); |
|
163 QVERIFY(variantMap.count() == 0); |
|
164 variantMap = messageAction->results(); |
|
165 QVERIFY(variantMap.count() == 0); |
|
166 QSignalSpy spyMessageAction(messageAction, SIGNAL(stateChanged(QContactAction::State))); |
|
167 messageAction->invokeAction(contact, numberList.at(0)); |
|
168 messageAction->invokeAction(contact); |
|
169 QTRY_COMPARE(spyMessageAction.count(), 2); // make sure the signal was emitted exactly one time |
|
170 delete messageAction; |
|
171 } |
|
172 |
|
173 void TestCntActions::phonenumberNoMessageSupport() |
|
174 { |
|
175 QContactPhoneNumber faxNumber; |
|
176 faxNumber.setNumber("555111222"); |
|
177 faxNumber.setSubTypes(QContactPhoneNumber::SubTypeFacsimile); |
|
178 |
|
179 QList<QContactActionDescriptor> actionDescriptors = QContactAction::actionDescriptors("message", "symbian"); |
|
180 |
|
181 QContactAction* contactAction = QContactAction::action(actionDescriptors.first()); |
|
182 bool isSupportDetail = contactAction->isDetailSupported(faxNumber); |
|
183 |
|
184 delete contactAction; |
|
185 |
|
186 QVERIFY(isSupportDetail == false); |
|
187 } |
|
188 |
|
189 void TestCntActions::phonenumberVideoCallSupport() |
|
190 { |
|
191 QContact contact; |
|
192 |
|
193 //Add phonenumber to contact |
|
194 QContactPhoneNumber number; |
|
195 number.setSubTypes(QContactPhoneNumber::SubTypeMobile); |
|
196 number.setNumber("555111222"); |
|
197 contact.saveDetail(&number); |
|
198 m_manager->saveContact(&contact); |
|
199 |
|
200 //verify that the contact has a phonenumber |
|
201 QList<QContactPhoneNumber> numberList = contact.details<QContactPhoneNumber>(); |
|
202 QVERIFY(numberList.count() > 0); |
|
203 |
|
204 //get the actions |
|
205 QList<QContactActionDescriptor> actionDescriptors = contact.availableActions(); |
|
206 QStringList actions; |
|
207 for (int i = 0;i < actionDescriptors.count();i++) |
|
208 { |
|
209 QString action = actionDescriptors.at(i).actionName(); |
|
210 actions << action; |
|
211 } |
|
212 |
|
213 //verify that it includes the actiosn |
|
214 QVERIFY(actions.contains("videocall", Qt::CaseInsensitive)); |
|
215 |
|
216 //Test Video Call action |
|
217 QList<QContactActionDescriptor> videoCallActionDescriptors = QContactAction::actionDescriptors("videocall", "symbian"); |
|
218 QVERIFY(videoCallActionDescriptors.count() == 1); |
|
219 QContactAction *videoCallAction = QContactAction::action(videoCallActionDescriptors.at(0)); |
|
220 QVERIFY(videoCallAction != 0); |
|
221 QVERIFY(videoCallAction->isDetailSupported(numberList.at(0)) == true); |
|
222 QVariantMap variantMap = videoCallAction->metaData(); |
|
223 QVERIFY(variantMap.count() == 0); |
|
224 variantMap = videoCallAction->results(); |
|
225 QVERIFY(variantMap.count() == 0); |
|
226 QSignalSpy spyVideoCallAction(videoCallAction, SIGNAL(stateChanged(QContactAction::State))); |
|
227 videoCallAction->invokeAction(contact, numberList.at(0)); |
|
228 videoCallAction->invokeAction(contact); |
|
229 QTRY_COMPARE(spyVideoCallAction.count(), 2); // make sure the signal was emitted exactly one time |
|
230 delete videoCallAction; |
|
231 } |
|
232 |
|
233 void TestCntActions::phonenumberNoVideoCallSupport() |
|
234 { |
|
235 QContact contact; |
|
236 m_manager->saveContact(&contact); |
|
237 |
|
238 //expected no actions found |
|
239 QList<QContactActionDescriptor> actionDescriptors = contact.availableActions(); |
|
240 QStringList actions; |
|
241 for (int i = 0;i < actionDescriptors.count();i++) |
|
242 { |
|
243 QString action = actionDescriptors.at(i).actionName(); |
|
244 actions << action; |
|
245 } |
|
246 QVERIFY(actions.contains("videocall", Qt::CaseInsensitive) == false); |
|
247 } |
|
248 |
|
249 void TestCntActions::emailSupport() |
|
250 { |
|
251 QContact contact; |
|
252 QContactEmailAddress email; |
|
253 email.setEmailAddress("test@test.com"); |
|
254 contact.saveDetail(&email); |
|
255 m_manager->saveContact(&contact); |
|
256 |
|
257 //one number exist in contact |
|
258 QList<QContactEmailAddress> emailList = contact.details<QContactEmailAddress>(); |
|
259 QVERIFY(emailList.count() == 1); |
|
260 |
|
261 //one action expected |
|
262 QList<QContactActionDescriptor> actionDescriptors = contact.availableActions(); |
|
263 QStringList actions; |
|
264 for (int i = 0;i < actionDescriptors.count();i++) |
|
265 { |
|
266 QString action = actionDescriptors.at(i).actionName(); |
|
267 actions << action; |
|
268 } |
|
269 QVERIFY(actions.count() == 1); |
|
270 QVERIFY(actions.contains("email", Qt::CaseInsensitive)); |
|
271 |
|
272 //pick first number for the actions |
|
273 QContactEmailAddress emailAddress = contact.detail<QContactEmailAddress>(); |
|
274 |
|
275 //Test Email action |
|
276 QList<QContactActionDescriptor> emailActionDescriptors = QContactAction::actionDescriptors("email", "symbian"); |
|
277 QVERIFY(emailActionDescriptors.count() == 1); |
|
278 QContactAction *emailAction = QContactAction::action(emailActionDescriptors.at(0)); |
|
279 QVERIFY(emailAction != 0); |
|
280 QVERIFY(emailAction->isDetailSupported(emailList.at(0)) == true); |
|
281 QVariantMap variantMap = emailAction->metaData(); |
|
282 QVERIFY(variantMap.count() == 0); |
|
283 variantMap = emailAction->results(); |
|
284 QVERIFY(variantMap.count() == 0); |
|
285 QSignalSpy spyEmailAction(emailAction, SIGNAL(stateChanged(QContactAction::State))); |
|
286 emailAction->invokeAction(contact, emailAddress); |
|
287 emailAction->invokeAction(contact); |
|
288 QTRY_COMPARE(spyEmailAction.count(), 2); // make sure the signal was emitted exactly one time |
|
289 delete emailAction; |
|
290 } |
|
291 |
|
292 void TestCntActions::noEmailSupport() |
|
293 { |
|
294 QContact contact; |
|
295 m_manager->saveContact(&contact); |
|
296 |
|
297 //expected no actions found |
|
298 QList<QContactActionDescriptor> actionDescriptors = contact.availableActions(); |
|
299 QStringList actions; |
|
300 for (int i = 0;i < actionDescriptors.count();i++) |
|
301 { |
|
302 QString action = actionDescriptors.at(i).actionName(); |
|
303 actions << action; |
|
304 } |
|
305 QVERIFY(actions.contains("email", Qt::CaseInsensitive) == false); |
|
306 } |
|
307 |
|
308 void TestCntActions::urlSupport() |
|
309 { |
|
310 QContact contact; |
|
311 QContactUrl url; |
|
312 url.setUrl("www.test.com"); |
|
313 contact.saveDetail(&url); |
|
314 m_manager->saveContact(&contact); |
|
315 |
|
316 //one number exist in contact |
|
317 QList<QContactUrl> urlList = contact.details<QContactUrl>(); |
|
318 QVERIFY(urlList.count() == 1); |
|
319 |
|
320 //no actions expected |
|
321 QList<QContactActionDescriptor> actionDescriptors = contact.availableActions(); |
|
322 QStringList actions; |
|
323 for (int i = 0;i < actionDescriptors.count();i++) |
|
324 { |
|
325 QString action = actionDescriptors.at(i).actionName(); |
|
326 actions << action; |
|
327 } |
|
328 QVERIFY(actions.count() == 1); |
|
329 QVERIFY(actions.contains("url", Qt::CaseInsensitive)); |
|
330 |
|
331 //pick first number for the actions |
|
332 QContactUrl urlAddress = contact.detail<QContactUrl>(); |
|
333 |
|
334 //Test Email action |
|
335 QList<QContactActionDescriptor> urlActionDescriptors = QContactAction::actionDescriptors("url", "symbian"); |
|
336 QVERIFY(urlActionDescriptors.count() == 1); |
|
337 QContactAction *urlAction = QContactAction::action(urlActionDescriptors.at(0)); |
|
338 QVERIFY(urlAction != 0); |
|
339 QVERIFY(urlAction->isDetailSupported(urlList.at(0)) == true); |
|
340 QVariantMap variantMap = urlAction->metaData(); |
|
341 QVERIFY(variantMap.count() == 0); |
|
342 variantMap = urlAction->results(); |
|
343 QVERIFY(variantMap.count() == 0); |
|
344 QSignalSpy spyUrlAction(urlAction, SIGNAL(stateChanged(QContactAction::State))); |
|
345 urlAction->invokeAction(contact, urlAddress); |
|
346 urlAction->invokeAction(contact); |
|
347 QTRY_COMPARE(spyUrlAction.count(), 2); // make sure the signal was emitted exactly once each time |
|
348 delete urlAction; |
|
349 } |
|
350 |
|
351 void TestCntActions::noUrlSupport() |
|
352 { |
|
353 QContact contact; |
|
354 m_manager->saveContact(&contact); |
|
355 |
|
356 //expected no actions found |
|
357 QList<QContactActionDescriptor> actionDescriptors = contact.availableActions(); |
|
358 QStringList actions; |
|
359 for (int i = 0;i < actionDescriptors.count();i++) |
|
360 { |
|
361 QString action = actionDescriptors.at(i).actionName(); |
|
362 actions << action; |
|
363 } |
|
364 QVERIFY(actions.contains("url", Qt::CaseInsensitive) == false); |
|
365 } |
|
366 |
|
367 //QTEST_MAIN(TestCntActions); |