|
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 class tst_QContactDetailDefinition: public QObject |
|
51 { |
|
52 Q_OBJECT |
|
53 |
|
54 public: |
|
55 tst_QContactDetailDefinition(); |
|
56 virtual ~tst_QContactDetailDefinition(); |
|
57 |
|
58 public slots: |
|
59 void init(); |
|
60 void cleanup(); |
|
61 private slots: |
|
62 void testCtor(); |
|
63 void testGetSet(); |
|
64 void testEquality(); |
|
65 void testEmpty(); |
|
66 void traits(); |
|
67 void fieldTraits(); |
|
68 }; |
|
69 |
|
70 tst_QContactDetailDefinition::tst_QContactDetailDefinition() |
|
71 { |
|
72 } |
|
73 |
|
74 tst_QContactDetailDefinition::~tst_QContactDetailDefinition() |
|
75 { |
|
76 } |
|
77 |
|
78 void tst_QContactDetailDefinition::init() |
|
79 { |
|
80 } |
|
81 |
|
82 void tst_QContactDetailDefinition::cleanup() |
|
83 { |
|
84 } |
|
85 |
|
86 |
|
87 void tst_QContactDetailDefinition::testCtor() |
|
88 { |
|
89 QContactDetailDefinition def; |
|
90 |
|
91 /* Check the ctor sets sane things */ |
|
92 QVERIFY(def.isEmpty()); |
|
93 QVERIFY(def.name().isEmpty()); |
|
94 QVERIFY(def.fields().isEmpty()); |
|
95 QVERIFY(def.isUnique() == false); |
|
96 |
|
97 /* Set a few things */ |
|
98 QMap<QString, QContactDetailFieldDefinition> map; |
|
99 QContactDetailFieldDefinition currField; |
|
100 currField.setDataType(QVariant::String); |
|
101 map.insert("string", currField); |
|
102 currField.setDataType(QVariant::DateTime); |
|
103 map.insert("datetime", currField); |
|
104 |
|
105 def.setName("Test ID"); |
|
106 def.setUnique(true); |
|
107 def.setFields(map); |
|
108 |
|
109 QVERIFY(def.name() == "Test ID"); |
|
110 QVERIFY(def.isUnique()); |
|
111 QVERIFY(def.fields() == map); |
|
112 |
|
113 QContactDetailDefinition def2(def); |
|
114 |
|
115 QVERIFY(def2.name() == "Test ID"); |
|
116 QVERIFY(def2.isUnique()); |
|
117 QVERIFY(def2.fields() == map); |
|
118 |
|
119 QContactDetailDefinition def3; |
|
120 def3 = def2; |
|
121 |
|
122 QVERIFY(def3.name() == "Test ID"); |
|
123 QVERIFY(def3.isUnique()); |
|
124 QVERIFY(def3.fields() == map); |
|
125 |
|
126 /* Make sure they aren't improperly shared */ |
|
127 def.setName("id one"); |
|
128 QVERIFY(def2.name() != def.name()); |
|
129 QVERIFY(def3.name() != def.name()); |
|
130 |
|
131 def2.setName("id two"); |
|
132 QVERIFY(def2.name() != def3.name()); |
|
133 } |
|
134 |
|
135 void tst_QContactDetailDefinition::testGetSet() |
|
136 { |
|
137 QContactDetailDefinition def; |
|
138 |
|
139 /* Id */ |
|
140 def.setName("this is the id"); |
|
141 QVERIFY(def.name() == "this is the id"); |
|
142 |
|
143 def.setName(QString()); |
|
144 QVERIFY(def.name() == QString()); |
|
145 |
|
146 /* Uniqueness */ |
|
147 def.setUnique(true); |
|
148 QVERIFY(def.isUnique() == true); |
|
149 |
|
150 def.setUnique(false); |
|
151 QVERIFY(def.isUnique() == false); |
|
152 |
|
153 /* Type map */ |
|
154 QMap<QString, QContactDetailFieldDefinition> map; |
|
155 QContactDetailFieldDefinition currField; |
|
156 currField.setDataType(QVariant::String); |
|
157 map.insert("string", currField); |
|
158 currField.setDataType(QVariant::DateTime); |
|
159 map.insert("datetime", currField); |
|
160 |
|
161 def.setFields(map); |
|
162 QVERIFY(def.fields() == map); |
|
163 |
|
164 def.setFields(QMap<QString, QContactDetailFieldDefinition>()); |
|
165 QVERIFY(def.fields().isEmpty()); |
|
166 |
|
167 /* Non const accessor - XXX TODO: remove after deprecation transition period. */ |
|
168 //def.fields() = map; |
|
169 //QVERIFY(def.fields() == map); |
|
170 // |
|
171 //QMap<QString, QContactDetailDefinitionField>& rmap = def.fields(); |
|
172 //def.fields().clear(); |
|
173 //QVERIFY(rmap == def.fields()); |
|
174 } |
|
175 |
|
176 void tst_QContactDetailDefinition::testEmpty() |
|
177 { |
|
178 QContactDetailDefinition def; |
|
179 |
|
180 QVERIFY(def.isEmpty()); |
|
181 |
|
182 def.setName("Name"); |
|
183 QVERIFY(!def.isEmpty()); |
|
184 def.setName(QString()); |
|
185 QVERIFY(def.isEmpty()); |
|
186 QMap<QString, QContactDetailFieldDefinition> fields; |
|
187 QContactDetailFieldDefinition f; |
|
188 f.setDataType(QVariant::String); |
|
189 fields.insert("Field", f); |
|
190 def.setFields(fields); |
|
191 QVERIFY(!def.isEmpty()); |
|
192 |
|
193 def.setName("Name"); |
|
194 QVERIFY(!def.isEmpty()); |
|
195 |
|
196 fields.clear(); |
|
197 def.setFields(fields); |
|
198 QVERIFY(!def.isEmpty()); |
|
199 |
|
200 def.setName(QString()); |
|
201 QVERIFY(def.isEmpty()); |
|
202 } |
|
203 |
|
204 void tst_QContactDetailDefinition::testEquality() |
|
205 { |
|
206 /* Create a few */ |
|
207 QContactDetailDefinition def1, def2; |
|
208 |
|
209 /* Both empty, should be equal */ |
|
210 QVERIFY(def1 == def2); |
|
211 QVERIFY(def2 == def1); |
|
212 |
|
213 /* Change id first */ |
|
214 def1.setName("id"); |
|
215 QVERIFY(def1 != def2); |
|
216 QVERIFY(def2 != def1); |
|
217 |
|
218 def2.setName("id"); |
|
219 QVERIFY(def1 == def2); |
|
220 QVERIFY(def2 == def1); |
|
221 |
|
222 /* Then uniqueness */ |
|
223 def1.setUnique(true); |
|
224 QVERIFY(def1 != def2); |
|
225 QVERIFY(def2 != def1); |
|
226 |
|
227 def2.setUnique(true); |
|
228 QVERIFY(def1 == def2); |
|
229 QVERIFY(def2 == def1); |
|
230 |
|
231 /* Test Fields */ |
|
232 QContactDetailFieldDefinition f1, f2; |
|
233 QVERIFY(f1 == f2); |
|
234 QVERIFY(f1.allowableValues().count() == 0); |
|
235 QVERIFY(f1.dataType() == QVariant::Invalid); |
|
236 |
|
237 f1.setDataType(QVariant::String); |
|
238 QVERIFY(f1 != f2); |
|
239 f1.setDataType(QVariant::Invalid); |
|
240 QVERIFY(f1 == f2); |
|
241 QVariantList vlist; |
|
242 vlist << "string" << 56; |
|
243 f1.setAllowableValues(vlist); |
|
244 QVERIFY(f1 != f2); |
|
245 f2.setAllowableValues(vlist); |
|
246 QVERIFY(f1 == f2); |
|
247 |
|
248 /* Field map */ |
|
249 QMap<QString, QContactDetailFieldDefinition> fields; |
|
250 QContactDetailFieldDefinition currField; |
|
251 currField.setDataType(QVariant::String); |
|
252 fields.insert("string", currField); |
|
253 currField.setDataType(QVariant::DateTime); |
|
254 fields.insert("datetime", currField); |
|
255 |
|
256 def1.setFields(fields); |
|
257 QVERIFY(def1 != def2); |
|
258 QVERIFY(def2 != def1); |
|
259 QVERIFY(def1.fields() != def2.fields()); |
|
260 |
|
261 def2.setFields(fields); |
|
262 QVERIFY(def1 == def2); |
|
263 QVERIFY(def2 == def1); |
|
264 QVERIFY(def1.fields() == def2.fields()); |
|
265 |
|
266 /* Same map done a different way */ |
|
267 fields.clear(); |
|
268 fields.insert("datetime", currField); |
|
269 currField.setDataType(QVariant::String); |
|
270 fields.insert("string", currField); |
|
271 def2.setFields(fields); |
|
272 QVERIFY(def1 == def2); |
|
273 QVERIFY(def2 == def1); |
|
274 } |
|
275 |
|
276 void tst_QContactDetailDefinition::traits() |
|
277 { |
|
278 QCOMPARE(sizeof(QContactDetailDefinition), sizeof(void *)); |
|
279 QTypeInfo<QTM_PREPEND_NAMESPACE(QContactDetailDefinition)> ti; |
|
280 QVERIFY(ti.isComplex); |
|
281 QVERIFY(!ti.isStatic); |
|
282 QVERIFY(!ti.isLarge); |
|
283 QVERIFY(!ti.isPointer); |
|
284 QVERIFY(!ti.isDummy); |
|
285 } |
|
286 |
|
287 void tst_QContactDetailDefinition::fieldTraits() |
|
288 { |
|
289 QCOMPARE(sizeof(QContactDetailFieldDefinition), sizeof(void *)); |
|
290 QTypeInfo<QTM_PREPEND_NAMESPACE(QContactDetailFieldDefinition)> ti; |
|
291 QVERIFY(ti.isComplex); |
|
292 QVERIFY(!ti.isStatic); |
|
293 QVERIFY(!ti.isLarge); |
|
294 QVERIFY(!ti.isPointer); |
|
295 QVERIFY(!ti.isDummy); |
|
296 } |
|
297 |
|
298 |
|
299 QTEST_MAIN(tst_QContactDetailDefinition) |
|
300 #include "tst_qcontactdetaildefinition.moc" |