|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 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 "qcontactid.h" |
|
46 #include <QSet> |
|
47 |
|
48 |
|
49 //TESTED_CLASS= |
|
50 //TESTED_FILES= |
|
51 |
|
52 QTM_USE_NAMESPACE |
|
53 class tst_QContact: public QObject |
|
54 { |
|
55 Q_OBJECT |
|
56 |
|
57 public: |
|
58 tst_QContact(); |
|
59 virtual ~tst_QContact(); |
|
60 |
|
61 private slots: |
|
62 void details(); |
|
63 void relationships(); |
|
64 void displayName(); |
|
65 void type(); |
|
66 void emptiness(); |
|
67 void idLessThan(); |
|
68 void idHash(); |
|
69 void hash(); |
|
70 void traits(); |
|
71 void idTraits(); |
|
72 void localIdTraits(); |
|
73 }; |
|
74 |
|
75 tst_QContact::tst_QContact() |
|
76 { |
|
77 } |
|
78 |
|
79 tst_QContact::~tst_QContact() |
|
80 { |
|
81 } |
|
82 |
|
83 void tst_QContact::details() |
|
84 { |
|
85 QContact c; |
|
86 |
|
87 // Test there are no details (apart from display label + type) by default |
|
88 QVERIFY(c.isEmpty() == true); |
|
89 QVERIFY(c.details().count() == 2); |
|
90 QVERIFY(c.details(QContactPhoneNumber::DefinitionName).count() == 0); |
|
91 QVERIFY(c.details<QContactPhoneNumber>().count() == 0); |
|
92 QVERIFY(c.detail(QContactPhoneNumber::DefinitionName).isEmpty()); |
|
93 QVERIFY(c.detail<QContactPhoneNumber>().isEmpty()); |
|
94 QVERIFY(c.details(QContactPhoneNumber::DefinitionName.latin1()).count() == 0); |
|
95 QVERIFY(c.detail(QContactPhoneNumber::DefinitionName.latin1()).isEmpty()); |
|
96 QVERIFY(c.details(QLatin1String(QContactPhoneNumber::DefinitionName)).count() == 0); |
|
97 QVERIFY(c.detail(QLatin1String(QContactPhoneNumber::DefinitionName)).isEmpty()); |
|
98 |
|
99 // Test retrieving the first detail (the display label) |
|
100 QList<QContactDetail> details = c.details(QString()); |
|
101 QVERIFY(details.at(0).definitionName() == QContactDisplayLabel::DefinitionName); |
|
102 QVERIFY(details.at(1).definitionName() == QContactType::DefinitionName); |
|
103 |
|
104 QContactDetail detail = c.detail("nonexistent"); |
|
105 QVERIFY(detail.isEmpty()); |
|
106 QVERIFY(detail.definitionName().isEmpty()); |
|
107 |
|
108 // retrieve the first detail using the empty definition name accessor. |
|
109 detail = c.detail(QString()); |
|
110 QVERIFY(detail == details.at(0)); |
|
111 |
|
112 QVERIFY(c.details("nonexistent").count() == 0); |
|
113 |
|
114 // Add a detail |
|
115 QContactPhoneNumber p; |
|
116 p.setNumber("12345678"); |
|
117 QVERIFY(c.saveDetail(&p)); |
|
118 QVERIFY(c.isEmpty() == false); |
|
119 |
|
120 QVERIFY(c.details().count() == 3); |
|
121 |
|
122 QVERIFY(c.details(QContactPhoneNumber::DefinitionName).count() == 1); |
|
123 QVERIFY(c.details(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber, QString("12345678")).count() == 1); |
|
124 QVERIFY(c.details(QContactPhoneNumber::DefinitionName, QString(), QString("12345678")).count() == c.details(QContactPhoneNumber::DefinitionName).count()); |
|
125 |
|
126 QVERIFY(c.details(QLatin1String(QContactPhoneNumber::DefinitionName)).count() == 1); |
|
127 QVERIFY(c.details(QLatin1String(QContactPhoneNumber::DefinitionName), QContactPhoneNumber::FieldNumber, QString("12345678")).count() == 1); |
|
128 QVERIFY(c.details(QLatin1String(QContactPhoneNumber::DefinitionName), QString(), QString("12345678")).count() == c.details(QContactPhoneNumber::DefinitionName).count()); |
|
129 |
|
130 QVERIFY(c.details(QContactPhoneNumber::DefinitionName.latin1()).count() == 1); |
|
131 QVERIFY(c.details(QContactPhoneNumber::DefinitionName.latin1(), QContactPhoneNumber::FieldNumber, QString("12345678")).count() == 1); |
|
132 QVERIFY(c.details(QContactPhoneNumber::DefinitionName.latin1(), QString(), QString("12345678")).count() == c.details(QContactPhoneNumber::DefinitionName).count()); |
|
133 |
|
134 QVERIFY(c.details<QContactPhoneNumber>(QContactPhoneNumber::FieldNumber, QString("12345678")).count() == 1); |
|
135 QVERIFY(c.details<QContactPhoneNumber>(QContactPhoneNumber::FieldNumber.latin1(), QString("12345678")).count() == 1); |
|
136 QVERIFY(c.details<QContactPhoneNumber>(QLatin1String(QContactPhoneNumber::FieldNumber), QString("12345678")).count() == 1); |
|
137 |
|
138 QVERIFY(c.details<QContactPhoneNumber>().count() == 1); |
|
139 QVERIFY(!c.detail(QContactPhoneNumber::DefinitionName).isEmpty()); |
|
140 QVERIFY(!c.detail<QContactPhoneNumber>().isEmpty()); |
|
141 QCOMPARE(c.detail<QContactPhoneNumber>(), p); |
|
142 |
|
143 // Remove detail |
|
144 QVERIFY(c.removeDetail(&p)); |
|
145 QVERIFY(c.details().count() == 2); |
|
146 QVERIFY(c.isEmpty() == true); |
|
147 QVERIFY(c.details(QContactPhoneNumber::DefinitionName).count() == 0); |
|
148 QVERIFY(c.details(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber, QString("12345678")).count() == 0); |
|
149 QVERIFY(c.details(QContactPhoneNumber::DefinitionName, QString(), QString("12345678")).count() == c.details(QContactPhoneNumber::DefinitionName).count()); |
|
150 QVERIFY(c.details<QContactPhoneNumber>().count() == 0); |
|
151 QVERIFY(c.detail(QContactPhoneNumber::DefinitionName).isEmpty()); |
|
152 QVERIFY(c.detail<QContactPhoneNumber>().isEmpty()); |
|
153 |
|
154 // Try removing it again |
|
155 QVERIFY(!c.removeDetail(&p)); |
|
156 |
|
157 // Add again, and remove a different way (retrieved copy) |
|
158 QVERIFY(c.saveDetail(&p)); |
|
159 QVERIFY(c.isEmpty() == false); |
|
160 QVERIFY(c.details().count() == 3); |
|
161 QContactPhoneNumber p2 = c.detail(QContactPhoneNumber::DefinitionName); |
|
162 QCOMPARE(p, p2); |
|
163 |
|
164 QVERIFY(c.removeDetail(&p2)); |
|
165 QVERIFY(c.details().count() == 2); |
|
166 QVERIFY(c.isEmpty() == true); |
|
167 QVERIFY(c.details(QContactPhoneNumber::DefinitionName).count() == 0); |
|
168 QVERIFY(c.details(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber, QString("12345678")).count() == 0); |
|
169 QVERIFY(c.details(QContactPhoneNumber::DefinitionName, QString(), QString("12345678")).count() == c.details(QContactPhoneNumber::DefinitionName).count()); |
|
170 QVERIFY(c.details<QContactPhoneNumber>().count() == 0); |
|
171 QVERIFY(c.detail(QContactPhoneNumber::DefinitionName).isEmpty()); |
|
172 QVERIFY(c.detail<QContactPhoneNumber>().isEmpty()); |
|
173 |
|
174 QCOMPARE(p, p2); |
|
175 |
|
176 // Add again again, and remove a different way (base class) |
|
177 QVERIFY(c.saveDetail(&p)); |
|
178 QVERIFY(c.details().count() == 3); |
|
179 QContactDetail p3 = c.detail(QContactPhoneNumber::DefinitionName); |
|
180 QVERIFY(p == p3); |
|
181 |
|
182 QVERIFY(c.removeDetail(&p3)); |
|
183 QVERIFY(c.details().count() == 2); |
|
184 QVERIFY(c.details(QContactPhoneNumber::DefinitionName).count() == 0); |
|
185 QVERIFY(c.details(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber, QString("12345678")).count() == 0); |
|
186 QVERIFY(c.details(QContactPhoneNumber::DefinitionName, QString(), QString("12345678")).count() == c.details(QContactPhoneNumber::DefinitionName).count()); |
|
187 QVERIFY(c.details<QContactPhoneNumber>().count() == 0); |
|
188 QVERIFY(c.detail(QContactPhoneNumber::DefinitionName).isEmpty()); |
|
189 QVERIFY(c.detail<QContactPhoneNumber>().isEmpty()); |
|
190 |
|
191 QVERIFY(p == p3); |
|
192 |
|
193 // now we want to add multiple details of the same type, and test that retrieval works correctly. |
|
194 p2 = QContactPhoneNumber(); |
|
195 p2.setNumber("22222"); |
|
196 p2.setValue("nonexistent-field", QVariant("22222-2")); |
|
197 c.saveDetail(&p); |
|
198 c.saveDetail(&p2); |
|
199 QVERIFY(c.details().count() == 4); |
|
200 QVERIFY(c.details(QContactPhoneNumber::DefinitionName).count() == 2); |
|
201 QVERIFY(c.details(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber, QString("12345678")).count() == 1); |
|
202 QVERIFY(c.details(QContactPhoneNumber::DefinitionName, QString(), QString("12345678")).count() == c.details(QContactPhoneNumber::DefinitionName).count()); |
|
203 QVERIFY(c.details<QContactPhoneNumber>().count() == 2); |
|
204 QVERIFY(!c.detail(QContactPhoneNumber::DefinitionName).isEmpty()); |
|
205 QVERIFY(!c.detail<QContactPhoneNumber>().isEmpty()); |
|
206 QCOMPARE(c.detail<QContactPhoneNumber>(), p); |
|
207 QVERIFY(c.removeDetail(&p2)); |
|
208 |
|
209 // Now try adding a detail to multiple contacts |
|
210 |
|
211 QContact c2; |
|
212 QVERIFY(c2.isEmpty() == true); |
|
213 QVERIFY(c.saveDetail(&p)); |
|
214 QVERIFY(c2.saveDetail(&p)); |
|
215 QVERIFY(c2.isEmpty() == false); |
|
216 |
|
217 QVERIFY(c.details().count() == 3); |
|
218 QVERIFY(c.details(QContactPhoneNumber::DefinitionName).count() == 1); |
|
219 QVERIFY(c.details<QContactPhoneNumber>().count() == 1); |
|
220 QVERIFY(!c.detail(QContactPhoneNumber::DefinitionName).isEmpty()); |
|
221 QVERIFY(!c.detail<QContactPhoneNumber>().isEmpty()); |
|
222 QCOMPARE(c.detail<QContactPhoneNumber>(), p); |
|
223 |
|
224 QVERIFY(c2.details().count() == 3); |
|
225 QVERIFY(c2.details(QContactPhoneNumber::DefinitionName).count() == 1); |
|
226 QVERIFY(c2.details<QContactPhoneNumber>().count() == 1); |
|
227 QVERIFY(!c2.detail(QContactPhoneNumber::DefinitionName).isEmpty()); |
|
228 QVERIFY(!c2.detail<QContactPhoneNumber>().isEmpty()); |
|
229 QCOMPARE(c2.detail<QContactPhoneNumber>(), p); |
|
230 |
|
231 // Now try removing it from one |
|
232 QVERIFY(c.removeDetail(&p)); |
|
233 |
|
234 // Make sure it's gone from the first contact |
|
235 QVERIFY(c.isEmpty() == true); |
|
236 QVERIFY(c.details().count() == 2); |
|
237 QVERIFY(c.details(QContactPhoneNumber::DefinitionName).count() == 0); |
|
238 QVERIFY(c.details<QContactPhoneNumber>().count() == 0); |
|
239 QVERIFY(c.detail(QContactPhoneNumber::DefinitionName).isEmpty()); |
|
240 QVERIFY(c.detail<QContactPhoneNumber>().isEmpty()); |
|
241 |
|
242 // but not the second |
|
243 QVERIFY(c2.isEmpty() == false); |
|
244 QVERIFY(c2.details().count() == 3); |
|
245 QVERIFY(c2.details(QContactPhoneNumber::DefinitionName).count() == 1); |
|
246 QVERIFY(c2.details<QContactPhoneNumber>().count() == 1); |
|
247 QVERIFY(!c2.detail(QContactPhoneNumber::DefinitionName).isEmpty()); |
|
248 QVERIFY(!c2.detail<QContactPhoneNumber>().isEmpty()); |
|
249 QCOMPARE(c2.detail<QContactPhoneNumber>(), p); |
|
250 |
|
251 // Now remove it from the second as well |
|
252 QVERIFY(c2.removeDetail(&p)); |
|
253 |
|
254 // Make sure it's gone from both |
|
255 QVERIFY(c.details().count() == 2); |
|
256 QVERIFY(c.details(QContactPhoneNumber::DefinitionName).count() == 0); |
|
257 QVERIFY(c.details<QContactPhoneNumber>().count() == 0); |
|
258 QVERIFY(c.detail(QContactPhoneNumber::DefinitionName).isEmpty()); |
|
259 QVERIFY(c.detail<QContactPhoneNumber>().isEmpty()); |
|
260 |
|
261 QVERIFY(c2.details().count() == 2); |
|
262 QVERIFY(c2.details(QContactPhoneNumber::DefinitionName).count() == 0); |
|
263 QVERIFY(c2.details<QContactPhoneNumber>().count() == 0); |
|
264 QVERIFY(c2.detail(QContactPhoneNumber::DefinitionName).isEmpty()); |
|
265 QVERIFY(c2.detail<QContactPhoneNumber>().isEmpty()); |
|
266 |
|
267 // add a, add b, remove a, add a, remove b, remove a |
|
268 QVERIFY(c.saveDetail(&p)); |
|
269 QVERIFY(c2.saveDetail(&p)); |
|
270 QVERIFY(c.removeDetail(&p)); |
|
271 QVERIFY(c.saveDetail(&p)); |
|
272 QVERIFY(c2.removeDetail(&p)); |
|
273 QVERIFY(c.removeDetail(&p)); |
|
274 |
|
275 // Now add a detail with the same values twice |
|
276 QContactPhoneNumber one; |
|
277 QContactPhoneNumber two; |
|
278 |
|
279 one.setNumber("12345"); |
|
280 two.setNumber("12345"); |
|
281 |
|
282 // add it once |
|
283 QVERIFY(c.saveDetail(&one)); |
|
284 QVERIFY(c.details().count() == 3); |
|
285 QVERIFY(c.details(QContactPhoneNumber::DefinitionName).count() == 1); |
|
286 QVERIFY(c.details<QContactPhoneNumber>().count() == 1); |
|
287 QVERIFY(!c.detail(QContactPhoneNumber::DefinitionName).isEmpty()); |
|
288 QVERIFY(!c.detail<QContactPhoneNumber>().isEmpty()); |
|
289 QCOMPARE(c.detail<QContactPhoneNumber>(), one); |
|
290 |
|
291 // add it twice |
|
292 QVERIFY(c.saveDetail(&two)); |
|
293 QVERIFY(c.details().count() == 4); |
|
294 QVERIFY(c.details(QContactPhoneNumber::DefinitionName).count() == 2); |
|
295 QVERIFY(c.details<QContactPhoneNumber>().count() == 2); |
|
296 QVERIFY(!c.detail(QContactPhoneNumber::DefinitionName).isEmpty()); |
|
297 QVERIFY(!c.detail<QContactPhoneNumber>().isEmpty()); |
|
298 QCOMPARE(c.detail<QContactPhoneNumber>(), one); |
|
299 QCOMPARE(c.details<QContactPhoneNumber>()[0], one); |
|
300 QCOMPARE(c.details<QContactPhoneNumber>()[1], two); |
|
301 |
|
302 // Remove it once |
|
303 QVERIFY(c.removeDetail(&one)); |
|
304 QVERIFY(c.details().count() == 3); |
|
305 QVERIFY(c.details(QContactPhoneNumber::DefinitionName).count() == 1); |
|
306 QVERIFY(c.details<QContactPhoneNumber>().count() == 1); |
|
307 QVERIFY(!c.detail(QContactPhoneNumber::DefinitionName).isEmpty()); |
|
308 QVERIFY(!c.detail<QContactPhoneNumber>().isEmpty()); |
|
309 QCOMPARE(c.detail<QContactPhoneNumber>(), two); |
|
310 |
|
311 // Remove it twice |
|
312 QVERIFY(c.removeDetail(&two)); |
|
313 QVERIFY(c.details().count() == 2); |
|
314 QVERIFY(c.details(QContactPhoneNumber::DefinitionName).count() == 0); |
|
315 QVERIFY(c.details<QContactPhoneNumber>().count() == 0); |
|
316 QVERIFY(c.detail(QContactPhoneNumber::DefinitionName).isEmpty()); |
|
317 QVERIFY(c.detail<QContactPhoneNumber>().isEmpty()); |
|
318 |
|
319 // Null pointer tests |
|
320 QVERIFY(c.saveDetail(0) == false); |
|
321 QVERIFY(c.removeDetail(0) == false); |
|
322 |
|
323 // Reference tests... |
|
324 QContactDetail& ref = one; |
|
325 QVERIFY(c.saveDetail(&one)); |
|
326 QVERIFY(ref == one); |
|
327 one.setNumber("56678"); |
|
328 QVERIFY(c.saveDetail(&one)); |
|
329 QVERIFY(ref == one); |
|
330 |
|
331 // Retrieve the detail again and modify it |
|
332 QContactPhoneNumber three = c.detail<QContactPhoneNumber>(); |
|
333 QVERIFY(ref == three); |
|
334 QVERIFY(one == three); |
|
335 three.setNumber("542343"); |
|
336 QVERIFY(c.saveDetail(&three)); |
|
337 |
|
338 // Now see if we got any updates to ref/one |
|
339 QVERIFY(ref == one); |
|
340 QVERIFY(ref != three); |
|
341 |
|
342 // test saving of a detail with an empty field. |
|
343 QContactPhoneNumber four; |
|
344 four.setNumber(""); |
|
345 c.saveDetail(&four); |
|
346 QVERIFY(c.details(QContactPhoneNumber::DefinitionName).count() == 2); |
|
347 QVERIFY(!four.variantValues().isEmpty()); // an empty qstring is not invalid; make sure it exists in the detail. |
|
348 |
|
349 // ensure that clearing a contact's details works correctly |
|
350 QContactName nameDetail; |
|
351 nameDetail.setCustomLabel("test"); |
|
352 c.saveDetail(&nameDetail); |
|
353 QCOMPARE(c.detail(QContactName::DefinitionName).value(QContactName::FieldCustomLabel), QString("test")); |
|
354 QVERIFY(c.details().size() > 0); |
|
355 QVERIFY(!c.isEmpty()); |
|
356 QContactId oldId = c.id(); |
|
357 c.clearDetails(); |
|
358 QVERIFY(c.details().size() == 2); // always has a display label and contact type. |
|
359 QCOMPARE(c.detail(QContactName::DefinitionName).value(QContactName::FieldCustomLabel), QString()); |
|
360 QVERIFY(c.isEmpty()); |
|
361 QCOMPARE(c.id(), oldId); // id shouldn't change. |
|
362 } |
|
363 |
|
364 void tst_QContact::relationships() |
|
365 { |
|
366 QContact c; |
|
367 |
|
368 // boring test, because the default contact has no relationships |
|
369 // we test this more convincingly in the QContactManager tests. |
|
370 QList<QContactId> related = c.relatedContacts(); |
|
371 QVERIFY(related.isEmpty()); |
|
372 |
|
373 related = c.relatedContacts(QContactRelationship::HasMember); |
|
374 QVERIFY(related.isEmpty()); |
|
375 |
|
376 related = c.relatedContacts(QContactRelationship::HasMember, QContactRelationship::First); |
|
377 QVERIFY(related.isEmpty()); |
|
378 |
|
379 QList<QContactRelationship> relationshipList = c.relationships(); |
|
380 QVERIFY(relationshipList.isEmpty()); |
|
381 |
|
382 relationshipList = c.relationships(QContactRelationship::HasMember); |
|
383 QVERIFY(relationshipList.isEmpty()); |
|
384 } |
|
385 |
|
386 void tst_QContact::displayName() |
|
387 { |
|
388 QContact c; |
|
389 QContactManager cm("memory"); // for formatting names |
|
390 |
|
391 QString label = c.displayLabel(); |
|
392 QVERIFY(label.isEmpty()); |
|
393 |
|
394 /* Try to make this a bit more consistent by using a single name */ |
|
395 QContact d; |
|
396 QContactName name; |
|
397 name.setCustomLabel("Wesley"); |
|
398 |
|
399 QVERIFY(d.displayLabel().isEmpty()); |
|
400 QVERIFY(d.saveDetail(&name)); |
|
401 |
|
402 /* |
|
403 * The display label is not updated until you save the contact or call synthCDL |
|
404 */ |
|
405 QVERIFY(d.displayLabel().isEmpty()); |
|
406 |
|
407 cm.synthesizeContactDisplayLabel(&d); |
|
408 QVERIFY(d.displayLabel() == "Wesley"); |
|
409 |
|
410 name.setCustomLabel("Bosley"); |
|
411 d.saveDetail(&name); |
|
412 |
|
413 QVERIFY(d.displayLabel() == "Wesley"); |
|
414 |
|
415 cm.synthesizeContactDisplayLabel(&d); |
|
416 QVERIFY(d.displayLabel() == "Bosley"); |
|
417 |
|
418 /* Remove the detail via removeDetail */ |
|
419 QContactDisplayLabel old; |
|
420 QVERIFY(d.details().count() == 3); |
|
421 QVERIFY(!d.removeDetail(&old)); // should fail. |
|
422 QVERIFY(d.isEmpty() == false); |
|
423 QVERIFY(d.details().count() == 3); // it should not be removed! |
|
424 |
|
425 /* Test self assign */ |
|
426 d.operator =(d); |
|
427 QVERIFY(d.details().count() == 3); |
|
428 QVERIFY(d.isEmpty() == false); |
|
429 } |
|
430 |
|
431 void tst_QContact::type() |
|
432 { |
|
433 QContact c; |
|
434 QVERIFY(c.isEmpty() == true); |
|
435 |
|
436 // ensure that the default type is the QContactType::TypeContact type |
|
437 QVERIFY(c.type() == QString(QLatin1String(QContactType::TypeContact))); |
|
438 |
|
439 // now set it to be a group via the type mutator, and test that it works |
|
440 QContactType groupType; |
|
441 groupType.setType(QString(QLatin1String(QContactType::TypeGroup))); |
|
442 c.setType(groupType); |
|
443 QVERIFY(c.type() == QString(QLatin1String(QContactType::TypeGroup))); |
|
444 |
|
445 // set it back to a contact, via the string mutator |
|
446 c.setType(QContactType::TypeContact); |
|
447 QVERIFY(c.type() == QString(QLatin1String(QContactType::TypeContact))); |
|
448 QVERIFY(c.isEmpty() == true); // type doesn't affect emptiness |
|
449 } |
|
450 |
|
451 void tst_QContact::emptiness() |
|
452 { |
|
453 QContact c; |
|
454 QVERIFY(c.isEmpty() == true); |
|
455 |
|
456 c.setType(QContactType::TypeContact); |
|
457 QVERIFY(c.type() == QString(QLatin1String(QContactType::TypeContact))); |
|
458 QVERIFY(c.isEmpty() == true); // type doesn't affect emptiness |
|
459 } |
|
460 |
|
461 void tst_QContact::idLessThan() |
|
462 { |
|
463 QContactId id1; |
|
464 id1.setManagerUri("a"); |
|
465 id1.setLocalId(1); |
|
466 QContactId id2; |
|
467 id2.setManagerUri("a"); |
|
468 id2.setLocalId(1); |
|
469 QVERIFY(!(id1 < id2)); |
|
470 QVERIFY(!(id2 < id1)); |
|
471 QContactId id3; |
|
472 id3.setManagerUri("a"); |
|
473 id3.setLocalId(2); |
|
474 QContactId id4; |
|
475 id4.setManagerUri("b"); |
|
476 id4.setLocalId(1); |
|
477 QContactId id5; // no URI |
|
478 id5.setLocalId(2); |
|
479 QVERIFY(id1 < id3); |
|
480 QVERIFY(!(id3 < id1)); |
|
481 QVERIFY(id1 < id4); |
|
482 QVERIFY(!(id4 < id1)); |
|
483 QVERIFY(id3 < id4); |
|
484 QVERIFY(!(id4 < id3)); |
|
485 QVERIFY(id5 < id1); |
|
486 QVERIFY(!(id1 < id5)); |
|
487 } |
|
488 |
|
489 void tst_QContact::idHash() |
|
490 { |
|
491 QContactId id1; |
|
492 id1.setManagerUri("a"); |
|
493 id1.setLocalId(1); |
|
494 QContactId id2; |
|
495 id2.setManagerUri("a"); |
|
496 id2.setLocalId(1); |
|
497 QContactId id3; |
|
498 id3.setManagerUri("b"); |
|
499 id3.setLocalId(1); |
|
500 QVERIFY(qHash(id1) == qHash(id2)); |
|
501 QVERIFY(qHash(id1) != qHash(id3)); |
|
502 QSet<QContactId> set; |
|
503 set.insert(id1); |
|
504 set.insert(id2); |
|
505 set.insert(id3); |
|
506 QCOMPARE(set.size(), 2); |
|
507 } |
|
508 |
|
509 void tst_QContact::hash() |
|
510 { |
|
511 QContactId id; |
|
512 id.setManagerUri("a"); |
|
513 id.setLocalId(1); |
|
514 QContact contact1; |
|
515 contact1.setId(id); |
|
516 QContactDetail detail1("definition"); |
|
517 detail1.setValue("key", "value"); |
|
518 contact1.saveDetail(&detail1); |
|
519 QContact contact2; |
|
520 contact2.setId(id); |
|
521 contact2.saveDetail(&detail1); |
|
522 QContact contact3; |
|
523 contact3.setId(id); |
|
524 QContactDetail detail3("definition"); |
|
525 detail3.setValue("key", "another value"); |
|
526 contact3.saveDetail(&detail3); |
|
527 QContact contact4; // no details |
|
528 contact4.setId(id); |
|
529 QContact contact5; // preferred details and relationships shouldn't affect the hash |
|
530 contact5.setId(id); |
|
531 contact5.saveDetail(&detail1); |
|
532 QContactRelationship rel; |
|
533 QContactManagerEngine::setContactRelationships(&contact5, QList<QContactRelationship>() << rel); |
|
534 QVERIFY(qHash(contact1) == qHash(contact2)); |
|
535 QVERIFY(qHash(contact1) != qHash(contact3)); |
|
536 QVERIFY(qHash(contact1) != qHash(contact4)); |
|
537 QVERIFY(qHash(contact1) == qHash(contact5)); |
|
538 } |
|
539 |
|
540 void tst_QContact::traits() |
|
541 { |
|
542 QVERIFY(sizeof(QContact) == sizeof(void *)); |
|
543 QTypeInfo<QTM_PREPEND_NAMESPACE(QContact)> ti; |
|
544 QVERIFY(ti.isComplex); |
|
545 QVERIFY(!ti.isStatic); |
|
546 QVERIFY(!ti.isLarge); |
|
547 QVERIFY(!ti.isPointer); |
|
548 QVERIFY(!ti.isDummy); |
|
549 } |
|
550 |
|
551 void tst_QContact::idTraits() |
|
552 { |
|
553 QVERIFY(sizeof(QContactId) == sizeof(void *)); |
|
554 QTypeInfo<QTM_PREPEND_NAMESPACE(QContactId)> ti; |
|
555 QVERIFY(ti.isComplex); |
|
556 QVERIFY(!ti.isStatic); |
|
557 QVERIFY(!ti.isLarge); |
|
558 QVERIFY(!ti.isPointer); |
|
559 QVERIFY(!ti.isDummy); |
|
560 } |
|
561 |
|
562 void tst_QContact::localIdTraits() |
|
563 { |
|
564 QVERIFY(sizeof(QContactId) == sizeof(void *)); |
|
565 QTypeInfo<QTM_PREPEND_NAMESPACE(QContactLocalId)> ti; |
|
566 QVERIFY(!ti.isComplex); |
|
567 QVERIFY(!ti.isStatic); |
|
568 QVERIFY(!ti.isLarge); |
|
569 QVERIFY(!ti.isPointer); |
|
570 QVERIFY(!ti.isDummy); |
|
571 } |
|
572 |
|
573 |
|
574 QTEST_MAIN(tst_QContact) |
|
575 #include "tst_qcontact.moc" |