1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2015 The Qt Company Ltd. |
4 | ** Contact: http://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the test suite of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL21$ |
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 The Qt Company. For licensing terms |
14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at http://www.qt.io/contact-us. |
16 | ** |
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 or version 3 as published by the Free |
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and |
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the |
22 | ** following information to ensure the GNU Lesser General Public License |
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and |
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
25 | ** |
26 | ** As a special exception, The Qt Company gives you certain additional |
27 | ** rights. These rights are described in The Qt Company LGPL Exception |
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
29 | ** |
30 | ** $QT_END_LICENSE$ |
31 | ** |
32 | ****************************************************************************/ |
33 | |
34 | #include <QtTest/QtTest> |
35 | |
36 | #include <QtCore/qset.h> |
37 | |
38 | #include <QtOrganizer/qorganizer.h> |
39 | #include <QtOrganizer/qorganizeritemid.h> |
40 | |
41 | //TESTED_COMPONENT=src/organizer |
42 | |
43 | QTORGANIZER_USE_NAMESPACE |
44 | |
45 | static inline QOrganizerItemId makeId(const QString &managerName, uint id) |
46 | { |
47 | return QOrganizerItemId(QStringLiteral("qtorganizer:%1:" ).arg(a: managerName), QByteArray(reinterpret_cast<const char *>(&id), sizeof(uint))); |
48 | } |
49 | |
50 | |
51 | class tst_QOrganizerItem: public QObject |
52 | { |
53 | Q_OBJECT |
54 | |
55 | public: |
56 | tst_QOrganizerItem(); |
57 | virtual ~tst_QOrganizerItem(); |
58 | |
59 | private slots: |
60 | void details(); |
61 | void displayLabel(); |
62 | void description(); |
63 | void comments(); |
64 | void tags(); |
65 | void type(); |
66 | void emptiness(); |
67 | void idComparison(); |
68 | void idHash(); |
69 | void idStringFunctions(); |
70 | void hash(); |
71 | void datastream(); |
72 | void traits(); |
73 | void idTraits(); |
74 | void debugOutput(); |
75 | |
76 | void event(); |
77 | void todo(); |
78 | void journal(); |
79 | void note(); |
80 | void eventOccurrence(); |
81 | void todoOccurrence(); |
82 | void testDebugStreamOut(); |
83 | void itemsCompare(); |
84 | }; |
85 | |
86 | tst_QOrganizerItem::tst_QOrganizerItem() |
87 | { |
88 | } |
89 | |
90 | tst_QOrganizerItem::~tst_QOrganizerItem() |
91 | { |
92 | } |
93 | |
94 | void tst_QOrganizerItem::details() |
95 | { |
96 | // Check that detail keys are unique, regardless of order of initialisation |
97 | // First, construct the detail first, then the contact |
98 | QOrganizerItemComment note; |
99 | note.setComment("Example Note" ); |
100 | QOrganizerItem keyTest; |
101 | QVERIFY(keyTest.saveDetail(¬e)); |
102 | QList<QOrganizerItemDetail> allDetails = keyTest.details(); |
103 | QList<int> detailKeys; |
104 | foreach (const QOrganizerItemDetail& det, allDetails) { |
105 | int currKey = det.key(); |
106 | QVERIFY(!detailKeys.contains(currKey)); |
107 | detailKeys.append(t: currKey); |
108 | } |
109 | // Second, construct the detail after the contact has been constructed |
110 | QOrganizerItemLocation adr; |
111 | adr.setLabel("this is a test address" ); |
112 | QVERIFY(keyTest.saveDetail(&adr)); |
113 | allDetails = keyTest.details(); |
114 | detailKeys.clear(); |
115 | foreach (const QOrganizerItemDetail& det, allDetails) { |
116 | int currKey = det.key(); |
117 | QVERIFY(!detailKeys.contains(currKey)); |
118 | detailKeys.append(t: currKey); |
119 | } |
120 | |
121 | // now test for default construction sanity |
122 | QOrganizerItem oi; |
123 | |
124 | // Test there are no details (apart from type) by default |
125 | QVERIFY(oi.isEmpty() == true); |
126 | QCOMPARE(oi.details().count(), 1); |
127 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeLocation).count(), 0); |
128 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeLocation).count(), 0); |
129 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
130 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
131 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeLocation).count(), 0); |
132 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
133 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeLocation).count(), 0); |
134 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
135 | |
136 | // Test retrieving the default details (type) |
137 | QList<QOrganizerItemDetail> details = oi.details(); |
138 | QVERIFY(details.at(0).type() == QOrganizerItemDetail::TypeItemType); |
139 | |
140 | QOrganizerItemDetail detail = oi.detail(detailType: QOrganizerItemDetail::TypeExtendedDetail); |
141 | QVERIFY(detail.isEmpty()); |
142 | |
143 | // retrieve the first detail using the empty definition name accessor. |
144 | detail = oi.detail(); |
145 | QVERIFY(detail == details.at(0)); |
146 | |
147 | QVERIFY(oi.details(QOrganizerItemDetail::TypeExtendedDetail).count() == 0); |
148 | |
149 | // Add a detail |
150 | QOrganizerItemLocation a; |
151 | a.setLabel("another test address label" ); |
152 | QVERIFY(oi.saveDetail(&a)); |
153 | QVERIFY(oi.isEmpty() == false); |
154 | |
155 | QVERIFY(oi.details().count() == 2); |
156 | |
157 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 1); |
158 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 1); |
159 | QVERIFY(!oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
160 | QVERIFY(!oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
161 | QCOMPARE(static_cast<QOrganizerItemLocation>(oi.detail(QOrganizerItemDetail::TypeLocation)), a); |
162 | |
163 | // Remove detail |
164 | QVERIFY(oi.removeDetail(&a)); |
165 | QCOMPARE(oi.details().count(), 1); |
166 | QVERIFY(oi.isEmpty() == true); |
167 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 0); |
168 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeLocation).count(), 0); |
169 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
170 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
171 | |
172 | // Try removing it again |
173 | QVERIFY(!oi.removeDetail(&a)); |
174 | |
175 | // Add again, and remove a different way (retrieved copy) |
176 | QVERIFY(oi.saveDetail(&a)); |
177 | QVERIFY(oi.isEmpty() == false); |
178 | QCOMPARE(oi.details().count(), 2); |
179 | QOrganizerItemLocation a2 = oi.detail(detailType: QOrganizerItemDetail::TypeLocation); |
180 | QCOMPARE(a, a2); |
181 | |
182 | QVERIFY(oi.removeDetail(&a2)); |
183 | QCOMPARE(oi.details().count(), 1); |
184 | QVERIFY(oi.isEmpty() == true); |
185 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 0); |
186 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 0); |
187 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
188 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
189 | |
190 | QCOMPARE(a, a2); |
191 | |
192 | // Add again again, and remove a different way (base class) |
193 | QVERIFY(oi.saveDetail(&a)); |
194 | QCOMPARE(oi.details().count(), 2); |
195 | QOrganizerItemDetail a3 = oi.detail(detailType: QOrganizerItemDetail::TypeLocation); |
196 | QVERIFY(a == a3); |
197 | |
198 | QVERIFY(oi.removeDetail(&a3)); |
199 | QCOMPARE(oi.details().count(), 1); |
200 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 0); |
201 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 0); |
202 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
203 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
204 | |
205 | QVERIFY(a == a3); |
206 | |
207 | // now we want to add multiple details of the same type, and test that retrieval works correctly. |
208 | a2 = QOrganizerItemLocation(); |
209 | a2.setLabel("22222" ); |
210 | a2.setValue(field: 100, value: QVariant("22222-2" )); // non-existing field |
211 | oi.saveDetail(detail: &a); |
212 | oi.saveDetail(detail: &a2); |
213 | QCOMPARE(oi.details().count(), 3); |
214 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 2); |
215 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 2); |
216 | QVERIFY(!oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
217 | QVERIFY(!oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
218 | QCOMPARE(static_cast<QOrganizerItemLocation>(oi.detail(QOrganizerItemDetail::TypeLocation)), a); |
219 | QVERIFY(oi.removeDetail(&a2)); |
220 | |
221 | // Now try adding a detail to multiple contacts |
222 | |
223 | QOrganizerItem oi2; |
224 | QVERIFY(oi2.isEmpty() == true); |
225 | QVERIFY(oi.saveDetail(&a)); |
226 | QVERIFY(oi2.saveDetail(&a)); |
227 | QVERIFY(oi2.isEmpty() == false); |
228 | |
229 | QCOMPARE(oi.details().count(), 2); |
230 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 1); |
231 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 1); |
232 | QVERIFY(!oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
233 | QVERIFY(!oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
234 | QCOMPARE(static_cast<QOrganizerItemLocation>(oi.detail(QOrganizerItemDetail::TypeLocation)), a); |
235 | |
236 | QCOMPARE(oi2.details().count(), 2); |
237 | QVERIFY(oi2.details(QOrganizerItemDetail::TypeLocation).count() == 1); |
238 | QVERIFY(oi2.details(QOrganizerItemDetail::TypeLocation).count() == 1); |
239 | QVERIFY(!oi2.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
240 | QVERIFY(!oi2.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
241 | QCOMPARE(static_cast<QOrganizerItemLocation>(oi2.detail(QOrganizerItemDetail::TypeLocation)), a); |
242 | |
243 | // Now try removing it from one |
244 | QVERIFY(oi.removeDetail(&a)); |
245 | |
246 | // Make sure it's gone from the first contact |
247 | QVERIFY(oi.isEmpty() == true); |
248 | QCOMPARE(oi.details().count(), 1); |
249 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 0); |
250 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 0); |
251 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
252 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
253 | |
254 | // but not the second |
255 | QVERIFY(oi2.isEmpty() == false); |
256 | QCOMPARE(oi2.details().count(), 2); |
257 | QVERIFY(oi2.details(QOrganizerItemDetail::TypeLocation).count() == 1); |
258 | QVERIFY(oi2.details(QOrganizerItemDetail::TypeLocation).count() == 1); |
259 | QVERIFY(!oi2.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
260 | QVERIFY(!oi2.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
261 | QCOMPARE(static_cast<QOrganizerItemLocation>(oi2.detail(QOrganizerItemDetail::TypeLocation)), a); |
262 | |
263 | // Now remove it from the second as well |
264 | QVERIFY(oi2.removeDetail(&a)); |
265 | |
266 | // Make sure it's gone from both |
267 | QCOMPARE(oi.details().count(), 1); |
268 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 0); |
269 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 0); |
270 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
271 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
272 | |
273 | QCOMPARE(oi2.details().count(), 1); |
274 | QVERIFY(oi2.details(QOrganizerItemDetail::TypeLocation).count() == 0); |
275 | QVERIFY(oi2.details(QOrganizerItemDetail::TypeLocation).count() == 0); |
276 | QVERIFY(oi2.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
277 | QVERIFY(oi2.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
278 | |
279 | // add a, add b, remove a, add a, remove b, remove a |
280 | QVERIFY(oi.saveDetail(&a)); |
281 | QVERIFY(oi2.saveDetail(&a)); |
282 | QVERIFY(oi.removeDetail(&a)); |
283 | QVERIFY(oi.saveDetail(&a)); |
284 | QVERIFY(oi2.removeDetail(&a)); |
285 | QVERIFY(oi.removeDetail(&a)); |
286 | |
287 | // Now add a detail with the same values twice |
288 | QOrganizerItemLocation one; |
289 | QOrganizerItemLocation two; |
290 | |
291 | one.setLabel("12345" ); |
292 | two.setLabel("12345" ); |
293 | |
294 | // add it once |
295 | QVERIFY(oi.saveDetail(&one)); |
296 | QCOMPARE(oi.details().count(), 2); |
297 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 1); |
298 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 1); |
299 | QVERIFY(!oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
300 | QVERIFY(!oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
301 | QCOMPARE(static_cast<QOrganizerItemLocation>(oi.detail(QOrganizerItemDetail::TypeLocation)), one); |
302 | |
303 | // add it twice |
304 | QVERIFY(oi.saveDetail(&two)); |
305 | QCOMPARE(oi.details().count(), 3); |
306 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 2); |
307 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 2); |
308 | QVERIFY(!oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
309 | QVERIFY(!oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
310 | QCOMPARE(static_cast<QOrganizerItemLocation>(oi.detail(QOrganizerItemDetail::TypeLocation)), one); |
311 | QCOMPARE(static_cast<QOrganizerItemLocation>(oi.details(QOrganizerItemDetail::TypeLocation)[0]), one); |
312 | QCOMPARE(static_cast<QOrganizerItemLocation>(oi.details(QOrganizerItemDetail::TypeLocation)[1]), two); |
313 | |
314 | // Remove it once |
315 | QVERIFY(oi.removeDetail(&one)); |
316 | QCOMPARE(oi.details().count(), 2); |
317 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 1); |
318 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 1); |
319 | QVERIFY(!oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
320 | QVERIFY(!oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
321 | QCOMPARE(static_cast<QOrganizerItemLocation>(oi.detail(QOrganizerItemDetail::TypeLocation)), two); |
322 | |
323 | // Remove it twice |
324 | QVERIFY(oi.removeDetail(&two)); |
325 | QCOMPARE(oi.details().count(), 1); |
326 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 0); |
327 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 0); |
328 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
329 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeLocation).isEmpty()); |
330 | |
331 | // Null pointer tests |
332 | QVERIFY(oi.saveDetail(0) == false); |
333 | QVERIFY(oi.removeDetail(0) == false); |
334 | |
335 | // Reference tests... |
336 | QOrganizerItemDetail& ref = one; |
337 | QVERIFY(oi.saveDetail(&one)); |
338 | QVERIFY(ref == one); |
339 | one.setLabel("56678" ); |
340 | QVERIFY(oi.saveDetail(&one)); |
341 | QVERIFY(ref == one); |
342 | |
343 | // Retrieve the detail again and modify it |
344 | QOrganizerItemLocation three = oi.detail(detailType: QOrganizerItemDetail::TypeLocation); |
345 | QVERIFY(ref == three); |
346 | QVERIFY(one == three); |
347 | three.setLabel("542343" ); |
348 | QVERIFY(oi.saveDetail(&three)); |
349 | |
350 | // Now see if we got any updates to ref/one |
351 | QVERIFY(ref == one); |
352 | QVERIFY(ref != three); |
353 | |
354 | // test saving of a detail with an empty field. |
355 | QOrganizerItemLocation four; |
356 | four.setLabel("" ); |
357 | oi.saveDetail(detail: &four); |
358 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).count() == 2); |
359 | QVERIFY(!four.values().isEmpty()); // an empty qstring is not invalid; make sure it exists in the detail. |
360 | |
361 | // ensure that clearing a contact's details works correctly |
362 | QOrganizerItemPriority priorityDetail; |
363 | priorityDetail.setPriority(QOrganizerItemPriority::VeryHighPriority); |
364 | oi.saveDetail(detail: &priorityDetail); |
365 | QCOMPARE(oi.detail(QOrganizerItemDetail::TypePriority).value(QOrganizerItemPriority::FieldPriority).toInt(), static_cast<int>(QOrganizerItemPriority::VeryHighPriority)); |
366 | QVERIFY(oi.details().size() > 0); |
367 | QVERIFY(!oi.isEmpty()); |
368 | QOrganizerItemId oldId = oi.id(); |
369 | oi.clearDetails(); |
370 | QCOMPARE(oi.details().size(), 1); // always has an item type. |
371 | QCOMPARE(oi.detail(QOrganizerItemDetail::TypePriority).value(QOrganizerItemPriority::FieldPriority).toString(), QString()); |
372 | QVERIFY(oi.isEmpty()); |
373 | QCOMPARE(oi.id(), oldId); // id shouldn't change. |
374 | } |
375 | |
376 | void tst_QOrganizerItem::displayLabel() |
377 | { |
378 | QOrganizerItem oi; |
379 | |
380 | QString label = oi.displayLabel(); |
381 | QVERIFY(label.isEmpty()); |
382 | oi.setDisplayLabel("Test Event Display Label" ); |
383 | QVERIFY(oi.displayLabel() == QString("Test Event Display Label" )); |
384 | |
385 | /* Remove the detail via removeDetail */ |
386 | QOrganizerItemDisplayLabel old; |
387 | QCOMPARE(oi.details().count(), 2); // type + label |
388 | QVERIFY(!oi.removeDetail(&old)); // should fail. |
389 | QVERIFY(oi.isEmpty() == false); |
390 | QVERIFY(oi.details().count() == 2); // it should not be removed! |
391 | |
392 | QOrganizerItemDisplayLabel displayLabel; |
393 | displayLabel.setLabel("test label" ); |
394 | oi.setDisplayLabel(displayLabel.label()); |
395 | QVERIFY(oi.displayLabel() == displayLabel.label()); |
396 | |
397 | /* Test self assign */ |
398 | oi.operator =(other: oi); |
399 | QVERIFY(oi.details().count() == 2); |
400 | QVERIFY(oi.isEmpty() == false); |
401 | } |
402 | |
403 | |
404 | void tst_QOrganizerItem::description() |
405 | { |
406 | QOrganizerItem oi; |
407 | |
408 | QString description = oi.description(); |
409 | QVERIFY(description.isEmpty()); |
410 | oi.setDescription("Test Event Description" ); |
411 | QVERIFY(oi.description() == QString("Test Event Description" )); |
412 | |
413 | /* Remove the detail via removeDetail */ |
414 | QOrganizerItemDescription old; |
415 | QCOMPARE(oi.details().count(), 2); // type + description |
416 | QVERIFY(!oi.removeDetail(&old)); // should fail. |
417 | QVERIFY(oi.isEmpty() == false); |
418 | QVERIFY(oi.details().count() == 2); // it should not be removed! |
419 | |
420 | QOrganizerItemDescription descr; |
421 | descr.setDescription("test description" ); |
422 | oi.setDescription(descr.description()); |
423 | QVERIFY(oi.description() == descr.description()); |
424 | |
425 | /* Test self assign */ |
426 | oi.operator =(other: oi); |
427 | QVERIFY(oi.details().count() == 2); |
428 | QVERIFY(oi.isEmpty() == false); |
429 | } |
430 | |
431 | void tst_QOrganizerItem::() |
432 | { |
433 | QOrganizerItem oi; |
434 | |
435 | QStringList = oi.comments(); |
436 | QVERIFY(comments.isEmpty()); |
437 | oi.addComment(comment: "test comment" ); |
438 | QCOMPARE(oi.comments().size(), 1); |
439 | QVERIFY(oi.details().count() == 2); |
440 | QVERIFY(oi.comments().at(0) == QString("test comment" )); |
441 | oi.addComment(comment: "another test comment" ); |
442 | QCOMPARE(oi.comments().size(), 2); |
443 | QVERIFY(oi.details().count() == 3); |
444 | QVERIFY(oi.comments().contains(QString("test comment" ))); |
445 | QVERIFY(oi.comments().contains(QString("another test comment" ))); |
446 | |
447 | oi.clearComments(); |
448 | QVERIFY(oi.comments().size() == 0); |
449 | QVERIFY(oi.details().count() == 1); // should have a type detail left. |
450 | |
451 | QOrganizerItemComment ; |
452 | comment.setComment("yet another test comment" ); |
453 | oi.saveDetail(detail: &comment); |
454 | QCOMPARE(oi.comments().size(), 1); |
455 | QVERIFY(oi.details().count() == 2); |
456 | QVERIFY(oi.comments().at(0) == QString("yet another test comment" )); |
457 | |
458 | oi.removeDetail(detail: &comment); |
459 | QVERIFY(oi.comments().size() == 0); |
460 | QVERIFY(oi.details().count() == 1); // should have a type detail left. |
461 | |
462 | oi.clearComments(); |
463 | oi.setComments(QStringList() << "comment 1" << "comment 2" ); |
464 | QVERIFY(oi.comments().size() == 2); |
465 | QVERIFY(oi.details().count() == 3); |
466 | |
467 | /* Test self assign */ |
468 | oi.operator =(other: oi); |
469 | QVERIFY(oi.details().count() == 3); |
470 | QVERIFY(oi.isEmpty() == false); |
471 | } |
472 | |
473 | void tst_QOrganizerItem::tags() |
474 | { |
475 | QOrganizerItem item; |
476 | QVERIFY(item.tags().isEmpty()); |
477 | |
478 | item.addTag(tag: "tag 1" ); |
479 | QStringList tags; |
480 | tags.append(t: "tag 1" ); |
481 | QCOMPARE(item.tags(), tags); |
482 | QList<QOrganizerItemDetail> tagDetails = item.details(detailType: QOrganizerItemDetail::TypeTag); |
483 | QCOMPARE(tagDetails.size(), 1); |
484 | QCOMPARE(tagDetails.first().value(QOrganizerItemTag::FieldTag).toString(), QString(QStringLiteral("tag 1" ))); |
485 | |
486 | item.clearTags(); |
487 | QVERIFY(item.tags().isEmpty()); |
488 | QVERIFY(item.details(QOrganizerItemDetail::TypeTag).isEmpty()); |
489 | |
490 | tags.append(t: "tag 2" ); // tags is now "tag 1", "tag 2" |
491 | item.setTags(tags); |
492 | QCOMPARE(item.tags(), tags); |
493 | tagDetails = item.details(detailType: QOrganizerItemDetail::TypeTag); |
494 | QCOMPARE(tagDetails.size(), 2); |
495 | QCOMPARE(tagDetails.at(0).value(QOrganizerItemTag::FieldTag).toString(), QString(QStringLiteral("tag 1" ))); |
496 | QCOMPARE(tagDetails.at(1).value(QOrganizerItemTag::FieldTag).toString(), QString(QStringLiteral("tag 2" ))); |
497 | } |
498 | |
499 | void tst_QOrganizerItem::debugOutput() |
500 | { |
501 | QOrganizerCollection c; |
502 | QOrganizerItem item; |
503 | QOrganizerItemDetail d; |
504 | |
505 | // Test that these can be used as the first argument to qDebug() |
506 | qDebug() << item.id(); |
507 | qDebug() << item.collectionId(); |
508 | qDebug() << item; |
509 | qDebug() << d; |
510 | qDebug() << c; |
511 | |
512 | // And that other things can come after them (return type) |
513 | qDebug() << item.id() << "id" ; |
514 | qDebug() << item.collectionId() << "collection id" ; |
515 | qDebug() << item << "item" ; |
516 | qDebug() << d << "detail" ; |
517 | qDebug() << c << "collection" ; |
518 | |
519 | // And for kicks, that other things can come first |
520 | qDebug() << " " << item.id(); |
521 | qDebug() << " " << item.collectionId(); |
522 | qDebug() << " " << item; |
523 | qDebug() << " " << d; |
524 | qDebug() << " " << c; |
525 | } |
526 | |
527 | void tst_QOrganizerItem::type() |
528 | { |
529 | QOrganizerItem oi; |
530 | QVERIFY(oi.isEmpty() == true); |
531 | |
532 | // ensure that the default type is the QOrganizerItemType::TypeUnknown type |
533 | QVERIFY(oi.type() == QOrganizerItemType::TypeUndefined); |
534 | |
535 | // now set it to be an event via the type mutator, and test that it works |
536 | QOrganizerItemType eventType; |
537 | eventType.setType(QOrganizerItemType::TypeEvent); |
538 | oi.setType(eventType.type()); |
539 | QVERIFY(oi.type() == QOrganizerItemType::TypeEvent); |
540 | |
541 | // set it back to a note, via the string mutator |
542 | oi.setType(QOrganizerItemType::TypeNote); |
543 | QVERIFY(oi.type() == QOrganizerItemType::TypeNote); |
544 | QVERIFY(oi.isEmpty() == true); // type doesn't affect emptiness |
545 | } |
546 | |
547 | void tst_QOrganizerItem::emptiness() |
548 | { |
549 | QOrganizerItem oi; |
550 | QVERIFY(oi.isEmpty() == true); |
551 | QVERIFY(oi.id().isNull() == true); |
552 | |
553 | oi.setType(QOrganizerItemType::TypeNote); |
554 | QVERIFY(oi.type() == QOrganizerItemType::TypeNote); |
555 | QVERIFY(oi.isEmpty() == true); // type doesn't affect emptiness |
556 | } |
557 | |
558 | void tst_QOrganizerItem::idComparison() |
559 | { |
560 | QOrganizerItemId id1(makeId(managerName: "a" , id: 1)); |
561 | QOrganizerItemId id2(makeId(managerName: "a" , id: 1)); |
562 | QVERIFY(!(id1 < id2)); |
563 | QVERIFY(!(id2 < id1)); |
564 | QVERIFY(id1 == id2); |
565 | |
566 | QOrganizerItemId id3(makeId(managerName: "a" , id: 2)); |
567 | QOrganizerItemId id4(makeId(managerName: "b" , id: 1)); |
568 | QOrganizerItemId id5(makeId(managerName: "b" , id: 2)); |
569 | QVERIFY((((id1 < id3) && !(id3 < id1)) || ((id3 < id1) && !(id1 < id3))) && (id1 != id3)); |
570 | QVERIFY((((id1 < id4) && !(id4 < id1)) || ((id4 < id1) && !(id1 < id4))) && (id1 != id4)); |
571 | QVERIFY((((id3 < id4) && !(id4 < id3)) || ((id4 < id3) && !(id3 < id4))) && (id3 != id4)); |
572 | QVERIFY((((id1 < id5) && !(id5 < id1)) || ((id5 < id1) && !(id1 < id5))) && (id3 != id4)); |
573 | |
574 | QOrganizerItemId id6; |
575 | QOrganizerItemId id7(QString(), "1" ); |
576 | QOrganizerItemId id8(QString(), "2" ); |
577 | QOrganizerItemId id9(QStringLiteral("qtorganizer:basic:" ), "" ); |
578 | QVERIFY(id6.isNull()); |
579 | QVERIFY(id7.isNull()); |
580 | QVERIFY(id8.isNull()); |
581 | QVERIFY(id9.isNull()); |
582 | QVERIFY(id6 == id7); |
583 | QVERIFY(!(id6 < id7)); |
584 | QVERIFY(id7 == id6); |
585 | QVERIFY(!(id7 < id6)); |
586 | QVERIFY(id7 == id8); |
587 | QVERIFY(!(id7 < id8)); |
588 | QVERIFY(id8 == id7); |
589 | QVERIFY(!(id9 < id8)); |
590 | QVERIFY(id8 == id9); |
591 | QVERIFY(!(id8 < id9)); |
592 | QVERIFY(id9 == id8); |
593 | QVERIFY(!(id9 < id8)); |
594 | |
595 | QVERIFY(!(id1 == id6)); |
596 | QVERIFY(!(id1 < id6)); |
597 | QVERIFY(id6 < id1); |
598 | QVERIFY(!(id1 == id7)); |
599 | QVERIFY(!(id1 < id7)); |
600 | QVERIFY(id7 < id1); |
601 | QVERIFY(!(id1 == id8)); |
602 | QVERIFY(!(id1 < id8)); |
603 | QVERIFY(id8 < id1); |
604 | QVERIFY(!(id1 == id9)); |
605 | QVERIFY(!(id1 < id9)); |
606 | QVERIFY(id9 < id1); |
607 | } |
608 | |
609 | void tst_QOrganizerItem::idHash() |
610 | { |
611 | QOrganizerItemId id1(makeId(managerName: "a" , id: 1)); |
612 | QOrganizerItemId id2(makeId(managerName: "a" , id: 1)); |
613 | QOrganizerItemId id3(makeId(managerName: "b" , id: 1)); |
614 | QOrganizerItemId id4(makeId(managerName: "a" , id: 2)); |
615 | // note that the hash function ignores the managerUri |
616 | QCOMPARE(qHash(id1), qHash(id2)); |
617 | QCOMPARE(qHash(id1), qHash(id3)); |
618 | QVERIFY(qHash(id1) != qHash(id4)); |
619 | |
620 | QSet<QOrganizerItemId> set; |
621 | set.insert(value: id1); |
622 | set.insert(value: id2); |
623 | set.insert(value: id3); |
624 | set.insert(value: id4); |
625 | QCOMPARE(set.size(), 3); |
626 | } |
627 | |
628 | void tst_QOrganizerItem::idStringFunctions() |
629 | { |
630 | // TODO: review test |
631 | QOrganizerItemId id1(makeId(managerName: "a" , id: 1)); |
632 | QOrganizerItemId id2(makeId(managerName: "a" , id: 1)); |
633 | QOrganizerItemId id3(makeId(managerName: "b" , id: 1)); |
634 | QOrganizerItemId id4(makeId(managerName: "a" , id: 2)); |
635 | QVERIFY(qHash(id1) == qHash(id2)); |
636 | QVERIFY(qHash(id1) != qHash(id4)); |
637 | |
638 | // note that the toString and fromString functions are |
639 | // engine and id specific. This test merely checks that |
640 | // the API is hooked up correctly. |
641 | |
642 | QVERIFY(id1.toString() == id2.toString()); |
643 | QVERIFY(id1.toString() != id3.toString()); |
644 | QVERIFY(id1.toString() != id4.toString()); |
645 | QVERIFY(id3.toString() != id4.toString()); |
646 | |
647 | // this should "work" -- string of the correct format |
648 | const uint numericId2 = 2u; |
649 | const QByteArray localId2 = QByteArray(reinterpret_cast<const char *>(&numericId2), sizeof(uint)); |
650 | QString prebuiltidstring = QString("qtorganizer" ) + QString(":" ) + QString("a" ) + QString("::" ) + localId2.toHex(); |
651 | QOrganizerItemId rebuiltid = QOrganizerItemId::fromString(idString: prebuiltidstring); |
652 | QVERIFY(rebuiltid == id4); |
653 | QVERIFY(rebuiltid.localId() == id4.localId()); |
654 | |
655 | // this string has the right format and one parameter, but requires a working backend |
656 | prebuiltidstring = QString("qtorganizer" ) + QString(":" ) + QString("a" ) + QString(":" ) + QString("key=value" ) + QString(":" ) + localId2.toHex(); |
657 | rebuiltid = QOrganizerItemId::fromString(idString: prebuiltidstring); |
658 | QVERIFY(rebuiltid != id4); |
659 | QVERIFY(rebuiltid.localId() == id4.localId()); |
660 | |
661 | // this string has the right format and some parameters, but requires a working backend |
662 | prebuiltidstring = QString("qtorganizer" ) + QString(":" ) + QString("a" ) + QString(":" ) + QString("key=value&key2=value2" ) + QString(":" ) + localId2.toHex(); |
663 | rebuiltid = QOrganizerItemId::fromString(idString: prebuiltidstring); |
664 | QVERIFY(rebuiltid != id4); |
665 | QVERIFY(rebuiltid.localId() == id4.localId()); |
666 | |
667 | // this string has the right format but misses the value for a parameter |
668 | prebuiltidstring = QString("qtorganizer" ) + QString(":" ) + QString("a" ) + QString(":" ) + QString("key=value&key2=" ) + QString(":" ) + localId2.toHex(); |
669 | rebuiltid = QOrganizerItemId::fromString(idString: prebuiltidstring); |
670 | QVERIFY(rebuiltid != id4); |
671 | QVERIFY(rebuiltid.localId() == id4.localId()); |
672 | |
673 | // this string misses a field (the parameters) |
674 | prebuiltidstring = QString("qtorganizer" ) + QString(":" ) + QString("a" ) + QString(":" ) + localId2.toHex(); |
675 | rebuiltid = QOrganizerItemId::fromString(idString: prebuiltidstring); |
676 | QVERIFY(rebuiltid == QOrganizerItemId()); // invalid so should be null. |
677 | |
678 | // this string misses two fields (params plus manager uri) |
679 | prebuiltidstring = QString("qtorganizer" ) + QString(":" ) + localId2.toHex(); |
680 | rebuiltid = QOrganizerItemId::fromString(idString: prebuiltidstring); |
681 | QVERIFY(rebuiltid == QOrganizerItemId()); // invalid so should be null. |
682 | |
683 | // this string misses the prefix (qtorganizer) |
684 | prebuiltidstring = QString("notorganizer" ) + QString(":" ) + QString("a" ) + QString("::" ) + localId2.toHex(); |
685 | rebuiltid = QOrganizerItemId::fromString(idString: prebuiltidstring); |
686 | QVERIFY(rebuiltid == QOrganizerItemId()); // invalid so should be null. |
687 | |
688 | // this string misses the manager uri |
689 | prebuiltidstring = QString("notorganizer" ) + QString(":::" ) + localId2.toHex(); |
690 | rebuiltid = QOrganizerItemId::fromString(idString: prebuiltidstring); |
691 | QVERIFY(rebuiltid == QOrganizerItemId()); // invalid so should be null. |
692 | } |
693 | |
694 | void tst_QOrganizerItem::hash() |
695 | { |
696 | // TODO: review test |
697 | QOrganizerItemId id(makeId(managerName: "a" , id: 1)); |
698 | QOrganizerItem oi1; |
699 | oi1.setId(id); |
700 | QOrganizerItemDetail detail1(QOrganizerItemDetail::TypeComment); |
701 | detail1.setValue(field: QOrganizerItemComment::FieldComment, value: "value" ); |
702 | oi1.saveDetail(detail: &detail1); |
703 | QOrganizerItem oi2; |
704 | oi2.setId(id); |
705 | oi2.saveDetail(detail: &detail1); |
706 | QOrganizerItem oi3; |
707 | oi3.setId(id); |
708 | QOrganizerItemDetail detail3(QOrganizerItemDetail::TypeComment); |
709 | detail3.setValue(field: QOrganizerItemComment::FieldComment, value: "another value" ); |
710 | oi3.saveDetail(detail: &detail3); |
711 | QOrganizerItem oi4; // no details |
712 | oi4.setId(id); |
713 | QOrganizerItem oi5; |
714 | oi5.setId(id); |
715 | oi5.saveDetail(detail: &detail1);qDebug()<<__LINE__; |
716 | QVERIFY(qHash(oi1) == qHash(oi2));qDebug()<<__LINE__; |
717 | QVERIFY(qHash(oi1) != qHash(oi3));qDebug()<<__LINE__; |
718 | QVERIFY(qHash(oi1) != qHash(oi4));qDebug()<<__LINE__; |
719 | QVERIFY(qHash(oi1) == qHash(oi5));qDebug()<<__LINE__; |
720 | } |
721 | |
722 | void tst_QOrganizerItem::datastream() |
723 | { |
724 | // item datastreaming |
725 | QByteArray buffer; |
726 | QOrganizerEvent itemIn; |
727 | itemIn.addComment(comment: "test comment" ); |
728 | QOrganizerItem itemOut; |
729 | QOrganizerItemId originalId; |
730 | QOrganizerCollectionId originalCollectionId; |
731 | |
732 | // first, stream an item with a complete id |
733 | { |
734 | QDataStream stream1(&buffer, QIODevice::WriteOnly); |
735 | QOrganizerManager om("memory" ); |
736 | QVERIFY(om.saveItem(&itemIn)); // fill in its ID |
737 | originalId = itemIn.id(); |
738 | originalCollectionId = itemIn.collectionId(); |
739 | stream1 << itemIn; |
740 | QVERIFY(buffer.size() > 0); |
741 | QDataStream stream2(buffer); |
742 | stream2 >> itemOut; |
743 | //QCOMPARE(itemOut, itemIn); // can't do QCOMPARE because detail keys get changed. |
744 | QVERIFY(itemOut.details() == itemIn.details()); |
745 | QVERIFY(itemOut.id() == itemIn.id()); |
746 | } |
747 | |
748 | // TODO : review tests |
749 | // second, stream an item with an id with the mgr uri set, local id null |
750 | /* { |
751 | QDataStream stream1(&buffer, QIODevice::WriteOnly); |
752 | QOrganizerItemId modifiedId = originalId; |
753 | modifiedId.setLocalId(QOrganizerItemLocalId()); |
754 | itemIn.setId(modifiedId); |
755 | stream1 << itemIn; |
756 | QVERIFY(buffer.size() > 0); |
757 | QDataStream stream2(buffer); |
758 | stream2 >> itemOut; |
759 | //QCOMPARE(itemOut, itemIn); // can't do QCOMPARE because detail keys get changed. |
760 | QVERIFY(itemOut.details() == itemIn.details()); |
761 | QVERIFY(itemOut.id() == itemIn.id()); |
762 | } |
763 | |
764 | // third, stream an item with an id with the mgr uri null, local id set |
765 | { |
766 | QDataStream stream1(&buffer, QIODevice::WriteOnly); |
767 | QOrganizerItemId modifiedId = originalId; |
768 | modifiedId.setManagerUri(QString()); // this will clear the local id! |
769 | modifiedId.setLocalId(originalId.localId()); // so reset it and make sure things don't fall over. |
770 | itemIn.setId(modifiedId); |
771 | stream1 << itemIn; |
772 | QVERIFY(buffer.size() > 0); |
773 | QDataStream stream2(buffer); |
774 | stream2 >> itemOut; |
775 | //QCOMPARE(itemOut, itemIn); // can't do QCOMPARE because detail keys get changed. |
776 | QVERIFY(itemOut.details() == itemIn.details()); |
777 | QVERIFY(itemOut.id() != itemIn.id()); // in this case, with null mgr uri, the id doesn't get serialized. |
778 | }*/ |
779 | |
780 | // fourth, stream an item with null ids |
781 | { |
782 | QDataStream stream1(&buffer, QIODevice::WriteOnly); |
783 | itemIn.setId(QOrganizerItemId()); |
784 | itemIn.setCollectionId(QOrganizerCollectionId()); |
785 | stream1 << itemIn; |
786 | QVERIFY(buffer.size() > 0); |
787 | QDataStream stream2(buffer); |
788 | stream2 >> itemOut; |
789 | //QCOMPARE(itemOut, itemIn); // can't do QCOMPARE because detail keys get changed. |
790 | QVERIFY(itemOut.details() == itemIn.details()); |
791 | QVERIFY(itemOut.id() == itemIn.id()); |
792 | } |
793 | |
794 | // fifth, stream an item with a collection id |
795 | { |
796 | QDataStream stream1(&buffer, QIODevice::WriteOnly); |
797 | itemIn.setId(QOrganizerItemId()); |
798 | itemIn.setCollectionId(originalCollectionId); |
799 | stream1 << itemIn; |
800 | QVERIFY(buffer.size() > 0); |
801 | QDataStream stream2(buffer); |
802 | stream2 >> itemOut; |
803 | //QCOMPARE(itemOut, itemIn); // can't do QCOMPARE because detail keys get changed. |
804 | QVERIFY(itemOut.details() == itemIn.details()); |
805 | QVERIFY(itemOut.collectionId() == itemIn.collectionId()); |
806 | QVERIFY(itemOut.id() == itemIn.id()); |
807 | } |
808 | |
809 | // id datastreaming |
810 | buffer.clear(); |
811 | QOrganizerItemId inputId; |
812 | QOrganizerItemId outputId; |
813 | |
814 | // first, stream the whole id (mgr uri set, local id set) |
815 | { |
816 | inputId = originalId; |
817 | QString serializedId = inputId.toString(); |
818 | outputId = QOrganizerItemId::fromString(idString: serializedId); |
819 | QCOMPARE(inputId, outputId); |
820 | |
821 | inputId = originalId; |
822 | buffer.clear(); |
823 | QDataStream stream1(&buffer, QIODevice::WriteOnly); |
824 | stream1 << inputId; |
825 | QVERIFY(buffer.size() > 0); |
826 | QDataStream stream2(buffer); |
827 | stream2 >> outputId; |
828 | QCOMPARE(inputId, outputId); |
829 | } |
830 | |
831 | // TODO : review tests |
832 | // second, stream a partial id (mgr uri null, local id set) |
833 | /* { |
834 | inputId.setManagerUri(QString()); |
835 | inputId.setLocalId(originalId.localId()); |
836 | buffer.clear(); |
837 | QDataStream stream1(&buffer, QIODevice::WriteOnly); |
838 | stream1 << inputId; |
839 | QVERIFY(buffer.size() > 0); |
840 | QDataStream stream2(buffer); |
841 | stream2 >> outputId; |
842 | |
843 | // because the manager uri is null, we cannot stream it in. |
844 | QVERIFY(outputId.isNull()); |
845 | QVERIFY(!inputId.isNull()); |
846 | } |
847 | |
848 | // third, stream a partial id (mgr uri set, local id null). |
849 | { |
850 | inputId.setManagerUri(originalId.managerUri()); |
851 | inputId.setLocalId(QOrganizerItemLocalId()); |
852 | buffer.clear(); |
853 | QDataStream stream1(&buffer, QIODevice::WriteOnly); |
854 | stream1 << inputId; |
855 | QVERIFY(buffer.size() > 0); |
856 | QDataStream stream2(buffer); |
857 | stream2 >> outputId; |
858 | QCOMPARE(inputId, outputId); |
859 | }*/ |
860 | |
861 | // fourth, stream a null id |
862 | { |
863 | inputId = QOrganizerItemId(); |
864 | QString serializedId = inputId.toString(); |
865 | outputId = QOrganizerItemId::fromString(idString: serializedId); |
866 | QCOMPARE(inputId, outputId); |
867 | |
868 | inputId = QOrganizerItemId(); |
869 | buffer.clear(); |
870 | QDataStream stream1(&buffer, QIODevice::WriteOnly); |
871 | stream1 << inputId; |
872 | QVERIFY(buffer.size() > 0); |
873 | QDataStream stream2(buffer); |
874 | stream2 >> outputId; |
875 | QCOMPARE(inputId, outputId); |
876 | } |
877 | |
878 | // TODO : review tests |
879 | // fifth, stream an id after changing it's manager uri string. |
880 | /* { |
881 | inputId.setManagerUri(originalId.managerUri()); |
882 | inputId.setLocalId(originalId.localId()); |
883 | inputId.setManagerUri("test manager uri"); // should clear the local id. |
884 | QVERIFY(inputId.localId() == QOrganizerItemLocalId()); |
885 | buffer.clear(); |
886 | QDataStream stream1(&buffer, QIODevice::WriteOnly); |
887 | stream1 << inputId; |
888 | QVERIFY(buffer.size() > 0); |
889 | QDataStream stream2(buffer); |
890 | stream2 >> outputId; |
891 | QCOMPARE(inputId, outputId); |
892 | } |
893 | |
894 | // sixth, stream an id after changing it's manager uri string, and resetting the local id. |
895 | // this should cause great problems, because the manager doesn't exist so it shouldn't |
896 | // be able to deserialize. Make sure it's handled gracefully. |
897 | { |
898 | inputId.setManagerUri(originalId.managerUri()); |
899 | inputId.setManagerUri("test manager uri"); // should clear the local id. |
900 | inputId.setLocalId(originalId.localId()); |
901 | buffer.clear(); |
902 | QDataStream stream1(&buffer, QIODevice::WriteOnly); |
903 | stream1 << inputId; |
904 | QVERIFY(buffer.size() > 0); |
905 | QDataStream stream2(buffer); |
906 | stream2 >> outputId; |
907 | QVERIFY(outputId.isNull()); |
908 | }*/ |
909 | } |
910 | |
911 | void tst_QOrganizerItem::traits() |
912 | { |
913 | QCOMPARE(sizeof(QOrganizerItem), sizeof(void *)); |
914 | QVERIFY(QTypeInfo<QOrganizerItem>::isComplex); |
915 | QVERIFY(!QTypeInfo<QOrganizerItem>::isStatic); |
916 | QVERIFY(!QTypeInfo<QOrganizerItem>::isLarge); |
917 | QVERIFY(!QTypeInfo<QOrganizerItem>::isPointer); |
918 | QVERIFY(!QTypeInfo<QOrganizerItem>::isDummy); |
919 | } |
920 | |
921 | void tst_QOrganizerItem::idTraits() |
922 | { |
923 | QCOMPARE(sizeof(QOrganizerItemId), 2*sizeof(void *)); |
924 | QVERIFY(QTypeInfo<QOrganizerItemId>::isComplex); |
925 | QVERIFY(!QTypeInfo<QOrganizerItemId>::isStatic); |
926 | QVERIFY(QTypeInfo<QOrganizerItemId>::isLarge); |
927 | QVERIFY(!QTypeInfo<QOrganizerItemId>::isPointer); |
928 | QVERIFY(!QTypeInfo<QOrganizerItemId>::isDummy); |
929 | } |
930 | |
931 | void tst_QOrganizerItem::event() |
932 | { |
933 | QOrganizerEvent testEvent; |
934 | QCOMPARE(testEvent.type(), QOrganizerItemType::TypeEvent); |
935 | |
936 | testEvent.setLocation("test address" ); |
937 | QCOMPARE(testEvent.location(), QString("test address" )); |
938 | |
939 | testEvent.setStartDateTime(QDateTime(QDate::currentDate())); |
940 | QCOMPARE(testEvent.startDateTime(), QDateTime(QDate::currentDate())); |
941 | testEvent.setEndDateTime(QDateTime(QDate::currentDate().addDays(days: 1))); |
942 | QCOMPARE(testEvent.endDateTime(), QDateTime(QDate::currentDate().addDays(1))); |
943 | QVERIFY(!testEvent.isAllDay()); // default to not all day |
944 | testEvent.setAllDay(true); |
945 | QVERIFY(testEvent.isAllDay()); |
946 | |
947 | testEvent.setPriority(QOrganizerItemPriority::VeryHighPriority); |
948 | QCOMPARE(testEvent.priority(), QOrganizerItemPriority::VeryHighPriority); |
949 | testEvent.setPriority(QOrganizerItemPriority::VeryLowPriority); |
950 | QCOMPARE(testEvent.priority(), QOrganizerItemPriority::VeryLowPriority); |
951 | |
952 | |
953 | QSet<QDate> rdates; |
954 | testEvent.setRecurrenceDate(QDate::currentDate()); |
955 | QCOMPARE(testEvent.recurrenceDates(), QSet<QDate>() << QDate::currentDate()); |
956 | rdates << QDate::currentDate() << QDate::currentDate().addDays(days: 3) << QDate::currentDate().addDays(days: 8); |
957 | testEvent.setRecurrenceDates(rdates); |
958 | QCOMPARE(testEvent.recurrenceDates(), rdates); |
959 | |
960 | QSet<QDate> exdates; |
961 | testEvent.setExceptionDate(QDate::currentDate()); |
962 | QCOMPARE(testEvent.exceptionDates(), QSet<QDate>() << QDate::currentDate()); |
963 | exdates << QDate::currentDate().addDays(days: 3); |
964 | testEvent.setExceptionDates(exdates); |
965 | QCOMPARE(testEvent.exceptionDates(), exdates); |
966 | |
967 | QSet<QOrganizerRecurrenceRule> rrules; |
968 | QOrganizerRecurrenceRule rrule; |
969 | |
970 | QVERIFY(rrule.limitType() == QOrganizerRecurrenceRule::NoLimit); |
971 | QVERIFY(rrule.limitCount() == -1); |
972 | QVERIFY(rrule.limitDate().isNull()); |
973 | |
974 | rrule.setLimit(1); |
975 | QVERIFY(rrule.limitType() == QOrganizerRecurrenceRule::CountLimit); |
976 | QVERIFY(rrule.limitCount() == 1); |
977 | QVERIFY(rrule.limitDate().isNull()); |
978 | |
979 | rrule.setLimit(-1); |
980 | QVERIFY(rrule.limitType() == QOrganizerRecurrenceRule::NoLimit); |
981 | QVERIFY(rrule.limitCount() == -1); |
982 | QVERIFY(rrule.limitDate().isNull()); |
983 | |
984 | rrule.setLimit(0); |
985 | QVERIFY(rrule.limitType() == QOrganizerRecurrenceRule::CountLimit); |
986 | QVERIFY(rrule.limitCount() == 0); |
987 | QVERIFY(rrule.limitDate().isNull()); |
988 | |
989 | rrule.setLimit(-100); |
990 | QVERIFY(rrule.limitType() == QOrganizerRecurrenceRule::NoLimit); |
991 | QVERIFY(rrule.limitCount() == -1); |
992 | QVERIFY(rrule.limitDate().isNull()); |
993 | |
994 | rrule.setLimit(QDate()); |
995 | QVERIFY(rrule.limitType() == QOrganizerRecurrenceRule::NoLimit); |
996 | QVERIFY(rrule.limitCount() == -1); |
997 | QVERIFY(rrule.limitDate().isNull()); |
998 | |
999 | rrule.setLimit(QDate(2010, 10, 6)); |
1000 | QVERIFY(rrule.limitType() == QOrganizerRecurrenceRule::DateLimit); |
1001 | QVERIFY(rrule.limitCount() == -1); |
1002 | QVERIFY(rrule.limitDate() == QDate(2010, 10, 6)); |
1003 | |
1004 | rrule.setLimit(QDate(2010, 13, 34)); |
1005 | QVERIFY(rrule.limitType() == QOrganizerRecurrenceRule::NoLimit); |
1006 | QVERIFY(rrule.limitCount() == -1); |
1007 | QVERIFY(rrule.limitDate() == QDate()); |
1008 | |
1009 | |
1010 | rrule.setLimit(2); |
1011 | rrule.setFrequency(QOrganizerRecurrenceRule::Daily); |
1012 | rrules << rrule; |
1013 | testEvent.setRecurrenceRule(rrule); |
1014 | QVERIFY(testEvent.recurrenceRules() == rrules); |
1015 | QVERIFY(testEvent.recurrenceRule() == rrule); |
1016 | testEvent.setRecurrenceRule(rrule); |
1017 | QVERIFY(testEvent.recurrenceRules() == rrules); |
1018 | QVERIFY(testEvent.recurrenceRule() == rrule); |
1019 | |
1020 | QSet<QOrganizerRecurrenceRule> exrules; |
1021 | QOrganizerRecurrenceRule exrule; |
1022 | exrule.setLimit(1); |
1023 | exrule.setFrequency(QOrganizerRecurrenceRule::Weekly); |
1024 | exrules << exrule; |
1025 | testEvent.setExceptionRules(exrules); |
1026 | QVERIFY(testEvent.exceptionRules() == exrules); |
1027 | QVERIFY(testEvent.exceptionRule() == exrule); |
1028 | testEvent.setExceptionRule(exrule); |
1029 | QVERIFY(testEvent.exceptionRules() == exrules); |
1030 | QVERIFY(testEvent.exceptionRule() == exrule); |
1031 | } |
1032 | |
1033 | void tst_QOrganizerItem::todo() |
1034 | { |
1035 | QOrganizerTodo testTodo; |
1036 | QCOMPARE(testTodo.type(), QOrganizerItemType::TypeTodo); |
1037 | |
1038 | QCOMPARE(testTodo.status(), QOrganizerTodoProgress::StatusNotStarted); |
1039 | testTodo.setStatus(QOrganizerTodoProgress::StatusInProgress); |
1040 | QCOMPARE(testTodo.status(), QOrganizerTodoProgress::StatusInProgress); |
1041 | |
1042 | QCOMPARE(testTodo.progressPercentage(), 0); |
1043 | testTodo.setProgressPercentage(50); |
1044 | QCOMPARE(testTodo.progressPercentage(), 50); |
1045 | testTodo.setStatus(QOrganizerTodoProgress::StatusComplete); |
1046 | QCOMPARE(testTodo.progressPercentage(), 50); // XXX TODO: should this update automatically? |
1047 | |
1048 | QDateTime currentDateTime = QDateTime::currentDateTime(); |
1049 | testTodo.setStartDateTime(currentDateTime); |
1050 | QCOMPARE(testTodo.startDateTime(), currentDateTime); |
1051 | testTodo.setDueDateTime(QDateTime(QDate::currentDate())); |
1052 | QCOMPARE(testTodo.dueDateTime(), QDateTime(QDate::currentDate())); |
1053 | testTodo.setFinishedDateTime(QDateTime(QDate::currentDate().addDays(days: 1))); |
1054 | QCOMPARE(testTodo.finishedDateTime(), QDateTime(QDate::currentDate().addDays(1))); |
1055 | |
1056 | QVERIFY(testTodo.isAllDay() == false); // default should not be all day event. |
1057 | testTodo.setAllDay(true); |
1058 | QVERIFY(testTodo.isAllDay() == true); |
1059 | testTodo.setAllDay(false); |
1060 | QVERIFY(testTodo.isAllDay() == false); |
1061 | |
1062 | testTodo.setPriority(QOrganizerItemPriority::VeryHighPriority); |
1063 | QCOMPARE(testTodo.priority(), QOrganizerItemPriority::VeryHighPriority); |
1064 | testTodo.setPriority(QOrganizerItemPriority::VeryLowPriority); |
1065 | QCOMPARE(testTodo.priority(), QOrganizerItemPriority::VeryLowPriority); |
1066 | |
1067 | QSet<QDate> rdates; |
1068 | rdates << QDate::currentDate() << QDate::currentDate().addDays(days: 3) << QDate::currentDate().addDays(days: 8); |
1069 | testTodo.setRecurrenceDates(rdates); |
1070 | QCOMPARE(testTodo.recurrenceDates(), rdates); |
1071 | |
1072 | QSet<QDate> exdates; |
1073 | exdates << QDate::currentDate().addDays(days: 3); |
1074 | testTodo.setExceptionDates(exdates); |
1075 | QCOMPARE(testTodo.exceptionDates(), exdates); |
1076 | |
1077 | QSet<QOrganizerRecurrenceRule> rrules; |
1078 | QOrganizerRecurrenceRule rrule; |
1079 | rrule.setLimit(2); |
1080 | rrule.setFrequency(QOrganizerRecurrenceRule::Daily); |
1081 | rrules << rrule; |
1082 | testTodo.setRecurrenceRules(rrules); |
1083 | QVERIFY(testTodo.recurrenceRules() == rrules); |
1084 | QVERIFY(testTodo.recurrenceRule() == rrule); |
1085 | testTodo.setRecurrenceRule(rrule); |
1086 | QVERIFY(testTodo.recurrenceRules() == rrules); |
1087 | QVERIFY(testTodo.recurrenceRule() == rrule); |
1088 | |
1089 | QSet<QOrganizerRecurrenceRule> exrules; |
1090 | QOrganizerRecurrenceRule exrule; |
1091 | exrule.setLimit(1); |
1092 | exrule.setFrequency(QOrganizerRecurrenceRule::Weekly); |
1093 | exrules << exrule; |
1094 | testTodo.setExceptionRules(exrules); |
1095 | QVERIFY(testTodo.exceptionRules() == exrules); |
1096 | QVERIFY(testTodo.exceptionRule() == exrule); |
1097 | testTodo.setExceptionRule(exrule); |
1098 | QVERIFY(testTodo.exceptionRules() == exrules); |
1099 | QVERIFY(testTodo.exceptionRule() == exrule); |
1100 | } |
1101 | |
1102 | void tst_QOrganizerItem::journal() |
1103 | { |
1104 | QOrganizerJournal testJournal; |
1105 | QCOMPARE(testJournal.type(), QOrganizerItemType::TypeJournal); |
1106 | |
1107 | QDateTime currDateTime = QDateTime::currentDateTime(); |
1108 | testJournal.setDateTime(currDateTime); |
1109 | QCOMPARE(testJournal.dateTime(), currDateTime); |
1110 | } |
1111 | |
1112 | void tst_QOrganizerItem::note() |
1113 | { |
1114 | QOrganizerNote testNote; |
1115 | QCOMPARE(testNote.type(), QOrganizerItemType::TypeNote); |
1116 | } |
1117 | |
1118 | void tst_QOrganizerItem::eventOccurrence() |
1119 | { |
1120 | QOrganizerEventOccurrence testEventOccurrence; |
1121 | QCOMPARE(testEventOccurrence.type(), QOrganizerItemType::TypeEventOccurrence); |
1122 | |
1123 | testEventOccurrence.setLocation("test address" ); |
1124 | QCOMPARE(testEventOccurrence.location(), QString("test address" )); |
1125 | |
1126 | testEventOccurrence.setStartDateTime(QDateTime(QDate::currentDate())); |
1127 | QCOMPARE(testEventOccurrence.startDateTime(), QDateTime(QDate::currentDate())); |
1128 | testEventOccurrence.setEndDateTime(QDateTime(QDate::currentDate().addDays(days: 1))); |
1129 | QCOMPARE(testEventOccurrence.endDateTime(), QDateTime(QDate::currentDate().addDays(1))); |
1130 | |
1131 | testEventOccurrence.setPriority(QOrganizerItemPriority::VeryHighPriority); |
1132 | QCOMPARE(testEventOccurrence.priority(), QOrganizerItemPriority::VeryHighPriority); |
1133 | testEventOccurrence.setPriority(QOrganizerItemPriority::VeryLowPriority); |
1134 | QCOMPARE(testEventOccurrence.priority(), QOrganizerItemPriority::VeryLowPriority); |
1135 | |
1136 | // the parent id and original date time must be tested properly in the manager unit test |
1137 | // but we will test the API mutator/accessor functions here. |
1138 | QOrganizerItemId id; |
1139 | testEventOccurrence.setParentId(id); |
1140 | QCOMPARE(testEventOccurrence.parentId(), id); |
1141 | QDateTime originalDateTime = QDateTime::currentDateTime(); |
1142 | testEventOccurrence.setOriginalDate(originalDateTime.date()); |
1143 | QCOMPARE(testEventOccurrence.originalDate(), originalDateTime.date()); |
1144 | } |
1145 | |
1146 | void tst_QOrganizerItem::todoOccurrence() |
1147 | { |
1148 | QOrganizerTodoOccurrence testTodoOccurrence; |
1149 | QCOMPARE(testTodoOccurrence.type(), QOrganizerItemType::TypeTodoOccurrence); |
1150 | |
1151 | QCOMPARE(testTodoOccurrence.status(), QOrganizerTodoProgress::StatusNotStarted); |
1152 | testTodoOccurrence.setStatus(QOrganizerTodoProgress::StatusInProgress); |
1153 | QCOMPARE(testTodoOccurrence.status(), QOrganizerTodoProgress::StatusInProgress); |
1154 | |
1155 | QCOMPARE(testTodoOccurrence.progressPercentage(), 0); |
1156 | testTodoOccurrence.setProgressPercentage(50); |
1157 | QCOMPARE(testTodoOccurrence.progressPercentage(), 50); |
1158 | testTodoOccurrence.setStatus(QOrganizerTodoProgress::StatusComplete); |
1159 | QCOMPARE(testTodoOccurrence.progressPercentage(), 50); // XXX TODO: should this update automatically? |
1160 | |
1161 | testTodoOccurrence.setStartDateTime(QDateTime(QDate::currentDate())); |
1162 | QCOMPARE(testTodoOccurrence.startDateTime(), QDateTime(QDate::currentDate())); |
1163 | testTodoOccurrence.setDueDateTime(QDateTime(QDate::currentDate())); |
1164 | QCOMPARE(testTodoOccurrence.dueDateTime(), QDateTime(QDate::currentDate())); |
1165 | testTodoOccurrence.setFinishedDateTime(QDateTime(QDate::currentDate().addDays(days: 1))); |
1166 | QCOMPARE(testTodoOccurrence.finishedDateTime(), QDateTime(QDate::currentDate().addDays(1))); |
1167 | |
1168 | testTodoOccurrence.setPriority(QOrganizerItemPriority::VeryHighPriority); |
1169 | QCOMPARE(testTodoOccurrence.priority(), QOrganizerItemPriority::VeryHighPriority); |
1170 | testTodoOccurrence.setPriority(QOrganizerItemPriority::VeryLowPriority); |
1171 | QCOMPARE(testTodoOccurrence.priority(), QOrganizerItemPriority::VeryLowPriority); |
1172 | |
1173 | // the parent id and original date time must be tested properly in the manager unit test |
1174 | // but we will test the API mutator/accessor functions here. |
1175 | QOrganizerItemId id; |
1176 | testTodoOccurrence.setParentId(id); |
1177 | QCOMPARE(testTodoOccurrence.parentId(), id); |
1178 | QDateTime originalDateTime = QDateTime::currentDateTime(); |
1179 | testTodoOccurrence.setOriginalDate(originalDateTime.date()); |
1180 | QCOMPARE(testTodoOccurrence.originalDate(), originalDateTime.date()); |
1181 | } |
1182 | |
1183 | |
1184 | |
1185 | void tst_QOrganizerItem::testDebugStreamOut() |
1186 | { |
1187 | QOrganizerRecurrenceRule rrule; |
1188 | // Testing the empty case |
1189 | QTest::ignoreMessage(type: QtDebugMsg, message: "QOrganizerRecurrenceRule(frequency=0,interval=1,no limit,daysOfWeek=\"\",daysOfMonth=\"\",daysOfYear=\"\",monthsOfYear=\"\",positions=\"\",firstDayOfWeek=1)" ); |
1190 | qDebug() << rrule; |
1191 | |
1192 | // Testing a completely filled case |
1193 | rrule.setLimit(1); |
1194 | rrule.setFrequency(QOrganizerRecurrenceRule::Weekly); |
1195 | rrule.setInterval(10); |
1196 | rrule.setLimit(20); |
1197 | QSet<Qt::DayOfWeek> days; |
1198 | days << Qt::Thursday << Qt::Friday; |
1199 | rrule.setDaysOfWeek(days); |
1200 | QSet<int> daysM; |
1201 | daysM << 1 << 2 << 3; |
1202 | rrule.setDaysOfMonth(daysM); |
1203 | QSet<int> daysY; |
1204 | daysY << 5 << 6 << 7 << 8; |
1205 | rrule.setDaysOfYear(daysY); |
1206 | QSet<QOrganizerRecurrenceRule::Month> months; |
1207 | months << QOrganizerRecurrenceRule::January << QOrganizerRecurrenceRule::February; |
1208 | rrule.setMonthsOfYear(months); |
1209 | QSet<int> pos; |
1210 | pos << -1; |
1211 | rrule.setPositions(pos); |
1212 | Qt::DayOfWeek firstDay; |
1213 | firstDay = Qt::Tuesday; |
1214 | rrule.setFirstDayOfWeek(firstDay); |
1215 | QTest::ignoreMessage(type: QtDebugMsg, message: "QOrganizerRecurrenceRule(frequency=2,interval=10,limitCount=20,daysOfWeek=\"4 5 \",daysOfMonth=\"1 2 3 \",daysOfYear=\"5 6 7 8 \",monthsOfYear=\"1 2 \",positions=\"-1 \",firstDayOfWeek=2)" ); |
1216 | qDebug() << rrule; |
1217 | } |
1218 | |
1219 | void tst_QOrganizerItem::itemsCompare() |
1220 | { |
1221 | QOrganizerItemDisplayLabel displayLabel; |
1222 | displayLabel.setLabel("test label" ); |
1223 | QOrganizerItemDescription descr; |
1224 | descr.setDescription("test description" ); |
1225 | QOrganizerItemComment ; |
1226 | comment.setComment("yet another test comment" ); |
1227 | QOrganizerItemLocation location; |
1228 | location.setLabel("another test address label" ); |
1229 | QOrganizerEventAttendee a; |
1230 | a.setAttendeeId("123456" ); |
1231 | a.setEmailAddress("people@qt-project.org" ); |
1232 | a.setName("people" ); |
1233 | |
1234 | QOrganizerEventAttendee a1; |
1235 | a1.setAttendeeId("777777" ); |
1236 | a1.setName("people1" ); |
1237 | a1.setEmailAddress("people1@qt-project.org" ); |
1238 | |
1239 | QOrganizerEventAttendee a2; |
1240 | a2.setAttendeeId("9jjjkkk" ); |
1241 | a2.setName("people2" ); |
1242 | a2.setEmailAddress("people1@qt-project.org" ); |
1243 | |
1244 | QOrganizerEventAttendee a3; |
1245 | a2.setAttendeeId("ppppp" ); |
1246 | a2.setName("people3" ); |
1247 | a2.setEmailAddress("people3@qt-project.org" ); |
1248 | |
1249 | QOrganizerEventTime etr; |
1250 | etr.setStartDateTime(QDateTime(QDate::currentDate())); |
1251 | etr.setEndDateTime(QDateTime(QDate::currentDate().addDays(days: 1))); |
1252 | |
1253 | QOrganizerItem item1; |
1254 | QOrganizerItem item2; |
1255 | item1.saveDetail(detail: &displayLabel); |
1256 | item1.saveDetail(detail: &descr); |
1257 | item1.saveDetail(detail: &comment); |
1258 | item1.saveDetail(detail: &location); |
1259 | item1.saveDetail(detail: &etr); |
1260 | |
1261 | item2.saveDetail(detail: &etr); |
1262 | item2.saveDetail(detail: &location); |
1263 | item2.saveDetail(detail: &comment); |
1264 | item2.saveDetail(detail: &descr); |
1265 | QVERIFY(item1 != item2); |
1266 | item2.saveDetail(detail: &displayLabel); |
1267 | QVERIFY(item1 == item2); |
1268 | |
1269 | // Identical details compare test |
1270 | // Same type details but different amount |
1271 | item1.addTag(tag: "TestTag1" ); |
1272 | item1.addTag(tag: "TestTag2" ); |
1273 | item1.saveDetail(detail: &a); |
1274 | |
1275 | item2.addTag(tag: "TestTag1" ); |
1276 | item2.saveDetail(detail: &a); |
1277 | item2.saveDetail(detail: &a1); |
1278 | QVERIFY(item1 != item2); |
1279 | |
1280 | // Make they same but different orders |
1281 | item1.saveDetail(detail: &a1); |
1282 | item2.addTag(tag: "TestTag2" ); |
1283 | QVERIFY(item1 == item2); |
1284 | |
1285 | item1.saveDetail(detail: &a2); |
1286 | item2.saveDetail(detail: &a3); |
1287 | QVERIFY(item1 != item2); |
1288 | item1.saveDetail(detail: &a3); |
1289 | item2.saveDetail(detail: &a2); |
1290 | QVERIFY(item1 == item2); |
1291 | } |
1292 | |
1293 | QTEST_MAIN(tst_QOrganizerItem) |
1294 | #include "tst_qorganizeritem.moc" |
1295 | |