1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2015 The Qt Company Ltd. |
4 | ** Contact: http://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the test suite of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL21$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at http://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 or version 3 as published by the Free |
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and |
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the |
22 | ** following information to ensure the GNU Lesser General Public License |
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and |
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
25 | ** |
26 | ** As a special exception, The Qt Company gives you certain additional |
27 | ** rights. These rights are described in The Qt Company LGPL Exception |
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
29 | ** |
30 | ** $QT_END_LICENSE$ |
31 | ** |
32 | ****************************************************************************/ |
33 | |
34 | #include <QtTest/QtTest> |
35 | |
36 | #include <QtContacts/qcontacts.h> |
37 | #include <QtContacts/QContactDetail> |
38 | |
39 | //TESTED_COMPONENT=src/contacts |
40 | |
41 | QTCONTACTS_USE_NAMESPACE |
42 | class tst_QContactDetails : public QObject |
43 | { |
44 | Q_OBJECT |
45 | |
46 | public: |
47 | tst_QContactDetails(); |
48 | virtual ~tst_QContactDetails(); |
49 | |
50 | public slots: |
51 | void init(); |
52 | void cleanup(); |
53 | |
54 | private slots: |
55 | // leaf class testing |
56 | void address(); |
57 | void anniversary(); |
58 | void avatar(); |
59 | void birthday(); |
60 | void displayLabel(); |
61 | void emailAddress(); |
62 | void extendedDetail(); |
63 | void family(); |
64 | void favorite(); |
65 | void gender(); |
66 | void geolocation(); |
67 | void globalPresence(); |
68 | void guid(); |
69 | void hobby(); |
70 | void name(); |
71 | void nickname(); |
72 | void note(); |
73 | void onlineAccount(); |
74 | void organization(); |
75 | void phoneNumber(); |
76 | void presence(); |
77 | void ringtone(); |
78 | void syncTarget(); |
79 | void tag(); |
80 | void timestamp(); |
81 | void type(); |
82 | void url(); |
83 | void version(); |
84 | }; |
85 | |
86 | tst_QContactDetails::tst_QContactDetails() |
87 | { |
88 | } |
89 | |
90 | tst_QContactDetails::~tst_QContactDetails() |
91 | { |
92 | } |
93 | |
94 | void tst_QContactDetails::init() |
95 | { |
96 | } |
97 | |
98 | void tst_QContactDetails::cleanup() |
99 | { |
100 | } |
101 | |
102 | void tst_QContactDetails::address() |
103 | { |
104 | QContact c; |
105 | QContactAddress a1, a2; |
106 | |
107 | QVERIFY(a1.isEmpty()); |
108 | QVERIFY(a2.isEmpty()); |
109 | |
110 | // test property set |
111 | QCOMPARE(a1.street(), QString()); |
112 | a1.setStreet("68 Imaginary Avenue" ); |
113 | a1.setCountry("Australia" ); |
114 | QCOMPARE(a1.street(), QString("68 Imaginary Avenue" )); |
115 | QCOMPARE(a1.country(), QString("Australia" )); |
116 | a1.setStreet("1234" ); |
117 | QCOMPARE(a1.street(), QString("1234" )); |
118 | a1.setPostOfficeBox("PO Box 5678" ); |
119 | QCOMPARE(a1.postOfficeBox(), QString("PO Box 5678" )); |
120 | |
121 | |
122 | // Sub types |
123 | a1.setSubTypes(QList<int>() << QContactAddress::SubTypeDomestic); |
124 | QCOMPARE(a1.subTypes(), QList<int>() << QContactAddress::SubTypeDomestic); |
125 | |
126 | QList<int> sl; |
127 | sl << QContactAddress::SubTypeParcel << QContactAddress::SubTypePostal; |
128 | a1.setSubTypes(sl); |
129 | QCOMPARE(a1.subTypes(), sl); |
130 | |
131 | // test property add |
132 | QVERIFY(c.saveDetail(&a1)); |
133 | QCOMPARE(c.details(QContactAddress::Type).count(), 1); |
134 | QCOMPARE(QContactAddress(c.details(QContactAddress::Type).value(0)).street(), a1.street()); |
135 | a2.setStreet("Test" ); |
136 | QVERIFY(c.saveDetail(&a2)); |
137 | QCOMPARE(c.details(QContactAddress::Type).count(), 2); |
138 | |
139 | // test property update |
140 | a1.setValue(field: QContactAddress::FieldContext, value: QContactDetail::ContextWork); |
141 | a1.setStreet("12345" ); |
142 | QVERIFY(c.saveDetail(&a1)); |
143 | |
144 | // test property remove |
145 | QVERIFY(c.removeDetail(&a1)); |
146 | QCOMPARE(c.details(QContactAddress::Type).count(), 1); |
147 | QVERIFY(c.removeDetail(&a2)); |
148 | QVERIFY(!c.removeDetail(&a2)); // cannot remove twice |
149 | QCOMPARE(c.details(QContactAddress::Type).count(), 0); |
150 | |
151 | QContactAddress a3; |
152 | |
153 | // set street |
154 | a3.setStreet("Test" ); |
155 | QCOMPARE(a3.street(), QString("Test" )); |
156 | a3.setStreet("" ); |
157 | |
158 | // set locality |
159 | a3.setLocality("Test" ); |
160 | QCOMPARE(a3.locality(), QString("Test" )); |
161 | a3.setLocality("" ); |
162 | |
163 | // set region |
164 | a3.setRegion("Test" ); |
165 | QCOMPARE(a3.region(), QString("Test" )); |
166 | a3.setRegion("" ); |
167 | |
168 | // set postcode |
169 | a3.setPostcode("Test" ); |
170 | QCOMPARE(a3.postcode(), QString("Test" )); |
171 | a3.setPostcode("" ); |
172 | |
173 | // set country |
174 | a3.setCountry("Test" ); |
175 | QCOMPARE(a3.country(), QString("Test" )); |
176 | a3.setCountry("" ); |
177 | |
178 | // subtypes |
179 | a3.setSubTypes(QList<int>() << QContactAddress::SubTypeDomestic); |
180 | QCOMPARE(a3.subTypes(), QList<int>() << QContactAddress::SubTypeDomestic); |
181 | a3.setSubTypes(QList<int>() << QContactAddress::SubTypeInternational << QContactAddress::SubTypePostal); |
182 | QCOMPARE(a3.subTypes(), QList<int>() << QContactAddress::SubTypeInternational << QContactAddress::SubTypePostal); |
183 | |
184 | // test comparison of two addresses |
185 | QContactAddress a4; |
186 | a4.setStreet("test" ); |
187 | a4.setLocality("test" ); |
188 | a4.setRegion("test" ); |
189 | a4.setCountry("test" ); |
190 | a4.setSubTypes(QList<int>() << QContactAddress::SubTypeInternational << QContactAddress::SubTypePostal); |
191 | QContactAddress a5; |
192 | a5.setStreet("test" ); |
193 | a5.setLocality("test" ); |
194 | a5.setRegion("test" ); |
195 | a5.setCountry("test" ); |
196 | a5.setSubTypes(QList<int>() << QContactAddress::SubTypeInternational << QContactAddress::SubTypePostal); |
197 | QVERIFY(a4 == a5); |
198 | a4.setCountry("" ); |
199 | QVERIFY(a4 != a5); |
200 | a4.setCountry("test" ); |
201 | QVERIFY(a4 == a5); |
202 | a5.setPostcode("test" ); |
203 | QVERIFY(a4 != a5); |
204 | a4.setPostcode("test" ); |
205 | QVERIFY(a4 == a5); |
206 | a4.setSubTypes(QList<int>() << QContactAddress::SubTypeDomestic); |
207 | QVERIFY(a4 != a5); |
208 | a5.setSubTypes(QList<int>() << QContactAddress::SubTypePostal); |
209 | QVERIFY(a4 != a5); |
210 | a5.setSubTypes(QList<int>() << QContactAddress::SubTypeDomestic); |
211 | QVERIFY(a4 == a5); |
212 | } |
213 | |
214 | void tst_QContactDetails::anniversary() |
215 | { |
216 | QContact c; |
217 | QContactAnniversary a1, a2; |
218 | QDateTime currDateTime = QDateTime::currentDateTime(); |
219 | QDate currDate = currDateTime.date(); |
220 | QDateTime snippedDateTime = QDateTime(currDate); |
221 | |
222 | // test property set |
223 | a1.setCalendarId("1234" ); |
224 | QCOMPARE(a1.calendarId(), QString("1234" )); |
225 | QCOMPARE(a1.value(QContactAnniversary::FieldCalendarId).toString(), QString("1234" )); |
226 | a1.setEvent("4321" ); |
227 | QCOMPARE(a1.event(), QString("4321" )); |
228 | QCOMPARE(a1.value(QContactAnniversary::FieldEvent).toString(), QString("4321" )); |
229 | a1.setSubType(QContactAnniversary::SubTypeWedding); |
230 | QCOMPARE(a1.subType(), QContactAnniversary::SubTypeWedding); |
231 | QCOMPARE(static_cast<QContactAnniversary::SubType>(a1.value<int>(QContactAnniversary::FieldSubType)), QContactAnniversary::SubTypeWedding); |
232 | |
233 | a1.setOriginalDate(currDate); |
234 | QCOMPARE(a1.originalDate(), currDate); |
235 | QCOMPARE(a1.originalDateTime(), snippedDateTime); |
236 | QCOMPARE(a1.value<QDate>(QContactAnniversary::FieldOriginalDate), currDate); |
237 | QCOMPARE(a1.value<QDateTime>(QContactAnniversary::FieldOriginalDate), snippedDateTime); |
238 | |
239 | a1.setOriginalDateTime(currDateTime); |
240 | QCOMPARE(a1.originalDate(), currDate); |
241 | QCOMPARE(a1.originalDateTime(), currDateTime); |
242 | QCOMPARE(a1.value<QDate>(QContactAnniversary::FieldOriginalDate), currDate); |
243 | QCOMPARE(a1.value<QDateTime>(QContactAnniversary::FieldOriginalDate), currDateTime); |
244 | |
245 | // test property add |
246 | QVERIFY(c.saveDetail(&a1)); |
247 | QCOMPARE(c.details(QContactAnniversary::Type).count(), 1); |
248 | QCOMPARE(QContactAnniversary(c.details(QContactAnniversary::Type).value(0)).event(), a1.event()); |
249 | |
250 | // test property update |
251 | a1.setValue(field: QContactAnniversary::FieldContext, value: QContactDetail::ContextWork); |
252 | a1.setCalendarId("12345" ); |
253 | QVERIFY(c.saveDetail(&a1)); |
254 | QCOMPARE(c.details(QContactAnniversary::Type).value(0).value(QContactAnniversary::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
255 | QCOMPARE(c.details(QContactAnniversary::Type).value(0).value(QContactAnniversary::FieldCalendarId).toString(), QString("12345" )); |
256 | |
257 | // test property remove |
258 | QVERIFY(c.removeDetail(&a1)); |
259 | QCOMPARE(c.details(QContactAnniversary::Type).count(), 0); |
260 | QVERIFY(c.saveDetail(&a2)); |
261 | QCOMPARE(c.details(QContactAnniversary::Type).count(), 1); |
262 | QVERIFY(c.removeDetail(&a2)); |
263 | QCOMPARE(c.details(QContactAnniversary::Type).count(), 0); |
264 | QVERIFY(c.removeDetail(&a2) == false); |
265 | QCOMPARE(c.details(QContactAnniversary::Type).count(), 0); |
266 | } |
267 | |
268 | void tst_QContactDetails::avatar() |
269 | { |
270 | QContact c; |
271 | QContactAvatar a1, a2; |
272 | |
273 | // test property set |
274 | a1.setImageUrl(QUrl("1234" )); |
275 | QCOMPARE(a1.imageUrl(), QUrl("1234" )); |
276 | QCOMPARE(a1.value<QUrl>(QContactAvatar::FieldImageUrl), QUrl("1234" )); |
277 | a2.setVideoUrl(QUrl("videoUrl" )); |
278 | a2.setImageUrl(QUrl("imageUrl" )); |
279 | a2.setMetaData(QString("1234" )); |
280 | QCOMPARE(a2.videoUrl(), QUrl("videoUrl" )); |
281 | QCOMPARE(a2.value<QUrl>(QContactAvatar::FieldVideoUrl), QUrl("videoUrl" )); |
282 | QCOMPARE(a2.imageUrl(), QUrl("imageUrl" )); |
283 | QCOMPARE(a2.value<QUrl>(QContactAvatar::FieldImageUrl), QUrl("imageUrl" )); |
284 | QCOMPARE(a2.metaData(), QString("1234" )); |
285 | QCOMPARE(a2.value<QString>(QContactAvatar::FieldMetaData), QString("1234" )); |
286 | |
287 | // test property add |
288 | QVERIFY(c.saveDetail(&a1)); |
289 | QCOMPARE(c.details(QContactAvatar::Type).count(), 1); |
290 | QCOMPARE(QContactAvatar(c.details(QContactAvatar::Type).value(0)).imageUrl(), a1.imageUrl()); |
291 | |
292 | // test property update |
293 | a1.setValue(field: QContactAvatar::FieldContext, value: QContactDetail::ContextWork); |
294 | a1.setImageUrl(QUrl("12345" )); |
295 | QVERIFY(c.saveDetail(&a1)); |
296 | QCOMPARE(c.details(QContactAvatar::Type).value(0).value(QContactAvatar::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
297 | QCOMPARE(c.details(QContactAvatar::Type).value(0).value<QUrl>(QContactAvatar::FieldImageUrl), QUrl("12345" )); |
298 | |
299 | // test property remove |
300 | QVERIFY(c.removeDetail(&a1)); |
301 | QCOMPARE(c.details(QContactAvatar::Type).count(), 0); |
302 | QVERIFY(c.saveDetail(&a2)); |
303 | QCOMPARE(c.details(QContactAvatar::Type).count(), 1); |
304 | QVERIFY(c.removeDetail(&a2)); |
305 | QCOMPARE(c.details(QContactAvatar::Type).count(), 0); |
306 | QVERIFY(c.removeDetail(&a2) == false); |
307 | QCOMPARE(c.details(QContactAvatar::Type).count(), 0); |
308 | } |
309 | |
310 | void tst_QContactDetails::birthday() |
311 | { |
312 | QContact c; |
313 | QContactBirthday b1, b2, b3; |
314 | QDateTime currDateTime = QDateTime::currentDateTime(); |
315 | QDate currDate = currDateTime.date(); |
316 | QDateTime snippedDateTime = QDateTime(currDate); |
317 | |
318 | // test property set |
319 | b1.setDate(currDate); |
320 | QCOMPARE(b1.date(), currDate); |
321 | QCOMPARE(b1.dateTime(), snippedDateTime); |
322 | QCOMPARE(b1.value<QDate>(QContactBirthday::FieldBirthday), currDate); |
323 | QCOMPARE(b1.value<QDateTime>(QContactBirthday::FieldBirthday), snippedDateTime); |
324 | |
325 | b1.setDateTime(currDateTime); |
326 | QCOMPARE(b1.date(), currDate); |
327 | QCOMPARE(b1.dateTime(), currDateTime); |
328 | QCOMPARE(b1.value<QDate>(QContactBirthday::FieldBirthday), currDate); |
329 | QCOMPARE(b1.value<QDateTime>(QContactBirthday::FieldBirthday), currDateTime); |
330 | |
331 | b1.setCalendarId("1234" ); |
332 | QCOMPARE(b1.calendarId(), QString("1234" )); |
333 | QCOMPARE(b1.value(QContactBirthday::FieldCalendarId).toString(), QString("1234" )); |
334 | |
335 | b3.setDate(currDate); |
336 | QCOMPARE(QContactDetail(b3).value(QContactBirthday::FieldBirthday), QVariant(currDate)); |
337 | b3.setDateTime(currDateTime); |
338 | QCOMPARE(QContactDetail(b3).value(QContactBirthday::FieldBirthday), QVariant(currDateTime)); |
339 | b3.setDateTime(QDateTime(currDate, QTime(0,0,0,0))); |
340 | QCOMPARE(QContactDetail(b3).value(QContactBirthday::FieldBirthday).type(), QVariant::Date); // unfortunate but unavoidable with current impl. |
341 | QCOMPARE(QContactDetail(b3).value<QDateTime>(QContactBirthday::FieldBirthday), b3.dateTime()); |
342 | |
343 | // test property add |
344 | QVERIFY(c.saveDetail(&b1)); |
345 | QCOMPARE(c.details(QContactBirthday::Type).count(), 1); |
346 | QCOMPARE(QContactBirthday(c.details(QContactBirthday::Type).value(0)).date(), b1.date()); |
347 | |
348 | // test property update |
349 | b1.setValue(field: QContactBirthday::FieldContext, value: QContactDetail::ContextWork); |
350 | b1.setDate(currDate.addDays(days: 3)); |
351 | b1.setCalendarId("12345" ); |
352 | QVERIFY(c.saveDetail(&b1)); |
353 | QCOMPARE(c.details(QContactBirthday::Type).value(0).value(QContactBirthday::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
354 | QCOMPARE(c.details(QContactBirthday::Type).value(0).value<QDate>(QContactBirthday::FieldBirthday), currDate.addDays(3)); |
355 | QCOMPARE(c.details(QContactBirthday::Type).value(0).value(QContactBirthday::FieldCalendarId).toString(), QString("12345" )); |
356 | |
357 | // test property remove |
358 | QVERIFY(c.removeDetail(&b1)); |
359 | QCOMPARE(c.details(QContactBirthday::Type).count(), 0); |
360 | QVERIFY(c.saveDetail(&b2)); |
361 | QCOMPARE(c.details(QContactBirthday::Type).count(), 1); |
362 | QVERIFY(c.removeDetail(&b2)); |
363 | QCOMPARE(c.details(QContactBirthday::Type).count(), 0); |
364 | QVERIFY(c.removeDetail(&b2) == false); |
365 | QCOMPARE(c.details(QContactBirthday::Type).count(), 0); |
366 | } |
367 | |
368 | void tst_QContactDetails::displayLabel() |
369 | { |
370 | QContact c; |
371 | QContactDisplayLabel d1, d2; |
372 | |
373 | // test property set |
374 | d1.setLabel("1234" ); |
375 | QCOMPARE(d1.label(), QString("1234" )); |
376 | QCOMPARE(d1.value(QContactDisplayLabel::FieldLabel).toString(), QString("1234" )); |
377 | |
378 | // test property add |
379 | QVERIFY(c.saveDetail(&d1)); |
380 | QCOMPARE(c.details(QContactDisplayLabel::Type).count(), 1); |
381 | QCOMPARE(QContactDisplayLabel(c.details(QContactDisplayLabel::Type).value(0)).label(), d1.label()); |
382 | |
383 | // test property update |
384 | d1.setValue(field: QContactDisplayLabel::FieldContext, value: QContactDetail::ContextWork); |
385 | d1.setLabel("12345" ); |
386 | QVERIFY(c.saveDetail(&d1)); |
387 | QCOMPARE(c.details(QContactDisplayLabel::Type).value(0).value(QContactDisplayLabel::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
388 | QCOMPARE(c.details(QContactDisplayLabel::Type).value(0).value(QContactDisplayLabel::FieldLabel).toString(), QString("12345" )); |
389 | |
390 | // test property remove |
391 | QVERIFY(c.removeDetail(&d1)); |
392 | QCOMPARE(c.details(QContactDisplayLabel::Type).count(), 0); |
393 | QVERIFY(c.saveDetail(&d2)); |
394 | QCOMPARE(c.details(QContactDisplayLabel::Type).count(), 1); |
395 | QVERIFY(c.removeDetail(&d2)); |
396 | QCOMPARE(c.details(QContactDisplayLabel::Type).count(), 0); |
397 | QVERIFY(c.removeDetail(&d2) == false); |
398 | QCOMPARE(c.details(QContactDisplayLabel::Type).count(), 0); |
399 | } |
400 | |
401 | void tst_QContactDetails::emailAddress() |
402 | { |
403 | QContact c; |
404 | QContactEmailAddress e1, e2; |
405 | |
406 | // test property set |
407 | e1.setEmailAddress("1234" ); |
408 | QCOMPARE(e1.emailAddress(), QString("1234" )); |
409 | QCOMPARE(e1.value(QContactEmailAddress::FieldEmailAddress).toString(), QString("1234" )); |
410 | |
411 | // test property add |
412 | QVERIFY(c.saveDetail(&e1)); |
413 | QCOMPARE(c.details(QContactEmailAddress::Type).count(), 1); |
414 | QCOMPARE(QContactEmailAddress(c.details(QContactEmailAddress::Type).value(0)).emailAddress(), e1.emailAddress()); |
415 | |
416 | // test property update |
417 | e1.setValue(field: QContactEmailAddress::FieldContext, value: QContactDetail::ContextWork); |
418 | e1.setEmailAddress("12345" ); |
419 | QVERIFY(c.saveDetail(&e1)); |
420 | QCOMPARE(c.details(QContactEmailAddress::Type).value(0).value(QContactEmailAddress::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
421 | QCOMPARE(c.details(QContactEmailAddress::Type).value(0).value(QContactEmailAddress::FieldEmailAddress).toString(), QString("12345" )); |
422 | |
423 | // test property remove |
424 | QVERIFY(c.removeDetail(&e1)); |
425 | QCOMPARE(c.details(QContactEmailAddress::Type).count(), 0); |
426 | QVERIFY(c.saveDetail(&e2)); |
427 | QCOMPARE(c.details(QContactEmailAddress::Type).count(), 1); |
428 | QVERIFY(c.removeDetail(&e2)); |
429 | QCOMPARE(c.details(QContactEmailAddress::Type).count(), 0); |
430 | QVERIFY(c.removeDetail(&e2) == false); |
431 | QCOMPARE(c.details(QContactEmailAddress::Type).count(), 0); |
432 | } |
433 | |
434 | void tst_QContactDetails::extendedDetail() |
435 | { |
436 | QContact c; |
437 | QContactExtendedDetail extD1, extD2; |
438 | QVariant v1; |
439 | // test property set |
440 | v1.setValue(1); |
441 | extD1.setName("detail1" ); |
442 | extD1.setValue(field: QContactExtendedDetail::FieldData, value: v1); |
443 | |
444 | QCOMPARE(extD1.name(), QString("detail1" )); |
445 | QCOMPARE(extD1.data(), v1); |
446 | |
447 | // test property add |
448 | QVERIFY(c.saveDetail(&extD1)); |
449 | QCOMPARE(c.details(QContactExtendedDetail::Type).count(), 1); |
450 | QCOMPARE(QContactExtendedDetail(c.details(QContactExtendedDetail::Type).value(0)).name(), extD1.name()); |
451 | |
452 | // test property update |
453 | extD1.setValue(field: QContactExtendedDetail::FieldContext, value: QContactDetail::ContextWork); |
454 | extD1.setName("newDetail1" ); |
455 | extD1.setData(v1); |
456 | QVERIFY(c.saveDetail(&extD1)); |
457 | QCOMPARE(c.details(QContactExtendedDetail::Type).value(0).value(QContactExtendedDetail::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
458 | QCOMPARE(c.details(QContactExtendedDetail::Type).value(0).value(QContactExtendedDetail::FieldData).toInt(), v1.toInt()); |
459 | QCOMPARE(c.details(QContactExtendedDetail::Type).value(0).value(QContactExtendedDetail::FieldName).toString(), QString("newDetail1" )); |
460 | |
461 | // test property remove |
462 | QVERIFY(c.removeDetail(&extD1)); |
463 | QCOMPARE(c.details(QContactExtendedDetail::Type).count(), 0); |
464 | extD2 = extD1; |
465 | |
466 | QVERIFY(c.saveDetail(&extD2)); |
467 | QCOMPARE(c.details(QContactExtendedDetail::Type).count(), 1); |
468 | QVERIFY(c.removeDetail(&extD2)); |
469 | QCOMPARE(c.details(QContactExtendedDetail::Type).count(), 0); |
470 | QVERIFY(c.removeDetail(&extD2) == false); |
471 | QCOMPARE(c.details(QContactExtendedDetail::Type).count(), 0); |
472 | } |
473 | |
474 | void tst_QContactDetails::family() |
475 | { |
476 | QContact c; |
477 | QContactFamily f1, f2; |
478 | |
479 | // test property set |
480 | f1.setSpouse("1234" ); |
481 | QCOMPARE(f1.spouse(), QString("1234" )); |
482 | QCOMPARE(f1.value(QContactFamily::FieldSpouse).toString(), QString("1234" )); |
483 | |
484 | // test property add |
485 | QVERIFY(c.saveDetail(&f1)); |
486 | QCOMPARE(c.details(QContactFamily::Type).count(), 1); |
487 | QCOMPARE(QContactFamily(c.details(QContactFamily::Type).value(0)).spouse(), f1.spouse()); |
488 | |
489 | // test property update |
490 | f1.setValue(field: QContactFamily::FieldContext, value: QContactDetail::ContextWork); |
491 | f1.setSpouse("12345" ); |
492 | f1.setChildren(QStringList("54321" )); |
493 | QVERIFY(c.saveDetail(&f1)); |
494 | QCOMPARE(c.details(QContactFamily::Type).value(0).value(QContactFamily::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
495 | QCOMPARE(c.details(QContactFamily::Type).value(0).value(QContactFamily::FieldSpouse).toString(), QString("12345" )); |
496 | QCOMPARE(c.details(QContactFamily::Type).value(0).value<QStringList>(QContactFamily::FieldChildren), QStringList("54321" )); |
497 | |
498 | // test property remove |
499 | f2.setSpouse("1111" ); |
500 | QVERIFY(c.removeDetail(&f1)); |
501 | QCOMPARE(c.details(QContactFamily::Type).count(), 0); |
502 | QVERIFY(c.saveDetail(&f2)); |
503 | QCOMPARE(c.details(QContactFamily::Type).count(), 1); |
504 | QVERIFY(c.removeDetail(&f2)); |
505 | QCOMPARE(c.details(QContactFamily::Type).count(), 0); |
506 | QVERIFY(c.removeDetail(&f2) == false); |
507 | QCOMPARE(c.details(QContactFamily::Type).count(), 0); |
508 | } |
509 | |
510 | void tst_QContactDetails::favorite() |
511 | { |
512 | QContact c; |
513 | QContactFavorite f1, f2; |
514 | |
515 | // first, ensure that the default value is "false" |
516 | QCOMPARE(c.detail<QContactFavorite>().isFavorite(), false); |
517 | QCOMPARE(c.detail<QContactFavorite>().index(), 0); // 0 being "no index" :-/ -1 would be better, but not default... |
518 | QVERIFY(!f1.isFavorite()); |
519 | |
520 | // test property set |
521 | f1.setFavorite(true); |
522 | QCOMPARE(f1.isFavorite(), true); |
523 | QCOMPARE(f1.value<bool>(QContactFavorite::FieldFavorite), true); |
524 | |
525 | // test property add |
526 | QVERIFY(c.saveDetail(&f1)); |
527 | QCOMPARE(c.details(QContactFavorite::Type).count(), 1); |
528 | QCOMPARE(QContactFavorite(c.details(QContactFavorite::Type).value(0)).isFavorite(), f1.isFavorite()); |
529 | |
530 | // test property update |
531 | f1.setValue(field: QContactFavorite::FieldContext, value: QContactDetail::ContextWork); |
532 | f1.setFavorite(false); |
533 | f1.setIndex(5); |
534 | QVERIFY(c.saveDetail(&f1)); |
535 | QCOMPARE(c.details(QContactFavorite::Type).value(0).value(QContactFavorite::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
536 | QCOMPARE(c.details(QContactFavorite::Type).value(0).value<bool>(QContactFavorite::FieldFavorite), false); |
537 | QCOMPARE(c.details(QContactFavorite::Type).value(0).value<int>(QContactFavorite::FieldIndex), 5); |
538 | QCOMPARE(c.details<QContactFavorite>().value(0).index(), 5); |
539 | |
540 | // test property remove |
541 | f2.setFavorite(true); |
542 | QVERIFY(c.removeDetail(&f1)); |
543 | QCOMPARE(c.details(QContactFavorite::Type).count(), 0); |
544 | QVERIFY(c.saveDetail(&f2)); |
545 | QCOMPARE(c.details(QContactFavorite::Type).count(), 1); |
546 | QVERIFY(c.removeDetail(&f2)); |
547 | QCOMPARE(c.details(QContactFavorite::Type).count(), 0); |
548 | QVERIFY(c.removeDetail(&f2) == false); |
549 | QCOMPARE(c.details(QContactFavorite::Type).count(), 0); |
550 | } |
551 | |
552 | void tst_QContactDetails::gender() |
553 | { |
554 | QContact c; |
555 | QContactGender g1, g2; |
556 | |
557 | // test property set |
558 | g1.setGender(QContactGender::GenderFemale); |
559 | QCOMPARE(g1.gender(), QContactGender::GenderFemale); |
560 | |
561 | // test property add |
562 | QVERIFY(c.saveDetail(&g1)); |
563 | QCOMPARE(c.details(QContactGender::Type).count(), 1); |
564 | QCOMPARE(QContactGender(c.details(QContactGender::Type).value(0)).gender(), g1.gender()); |
565 | |
566 | // test property update |
567 | g1.setValue(field: QContactGender::FieldContext, value: QContactDetail::ContextWork); |
568 | g1.setGender(QContactGender::GenderMale); |
569 | QVERIFY(c.saveDetail(&g1)); |
570 | QCOMPARE(c.details(QContactGender::Type).value(0).value(QContactGender::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
571 | QCOMPARE(c.details(QContactGender::Type).value(0).value(QContactGender::FieldGender).toInt(), (int)QContactGender::GenderMale); |
572 | |
573 | // test property remove |
574 | QVERIFY(c.removeDetail(&g1)); |
575 | QCOMPARE(c.details(QContactGender::Type).count(), 0); |
576 | QVERIFY(c.saveDetail(&g2)); |
577 | QCOMPARE(c.details(QContactGender::Type).count(), 1); |
578 | QVERIFY(c.removeDetail(&g2)); |
579 | QCOMPARE(c.details(QContactGender::Type).count(), 0); |
580 | QVERIFY(c.removeDetail(&g2) == false); |
581 | QCOMPARE(c.details(QContactGender::Type).count(), 0); |
582 | } |
583 | |
584 | void tst_QContactDetails::geolocation() |
585 | { |
586 | QContact c; |
587 | QContactGeoLocation g1, g2; |
588 | |
589 | // test property set |
590 | g1.setLabel("1234" ); |
591 | QCOMPARE(g1.label(), QString("1234" )); |
592 | QCOMPARE(g1.value(QContactGeoLocation::FieldLabel).toString(), QString("1234" )); |
593 | g1.setAccuracy(3.2); |
594 | QCOMPARE(g1.accuracy(), 3.2); |
595 | QCOMPARE(g1.value(QContactGeoLocation::FieldAccuracy), QVariant(3.2)); |
596 | g1.setAltitude(3.3); |
597 | QCOMPARE(g1.altitude(), 3.3); |
598 | QCOMPARE(g1.value(QContactGeoLocation::FieldAltitude), QVariant(3.3)); |
599 | g1.setAltitudeAccuracy(3.4); |
600 | QCOMPARE(g1.altitudeAccuracy(), 3.4); |
601 | QCOMPARE(g1.value(QContactGeoLocation::FieldAltitudeAccuracy), QVariant(3.4)); |
602 | g1.setHeading(3.5); |
603 | QCOMPARE(g1.heading(), 3.5); |
604 | QCOMPARE(g1.value(QContactGeoLocation::FieldHeading), QVariant(3.5)); |
605 | g1.setLatitude(3.6); |
606 | QCOMPARE(g1.latitude(), 3.6); |
607 | QCOMPARE(g1.value(QContactGeoLocation::FieldLatitude), QVariant(3.6)); |
608 | g1.setLongitude(3.7); |
609 | QCOMPARE(g1.longitude(), 3.7); |
610 | QCOMPARE(g1.value(QContactGeoLocation::FieldLongitude), QVariant(3.7)); |
611 | QDateTime current = QDateTime::currentDateTime(); |
612 | g1.setTimestamp(current); |
613 | QCOMPARE(g1.timestamp(), current); |
614 | QCOMPARE(g1.value(QContactGeoLocation::FieldTimestamp), QVariant(current)); |
615 | g1.setSpeed(3.8); |
616 | QCOMPARE(g1.speed(), 3.8); |
617 | QCOMPARE(g1.value(QContactGeoLocation::FieldSpeed), QVariant(3.8)); |
618 | |
619 | // test property add |
620 | QVERIFY(c.saveDetail(&g1)); |
621 | QCOMPARE(c.details(QContactGeoLocation::Type).count(), 1); |
622 | QCOMPARE(QContactGeoLocation(c.details(QContactGeoLocation::Type).value(0)).label(), g1.label()); |
623 | |
624 | // test property update |
625 | g1.setLabel("12345" ); |
626 | QVERIFY(c.saveDetail(&g1)); |
627 | QCOMPARE(c.details(QContactGeoLocation::Type).value(0).value(QContactGeoLocation::FieldLabel).toString(), QString("12345" )); |
628 | |
629 | // test property remove |
630 | QVERIFY(c.removeDetail(&g1)); |
631 | QCOMPARE(c.details(QContactGeoLocation::Type).count(), 0); |
632 | QVERIFY(c.saveDetail(&g2)); |
633 | QCOMPARE(c.details(QContactGeoLocation::Type).count(), 1); |
634 | QVERIFY(c.removeDetail(&g2)); |
635 | QCOMPARE(c.details(QContactGeoLocation::Type).count(), 0); |
636 | QVERIFY(c.removeDetail(&g2) == false); |
637 | QCOMPARE(c.details(QContactGeoLocation::Type).count(), 0); |
638 | } |
639 | |
640 | void tst_QContactDetails::globalPresence() |
641 | { |
642 | QContact c; |
643 | QContactGlobalPresence p1, p2; |
644 | |
645 | // test property set |
646 | QDateTime ts = QDateTime::currentDateTime(); |
647 | p1.setTimestamp(ts); |
648 | p1.setNickname(QString("nick" )); |
649 | p1.setPresenceState(QContactPresence::PresenceExtendedAway); |
650 | p1.setPresenceStateText("1234" ); |
651 | p1.setPresenceStateImageUrl(QUrl("http://example.com/someimage.png" )); |
652 | p1.setCustomMessage("gone fishing!" ); |
653 | QCOMPARE(p1.timestamp(), ts); |
654 | QCOMPARE(p1.value<QDateTime>(QContactGlobalPresence::FieldTimestamp), ts); |
655 | QCOMPARE(p1.nickname(), QString("nick" )); |
656 | QCOMPARE(p1.value(QContactGlobalPresence::FieldNickname).toString(), QString("nick" )); |
657 | QCOMPARE(p1.presenceState(), QContactPresence::PresenceExtendedAway); |
658 | QCOMPARE(p1.value<int>(QContactGlobalPresence::FieldPresenceState), static_cast<int>(QContactPresence::PresenceExtendedAway)); |
659 | QCOMPARE(p1.presenceStateText(), QString("1234" )); |
660 | QCOMPARE(p1.value(QContactGlobalPresence::FieldPresenceStateText).toString(), QString("1234" )); |
661 | QCOMPARE(p1.presenceStateImageUrl(), QUrl("http://example.com/someimage.png" )); |
662 | QCOMPARE(p1.value<QUrl>(QContactGlobalPresence::FieldPresenceStateImageUrl), QUrl("http://example.com/someimage.png" )); |
663 | QCOMPARE(p1.customMessage(), QString("gone fishing!" )); |
664 | QCOMPARE(p1.value(QContactGlobalPresence::FieldCustomMessage).toString(), QString("gone fishing!" )); |
665 | |
666 | // test property add |
667 | QVERIFY(c.saveDetail(&p1)); |
668 | QCOMPARE(c.details(QContactGlobalPresence::Type).count(), 1); |
669 | QCOMPARE(QContactGlobalPresence(c.details(QContactGlobalPresence::Type).value(0)).presenceStateText(), p1.presenceStateText()); |
670 | |
671 | // test property update |
672 | p1.setValue(field: QContactGlobalPresence::FieldContext, value: QContactDetail::ContextWork); |
673 | p1.setPresenceStateText("12345" ); |
674 | QVERIFY(c.saveDetail(&p1)); |
675 | QCOMPARE(c.details(QContactGlobalPresence::Type).value(0).value(QContactGlobalPresence::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
676 | QCOMPARE(c.details(QContactGlobalPresence::Type).value(0).value(QContactGlobalPresence::FieldPresenceStateText).toString(), QString("12345" )); |
677 | |
678 | p2.setTimestamp(ts); |
679 | p2.setNickname(QString("test" )); |
680 | p2.setPresenceState(QContactPresence::PresenceAvailable); |
681 | p2.setPresenceStateText("online" ); |
682 | p2.setPresenceStateImageUrl(QUrl("http://example.com/someimage.png" )); |
683 | p2.setCustomMessage("C is for generic biscuit-type pastry product!" ); |
684 | |
685 | // now test that the setPresenceStateImageUrl function doesn't escape spaces and so forth. |
686 | QString imgUrlStr(QStringLiteral("http://example.com/some image.png" )); |
687 | QUrl imgUrl(imgUrlStr); |
688 | QContactPresence p3; |
689 | p3.setPresenceStateImageUrl(imgUrl); |
690 | QCOMPARE(p3.presenceStateImageUrl(), imgUrl); |
691 | QCOMPARE(p3.presenceStateImageUrl().toString(), imgUrlStr); |
692 | |
693 | // test property remove |
694 | QVERIFY(c.removeDetail(&p1)); |
695 | QCOMPARE(c.details(QContactGlobalPresence::Type).count(), 0); |
696 | QVERIFY(c.saveDetail(&p2)); |
697 | QCOMPARE(c.details(QContactGlobalPresence::Type).count(), 1); |
698 | QVERIFY(c.removeDetail(&p2)); |
699 | QCOMPARE(c.details(QContactGlobalPresence::Type).count(), 0); |
700 | QVERIFY(c.removeDetail(&p2) == false); |
701 | QCOMPARE(c.details(QContactGlobalPresence::Type).count(), 0); |
702 | } |
703 | |
704 | void tst_QContactDetails::guid() |
705 | { |
706 | QContact c; |
707 | QContactGuid g1, g2; |
708 | |
709 | // test property set |
710 | g1.setGuid("1234" ); |
711 | QCOMPARE(g1.guid(), QString("1234" )); |
712 | QCOMPARE(g1.value(QContactGuid::FieldGuid).toString(), QString("1234" )); |
713 | |
714 | // test property add |
715 | QVERIFY(c.saveDetail(&g1)); |
716 | QCOMPARE(c.details(QContactGuid::Type).count(), 1); |
717 | QCOMPARE(QContactGuid(c.details(QContactGuid::Type).value(0)).guid(), g1.guid()); |
718 | |
719 | // test property update |
720 | g1.setValue(field: QContactGuid::FieldContext, value: QContactDetail::ContextWork); |
721 | g1.setGuid("12345" ); |
722 | QVERIFY(c.saveDetail(&g1)); |
723 | QCOMPARE(c.details(QContactGuid::Type).value(0).value(QContactGuid::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
724 | QCOMPARE(c.details(QContactGuid::Type).value(0).value(QContactGuid::FieldGuid).toString(), QString("12345" )); |
725 | |
726 | // test property remove |
727 | QVERIFY(c.removeDetail(&g1)); |
728 | QCOMPARE(c.details(QContactGuid::Type).count(), 0); |
729 | QVERIFY(c.saveDetail(&g2)); |
730 | QCOMPARE(c.details(QContactGuid::Type).count(), 1); |
731 | QVERIFY(c.removeDetail(&g2)); |
732 | QCOMPARE(c.details(QContactGuid::Type).count(), 0); |
733 | QVERIFY(c.removeDetail(&g2) == false); |
734 | QCOMPARE(c.details(QContactGuid::Type).count(), 0); |
735 | } |
736 | |
737 | void tst_QContactDetails::hobby() |
738 | { |
739 | QContact c; |
740 | QContactHobby h1, h2; |
741 | |
742 | // test property set |
743 | h1.setHobby("1234" ); |
744 | QCOMPARE(h1.hobby(), QString("1234" )); |
745 | QCOMPARE(h1.value(QContactHobby::FieldHobby).toString(), QString("1234" )); |
746 | |
747 | // test property add |
748 | QVERIFY(c.saveDetail(&h1)); |
749 | QCOMPARE(c.details(QContactHobby::Type).count(), 1); |
750 | QCOMPARE(QContactHobby(c.details(QContactHobby::Type).value(0)).hobby(), h1.hobby()); |
751 | |
752 | // test property update |
753 | h1.setValue(field: QContactHobby::FieldContext, value: QContactDetail::ContextWork); |
754 | h1.setHobby("12345" ); |
755 | QVERIFY(c.saveDetail(&h1)); |
756 | QCOMPARE(c.details(QContactHobby::Type).value(0).value(QContactHobby::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
757 | QCOMPARE(c.details(QContactHobby::Type).value(0).value(QContactHobby::FieldHobby).toString(), QString("12345" )); |
758 | |
759 | // test property remove |
760 | h2.setHobby("1111" ); |
761 | QVERIFY(c.removeDetail(&h1)); |
762 | QCOMPARE(c.details(QContactHobby::Type).count(), 0); |
763 | QVERIFY(c.saveDetail(&h2)); |
764 | QCOMPARE(c.details(QContactHobby::Type).count(), 1); |
765 | QVERIFY(c.removeDetail(&h2)); |
766 | QCOMPARE(c.details(QContactHobby::Type).count(), 0); |
767 | QVERIFY(c.removeDetail(&h2) == false); |
768 | QCOMPARE(c.details(QContactHobby::Type).count(), 0); |
769 | } |
770 | |
771 | void tst_QContactDetails::name() |
772 | { |
773 | QContact c; |
774 | QContactName n1, n2; |
775 | |
776 | QVERIFY(n1.isEmpty()); |
777 | QVERIFY(n2.isEmpty()); |
778 | |
779 | // test property set |
780 | n1.setPrefix("Dr" ); |
781 | n1.setFirstName("Freddy" ); |
782 | n1.setMiddleName("William Preston" ); |
783 | n1.setLastName("Gumboots" ); |
784 | n1.setSuffix("Esquire" ); |
785 | n1.setCustomLabel("Frederick The Example" ); |
786 | QCOMPARE(n1.prefix(), QString("Dr" )); |
787 | QCOMPARE(n1.firstName(), QString("Freddy" )); |
788 | QCOMPARE(n1.middleName(), QString("William Preston" )); |
789 | QCOMPARE(n1.lastName(), QString("Gumboots" )); |
790 | QCOMPARE(n1.suffix(), QString("Esquire" )); |
791 | QCOMPARE(n1.customLabel(), QString("Frederick The Example" )); |
792 | |
793 | // Values based (QString) |
794 | QCOMPARE(n1.value(QContactName::FieldPrefix).toString(), QString("Dr" )); |
795 | QCOMPARE(n1.value(QContactName::FieldFirstName).toString(), QString("Freddy" )); |
796 | QCOMPARE(n1.value(QContactName::FieldMiddleName).toString(), QString("William Preston" )); |
797 | QCOMPARE(n1.value(QContactName::FieldLastName).toString(), QString("Gumboots" )); |
798 | QCOMPARE(n1.value(QContactName::FieldSuffix).toString(), QString("Esquire" )); |
799 | QCOMPARE(n1.value(QContactName::FieldCustomLabel).toString(), QString("Frederick The Example" )); |
800 | |
801 | // test property add |
802 | QVERIFY(c.saveDetail(&n1)); |
803 | QCOMPARE(c.details(QContactName::Type).count(), 1); |
804 | n2.setFirstName("Billy" ); |
805 | n2.setLastName("Galoshes" ); |
806 | QVERIFY(c.saveDetail(&n2)); |
807 | QCOMPARE(c.details(QContactName::Type).count(), 2); |
808 | |
809 | // test property update |
810 | n1.setValue(field: QContactName::FieldContext, value: QContactDetail::ContextWork); |
811 | QVERIFY(c.saveDetail(&n1)); |
812 | |
813 | // test property remove |
814 | QVERIFY(c.removeDetail(&n1)); // remove |
815 | QCOMPARE(c.details(QContactName::Type).count(), 1); |
816 | QVERIFY(c.saveDetail(&n2)); // save but already added; count remains the same. |
817 | QCOMPARE(c.details(QContactName::Type).count(), 1); |
818 | QVERIFY(c.removeDetail(&n2)); // remove it |
819 | QCOMPARE(c.details(QContactName::Type).count(), 0); |
820 | QVERIFY(!c.removeDetail(&n2));// remove now fails |
821 | QVERIFY(c.saveDetail(&n1)); // save the original name |
822 | QCOMPARE(c.details(QContactName::Type).count(), 1); |
823 | } |
824 | |
825 | void tst_QContactDetails::nickname() |
826 | { |
827 | QContact c; |
828 | QContactNickname n1, n2; |
829 | |
830 | // test property set |
831 | n1.setNickname("1234" ); |
832 | QCOMPARE(n1.nickname(), QString("1234" )); |
833 | QCOMPARE(n1.value(QContactNickname::FieldNickname).toString(), QString("1234" )); |
834 | |
835 | // test property add |
836 | QVERIFY(c.saveDetail(&n1)); |
837 | QCOMPARE(c.details(QContactNickname::Type).count(), 1); |
838 | QCOMPARE(QContactNickname(c.details(QContactNickname::Type).value(0)).nickname(), n1.nickname()); |
839 | |
840 | // test property update |
841 | n1.setValue(field: QContactNickname::FieldContext, value: QContactDetail::ContextWork); |
842 | n1.setNickname("12345" ); |
843 | QVERIFY(c.saveDetail(&n1)); |
844 | QCOMPARE(c.details(QContactNickname::Type).value(0).value(QContactNickname::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
845 | QCOMPARE(c.details(QContactNickname::Type).value(0).value(QContactNickname::FieldNickname).toString(), QString("12345" )); |
846 | |
847 | // test property remove |
848 | QVERIFY(c.removeDetail(&n1)); |
849 | QCOMPARE(c.details(QContactNickname::Type).count(), 0); |
850 | QVERIFY(c.saveDetail(&n2)); |
851 | QCOMPARE(c.details(QContactNickname::Type).count(), 1); |
852 | QVERIFY(c.removeDetail(&n2)); |
853 | QCOMPARE(c.details(QContactNickname::Type).count(), 0); |
854 | QVERIFY(c.removeDetail(&n2) == false); |
855 | QCOMPARE(c.details(QContactNickname::Type).count(), 0); |
856 | } |
857 | |
858 | void tst_QContactDetails::note() |
859 | { |
860 | QContact c; |
861 | QContactNote n1, n2; |
862 | |
863 | // test property set |
864 | n1.setNote("lorem ipsum" ); |
865 | QCOMPARE(n1.note(), QString("lorem ipsum" )); |
866 | QCOMPARE(n1.value(QContactNote::FieldNote).toString(), QString("lorem ipsum" )); |
867 | |
868 | // test property add |
869 | QVERIFY(c.saveDetail(&n1)); |
870 | QCOMPARE(c.details(QContactNote::Type).count(), 1); |
871 | QCOMPARE(QContactNote(c.details(QContactNote::Type).value(0)).note(), n1.note()); |
872 | |
873 | // test property update |
874 | n1.setValue(field: QContactNote::FieldContext, value: QContactDetail::ContextWork); |
875 | n1.setNote("orange gypsum" ); |
876 | QVERIFY(c.saveDetail(&n1)); |
877 | QCOMPARE(c.details(QContactNote::Type).value(0).value(QContactNote::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
878 | QCOMPARE(c.details(QContactNote::Type).value(0).value(QContactNote::FieldNote).toString(), QString("orange gypsum" )); |
879 | |
880 | // test property remove |
881 | QVERIFY(c.removeDetail(&n1)); |
882 | QCOMPARE(c.details(QContactNote::Type).count(), 0); |
883 | QVERIFY(c.saveDetail(&n2)); |
884 | QCOMPARE(c.details(QContactNote::Type).count(), 1); |
885 | QVERIFY(c.removeDetail(&n2)); |
886 | QCOMPARE(c.details(QContactNote::Type).count(), 0); |
887 | QVERIFY(c.removeDetail(&n2) == false); |
888 | QCOMPARE(c.details(QContactNote::Type).count(), 0); |
889 | } |
890 | |
891 | void tst_QContactDetails::onlineAccount() |
892 | { |
893 | QContact c; |
894 | QContactOnlineAccount o1, o2; |
895 | |
896 | // test property set |
897 | o1.setAccountUri("test@nokia.com" ); |
898 | QCOMPARE(o1.accountUri(), QString("test@nokia.com" )); |
899 | QCOMPARE(o1.value(QContactOnlineAccount::FieldAccountUri).toString(), QString("test@nokia.com" )); |
900 | o1.setProtocol(QContactOnlineAccount::ProtocolJabber); |
901 | QCOMPARE(o1.protocol(), QContactOnlineAccount::ProtocolJabber); |
902 | |
903 | // Sub types |
904 | o1.setSubTypes(QList<int>() << QContactOnlineAccount::SubTypeSip); |
905 | QCOMPARE(o1.subTypes(), QList<int>() << QContactOnlineAccount::SubTypeSip); |
906 | |
907 | QList<int> sl; |
908 | sl << QContactOnlineAccount::SubTypeImpp << QContactOnlineAccount::SubTypeVideoShare; |
909 | o1.setSubTypes(sl); |
910 | QCOMPARE(o1.subTypes(), sl); |
911 | |
912 | o1 = QContactOnlineAccount(); |
913 | o1.setAccountUri("test@nokia.com" ); |
914 | |
915 | // test property add |
916 | QVERIFY(c.saveDetail(&o1)); |
917 | QCOMPARE(c.details(QContactOnlineAccount::Type).count(), 1); |
918 | QCOMPARE(QContactOnlineAccount(c.details(QContactOnlineAccount::Type).value(0)).accountUri(), o1.accountUri()); |
919 | QCOMPARE(QContactOnlineAccount(c.details(QContactOnlineAccount::Type).value(0)).accountUri(), o1.accountUri()); |
920 | |
921 | // test property update |
922 | QStringList caps; |
923 | caps << "cap1" << "cap3" << "cap4" ; |
924 | o1.setValue(field: QContactOnlineAccount::FieldContext, value: QContactDetail::ContextWork); |
925 | o1.setAccountUri("test2@nokia.com" ); |
926 | o1.setServiceProvider("some provider" ); |
927 | o1.setCapabilities(caps); |
928 | QVERIFY(c.saveDetail(&o1)); |
929 | QCOMPARE(c.details(QContactOnlineAccount::Type).value(0).value(QContactOnlineAccount::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
930 | QCOMPARE(c.details(QContactOnlineAccount::Type).value(0).value(QContactOnlineAccount::FieldAccountUri).toString(), QString("test2@nokia.com" )); |
931 | QCOMPARE(c.details(QContactOnlineAccount::Type).value(0).value<QStringList>(QContactOnlineAccount::FieldCapabilities), caps); |
932 | QCOMPARE(c.details<QContactOnlineAccount>().value(0).capabilities(), caps); |
933 | QCOMPARE(c.details(QContactOnlineAccount::Type).value(0).value(QContactOnlineAccount::FieldServiceProvider).toString(), QString("some provider" )); |
934 | QCOMPARE(c.details<QContactOnlineAccount>().value(0).serviceProvider(), QString("some provider" )); |
935 | |
936 | // test property remove |
937 | QVERIFY(c.removeDetail(&o1)); |
938 | QCOMPARE(c.details(QContactOnlineAccount::Type).count(), 0); |
939 | QVERIFY(c.saveDetail(&o2)); |
940 | QCOMPARE(c.details(QContactOnlineAccount::Type).count(), 1); |
941 | QVERIFY(c.removeDetail(&o2)); |
942 | QCOMPARE(c.details(QContactOnlineAccount::Type).count(), 0); |
943 | QVERIFY(c.removeDetail(&o2) == false); |
944 | QCOMPARE(c.details(QContactOnlineAccount::Type).count(), 0); |
945 | } |
946 | |
947 | void tst_QContactDetails::organization() |
948 | { |
949 | QContact c; |
950 | QContactOrganization o1, o2; |
951 | |
952 | // test property set |
953 | o1.setName("organization one" ); |
954 | QCOMPARE(o1.name(), QString("organization one" )); |
955 | QCOMPARE(o1.value(QContactOrganization::FieldName).toString(), QString("organization one" )); |
956 | |
957 | o1.setDepartment(QStringList(QString("department one" ))); |
958 | QCOMPARE(o1.department(), QStringList(QString("department one" ))); |
959 | QCOMPARE(o1.value<QStringList>(QContactOrganization::FieldDepartment), QStringList(QString("department one" ))); |
960 | |
961 | o1.setLocation("location one" ); |
962 | QCOMPARE(o1.location(), QString("location one" )); |
963 | QCOMPARE(o1.value(QContactOrganization::FieldLocation).toString(), QString("location one" )); |
964 | |
965 | o1.setLogoUrl(QUrl("logo one" )); |
966 | QCOMPARE(o1.logoUrl(), QUrl("logo one" )); |
967 | QCOMPARE(o1.value<QUrl>(QContactOrganization::FieldLogoUrl), QUrl("logo one" )); |
968 | |
969 | o1.setTitle("title one" ); |
970 | QCOMPARE(o1.title(), QString("title one" )); |
971 | QCOMPARE(o1.value(QContactOrganization::FieldTitle).toString(), QString("title one" )); |
972 | |
973 | o1.setAssistantName("assistant one" ); |
974 | QCOMPARE(o1.assistantName(), QString("assistant one" )); |
975 | QCOMPARE(o1.value(QContactOrganization::FieldAssistantName).toString(), QString("assistant one" )); |
976 | |
977 | // test property add |
978 | QVERIFY(c.saveDetail(&o1)); |
979 | QCOMPARE(c.details(QContactOrganization::Type).count(), 1); |
980 | QCOMPARE(QContactOrganization(c.details(QContactOrganization::Type).value(0)).name(), o1.name()); |
981 | |
982 | // test property update |
983 | o1.setName("organization two" ); |
984 | QVERIFY(c.saveDetail(&o1)); |
985 | QCOMPARE(c.details(QContactOrganization::Type).value(0).value(QContactOrganization::FieldName).toString(), QString("organization two" )); |
986 | |
987 | // test property remove |
988 | QVERIFY(c.removeDetail(&o1)); |
989 | QCOMPARE(c.details(QContactOrganization::Type).count(), 0); |
990 | QVERIFY(c.saveDetail(&o2)); |
991 | QCOMPARE(c.details(QContactOrganization::Type).count(), 1); |
992 | QVERIFY(c.removeDetail(&o2)); |
993 | QCOMPARE(c.details(QContactOrganization::Type).count(), 0); |
994 | QVERIFY(c.removeDetail(&o2) == false); |
995 | QCOMPARE(c.details(QContactOrganization::Type).count(), 0); |
996 | |
997 | // organization-specific API testing |
998 | o1.setDepartment(QStringList(QString("Imaginary Dept" ))); |
999 | o1.setLocation("Utopia" ); |
1000 | o1.setLogoUrl(QUrl("logo.png" )); |
1001 | o1.setName("Utopian Megacorporation" ); |
1002 | o1.setTitle("Generic Employee" ); |
1003 | c.saveDetail(detail: &o1); |
1004 | QVERIFY(c.detail(QContactOrganization::Type).value<QStringList>(QContactOrganization::FieldDepartment) == QStringList(QString("Imaginary Dept" ))); |
1005 | QVERIFY(c.detail(QContactOrganization::Type).value(QContactOrganization::FieldLocation).toString() == QString("Utopia" )); |
1006 | QVERIFY(c.detail(QContactOrganization::Type).value<QUrl>(QContactOrganization::FieldLogoUrl) == QUrl("logo.png" )); |
1007 | QVERIFY(c.detail(QContactOrganization::Type).value(QContactOrganization::FieldName).toString() == QString("Utopian Megacorporation" )); |
1008 | QVERIFY(c.detail(QContactOrganization::Type).value(QContactOrganization::FieldTitle).toString() == QString("Generic Employee" )); |
1009 | } |
1010 | |
1011 | void tst_QContactDetails::phoneNumber() |
1012 | { |
1013 | QContact c; |
1014 | QContactPhoneNumber p1, p2; |
1015 | |
1016 | // test property set |
1017 | p1.setNumber("1234" ); |
1018 | QCOMPARE(p1.number(), QString("1234" )); |
1019 | QCOMPARE(p1.value(QContactPhoneNumber::FieldNumber).toString(), QString("1234" )); |
1020 | |
1021 | // normalized number |
1022 | p1.setNormalizedNumber("123" ); |
1023 | QCOMPARE(p1.normalizedNumber(), QString("123" )); |
1024 | QCOMPARE(p1.value(QContactPhoneNumber::FieldNormalizedNumber).toString(), QString("123" )); |
1025 | |
1026 | // Sub types |
1027 | p1.setSubTypes(QList<int>() << QContactPhoneNumber::SubTypeCar); |
1028 | QCOMPARE(p1.subTypes(), QList<int>() << QContactPhoneNumber::SubTypeCar); |
1029 | |
1030 | QList<int> sl; |
1031 | sl << QContactPhoneNumber::SubTypeMobile << QContactPhoneNumber::SubTypeFax; |
1032 | p1.setSubTypes(sl); |
1033 | QCOMPARE(p1.subTypes(), sl); |
1034 | |
1035 | // test property add |
1036 | QVERIFY(c.saveDetail(&p1)); |
1037 | QCOMPARE(c.details(QContactPhoneNumber::Type).count(), 1); |
1038 | QCOMPARE(QContactPhoneNumber(c.details(QContactPhoneNumber::Type).value(0)).number(), p1.number()); |
1039 | |
1040 | // test property update |
1041 | p1.setValue(field: QContactPhoneNumber::FieldContext, value: QContactDetail::ContextWork); |
1042 | p1.setNumber("12345" ); |
1043 | QVERIFY(c.saveDetail(&p1)); |
1044 | QCOMPARE(c.details(QContactPhoneNumber::Type).value(0).value(QContactPhoneNumber::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
1045 | QCOMPARE(c.details(QContactPhoneNumber::Type).value(0).value(QContactPhoneNumber::FieldNumber).toString(), QString("12345" )); |
1046 | |
1047 | p1.setSubTypes(QList<int>() << QContactPhoneNumber::SubTypeDtmfMenu); |
1048 | c.saveDetail(detail: &p1); |
1049 | |
1050 | QCOMPARE(c.detail(QContactPhoneNumber::Type).value<QList<int> >(QContactPhoneNumber::FieldSubTypes), QList<int>() << QContactPhoneNumber::SubTypeDtmfMenu); |
1051 | p1.setSubTypes(QList<int>() << QContactPhoneNumber::SubTypeModem << QContactPhoneNumber::SubTypeFax); |
1052 | c.saveDetail(detail: &p1); |
1053 | QVERIFY(c.detail(QContactPhoneNumber::Type).value<QList<int> >(QContactPhoneNumber::FieldSubTypes) == p1.subTypes()); |
1054 | |
1055 | // test property remove |
1056 | QVERIFY(c.removeDetail(&p1)); |
1057 | QCOMPARE(c.details(QContactPhoneNumber::Type).count(), 0); |
1058 | QVERIFY(c.saveDetail(&p2)); |
1059 | QCOMPARE(c.details(QContactPhoneNumber::Type).count(), 1); |
1060 | QVERIFY(c.removeDetail(&p2)); |
1061 | QCOMPARE(c.details(QContactPhoneNumber::Type).count(), 0); |
1062 | QVERIFY(c.removeDetail(&p2) == false); |
1063 | QCOMPARE(c.details(QContactPhoneNumber::Type).count(), 0); |
1064 | |
1065 | // test comparison of two phone numbers |
1066 | QContactPhoneNumber p3; |
1067 | p3.setNumber("1234" ); |
1068 | p3.setSubTypes(QList<int>() << QContactPhoneNumber::SubTypeModem << QContactPhoneNumber::SubTypeFax); |
1069 | QContactPhoneNumber p4; |
1070 | p4.setNumber("1234" ); |
1071 | p4.setSubTypes(QList<int>() << QContactPhoneNumber::SubTypeModem << QContactPhoneNumber::SubTypeFax); |
1072 | QVERIFY(p3 == p4); |
1073 | p3.setNumber("" ); |
1074 | QVERIFY(p3 != p4); |
1075 | p3.setNumber("1234" ); |
1076 | QVERIFY(p3 == p4); |
1077 | p4.setNormalizedNumber("1234" ); |
1078 | QVERIFY(p3 != p4); |
1079 | p3.setNormalizedNumber("1234" ); |
1080 | QVERIFY(p3 == p4); |
1081 | p3.setSubTypes(QList<int>() << QContactPhoneNumber::SubTypeModem); |
1082 | QVERIFY(p3 != p4); |
1083 | p4.setSubTypes(QList<int>() << QContactPhoneNumber::SubTypeDtmfMenu); |
1084 | QVERIFY(p3 != p4); |
1085 | p3.setSubTypes(QList<int>() << QContactPhoneNumber::SubTypeDtmfMenu); |
1086 | QVERIFY(p3 == p4); |
1087 | } |
1088 | |
1089 | void tst_QContactDetails::presence() |
1090 | { |
1091 | QContact c; |
1092 | QContactPresence p1, p2; |
1093 | |
1094 | // test property set |
1095 | QDateTime ts = QDateTime::currentDateTime(); |
1096 | p1.setTimestamp(ts); |
1097 | p1.setNickname(QString("nick" )); |
1098 | p1.setPresenceState(QContactPresence::PresenceExtendedAway); |
1099 | p1.setPresenceStateText("1234" ); |
1100 | p1.setPresenceStateImageUrl(QUrl("http://example.com/someimage.png" )); |
1101 | p1.setCustomMessage("gone fishing!" ); |
1102 | QCOMPARE(p1.timestamp(), ts); |
1103 | QCOMPARE(p1.value<QDateTime>(QContactPresence::FieldTimestamp), ts); |
1104 | QCOMPARE(p1.nickname(), QString("nick" )); |
1105 | QCOMPARE(p1.value(QContactPresence::FieldNickname).toString(), QString("nick" )); |
1106 | QCOMPARE(p1.presenceState(), QContactPresence::PresenceExtendedAway); |
1107 | QCOMPARE(p1.value<int>(QContactPresence::FieldPresenceState), static_cast<int>(QContactPresence::PresenceExtendedAway)); |
1108 | QCOMPARE(p1.presenceStateText(), QString("1234" )); |
1109 | QCOMPARE(p1.value(QContactPresence::FieldPresenceStateText).toString(), QString("1234" )); |
1110 | QCOMPARE(p1.presenceStateImageUrl(), QUrl("http://example.com/someimage.png" )); |
1111 | QCOMPARE(p1.value<QUrl>(QContactPresence::FieldPresenceStateImageUrl), QUrl("http://example.com/someimage.png" )); |
1112 | QCOMPARE(p1.customMessage(), QString("gone fishing!" )); |
1113 | QCOMPARE(p1.value(QContactPresence::FieldCustomMessage).toString(), QString("gone fishing!" )); |
1114 | |
1115 | // test property add |
1116 | QVERIFY(c.saveDetail(&p1)); |
1117 | QCOMPARE(c.details(QContactPresence::Type).count(), 1); |
1118 | QCOMPARE(QContactPresence(c.details(QContactPresence::Type).value(0)).presenceStateText(), p1.presenceStateText()); |
1119 | |
1120 | // test property update |
1121 | p1.setValue(field: QContactPresence::FieldContext, value: QContactDetail::ContextWork); |
1122 | p1.setPresenceStateText("12345" ); |
1123 | QVERIFY(c.saveDetail(&p1)); |
1124 | QCOMPARE(c.details(QContactPresence::Type).value(0).value(QContactPresence::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
1125 | QCOMPARE(c.details(QContactPresence::Type).value(0).value(QContactPresence::FieldPresenceStateText).toString(), QString("12345" )); |
1126 | |
1127 | p2.setTimestamp(ts); |
1128 | p2.setNickname(QString("test" )); |
1129 | p2.setPresenceState(QContactPresence::PresenceAvailable); |
1130 | p2.setPresenceStateText("online" ); |
1131 | p2.setPresenceStateImageUrl(QUrl("http://example.com/someimage.png" )); |
1132 | p2.setCustomMessage("C is for generic biscuit-type pastry product!" ); |
1133 | |
1134 | // test property remove |
1135 | QVERIFY(c.removeDetail(&p1)); |
1136 | QCOMPARE(c.details(QContactPresence::Type).count(), 0); |
1137 | QVERIFY(c.saveDetail(&p2)); |
1138 | QCOMPARE(c.details(QContactPresence::Type).count(), 1); |
1139 | QVERIFY(c.removeDetail(&p2)); |
1140 | QCOMPARE(c.details(QContactPresence::Type).count(), 0); |
1141 | QVERIFY(c.removeDetail(&p2) == false); |
1142 | QCOMPARE(c.details(QContactPresence::Type).count(), 0); |
1143 | } |
1144 | |
1145 | void tst_QContactDetails::ringtone() |
1146 | { |
1147 | QContact c; |
1148 | QContactRingtone r1, r2; |
1149 | |
1150 | // test property set |
1151 | r1.setAudioRingtoneUrl(QUrl("audioUrl" )); |
1152 | QCOMPARE(r1.audioRingtoneUrl(), QUrl("audioUrl" )); |
1153 | QCOMPARE(r1.value<QUrl>(QContactRingtone::FieldAudioRingtoneUrl), QUrl("audioUrl" )); |
1154 | |
1155 | // and the other fields |
1156 | r2.setVideoRingtoneUrl(QUrl("videoUrl" )); |
1157 | QCOMPARE(r2.videoRingtoneUrl(), QUrl("videoUrl" )); |
1158 | QCOMPARE(r2.value<QUrl>(QContactRingtone::FieldVideoRingtoneUrl), QUrl("videoUrl" )); |
1159 | r2.setVibrationRingtoneUrl(QUrl("vibrationUrl" )); |
1160 | QCOMPARE(r2.vibrationRingtoneUrl(), QUrl("vibrationUrl" )); |
1161 | QCOMPARE(r2.value<QUrl>(QContactRingtone::FieldVibrationRingtoneUrl), QUrl("vibrationUrl" )); |
1162 | |
1163 | // test property add |
1164 | QVERIFY(c.saveDetail(&r1)); |
1165 | QCOMPARE(c.details(QContactRingtone::Type).count(), 1); |
1166 | QCOMPARE(QContactRingtone(c.details(QContactRingtone::Type).value(0)).audioRingtoneUrl(), r1.audioRingtoneUrl()); |
1167 | |
1168 | // test property update |
1169 | r1.setValue(field: QContactRingtone::FieldContext, value: QContactDetail::ContextWork); |
1170 | r1.setAudioRingtoneUrl(QUrl("audioUrl2" )); |
1171 | QVERIFY(c.saveDetail(&r1)); |
1172 | QCOMPARE(c.details(QContactRingtone::Type).value(0).value(QContactRingtone::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
1173 | QCOMPARE(c.details(QContactRingtone::Type).value(0).value<QUrl>(QContactRingtone::FieldAudioRingtoneUrl), QUrl("audioUrl2" )); |
1174 | |
1175 | // test property remove |
1176 | QVERIFY(c.removeDetail(&r1)); |
1177 | QCOMPARE(c.details(QContactRingtone::Type).count(), 0); |
1178 | QVERIFY(c.saveDetail(&r2)); |
1179 | QCOMPARE(c.details(QContactRingtone::Type).count(), 1); |
1180 | QVERIFY(c.removeDetail(&r2)); |
1181 | QCOMPARE(c.details(QContactRingtone::Type).count(), 0); |
1182 | QVERIFY(c.removeDetail(&r2) == false); |
1183 | QCOMPARE(c.details(QContactRingtone::Type).count(), 0); |
1184 | } |
1185 | |
1186 | void tst_QContactDetails::syncTarget() |
1187 | { |
1188 | QContact c; |
1189 | QContactSyncTarget s1, s2; |
1190 | |
1191 | // test property set |
1192 | s1.setSyncTarget("1234" ); |
1193 | QCOMPARE(s1.syncTarget(), QString("1234" )); |
1194 | QCOMPARE(s1.value(QContactSyncTarget::FieldSyncTarget).toString(), QString("1234" )); |
1195 | |
1196 | // test property add |
1197 | QVERIFY(c.saveDetail(&s1)); |
1198 | QCOMPARE(c.details(QContactSyncTarget::Type).count(), 1); |
1199 | QCOMPARE(QContactSyncTarget(c.details(QContactSyncTarget::Type).value(0)).syncTarget(), s1.syncTarget()); |
1200 | |
1201 | // test property update |
1202 | s1.setValue(field: QContactSyncTarget::FieldContext, value: QContactDetail::ContextWork); |
1203 | s1.setSyncTarget("12345" ); |
1204 | QVERIFY(c.saveDetail(&s1)); |
1205 | QCOMPARE(c.details(QContactSyncTarget::Type).value(0).value(QContactSyncTarget::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
1206 | QCOMPARE(c.details(QContactSyncTarget::Type).value(0).value(QContactSyncTarget::FieldSyncTarget).toString(), QString("12345" )); |
1207 | |
1208 | // test property remove |
1209 | QVERIFY(c.removeDetail(&s1)); |
1210 | QCOMPARE(c.details(QContactSyncTarget::Type).count(), 0); |
1211 | QVERIFY(c.saveDetail(&s2)); |
1212 | QCOMPARE(c.details(QContactSyncTarget::Type).count(), 1); |
1213 | QVERIFY(c.removeDetail(&s2)); |
1214 | QCOMPARE(c.details(QContactSyncTarget::Type).count(), 0); |
1215 | QVERIFY(c.removeDetail(&s2) == false); |
1216 | QCOMPARE(c.details(QContactSyncTarget::Type).count(), 0); |
1217 | } |
1218 | |
1219 | void tst_QContactDetails::tag() |
1220 | { |
1221 | QContact c; |
1222 | QContactTag t1, t2; |
1223 | |
1224 | // test property set |
1225 | t1.setTag("red" ); |
1226 | QCOMPARE(t1.tag(), QString("red" )); |
1227 | QCOMPARE(t1.value(QContactTag::FieldTag).toString(), QString("red" )); |
1228 | |
1229 | // test property add |
1230 | QVERIFY(c.saveDetail(&t1)); |
1231 | QCOMPARE(c.details(QContactTag::Type).count(), 1); |
1232 | QCOMPARE(QContactTag(c.details(QContactTag::Type).value(0)).tag(), t1.tag()); |
1233 | QVERIFY(c.saveDetail(&t2)); |
1234 | QCOMPARE(c.details(QContactTag::Type).count(), 2); |
1235 | |
1236 | // test property update |
1237 | t1.setValue(field: QContactTag::FieldContext, value: QContactDetail::ContextWork); |
1238 | t1.setTag("green" ); |
1239 | QVERIFY(c.saveDetail(&t1)); |
1240 | QCOMPARE(c.details(QContactTag::Type).value(0).value(QContactTag::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
1241 | QCOMPARE(c.details(QContactTag::Type).value(0).value(QContactTag::FieldTag).toString(), QString("green" )); |
1242 | |
1243 | // test property remove |
1244 | QVERIFY(c.removeDetail(&t1)); |
1245 | QCOMPARE(c.details(QContactTag::Type).count(), 1); |
1246 | QVERIFY(c.removeDetail(&t2)); |
1247 | QCOMPARE(c.details(QContactTag::Type).count(), 0); |
1248 | QVERIFY(c.removeDetail(&t2) == false); |
1249 | QCOMPARE(c.details(QContactTag::Type).count(), 0); |
1250 | } |
1251 | |
1252 | void tst_QContactDetails::timestamp() |
1253 | { |
1254 | QContact c; |
1255 | QContactTimestamp t1, t2; |
1256 | QDateTime modified = QDateTime::currentDateTime(); |
1257 | QDateTime created = modified.addSecs(secs: -43); |
1258 | QDateTime deleted = modified.addSecs(secs: 20); |
1259 | |
1260 | // test property set |
1261 | t1.setCreated(created); |
1262 | t1.setDeleted(deleted); |
1263 | QCOMPARE(t1.created(), created); |
1264 | QCOMPARE(t1.value(QContactTimestamp::FieldCreationTimestamp).toDateTime(), created); |
1265 | QCOMPARE(t1.deleted(), deleted); |
1266 | QCOMPARE(t1.value(QContactTimestamp::FieldDeletionTimestamp).toDateTime(), deleted); |
1267 | |
1268 | // test property add |
1269 | QVERIFY(c.saveDetail(&t1)); |
1270 | QCOMPARE(c.details(QContactTimestamp::Type).count(), 1); |
1271 | QCOMPARE(QContactTimestamp(c.details(QContactTimestamp::Type).value(0)).created(), t1.created()); |
1272 | QCOMPARE(QContactTimestamp(c.details(QContactTimestamp::Type).value(0)).deleted(), t1.deleted()); |
1273 | |
1274 | // test property update |
1275 | t1.setValue(field: QContactTimestamp::FieldContext, value: QContactDetail::ContextWork); |
1276 | t1.setLastModified(modified); |
1277 | QVERIFY(c.saveDetail(&t1)); |
1278 | QCOMPARE(c.details(QContactTimestamp::Type).value(0).value(QContactTimestamp::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
1279 | QCOMPARE(c.details(QContactTimestamp::Type).value(0).value(QContactTimestamp::FieldCreationTimestamp).toDateTime(), created); |
1280 | QCOMPARE(c.details(QContactTimestamp::Type).value(0).value(QContactTimestamp::FieldModificationTimestamp).toDateTime(), modified); |
1281 | QCOMPARE(c.details(QContactTimestamp::Type).value(0).value(QContactTimestamp::FieldDeletionTimestamp).toDateTime(), deleted); |
1282 | |
1283 | // test property remove |
1284 | QVERIFY(c.removeDetail(&t1)); |
1285 | QCOMPARE(c.details(QContactTimestamp::Type).count(), 0); |
1286 | t2.setCreated(created.addSecs(secs: 15)); |
1287 | QVERIFY(c.saveDetail(&t2)); |
1288 | QCOMPARE(c.details(QContactTimestamp::Type).count(), 1); |
1289 | QVERIFY(c.removeDetail(&t2)); |
1290 | QCOMPARE(c.details(QContactTimestamp::Type).count(), 0); |
1291 | QVERIFY(c.removeDetail(&t2) == false); |
1292 | QCOMPARE(c.details(QContactTimestamp::Type).count(), 0); |
1293 | } |
1294 | |
1295 | void tst_QContactDetails::type() |
1296 | { |
1297 | QContact c; |
1298 | QContactType t1, t2; |
1299 | |
1300 | // test property set |
1301 | t1.setType(QContactType::TypeGroup); |
1302 | QCOMPARE(t1.type(), QContactType::TypeGroup); |
1303 | QCOMPARE(static_cast<QContactType::TypeValues>(t1.value<int>(QContactType::FieldType)), QContactType::TypeGroup); |
1304 | |
1305 | // test property add |
1306 | QVERIFY(c.saveDetail(&t1)); |
1307 | QCOMPARE(c.details(QContactType::Type).count(), 1); |
1308 | QCOMPARE(QContactType(c.details(QContactType::Type).value(0)).type(), t1.type()); |
1309 | |
1310 | // test property update |
1311 | t1.setType(QContactType::TypeContact); |
1312 | QVERIFY(c.saveDetail(&t1)); |
1313 | QCOMPARE(static_cast<QContactType::TypeValues>(c.details(QContactType::Type).value(0).value<int>(QContactType::FieldType)), QContactType::TypeContact); |
1314 | |
1315 | // test property remove |
1316 | QVERIFY(!c.removeDetail(&t1)); // cannot remove type |
1317 | QCOMPARE(c.details(QContactType::Type).count(), 1); |
1318 | t2.setType(QContactType::TypeGroup); |
1319 | QVERIFY(c.saveDetail(&t2)); // overwrites t1 |
1320 | QCOMPARE(c.details(QContactType::Type).count(), 1); |
1321 | QVERIFY(!c.removeDetail(&t2)); // cannot remove type - "succeeds" but count remains unchanged |
1322 | QCOMPARE(c.details(QContactType::Type).count(), 1); |
1323 | QVERIFY(!c.removeDetail(&t2)); |
1324 | QCOMPARE(c.details(QContactType::Type).count(), 1); |
1325 | } |
1326 | |
1327 | void tst_QContactDetails::url() |
1328 | { |
1329 | QContact c; |
1330 | QContactUrl u1, u2; |
1331 | |
1332 | // test property set |
1333 | u1.setUrl("1234" ); |
1334 | QCOMPARE(u1.url(), QString("1234" )); |
1335 | QCOMPARE(u1.value(QContactUrl::FieldUrl).toString(), QString("1234" )); |
1336 | |
1337 | u1.setSubType(QContactUrl::SubTypeHomePage); |
1338 | QCOMPARE(u1.subType(), QContactUrl::SubTypeHomePage); |
1339 | QCOMPARE(static_cast<QContactUrl::SubType>(u1.value<int>(QContactUrl::FieldSubType)), QContactUrl::SubTypeHomePage); |
1340 | |
1341 | // test property add |
1342 | QVERIFY(c.saveDetail(&u1)); |
1343 | QCOMPARE(c.details(QContactUrl::Type).count(), 1); |
1344 | QCOMPARE(QContactUrl(c.details(QContactUrl::Type).value(0)).url(), u1.url()); |
1345 | |
1346 | // test property update |
1347 | u1.setValue(field: QContactUrl::FieldContext, value: QContactDetail::ContextWork); |
1348 | u1.setUrl("12345" ); |
1349 | QVERIFY(c.saveDetail(&u1)); |
1350 | QCOMPARE(c.details(QContactUrl::Type).value(0).value(QContactUrl::FieldContext).value<QList<int> >(), QList<int>() << QContactDetail::ContextWork); |
1351 | QCOMPARE(c.details(QContactUrl::Type).value(0).value(QContactUrl::FieldUrl).toString(), QString("12345" )); |
1352 | |
1353 | // now as above, but with the QUrl setter. |
1354 | QUrl urlValue("http://www.example.com" ); |
1355 | QContactUrl u3; |
1356 | u3.setUrl(urlValue); |
1357 | QCOMPARE(u3.url(), urlValue.toString()); |
1358 | QVERIFY(c.saveDetail(&u3)); |
1359 | QVERIFY(c.details(QContactUrl::Type).contains(u3)); |
1360 | u3.setUrl(QString(QStringLiteral("http://www.anotherexample.com" ))); |
1361 | QCOMPARE(u3.url(), QString(QStringLiteral("http://www.anotherexample.com" ))); |
1362 | QVERIFY(c.saveDetail(&u3)); |
1363 | |
1364 | // test property remove |
1365 | QVERIFY(c.removeDetail(&u3)); |
1366 | QVERIFY(c.removeDetail(&u1)); |
1367 | QCOMPARE(c.details(QContactUrl::Type).count(), 0); |
1368 | QVERIFY(c.saveDetail(&u2)); |
1369 | QCOMPARE(c.details(QContactUrl::Type).count(), 1); |
1370 | QVERIFY(c.removeDetail(&u2)); |
1371 | QCOMPARE(c.details(QContactUrl::Type).count(), 0); |
1372 | QVERIFY(c.removeDetail(&u2) == false); |
1373 | QCOMPARE(c.details(QContactUrl::Type).count(), 0); |
1374 | } |
1375 | |
1376 | void tst_QContactDetails::version() |
1377 | { |
1378 | QContact c; |
1379 | QContactVersion v1, v2; |
1380 | QByteArray extendedVersion("Qt rules!" ); |
1381 | QByteArray anotherExtendedVersion("Qt rules again!" ); |
1382 | // test property set |
1383 | v1.setSequenceNumber(64); |
1384 | QCOMPARE(v1.sequenceNumber(), 64); |
1385 | QCOMPARE(v1.value(QContactVersion::FieldSequenceNumber).toInt(), 64); |
1386 | v1.setExtendedVersion(extendedVersion); |
1387 | QCOMPARE(v1.extendedVersion(), extendedVersion); |
1388 | QCOMPARE(v1.value(QContactVersion::FieldExtendedVersion).toByteArray(), extendedVersion); |
1389 | |
1390 | // test property add |
1391 | QVERIFY(c.saveDetail(&v1)); |
1392 | QCOMPARE(c.details(QContactVersion::Type).count(), 1); |
1393 | QCOMPARE(QContactVersion(c.details(QContactVersion::Type).value(0)).sequenceNumber(), v1.sequenceNumber()); |
1394 | QCOMPARE(QContactVersion(c.details(QContactVersion::Type).value(0)).extendedVersion(), v1.extendedVersion()); |
1395 | QVERIFY(c.saveDetail(&v2)); |
1396 | QCOMPARE(c.details(QContactVersion::Type).count(), 2); |
1397 | |
1398 | // test property update |
1399 | v1.setSequenceNumber(65); |
1400 | v1.setExtendedVersion(anotherExtendedVersion); |
1401 | QVERIFY(c.saveDetail(&v1)); |
1402 | QCOMPARE(c.details(QContactVersion::Type).value(0).value(QContactVersion::FieldSequenceNumber).toInt(), 65); |
1403 | QCOMPARE(c.details(QContactVersion::Type).value(0).value(QContactVersion::FieldExtendedVersion).toByteArray(), |
1404 | anotherExtendedVersion); |
1405 | |
1406 | // test property remove |
1407 | QVERIFY(c.removeDetail(&v1)); |
1408 | QCOMPARE(c.details(QContactVersion::Type).count(), 1); |
1409 | QVERIFY(c.removeDetail(&v2)); |
1410 | QCOMPARE(c.details(QContactVersion::Type).count(), 0); |
1411 | QVERIFY(c.removeDetail(&v2) == false); |
1412 | QCOMPARE(c.details(QContactVersion::Type).count(), 0); |
1413 | } |
1414 | |
1415 | QTEST_MAIN(tst_QContactDetails) |
1416 | #include "tst_qcontactdetails.moc" |
1417 | |