40 ****************************************************************************/ |
40 ****************************************************************************/ |
41 |
41 |
42 #include <QtTest/QtTest> |
42 #include <QtTest/QtTest> |
43 |
43 |
44 #include "qtcontacts.h" |
44 #include "qtcontacts.h" |
|
45 #include "qcontactid.h" |
45 #include "qcontactmanagerdataholder.h" //QContactManagerDataHolder |
46 #include "qcontactmanagerdataholder.h" //QContactManagerDataHolder |
|
47 #include <QSet> |
|
48 |
46 |
49 |
47 //TESTED_CLASS= |
50 //TESTED_CLASS= |
48 //TESTED_FILES= |
51 //TESTED_FILES= |
49 |
52 |
50 QTM_USE_NAMESPACE |
53 QTM_USE_NAMESPACE |
|
54 class HackEngine : public QContactManagerEngine |
|
55 { |
|
56 public: |
|
57 static void setRels(QContact* contact, const QList<QContactRelationship>& rels) {QContactManagerEngine::setContactRelationships(contact, rels);} |
|
58 }; |
|
59 |
51 class tst_QContact: public QObject |
60 class tst_QContact: public QObject |
52 { |
61 { |
53 Q_OBJECT |
62 Q_OBJECT |
54 |
63 |
55 public: |
64 public: |
548 QVERIFY(related.isEmpty()); |
560 QVERIFY(related.isEmpty()); |
549 |
561 |
550 related = c.relatedContacts(QContactRelationship::HasMember); |
562 related = c.relatedContacts(QContactRelationship::HasMember); |
551 QVERIFY(related.isEmpty()); |
563 QVERIFY(related.isEmpty()); |
552 |
564 |
553 related = c.relatedContacts(QContactRelationship::HasMember, QContactRelationshipFilter::First); |
565 related = c.relatedContacts(QContactRelationship::HasMember, QContactRelationship::First); |
554 QVERIFY(related.isEmpty()); |
566 QVERIFY(related.isEmpty()); |
555 |
567 |
556 QList<QContactRelationship> relationshipList = c.relationships(); |
568 QList<QContactRelationship> relationshipList = c.relationships(); |
557 QVERIFY(relationshipList.isEmpty()); |
569 QVERIFY(relationshipList.isEmpty()); |
558 |
570 |
559 relationshipList = c.relationships(QContactRelationship::HasMember); |
571 relationshipList = c.relationships(QContactRelationship::HasMember); |
560 QVERIFY(relationshipList.isEmpty()); |
572 QVERIFY(relationshipList.isEmpty()); |
561 |
|
562 // now test that we can change the order of relationships regardless of the number of relationships |
|
563 QList<QContactRelationship> orderedList = c.relationshipOrder(); |
|
564 QVERIFY(orderedList == relationshipList); // should be the same by default |
|
565 |
|
566 QContactRelationship dummyRel; |
|
567 QContactId firstId; |
|
568 firstId.setManagerUri("test-nokia"); |
|
569 firstId.setLocalId(QContactLocalId(5)); |
|
570 QContactId secondId; |
|
571 secondId.setManagerUri("test-nokia-2"); |
|
572 secondId.setLocalId(QContactLocalId(5)); |
|
573 dummyRel.setFirst(firstId); |
|
574 dummyRel.setSecond(secondId); |
|
575 dummyRel.setRelationshipType(QContactRelationship::HasAssistant); |
|
576 |
|
577 QList<QContactRelationship> reorderedList; |
|
578 reorderedList.append(dummyRel); |
|
579 c.setRelationshipOrder(reorderedList); |
|
580 |
|
581 QVERIFY(c.relationshipOrder() == reorderedList); |
|
582 } |
573 } |
583 |
574 |
584 void tst_QContact::displayName() |
575 void tst_QContact::displayName() |
585 { |
576 { |
586 QContact c; |
577 QContact c; |
641 QVERIFY(c.isEmpty() == true); |
632 QVERIFY(c.isEmpty() == true); |
642 |
633 |
643 c.setType(QContactType::TypeContact); |
634 c.setType(QContactType::TypeContact); |
644 QVERIFY(c.type() == QString(QLatin1String(QContactType::TypeContact))); |
635 QVERIFY(c.type() == QString(QLatin1String(QContactType::TypeContact))); |
645 QVERIFY(c.isEmpty() == true); // type doesn't affect emptiness |
636 QVERIFY(c.isEmpty() == true); // type doesn't affect emptiness |
|
637 } |
|
638 |
|
639 void tst_QContact::idLessThan() |
|
640 { |
|
641 QContactId id1; |
|
642 id1.setManagerUri("a"); |
|
643 id1.setLocalId(1); |
|
644 QContactId id2; |
|
645 id2.setManagerUri("a"); |
|
646 id2.setLocalId(1); |
|
647 QVERIFY(!(id1 < id2)); |
|
648 QVERIFY(!(id2 < id1)); |
|
649 QContactId id3; |
|
650 id3.setManagerUri("a"); |
|
651 id3.setLocalId(2); |
|
652 QContactId id4; |
|
653 id4.setManagerUri("b"); |
|
654 id4.setLocalId(1); |
|
655 QContactId id5; // no URI |
|
656 id5.setLocalId(2); |
|
657 QVERIFY(id1 < id3); |
|
658 QVERIFY(!(id3 < id1)); |
|
659 QVERIFY(id1 < id4); |
|
660 QVERIFY(!(id4 < id1)); |
|
661 QVERIFY(id3 < id4); |
|
662 QVERIFY(!(id4 < id3)); |
|
663 QVERIFY(id5 < id1); |
|
664 QVERIFY(!(id1 < id5)); |
|
665 } |
|
666 |
|
667 void tst_QContact::idHash() |
|
668 { |
|
669 QContactId id1; |
|
670 id1.setManagerUri("a"); |
|
671 id1.setLocalId(1); |
|
672 QContactId id2; |
|
673 id2.setManagerUri("a"); |
|
674 id2.setLocalId(1); |
|
675 QContactId id3; |
|
676 id3.setManagerUri("b"); |
|
677 id3.setLocalId(1); |
|
678 QVERIFY(qHash(id1) == qHash(id2)); |
|
679 QVERIFY(qHash(id1) != qHash(id3)); |
|
680 QSet<QContactId> set; |
|
681 set.insert(id1); |
|
682 set.insert(id2); |
|
683 set.insert(id3); |
|
684 QCOMPARE(set.size(), 2); |
|
685 } |
|
686 |
|
687 void tst_QContact::hash() |
|
688 { |
|
689 QContactId id; |
|
690 id.setManagerUri("a"); |
|
691 id.setLocalId(1); |
|
692 QContact contact1; |
|
693 contact1.setId(id); |
|
694 QContactDetail detail1("definition"); |
|
695 detail1.setValue("key", "value"); |
|
696 contact1.saveDetail(&detail1); |
|
697 QContact contact2; |
|
698 contact2.setId(id); |
|
699 contact2.saveDetail(&detail1); |
|
700 QContact contact3; |
|
701 contact3.setId(id); |
|
702 QContactDetail detail3("definition"); |
|
703 detail3.setValue("key", "another value"); |
|
704 contact3.saveDetail(&detail3); |
|
705 QContact contact4; // no details |
|
706 contact4.setId(id); |
|
707 QContact contact5; // preferred details and relationships shouldn't affect the hash |
|
708 contact5.setId(id); |
|
709 contact5.saveDetail(&detail1); |
|
710 contact5.setPreferredDetail("action", detail1); |
|
711 QContactRelationship rel; |
|
712 HackEngine::setRels(&contact5, QList<QContactRelationship>() << rel); |
|
713 QVERIFY(qHash(contact1) == qHash(contact2)); |
|
714 QVERIFY(qHash(contact1) != qHash(contact3)); |
|
715 QVERIFY(qHash(contact1) != qHash(contact4)); |
|
716 QVERIFY(qHash(contact1) == qHash(contact5)); |
646 } |
717 } |
647 |
718 |
648 void tst_QContact::traits() |
719 void tst_QContact::traits() |
649 { |
720 { |
650 QVERIFY(sizeof(QContact) == sizeof(void *)); |
721 QVERIFY(sizeof(QContact) == sizeof(void *)); |