|
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 |
|
46 //TESTED_CLASS= |
|
47 //TESTED_FILES= |
|
48 |
|
49 QTM_USE_NAMESPACE |
|
50 |
|
51 class tst_QContactRelationship: public QObject |
|
52 { |
|
53 Q_OBJECT |
|
54 |
|
55 public: |
|
56 tst_QContactRelationship(); |
|
57 virtual ~tst_QContactRelationship(); |
|
58 |
|
59 private slots: |
|
60 void operations(); |
|
61 void emptiness(); |
|
62 void hash(); |
|
63 }; |
|
64 |
|
65 tst_QContactRelationship::tst_QContactRelationship() |
|
66 { |
|
67 } |
|
68 |
|
69 tst_QContactRelationship::~tst_QContactRelationship() |
|
70 { |
|
71 } |
|
72 |
|
73 void tst_QContactRelationship::operations() |
|
74 { |
|
75 QContactRelationship r1; |
|
76 |
|
77 QContactId id1, id2; |
|
78 id1.setLocalId(1); |
|
79 id1.setManagerUri("test"); |
|
80 id2.setLocalId(2); |
|
81 id2.setManagerUri("test"); |
|
82 |
|
83 QVERIFY(r1.first() == QContactId()); |
|
84 QVERIFY(r1.second() == QContactId()); |
|
85 QVERIFY(r1.relationshipType() == QString()); |
|
86 |
|
87 r1.setFirst(id1); |
|
88 QVERIFY(r1.first() == id1); |
|
89 r1.setSecond(id2); |
|
90 QVERIFY(r1.second() == id2); |
|
91 QVERIFY(r1.first() == id1); |
|
92 QVERIFY(r1.relationshipType() == QString()); |
|
93 |
|
94 r1.setRelationshipType(QContactRelationship::HasSpouse); |
|
95 QVERIFY(r1.relationshipType() == QString(QLatin1String(QContactRelationship::HasSpouse))); |
|
96 } |
|
97 |
|
98 void tst_QContactRelationship::emptiness() |
|
99 { |
|
100 QContactRelationship r1, r2, r3; |
|
101 |
|
102 QContactId id1, id2, id3; |
|
103 id1.setLocalId(1); |
|
104 id1.setManagerUri("test"); |
|
105 id2.setLocalId(2); |
|
106 id2.setManagerUri("test"); |
|
107 id3.setLocalId(3); |
|
108 id3.setManagerUri("test"); |
|
109 |
|
110 QVERIFY(r1.first() == QContactId()); |
|
111 QVERIFY(r1.second() == QContactId()); |
|
112 QVERIFY(r1.relationshipType() == QString()); |
|
113 |
|
114 r1.setFirst(id1); |
|
115 QVERIFY(r1.first() == id1); |
|
116 r1.setSecond(id2); |
|
117 QVERIFY(r1.second() == id2); |
|
118 QVERIFY(r1.first() == id1); |
|
119 QVERIFY(r1.relationshipType() == QString()); |
|
120 |
|
121 r1.setRelationshipType(QContactRelationship::HasSpouse); |
|
122 QVERIFY(r1.relationshipType() == QString(QLatin1String(QContactRelationship::HasSpouse))); |
|
123 |
|
124 r2 = r1; |
|
125 QVERIFY(r1 == r2); |
|
126 QVERIFY(r1 != r3); |
|
127 QVERIFY(r2 != r3); |
|
128 |
|
129 r3.setFirst(id3); |
|
130 r3.setSecond(id2); |
|
131 r3.setRelationshipType(QContactRelationship::HasAssistant); |
|
132 |
|
133 r2.setFirst(id3); |
|
134 |
|
135 QVERIFY(r1 != r2); |
|
136 QVERIFY(r2 != r3); |
|
137 QVERIFY(r3 != r1); |
|
138 } |
|
139 |
|
140 void tst_QContactRelationship::hash() |
|
141 { |
|
142 QContactRelationship r1; |
|
143 QContactId id1; |
|
144 id1.setManagerUri("a"); |
|
145 id1.setLocalId(1); |
|
146 r1.setFirst(id1); |
|
147 QContactId id2; |
|
148 id2.setManagerUri("b"); |
|
149 id2.setLocalId(2); |
|
150 r1.setSecond(id2); |
|
151 r1.setRelationshipType(QContactRelationship::HasMember); |
|
152 |
|
153 QContactRelationship r2; |
|
154 r2.setFirst(id1); |
|
155 r2.setSecond(id2); |
|
156 r2.setRelationshipType(QContactRelationship::HasMember); |
|
157 |
|
158 QContactRelationship r3; |
|
159 r3.setFirst(id1); |
|
160 QContactId id3; |
|
161 id3.setManagerUri("c"); |
|
162 id3.setLocalId(3); |
|
163 r3.setSecond(id3); |
|
164 r3.setRelationshipType(QContactRelationship::HasMember); |
|
165 |
|
166 QVERIFY(qHash(r1) == qHash(r2)); |
|
167 QVERIFY(qHash(r1) != qHash(r3)); |
|
168 |
|
169 } |
|
170 |
|
171 QTEST_MAIN(tst_QContactRelationship) |
|
172 #include "tst_qcontactrelationship.moc" |