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 <QtOrganizer/qorganizer.h> |
37 | |
38 | //TESTED_COMPONENT=src/organizer |
39 | |
40 | QTORGANIZER_USE_NAMESPACE |
41 | class tst_QOrganizerItemDetails : public QObject |
42 | { |
43 | Q_OBJECT |
44 | |
45 | public: |
46 | tst_QOrganizerItemDetails(); |
47 | virtual ~tst_QOrganizerItemDetails(); |
48 | |
49 | public slots: |
50 | void init(); |
51 | void cleanup(); |
52 | |
53 | private slots: |
54 | void compare(); |
55 | |
56 | // leaf class testing |
57 | void description(); |
58 | void displayLabel(); |
59 | void guid(); |
60 | void location(); |
61 | void parent(); |
62 | void priority(); |
63 | void recurrence(); |
64 | void tag(); |
65 | void timestamp(); |
66 | void type(); |
67 | |
68 | void todoProgress(); |
69 | |
70 | // time range |
71 | void eventTime(); |
72 | void journalTime(); |
73 | void todoTime(); |
74 | |
75 | // reminders |
76 | void reminder(); |
77 | void audibleReminder(); |
78 | void emailReminder(); |
79 | void visualReminder(); |
80 | |
81 | void attendee(); |
82 | void rsvp(); |
83 | void classification(); |
84 | void version(); |
85 | }; |
86 | |
87 | tst_QOrganizerItemDetails::tst_QOrganizerItemDetails() |
88 | { |
89 | } |
90 | |
91 | tst_QOrganizerItemDetails::~tst_QOrganizerItemDetails() |
92 | { |
93 | } |
94 | |
95 | void tst_QOrganizerItemDetails::init() |
96 | { |
97 | } |
98 | |
99 | void tst_QOrganizerItemDetails::cleanup() |
100 | { |
101 | } |
102 | |
103 | void tst_QOrganizerItemDetails::compare() |
104 | { |
105 | QOrganizerItemRecurrence r, r2; |
106 | QVERIFY(r == r2); |
107 | QVERIFY(QOrganizerItemDetail() != r); |
108 | |
109 | QOrganizerRecurrenceRule testRule; |
110 | testRule.setFrequency(QOrganizerRecurrenceRule::Weekly); |
111 | testRule.setLimit(4); |
112 | QSet<QOrganizerRecurrenceRule> rrules; |
113 | rrules << testRule; |
114 | |
115 | QOrganizerRecurrenceRule exrule; |
116 | exrule.setFrequency(QOrganizerRecurrenceRule::Daily); |
117 | testRule.setLimit(12); |
118 | QSet<QOrganizerRecurrenceRule> exrules; |
119 | exrules << exrule; |
120 | |
121 | QSet<QDate> rdates, exdates; |
122 | rdates << QDate(2010, 10, 13); |
123 | exdates << QDate(2010, 11, 17) << QDate(2010, 11, 20); |
124 | |
125 | r.setRecurrenceRules(rrules); |
126 | QVERIFY(r != r2); |
127 | r2.setRecurrenceRules(rrules); |
128 | QVERIFY(r == r2); |
129 | r.setExceptionRules(exrules); |
130 | QVERIFY(r != r2); |
131 | r2.setExceptionRules(exrules); |
132 | QVERIFY(r == r2); |
133 | r.setRecurrenceDates(rdates); |
134 | QVERIFY(r != r2); |
135 | r2.setRecurrenceDates(rdates); |
136 | QVERIFY(r == r2); |
137 | r.setExceptionDates(exdates); |
138 | QVERIFY(r != r2); |
139 | r2.setExceptionDates(exdates); |
140 | QVERIFY(r == r2); |
141 | |
142 | QOrganizerEvent e, e2; |
143 | QCOMPARE(e.details(QOrganizerItemDetail::TypeRecurrence).size(), 0); |
144 | QVERIFY(e == e2); |
145 | |
146 | // now save |
147 | QVERIFY(e.saveDetail(&r)); |
148 | QCOMPARE(e.details(QOrganizerItemDetail::TypeRecurrence).size(), 1); |
149 | QVERIFY(e.detail(QOrganizerItemDetail::TypeRecurrence) == r); |
150 | QVERIFY(e != e2); |
151 | |
152 | QVERIFY(e2.saveDetail(&r2)); |
153 | QCOMPARE(e2.details(QOrganizerItemDetail::TypeRecurrence).size(), 1); |
154 | QVERIFY(e2.detail(QOrganizerItemDetail::TypeRecurrence) == r2); |
155 | QVERIFY(e == e2); |
156 | |
157 | // update |
158 | exdates << QDate(2010, 10, 17); |
159 | r.setExceptionDates(exdates); |
160 | QVERIFY(r != r2); |
161 | QVERIFY(e.detail(QOrganizerItemDetail::TypeRecurrence) != r); |
162 | QVERIFY(e.detail(QOrganizerItemDetail::TypeRecurrence) == r2); |
163 | QVERIFY(e.saveDetail(&r)); |
164 | QVERIFY(e.detail(QOrganizerItemDetail::TypeRecurrence) == r); |
165 | QVERIFY(e.detail(QOrganizerItemDetail::TypeRecurrence) != r2); |
166 | QVERIFY(e != e2); |
167 | |
168 | // remove. |
169 | QVERIFY(e.removeDetail(&r)); |
170 | QVERIFY(e != e2); |
171 | QVERIFY(e2.removeDetail(&r2)); |
172 | QVERIFY(e == e2); |
173 | |
174 | QVERIFY(e.saveDetail(&r)); |
175 | e2 = QOrganizerEvent(); |
176 | QVERIFY(e != e2); |
177 | e2 = e; |
178 | QVERIFY(e == e2); |
179 | } |
180 | |
181 | void tst_QOrganizerItemDetails::description() |
182 | { |
183 | QOrganizerItemDescription d1; |
184 | QOrganizerItem oi; |
185 | QVERIFY(d1.description().isEmpty()); |
186 | QVERIFY(d1.value(QOrganizerItemDescription::FieldDescription).isNull()); |
187 | d1.setValue(field: QOrganizerItemDescription::FieldDescription, value: "Test" ); |
188 | QVERIFY(d1.value(QOrganizerItemDescription::FieldDescription) == QString("Test" )); |
189 | QVERIFY(d1.description() == QString("Test" )); |
190 | |
191 | QOrganizerItemDescription d2; |
192 | d2.setValue(field: QOrganizerItemDescription::FieldDescription, value: "Test 2" ); |
193 | |
194 | // test property add -- description is unique. |
195 | QVERIFY(oi.saveDetail(&d2)); |
196 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeDescription).count(), 1); // count should be 1 |
197 | QVERIFY(oi.saveDetail(&d1)); |
198 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeDescription).count(), 1); // count should be 1 |
199 | |
200 | // test property update |
201 | d1.setDescription("Test 3" ); |
202 | QVERIFY(oi.saveDetail(&d1)); |
203 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeDescription).count(), 1); // count should be 1 |
204 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeDescription).value(QOrganizerItemDescription::FieldDescription) == QString("Test 3" )); |
205 | |
206 | // test property remove |
207 | QVERIFY(oi.removeDetail(&d1)); |
208 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeDescription).count(), 0); |
209 | } |
210 | |
211 | void tst_QOrganizerItemDetails::displayLabel() |
212 | { |
213 | QOrganizerItemDisplayLabel d1; |
214 | QOrganizerItem oi; |
215 | |
216 | QVERIFY(d1.label().isEmpty()); |
217 | QVERIFY(d1.value(QOrganizerItemDisplayLabel::FieldLabel).isNull()); |
218 | d1.setValue(field: QOrganizerItemDisplayLabel::FieldLabel, value: "Test" ); |
219 | QVERIFY(d1.value(QOrganizerItemDisplayLabel::FieldLabel) == QString("Test" )); |
220 | QVERIFY(d1.label() == QString("Test" )); |
221 | |
222 | QOrganizerItemDisplayLabel d2; |
223 | d2.setValue(field: QOrganizerItemDisplayLabel::FieldLabel, value: "Test 2" ); |
224 | |
225 | // test property add - should update. |
226 | QVERIFY(oi.saveDetail(&d2)); |
227 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeDisplayLabel).count(), 1); |
228 | QVERIFY(oi.saveDetail(&d1)); |
229 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeDisplayLabel).count(), 1); |
230 | |
231 | // test property update - should update |
232 | d1.setLabel("Test 3" ); |
233 | QVERIFY(oi.saveDetail(&d1)); |
234 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeDisplayLabel).count(), 1); |
235 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeDisplayLabel).value(QOrganizerItemDisplayLabel::FieldLabel) == QString("Test 3" )); |
236 | |
237 | // test property remove |
238 | QVERIFY(oi.removeDetail(&d1)); // can remove display label. it's unique but not required. |
239 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeDisplayLabel).count(), 0); |
240 | } |
241 | |
242 | |
243 | void tst_QOrganizerItemDetails::guid() |
244 | { |
245 | QOrganizerItem oi; |
246 | QOrganizerItemGuid g1, g2; |
247 | |
248 | // test property set |
249 | g1.setGuid("1234" ); |
250 | QCOMPARE(g1.guid(), QString("1234" )); |
251 | QCOMPARE(g1.value(QOrganizerItemGuid::FieldGuid).toString(), QString("1234" )); |
252 | |
253 | // test property add |
254 | QVERIFY(oi.saveDetail(&g1)); |
255 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeGuid).count(), 1); |
256 | QCOMPARE(QOrganizerItemGuid(oi.details(QOrganizerItemDetail::TypeGuid).value(0)).guid(), g1.guid()); |
257 | |
258 | // test property update |
259 | g1.setValue(field: 101,value: "label1" ); |
260 | g1.setGuid("12345" ); |
261 | QVERIFY(oi.saveDetail(&g1)); |
262 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeGuid).value(0).value(101).toString(), QString("label1" )); |
263 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeGuid).value(0).value(QOrganizerItemGuid::FieldGuid).toString(), QString("12345" )); |
264 | |
265 | // test property remove |
266 | QVERIFY(oi.removeDetail(&g1)); |
267 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeGuid).count(), 0); |
268 | QVERIFY(oi.saveDetail(&g2)); |
269 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeGuid).count(), 1); |
270 | QVERIFY(oi.removeDetail(&g2)); |
271 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeGuid).count(), 0); |
272 | QVERIFY(oi.removeDetail(&g2) == false); |
273 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeGuid).count(), 0); |
274 | } |
275 | |
276 | void tst_QOrganizerItemDetails::location() |
277 | { |
278 | QOrganizerItemLocation l1; |
279 | QOrganizerItem oi; |
280 | QVERIFY(l1.isEmpty()); |
281 | |
282 | l1.setLatitude(89.999); |
283 | QVERIFY(!l1.isEmpty()); |
284 | QVERIFY(l1.latitude() == 89.999); |
285 | l1.setValue(field: QOrganizerItemLocation::FieldLatitude, value: -89.12345); |
286 | QVERIFY(l1.value(QOrganizerItemLocation::FieldLatitude) == -89.12345); |
287 | l1.setLatitude(-90.12345); |
288 | l1.setLatitude(91); |
289 | QVERIFY(l1.latitude() == -89.12345); |
290 | |
291 | l1.setLongitude(179); |
292 | QVERIFY(l1.longitude() == 179); |
293 | l1.setValue(field: QOrganizerItemLocation::FieldLongitude, value: -179.54321); |
294 | QVERIFY(l1.value(QOrganizerItemLocation::FieldLongitude) == -179.54321); |
295 | l1.setLongitude(180.1); |
296 | l1.setLongitude(-180.1); |
297 | QVERIFY(l1.longitude() == -179.54321); |
298 | |
299 | l1.setLabel("test" ); |
300 | QVERIFY(l1.label() == QString("test" )); |
301 | |
302 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).size() == 0); |
303 | QVERIFY(oi.saveDetail(&l1)); |
304 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).size() == 1); |
305 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeLocation) == l1); |
306 | |
307 | l1.setLabel("test 2" ); |
308 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeLocation) != l1); |
309 | QVERIFY(oi.saveDetail(&l1)); // update. |
310 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).size() == 1); // should update, not add another. |
311 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeLocation) == l1); |
312 | |
313 | oi.removeDetail(detail: &l1); |
314 | QVERIFY(oi.details(QOrganizerItemDetail::TypeLocation).size() == 0); |
315 | } |
316 | |
317 | void tst_QOrganizerItemDetails::parent() |
318 | { |
319 | QOrganizerItemParent p; |
320 | QOrganizerItem oi; |
321 | |
322 | // hrm, how to test parent local id? |
323 | |
324 | QVERIFY(p.isEmpty()); |
325 | p.setOriginalDate(QDate(2010, 10, 13)); |
326 | QVERIFY(p.originalDate() == QDate(2010, 10, 13)); |
327 | QVERIFY(!p.isEmpty()); |
328 | |
329 | QVERIFY(oi.saveDetail(&p)); |
330 | QVERIFY(oi.details(QOrganizerItemDetail::TypeParent).size() == 1); |
331 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeParent) == p); |
332 | |
333 | p.setOriginalDate(QDate(2010, 10, 14)); |
334 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeParent) != p); |
335 | QVERIFY(oi.saveDetail(&p)); // update |
336 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeParent) == p); |
337 | |
338 | QVERIFY(oi.removeDetail(&p)); |
339 | QVERIFY(oi.details(QOrganizerItemDetail::TypeParent).size() == 0); |
340 | } |
341 | |
342 | void tst_QOrganizerItemDetails::priority() |
343 | { |
344 | QOrganizerItemPriority p; |
345 | QOrganizerItem oi; |
346 | |
347 | QVERIFY(p.isEmpty()); |
348 | p.setValue(field: QOrganizerItemPriority::FieldPriority, value: QOrganizerItemPriority::VeryHighPriority); |
349 | QVERIFY(p.priority() == QOrganizerItemPriority::VeryHighPriority); |
350 | QVERIFY(oi.saveDetail(&p)); |
351 | QVERIFY(oi.details(QOrganizerItemDetail::TypePriority).size() == 1); |
352 | QVERIFY(oi.detail(QOrganizerItemDetail::TypePriority) == p); |
353 | |
354 | p.setPriority(QOrganizerItemPriority::VeryLowPriority); |
355 | QVERIFY(oi.detail(QOrganizerItemDetail::TypePriority) != p); |
356 | QVERIFY(oi.saveDetail(&p)); |
357 | QVERIFY(oi.details(QOrganizerItemDetail::TypePriority).size() == 1); // update shouldn't add another detail. |
358 | QVERIFY(oi.detail(QOrganizerItemDetail::TypePriority) == p); |
359 | |
360 | QVERIFY(oi.removeDetail(&p)); |
361 | QVERIFY(oi.details(QOrganizerItemDetail::TypePriority).size() == 0); |
362 | } |
363 | |
364 | void tst_QOrganizerItemDetails::recurrence() |
365 | { |
366 | QOrganizerItemRecurrence r; |
367 | QOrganizerEvent e; |
368 | |
369 | QOrganizerRecurrenceRule testRule; |
370 | testRule.setFrequency(QOrganizerRecurrenceRule::Weekly); |
371 | testRule.setLimit(4); |
372 | QSet<QOrganizerRecurrenceRule> rrules; |
373 | rrules << testRule; |
374 | |
375 | QOrganizerRecurrenceRule exrule; |
376 | exrule.setFrequency(QOrganizerRecurrenceRule::Daily); |
377 | testRule.setLimit(12); |
378 | QSet<QOrganizerRecurrenceRule> exrules; |
379 | exrules << exrule; |
380 | |
381 | QSet<QDate> rdates, exdates; |
382 | rdates << QDate(2010, 10, 13); |
383 | exdates << QDate(2010, 11, 17) << QDate(2010, 11, 20); |
384 | |
385 | QVERIFY(e.details(QOrganizerItemDetail::TypeRecurrence).size() == 0); |
386 | r.setRecurrenceRules(rrules); |
387 | QVERIFY(r.recurrenceRules() == rrules); |
388 | QVERIFY(r.recurrenceDates().isEmpty()); |
389 | QVERIFY(r.exceptionRules().isEmpty()); |
390 | |
391 | r.setExceptionRules(exrules); |
392 | QVERIFY(r.recurrenceRules() == rrules); |
393 | QVERIFY(r.exceptionRules() == exrules); |
394 | QVERIFY(r.exceptionDates().isEmpty()); |
395 | |
396 | r.setRecurrenceDates(rdates); |
397 | QVERIFY(r.recurrenceDates() == rdates); |
398 | QVERIFY(r.exceptionDates().isEmpty()); |
399 | QVERIFY(r.recurrenceRules() == rrules); |
400 | QVERIFY(r.exceptionRules() == exrules); |
401 | |
402 | r.setExceptionDates(exdates); |
403 | QVERIFY(r.recurrenceDates() == rdates); |
404 | QVERIFY(r.exceptionDates() == exdates); |
405 | QVERIFY(r.recurrenceRules() == rrules); |
406 | QVERIFY(r.exceptionRules() == exrules); |
407 | |
408 | // now save. |
409 | QVERIFY(e.saveDetail(&r)); |
410 | QVERIFY(e.details(QOrganizerItemDetail::TypeRecurrence).size() == 1); |
411 | QVERIFY(e.detail(QOrganizerItemDetail::TypeRecurrence) == r); |
412 | |
413 | // update |
414 | exdates << QDate(2010, 10, 17); |
415 | r.setExceptionDates(exdates); |
416 | QVERIFY(e.detail(QOrganizerItemDetail::TypeRecurrence) != r); |
417 | QVERIFY(e.saveDetail(&r)); |
418 | QVERIFY(e.detail(QOrganizerItemDetail::TypeRecurrence) == r); |
419 | QVERIFY(e.details(QOrganizerItemDetail::TypeRecurrence).size() == 1); // should update, not add another. |
420 | |
421 | // remove. |
422 | QVERIFY(e.removeDetail(&r)); |
423 | QVERIFY(e.details(QOrganizerItemDetail::TypeRecurrence).size() == 0); |
424 | } |
425 | |
426 | void tst_QOrganizerItemDetails::tag() |
427 | { |
428 | QOrganizerItem oi; |
429 | QOrganizerItemTag t1, t2; |
430 | |
431 | // test property set |
432 | t1.setTag("red" ); |
433 | QCOMPARE(t1.tag(), QString("red" )); |
434 | QCOMPARE(t1.value(QOrganizerItemTag::FieldTag).toString(), QString("red" )); |
435 | |
436 | // test property add |
437 | QVERIFY(oi.saveDetail(&t1)); |
438 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeTag).count(), 1); |
439 | QCOMPARE(QOrganizerItemTag(oi.details(QOrganizerItemDetail::TypeTag).value(0)).tag(), t1.tag()); |
440 | QVERIFY(oi.saveDetail(&t2)); |
441 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeTag).count(), 2); |
442 | |
443 | // test property update |
444 | t1.setValue(field: 101,value: "label1" ); |
445 | t1.setTag("green" ); |
446 | QVERIFY(oi.saveDetail(&t1)); |
447 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeTag).value(0).value(101).toString(), QString("label1" )); |
448 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeTag).value(0).value(QOrganizerItemTag::FieldTag).toString(), QString("green" )); |
449 | |
450 | // test property remove |
451 | QVERIFY(oi.removeDetail(&t1)); |
452 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeTag).count(), 1); |
453 | QVERIFY(oi.removeDetail(&t2)); |
454 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeTag).count(), 0); |
455 | QVERIFY(oi.removeDetail(&t2) == false); |
456 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeTag).count(), 0); |
457 | } |
458 | |
459 | |
460 | void tst_QOrganizerItemDetails::timestamp() |
461 | { |
462 | QOrganizerItem oi; |
463 | QOrganizerItemTimestamp t1, t2; |
464 | QDateTime modified = QDateTime::currentDateTime(); |
465 | QDateTime created = modified.addSecs(secs: -43); |
466 | |
467 | // test property set |
468 | t1.setCreated(created); |
469 | QCOMPARE(t1.created(), created); |
470 | QCOMPARE(t1.value(QOrganizerItemTimestamp::FieldCreated).toDateTime(), created); |
471 | |
472 | // test property add |
473 | QVERIFY(oi.saveDetail(&t1)); |
474 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeTimestamp).count(), 1); |
475 | QCOMPARE(QOrganizerItemTimestamp(oi.details(QOrganizerItemDetail::TypeTimestamp).value(0)).created(), t1.created()); |
476 | |
477 | // test property update |
478 | t1.setValue(field: 101,value: "label1" ); |
479 | t1.setLastModified(modified); |
480 | QVERIFY(oi.saveDetail(&t1)); |
481 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeTimestamp).value(0).value(101).toString(), QString("label1" )); |
482 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeTimestamp).value(0).value(QOrganizerItemTimestamp::FieldCreated).toDateTime(), created); |
483 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeTimestamp).value(0).value(QOrganizerItemTimestamp::FieldLastModified).toDateTime(), modified); |
484 | |
485 | // test property remove |
486 | QVERIFY(oi.removeDetail(&t1)); |
487 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeTimestamp).count(), 0); |
488 | t2.setCreated(created.addSecs(secs: 15)); |
489 | QVERIFY(oi.saveDetail(&t2)); |
490 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeTimestamp).count(), 1); |
491 | QVERIFY(oi.removeDetail(&t2)); |
492 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeTimestamp).count(), 0); |
493 | QVERIFY(oi.removeDetail(&t2) == false); |
494 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeTimestamp).count(), 0); |
495 | } |
496 | |
497 | void tst_QOrganizerItemDetails::todoProgress() |
498 | { |
499 | QOrganizerTodoProgress p; |
500 | QOrganizerTodo t; |
501 | |
502 | QVERIFY(p.status() == QOrganizerTodoProgress::StatusNotStarted); |
503 | QVERIFY(p.isEmpty()); |
504 | p.setStatus(QOrganizerTodoProgress::StatusInProgress); |
505 | QVERIFY(!p.isEmpty()); |
506 | QVERIFY(p.status() == QOrganizerTodoProgress::StatusInProgress); |
507 | |
508 | p.setPercentageComplete(50); |
509 | QVERIFY(p.percentageComplete() == 50); |
510 | p.setPercentageComplete(200); // this should fail |
511 | QVERIFY(p.percentageComplete() == 50); // value should remain unchanged. |
512 | |
513 | p.setFinishedDateTime(QDateTime(QDate(2010, 10, 13))); |
514 | QVERIFY(p.finishedDateTime() == QDateTime(QDate(2010, 10, 13))); |
515 | QVERIFY(p.status() != QOrganizerTodoProgress::StatusComplete); // XXX TODO: should this be automatic? |
516 | p.setPercentageComplete(100); |
517 | QVERIFY(p.percentageComplete() == 100); |
518 | QVERIFY(p.status() != QOrganizerTodoProgress::StatusComplete); // XXX TODO: should this be automatic? |
519 | |
520 | // add |
521 | QVERIFY(t.saveDetail(&p)); |
522 | QVERIFY(t.details(QOrganizerItemDetail::TypeTodoProgress).size() == 1); |
523 | QVERIFY(t.detail(QOrganizerItemDetail::TypeTodoProgress) == p); |
524 | |
525 | // update |
526 | p.setStatus(QOrganizerTodoProgress::StatusComplete); |
527 | QVERIFY(p.status() == QOrganizerTodoProgress::StatusComplete); |
528 | QVERIFY(t.detail(QOrganizerItemDetail::TypeTodoProgress) != p); |
529 | QVERIFY(t.saveDetail(&p)); |
530 | QVERIFY(t.details(QOrganizerItemDetail::TypeTodoProgress).size() == 1); // update, not add another |
531 | QVERIFY(t.detail(QOrganizerItemDetail::TypeTodoProgress) == p); |
532 | |
533 | // remove |
534 | QVERIFY(t.removeDetail(&p)); |
535 | QVERIFY(t.details(QOrganizerItemDetail::TypeTodoProgress).size() == 0); |
536 | } |
537 | |
538 | void tst_QOrganizerItemDetails::type() |
539 | { |
540 | QOrganizerItem oi; |
541 | QOrganizerItemType t1, t2; |
542 | |
543 | QOrganizerEvent e; |
544 | QOrganizerNote n; |
545 | QOrganizerTodo t; |
546 | QOrganizerJournal j; |
547 | QOrganizerEventOccurrence eo; |
548 | QOrganizerTodoOccurrence to; |
549 | QVERIFY(e.type() == QOrganizerItemType::TypeEvent); |
550 | QVERIFY(n.type() == QOrganizerItemType::TypeNote); |
551 | QVERIFY(t.type() == QOrganizerItemType::TypeTodo); |
552 | QVERIFY(j.type() == QOrganizerItemType::TypeJournal); |
553 | QVERIFY(eo.type() == QOrganizerItemType::TypeEventOccurrence); |
554 | QVERIFY(to.type() == QOrganizerItemType::TypeTodoOccurrence); |
555 | |
556 | // test property set |
557 | t1.setType(QOrganizerItemType::TypeEvent); |
558 | QCOMPARE(t1.type(), QOrganizerItemType::TypeEvent); |
559 | QCOMPARE(static_cast<QOrganizerItemType::ItemType>(t1.value(QOrganizerItemType::FieldType).toInt()), QOrganizerItemType::TypeEvent); |
560 | |
561 | // test property add |
562 | QVERIFY(oi.saveDetail(&t1)); |
563 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeItemType).count(), 1); |
564 | QCOMPARE(QOrganizerItemType(oi.details(QOrganizerItemDetail::TypeItemType).value(0)).type(), t1.type()); |
565 | |
566 | // test property update |
567 | t1.setType(QOrganizerItemType::TypeTodo); |
568 | QVERIFY(oi.saveDetail(&t1)); |
569 | QCOMPARE(static_cast<QOrganizerItemType::ItemType>(oi.details(QOrganizerItemDetail::TypeItemType).value(0).value(QOrganizerItemType::FieldType).toInt()), QOrganizerItemType::TypeTodo); |
570 | |
571 | // test property remove |
572 | QVERIFY(!oi.removeDetail(&t1)); // cannot remove type |
573 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeItemType).count(), 1); |
574 | t2.setType(QOrganizerItemType::TypeNote); |
575 | QVERIFY(oi.saveDetail(&t2)); // overwrites t1 |
576 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeItemType).count(), 1); |
577 | QVERIFY(!oi.removeDetail(&t2)); // cannot remove type - "succeeds" but count remains unchanged |
578 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeItemType).count(), 1); |
579 | QVERIFY(!oi.removeDetail(&t2)); |
580 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeItemType).count(), 1); |
581 | } |
582 | |
583 | |
584 | void tst_QOrganizerItemDetails::eventTime() |
585 | { |
586 | QOrganizerEventTime r; |
587 | QOrganizerEvent e; |
588 | |
589 | QVERIFY(r.isEmpty()); |
590 | QVERIFY(!r.isAllDay()); |
591 | |
592 | r.setStartDateTime(QDateTime(QDate(2010, 10, 13))); |
593 | QVERIFY(r.startDateTime() == QDateTime(QDate(2010, 10, 13))); |
594 | QVERIFY(!r.isAllDay()); |
595 | r.setAllDay(true); |
596 | QVERIFY(r.isAllDay()); |
597 | |
598 | r.setEndDateTime(QDateTime(QDate(2010, 10, 14))); |
599 | QVERIFY(r.endDateTime() == QDateTime(QDate(2010, 10, 14))); |
600 | |
601 | // add |
602 | QOrganizerEventTime r2; |
603 | r2.setStartDateTime(QDateTime(QDate(2010, 10, 23))); |
604 | r2.setEndDateTime(QDateTime(QDate(2010, 10, 24))); |
605 | QVERIFY(e.saveDetail(&r)); |
606 | QVERIFY(e.details(QOrganizerItemDetail::TypeEventTime).size() == 1); |
607 | QVERIFY(e.detail(QOrganizerItemDetail::TypeEventTime) == r); |
608 | QVERIFY(e.saveDetail(&r2)); // note that we don't enforce uniqueness in organizeritem; that's done by the manager! |
609 | QVERIFY(e.details(QOrganizerItemDetail::TypeEventTime).size() == 2); |
610 | QVERIFY(e.removeDetail(&r2)); |
611 | QVERIFY(e.details(QOrganizerItemDetail::TypeEventTime).size() == 1); |
612 | QVERIFY(e.detail(QOrganizerItemDetail::TypeEventTime) == r); |
613 | |
614 | // update |
615 | r.setAllDay(false); |
616 | QVERIFY(e.detail(QOrganizerItemDetail::TypeEventTime) != r); |
617 | QVERIFY(e.saveDetail(&r)); |
618 | QVERIFY(e.detail(QOrganizerItemDetail::TypeEventTime) == r); |
619 | QVERIFY(e.details(QOrganizerItemDetail::TypeEventTime).size() == 1); |
620 | |
621 | // remove |
622 | QVERIFY(e.removeDetail(&r)); |
623 | QVERIFY(e.details(QOrganizerItemDetail::TypeEventTime).size() == 0); |
624 | } |
625 | |
626 | void tst_QOrganizerItemDetails::journalTime() |
627 | { |
628 | QOrganizerJournalTime r; |
629 | QOrganizerJournal j; |
630 | |
631 | QVERIFY(r.isEmpty()); |
632 | r.setEntryDateTime(QDateTime(QDate(2010, 10, 13))); |
633 | QVERIFY(r.entryDateTime() == QDateTime(QDate(2010, 10, 13))); |
634 | |
635 | // add |
636 | QOrganizerJournalTime r2; |
637 | r2.setEntryDateTime(QDateTime(QDate(2010, 10, 23))); |
638 | QVERIFY(j.saveDetail(&r)); |
639 | QVERIFY(j.details(QOrganizerItemDetail::TypeJournalTime).size() == 1); |
640 | QVERIFY(j.detail(QOrganizerItemDetail::TypeJournalTime) == r); |
641 | QVERIFY(j.saveDetail(&r2)); // note that we don't enforce uniqueness in organizeritem; that's done by the manager! |
642 | QVERIFY(j.details(QOrganizerItemDetail::TypeJournalTime).size() == 2); |
643 | QVERIFY(j.removeDetail(&r2)); |
644 | QVERIFY(j.details(QOrganizerItemDetail::TypeJournalTime).size() == 1); |
645 | QVERIFY(j.detail(QOrganizerItemDetail::TypeJournalTime) == r); |
646 | |
647 | // update |
648 | r.setEntryDateTime(QDateTime(QDate(2010, 11, 05))); |
649 | QVERIFY(j.detail(QOrganizerItemDetail::TypeJournalTime) != r); |
650 | QVERIFY(j.saveDetail(&r)); |
651 | QVERIFY(j.detail(QOrganizerItemDetail::TypeJournalTime) == r); |
652 | QVERIFY(j.details(QOrganizerItemDetail::TypeJournalTime).size() == 1); |
653 | |
654 | // remove |
655 | QVERIFY(j.removeDetail(&r)); |
656 | QVERIFY(j.details(QOrganizerItemDetail::TypeJournalTime).size() == 0); |
657 | } |
658 | |
659 | void tst_QOrganizerItemDetails::todoTime() |
660 | { |
661 | QOrganizerTodoTime r; |
662 | QOrganizerTodo t; |
663 | |
664 | QVERIFY(r.isEmpty()); |
665 | QVERIFY(!r.isAllDay()); |
666 | |
667 | r.setStartDateTime(QDateTime(QDate(2010, 10, 13))); |
668 | QVERIFY(r.startDateTime() == QDateTime(QDate(2010, 10, 13))); |
669 | QVERIFY(!r.isAllDay()); |
670 | r.setAllDay(true); |
671 | QVERIFY(r.isAllDay()); |
672 | |
673 | r.setDueDateTime(QDateTime(QDate(2010, 10, 14))); |
674 | QVERIFY(r.dueDateTime() == QDateTime(QDate(2010, 10, 14))); |
675 | |
676 | // add |
677 | QOrganizerTodoTime r2; |
678 | r2.setStartDateTime(QDateTime(QDate(2010, 10, 23))); |
679 | r2.setDueDateTime(QDateTime(QDate(2010, 10, 24))); |
680 | QVERIFY(t.saveDetail(&r)); |
681 | QVERIFY(t.details(QOrganizerItemDetail::TypeTodoTime).size() == 1); |
682 | QVERIFY(t.detail(QOrganizerItemDetail::TypeTodoTime) == r); |
683 | QVERIFY(t.saveDetail(&r2)); // note that we don't enforce uniqueness in organizeritem; that's done by the manager! |
684 | QVERIFY(t.details(QOrganizerItemDetail::TypeTodoTime).size() == 2); |
685 | QVERIFY(t.removeDetail(&r2)); |
686 | QVERIFY(t.details(QOrganizerItemDetail::TypeTodoTime).size() == 1); |
687 | QVERIFY(t.detail(QOrganizerItemDetail::TypeTodoTime) == r); |
688 | |
689 | // update |
690 | r.setAllDay(false); |
691 | QVERIFY(t.detail(QOrganizerItemDetail::TypeTodoTime) != r); |
692 | QVERIFY(t.saveDetail(&r)); |
693 | QVERIFY(t.detail(QOrganizerItemDetail::TypeTodoTime) == r); |
694 | QVERIFY(t.details(QOrganizerItemDetail::TypeTodoTime).size() == 1); |
695 | |
696 | // remove |
697 | QVERIFY(t.removeDetail(&r)); |
698 | QVERIFY(t.details(QOrganizerItemDetail::TypeTodoTime).size() == 0); |
699 | } |
700 | |
701 | void tst_QOrganizerItemDetails::reminder() |
702 | { |
703 | QOrganizerItemReminder r; |
704 | QOrganizerItem oi; |
705 | |
706 | QVERIFY(r.isEmpty()); |
707 | QVERIFY(r.reminderType() == QOrganizerItemReminder::NoReminder); |
708 | |
709 | QVERIFY(r.secondsBeforeStart() == 0); |
710 | QVERIFY(r.repetitionCount() == 0); |
711 | QVERIFY(r.repetitionDelay() == 0); |
712 | |
713 | r.setSecondsBeforeStart(45); |
714 | QVERIFY(!r.isEmpty()); |
715 | r.removeValue(field: QOrganizerItemReminder::FieldSecondsBeforeStart); |
716 | QVERIFY(r.isEmpty()); |
717 | |
718 | r.setRepetition(count: 3, delaySeconds: 100); |
719 | QVERIFY(r.repetitionCount() == 3); |
720 | QVERIFY(r.repetitionDelay() == 100); |
721 | QVERIFY(!r.isEmpty()); |
722 | |
723 | r.setSecondsBeforeStart(30); // reminder, 30 seconds before the item is due to start. |
724 | QVERIFY(r.secondsBeforeStart() == 30); |
725 | |
726 | // add |
727 | QVERIFY(oi.details(QOrganizerItemDetail::TypeReminder).size() == 0); |
728 | QVERIFY(oi.saveDetail(&r)); |
729 | QVERIFY(oi.details(QOrganizerItemDetail::TypeReminder).size() == 1); |
730 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeReminder) == r); |
731 | |
732 | // update |
733 | r.setSecondsBeforeStart(300); |
734 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeReminder) != r); |
735 | QVERIFY(oi.saveDetail(&r)); |
736 | QVERIFY(oi.details(QOrganizerItemDetail::TypeReminder).size() == 1); // should update, not add another |
737 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeReminder) == r); |
738 | |
739 | // remove |
740 | QVERIFY(oi.removeDetail(&r)); |
741 | QVERIFY(oi.details(QOrganizerItemDetail::TypeReminder).size() == 0); |
742 | } |
743 | |
744 | void tst_QOrganizerItemDetails::audibleReminder() |
745 | { |
746 | QOrganizerItemAudibleReminder r; |
747 | QOrganizerItem oi; |
748 | |
749 | QVERIFY(r.isEmpty()); |
750 | QVERIFY(r.reminderType() == QOrganizerItemReminder::AudibleReminder); |
751 | |
752 | QVERIFY(r.secondsBeforeStart() == 0); |
753 | QVERIFY(r.repetitionCount() == 0); |
754 | QVERIFY(r.repetitionDelay() == 0); |
755 | |
756 | r.setSecondsBeforeStart(45); |
757 | QVERIFY(!r.isEmpty()); |
758 | r.removeValue(field: QOrganizerItemReminder::FieldSecondsBeforeStart); |
759 | QVERIFY(r.isEmpty()); |
760 | |
761 | QOrganizerItemReminder baseR; |
762 | baseR = r; |
763 | QVERIFY(baseR.isEmpty()); |
764 | baseR.setSecondsBeforeStart(50); |
765 | QVERIFY(baseR.secondsBeforeStart() == 50); |
766 | QVERIFY(r.secondsBeforeStart() == 0); |
767 | QVERIFY(!baseR.isEmpty()); |
768 | QVERIFY(r.isEmpty()); |
769 | |
770 | r.setRepetition(count: 3, delaySeconds: 100); |
771 | QVERIFY(r.repetitionCount() == 3); |
772 | QVERIFY(r.repetitionDelay() == 100); |
773 | QVERIFY(!r.isEmpty()); |
774 | |
775 | r.setSecondsBeforeStart(30); // reminder, 30 seconds before the item is due to start. |
776 | QVERIFY(r.secondsBeforeStart() == 30); |
777 | |
778 | // add |
779 | QVERIFY(oi.details(QOrganizerItemDetail::TypeAudibleReminder).size() == 0); |
780 | QVERIFY(oi.saveDetail(&r)); |
781 | QVERIFY(oi.details(QOrganizerItemDetail::TypeAudibleReminder).size() == 1); |
782 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeAudibleReminder) == r); |
783 | |
784 | // update |
785 | r.setSecondsBeforeStart(300); |
786 | r.setDataUrl(QUrl("http://www.test.com" )); |
787 | QVERIFY(r.dataUrl() == QUrl("http://www.test.com" )); |
788 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeAudibleReminder) != r); |
789 | QVERIFY(oi.saveDetail(&r)); |
790 | QVERIFY(oi.details(QOrganizerItemDetail::TypeAudibleReminder).size() == 1); // should update, not add another |
791 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeAudibleReminder) == r); |
792 | |
793 | // remove |
794 | QVERIFY(oi.removeDetail(&r)); |
795 | QVERIFY(oi.details(QOrganizerItemDetail::TypeAudibleReminder).size() == 0); |
796 | } |
797 | |
798 | void tst_QOrganizerItemDetails::emailReminder() |
799 | { |
800 | QOrganizerItemEmailReminder r; |
801 | QOrganizerItem oi; |
802 | |
803 | QVERIFY(r.isEmpty()); |
804 | QVERIFY(r.reminderType() == QOrganizerItemReminder::EmailReminder); |
805 | |
806 | QVERIFY(r.secondsBeforeStart() == 0); |
807 | QVERIFY(r.repetitionCount() == 0); |
808 | QVERIFY(r.repetitionDelay() == 0); |
809 | |
810 | r.setRepetition(count: 3, delaySeconds: 100); |
811 | QVERIFY(r.repetitionCount() == 3); |
812 | QVERIFY(r.repetitionDelay() == 100); |
813 | QVERIFY(!r.isEmpty()); |
814 | |
815 | r.setSecondsBeforeStart(30); // reminder, 30 seconds before the item is due to start. |
816 | QVERIFY(r.secondsBeforeStart() == 30); |
817 | |
818 | // add |
819 | QVERIFY(oi.details(QOrganizerItemDetail::TypeEmailReminder).size() == 0); |
820 | QVERIFY(oi.saveDetail(&r)); |
821 | QVERIFY(oi.details(QOrganizerItemDetail::TypeEmailReminder).size() == 1); |
822 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeEmailReminder) == r); |
823 | |
824 | // update |
825 | r.setSecondsBeforeStart(300); |
826 | r.setContents(subject: "subject" , body: "body" , attachments: QVariantList()); |
827 | r.setRecipients(QStringList() << "recipient" << "other recipient" ); |
828 | QVERIFY(r.subject() == QString("subject" )); |
829 | QVERIFY(r.body() == QString("body" )); |
830 | QVERIFY(r.attachments() == QVariantList()); |
831 | QVERIFY(r.recipients() == (QStringList() << "recipient" << "other recipient" )); |
832 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeEmailReminder) != r); |
833 | QVERIFY(oi.saveDetail(&r)); |
834 | QVERIFY(oi.details(QOrganizerItemDetail::TypeEmailReminder).size() == 1); // should update, not add another |
835 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeEmailReminder) == r); |
836 | |
837 | // remove |
838 | QVERIFY(oi.removeDetail(&r)); |
839 | QVERIFY(oi.details(QOrganizerItemDetail::TypeEmailReminder).size() == 0); |
840 | } |
841 | |
842 | void tst_QOrganizerItemDetails::visualReminder() |
843 | { |
844 | QOrganizerItemVisualReminder r; |
845 | QOrganizerItem oi; |
846 | |
847 | QVERIFY(r.isEmpty()); |
848 | QVERIFY(r.reminderType() == QOrganizerItemReminder::VisualReminder); |
849 | |
850 | QVERIFY(r.secondsBeforeStart() == 0); |
851 | QVERIFY(r.repetitionCount() == 0); |
852 | QVERIFY(r.repetitionDelay() == 0); |
853 | |
854 | r.setRepetition(count: 3, delaySeconds: 100); |
855 | QVERIFY(r.repetitionCount() == 3); |
856 | QVERIFY(r.repetitionDelay() == 100); |
857 | QVERIFY(!r.isEmpty()); |
858 | |
859 | r.setSecondsBeforeStart(30); // reminder, 30 seconds before the item is due to start. |
860 | QVERIFY(r.secondsBeforeStart() == 30); |
861 | |
862 | // add |
863 | QVERIFY(oi.details(QOrganizerItemDetail::TypeVisualReminder).size() == 0); |
864 | QVERIFY(oi.saveDetail(&r)); |
865 | QVERIFY(oi.details(QOrganizerItemDetail::TypeVisualReminder).size() == 1); |
866 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeVisualReminder) == r); |
867 | |
868 | // update |
869 | r.setSecondsBeforeStart(300); |
870 | r.setMessage("test" ); |
871 | r.setDataUrl(QUrl("http://www.test.com" )); |
872 | QVERIFY(r.message() == QString("test" )); |
873 | QVERIFY(r.dataUrl() == QUrl("http://www.test.com" )); |
874 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeVisualReminder) != r); |
875 | QVERIFY(oi.saveDetail(&r)); |
876 | QVERIFY(oi.details(QOrganizerItemDetail::TypeVisualReminder).size() == 1); // should update, not add another |
877 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeVisualReminder) == r); |
878 | |
879 | // remove |
880 | QVERIFY(oi.removeDetail(&r)); |
881 | QVERIFY(oi.details(QOrganizerItemDetail::TypeVisualReminder).size() == 0); |
882 | } |
883 | |
884 | void tst_QOrganizerItemDetails::attendee() |
885 | { |
886 | QOrganizerEventAttendee a; |
887 | QOrganizerItem oi; |
888 | |
889 | QVERIFY(a.isEmpty()); |
890 | QVERIFY(a.name().isEmpty()); |
891 | QVERIFY(a.emailAddress().isEmpty()); |
892 | QVERIFY(a.attendeeId().isEmpty()); |
893 | QVERIFY(a.participationRole() == 0); |
894 | QVERIFY(a.participationStatus() == 0); |
895 | |
896 | a.setAttendeeId("123456" ); |
897 | QVERIFY(a.attendeeId() == QString("123456" )); |
898 | a.setEmailAddress("people@nokia.com" ); |
899 | QVERIFY(a.emailAddress() == QString("people@nokia.com" )); |
900 | a.setName("people" ); |
901 | QVERIFY(a.name() == QString("people" )); |
902 | a.setParticipationRole(QOrganizerEventAttendee::RoleRequiredParticipant); |
903 | QVERIFY(a.participationRole() == QOrganizerEventAttendee::RoleRequiredParticipant); |
904 | a.setParticipationStatus(QOrganizerEventAttendee::StatusAccepted); |
905 | QVERIFY(a.participationStatus() == QOrganizerEventAttendee::StatusAccepted); |
906 | // add |
907 | QVERIFY(oi.details(QOrganizerItemDetail::TypeEventAttendee).size() == 0); |
908 | QVERIFY(oi.saveDetail(&a)); |
909 | QVERIFY(oi.details(QOrganizerItemDetail::TypeEventAttendee).size() == 1); |
910 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeEventAttendee) == a); |
911 | // update |
912 | a.setAttendeeId("54321" ); |
913 | a.setName("newpeople" ); |
914 | a.setEmailAddress("newpeople@nokia.com" ); |
915 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeEventAttendee) != a); |
916 | QVERIFY(oi.saveDetail(&a)); |
917 | QVERIFY(oi.details(QOrganizerItemDetail::TypeEventAttendee).size() == 1); |
918 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeEventAttendee) == a); |
919 | |
920 | // add one more attendee |
921 | QOrganizerEventAttendee a1; |
922 | a1.setAttendeeId("777777" ); |
923 | a1.setName("people1" ); |
924 | a1.setEmailAddress("people1@nokia.com" ); |
925 | QVERIFY(oi.saveDetail(&a1)); |
926 | QVERIFY(oi.details(QOrganizerItemDetail::TypeEventAttendee).size() == 2); |
927 | |
928 | // remove |
929 | QVERIFY(oi.removeDetail(&a)); |
930 | QVERIFY(oi.details(QOrganizerItemDetail::TypeEventAttendee).size() == 1); |
931 | QVERIFY(oi.removeDetail(&a1)); |
932 | QVERIFY(oi.details(QOrganizerItemDetail::TypeEventAttendee).size() == 0); |
933 | } |
934 | |
935 | void tst_QOrganizerItemDetails::rsvp() |
936 | { |
937 | QOrganizerEventRsvp rsvp; |
938 | QOrganizerItem oi; |
939 | |
940 | QVERIFY(rsvp.isEmpty()); |
941 | QVERIFY(rsvp.organizerName().isEmpty()); |
942 | QVERIFY(rsvp.organizerEmail().isEmpty()); |
943 | QVERIFY(rsvp.responseDate().isNull()); |
944 | QVERIFY(!rsvp.responseDate().isValid()); |
945 | QVERIFY(rsvp.responseDeadline().isNull()); |
946 | QVERIFY(!rsvp.responseDeadline().isValid()); |
947 | QVERIFY(rsvp.participationRole() == 0); |
948 | QVERIFY(rsvp.participationStatus() == 0); |
949 | QVERIFY(rsvp.responseRequirement() == 0); |
950 | |
951 | rsvp.setOrganizerName("Donald Duck" ); |
952 | QVERIFY(rsvp.organizerName() == QString("Donald Duck" )); |
953 | rsvp.setOrganizerEmail("don@duck.com" ); |
954 | QVERIFY(rsvp.organizerEmail() == QString("don@duck.com" )); |
955 | QDate testDate(2010, 10, 10); |
956 | rsvp.setResponseDate(testDate); |
957 | QVERIFY(!rsvp.responseDate().isNull()); |
958 | QVERIFY(rsvp.responseDate().isValid()); |
959 | QCOMPARE(testDate, rsvp.responseDate()); |
960 | rsvp.setResponseDeadline(testDate); |
961 | QVERIFY(!rsvp.responseDeadline().isNull()); |
962 | QVERIFY(rsvp.responseDeadline().isValid()); |
963 | QCOMPARE(testDate, rsvp.responseDeadline()); |
964 | rsvp.setParticipationRole(QOrganizerEventAttendee::RoleOrganizer); |
965 | QVERIFY(rsvp.participationRole() == QOrganizerEventAttendee::RoleOrganizer); |
966 | rsvp.setParticipationStatus(QOrganizerEventAttendee::StatusAccepted); |
967 | QVERIFY(rsvp.participationStatus() == QOrganizerEventAttendee::StatusAccepted); |
968 | rsvp.setResponseRequirement(QOrganizerEventRsvp::ResponseRequired); |
969 | QVERIFY(rsvp.responseRequirement() == QOrganizerEventRsvp::ResponseRequired); |
970 | |
971 | // add |
972 | QCOMPARE(0, oi.details(QOrganizerItemDetail::TypeEventRsvp).size()); |
973 | QVERIFY(oi.saveDetail(&rsvp)); |
974 | QCOMPARE(1, oi.details(QOrganizerItemDetail::TypeEventRsvp).size()); |
975 | QVERIFY(rsvp == oi.detail(QOrganizerItemDetail::TypeEventRsvp)); |
976 | |
977 | // update |
978 | rsvp.setOrganizerName("Mickey Mouse" ); |
979 | rsvp.setOrganizerEmail("mick@mouse.com" ); |
980 | QDate testDate2(2011, 11, 11); |
981 | rsvp.setResponseDate(testDate2); |
982 | rsvp.setResponseDeadline(testDate2); |
983 | rsvp.setParticipationRole(QOrganizerEventAttendee::RoleChairperson); |
984 | rsvp.setParticipationStatus(QOrganizerEventAttendee::StatusDelegated); |
985 | rsvp.setResponseRequirement(QOrganizerEventRsvp::ResponseNotRequired); |
986 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeEventRsvp) != rsvp); |
987 | QVERIFY(oi.saveDetail(&rsvp)); |
988 | QCOMPARE(1, oi.details(QOrganizerItemDetail::TypeEventRsvp).size()); |
989 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeEventRsvp) == rsvp); |
990 | |
991 | // add another rsvp - not supported by all the backends |
992 | QOrganizerEventRsvp rsvp2; |
993 | rsvp2.setOrganizerName("Goofy" ); |
994 | QVERIFY(oi.saveDetail(&rsvp2)); |
995 | QCOMPARE(2, oi.details(QOrganizerItemDetail::TypeEventRsvp).size()); |
996 | |
997 | // remove |
998 | QVERIFY(oi.removeDetail(&rsvp2)); |
999 | QCOMPARE(1, oi.details(QOrganizerItemDetail::TypeEventRsvp).size()); |
1000 | QVERIFY(oi.removeDetail(&rsvp)); |
1001 | QCOMPARE(0, oi.details(QOrganizerItemDetail::TypeEventRsvp).size()); |
1002 | } |
1003 | |
1004 | void tst_QOrganizerItemDetails::classification() |
1005 | { |
1006 | QOrganizerItemClassification classification; |
1007 | QOrganizerItem oi; |
1008 | |
1009 | QVERIFY(classification.isEmpty()); |
1010 | |
1011 | // setters/getters |
1012 | classification.setClassification(QOrganizerItemClassification::AccessPublic); |
1013 | QVERIFY(classification.classification() == QOrganizerItemClassification::AccessPublic); |
1014 | classification.setClassification(QOrganizerItemClassification::AccessPrivate); |
1015 | QVERIFY(classification.classification() == QOrganizerItemClassification::AccessPrivate); |
1016 | classification.setClassification(QOrganizerItemClassification::AccessConfidential); |
1017 | QVERIFY(classification.classification() == QOrganizerItemClassification::AccessConfidential); |
1018 | |
1019 | // add |
1020 | QCOMPARE(0, oi.details(QOrganizerItemDetail::TypeClassification).size()); |
1021 | QVERIFY(oi.saveDetail(&classification)); |
1022 | QCOMPARE(1, oi.details(QOrganizerItemDetail::TypeClassification).size()); |
1023 | QCOMPARE(classification, static_cast<QOrganizerItemClassification>(oi.detail(QOrganizerItemDetail::TypeClassification))); |
1024 | |
1025 | // update |
1026 | classification.setValue(field: QOrganizerItemClassification::FieldClassification, value: QOrganizerItemClassification::AccessPrivate); |
1027 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeClassification) != classification); |
1028 | QVERIFY(oi.saveDetail(&classification)); |
1029 | QCOMPARE(1, oi.details(QOrganizerItemDetail::TypeClassification).size()); |
1030 | QVERIFY(oi.detail(QOrganizerItemDetail::TypeClassification) == classification); |
1031 | |
1032 | // try adding another, amount of details should stay the same |
1033 | QOrganizerItemClassification classification2; |
1034 | classification2.setClassification(QOrganizerItemClassification::AccessConfidential); |
1035 | QVERIFY(oi.saveDetail(&classification2)); |
1036 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeClassification).size(), 1); |
1037 | |
1038 | // remove |
1039 | QVERIFY(oi.removeDetail(&classification2)); |
1040 | QCOMPARE(oi.details(QOrganizerItemDetail::TypeClassification).size(), 0); |
1041 | } |
1042 | |
1043 | void tst_QOrganizerItemDetails::version() |
1044 | { |
1045 | QOrganizerItemVersion version; |
1046 | QCOMPARE(version.type(), QOrganizerItemDetail::TypeVersion); |
1047 | QVERIFY(!version.hasValue(QOrganizerItemVersion::FieldVersion)); |
1048 | QVERIFY(!version.hasValue(QOrganizerItemVersion::FieldExtendedVersion)); |
1049 | |
1050 | version.setVersion(64); |
1051 | QCOMPARE(version.version(), 64); |
1052 | QVERIFY(version.hasValue(QOrganizerItemVersion::FieldVersion)); |
1053 | QVERIFY(!version.hasValue(QOrganizerItemVersion::FieldExtendedVersion)); |
1054 | |
1055 | QByteArray extendedVersion("Qt rules!" ); |
1056 | version.setExtendedVersion(extendedVersion); |
1057 | QCOMPARE(version.extendedVersion(), extendedVersion); |
1058 | QVERIFY(version.hasValue(QOrganizerItemVersion::FieldVersion)); |
1059 | QVERIFY(version.hasValue(QOrganizerItemVersion::FieldExtendedVersion)); |
1060 | } |
1061 | |
1062 | QTEST_MAIN(tst_QOrganizerItemDetails) |
1063 | #include "tst_qorganizeritemdetails.moc" |
1064 | |