|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QtTest/QtTest> |
|
43 |
|
44 #include "qtcontacts.h" |
|
45 #include "qcontactmanagerdataholder.h" //QContactManagerDataHolder |
|
46 |
|
47 //TESTED_CLASS= |
|
48 //TESTED_FILES= |
|
49 |
|
50 QTM_USE_NAMESPACE |
|
51 class tst_QContactDetails : public QObject |
|
52 { |
|
53 Q_OBJECT |
|
54 |
|
55 public: |
|
56 tst_QContactDetails(); |
|
57 virtual ~tst_QContactDetails(); |
|
58 |
|
59 private: |
|
60 QContactManagerDataHolder managerDataHolder; |
|
61 |
|
62 public slots: |
|
63 void init(); |
|
64 void cleanup(); |
|
65 |
|
66 private slots: |
|
67 // leaf class testing |
|
68 void address(); |
|
69 void anniversary(); |
|
70 void avatar(); |
|
71 void birthday(); |
|
72 void displayLabel(); |
|
73 void emailAddress(); |
|
74 void family(); |
|
75 void gender(); |
|
76 void geolocation(); |
|
77 void guid(); |
|
78 void name(); |
|
79 void nickname(); |
|
80 void note(); |
|
81 void onlineAccount(); |
|
82 void organization(); |
|
83 void phoneNumber(); |
|
84 void syncTarget(); |
|
85 void timestamp(); |
|
86 void type(); |
|
87 void url(); |
|
88 |
|
89 // custom definition testing |
|
90 void custom(); |
|
91 }; |
|
92 |
|
93 tst_QContactDetails::tst_QContactDetails() |
|
94 { |
|
95 } |
|
96 |
|
97 tst_QContactDetails::~tst_QContactDetails() |
|
98 { |
|
99 } |
|
100 |
|
101 void tst_QContactDetails::init() |
|
102 { |
|
103 } |
|
104 |
|
105 void tst_QContactDetails::cleanup() |
|
106 { |
|
107 } |
|
108 |
|
109 void tst_QContactDetails::address() |
|
110 { |
|
111 QContact c; |
|
112 QContactAddress a1, a2; |
|
113 |
|
114 QVERIFY(a1.isEmpty()); |
|
115 QVERIFY(a2.isEmpty()); |
|
116 |
|
117 // test property set |
|
118 QCOMPARE(a1.street(), QString()); |
|
119 a1.setStreet("68 Imaginary Avenue"); |
|
120 a1.setCountry("Australia"); |
|
121 QCOMPARE(a1.street(), QString("68 Imaginary Avenue")); |
|
122 a1.setStreet("1234"); |
|
123 QCOMPARE(a1.street(), QString("1234")); |
|
124 a1.setPostOfficeBox("PO Box 5678"); |
|
125 QCOMPARE(a1.postOfficeBox(), QString("PO Box 5678")); |
|
126 |
|
127 |
|
128 // Sub types |
|
129 a1.setSubTypes(QContactAddress::SubTypeDomestic); |
|
130 QCOMPARE(a1.subTypes(), QStringList() << QLatin1String(QContactAddress::SubTypeDomestic)); |
|
131 |
|
132 QStringList sl; |
|
133 sl << QLatin1String(QContactAddress::SubTypeParcel) << QLatin1String(QContactAddress::SubTypePostal); |
|
134 a1.setSubTypes(sl); |
|
135 QCOMPARE(a1.subTypes(), sl); |
|
136 |
|
137 // test property add |
|
138 QVERIFY(c.saveDetail(&a1)); |
|
139 QCOMPARE(c.details(QContactAddress::DefinitionName).count(), 1); |
|
140 QCOMPARE(QContactAddress(c.details(QContactAddress::DefinitionName).value(0)).street(), a1.street()); |
|
141 a2.setStreet("Test"); |
|
142 QVERIFY(c.saveDetail(&a2)); |
|
143 QCOMPARE(c.details(QContactAddress::DefinitionName).count(), 2); |
|
144 |
|
145 // test property update |
|
146 a1.setValue("label","label1"); |
|
147 a1.setStreet("12345"); |
|
148 QVERIFY(c.saveDetail(&a1)); |
|
149 |
|
150 // test property remove |
|
151 QVERIFY(c.removeDetail(&a1)); |
|
152 QCOMPARE(c.details(QContactAddress::DefinitionName).count(), 1); |
|
153 QVERIFY(c.removeDetail(&a2)); |
|
154 QVERIFY(!c.removeDetail(&a2)); // cannot remove twice |
|
155 QCOMPARE(c.details(QContactAddress::DefinitionName).count(), 0); |
|
156 |
|
157 QContactAddress a3; |
|
158 |
|
159 // set street |
|
160 a3.setStreet("Test"); |
|
161 QCOMPARE(a3.street(), QString("Test")); |
|
162 a3.setStreet(""); |
|
163 |
|
164 // set locality |
|
165 a3.setLocality("Test"); |
|
166 QCOMPARE(a3.locality(), QString("Test")); |
|
167 a3.setLocality(""); |
|
168 |
|
169 // set region |
|
170 a3.setRegion("Test"); |
|
171 QCOMPARE(a3.region(), QString("Test")); |
|
172 a3.setRegion(""); |
|
173 |
|
174 // set postcode |
|
175 a3.setPostcode("Test"); |
|
176 QCOMPARE(a3.postcode(), QString("Test")); |
|
177 a3.setPostcode(""); |
|
178 |
|
179 // set country |
|
180 a3.setCountry("Test"); |
|
181 QCOMPARE(a3.country(), QString("Test")); |
|
182 a3.setCountry(""); |
|
183 |
|
184 // subtypes |
|
185 a3.setSubTypes(QContactAddress::SubTypeDomestic); |
|
186 QCOMPARE(a3.subTypes(), QStringList(QContactAddress::SubTypeDomestic)); |
|
187 a3.setSubTypes(QStringList() << QContactAddress::SubTypeInternational << QContactAddress::SubTypePostal); |
|
188 QCOMPARE(a3.subTypes(), QStringList() << QContactAddress::SubTypeInternational << QContactAddress::SubTypePostal); |
|
189 } |
|
190 |
|
191 void tst_QContactDetails::anniversary() |
|
192 { |
|
193 QContact c; |
|
194 QContactAnniversary a1, a2; |
|
195 QDate currDate = QDate::currentDate(); |
|
196 |
|
197 // test property set |
|
198 a1.setCalendarId("1234"); |
|
199 QCOMPARE(a1.calendarId(), QString("1234")); |
|
200 QCOMPARE(a1.value(QContactAnniversary::FieldCalendarId), QString("1234")); |
|
201 a1.setEvent("4321"); |
|
202 QCOMPARE(a1.event(), QString("4321")); |
|
203 QCOMPARE(a1.value(QContactAnniversary::FieldEvent), QString("4321")); |
|
204 a1.setOriginalDate(currDate); |
|
205 QCOMPARE(a1.originalDate(), currDate); |
|
206 QCOMPARE(a1.value<QDate>(QContactAnniversary::FieldOriginalDate), currDate); |
|
207 a1.setSubType(QContactAnniversary::SubTypeWedding); |
|
208 QCOMPARE(a1.subType(), QString(QLatin1String(QContactAnniversary::SubTypeWedding))); |
|
209 QCOMPARE(a1.value(QContactAnniversary::FieldSubType), QString(QLatin1String(QContactAnniversary::SubTypeWedding))); |
|
210 |
|
211 // test property add |
|
212 QVERIFY(c.saveDetail(&a1)); |
|
213 QCOMPARE(c.details(QContactAnniversary::DefinitionName).count(), 1); |
|
214 QCOMPARE(QContactAnniversary(c.details(QContactAnniversary::DefinitionName).value(0)).event(), a1.event()); |
|
215 |
|
216 // test property update |
|
217 a1.setValue("label","label1"); |
|
218 a1.setCalendarId("12345"); |
|
219 QVERIFY(c.saveDetail(&a1)); |
|
220 QCOMPARE(c.details(QContactAnniversary::DefinitionName).value(0).value("label"), QString("label1")); |
|
221 QCOMPARE(c.details(QContactAnniversary::DefinitionName).value(0).value(QContactAnniversary::FieldCalendarId), QString("12345")); |
|
222 |
|
223 // test property remove |
|
224 QVERIFY(c.removeDetail(&a1)); |
|
225 QCOMPARE(c.details(QContactAnniversary::DefinitionName).count(), 0); |
|
226 QVERIFY(c.saveDetail(&a2)); |
|
227 QCOMPARE(c.details(QContactAnniversary::DefinitionName).count(), 1); |
|
228 QVERIFY(c.removeDetail(&a2)); |
|
229 QCOMPARE(c.details(QContactAnniversary::DefinitionName).count(), 0); |
|
230 QVERIFY(c.removeDetail(&a2) == false); |
|
231 QCOMPARE(c.details(QContactAnniversary::DefinitionName).count(), 0); |
|
232 } |
|
233 |
|
234 void tst_QContactDetails::avatar() |
|
235 { |
|
236 QContact c; |
|
237 QContactAvatar a1, a2; |
|
238 |
|
239 // test property set |
|
240 a1.setAvatar("1234"); |
|
241 QCOMPARE(a1.avatar(), QString("1234")); |
|
242 QCOMPARE(a1.value(QContactAvatar::FieldAvatar), QString("1234")); |
|
243 a1.setSubType(QContactAvatar::SubTypeAudioRingtone); |
|
244 QCOMPARE(a1.subType(), QString(QLatin1String(QContactAvatar::SubTypeAudioRingtone))); |
|
245 QCOMPARE(a1.value(QContactAvatar::FieldSubType), QString(QLatin1String(QContactAvatar::SubTypeAudioRingtone))); |
|
246 |
|
247 a1.setSubType(QContactAvatar::SubTypeImage); |
|
248 |
|
249 //pixmap |
|
250 uchar pixDataRGB[] = {255, 0, 0, 0, 0, 255, 0, 0, 255, 255, 0, 0}; // Red, Blue, Red, Blue |
|
251 QImage img(pixDataRGB, 2, 2, 6, QImage::Format_RGB888); // 2 pixels width, 2 pixels height, 6 bytes per line, RGB888 format |
|
252 QImage scaled = img.scaled(100, 100); // Scale image to show results better |
|
253 QPixmap pix = QPixmap::fromImage(scaled); // Create pixmap from image |
|
254 a1.setPixmap(pix); |
|
255 |
|
256 // test property add |
|
257 QVERIFY(c.saveDetail(&a1)); |
|
258 QCOMPARE(c.details(QContactAvatar::DefinitionName).count(), 1); |
|
259 QCOMPARE(QContactAvatar(c.details(QContactAvatar::DefinitionName).value(0)).avatar(), a1.avatar()); |
|
260 QCOMPARE(a1.pixmap(), pix); |
|
261 |
|
262 // test property update |
|
263 a1.setValue("label","label1"); |
|
264 a1.setAvatar("12345"); |
|
265 QVERIFY(c.saveDetail(&a1)); |
|
266 QCOMPARE(c.details(QContactAvatar::DefinitionName).value(0).value("label"), QString("label1")); |
|
267 QCOMPARE(c.details(QContactAvatar::DefinitionName).value(0).value(QContactAvatar::FieldAvatar), QString("12345")); |
|
268 |
|
269 // test property remove |
|
270 QVERIFY(c.removeDetail(&a1)); |
|
271 QCOMPARE(c.details(QContactAvatar::DefinitionName).count(), 0); |
|
272 QVERIFY(c.saveDetail(&a2)); |
|
273 QCOMPARE(c.details(QContactAvatar::DefinitionName).count(), 1); |
|
274 QVERIFY(c.removeDetail(&a2)); |
|
275 QCOMPARE(c.details(QContactAvatar::DefinitionName).count(), 0); |
|
276 QVERIFY(c.removeDetail(&a2) == false); |
|
277 QCOMPARE(c.details(QContactAvatar::DefinitionName).count(), 0); |
|
278 } |
|
279 |
|
280 void tst_QContactDetails::birthday() |
|
281 { |
|
282 QContact c; |
|
283 QContactBirthday b1, b2; |
|
284 QDate currDate = QDate::currentDate(); |
|
285 |
|
286 // test property set |
|
287 b1.setDate(currDate); |
|
288 QCOMPARE(b1.date(), currDate); |
|
289 QCOMPARE(b1.value<QDate>(QContactBirthday::FieldBirthday), currDate); |
|
290 |
|
291 // test property add |
|
292 QVERIFY(c.saveDetail(&b1)); |
|
293 QCOMPARE(c.details(QContactBirthday::DefinitionName).count(), 1); |
|
294 QCOMPARE(QContactBirthday(c.details(QContactBirthday::DefinitionName).value(0)).date(), b1.date()); |
|
295 |
|
296 // test property update |
|
297 b1.setValue("label","label1"); |
|
298 b1.setDate(currDate.addDays(3)); |
|
299 QVERIFY(c.saveDetail(&b1)); |
|
300 QCOMPARE(c.details(QContactBirthday::DefinitionName).value(0).value("label"), QString("label1")); |
|
301 QCOMPARE(c.details(QContactBirthday::DefinitionName).value(0).value<QDate>(QContactBirthday::FieldBirthday), currDate.addDays(3)); |
|
302 |
|
303 // test property remove |
|
304 QVERIFY(c.removeDetail(&b1)); |
|
305 QCOMPARE(c.details(QContactBirthday::DefinitionName).count(), 0); |
|
306 QVERIFY(c.saveDetail(&b2)); |
|
307 QCOMPARE(c.details(QContactBirthday::DefinitionName).count(), 1); |
|
308 QVERIFY(c.removeDetail(&b2)); |
|
309 QCOMPARE(c.details(QContactBirthday::DefinitionName).count(), 0); |
|
310 QVERIFY(c.removeDetail(&b2) == false); |
|
311 QCOMPARE(c.details(QContactBirthday::DefinitionName).count(), 0); |
|
312 } |
|
313 |
|
314 void tst_QContactDetails::displayLabel() |
|
315 { |
|
316 QContactDisplayLabel d1; |
|
317 |
|
318 QVERIFY(d1.label().isEmpty()); |
|
319 QVERIFY(d1.value(QContactDisplayLabel::FieldLabel).isEmpty()); |
|
320 d1.setValue(QContactDisplayLabel::FieldLabel, "Test"); |
|
321 QVERIFY(d1.value(QContactDisplayLabel::FieldLabel) == QString("Test")); |
|
322 QVERIFY(d1.label() == QString("Test")); |
|
323 |
|
324 /* XXX TODO: test property add, update and remove. Special semantics for display label. */ |
|
325 } |
|
326 |
|
327 void tst_QContactDetails::emailAddress() |
|
328 { |
|
329 QContact c; |
|
330 QContactEmailAddress e1, e2; |
|
331 |
|
332 // test property set |
|
333 e1.setEmailAddress("1234"); |
|
334 QCOMPARE(e1.emailAddress(), QString("1234")); |
|
335 QCOMPARE(e1.value(QContactEmailAddress::FieldEmailAddress), QString("1234")); |
|
336 |
|
337 // test property add |
|
338 QVERIFY(c.saveDetail(&e1)); |
|
339 QCOMPARE(c.details(QContactEmailAddress::DefinitionName).count(), 1); |
|
340 QCOMPARE(QContactEmailAddress(c.details(QContactEmailAddress::DefinitionName).value(0)).emailAddress(), e1.emailAddress()); |
|
341 |
|
342 // test property update |
|
343 e1.setValue("label","label1"); |
|
344 e1.setEmailAddress("12345"); |
|
345 QVERIFY(c.saveDetail(&e1)); |
|
346 QCOMPARE(c.details(QContactEmailAddress::DefinitionName).value(0).value("label"), QString("label1")); |
|
347 QCOMPARE(c.details(QContactEmailAddress::DefinitionName).value(0).value(QContactEmailAddress::FieldEmailAddress), QString("12345")); |
|
348 |
|
349 // test property remove |
|
350 QVERIFY(c.removeDetail(&e1)); |
|
351 QCOMPARE(c.details(QContactEmailAddress::DefinitionName).count(), 0); |
|
352 QVERIFY(c.saveDetail(&e2)); |
|
353 QCOMPARE(c.details(QContactEmailAddress::DefinitionName).count(), 1); |
|
354 QVERIFY(c.removeDetail(&e2)); |
|
355 QCOMPARE(c.details(QContactEmailAddress::DefinitionName).count(), 0); |
|
356 QVERIFY(c.removeDetail(&e2) == false); |
|
357 QCOMPARE(c.details(QContactEmailAddress::DefinitionName).count(), 0); |
|
358 } |
|
359 |
|
360 void tst_QContactDetails::family() |
|
361 { |
|
362 QContact c; |
|
363 QContactFamily f1, f2; |
|
364 |
|
365 // test property set |
|
366 f1.setSpouse("1234"); |
|
367 QCOMPARE(f1.spouse(), QString("1234")); |
|
368 QCOMPARE(f1.value(QContactFamily::FieldSpouse), QString("1234")); |
|
369 |
|
370 // test property add |
|
371 QVERIFY(c.saveDetail(&f1)); |
|
372 QCOMPARE(c.details(QContactFamily::DefinitionName).count(), 1); |
|
373 QCOMPARE(QContactFamily(c.details(QContactFamily::DefinitionName).value(0)).spouse(), f1.spouse()); |
|
374 |
|
375 // test property update |
|
376 f1.setValue("label","label1"); |
|
377 f1.setSpouse("12345"); |
|
378 f1.setChildren(QStringList("54321")); |
|
379 QVERIFY(c.saveDetail(&f1)); |
|
380 QCOMPARE(c.details(QContactFamily::DefinitionName).value(0).value("label"), QString("label1")); |
|
381 QCOMPARE(c.details(QContactFamily::DefinitionName).value(0).value(QContactFamily::FieldSpouse), QString("12345")); |
|
382 QCOMPARE(c.details(QContactFamily::DefinitionName).value(0).value<QStringList>(QContactFamily::FieldChildren), QStringList("54321")); |
|
383 |
|
384 // test property remove |
|
385 f2.setSpouse("1111"); |
|
386 QVERIFY(c.removeDetail(&f1)); |
|
387 QCOMPARE(c.details(QContactFamily::DefinitionName).count(), 0); |
|
388 QVERIFY(c.saveDetail(&f2)); |
|
389 QCOMPARE(c.details(QContactFamily::DefinitionName).count(), 1); |
|
390 QVERIFY(c.removeDetail(&f2)); |
|
391 QCOMPARE(c.details(QContactFamily::DefinitionName).count(), 0); |
|
392 QVERIFY(c.removeDetail(&f2) == false); |
|
393 QCOMPARE(c.details(QContactFamily::DefinitionName).count(), 0); |
|
394 } |
|
395 |
|
396 void tst_QContactDetails::gender() |
|
397 { |
|
398 QContact c; |
|
399 QContactGender g1, g2; |
|
400 |
|
401 // test property set |
|
402 g1.setGender("1234"); |
|
403 QCOMPARE(g1.gender(), QString("1234")); |
|
404 QCOMPARE(g1.value(QContactGender::FieldGender), QString("1234")); |
|
405 |
|
406 // test property add |
|
407 QVERIFY(c.saveDetail(&g1)); |
|
408 QCOMPARE(c.details(QContactGender::DefinitionName).count(), 1); |
|
409 QCOMPARE(QContactGender(c.details(QContactGender::DefinitionName).value(0)).gender(), g1.gender()); |
|
410 |
|
411 // test property update |
|
412 g1.setValue("label","label1"); |
|
413 g1.setGender("12345"); |
|
414 QVERIFY(c.saveDetail(&g1)); |
|
415 QCOMPARE(c.details(QContactGender::DefinitionName).value(0).value("label"), QString("label1")); |
|
416 QCOMPARE(c.details(QContactGender::DefinitionName).value(0).value(QContactGender::FieldGender), QString("12345")); |
|
417 |
|
418 // test property remove |
|
419 QVERIFY(c.removeDetail(&g1)); |
|
420 QCOMPARE(c.details(QContactGender::DefinitionName).count(), 0); |
|
421 QVERIFY(c.saveDetail(&g2)); |
|
422 QCOMPARE(c.details(QContactGender::DefinitionName).count(), 1); |
|
423 QVERIFY(c.removeDetail(&g2)); |
|
424 QCOMPARE(c.details(QContactGender::DefinitionName).count(), 0); |
|
425 QVERIFY(c.removeDetail(&g2) == false); |
|
426 QCOMPARE(c.details(QContactGender::DefinitionName).count(), 0); |
|
427 } |
|
428 |
|
429 void tst_QContactDetails::geolocation() |
|
430 { |
|
431 QContact c; |
|
432 QContactGeolocation g1, g2; |
|
433 |
|
434 // test property set |
|
435 g1.setLabel("1234"); |
|
436 QCOMPARE(g1.label(), QString("1234")); |
|
437 QCOMPARE(g1.value(QContactGeolocation::FieldLabel), QString("1234")); |
|
438 g1.setAccuracy(3.2); |
|
439 QCOMPARE(g1.accuracy(), 3.2); |
|
440 QCOMPARE(g1.variantValue(QContactGeolocation::FieldAccuracy), QVariant(3.2)); |
|
441 g1.setAltitude(3.3); |
|
442 QCOMPARE(g1.altitude(), 3.3); |
|
443 QCOMPARE(g1.variantValue(QContactGeolocation::FieldAltitude), QVariant(3.3)); |
|
444 g1.setAltitudeAccuracy(3.4); |
|
445 QCOMPARE(g1.altitudeAccuracy(), 3.4); |
|
446 QCOMPARE(g1.variantValue(QContactGeolocation::FieldAltitudeAccuracy), QVariant(3.4)); |
|
447 g1.setHeading(3.5); |
|
448 QCOMPARE(g1.heading(), 3.5); |
|
449 QCOMPARE(g1.variantValue(QContactGeolocation::FieldHeading), QVariant(3.5)); |
|
450 g1.setLatitude(3.6); |
|
451 QCOMPARE(g1.latitude(), 3.6); |
|
452 QCOMPARE(g1.variantValue(QContactGeolocation::FieldLatitude), QVariant(3.6)); |
|
453 g1.setLongitude(3.7); |
|
454 QCOMPARE(g1.longitude(), 3.7); |
|
455 QCOMPARE(g1.variantValue(QContactGeolocation::FieldLongitude), QVariant(3.7)); |
|
456 QDateTime current = QDateTime::currentDateTime(); |
|
457 g1.setTimestamp(current); |
|
458 QCOMPARE(g1.timestamp(), current); |
|
459 QCOMPARE(g1.variantValue(QContactGeolocation::FieldTimestamp), QVariant(current)); |
|
460 g1.setSpeed(3.8); |
|
461 QCOMPARE(g1.speed(), 3.8); |
|
462 QCOMPARE(g1.variantValue(QContactGeolocation::FieldSpeed), QVariant(3.8)); |
|
463 |
|
464 // test property add |
|
465 QVERIFY(c.saveDetail(&g1)); |
|
466 QCOMPARE(c.details(QContactGeolocation::DefinitionName).count(), 1); |
|
467 QCOMPARE(QContactGeolocation(c.details(QContactGeolocation::DefinitionName).value(0)).label(), g1.label()); |
|
468 |
|
469 // test property update |
|
470 g1.setLabel("12345"); |
|
471 QVERIFY(c.saveDetail(&g1)); |
|
472 QCOMPARE(c.details(QContactGeolocation::DefinitionName).value(0).value(QContactGeolocation::FieldLabel), QString("12345")); |
|
473 |
|
474 // test property remove |
|
475 QVERIFY(c.removeDetail(&g1)); |
|
476 QCOMPARE(c.details(QContactGeolocation::DefinitionName).count(), 0); |
|
477 QVERIFY(c.saveDetail(&g2)); |
|
478 QCOMPARE(c.details(QContactGeolocation::DefinitionName).count(), 1); |
|
479 QVERIFY(c.removeDetail(&g2)); |
|
480 QCOMPARE(c.details(QContactGeolocation::DefinitionName).count(), 0); |
|
481 QVERIFY(c.removeDetail(&g2) == false); |
|
482 QCOMPARE(c.details(QContactGeolocation::DefinitionName).count(), 0); |
|
483 } |
|
484 |
|
485 void tst_QContactDetails::guid() |
|
486 { |
|
487 QContact c; |
|
488 QContactGuid g1, g2; |
|
489 |
|
490 // test property set |
|
491 g1.setGuid("1234"); |
|
492 QCOMPARE(g1.guid(), QString("1234")); |
|
493 QCOMPARE(g1.value(QContactGuid::FieldGuid), QString("1234")); |
|
494 |
|
495 // test property add |
|
496 QVERIFY(c.saveDetail(&g1)); |
|
497 QCOMPARE(c.details(QContactGuid::DefinitionName).count(), 1); |
|
498 QCOMPARE(QContactGuid(c.details(QContactGuid::DefinitionName).value(0)).guid(), g1.guid()); |
|
499 |
|
500 // test property update |
|
501 g1.setValue("label","label1"); |
|
502 g1.setGuid("12345"); |
|
503 QVERIFY(c.saveDetail(&g1)); |
|
504 QCOMPARE(c.details(QContactGuid::DefinitionName).value(0).value("label"), QString("label1")); |
|
505 QCOMPARE(c.details(QContactGuid::DefinitionName).value(0).value(QContactGuid::FieldGuid), QString("12345")); |
|
506 |
|
507 // test property remove |
|
508 QVERIFY(c.removeDetail(&g1)); |
|
509 QCOMPARE(c.details(QContactGuid::DefinitionName).count(), 0); |
|
510 QVERIFY(c.saveDetail(&g2)); |
|
511 QCOMPARE(c.details(QContactGuid::DefinitionName).count(), 1); |
|
512 QVERIFY(c.removeDetail(&g2)); |
|
513 QCOMPARE(c.details(QContactGuid::DefinitionName).count(), 0); |
|
514 QVERIFY(c.removeDetail(&g2) == false); |
|
515 QCOMPARE(c.details(QContactGuid::DefinitionName).count(), 0); |
|
516 } |
|
517 |
|
518 void tst_QContactDetails::name() |
|
519 { |
|
520 QContact c; |
|
521 QContactName n1, n2; |
|
522 |
|
523 QVERIFY(n1.isEmpty()); |
|
524 QVERIFY(n2.isEmpty()); |
|
525 |
|
526 // test property set |
|
527 n1.setPrefix("Dr"); |
|
528 n1.setFirst("Freddy"); |
|
529 n1.setMiddle("William Preston"); |
|
530 n1.setLast("Gumboots"); |
|
531 n1.setSuffix("Esquire"); |
|
532 QCOMPARE(n1.prefix(), QString("Dr")); |
|
533 QCOMPARE(n1.first(), QString("Freddy")); |
|
534 QCOMPARE(n1.middle(), QString("William Preston")); |
|
535 QCOMPARE(n1.last(), QString("Gumboots")); |
|
536 QCOMPARE(n1.suffix(), QString("Esquire")); |
|
537 |
|
538 // test property add |
|
539 QVERIFY(c.saveDetail(&n1)); |
|
540 QCOMPARE(c.details(QContactName::DefinitionName).count(), 1); |
|
541 n2.setFirst("Billy"); |
|
542 n2.setLast("Galoshes"); |
|
543 QVERIFY(c.saveDetail(&n2)); |
|
544 QCOMPARE(c.details(QContactName::DefinitionName).count(), 2); |
|
545 |
|
546 // test property update |
|
547 n1.setValue("label","label1"); |
|
548 QVERIFY(c.saveDetail(&n1)); |
|
549 |
|
550 // test property remove |
|
551 QVERIFY(c.removeDetail(&n1)); // remove |
|
552 QCOMPARE(c.details(QContactName::DefinitionName).count(), 1); |
|
553 QVERIFY(c.saveDetail(&n2)); // save but already added; count remains the same. |
|
554 QCOMPARE(c.details(QContactName::DefinitionName).count(), 1); |
|
555 QVERIFY(c.removeDetail(&n2)); // remove it |
|
556 QCOMPARE(c.details(QContactName::DefinitionName).count(), 0); |
|
557 QVERIFY(!c.removeDetail(&n2));// remove now fails |
|
558 QVERIFY(c.saveDetail(&n1)); // save the original name |
|
559 QCOMPARE(c.details(QContactName::DefinitionName).count(), 1); |
|
560 } |
|
561 |
|
562 void tst_QContactDetails::nickname() |
|
563 { |
|
564 QContact c; |
|
565 QContactNickname n1, n2; |
|
566 |
|
567 // test property set |
|
568 n1.setNickname("1234"); |
|
569 QCOMPARE(n1.nickname(), QString("1234")); |
|
570 QCOMPARE(n1.value(QContactNickname::FieldNickname), QString("1234")); |
|
571 |
|
572 // test property add |
|
573 QVERIFY(c.saveDetail(&n1)); |
|
574 QCOMPARE(c.details(QContactNickname::DefinitionName).count(), 1); |
|
575 QCOMPARE(QContactNickname(c.details(QContactNickname::DefinitionName).value(0)).nickname(), n1.nickname()); |
|
576 |
|
577 // test property update |
|
578 n1.setValue("label","label1"); |
|
579 n1.setNickname("12345"); |
|
580 QVERIFY(c.saveDetail(&n1)); |
|
581 QCOMPARE(c.details(QContactNickname::DefinitionName).value(0).value("label"), QString("label1")); |
|
582 QCOMPARE(c.details(QContactNickname::DefinitionName).value(0).value(QContactNickname::FieldNickname), QString("12345")); |
|
583 |
|
584 // test property remove |
|
585 QVERIFY(c.removeDetail(&n1)); |
|
586 QCOMPARE(c.details(QContactNickname::DefinitionName).count(), 0); |
|
587 QVERIFY(c.saveDetail(&n2)); |
|
588 QCOMPARE(c.details(QContactNickname::DefinitionName).count(), 1); |
|
589 QVERIFY(c.removeDetail(&n2)); |
|
590 QCOMPARE(c.details(QContactNickname::DefinitionName).count(), 0); |
|
591 QVERIFY(c.removeDetail(&n2) == false); |
|
592 QCOMPARE(c.details(QContactNickname::DefinitionName).count(), 0); |
|
593 } |
|
594 |
|
595 void tst_QContactDetails::onlineAccount() |
|
596 { |
|
597 QContact c; |
|
598 QContactOnlineAccount o1, o2; |
|
599 |
|
600 // test property set |
|
601 o1.setAccountUri("test@nokia.com"); |
|
602 QCOMPARE(o1.accountUri(), QString("test@nokia.com")); |
|
603 QCOMPARE(o1.value(QContactOnlineAccount::FieldAccountUri), QString("test@nokia.com")); |
|
604 o1.setNickname("test"); |
|
605 QCOMPARE(o1.nickname(), QString("test")); |
|
606 QCOMPARE(o1.value(QContactOnlineAccount::FieldNickname), QString("test")); |
|
607 o1.setStatusMessage("Gone Fishing"); |
|
608 QCOMPARE(o1.statusMessage(), QString("Gone Fishing")); |
|
609 QCOMPARE(o1.value(QContactOnlineAccount::FieldStatusMessage), QString("Gone Fishing")); |
|
610 o1.setPresence("Extended Away"); |
|
611 QCOMPARE(o1.presence(), QString("Extended Away")); |
|
612 QCOMPARE(o1.value(QContactOnlineAccount::FieldPresence), QString("Extended Away")); |
|
613 |
|
614 // Sub types |
|
615 o1.setSubTypes(QContactOnlineAccount::SubTypeSip); |
|
616 QCOMPARE(o1.subTypes(), QStringList() << QLatin1String(QContactOnlineAccount::SubTypeSip)); |
|
617 |
|
618 QStringList sl; |
|
619 sl << QLatin1String(QContactOnlineAccount::SubTypeImpp) << QLatin1String(QContactOnlineAccount::SubTypeVideoShare); |
|
620 o1.setSubTypes(sl); |
|
621 QCOMPARE(o1.subTypes(), sl); |
|
622 |
|
623 o1 = QContactOnlineAccount(); |
|
624 o1.setAccountUri("test@nokia.com"); |
|
625 |
|
626 // test property add |
|
627 QVERIFY(c.saveDetail(&o1)); |
|
628 QCOMPARE(c.details(QContactOnlineAccount::DefinitionName).count(), 1); |
|
629 QCOMPARE(QContactOnlineAccount(c.details(QContactOnlineAccount::DefinitionName).value(0)).accountUri(), o1.accountUri()); |
|
630 QCOMPARE(QContactOnlineAccount(c.details(QContactOnlineAccount::DefinitionName).value(0)).presence(), o1.presence()); |
|
631 QCOMPARE(QContactOnlineAccount(c.details(QContactOnlineAccount::DefinitionName).value(0)).nickname(), o1.nickname()); |
|
632 QCOMPARE(QContactOnlineAccount(c.details(QContactOnlineAccount::DefinitionName).value(0)).statusMessage(), o1.statusMessage()); |
|
633 QCOMPARE(QContactOnlineAccount(c.details(QContactOnlineAccount::DefinitionName).value(0)).accountUri(), o1.accountUri()); |
|
634 |
|
635 // test property update |
|
636 o1.setValue("label","label1"); |
|
637 o1.setAccountUri("test2@nokia.com"); |
|
638 QVERIFY(c.saveDetail(&o1)); |
|
639 QCOMPARE(c.details(QContactOnlineAccount::DefinitionName).value(0).value("label"), QString("label1")); |
|
640 QCOMPARE(c.details(QContactOnlineAccount::DefinitionName).value(0).value(QContactOnlineAccount::FieldAccountUri), QString("test2@nokia.com")); |
|
641 |
|
642 // test property remove |
|
643 QVERIFY(c.removeDetail(&o1)); |
|
644 QCOMPARE(c.details(QContactOnlineAccount::DefinitionName).count(), 0); |
|
645 QVERIFY(c.saveDetail(&o2)); |
|
646 QCOMPARE(c.details(QContactOnlineAccount::DefinitionName).count(), 1); |
|
647 QVERIFY(c.removeDetail(&o2)); |
|
648 QCOMPARE(c.details(QContactOnlineAccount::DefinitionName).count(), 0); |
|
649 QVERIFY(c.removeDetail(&o2) == false); |
|
650 QCOMPARE(c.details(QContactOnlineAccount::DefinitionName).count(), 0); |
|
651 } |
|
652 |
|
653 void tst_QContactDetails::organization() |
|
654 { |
|
655 QContact c; |
|
656 QContactOrganization o1, o2; |
|
657 |
|
658 // test property set |
|
659 o1.setName("organization one"); |
|
660 QCOMPARE(o1.name(), QString("organization one")); |
|
661 QCOMPARE(o1.value(QContactOrganization::FieldName), QString("organization one")); |
|
662 |
|
663 o1.setDepartment(QStringList(QString("department one"))); |
|
664 QCOMPARE(o1.department(), QStringList(QString("department one"))); |
|
665 QCOMPARE(o1.value<QStringList>(QContactOrganization::FieldDepartment), QStringList(QString("department one"))); |
|
666 |
|
667 o1.setLocation("location one"); |
|
668 QCOMPARE(o1.location(), QString("location one")); |
|
669 QCOMPARE(o1.value(QContactOrganization::FieldLocation), QString("location one")); |
|
670 |
|
671 o1.setLogo("logo one"); |
|
672 QCOMPARE(o1.logo(), QString("logo one")); |
|
673 QCOMPARE(o1.value(QContactOrganization::FieldLogo), QString("logo one")); |
|
674 |
|
675 o1.setTitle("title one"); |
|
676 QCOMPARE(o1.title(), QString("title one")); |
|
677 QCOMPARE(o1.value(QContactOrganization::FieldTitle), QString("title one")); |
|
678 |
|
679 o1.setAssistantName("assistant one"); |
|
680 QCOMPARE(o1.assistantName(), QString("assistant one")); |
|
681 QCOMPARE(o1.value(QContactOrganization::FieldAssistantName), QString("assistant one")); |
|
682 |
|
683 // test property add |
|
684 QVERIFY(c.saveDetail(&o1)); |
|
685 QCOMPARE(c.details(QContactOrganization::DefinitionName).count(), 1); |
|
686 QCOMPARE(QContactOrganization(c.details(QContactOrganization::DefinitionName).value(0)).name(), o1.name()); |
|
687 |
|
688 // test property update |
|
689 o1.setName("organization two"); |
|
690 QVERIFY(c.saveDetail(&o1)); |
|
691 QCOMPARE(c.details(QContactOrganization::DefinitionName).value(0).value(QContactOrganization::FieldName), QString("organization two")); |
|
692 |
|
693 // test property remove |
|
694 QVERIFY(c.removeDetail(&o1)); |
|
695 QCOMPARE(c.details(QContactOrganization::DefinitionName).count(), 0); |
|
696 QVERIFY(c.saveDetail(&o2)); |
|
697 QCOMPARE(c.details(QContactOrganization::DefinitionName).count(), 1); |
|
698 QVERIFY(c.removeDetail(&o2)); |
|
699 QCOMPARE(c.details(QContactOrganization::DefinitionName).count(), 0); |
|
700 QVERIFY(c.removeDetail(&o2) == false); |
|
701 QCOMPARE(c.details(QContactOrganization::DefinitionName).count(), 0); |
|
702 |
|
703 // organization-specific API testing |
|
704 o1.setDepartment(QStringList(QString("Imaginary Dept"))); |
|
705 o1.setLocation("Utopia"); |
|
706 o1.setLogo("logo.png"); |
|
707 o1.setName("Utopian Megacorporation"); |
|
708 o1.setTitle("Generic Employee"); |
|
709 c.saveDetail(&o1); |
|
710 QVERIFY(c.detail(QContactOrganization::DefinitionName).value<QStringList>(QContactOrganization::FieldDepartment) == QStringList(QString("Imaginary Dept"))); |
|
711 QVERIFY(c.detail(QContactOrganization::DefinitionName).value(QContactOrganization::FieldLocation) == QString("Utopia")); |
|
712 QVERIFY(c.detail(QContactOrganization::DefinitionName).value(QContactOrganization::FieldLogo) == QString("logo.png")); |
|
713 QVERIFY(c.detail(QContactOrganization::DefinitionName).value(QContactOrganization::FieldName) == QString("Utopian Megacorporation")); |
|
714 QVERIFY(c.detail(QContactOrganization::DefinitionName).value(QContactOrganization::FieldTitle) == QString("Generic Employee")); |
|
715 } |
|
716 |
|
717 void tst_QContactDetails::phoneNumber() |
|
718 { |
|
719 QContact c; |
|
720 QContactPhoneNumber p1, p2; |
|
721 |
|
722 // test property set |
|
723 p1.setNumber("1234"); |
|
724 QCOMPARE(p1.number(), QString("1234")); |
|
725 QCOMPARE(p1.value(QContactPhoneNumber::FieldNumber), QString("1234")); |
|
726 |
|
727 // Sub types |
|
728 p1.setSubTypes(QContactPhoneNumber::SubTypeCar); |
|
729 QCOMPARE(p1.subTypes(), QStringList() << QLatin1String(QContactPhoneNumber::SubTypeCar)); |
|
730 |
|
731 QStringList sl; |
|
732 sl << QLatin1String(QContactPhoneNumber::SubTypeMobile) << QLatin1String(QContactPhoneNumber::SubTypeFacsimile); |
|
733 p1.setSubTypes(sl); |
|
734 QCOMPARE(p1.subTypes(), sl); |
|
735 |
|
736 // test property add |
|
737 QVERIFY(c.saveDetail(&p1)); |
|
738 QCOMPARE(c.details(QContactPhoneNumber::DefinitionName).count(), 1); |
|
739 QCOMPARE(QContactPhoneNumber(c.details(QContactPhoneNumber::DefinitionName).value(0)).number(), p1.number()); |
|
740 |
|
741 // test property update |
|
742 p1.setValue("label","label1"); |
|
743 p1.setNumber("12345"); |
|
744 QVERIFY(c.saveDetail(&p1)); |
|
745 QCOMPARE(c.details(QContactPhoneNumber::DefinitionName).value(0).value("label"), QString("label1")); |
|
746 QCOMPARE(c.details(QContactPhoneNumber::DefinitionName).value(0).value(QContactPhoneNumber::FieldNumber), QString("12345")); |
|
747 |
|
748 p1.setSubTypes(QContactPhoneNumber::SubTypeDtmfMenu); |
|
749 c.saveDetail(&p1); |
|
750 QVERIFY(c.detail(QContactPhoneNumber::DefinitionName).variantValue(QContactPhoneNumber::FieldSubTypes).toStringList() == QStringList(QString(QLatin1String(QContactPhoneNumber::SubTypeDtmfMenu)))); |
|
751 p1.setSubTypes(QStringList() << QContactPhoneNumber::SubTypeModem << QContactPhoneNumber::SubTypeFacsimile); |
|
752 c.saveDetail(&p1); |
|
753 QVERIFY(c.detail(QContactPhoneNumber::DefinitionName).variantValue(QContactPhoneNumber::FieldSubTypes).toStringList() == p1.subTypes()); |
|
754 |
|
755 // test property remove |
|
756 QVERIFY(c.removeDetail(&p1)); |
|
757 QCOMPARE(c.details(QContactPhoneNumber::DefinitionName).count(), 0); |
|
758 QVERIFY(c.saveDetail(&p2)); |
|
759 QCOMPARE(c.details(QContactPhoneNumber::DefinitionName).count(), 1); |
|
760 QVERIFY(c.removeDetail(&p2)); |
|
761 QCOMPARE(c.details(QContactPhoneNumber::DefinitionName).count(), 0); |
|
762 QVERIFY(c.removeDetail(&p2) == false); |
|
763 QCOMPARE(c.details(QContactPhoneNumber::DefinitionName).count(), 0); |
|
764 } |
|
765 |
|
766 void tst_QContactDetails::syncTarget() |
|
767 { |
|
768 QContact c; |
|
769 QContactSyncTarget s1, s2; |
|
770 |
|
771 // test property set |
|
772 s1.setSyncTarget("1234"); |
|
773 QCOMPARE(s1.syncTarget(), QString("1234")); |
|
774 QCOMPARE(s1.value(QContactSyncTarget::FieldSyncTarget), QString("1234")); |
|
775 |
|
776 // test property add |
|
777 QVERIFY(c.saveDetail(&s1)); |
|
778 QCOMPARE(c.details(QContactSyncTarget::DefinitionName).count(), 1); |
|
779 QCOMPARE(QContactSyncTarget(c.details(QContactSyncTarget::DefinitionName).value(0)).syncTarget(), s1.syncTarget()); |
|
780 |
|
781 // test property update |
|
782 s1.setValue("label","label1"); |
|
783 s1.setSyncTarget("12345"); |
|
784 QVERIFY(c.saveDetail(&s1)); |
|
785 QCOMPARE(c.details(QContactSyncTarget::DefinitionName).value(0).value("label"), QString("label1")); |
|
786 QCOMPARE(c.details(QContactSyncTarget::DefinitionName).value(0).value(QContactSyncTarget::FieldSyncTarget), QString("12345")); |
|
787 |
|
788 // test property remove |
|
789 QVERIFY(c.removeDetail(&s1)); |
|
790 QCOMPARE(c.details(QContactSyncTarget::DefinitionName).count(), 0); |
|
791 QVERIFY(c.saveDetail(&s2)); |
|
792 QCOMPARE(c.details(QContactSyncTarget::DefinitionName).count(), 1); |
|
793 QVERIFY(c.removeDetail(&s2)); |
|
794 QCOMPARE(c.details(QContactSyncTarget::DefinitionName).count(), 0); |
|
795 QVERIFY(c.removeDetail(&s2) == false); |
|
796 QCOMPARE(c.details(QContactSyncTarget::DefinitionName).count(), 0); |
|
797 } |
|
798 |
|
799 void tst_QContactDetails::timestamp() |
|
800 { |
|
801 QContact c; |
|
802 QContactTimestamp t1, t2; |
|
803 QDateTime modified = QDateTime::currentDateTime(); |
|
804 QDateTime created = modified.addSecs(-43); |
|
805 |
|
806 // test property set |
|
807 t1.setCreated(created); |
|
808 QCOMPARE(t1.created(), created); |
|
809 QCOMPARE(t1.variantValue(QContactTimestamp::FieldCreationTimestamp).toDateTime(), created); |
|
810 |
|
811 // test property add |
|
812 QVERIFY(c.saveDetail(&t1)); |
|
813 QCOMPARE(c.details(QContactTimestamp::DefinitionName).count(), 1); |
|
814 QCOMPARE(QContactTimestamp(c.details(QContactTimestamp::DefinitionName).value(0)).created(), t1.created()); |
|
815 |
|
816 // test property update |
|
817 t1.setValue("label","label1"); |
|
818 t1.setLastModified(modified); |
|
819 QVERIFY(c.saveDetail(&t1)); |
|
820 QCOMPARE(c.details(QContactTimestamp::DefinitionName).value(0).value("label"), QString("label1")); |
|
821 QCOMPARE(c.details(QContactTimestamp::DefinitionName).value(0).variantValue(QContactTimestamp::FieldCreationTimestamp).toDateTime(), created); |
|
822 QCOMPARE(c.details(QContactTimestamp::DefinitionName).value(0).variantValue(QContactTimestamp::FieldModificationTimestamp).toDateTime(), modified); |
|
823 |
|
824 // test property remove |
|
825 QVERIFY(c.removeDetail(&t1)); |
|
826 QCOMPARE(c.details(QContactTimestamp::DefinitionName).count(), 0); |
|
827 t2.setCreated(created.addSecs(15)); |
|
828 QVERIFY(c.saveDetail(&t2)); |
|
829 QCOMPARE(c.details(QContactTimestamp::DefinitionName).count(), 1); |
|
830 QVERIFY(c.removeDetail(&t2)); |
|
831 QCOMPARE(c.details(QContactTimestamp::DefinitionName).count(), 0); |
|
832 QVERIFY(c.removeDetail(&t2) == false); |
|
833 QCOMPARE(c.details(QContactTimestamp::DefinitionName).count(), 0); |
|
834 } |
|
835 |
|
836 void tst_QContactDetails::type() |
|
837 { |
|
838 QContact c; |
|
839 QContactType t1, t2; |
|
840 |
|
841 // test property set |
|
842 t1.setType(QContactType::TypeGroup); |
|
843 QCOMPARE(t1.type(), QString(QLatin1String(QContactType::TypeGroup))); |
|
844 QCOMPARE(t1.value(QContactType::FieldType), QString(QLatin1String(QContactType::TypeGroup))); |
|
845 |
|
846 // test property add |
|
847 QVERIFY(c.saveDetail(&t1)); |
|
848 QCOMPARE(c.details(QContactType::DefinitionName).count(), 1); |
|
849 QCOMPARE(QContactType(c.details(QContactType::DefinitionName).value(0)).type(), t1.type()); |
|
850 |
|
851 // test property update |
|
852 t1.setType(QContactType::TypeContact); |
|
853 QVERIFY(c.saveDetail(&t1)); |
|
854 QCOMPARE(c.details(QContactType::DefinitionName).value(0).value(QContactType::FieldType), QString(QLatin1String(QContactType::TypeContact))); |
|
855 |
|
856 // test property remove |
|
857 QVERIFY(c.removeDetail(&t1)); // cannot remove type - "succeeds" but count remains unchanged |
|
858 QCOMPARE(c.details(QContactType::DefinitionName).count(), 1); |
|
859 t2.setType(QContactType::TypeGroup); |
|
860 QVERIFY(c.saveDetail(&t2)); // overwrites t1 |
|
861 QCOMPARE(c.details(QContactType::DefinitionName).count(), 1); |
|
862 QVERIFY(c.removeDetail(&t2)); // cannot remove type - "succeeds" but count remains unchanged |
|
863 QCOMPARE(c.details(QContactType::DefinitionName).count(), 1); |
|
864 QVERIFY(c.removeDetail(&t2)); // Should still succeed |
|
865 QCOMPARE(c.details(QContactType::DefinitionName).count(), 1); |
|
866 } |
|
867 |
|
868 void tst_QContactDetails::url() |
|
869 { |
|
870 QContact c; |
|
871 QContactUrl u1, u2; |
|
872 |
|
873 // test property set |
|
874 u1.setUrl("1234"); |
|
875 QCOMPARE(u1.url(), QString("1234")); |
|
876 QCOMPARE(u1.value(QContactUrl::FieldUrl), QString("1234")); |
|
877 |
|
878 u1.setSubType(QContactUrl::SubTypeHomePage); |
|
879 QCOMPARE(u1.subType(), QString(QLatin1String(QContactUrl::SubTypeHomePage))); |
|
880 QCOMPARE(u1.value(QContactUrl::FieldSubType), QString(QLatin1String(QContactUrl::SubTypeHomePage))); |
|
881 |
|
882 // test property add |
|
883 QVERIFY(c.saveDetail(&u1)); |
|
884 QCOMPARE(c.details(QContactUrl::DefinitionName).count(), 1); |
|
885 QCOMPARE(QContactUrl(c.details(QContactUrl::DefinitionName).value(0)).url(), u1.url()); |
|
886 |
|
887 // test property update |
|
888 u1.setValue("label","label1"); |
|
889 u1.setUrl("12345"); |
|
890 QVERIFY(c.saveDetail(&u1)); |
|
891 QCOMPARE(c.details(QContactUrl::DefinitionName).value(0).value("label"), QString("label1")); |
|
892 QCOMPARE(c.details(QContactUrl::DefinitionName).value(0).value(QContactUrl::FieldUrl), QString("12345")); |
|
893 |
|
894 // test property remove |
|
895 QVERIFY(c.removeDetail(&u1)); |
|
896 QCOMPARE(c.details(QContactUrl::DefinitionName).count(), 0); |
|
897 QVERIFY(c.saveDetail(&u2)); |
|
898 QCOMPARE(c.details(QContactUrl::DefinitionName).count(), 1); |
|
899 QVERIFY(c.removeDetail(&u2)); |
|
900 QCOMPARE(c.details(QContactUrl::DefinitionName).count(), 0); |
|
901 QVERIFY(c.removeDetail(&u2) == false); |
|
902 QCOMPARE(c.details(QContactUrl::DefinitionName).count(), 0); |
|
903 } |
|
904 |
|
905 void tst_QContactDetails::custom() |
|
906 { |
|
907 QContact c; |
|
908 QContactDetail c1("mycustom"), c2("mycustom"); |
|
909 |
|
910 // test property set |
|
911 c1.setValue("custom", "1234"); |
|
912 QCOMPARE(c1.value("custom"), QString("1234")); |
|
913 |
|
914 // test property add |
|
915 QVERIFY(c.saveDetail(&c1)); |
|
916 QCOMPARE(c.details("mycustom").count(), 1); |
|
917 QCOMPARE((c.details("mycustom").value(0)).value("custom"), c1.value("custom")); |
|
918 |
|
919 // test property update |
|
920 c1.setValue("label","label1"); |
|
921 c1.setValue("custom", "12345"); |
|
922 QVERIFY(c.saveDetail(&c1)); |
|
923 |
|
924 // test property remove |
|
925 QVERIFY(c.removeDetail(&c1)); |
|
926 QCOMPARE(c.details("mycustom").count(), 0); |
|
927 QVERIFY(c.saveDetail(&c2)); |
|
928 QCOMPARE(c.details("mycustom").count(), 1); |
|
929 QVERIFY(c.removeDetail(&c2)); |
|
930 QCOMPARE(c.details("mycustom").count(), 0); |
|
931 QVERIFY(c.removeDetail(&c2) == false); |
|
932 QCOMPARE(c.details("mycustom").count(), 0); |
|
933 } |
|
934 |
|
935 void tst_QContactDetails::note() |
|
936 { |
|
937 QContact c; |
|
938 QContactNote n1, n2; |
|
939 |
|
940 // test property set |
|
941 n1.setNote("lorem ipsum"); |
|
942 QCOMPARE(n1.note(), QString("lorem ipsum")); |
|
943 QCOMPARE(n1.value(QContactNote::FieldNote), QString("lorem ipsum")); |
|
944 |
|
945 // test property add |
|
946 QVERIFY(c.saveDetail(&n1)); |
|
947 QCOMPARE(c.details(QContactNote::DefinitionName).count(), 1); |
|
948 QCOMPARE(QContactNote(c.details(QContactNote::DefinitionName).value(0)).note(), n1.note()); |
|
949 |
|
950 // test property update |
|
951 n1.setValue("label","label1"); |
|
952 n1.setNote("orange gypsum"); |
|
953 QVERIFY(c.saveDetail(&n1)); |
|
954 QCOMPARE(c.details(QContactNote::DefinitionName).value(0).value("label"), QString("label1")); |
|
955 QCOMPARE(c.details(QContactNote::DefinitionName).value(0).value(QContactNote::FieldNote), QString("orange gypsum")); |
|
956 |
|
957 // test property remove |
|
958 QVERIFY(c.removeDetail(&n1)); |
|
959 QCOMPARE(c.details(QContactNote::DefinitionName).count(), 0); |
|
960 QVERIFY(c.saveDetail(&n2)); |
|
961 QCOMPARE(c.details(QContactNote::DefinitionName).count(), 1); |
|
962 QVERIFY(c.removeDetail(&n2)); |
|
963 QCOMPARE(c.details(QContactNote::DefinitionName).count(), 0); |
|
964 QVERIFY(c.removeDetail(&n2) == false); |
|
965 QCOMPARE(c.details(QContactNote::DefinitionName).count(), 0); |
|
966 } |
|
967 |
|
968 |
|
969 QTEST_MAIN(tst_QContactDetails) |
|
970 #include "tst_qcontactdetails.moc" |