1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the test suite of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
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 Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
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 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
42
#include <QtTest/QtTest>
43
#include <qcontacts.h>
45
#include "../qcontactidmock.h"
47
//TESTED_COMPONENT=src/contacts
49
QTCONTACTS_USE_NAMESPACE
51
class tst_QContact: public QObject
57
virtual ~tst_QContact();
74
void preferredDetails();
77
tst_QContact::tst_QContact()
81
tst_QContact::~tst_QContact()
85
void tst_QContact::details()
87
// Check that detail keys are unique, regardless of order of initialisation
88
// First, construct the detail first, then the contact
89
QContactOrganization org;
90
org.setTitle("Example Title");
92
QVERIFY(keyTest.saveDetail(&org));
93
QList<QContactDetail> allDetails = keyTest.details();
94
QList<int> detailKeys;
95
foreach (const QContactDetail& det, allDetails) {
96
int currKey = det.key();
97
QVERIFY(!detailKeys.contains(currKey));
98
detailKeys.append(currKey);
100
// Second, construct the detail after the contact has been constructed
101
QContactPhoneNumber num;
102
num.setNumber("123456");
103
QVERIFY(keyTest.saveDetail(&num));
104
allDetails = keyTest.details();
106
foreach (const QContactDetail& det, allDetails) {
107
int currKey = det.key();
108
QVERIFY(!detailKeys.contains(currKey));
109
detailKeys.append(currKey);
112
// now test for default construction sanity
115
// Test there are no details (apart from type) by default
116
QVERIFY(c.isEmpty() == true);
117
QVERIFY(c.details().count() == 1);
118
QVERIFY(c.details(QContactPhoneNumber::Type).count() == 0);
119
QVERIFY(c.details<QContactPhoneNumber>().count() == 0);
120
QVERIFY(c.detail(QContactPhoneNumber::Type).isEmpty());
121
QVERIFY(c.detail<QContactPhoneNumber>().isEmpty());
122
QVERIFY(c.details(QContactPhoneNumber::Type).count() == 0);
123
QVERIFY(c.detail(QContactPhoneNumber::Type).isEmpty());
124
QVERIFY(c.details(QContactPhoneNumber::Type).count() == 0);
125
QVERIFY(c.detail(QContactPhoneNumber::Type).isEmpty());
127
// Test retrieving the first detail (the contact type)
128
QList<QContactDetail> details = c.details();
129
QVERIFY(details.at(0).type() == QContactType::Type);
131
// Fetch non existent detail
132
QContactDetail detail = c.detail(QContactDetail::TypeAddress);
134
QVERIFY(detail.isEmpty());
135
QVERIFY(detail.type() == QContactDetail::TypeUndefined);
137
// retrieve the first detail using the undefined type accessor.
138
detail = c.detail(QContactDetail::TypeUndefined);
139
QVERIFY(detail == details.at(0));
141
QVERIFY(c.details(QContactDetail::TypeAddress).count() == 0);
144
QContactPhoneNumber p;
145
p.setNumber("12345678");
146
QVERIFY(c.saveDetail(&p));
147
QVERIFY(c.isEmpty() == false);
149
QVERIFY(c.details().count() == 2);
151
QVERIFY(c.details(QContactPhoneNumber::Type).count() == 1);
152
QVERIFY(c.details<QContactPhoneNumber>().count() == 1);
153
QVERIFY(!c.detail(QContactPhoneNumber::Type).isEmpty());
154
QVERIFY(!c.detail<QContactPhoneNumber>().isEmpty());
155
QCOMPARE(c.detail<QContactPhoneNumber>(), p);
158
QVERIFY(c.removeDetail(&p));
159
QVERIFY(c.details().count() == 1);
160
QVERIFY(c.isEmpty() == true);
161
QVERIFY(c.details(QContactPhoneNumber::Type).count() == 0);
162
QVERIFY(c.details<QContactPhoneNumber>().count() == 0);
163
QVERIFY(c.detail(QContactPhoneNumber::Type).isEmpty());
164
QVERIFY(c.detail<QContactPhoneNumber>().isEmpty());
166
// Try removing it again
167
QVERIFY(!c.removeDetail(&p));
169
// Add again, and remove a different way (retrieved copy)
170
QVERIFY(c.saveDetail(&p));
171
QVERIFY(c.isEmpty() == false);
172
QVERIFY(c.details().count() == 2);
173
QContactPhoneNumber p2 = c.detail(QContactPhoneNumber::Type);
176
QVERIFY(c.removeDetail(&p2));
177
QVERIFY(c.details().count() == 1);
178
QVERIFY(c.isEmpty() == true);
179
QVERIFY(c.details(QContactPhoneNumber::Type).count() == 0);
180
QVERIFY(c.details<QContactPhoneNumber>().count() == 0);
181
QVERIFY(c.detail(QContactPhoneNumber::Type).isEmpty());
182
QVERIFY(c.detail<QContactPhoneNumber>().isEmpty());
186
// Add again again, and remove a different way (base class)
187
QVERIFY(c.saveDetail(&p));
188
QVERIFY(c.details().count() == 2);
189
QContactDetail p3 = c.detail(QContactPhoneNumber::Type);
192
QVERIFY(c.removeDetail(&p3));
193
QVERIFY(c.details().count() == 1);
194
QVERIFY(c.details(QContactPhoneNumber::Type).count() == 0);
195
QVERIFY(c.details<QContactPhoneNumber>().count() == 0);
196
QVERIFY(c.detail(QContactPhoneNumber::Type).isEmpty());
197
QVERIFY(c.detail<QContactPhoneNumber>().isEmpty());
201
// now we want to add multiple details of the same type, and test that retrieval works correctly.
202
p2 = QContactPhoneNumber();
203
p2.setNumber("22222");
206
QVERIFY(c.details().count() == 3);
207
QVERIFY(c.details(QContactPhoneNumber::Type).count() == 2);
208
QVERIFY(c.details<QContactPhoneNumber>().count() == 2);
209
QVERIFY(!c.detail(QContactPhoneNumber::Type).isEmpty());
210
QVERIFY(!c.detail<QContactPhoneNumber>().isEmpty());
211
QCOMPARE(c.detail<QContactPhoneNumber>(), p);
212
QVERIFY(c.removeDetail(&p2));
214
// now try removing a detail for which we've set a preference
215
QContactEmailAddress pref;
216
pref.setEmailAddress("test@test");
218
c.setPreferredDetail("SendEmail", pref);
219
QVERIFY(c.isPreferredDetail(QString(), pref));
220
QVERIFY(c.removeDetail(&pref));
221
QVERIFY(!c.isPreferredDetail(QString(), pref));
223
// Now try adding a detail to multiple contacts
226
QVERIFY(c2.isEmpty() == true);
227
QVERIFY(c.saveDetail(&p));
228
QVERIFY(c2.saveDetail(&p));
229
QVERIFY(c2.isEmpty() == false);
231
QVERIFY(c.details().count() == 2);
232
QVERIFY(c.details(QContactPhoneNumber::Type).count() == 1);
233
QVERIFY(c.details<QContactPhoneNumber>().count() == 1);
234
QVERIFY(!c.detail(QContactPhoneNumber::Type).isEmpty());
235
QVERIFY(!c.detail<QContactPhoneNumber>().isEmpty());
236
QCOMPARE(c.detail<QContactPhoneNumber>(), p);
238
QVERIFY(c2.details().count() == 2);
239
QVERIFY(c2.details(QContactPhoneNumber::Type).count() == 1);
240
QVERIFY(c2.details<QContactPhoneNumber>().count() == 1);
241
QVERIFY(!c2.detail(QContactPhoneNumber::Type).isEmpty());
242
QVERIFY(!c2.detail<QContactPhoneNumber>().isEmpty());
243
QCOMPARE(c2.detail<QContactPhoneNumber>(), p);
245
// Now try removing it from one
246
QVERIFY(c.removeDetail(&p));
248
// Make sure it's gone from the first contact
249
QVERIFY(c.isEmpty() == true);
250
QVERIFY(c.details().count() == 1);
251
QVERIFY(c.details(QContactPhoneNumber::Type).count() == 0);
252
QVERIFY(c.details<QContactPhoneNumber>().count() == 0);
253
QVERIFY(c.detail(QContactPhoneNumber::Type).isEmpty());
254
QVERIFY(c.detail<QContactPhoneNumber>().isEmpty());
256
// but not the second
257
QVERIFY(c2.isEmpty() == false);
258
QVERIFY(c2.details().count() == 2);
259
QVERIFY(c2.details(QContactPhoneNumber::Type).count() == 1);
260
QVERIFY(c2.details<QContactPhoneNumber>().count() == 1);
261
QVERIFY(!c2.detail(QContactPhoneNumber::Type).isEmpty());
262
QVERIFY(!c2.detail<QContactPhoneNumber>().isEmpty());
263
QCOMPARE(c2.detail<QContactPhoneNumber>(), p);
265
// Now remove it from the second as well
266
QVERIFY(c2.removeDetail(&p));
268
// Make sure it's gone from both
269
QVERIFY(c.details().count() == 1);
270
QVERIFY(c.details(QContactPhoneNumber::Type).count() == 0);
271
QVERIFY(c.details<QContactPhoneNumber>().count() == 0);
272
QVERIFY(c.detail(QContactPhoneNumber::Type).isEmpty());
273
QVERIFY(c.detail<QContactPhoneNumber>().isEmpty());
275
QVERIFY(c2.details().count() == 1);
276
QVERIFY(c2.details(QContactPhoneNumber::Type).count() == 0);
277
QVERIFY(c2.details<QContactPhoneNumber>().count() == 0);
278
QVERIFY(c2.detail(QContactPhoneNumber::Type).isEmpty());
279
QVERIFY(c2.detail<QContactPhoneNumber>().isEmpty());
281
// add a, add b, remove a, add a, remove b, remove a
282
QVERIFY(c.saveDetail(&p));
283
QVERIFY(c2.saveDetail(&p));
284
QVERIFY(c.removeDetail(&p));
285
QVERIFY(c.saveDetail(&p));
286
QVERIFY(c2.removeDetail(&p));
287
QVERIFY(c.removeDetail(&p));
289
// Now add a detail with the same values twice
290
QContactPhoneNumber one;
291
QContactPhoneNumber two;
293
one.setNumber("12345");
294
two.setNumber("12345");
297
QVERIFY(c.saveDetail(&one));
298
QVERIFY(c.details().count() == 2);
299
QVERIFY(c.details(QContactPhoneNumber::Type).count() == 1);
300
QVERIFY(c.details<QContactPhoneNumber>().count() == 1);
301
QVERIFY(!c.detail(QContactPhoneNumber::Type).isEmpty());
302
QVERIFY(!c.detail<QContactPhoneNumber>().isEmpty());
303
QCOMPARE(c.detail<QContactPhoneNumber>(), one);
306
QVERIFY(c.saveDetail(&two));
307
QVERIFY(c.details().count() == 3);
308
QVERIFY(c.details(QContactPhoneNumber::Type).count() == 2);
309
QVERIFY(c.details<QContactPhoneNumber>().count() == 2);
310
QVERIFY(!c.detail(QContactPhoneNumber::Type).isEmpty());
311
QVERIFY(!c.detail<QContactPhoneNumber>().isEmpty());
312
QCOMPARE(c.detail<QContactPhoneNumber>(), one);
313
QCOMPARE(c.details<QContactPhoneNumber>()[0], one);
314
QCOMPARE(c.details<QContactPhoneNumber>()[1], two);
317
QVERIFY(c.removeDetail(&one));
318
QVERIFY(c.details().count() == 2);
319
QVERIFY(c.details(QContactPhoneNumber::Type).count() == 1);
320
QVERIFY(c.details<QContactPhoneNumber>().count() == 1);
321
QVERIFY(!c.detail(QContactPhoneNumber::Type).isEmpty());
322
QVERIFY(!c.detail<QContactPhoneNumber>().isEmpty());
323
QCOMPARE(c.detail<QContactPhoneNumber>(), two);
326
QVERIFY(c.removeDetail(&two));
327
QVERIFY(c.details().count() == 1);
328
QVERIFY(c.details(QContactPhoneNumber::Type).count() == 0);
329
QVERIFY(c.details<QContactPhoneNumber>().count() == 0);
330
QVERIFY(c.detail(QContactPhoneNumber::Type).isEmpty());
331
QVERIFY(c.detail<QContactPhoneNumber>().isEmpty());
333
// Null pointer tests
334
QVERIFY(c.saveDetail(0) == false);
335
QVERIFY(c.removeDetail(0) == false);
337
// Reference tests...
338
QContactDetail& ref = one;
339
QVERIFY(c.saveDetail(&one));
341
one.setNumber("56678");
342
QVERIFY(c.saveDetail(&one));
345
// Retrieve the detail again and modify it
346
QContactPhoneNumber three = c.detail<QContactPhoneNumber>();
347
QVERIFY(ref == three);
348
QVERIFY(one == three);
349
three.setNumber("542343");
350
QVERIFY(c.saveDetail(&three));
352
// Now see if we got any updates to ref/one
354
QVERIFY(ref != three);
356
// test saving of a detail with an empty field.
357
QContactPhoneNumber four;
360
QVERIFY(c.details(QContactPhoneNumber::Type).count() == 2);
361
QVERIFY(!four.values().isEmpty()); // an empty qstring is not invalid; make sure it exists in the detail.
363
// ensure that clearing a contact's details works correctly
364
QContactName nameDetail;
365
nameDetail.setFirstName("test");
366
c.saveDetail(&nameDetail);
367
QCOMPARE(c.detail(QContactName::Type).value(QContactName::FieldFirstName).toString(), QString("test"));
368
QVERIFY(c.details().size() > 0);
369
QVERIFY(!c.isEmpty());
370
QContactId oldId = c.id();
372
QVERIFY(c.details().size() == 1); // contact type.
373
QCOMPARE(c.detail(QContactName::Type).value(QContactName::FieldFirstName).toString(), QString());
374
QVERIFY(c.isEmpty());
375
QCOMPARE(c.id(), oldId); // id shouldn't change.
378
void tst_QContact::preferences()
383
QContactDetail det(QContactDetail::TypeExtendedDetail);
385
QCOMPARE(c.isPreferredDetail("testAction", det), false);
387
QCOMPARE(c.setPreferredDetail("testAction", det), true);
389
QCOMPARE(c.isPreferredDetail("testAction", det), true);
391
QCOMPARE(c.isPreferredDetail(QString(), det), true);
393
QCOMPARE(c.preferredDetail("testAction"), det);
396
QContactDetail det2(QContactDetail::TypeExtendedDetail);
398
QCOMPARE(c.isPreferredDetail("testAction", det2), false);
400
QCOMPARE(c.setPreferredDetail("testAction", det2), true);
402
QCOMPARE(c.isPreferredDetail("testAction", det2), true);
404
QCOMPARE(c.isPreferredDetail("testAction", det), false);
406
QCOMPARE(c.preferredDetail("testAction"), det2);
408
// test for detail that is not part of the contact
409
QContactDetail det3(QContactDetail::TypeEmailAddress);
410
QCOMPARE(c.setPreferredDetail("testAction", det3), false);
412
QCOMPARE(c.preferredDetail("testAction"), det2); // shouldn't have changed.
415
QCOMPARE(c.setPreferredDetail(QString(), det3), false);
417
QCOMPARE(c.setPreferredDetail(QString(), QContactDetail()), false);
419
QCOMPARE(c.setPreferredDetail("testAction", QContactDetail()), false);
421
QCOMPARE(c.preferredDetail("testAction"), det2); // shouldn't have changed.
423
// test invalid query
426
QCOMPARE(c.isPreferredDetail(QString(), QContactDetail()), false);
428
QCOMPARE(c.isPreferredDetail(QString(), det4), false); // valid detail, but no pref set.
430
QCOMPARE(c.isPreferredDetail("testAction", QContactDetail()), false);
432
// test retrieving preferred details
433
QContactDetail pd = c.preferredDetail(QString());
434
QVERIFY(pd.isEmpty());
435
pd = c.preferredDetail("testAction");
436
QVERIFY(pd == det2); // shouldn't have changed.
438
// test for preference for action that hasn't been added
439
QVERIFY(c.preferredDetail("NonexistentAction").isEmpty());
441
// Remove a non preferred detail
442
QContactDetail det2copy(QContactDetail::TypeExtendedDetail);
443
QVERIFY(c.saveDetail(&det2copy));
445
QVERIFY(c.isPreferredDetail("testAction", det2) == true);
446
QVERIFY(c.isPreferredDetail("testAction", det2copy) == false);
447
QVERIFY(c.removeDetail(&det2copy));
448
QVERIFY(c.isPreferredDetail("testAction", det2) == true);
449
QVERIFY(c.isPreferredDetail("testAction", det2copy) == false);
452
QVERIFY(c.saveDetail(&det2copy));
453
QVERIFY(c.isPreferredDetail("testAction", det2) == true);
454
QVERIFY(c.isPreferredDetail("testAction", det2copy) == false);
456
// Remove the preferred detail (the copy should not become preferred)
457
QVERIFY(c.removeDetail(&det2));
458
QVERIFY(c.isPreferredDetail("testAction", det2) == false);
459
QVERIFY(c.isPreferredDetail("testAction", det2copy) == false);
462
void tst_QContact::relationships()
466
// boring test, because the default contact has no relationships
467
// we test this more convincingly in the QContactManager tests.
468
QList<QContact> related = c.relatedContacts();
469
QVERIFY(related.isEmpty());
471
related = c.relatedContacts(QContactRelationship::HasMember());
472
QVERIFY(related.isEmpty());
474
related = c.relatedContacts(QContactRelationship::HasMember(), QContactRelationship::First);
475
QVERIFY(related.isEmpty());
477
QList<QContactRelationship> relationshipList = c.relationships();
478
QVERIFY(relationshipList.isEmpty());
480
relationshipList = c.relationships(QContactRelationship::HasMember());
481
QVERIFY(relationshipList.isEmpty());
484
void tst_QContact::type()
487
QVERIFY(c.isEmpty() == true);
489
// ensure that the default type is the QContactType::TypeContact type
490
QVERIFY(c.type() == QContactType::TypeContact);
492
// now set it to be a group via the type mutator, and test that it works
493
c.setType(QContactType::TypeGroup);
494
QCOMPARE(c.type(), QContactType::TypeGroup);
496
// set it back to a contact, via the string mutator
497
c.setType(QContactType::TypeContact);
498
QCOMPARE(c.type(), QContactType::TypeContact);
499
QVERIFY(c.isEmpty() == true); // type doesn't affect emptiness
502
void tst_QContact::tags()
505
QVERIFY(c.tags().isEmpty());
509
tags.append("tag 1");
510
QCOMPARE(c.tags(), tags);
511
QList<QContactTag> tagDetails = c.details<QContactTag>();
512
QCOMPARE(tagDetails.size(), 1);
513
QCOMPARE(tagDetails.first().tag(), QStringLiteral("tag 1"));
516
QVERIFY(c.tags().isEmpty());
517
QVERIFY(c.details<QContactTag>().isEmpty());
519
tags.append("tag 2"); // tags is now "tag 1", "tag 2"
521
QCOMPARE(c.tags(), tags);
522
tagDetails = c.details<QContactTag>();
523
QCOMPARE(tagDetails.size(), 2);
524
QCOMPARE(tagDetails.at(0).tag(), QStringLiteral("tag 1"));
525
QCOMPARE(tagDetails.at(1).tag(), QStringLiteral("tag 2"));
528
void tst_QContact::emptiness()
531
QVERIFY(c.isEmpty() == true);
532
c.setType(QContactType::TypeContact);
533
QVERIFY(c.type() == QContactType::TypeContact);
534
QVERIFY(c.isEmpty() == true); // type doesn't affect emptiness
537
void tst_QContact::idLessThan()
539
QContactId id1 = QContactIdMock::createId("a", 1);
540
QContactId id2 = QContactIdMock::createId("a", 1);
541
QVERIFY(!(id1 < id2));
542
QVERIFY(!(id2 < id1));
543
QContactId id3 = QContactIdMock::createId("a", 2);
544
QContactId id4 = QContactIdMock::createId("b", 1);
545
QContactId id5 = QContactIdMock::createId("", 2);
547
QVERIFY(!(id3 < id1));
549
QVERIFY(!(id4 < id1));
551
QVERIFY(!(id4 < id3));
553
QVERIFY(!(id1 < id5));
556
void tst_QContact::idHash()
558
QContactId id1 = QContactIdMock::createId("a", 1);
559
QContactId id2 = QContactIdMock::createId("a", 1);
560
QContactId id3 = QContactIdMock::createId("b", 1);
561
QVERIFY(qHash(id1) == qHash(id2));
562
QVERIFY(qHash(id1) != qHash(id3));
563
QSet<QContactId> set;
567
QCOMPARE(set.size(), 2);
570
void tst_QContact::hash()
572
QContactId id = QContactIdMock::createId("a", 1);
575
QContactDetail detail1(QContactDetail::TypeExtendedDetail);
576
detail1.setValue(QContactDetail::FieldContext, "value");
577
contact1.saveDetail(&detail1);
580
contact2.saveDetail(&detail1);
583
QContactDetail detail3(QContactDetail::TypeExtendedDetail);
584
detail3.setValue(QContactDetail::FieldContext, "another value");
585
contact3.saveDetail(&detail3);
586
QContact contact4; // no details
588
QContact contact5; // preferred details and relationships shouldn't affect the hash
590
contact5.saveDetail(&detail1);
591
contact5.setPreferredDetail("action", detail1);
592
QContactRelationship rel;
593
QContactManagerEngine::setContactRelationships(&contact5, QList<QContactRelationship>() << rel);
594
QVERIFY(qHash(contact1) == qHash(contact2));
595
QVERIFY(qHash(contact1) != qHash(contact3));
596
QVERIFY(qHash(contact1) != qHash(contact4));
597
QVERIFY(qHash(contact1) == qHash(contact5));
600
void tst_QContact::datastream()
603
QDataStream stream1(&buffer, QIODevice::WriteOnly);
605
QContactId id = QContactIdMock::createId("manager", 1234);
607
QContactPhoneNumber phone;
608
phone.setNumber("5678");
609
contactIn.saveDetail(&phone);
610
stream1 << contactIn;
612
QVERIFY(buffer.size() > 0);
615
QDataStream stream2(buffer);
617
stream2 >> contactOut;
618
QCOMPARE(contactOut, contactIn);*/
621
void tst_QContact::traits()
623
QVERIFY(sizeof(QContact) == sizeof(void *));
624
QVERIFY(QTypeInfo<QContact>::isComplex);
625
QVERIFY(!QTypeInfo<QContact>::isStatic);
626
QVERIFY(!QTypeInfo<QContact>::isLarge);
627
QVERIFY(!QTypeInfo<QContact>::isPointer);
628
QVERIFY(!QTypeInfo<QContact>::isDummy);
631
void tst_QContact::idTraits()
633
QVERIFY(sizeof(QContactId) == sizeof(void *));
634
QVERIFY(QTypeInfo<QContactId>::isComplex);
635
QVERIFY(!QTypeInfo<QContactId>::isStatic);
636
QVERIFY(!QTypeInfo<QContactId>::isLarge);
637
QVERIFY(!QTypeInfo<QContactId>::isPointer);
638
QVERIFY(!QTypeInfo<QContactId>::isDummy);
641
void tst_QContact::equality()
644
name.setFirstName("John");
645
name.setLastName("Doe");
646
QContactPhoneNumber number;
647
number.setNumber("7654321");
648
QContactEmailAddress email;
649
email.setEmailAddress("john.doe@nokia.com");
650
QContactExtendedDetail xdetail;
651
xdetail.setName("shoesize");
652
xdetail.setData("45");
653
// Setup two identical contacts
655
one.saveDetail(&name);
656
one.saveDetail(&number);
657
one.saveDetail(&email);
658
one.saveDetail(&xdetail);
659
two.saveDetail(&xdetail);
660
two.saveDetail(&email);
661
two.saveDetail(&number);
662
two.saveDetail(&name);
667
void tst_QContact::inequality()
669
QContactId id = QContactIdMock::createId("a", 123);
671
name.setFirstName("John");
672
name.setLastName("Doe");
673
QContactPhoneNumber number;
674
number.setNumber("7654321");
675
QContactEmailAddress email;
676
email.setEmailAddress("john.doe@nokia.com");
677
QContactExtendedDetail xdetail;
678
xdetail.setName("shoesize");
679
xdetail.setData("45");
680
// Setup two contacts
686
// insert different amount of details
687
one.saveDetail(&name);
688
one.saveDetail(&number);
689
two.saveDetail(&number);
692
// same amount of details with different types
693
two.saveDetail(&number);
694
two.saveDetail(&email);
697
// same amount of details with different value
698
name.setFirstName("Jim");
699
two.saveDetail(&name);
700
two.saveDetail(&number);
703
name.setFirstName("John");
704
// different types of details with same value
705
email.setEmailAddress("7654321");
706
two.saveDetail(&name);
707
two.saveDetail(&email);
711
void tst_QContact::preferredDetails()
713
QContactPhoneNumber number;
714
number.setNumber("7654321");
715
QContactEmailAddress email;
716
email.setEmailAddress("john.doe@nokia.com");
717
QContactPhoneNumber number2;
718
number2.setNumber("1234567");
721
one.saveDetail(&email);
722
one.saveDetail(&number);
723
one.saveDetail(&number2);
725
one.setPreferredDetail("EMAIL", email);
726
one.setPreferredDetail("PHONE", number);
728
QVERIFY(one.preferredDetail("EMAIL") == email);
729
QVERIFY(one.preferredDetail("PHONE") == number);
731
QMap<QString, QContactDetail> prefDetails = one.preferredDetails();
732
QCOMPARE(prefDetails.count(), 2);
733
QVERIFY(prefDetails["EMAIL"] == email);
734
QVERIFY(prefDetails["PHONE"] == number);
737
QTEST_MAIN(tst_QContact)
738
#include "tst_qcontact.moc"