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 | //TESTED_COMPONENT=src/versit |
35 | |
36 | #include "tst_qversitorganizerimporter.h" |
37 | #include <QtTest/QtTest> |
38 | |
39 | QTORGANIZER_USE_NAMESPACE |
40 | QTVERSITORGANIZER_USE_NAMESPACE |
41 | |
42 | Q_DECLARE_METATYPE(QList<QOrganizerItem>) |
43 | Q_DECLARE_METATYPE(QList<QOrganizerItemDetail>) |
44 | Q_DECLARE_METATYPE(QList<QVersitProperty>) |
45 | |
46 | void tst_QVersitOrganizerImporter::testImport() |
47 | { |
48 | QFETCH(QVersitDocument, document); |
49 | QFETCH(QList<QOrganizerItem>, expectedItems); |
50 | |
51 | QVersitOrganizerImporter importer; |
52 | QVERIFY(importer.importDocument(document)); |
53 | QVERIFY(importer.errorMap().isEmpty()); |
54 | QList<QOrganizerItem> items = importer.items(); |
55 | if (items != expectedItems) { |
56 | qDebug() << "Actual:" << items; |
57 | qDebug() << "Expected:" << expectedItems; |
58 | QCOMPARE(items, expectedItems); |
59 | } |
60 | } |
61 | |
62 | void tst_QVersitOrganizerImporter::testImport_data() |
63 | { |
64 | QTest::addColumn<QVersitDocument>(name: "document" ); |
65 | QTest::addColumn<QList<QOrganizerItem> >(name: "expectedItems" ); |
66 | |
67 | { |
68 | QVersitDocument document(QVersitDocument::ICalendar20Type); |
69 | document.setComponentType(QStringLiteral("VCALENDAR" )); |
70 | QVersitProperty property; |
71 | property.setName(QStringLiteral("PRODID" )); |
72 | property.setValue(QStringLiteral("-//hacksw/handcal//NONSGML v1.0//EN" )); |
73 | document.addProperty(property); |
74 | QVersitDocument nested(QVersitDocument::ICalendar20Type); |
75 | nested.setComponentType(QStringLiteral("VEVENT" )); |
76 | property.setName(QStringLiteral("SUMMARY" )); |
77 | property.setValue(QStringLiteral("Bastille Day Party" )); |
78 | nested.addProperty(property); |
79 | property.setName(QStringLiteral("DTSTART" )); |
80 | property.setValue(QStringLiteral("19970714T170000Z" )); |
81 | nested.addProperty(property); |
82 | property.setName(QStringLiteral("DTEND" )); |
83 | property.setValue(QStringLiteral("19970715T035959Z" )); |
84 | nested.addProperty(property); |
85 | document.addSubDocument(subdocument: nested); |
86 | |
87 | nested.clear(); |
88 | nested.setType(QVersitDocument::ICalendar20Type); |
89 | nested.setComponentType(QStringLiteral("VTODO" )); |
90 | property.setName(QStringLiteral("SUMMARY" )); |
91 | property.setValue(QStringLiteral("Take out the garbage" )); |
92 | nested.addProperty(property); |
93 | property.setName(QStringLiteral("DTSTART" )); |
94 | property.setValue(QStringLiteral("20100609T080000" )); |
95 | nested.addProperty(property); |
96 | property.setName(QStringLiteral("DUE" )); |
97 | property.setValue(QStringLiteral("20100610T080000" )); |
98 | nested.addProperty(property); |
99 | document.addSubDocument(subdocument: nested); |
100 | |
101 | nested.clear(); |
102 | nested.setType(QVersitDocument::ICalendar20Type); |
103 | nested.setComponentType(QStringLiteral("VJOURNAL" )); |
104 | property.setName(QStringLiteral("SUMMARY" )); |
105 | property.setValue(QStringLiteral("Trip to Thailand" )); |
106 | nested.addProperty(property); |
107 | property.setName(QStringLiteral("DTSTART" )); |
108 | property.setValue(QStringLiteral("20100615T112300" )); |
109 | nested.addProperty(property); |
110 | document.addSubDocument(subdocument: nested); |
111 | |
112 | QOrganizerEvent event; |
113 | event.setDisplayLabel(QStringLiteral("Bastille Day Party" )); |
114 | event.setStartDateTime(QDateTime(QDate(1997, 7, 14), QTime(17, 0, 0), Qt::UTC)); |
115 | event.setEndDateTime(QDateTime(QDate(1997, 7, 15), QTime(3, 59, 59), Qt::UTC)); |
116 | |
117 | QOrganizerTodo todo; |
118 | todo.setDisplayLabel(QStringLiteral("Take out the garbage" )); |
119 | todo.setStartDateTime(QDateTime(QDate(2010, 6, 9), QTime(8, 0, 0))); |
120 | todo.setDueDateTime(QDateTime(QDate(2010, 6, 10), QTime(8, 0, 0))); |
121 | |
122 | QOrganizerJournal journal; |
123 | journal.setDisplayLabel(QStringLiteral("Trip to Thailand" )); |
124 | journal.setDateTime(QDateTime(QDate(2010, 6, 15), QTime(11, 23, 0))); |
125 | |
126 | QList<QOrganizerItem> items; |
127 | items << static_cast<QOrganizerItem>(event); |
128 | items << static_cast<QOrganizerItem>(todo); |
129 | items << static_cast<QOrganizerItem>(journal); |
130 | |
131 | QTest::newRow(dataTag: "sample event and todo" ) << document << items; |
132 | } |
133 | |
134 | { |
135 | QVersitDocument document(QVersitDocument::ICalendar20Type); |
136 | document.setComponentType(QStringLiteral("VCALENDAR" )); |
137 | QVersitDocument nested(QVersitDocument::ICalendar20Type); |
138 | nested.setComponentType(QStringLiteral("VEVENT" )); |
139 | QVersitProperty property; |
140 | property.setName(QStringLiteral("UID" )); |
141 | property.setValue(QStringLiteral("1234" )); |
142 | nested.addProperty(property); |
143 | property.setName(QStringLiteral("RECURRENCE-ID" )); |
144 | property.setValue(QStringLiteral("20100608" )); |
145 | nested.addProperty(property); |
146 | document.addSubDocument(subdocument: nested); |
147 | |
148 | // An event occurrence with OriginalDate and Guid set |
149 | QOrganizerEventOccurrence event; |
150 | event.setGuid(QStringLiteral("1234" )); |
151 | event.setOriginalDate(QDate(2010, 6, 8)); |
152 | |
153 | QList<QOrganizerItem> items; |
154 | items << static_cast<QOrganizerItem>(event); |
155 | |
156 | QTest::newRow(dataTag: "event occurrence exception" ) << document << items; |
157 | } |
158 | |
159 | { |
160 | QVersitDocument document(QVersitDocument::ICalendar20Type); |
161 | document.setComponentType(QStringLiteral("VCALENDAR" )); |
162 | QVersitDocument nested(QVersitDocument::ICalendar20Type); |
163 | nested.setComponentType(QStringLiteral("VTODO" )); |
164 | QVersitProperty property; |
165 | property.setName(QStringLiteral("RRULE" )); |
166 | property.setValue(QStringLiteral("FREQ=WEEKLY" )); |
167 | nested.addProperty(property); |
168 | document.addSubDocument(subdocument: nested); |
169 | |
170 | QOrganizerTodo todo; |
171 | QOrganizerRecurrenceRule rrule; |
172 | rrule.setFrequency(QOrganizerRecurrenceRule::Weekly); |
173 | todo.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << rrule); |
174 | |
175 | QList<QOrganizerItem> items; |
176 | items << static_cast<QOrganizerItem>(todo); |
177 | |
178 | QTest::newRow(dataTag: "todo recurrence rule" ) << document << items; |
179 | } |
180 | } |
181 | |
182 | void tst_QVersitOrganizerImporter::testImportEventProperties() |
183 | { |
184 | QFETCH(QList<QVersitProperty>, properties); |
185 | QFETCH(QList<QOrganizerItemDetail>, expectedDetails); |
186 | |
187 | QVersitDocument document(QVersitDocument::ICalendar20Type); |
188 | document.setComponentType(QStringLiteral("VCALENDAR" )); |
189 | QVersitDocument nested(QVersitDocument::ICalendar20Type); |
190 | nested.setComponentType(QStringLiteral("VEVENT" )); |
191 | foreach (const QVersitProperty& property, properties) { |
192 | if (property.valueType() == QVersitProperty::VersitDocumentType) |
193 | nested.addSubDocument(subdocument: property.value<QVersitDocument>()); |
194 | else |
195 | nested.addProperty(property); |
196 | } |
197 | document.addSubDocument(subdocument: nested); |
198 | QVersitOrganizerImporter importer; |
199 | QVERIFY(importer.importDocument(document)); |
200 | QVERIFY(importer.errorMap().isEmpty()); |
201 | QList<QOrganizerItem> items = importer.items(); |
202 | QCOMPARE(items.size(), 1); |
203 | foreach (const QOrganizerItemDetail& expectedDetail, expectedDetails) { |
204 | |
205 | QList<QOrganizerItemDetail> actualDetails = items.first().details(detailType: expectedDetail.type()); |
206 | if (!actualDetails.contains(t: expectedDetail)) { |
207 | qDebug() << "Actual:" << actualDetails; |
208 | qDebug() << "Expected to find:" << expectedDetail; |
209 | QVERIFY(false); |
210 | } |
211 | } |
212 | } |
213 | |
214 | void tst_QVersitOrganizerImporter::testImportEventProperties_data() |
215 | { |
216 | QTest::addColumn<QList<QVersitProperty> >(name: "properties" ); |
217 | QTest::addColumn<QList<QOrganizerItemDetail> >(name: "expectedDetails" ); |
218 | |
219 | { |
220 | QVersitProperty property; |
221 | property.setName(QStringLiteral("SUMMARY" )); |
222 | property.setValue(QStringLiteral("jabberwocky" )); |
223 | QOrganizerItemDisplayLabel displayLabel; |
224 | displayLabel.setLabel(QStringLiteral("jabberwocky" )); |
225 | QTest::newRow(dataTag: "one summary" ) << (QList<QVersitProperty>() << property) |
226 | << (QList<QOrganizerItemDetail>() << displayLabel); |
227 | } |
228 | |
229 | { |
230 | QVersitProperty property; |
231 | QVersitDocument valarmDocument(QVersitDocument::ICalendar20Type); |
232 | QList<QVersitProperty> valarmProperties; |
233 | |
234 | property.setName(QStringLiteral("ACTION" )); |
235 | property.setValue(QStringLiteral("AUDIO" )); |
236 | valarmProperties << property; |
237 | property.setName(QStringLiteral("ATTACH" )); |
238 | property.setValue(QUrl(QStringLiteral("http://qt.nokia.com" ))); |
239 | valarmProperties << property; |
240 | property.setName(QStringLiteral("DURATION" )); |
241 | property.setValue(QStringLiteral("PT5S" )); |
242 | valarmProperties << property; |
243 | property.setName(QStringLiteral("REPEAT" )); |
244 | property.setValue(3); |
245 | valarmProperties << property; |
246 | property.setName(QStringLiteral("TRIGGER" )); |
247 | property.setValue(QStringLiteral("-PT90S" )); |
248 | valarmProperties << property; |
249 | |
250 | valarmDocument.setComponentType("VALARM" ); |
251 | valarmDocument.setProperties(valarmProperties); |
252 | property.setValueType(QVersitProperty::VersitDocumentType); |
253 | property.setName(QStringLiteral("VALARM" )); |
254 | property.setValue(QVariant::fromValue(value: valarmDocument)); |
255 | QOrganizerItemAudibleReminder audibleReminder; |
256 | audibleReminder.setDataUrl(QUrl("http://qt.nokia.com" )); |
257 | audibleReminder.setRepetition(count: 3, delaySeconds: 5); |
258 | audibleReminder.setSecondsBeforeStart(90); |
259 | QTest::newRow(dataTag: "audible reminder" ) << (QList<QVersitProperty>() << property) |
260 | << (QList<QOrganizerItemDetail>() << audibleReminder); |
261 | } |
262 | |
263 | { |
264 | QVersitProperty property; |
265 | QVersitDocument valarmDocument(QVersitDocument::ICalendar20Type); |
266 | QList<QVersitProperty> valarmProperties; |
267 | |
268 | property.setName(QStringLiteral("ACTION" )); |
269 | property.setValue(QStringLiteral("AUDIO" )); |
270 | valarmProperties << property; |
271 | property.setName(QStringLiteral("ATTACH" )); |
272 | property.setValue(QUrl(QStringLiteral("http://qt.nokia.com" ))); |
273 | valarmProperties << property; |
274 | property.setName(QStringLiteral("DURATION" )); |
275 | property.setValue(QStringLiteral("PT5S" )); |
276 | valarmProperties << property; |
277 | property.setName(QStringLiteral("REPEAT" )); |
278 | property.setValue(3); |
279 | valarmProperties << property; |
280 | property.setName(QStringLiteral("TRIGGER" )); |
281 | property.setValue(QStringLiteral("-PT90S" )); |
282 | property.insertParameter(QStringLiteral("VALUE" ), QStringLiteral("DURATION" )); |
283 | valarmProperties << property; |
284 | property.clear(); |
285 | |
286 | valarmDocument.setComponentType("VALARM" ); |
287 | valarmDocument.setProperties(valarmProperties); |
288 | property.setValueType(QVersitProperty::VersitDocumentType); |
289 | property.setName(QStringLiteral("VALARM" )); |
290 | property.setValue(QVariant::fromValue(value: valarmDocument)); |
291 | QOrganizerItemAudibleReminder audibleReminder; |
292 | audibleReminder.setDataUrl(QUrl("http://qt.nokia.com" )); |
293 | audibleReminder.setRepetition(count: 3, delaySeconds: 5); |
294 | audibleReminder.setSecondsBeforeStart(90); |
295 | QTest::newRow(dataTag: "audible reminder with trigger VALUE = DURATION" ) << (QList<QVersitProperty>() << property) |
296 | << (QList<QOrganizerItemDetail>() << audibleReminder); |
297 | } |
298 | |
299 | { |
300 | QVersitProperty property; |
301 | QVersitDocument valarmDocument(QVersitDocument::ICalendar20Type); |
302 | QList<QVersitProperty> valarmProperties; |
303 | QVersitProperty dtstart; |
304 | dtstart.setName(QStringLiteral("DTSTART" )); |
305 | dtstart.setValue(QStringLiteral("20100102T030405" )); |
306 | QVersitProperty dtend; |
307 | dtend.setName(QStringLiteral("DTEND" )); |
308 | dtend.setValue(QStringLiteral("20100102T030415" )); |
309 | QOrganizerEventTime etr; |
310 | etr.setStartDateTime(QDateTime(QDate(2010, 1, 2), QTime(3, 4, 5))); |
311 | etr.setEndDateTime(QDateTime(QDate(2010, 1, 2), QTime(3, 4, 15))); |
312 | |
313 | property.setName(QStringLiteral("ACTION" )); |
314 | property.setValue(QStringLiteral("AUDIO" )); |
315 | valarmProperties << property; |
316 | property.setName(QStringLiteral("ATTACH" )); |
317 | property.setValue(QUrl(QStringLiteral("http://qt.nokia.com" ))); |
318 | valarmProperties << property; |
319 | property.setName(QStringLiteral("DURATION" )); |
320 | property.setValue(QStringLiteral("PT5S" )); |
321 | valarmProperties << property; |
322 | property.setName(QStringLiteral("REPEAT" )); |
323 | property.setValue(3); |
324 | valarmProperties << property; |
325 | property.setName(QStringLiteral("TRIGGER" )); |
326 | property.setValue(QStringLiteral("-PT90S" )); |
327 | property.insertParameter(QStringLiteral("RELATED" ), QStringLiteral("END" )); |
328 | valarmProperties << property; |
329 | property.clear(); |
330 | |
331 | valarmDocument.setComponentType("VALARM" ); |
332 | valarmDocument.setProperties(valarmProperties); |
333 | property.setValueType(QVersitProperty::VersitDocumentType); |
334 | property.setName(QStringLiteral("VALARM" )); |
335 | property.setValue(QVariant::fromValue(value: valarmDocument)); |
336 | QOrganizerItemAudibleReminder audibleReminder; |
337 | audibleReminder.setDataUrl(QUrl("http://qt.nokia.com" )); |
338 | audibleReminder.setRepetition(count: 3, delaySeconds: 5); |
339 | audibleReminder.setSecondsBeforeStart(80); |
340 | QTest::newRow(dataTag: "audible reminder with relative (END) trigger" ) |
341 | << (QList<QVersitProperty>() << dtstart << dtend << property) |
342 | << (QList<QOrganizerItemDetail>() << etr << audibleReminder); |
343 | } |
344 | |
345 | { |
346 | QVersitProperty property; |
347 | QVersitDocument valarmDocument(QVersitDocument::ICalendar20Type); |
348 | QList<QVersitProperty> valarmProperties; |
349 | QVersitProperty dtstart; |
350 | dtstart.setName(QStringLiteral("DTSTART" )); |
351 | dtstart.setValue(QStringLiteral("20100102T030405" )); |
352 | QVersitProperty dtend; |
353 | dtend.setName(QStringLiteral("DTEND" )); |
354 | dtend.setValue(QStringLiteral("20100102T030415" )); |
355 | QOrganizerEventTime etr; |
356 | etr.setStartDateTime(QDateTime(QDate(2010, 1, 2), QTime(3, 4, 5))); |
357 | etr.setEndDateTime(QDateTime(QDate(2010, 1, 2), QTime(3, 4, 15))); |
358 | |
359 | property.setName(QStringLiteral("ACTION" )); |
360 | property.setValue(QStringLiteral("AUDIO" )); |
361 | valarmProperties << property; |
362 | property.setName(QStringLiteral("ATTACH" )); |
363 | property.setValue(QUrl(QStringLiteral("http://qt.nokia.com" ))); |
364 | valarmProperties << property; |
365 | property.setName(QStringLiteral("DURATION" )); |
366 | property.setValue(QStringLiteral("PT5S" )); |
367 | valarmProperties << property; |
368 | property.setName(QStringLiteral("REPEAT" )); |
369 | property.setValue(3); |
370 | valarmProperties << property; |
371 | property.setName(QStringLiteral("TRIGGER" )); |
372 | property.setValue(QStringLiteral("-PT90S" )); |
373 | property.insertParameter(QStringLiteral("RELATED" ), QStringLiteral("START" )); |
374 | valarmProperties << property; |
375 | property.clear(); |
376 | |
377 | valarmDocument.setComponentType("VALARM" ); |
378 | valarmDocument.setProperties(valarmProperties); |
379 | property.setValueType(QVersitProperty::VersitDocumentType); |
380 | property.setName(QStringLiteral("VALARM" )); |
381 | property.setValue(QVariant::fromValue(value: valarmDocument)); |
382 | QOrganizerItemAudibleReminder audibleReminder; |
383 | audibleReminder.setDataUrl(QUrl("http://qt.nokia.com" )); |
384 | audibleReminder.setRepetition(count: 3, delaySeconds: 5); |
385 | audibleReminder.setSecondsBeforeStart(90); |
386 | QTest::newRow(dataTag: "audible reminder with relative (START) trigger" ) |
387 | << (QList<QVersitProperty>() << dtstart << dtend << property) |
388 | << (QList<QOrganizerItemDetail>() << etr << audibleReminder); |
389 | } |
390 | |
391 | { |
392 | QVersitProperty property; |
393 | QVersitDocument valarmDocument(QVersitDocument::ICalendar20Type); |
394 | QList<QVersitProperty> valarmProperties; |
395 | QVersitProperty dtstart; |
396 | dtstart.setName(QStringLiteral("DTSTART" )); |
397 | dtstart.setValue(QStringLiteral("20100102T030405" )); |
398 | QVersitProperty dtend; |
399 | dtend.setName(QStringLiteral("DTEND" )); |
400 | dtend.setValue(QStringLiteral("20100102T030415" )); |
401 | QOrganizerEventTime etr; |
402 | etr.setStartDateTime(QDateTime(QDate(2010, 1, 2), QTime(3, 4, 5))); |
403 | etr.setEndDateTime(QDateTime(QDate(2010, 1, 2), QTime(3, 4, 15))); |
404 | |
405 | property.setName(QStringLiteral("ACTION" )); |
406 | property.setValue(QStringLiteral("AUDIO" )); |
407 | valarmProperties << property; |
408 | property.setName(QStringLiteral("ATTACH" )); |
409 | property.setValue(QUrl(QStringLiteral("http://qt.nokia.com" ))); |
410 | valarmProperties << property; |
411 | property.setName(QStringLiteral("DURATION" )); |
412 | property.setValue(QStringLiteral("PT5S" )); |
413 | valarmProperties << property; |
414 | property.setName(QStringLiteral("REPEAT" )); |
415 | property.setValue(3); |
416 | valarmProperties << property; |
417 | property.setName(QStringLiteral("TRIGGER" )); |
418 | property.setValue(QStringLiteral("20100102T030305" )); |
419 | property.insertParameter(QStringLiteral("VALUE" ), QStringLiteral("DATE-TIME" )); |
420 | valarmProperties << property; |
421 | property.clear(); |
422 | |
423 | valarmDocument.setComponentType("VALARM" ); |
424 | valarmDocument.setProperties(valarmProperties); |
425 | property.setValueType(QVersitProperty::VersitDocumentType); |
426 | property.setName(QStringLiteral("VALARM" )); |
427 | property.setValue(QVariant::fromValue(value: valarmDocument)); |
428 | QOrganizerItemAudibleReminder audibleReminder; |
429 | audibleReminder.setDataUrl(QUrl("http://qt.nokia.com" )); |
430 | audibleReminder.setRepetition(count: 3, delaySeconds: 5); |
431 | audibleReminder.setSecondsBeforeStart(60); |
432 | QTest::newRow(dataTag: "audible reminder with absolute trigger" ) |
433 | << (QList<QVersitProperty>() << dtstart << dtend << property) |
434 | << (QList<QOrganizerItemDetail>() << etr << audibleReminder); |
435 | } |
436 | |
437 | { |
438 | QVersitProperty property; |
439 | QVersitDocument valarmDocument(QVersitDocument::ICalendar20Type); |
440 | QList<QVersitProperty> valarmProperties; |
441 | |
442 | property.setName(QStringLiteral("ACTION" )); |
443 | property.setValue(QStringLiteral("DISPLAY" )); |
444 | valarmProperties << property; |
445 | property.setName(QStringLiteral("DURATION" )); |
446 | property.setValue(QStringLiteral("PT5S" )); |
447 | valarmProperties << property; |
448 | property.setName(QStringLiteral("REPEAT" )); |
449 | property.setValue(3); |
450 | valarmProperties << property; |
451 | property.setName(QStringLiteral("TRIGGER" )); |
452 | property.setValue(QStringLiteral("-PT90S" )); |
453 | valarmProperties << property; |
454 | property.setName(QStringLiteral("DESCRIPTION" )); |
455 | property.setValue(QStringLiteral("Test visual reminder" )); |
456 | valarmProperties << property; |
457 | |
458 | valarmDocument.setComponentType("VALARM" ); |
459 | valarmDocument.setProperties(valarmProperties); |
460 | property.setValueType(QVersitProperty::VersitDocumentType); |
461 | property.setName(QStringLiteral("VALARM" )); |
462 | property.setValue(QVariant::fromValue(value: valarmDocument)); |
463 | QOrganizerItemVisualReminder visualReminder; |
464 | visualReminder.setMessage(QStringLiteral("Test visual reminder" )); |
465 | visualReminder.setRepetition(count: 3, delaySeconds: 5); |
466 | visualReminder.setSecondsBeforeStart(90); |
467 | QTest::newRow(dataTag: "visual reminder" ) << (QList<QVersitProperty>() << property) |
468 | << (QList<QOrganizerItemDetail>() << visualReminder); |
469 | } |
470 | |
471 | { |
472 | QVersitProperty property; |
473 | QVersitDocument valarmDocument; |
474 | QList<QVersitProperty> valarmProperties; |
475 | |
476 | property.setName(QStringLiteral("ACTION" )); |
477 | property.setValue(QStringLiteral("EMAIL" )); |
478 | valarmProperties << property; |
479 | property.setName(QStringLiteral("DURATION" )); |
480 | property.setValue(QStringLiteral("PT5S" )); |
481 | valarmProperties << property; |
482 | property.setName(QStringLiteral("REPEAT" )); |
483 | property.setValue(3); |
484 | valarmProperties << property; |
485 | property.setName(QStringLiteral("TRIGGER" )); |
486 | property.setValue(QStringLiteral("-PT90S" )); |
487 | valarmProperties << property; |
488 | property.setName(QStringLiteral("DESCRIPTION" )); |
489 | property.setValue(QStringLiteral("Test email body" )); |
490 | valarmProperties << property; |
491 | property.setName(QStringLiteral("SUMMARY" )); |
492 | property.setValue(QStringLiteral("Test email subject" )); |
493 | valarmProperties << property; |
494 | property.setName(QStringLiteral("ATTENDEE" )); |
495 | property.setValue(QStringLiteral("First email recipient" )); |
496 | valarmProperties << property; |
497 | property.setValue(QStringLiteral("Second email recipient" )); |
498 | valarmProperties << property; |
499 | |
500 | valarmDocument.setComponentType("VALARM" ); |
501 | valarmDocument.setProperties(valarmProperties); |
502 | property.setValueType(QVersitProperty::VersitDocumentType); |
503 | property.setName(QStringLiteral("VALARM" )); |
504 | property.setValue(QVariant::fromValue(value: valarmDocument)); |
505 | QOrganizerItemEmailReminder emailReminder; |
506 | emailReminder.setContents(QStringLiteral("Test email subject" ), |
507 | QStringLiteral("Test email body" ), |
508 | attachments: QVariantList()); |
509 | emailReminder.setRepetition(count: 3, delaySeconds: 5); |
510 | emailReminder.setSecondsBeforeStart(90); |
511 | emailReminder.setRecipients(QStringList() |
512 | << QStringLiteral("First email recipient" ) |
513 | << QStringLiteral("Second email recipient" )); |
514 | QTest::newRow(dataTag: "email reminder" ) << (QList<QVersitProperty>() << property) |
515 | << (QList<QOrganizerItemDetail>() << emailReminder); |
516 | } |
517 | |
518 | { |
519 | QList<QOrganizerItemDetail> expectedDetails; |
520 | QList<QVersitProperty> propertiesToImport; |
521 | |
522 | { |
523 | QVersitProperty property; |
524 | QVersitDocument valarmDocument(QVersitDocument::ICalendar20Type); |
525 | QList<QVersitProperty> valarmProperties; |
526 | |
527 | property.setName(QStringLiteral("ACTION" )); |
528 | property.setValue(QStringLiteral("AUDIO" )); |
529 | valarmProperties << property; |
530 | property.setName(QStringLiteral("ATTACH" )); |
531 | property.setValue(QUrl(QStringLiteral("http://qt.nokia.com" ))); |
532 | valarmProperties << property; |
533 | property.setName(QStringLiteral("DURATION" )); |
534 | property.setValue(QStringLiteral("PT5S" )); |
535 | valarmProperties << property; |
536 | property.setName(QStringLiteral("REPEAT" )); |
537 | property.setValue(3); |
538 | valarmProperties << property; |
539 | property.setName(QStringLiteral("TRIGGER" )); |
540 | property.setValue(QStringLiteral("-PT90S" )); |
541 | valarmProperties << property; |
542 | |
543 | valarmDocument.setComponentType("VALARM" ); |
544 | valarmDocument.setProperties(valarmProperties); |
545 | property.setValueType(QVersitProperty::VersitDocumentType); |
546 | property.setName(QStringLiteral("VALARM" )); |
547 | property.setValue(QVariant::fromValue(value: valarmDocument)); |
548 | QOrganizerItemAudibleReminder audibleReminder; |
549 | audibleReminder.setDataUrl(QUrl("http://qt.nokia.com" )); |
550 | audibleReminder.setRepetition(count: 3, delaySeconds: 5); |
551 | audibleReminder.setSecondsBeforeStart(90); |
552 | propertiesToImport << property; |
553 | expectedDetails << audibleReminder; |
554 | } |
555 | { |
556 | QVersitProperty property; |
557 | QVersitDocument valarmDocument(QVersitDocument::ICalendar20Type); |
558 | QList<QVersitProperty> valarmProperties; |
559 | |
560 | property.setName(QStringLiteral("ACTION" )); |
561 | property.setValue(QStringLiteral("DISPLAY" )); |
562 | valarmProperties << property; |
563 | property.setName(QStringLiteral("DURATION" )); |
564 | property.setValue(QStringLiteral("PT5S" )); |
565 | valarmProperties << property; |
566 | property.setName(QStringLiteral("REPEAT" )); |
567 | property.setValue(3); |
568 | valarmProperties << property; |
569 | property.setName(QStringLiteral("TRIGGER" )); |
570 | property.setValue(QStringLiteral("-PT90S" )); |
571 | valarmProperties << property; |
572 | property.setName(QStringLiteral("DESCRIPTION" )); |
573 | property.setValue(QStringLiteral("Test visual reminder" )); |
574 | valarmProperties << property; |
575 | |
576 | valarmDocument.setComponentType("VALARM" ); |
577 | valarmDocument.setProperties(valarmProperties); |
578 | property.setValueType(QVersitProperty::VersitDocumentType); |
579 | property.setName(QStringLiteral("VALARM" )); |
580 | property.setValue(QVariant::fromValue(value: valarmDocument)); |
581 | QOrganizerItemVisualReminder visualReminder; |
582 | visualReminder.setMessage(QStringLiteral("Test visual reminder" )); |
583 | visualReminder.setRepetition(count: 3, delaySeconds: 5); |
584 | visualReminder.setSecondsBeforeStart(90); |
585 | propertiesToImport << property; |
586 | expectedDetails << visualReminder; |
587 | } |
588 | { |
589 | QVersitProperty property; |
590 | QVersitDocument valarmDocument; |
591 | QList<QVersitProperty> valarmProperties; |
592 | |
593 | property.setName(QStringLiteral("ACTION" )); |
594 | property.setValue(QStringLiteral("EMAIL" )); |
595 | valarmProperties << property; |
596 | property.setName(QStringLiteral("DURATION" )); |
597 | property.setValue(QStringLiteral("PT5S" )); |
598 | valarmProperties << property; |
599 | property.setName(QStringLiteral("REPEAT" )); |
600 | property.setValue(3); |
601 | valarmProperties << property; |
602 | property.setName(QStringLiteral("TRIGGER" )); |
603 | property.setValue(QStringLiteral("-PT90S" )); |
604 | valarmProperties << property; |
605 | property.setName(QStringLiteral("DESCRIPTION" )); |
606 | property.setValue(QStringLiteral("Test email body" )); |
607 | valarmProperties << property; |
608 | property.setName(QStringLiteral("SUMMARY" )); |
609 | property.setValue(QStringLiteral("Test email subject" )); |
610 | valarmProperties << property; |
611 | property.setName(QStringLiteral("ATTENDEE" )); |
612 | property.setValue(QStringLiteral("First email recipient" )); |
613 | valarmProperties << property; |
614 | property.setValue(QStringLiteral("Second email recipient" )); |
615 | valarmProperties << property; |
616 | |
617 | valarmDocument.setComponentType("VALARM" ); |
618 | valarmDocument.setProperties(valarmProperties); |
619 | property.setValueType(QVersitProperty::VersitDocumentType); |
620 | property.setName(QStringLiteral("VALARM" )); |
621 | property.setValue(QVariant::fromValue(value: valarmDocument)); |
622 | QOrganizerItemEmailReminder emailReminder; |
623 | emailReminder.setContents(QStringLiteral("Test email subject" ), |
624 | QStringLiteral("Test email body" ), |
625 | attachments: QVariantList()); |
626 | emailReminder.setRepetition(count: 3, delaySeconds: 5); |
627 | emailReminder.setSecondsBeforeStart(90); |
628 | emailReminder.setRecipients(QStringList() |
629 | << QStringLiteral("First email recipient" ) |
630 | << QStringLiteral("Second email recipient" )); |
631 | propertiesToImport << property; |
632 | expectedDetails << emailReminder; |
633 | } |
634 | QTest::newRow(dataTag: "multiple reminders" ) << propertiesToImport |
635 | << expectedDetails; |
636 | } |
637 | { |
638 | QVersitProperty property; |
639 | property.setName(QStringLiteral("DESCRIPTION" )); |
640 | property.setValue(QStringLiteral("Twinkle, twinkle, little bat! How I wonder what you're at." )); |
641 | QOrganizerItemDescription description; |
642 | description.setDescription(QStringLiteral("Twinkle, twinkle, little bat! How I wonder what you're at." )); |
643 | QTest::newRow(dataTag: "one description" ) << (QList<QVersitProperty>() << property) |
644 | << (QList<QOrganizerItemDetail>() << description); |
645 | } |
646 | |
647 | { |
648 | QVersitProperty property; |
649 | property.setName(QStringLiteral("CATEGORIES" )); |
650 | property.setValue(QStringLiteral("Important Event" )); |
651 | QOrganizerItemTag tag; |
652 | tag.setTag(QStringLiteral("Important Event" )); |
653 | QTest::newRow(dataTag: "tag 1" ) |
654 | << (QList<QVersitProperty>() << property) |
655 | << (QList<QOrganizerItemDetail>() << tag); |
656 | |
657 | // Set another one for multiple handling test |
658 | property.setValue(QStringLiteral("Important Event 2" )); |
659 | tag.setTag(QStringLiteral("Important Event 2" )); |
660 | QTest::newRow(dataTag: "tag 2" ) |
661 | << (QList<QVersitProperty>() << property) |
662 | << (QList<QOrganizerItemDetail>() << tag); |
663 | |
664 | // Empty tag |
665 | property.clear(); |
666 | property.setName("CATEGORIES" ); |
667 | tag.removeValue(field: QOrganizerItemTag::FieldTag); |
668 | QTest::newRow(dataTag: "empty tag" ) |
669 | << (QList<QVersitProperty>() << property) |
670 | << (QList<QOrganizerItemDetail>() ); // Detail side should be empty |
671 | } |
672 | |
673 | { |
674 | QVersitProperty property = createExtendedDetailPropertyForStringData(name: "name" , data: "data" ); |
675 | QOrganizerItemExtendedDetail extendedDetail = createExtendedDetail(name: "name" , data: "data" ); |
676 | QTest::newRow(dataTag: "extended detail" ) |
677 | << (QList<QVersitProperty>() << property) |
678 | << (QList<QOrganizerItemDetail>() << extendedDetail); |
679 | } |
680 | |
681 | { |
682 | QVersitProperty property; // Proper property. |
683 | property.setName(QStringLiteral("X-QTPROJECT-VERSION" )); |
684 | property.setValueType(QVersitProperty::CompoundType); |
685 | property.setValue(QStringList() << QStringLiteral("4711" ) << QStringLiteral("134f23dbb2" )); |
686 | QOrganizerItemVersion version; |
687 | version.setVersion(4711); |
688 | version.setExtendedVersion(QByteArray("134f23dbb2" )); |
689 | QTest::newRow(dataTag: "version" ) << (QList<QVersitProperty>() << property) |
690 | << (QList<QOrganizerItemDetail>() << version); |
691 | } |
692 | |
693 | { |
694 | QVersitProperty property; // Extended version empty. |
695 | property.setName(QStringLiteral("X-QTPROJECT-VERSION" )); |
696 | property.setValueType(QVersitProperty::CompoundType); |
697 | property.setValue(QStringList() << QStringLiteral("4711" ) << QStringLiteral("" )); |
698 | QOrganizerItemVersion version; |
699 | version.setVersion(4711); |
700 | QTest::newRow(dataTag: "version" ) << (QList<QVersitProperty>() << property) |
701 | << (QList<QOrganizerItemDetail>() << version); |
702 | } |
703 | |
704 | { |
705 | QVersitProperty property; // No extended version. |
706 | property.setName(QStringLiteral("X-QTPROJECT-VERSION" )); |
707 | property.setValueType(QVersitProperty::CompoundType); |
708 | property.setValue(QStringList() << QStringLiteral("4711" )); |
709 | QOrganizerItemVersion version; |
710 | version.setVersion(4711); |
711 | QTest::newRow(dataTag: "version" ) << (QList<QVersitProperty>() << property) |
712 | << (QList<QOrganizerItemDetail>() << version); |
713 | } |
714 | |
715 | { |
716 | QVersitProperty property; // Version non number. |
717 | property.setName(QStringLiteral("X-QTPROJECT-VERSION" )); |
718 | property.setValueType(QVersitProperty::CompoundType); |
719 | property.setValue(QStringList() << QStringLiteral("2someletters" )); |
720 | QTest::newRow(dataTag: "version" ) << (QList<QVersitProperty>() << property) |
721 | << (QList<QOrganizerItemDetail>()); |
722 | } |
723 | |
724 | { |
725 | QVersitProperty property; // Version emptry string. |
726 | property.setName(QStringLiteral("X-QTPROJECT-VERSION" )); |
727 | property.setValueType(QVersitProperty::CompoundType); |
728 | property.setValue(QStringList() << QStringLiteral("" )); |
729 | QTest::newRow(dataTag: "version" ) << (QList<QVersitProperty>() << property) |
730 | << (QList<QOrganizerItemDetail>()); |
731 | } |
732 | |
733 | { |
734 | QVersitProperty property; // Empty property. |
735 | property.setName(QStringLiteral("X-QTPROJECT-VERSION" )); |
736 | property.setValueType(QVersitProperty::CompoundType); |
737 | QTest::newRow(dataTag: "version" ) << (QList<QVersitProperty>() << property) |
738 | << (QList<QOrganizerItemDetail>()); |
739 | } |
740 | |
741 | { |
742 | QVersitProperty property1; |
743 | property1.setName(QStringLiteral("COMMENT" )); |
744 | property1.setValue(QStringLiteral("Comment 1" )); |
745 | QVersitProperty property2; |
746 | property2.setName(QStringLiteral("COMMENT" )); |
747 | property2.setValue(QStringLiteral("Comment 2" )); |
748 | QOrganizerItemComment ; |
749 | comment1.setComment(QStringLiteral("Comment 1" )); |
750 | QOrganizerItemComment ; |
751 | comment2.setComment(QStringLiteral("Comment 2" )); |
752 | QTest::newRow(dataTag: "two comments" ) |
753 | << (QList<QVersitProperty>() << property1 << property2) |
754 | << (QList<QOrganizerItemDetail>() << comment1 << comment2); |
755 | } |
756 | |
757 | { |
758 | QVersitProperty property; |
759 | property.setName(QStringLiteral("UID" )); |
760 | property.setValue(QStringLiteral("1234567" )); |
761 | QOrganizerItemGuid guid; |
762 | guid.setGuid(QStringLiteral("1234567" )); |
763 | QTest::newRow(dataTag: "guid" ) |
764 | << (QList<QVersitProperty>() << property) |
765 | << (QList<QOrganizerItemDetail>() << guid); |
766 | } |
767 | |
768 | { |
769 | QList<QVersitProperty> properties; |
770 | QVersitProperty dtstart; |
771 | dtstart.setName(QStringLiteral("DTSTART" )); |
772 | dtstart.setValue(QStringLiteral("20100102T030405" )); |
773 | properties << dtstart; |
774 | QVersitProperty dtend; |
775 | dtend.setName(QStringLiteral("DTEND" )); |
776 | dtend.setValue(QStringLiteral("20100102T030406" )); |
777 | properties << dtend; |
778 | QOrganizerEventTime etr; |
779 | etr.setStartDateTime(QDateTime(QDate(2010, 1, 2), QTime(3, 4, 5))); |
780 | etr.setEndDateTime(QDateTime(QDate(2010, 1, 2), QTime(3, 4, 6))); |
781 | QTest::newRow(dataTag: "dtstart and dtend" ) << properties |
782 | << (QList<QOrganizerItemDetail>() << etr); |
783 | |
784 | dtend.setValue(QStringLiteral("20100102T235959" )); |
785 | properties.prepend(t: dtend); |
786 | QTest::newRow(dataTag: "multiple dtstart and dtend" ) << properties |
787 | << (QList<QOrganizerItemDetail>() << etr); // last takes precedence |
788 | } |
789 | |
790 | { |
791 | QList<QVersitProperty> properties; |
792 | QVersitProperty dtstart; |
793 | dtstart.setName(QStringLiteral("DTSTART" )); |
794 | dtstart.setValue(QStringLiteral("20100102" )); |
795 | dtstart.insertParameter(QStringLiteral("VALUE" ), QStringLiteral("DATE" )); |
796 | properties << dtstart; |
797 | QVersitProperty dtend; |
798 | dtend.setName(QStringLiteral("DTEND" )); |
799 | // Note: in iCalendar, the end date is exclusive while in Qt Organizer, it is inclusive. |
800 | // Hence, this is an event that occurs all day on 2 January (not including 3 January) |
801 | dtend.setValue(QStringLiteral("20100103" )); |
802 | dtend.insertParameter(QStringLiteral("VALUE" ), QStringLiteral("DATE" )); |
803 | properties << dtend; |
804 | QOrganizerEventTime etr; |
805 | // The time portion must be valid but is ignored. This test cheats a bit because it knows |
806 | // the implementation sets it to 00:00:00 |
807 | etr.setStartDateTime(QDateTime(QDate(2010, 1, 2), QTime(0, 0, 0))); |
808 | etr.setEndDateTime(QDateTime(QDate(2010, 1, 2), QTime(0, 0, 0))); |
809 | etr.setAllDay(true); |
810 | QTest::newRow(dataTag: "all day event" ) << properties |
811 | << (QList<QOrganizerItemDetail>() << etr); |
812 | } |
813 | |
814 | { |
815 | QVersitProperty dtstart; |
816 | dtstart.setName(QStringLiteral("DTSTART" )); |
817 | dtstart.setValue(QStringLiteral("20091231T000000" )); // equivalent to 2010, day zero |
818 | |
819 | QVersitProperty duration; |
820 | duration.setName(QStringLiteral("DURATION" )); |
821 | duration.setValue(QStringLiteral("P15DT5H7M20S" )); |
822 | QOrganizerEventTime etr; |
823 | etr.setStartDateTime(QDateTime(QDate(2009, 12, 31), QTime(0, 0, 0))); |
824 | etr.setEndDateTime(QDateTime(QDate(2010, 1, 15), QTime(5, 7, 20))); |
825 | QTest::newRow(dataTag: "dtstart and duration: days hours minutes seconds" ) |
826 | << (QList<QVersitProperty>() << dtstart << duration) |
827 | << (QList<QOrganizerItemDetail>() << etr); |
828 | QTest::newRow(dataTag: "duration and dtstart" ) |
829 | << (QList<QVersitProperty>() << duration << dtstart) |
830 | << (QList<QOrganizerItemDetail>() << etr); |
831 | |
832 | duration.setValue(QStringLiteral("PT5H7M20S" )); |
833 | etr.setEndDateTime(QDateTime(QDate(2009, 12, 31), QTime(5, 7, 20))); |
834 | QTest::newRow(dataTag: "dtstart and duration: hours minutes seconds" ) |
835 | << (QList<QVersitProperty>() << dtstart << duration) |
836 | << (QList<QOrganizerItemDetail>() << etr); |
837 | |
838 | duration.setValue(QStringLiteral("PT7M20S" )); |
839 | etr.setEndDateTime(QDateTime(QDate(2009, 12, 31), QTime(0, 7, 20))); |
840 | QTest::newRow(dataTag: "dtstart and duration: minutes seconds" ) |
841 | << (QList<QVersitProperty>() << dtstart << duration) |
842 | << (QList<QOrganizerItemDetail>() << etr); |
843 | |
844 | duration.setValue(QStringLiteral("PT20S" )); |
845 | etr.setEndDateTime(QDateTime(QDate(2009, 12, 31), QTime(0, 0, 20))); |
846 | QTest::newRow(dataTag: "dtstart and duration: seconds" ) |
847 | << (QList<QVersitProperty>() << dtstart << duration) |
848 | << (QList<QOrganizerItemDetail>() << etr); |
849 | |
850 | duration.setValue(QStringLiteral("P15DT5H7M" )); |
851 | etr.setEndDateTime(QDateTime(QDate(2010, 1, 15), QTime(5, 7, 0))); |
852 | QTest::newRow(dataTag: "dtstart and duration: days hours minutes" ) |
853 | << (QList<QVersitProperty>() << dtstart << duration) |
854 | << (QList<QOrganizerItemDetail>() << etr); |
855 | |
856 | duration.setValue(QStringLiteral("P15DT5H" )); |
857 | etr.setEndDateTime(QDateTime(QDate(2010, 1, 15), QTime(5, 0, 0))); |
858 | QTest::newRow(dataTag: "dtstart and duration: days hours" ) |
859 | << (QList<QVersitProperty>() << dtstart << duration) |
860 | << (QList<QOrganizerItemDetail>() << etr); |
861 | |
862 | duration.setValue(QStringLiteral("P15D" )); |
863 | etr.setEndDateTime(QDateTime(QDate(2010, 1, 15), QTime(0, 0, 0))); |
864 | QTest::newRow(dataTag: "dtstart and duration: days" ) |
865 | << (QList<QVersitProperty>() << dtstart << duration) |
866 | << (QList<QOrganizerItemDetail>() << etr); |
867 | |
868 | duration.setValue(QStringLiteral("P7W" )); |
869 | etr.setEndDateTime(QDateTime(QDate(2010, 2, 18), QTime(0, 0, 0))); |
870 | QTest::newRow(dataTag: "dtstart and duration: weeks" ) |
871 | << (QList<QVersitProperty>() << dtstart << duration) |
872 | << (QList<QOrganizerItemDetail>() << etr); |
873 | |
874 | dtstart.setValue(QStringLiteral("20100115T050720" )); |
875 | duration.setValue(QStringLiteral("-P15DT5H7M20S" )); |
876 | etr.setStartDateTime(QDateTime(QDate(2010, 1, 15), QTime(5, 7, 20))); |
877 | etr.setEndDateTime(QDateTime(QDate(2009, 12, 31), QTime(0, 0, 0))); |
878 | QTest::newRow(dataTag: "dtstart and duration: negative" ) |
879 | << (QList<QVersitProperty>() << dtstart << duration) |
880 | << (QList<QOrganizerItemDetail>() << etr); |
881 | } |
882 | |
883 | { |
884 | QList<QVersitProperty> properties; |
885 | QVersitProperty created; |
886 | created.setName(QStringLiteral("CREATED" )); |
887 | created.setValue(QStringLiteral("20100102T030405Z" )); |
888 | properties << created; |
889 | QVersitProperty modified; |
890 | modified.setName(QStringLiteral("LAST-MODIFIED" )); |
891 | modified.setValue(QStringLiteral("20100102T030406Z" )); |
892 | properties << modified; |
893 | QOrganizerItemTimestamp timestamp; |
894 | timestamp.setCreated(QDateTime(QDate(2010, 1, 2), QTime(3, 4, 5), Qt::UTC)); |
895 | timestamp.setLastModified(QDateTime(QDate(2010, 1, 2), QTime(3, 4, 6), Qt::UTC)); |
896 | QTest::newRow(dataTag: "created and last modified" ) << properties |
897 | << (QList<QOrganizerItemDetail>() << timestamp); |
898 | } |
899 | |
900 | { |
901 | QVersitProperty rrule; |
902 | rrule.setName(QStringLiteral("RRULE" )); |
903 | rrule.setValue(QStringLiteral("FREQ=DAILY" )); |
904 | QOrganizerItemRecurrence recurrence; |
905 | QOrganizerRecurrenceRule recurrenceRule; |
906 | recurrenceRule.setFrequency(QOrganizerRecurrenceRule::Daily); |
907 | recurrence.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << recurrenceRule); |
908 | QTest::newRow(dataTag: "rrule daily" ) |
909 | << (QList<QVersitProperty>() << rrule) |
910 | << (QList<QOrganizerItemDetail>() << recurrence); |
911 | |
912 | rrule.setValue(QStringLiteral("FREQ=WEEKLY" )); |
913 | recurrenceRule.setFrequency(QOrganizerRecurrenceRule::Weekly); |
914 | recurrence.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << recurrenceRule); |
915 | QTest::newRow(dataTag: "rrule weekly" ) |
916 | << (QList<QVersitProperty>() << rrule) |
917 | << (QList<QOrganizerItemDetail>() << recurrence); |
918 | |
919 | rrule.setValue(QStringLiteral("FREQ=MONTHLY" )); |
920 | recurrenceRule.setFrequency(QOrganizerRecurrenceRule::Monthly); |
921 | recurrence.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << recurrenceRule); |
922 | QTest::newRow(dataTag: "rrule monthly" ) |
923 | << (QList<QVersitProperty>() << rrule) |
924 | << (QList<QOrganizerItemDetail>() << recurrence); |
925 | |
926 | rrule.setValue(QStringLiteral("FREQ=YEARLY" )); |
927 | recurrenceRule.setFrequency(QOrganizerRecurrenceRule::Yearly); |
928 | recurrence.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << recurrenceRule); |
929 | QTest::newRow(dataTag: "rrule yearly" ) |
930 | << (QList<QVersitProperty>() << rrule) |
931 | << (QList<QOrganizerItemDetail>() << recurrence); |
932 | |
933 | rrule.setValue(QStringLiteral("FREQ=MONTHLY;INTERVAL=2;BYDAY=TU" )); |
934 | recurrenceRule.setFrequency(QOrganizerRecurrenceRule::Monthly); |
935 | recurrenceRule.setInterval(2); |
936 | recurrenceRule.setDaysOfWeek(QSet<Qt::DayOfWeek>() << Qt::Tuesday); |
937 | recurrence.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << recurrenceRule); |
938 | QTest::newRow(dataTag: "rrule monthly" ) |
939 | << (QList<QVersitProperty>() << rrule) |
940 | << (QList<QOrganizerItemDetail>() << recurrence); |
941 | } |
942 | |
943 | { |
944 | QVersitProperty rrule; |
945 | rrule.setName(QStringLiteral("RRULE" )); |
946 | rrule.setValue(QStringLiteral("FREQ=MONTHLY;BYMONTHDAY=1,-3" )); |
947 | QOrganizerItemRecurrence recurrence; |
948 | QOrganizerRecurrenceRule recurrenceRule; |
949 | recurrenceRule.setFrequency(QOrganizerRecurrenceRule::Monthly); |
950 | recurrenceRule.setDaysOfMonth(QSet<int>() << 1 << -3); |
951 | recurrence.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << recurrenceRule); |
952 | QTest::newRow(dataTag: "rrule bymonthday" ) |
953 | << (QList<QVersitProperty>() << rrule) |
954 | << (QList<QOrganizerItemDetail>() << recurrence); |
955 | } |
956 | |
957 | { |
958 | QVersitProperty rrule; |
959 | rrule.setName(QStringLiteral("RRULE" )); |
960 | rrule.setValue(QStringLiteral("FREQ=YEARLY;BYWEEKNO=1,-3" )); |
961 | QOrganizerItemRecurrence recurrence; |
962 | QOrganizerRecurrenceRule recurrenceRule; |
963 | recurrenceRule.setFrequency(QOrganizerRecurrenceRule::Yearly); |
964 | recurrenceRule.setWeeksOfYear(QSet<int>() << 1 << -3); |
965 | recurrence.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << recurrenceRule); |
966 | QTest::newRow(dataTag: "rrule byweekno" ) |
967 | << (QList<QVersitProperty>() << rrule) |
968 | << (QList<QOrganizerItemDetail>() << recurrence); |
969 | } |
970 | |
971 | { |
972 | QVersitProperty rrule; |
973 | rrule.setName(QStringLiteral("RRULE" )); |
974 | rrule.setValue(QStringLiteral("FREQ=YEARLY;BYMONTH=1,10" )); |
975 | QOrganizerItemRecurrence recurrence; |
976 | QOrganizerRecurrenceRule recurrenceRule; |
977 | recurrenceRule.setFrequency(QOrganizerRecurrenceRule::Yearly); |
978 | recurrenceRule.setMonthsOfYear(QSet<QOrganizerRecurrenceRule::Month>() |
979 | << QOrganizerRecurrenceRule::January |
980 | << QOrganizerRecurrenceRule::October); |
981 | recurrence.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << recurrenceRule); |
982 | QTest::newRow(dataTag: "rrule bymonth" ) |
983 | << (QList<QVersitProperty>() << rrule) |
984 | << (QList<QOrganizerItemDetail>() << recurrence); |
985 | } |
986 | |
987 | { |
988 | QVersitProperty rrule; |
989 | rrule.setName(QStringLiteral("RRULE" )); |
990 | rrule.setValue(QStringLiteral("FREQ=YEARLY;BYYEARDAY=1,366,-1" )); |
991 | QOrganizerItemRecurrence recurrence; |
992 | QOrganizerRecurrenceRule recurrenceRule; |
993 | recurrenceRule.setFrequency(QOrganizerRecurrenceRule::Yearly); |
994 | recurrenceRule.setDaysOfYear(QSet<int>() << 1 << 366 << -1); |
995 | recurrence.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << recurrenceRule); |
996 | QTest::newRow(dataTag: "rrule byyearday" ) |
997 | << (QList<QVersitProperty>() << rrule) |
998 | << (QList<QOrganizerItemDetail>() << recurrence); |
999 | } |
1000 | |
1001 | { |
1002 | QVersitProperty rrule; |
1003 | rrule.setName(QStringLiteral("RRULE" )); |
1004 | rrule.setValue(QStringLiteral("FREQ=WEEKLY;COUNT=4;INTERVAL=2;BYDAY=TU,SU;WKST=SU" )); |
1005 | QOrganizerItemRecurrence recurrence; |
1006 | QOrganizerRecurrenceRule recurrenceRule; |
1007 | recurrenceRule.setFrequency(QOrganizerRecurrenceRule::Weekly); |
1008 | recurrenceRule.setInterval(2); |
1009 | recurrenceRule.setLimit(4); |
1010 | recurrenceRule.setDaysOfWeek(QSet<Qt::DayOfWeek>() << Qt::Tuesday << Qt::Sunday); |
1011 | recurrenceRule.setFirstDayOfWeek(Qt::Sunday); |
1012 | recurrence.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << recurrenceRule); |
1013 | QTest::newRow(dataTag: "rrule wkst" ) |
1014 | << (QList<QVersitProperty>() << rrule) |
1015 | << (QList<QOrganizerItemDetail>() << recurrence); |
1016 | } |
1017 | |
1018 | { |
1019 | QVersitProperty rrule; |
1020 | rrule.setName(QStringLiteral("RRULE" )); |
1021 | rrule.setValue(QStringLiteral("FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1" )); |
1022 | QOrganizerItemRecurrence recurrence; |
1023 | QOrganizerRecurrenceRule recurrenceRule; |
1024 | recurrenceRule.setFrequency(QOrganizerRecurrenceRule::Monthly); |
1025 | recurrenceRule.setDaysOfWeek(QSet<Qt::DayOfWeek>() |
1026 | << Qt::Monday << Qt::Tuesday << Qt::Wednesday << Qt::Thursday << Qt::Friday); |
1027 | recurrenceRule.setPositions(QSet<int>() << -1); |
1028 | recurrence.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << recurrenceRule); |
1029 | QTest::newRow(dataTag: "rrule bysetpos" ) |
1030 | << (QList<QVersitProperty>() << rrule) |
1031 | << (QList<QOrganizerItemDetail>() << recurrence); |
1032 | } |
1033 | |
1034 | { |
1035 | QVersitProperty rrule; |
1036 | rrule.setName(QStringLiteral("RRULE" )); |
1037 | rrule.setValue(QStringLiteral("FREQ=YEARLY;BYMONTH=4;BYDAY=1SU" )); |
1038 | QOrganizerItemRecurrence recurrence; |
1039 | QOrganizerRecurrenceRule recurrenceRule; |
1040 | recurrenceRule.setFrequency(QOrganizerRecurrenceRule::Yearly); |
1041 | recurrenceRule.setMonthsOfYear(QSet<QOrganizerRecurrenceRule::Month>() |
1042 | << QOrganizerRecurrenceRule::April); |
1043 | recurrenceRule.setDaysOfWeek(QSet<Qt::DayOfWeek>() << Qt::Sunday); |
1044 | recurrenceRule.setPositions(QSet<int>() << 1); |
1045 | recurrence.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << recurrenceRule); |
1046 | QTest::newRow(dataTag: "rrule byday with position" ) |
1047 | << (QList<QVersitProperty>() << rrule) |
1048 | << (QList<QOrganizerItemDetail>() << recurrence); |
1049 | } |
1050 | |
1051 | { |
1052 | QVersitProperty rrule; |
1053 | rrule.setName(QStringLiteral("RRULE" )); |
1054 | rrule.setValue(QStringLiteral("FREQ=DAILY;UNTIL=20000131;BYMONTH=1" )); |
1055 | QOrganizerItemRecurrence recurrence; |
1056 | QOrganizerRecurrenceRule recurrenceRule; |
1057 | recurrenceRule.setFrequency(QOrganizerRecurrenceRule::Daily); |
1058 | recurrenceRule.setLimit(QDate(2000, 1, 31)); |
1059 | recurrenceRule.setMonthsOfYear(QSet<QOrganizerRecurrenceRule::Month>() |
1060 | << QOrganizerRecurrenceRule::January); |
1061 | recurrence.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << recurrenceRule); |
1062 | QTest::newRow(dataTag: "rrule until" ) |
1063 | << (QList<QVersitProperty>() << rrule) |
1064 | << (QList<QOrganizerItemDetail>() << recurrence); |
1065 | |
1066 | rrule.setValue(QStringLiteral("FREQ=DAILY;UNTIL=20000131T101112;BYMONTH=1" )); |
1067 | QTest::newRow(dataTag: "rrule until with time" ) |
1068 | << (QList<QVersitProperty>() << rrule) |
1069 | << (QList<QOrganizerItemDetail>() << recurrence); |
1070 | } |
1071 | |
1072 | { |
1073 | QVersitProperty rrule; |
1074 | rrule.setName(QStringLiteral("RRULE" )); |
1075 | rrule.setValue(QStringLiteral("FREQ=DAILY;COUNT=5;BYMONTH=1" )); |
1076 | QOrganizerItemRecurrence recurrence; |
1077 | QOrganizerRecurrenceRule recurrenceRule; |
1078 | recurrenceRule.setFrequency(QOrganizerRecurrenceRule::Daily); |
1079 | recurrenceRule.setLimit(5); |
1080 | recurrenceRule.setMonthsOfYear(QSet<QOrganizerRecurrenceRule::Month>() |
1081 | << QOrganizerRecurrenceRule::January); |
1082 | recurrence.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << recurrenceRule); |
1083 | QTest::newRow(dataTag: "rrule count" ) |
1084 | << (QList<QVersitProperty>() << rrule) |
1085 | << (QList<QOrganizerItemDetail>() << recurrence); |
1086 | } |
1087 | |
1088 | { |
1089 | QVersitProperty rrule; |
1090 | rrule.setName(QStringLiteral("RRULE" )); |
1091 | rrule.setValue(QStringLiteral("FREQ=WEEKLY;INTERVAL=0" )); |
1092 | QOrganizerItemRecurrence recurrence; |
1093 | QOrganizerRecurrenceRule recurrenceRule; |
1094 | recurrenceRule.setFrequency(QOrganizerRecurrenceRule::Weekly); |
1095 | recurrenceRule.setInterval(1); // default interval when invalid interval is found |
1096 | recurrence.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << recurrenceRule); |
1097 | QTest::newRow(dataTag: "rrule invalid interval1" ) |
1098 | << (QList<QVersitProperty>() << rrule) |
1099 | << (QList<QOrganizerItemDetail>() << recurrence); |
1100 | |
1101 | rrule.setValue(QStringLiteral("FREQ=WEEKLY;INTERVAL=bad" )); |
1102 | QTest::newRow(dataTag: "rrule invalid interval2" ) |
1103 | << (QList<QVersitProperty>() << rrule) |
1104 | << (QList<QOrganizerItemDetail>() << recurrence); |
1105 | |
1106 | rrule.setValue(QStringLiteral("FREQ=WEEKLY;INTERVAL=" )); |
1107 | QTest::newRow(dataTag: "rrule invalid interval3" ) |
1108 | << (QList<QVersitProperty>() << rrule) |
1109 | << (QList<QOrganizerItemDetail>() << recurrence); |
1110 | } |
1111 | |
1112 | { |
1113 | QVersitProperty rrule; |
1114 | rrule.setName(QStringLiteral("RRULE" )); |
1115 | rrule.setValue(QStringLiteral("FREQ=WEEKLY;COUNT=-2" )); |
1116 | QOrganizerItemRecurrence recurrence; |
1117 | QOrganizerRecurrenceRule recurrenceRule; |
1118 | recurrenceRule.setFrequency(QOrganizerRecurrenceRule::Weekly); |
1119 | recurrenceRule.setLimit(-1); // default count when invalid count is found |
1120 | recurrence.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << recurrenceRule); |
1121 | QTest::newRow(dataTag: "rrule invalid count1" ) |
1122 | << (QList<QVersitProperty>() << rrule) |
1123 | << (QList<QOrganizerItemDetail>() << recurrence); |
1124 | |
1125 | rrule.setValue(QStringLiteral("FREQ=WEEKLY;COUNT=bad" )); |
1126 | QTest::newRow(dataTag: "rrule invalid count2" ) |
1127 | << (QList<QVersitProperty>() << rrule) |
1128 | << (QList<QOrganizerItemDetail>() << recurrence); |
1129 | |
1130 | rrule.setValue(QStringLiteral("FREQ=WEEKLY;COUNT=" )); |
1131 | QTest::newRow(dataTag: "rrule invalid count3" ) |
1132 | << (QList<QVersitProperty>() << rrule) |
1133 | << (QList<QOrganizerItemDetail>() << recurrence); |
1134 | } |
1135 | |
1136 | { |
1137 | QVersitProperty dtstart; |
1138 | dtstart.setName(QStringLiteral("DTSTART" )); |
1139 | dtstart.setValue(QStringLiteral("19970304T110000" )); |
1140 | QVersitProperty dtend; |
1141 | dtend.setName(QStringLiteral("DTEND" )); |
1142 | dtend.setValue(QStringLiteral("19970304T110000" )); |
1143 | QVersitProperty rdate; |
1144 | rdate.setName(QStringLiteral("RDATE" )); |
1145 | rdate.setValue(QStringLiteral("19970304" )); |
1146 | QOrganizerEventTime etr; |
1147 | etr.setStartDateTime(QDateTime(QDate(1997, 3, 4), QTime(11, 0, 0))); |
1148 | etr.setEndDateTime(QDateTime(QDate(1997, 3, 4), QTime(11, 0, 0))); |
1149 | QOrganizerItemRecurrence recurrence; |
1150 | QSet<QDate> recurrenceDates; |
1151 | recurrenceDates << QDate(1997, 3, 4); |
1152 | recurrence.setRecurrenceDates(recurrenceDates); |
1153 | QTest::newRow(dataTag: "rdate" ) |
1154 | << (QList<QVersitProperty>() << dtstart << dtend << rdate) |
1155 | << (QList<QOrganizerItemDetail>() << etr << recurrence); |
1156 | |
1157 | // XXX times in RDATE are ignored |
1158 | rdate.setValue(QStringLiteral("19970304T133700" )); |
1159 | recurrenceDates.clear(); |
1160 | recurrenceDates << QDate(1997, 3, 4); |
1161 | recurrence.setRecurrenceDates(recurrenceDates); |
1162 | QTest::newRow(dataTag: "rdate with time" ) |
1163 | << (QList<QVersitProperty>() << dtstart << dtend << rdate) |
1164 | << (QList<QOrganizerItemDetail>() << etr << recurrence); |
1165 | |
1166 | rdate.setValue(QStringLiteral("19970304,19970504,19970704" )); |
1167 | recurrenceDates.clear(); |
1168 | recurrenceDates << QDate(1997, 3, 4) |
1169 | << QDate(1997, 5, 4) |
1170 | << QDate(1997, 7, 4); |
1171 | recurrence.setRecurrenceDates(recurrenceDates); |
1172 | QTest::newRow(dataTag: "multiple rdate" ) |
1173 | << (QList<QVersitProperty>() << dtstart << dtend << rdate) |
1174 | << (QList<QOrganizerItemDetail>() << etr << recurrence); |
1175 | } |
1176 | |
1177 | { |
1178 | QVersitProperty dtstart; |
1179 | dtstart.setName(QStringLiteral("DTSTART" )); |
1180 | dtstart.setValue(QStringLiteral("19970304T110000" )); |
1181 | QVersitProperty dtend; |
1182 | dtend.setName(QStringLiteral("DTEND" )); |
1183 | dtend.setValue(QStringLiteral("19970304T110000" )); |
1184 | QVersitProperty rdate; |
1185 | rdate.setName(QStringLiteral("EXDATE" )); |
1186 | rdate.setValue(QStringLiteral("19970304" )); |
1187 | QOrganizerEventTime etr; |
1188 | etr.setStartDateTime(QDateTime(QDate(1997, 3, 4), QTime(11, 0, 0))); |
1189 | etr.setEndDateTime(QDateTime(QDate(1997, 3, 4), QTime(11, 0, 0))); |
1190 | QOrganizerItemRecurrence recurrence; |
1191 | QSet<QDate> exceptionDates; |
1192 | exceptionDates << QDate(1997, 3, 4); |
1193 | recurrence.setExceptionDates(exceptionDates); |
1194 | QTest::newRow(dataTag: "exdate" ) |
1195 | << (QList<QVersitProperty>() << dtstart << dtend << rdate) |
1196 | << (QList<QOrganizerItemDetail>() << etr << recurrence); |
1197 | } |
1198 | |
1199 | { |
1200 | QVersitProperty property; |
1201 | property.setName(QStringLiteral("PRIORITY" )); |
1202 | property.setValue(QStringLiteral("0" )); |
1203 | |
1204 | QOrganizerItemPriority detail; |
1205 | detail.setPriority(QOrganizerItemPriority::UnknownPriority); |
1206 | QTest::newRow(dataTag: "priority 0" ) |
1207 | << (QList<QVersitProperty>() << property) |
1208 | << (QList<QOrganizerItemDetail>() << detail); |
1209 | |
1210 | property.setValue(QStringLiteral("1" )); |
1211 | detail.setPriority(QOrganizerItemPriority::HighestPriority); |
1212 | QTest::newRow(dataTag: "priority 1" ) |
1213 | << (QList<QVersitProperty>() << property) |
1214 | << (QList<QOrganizerItemDetail>() << detail); |
1215 | |
1216 | property.setValue(QStringLiteral("2" )); |
1217 | detail.setPriority(QOrganizerItemPriority::ExtremelyHighPriority); |
1218 | QTest::newRow(dataTag: "priority 2" ) |
1219 | << (QList<QVersitProperty>() << property) |
1220 | << (QList<QOrganizerItemDetail>() << detail); |
1221 | |
1222 | property.setValue(QStringLiteral("3" )); |
1223 | detail.setPriority(QOrganizerItemPriority::VeryHighPriority); |
1224 | QTest::newRow(dataTag: "priority 3" ) |
1225 | << (QList<QVersitProperty>() << property) |
1226 | << (QList<QOrganizerItemDetail>() << detail); |
1227 | |
1228 | property.setValue(QStringLiteral("4" )); |
1229 | detail.setPriority(QOrganizerItemPriority::HighPriority); |
1230 | QTest::newRow(dataTag: "priority 4" ) |
1231 | << (QList<QVersitProperty>() << property) |
1232 | << (QList<QOrganizerItemDetail>() << detail); |
1233 | |
1234 | property.setValue(QStringLiteral("5" )); |
1235 | detail.setPriority(QOrganizerItemPriority::MediumPriority); |
1236 | QTest::newRow(dataTag: "priority 5" ) |
1237 | << (QList<QVersitProperty>() << property) |
1238 | << (QList<QOrganizerItemDetail>() << detail); |
1239 | |
1240 | property.setValue(QStringLiteral("6" )); |
1241 | detail.setPriority(QOrganizerItemPriority::LowPriority); |
1242 | QTest::newRow(dataTag: "priority 6" ) |
1243 | << (QList<QVersitProperty>() << property) |
1244 | << (QList<QOrganizerItemDetail>() << detail); |
1245 | |
1246 | property.setValue(QStringLiteral("7" )); |
1247 | detail.setPriority(QOrganizerItemPriority::VeryLowPriority); |
1248 | QTest::newRow(dataTag: "priority 7" ) |
1249 | << (QList<QVersitProperty>() << property) |
1250 | << (QList<QOrganizerItemDetail>() << detail); |
1251 | |
1252 | property.setValue(QStringLiteral("8" )); |
1253 | detail.setPriority(QOrganizerItemPriority::ExtremelyLowPriority); |
1254 | QTest::newRow(dataTag: "priority 8" ) |
1255 | << (QList<QVersitProperty>() << property) |
1256 | << (QList<QOrganizerItemDetail>() << detail); |
1257 | |
1258 | property.setValue(QStringLiteral("9" )); |
1259 | detail.setPriority(QOrganizerItemPriority::LowestPriority); |
1260 | QTest::newRow(dataTag: "priority 9" ) |
1261 | << (QList<QVersitProperty>() << property) |
1262 | << (QList<QOrganizerItemDetail>() << detail); |
1263 | } |
1264 | } |
1265 | |
1266 | void tst_QVersitOrganizerImporter::testImportTodoProperties() |
1267 | { |
1268 | QFETCH(QList<QVersitProperty>, properties); |
1269 | QFETCH(QList<QOrganizerItemDetail>, expectedDetails); |
1270 | |
1271 | QVersitDocument document(QVersitDocument::ICalendar20Type); |
1272 | document.setComponentType(QStringLiteral("VCALENDAR" )); |
1273 | QVersitDocument nested(QVersitDocument::ICalendar20Type); |
1274 | nested.setComponentType(QStringLiteral("VTODO" )); |
1275 | foreach (const QVersitProperty& property, properties) { |
1276 | if (property.valueType() == QVersitProperty::VersitDocumentType) |
1277 | nested.addSubDocument(subdocument: property.value<QVersitDocument>()); |
1278 | else |
1279 | nested.addProperty(property); |
1280 | } |
1281 | document.addSubDocument(subdocument: nested); |
1282 | |
1283 | QVersitOrganizerImporter importer; |
1284 | QVERIFY(importer.importDocument(document)); |
1285 | QVERIFY(importer.errorMap().isEmpty()); |
1286 | QList<QOrganizerItem> items = importer.items(); |
1287 | QCOMPARE(items.size(), 1); |
1288 | |
1289 | foreach (const QOrganizerItemDetail& expectedDetail, expectedDetails) { |
1290 | QOrganizerItemDetail actualDetail = items.first().detail(detailType: expectedDetail.type()); |
1291 | if (actualDetail != expectedDetail) { |
1292 | qDebug() << "Actual:" << actualDetail; |
1293 | qDebug() << "Expected:" << expectedDetail; |
1294 | QCOMPARE(actualDetail, expectedDetail); |
1295 | } |
1296 | } |
1297 | } |
1298 | |
1299 | void tst_QVersitOrganizerImporter::testImportTodoProperties_data() |
1300 | { |
1301 | QTest::addColumn<QList<QVersitProperty> >(name: "properties" ); |
1302 | QTest::addColumn<QList<QOrganizerItemDetail> >(name: "expectedDetails" ); |
1303 | |
1304 | { |
1305 | QList<QVersitProperty> properties; |
1306 | QVersitProperty dtstart; |
1307 | dtstart.setName(QStringLiteral("DTSTART" )); |
1308 | dtstart.setValue(QStringLiteral("20100102" )); |
1309 | dtstart.insertParameter(QStringLiteral("VALUE" ), QStringLiteral("DATE" )); |
1310 | properties << dtstart; |
1311 | QVersitProperty dtdue; |
1312 | dtdue.setName(QStringLiteral("DUE" )); |
1313 | dtdue.setValue(QStringLiteral("20100103" )); |
1314 | dtdue.insertParameter(QStringLiteral("VALUE" ), QStringLiteral("DATE" )); |
1315 | properties << dtdue; |
1316 | QOrganizerTodoTime todoTime; |
1317 | // The time portion must be valid but is ignored. This test cheats a bit because it knows |
1318 | // the implementation sets it to 00:00:00 |
1319 | todoTime.setStartDateTime(QDateTime(QDate(2010, 1, 2), QTime(0, 0, 0))); |
1320 | todoTime.setDueDateTime(QDateTime(QDate(2010, 1, 3), QTime(0, 0, 0))); |
1321 | todoTime.setAllDay(true); |
1322 | QTest::newRow(dataTag: "all day todo" ) << properties |
1323 | << (QList<QOrganizerItemDetail>() << todoTime); |
1324 | } |
1325 | |
1326 | { |
1327 | QVersitProperty property; |
1328 | QVersitDocument valarmDocument; |
1329 | QList<QVersitProperty> valarmProperties; |
1330 | |
1331 | property.setName(QStringLiteral("ACTION" )); |
1332 | property.setValue(QStringLiteral("AUDIO" )); |
1333 | valarmProperties << property; |
1334 | property.setName(QStringLiteral("ATTACH" )); |
1335 | property.setValue(QUrl(QStringLiteral("http://qt.nokia.com" ))); |
1336 | valarmProperties << property; |
1337 | property.setName(QStringLiteral("DURATION" )); |
1338 | property.setValue(QStringLiteral("PT5S" )); |
1339 | valarmProperties << property; |
1340 | property.setName(QStringLiteral("REPEAT" )); |
1341 | property.setValue(3); |
1342 | valarmProperties << property; |
1343 | property.setName(QStringLiteral("TRIGGER" )); |
1344 | property.setValue(QStringLiteral("-PT90S" )); |
1345 | valarmProperties << property; |
1346 | |
1347 | valarmDocument.setComponentType("VALARM" ); |
1348 | valarmDocument.setProperties(valarmProperties); |
1349 | property.setValueType(QVersitProperty::VersitDocumentType); |
1350 | property.setName(QStringLiteral("VALARM" )); |
1351 | property.setValue(QVariant::fromValue(value: valarmDocument)); |
1352 | QOrganizerItemAudibleReminder audibleReminder; |
1353 | audibleReminder.setDataUrl(QUrl("http://qt.nokia.com" )); |
1354 | audibleReminder.setRepetition(count: 3, delaySeconds: 5); |
1355 | audibleReminder.setSecondsBeforeStart(90); |
1356 | QTest::newRow(dataTag: "audible reminder" ) << (QList<QVersitProperty>() << property) |
1357 | << (QList<QOrganizerItemDetail>() << audibleReminder); |
1358 | } |
1359 | |
1360 | { |
1361 | QVersitProperty property; |
1362 | QVersitDocument valarmDocument(QVersitDocument::ICalendar20Type); |
1363 | QList<QVersitProperty> valarmProperties; |
1364 | QVersitProperty dtstart; |
1365 | dtstart.setName(QStringLiteral("DTSTART" )); |
1366 | dtstart.setValue(QStringLiteral("20100102T030405" )); |
1367 | QVersitProperty dtend; |
1368 | dtend.setName(QStringLiteral("DUE" )); |
1369 | dtend.setValue(QStringLiteral("20100102T030415" )); |
1370 | QOrganizerTodoTime todoTime; |
1371 | todoTime.setStartDateTime(QDateTime(QDate(2010, 1, 2), QTime(3, 4, 5))); |
1372 | todoTime.setDueDateTime(QDateTime(QDate(2010, 1, 2), QTime(3, 4, 15))); |
1373 | |
1374 | property.setName(QStringLiteral("ACTION" )); |
1375 | property.setValue(QStringLiteral("AUDIO" )); |
1376 | valarmProperties << property; |
1377 | property.setName(QStringLiteral("ATTACH" )); |
1378 | property.setValue(QUrl(QStringLiteral("http://qt.nokia.com" ))); |
1379 | valarmProperties << property; |
1380 | property.setName(QStringLiteral("DURATION" )); |
1381 | property.setValue(QStringLiteral("PT10S" )); |
1382 | valarmProperties << property; |
1383 | property.setName(QStringLiteral("REPEAT" )); |
1384 | property.setValue(3); |
1385 | valarmProperties << property; |
1386 | property.setName(QStringLiteral("TRIGGER" )); |
1387 | property.setValue(QStringLiteral("-PT90S" )); |
1388 | property.insertParameter(QStringLiteral("RELATED" ), QStringLiteral("END" )); |
1389 | valarmProperties << property; |
1390 | property.clear(); |
1391 | |
1392 | valarmDocument.setComponentType("VALARM" ); |
1393 | valarmDocument.setProperties(valarmProperties); |
1394 | property.setValueType(QVersitProperty::VersitDocumentType); |
1395 | property.setName(QStringLiteral("VALARM" )); |
1396 | property.setValue(QVariant::fromValue(value: valarmDocument)); |
1397 | QOrganizerItemAudibleReminder audibleReminder; |
1398 | audibleReminder.setDataUrl(QUrl("http://qt.nokia.com" )); |
1399 | audibleReminder.setRepetition(count: 3, delaySeconds: 10); |
1400 | audibleReminder.setSecondsBeforeStart(90); |
1401 | QTest::newRow(dataTag: "audible reminder with relative (END) trigger" ) |
1402 | << (QList<QVersitProperty>() << dtstart << dtend << property) |
1403 | << (QList<QOrganizerItemDetail>() << todoTime << audibleReminder); |
1404 | } |
1405 | |
1406 | { |
1407 | QVersitProperty property; |
1408 | QVersitDocument valarmDocument(QVersitDocument::ICalendar20Type); |
1409 | QList<QVersitProperty> valarmProperties; |
1410 | QVersitProperty dtstart; |
1411 | dtstart.setName(QStringLiteral("DTSTART" )); |
1412 | dtstart.setValue(QStringLiteral("20100102T030405" )); |
1413 | QVersitProperty dtend; |
1414 | dtend.setName(QStringLiteral("DUE" )); |
1415 | dtend.setValue(QStringLiteral("20100102T030415" )); |
1416 | QOrganizerTodoTime todoTime; |
1417 | todoTime.setStartDateTime(QDateTime(QDate(2010, 1, 2), QTime(3, 4, 5))); |
1418 | todoTime.setDueDateTime(QDateTime(QDate(2010, 1, 2), QTime(3, 4, 15))); |
1419 | |
1420 | property.setName(QStringLiteral("ACTION" )); |
1421 | property.setValue(QStringLiteral("AUDIO" )); |
1422 | valarmProperties << property; |
1423 | property.setName(QStringLiteral("ATTACH" )); |
1424 | property.setValue(QUrl(QStringLiteral("http://qt.nokia.com" ))); |
1425 | valarmProperties << property; |
1426 | property.setName(QStringLiteral("DURATION" )); |
1427 | property.setValue(QStringLiteral("PT10S" )); |
1428 | valarmProperties << property; |
1429 | property.setName(QStringLiteral("REPEAT" )); |
1430 | property.setValue(3); |
1431 | valarmProperties << property; |
1432 | property.setName(QStringLiteral("TRIGGER" )); |
1433 | property.setValue(QStringLiteral("-PT90S" )); |
1434 | property.insertParameter(QStringLiteral("RELATED" ), QStringLiteral("START" )); |
1435 | valarmProperties << property; |
1436 | property.clear(); |
1437 | |
1438 | valarmDocument.setComponentType("VALARM" ); |
1439 | valarmDocument.setProperties(valarmProperties); |
1440 | property.setValueType(QVersitProperty::VersitDocumentType); |
1441 | property.setName(QStringLiteral("VALARM" )); |
1442 | property.setValue(QVariant::fromValue(value: valarmDocument)); |
1443 | QOrganizerItemAudibleReminder audibleReminder; |
1444 | audibleReminder.setDataUrl(QUrl("http://qt.nokia.com" )); |
1445 | audibleReminder.setRepetition(count: 3, delaySeconds: 10); |
1446 | audibleReminder.setSecondsBeforeStart(100); |
1447 | QTest::newRow(dataTag: "audible reminder with relative (START) trigger" ) |
1448 | << (QList<QVersitProperty>() << dtstart << dtend << property) |
1449 | << (QList<QOrganizerItemDetail>() << todoTime << audibleReminder); |
1450 | } |
1451 | |
1452 | { |
1453 | QVersitProperty property; |
1454 | QVersitDocument valarmDocument(QVersitDocument::ICalendar20Type); |
1455 | QList<QVersitProperty> valarmProperties; |
1456 | QVersitProperty dtstart; |
1457 | dtstart.setName(QStringLiteral("DTSTART" )); |
1458 | dtstart.setValue(QStringLiteral("20100102T030405" )); |
1459 | QVersitProperty dtend; |
1460 | dtend.setName(QStringLiteral("DUE" )); |
1461 | dtend.setValue(QStringLiteral("20100102T030415" )); |
1462 | QOrganizerTodoTime todoTime; |
1463 | todoTime.setStartDateTime(QDateTime(QDate(2010, 1, 2), QTime(3, 4, 5))); |
1464 | todoTime.setDueDateTime(QDateTime(QDate(2010, 1, 2), QTime(3, 4, 15))); |
1465 | |
1466 | property.setName(QStringLiteral("ACTION" )); |
1467 | property.setValue(QStringLiteral("AUDIO" )); |
1468 | valarmProperties << property; |
1469 | property.setName(QStringLiteral("ATTACH" )); |
1470 | property.setValue(QUrl(QStringLiteral("http://qt.nokia.com" ))); |
1471 | valarmProperties << property; |
1472 | property.setName(QStringLiteral("DURATION" )); |
1473 | property.setValue(QStringLiteral("PT10S" )); |
1474 | valarmProperties << property; |
1475 | property.setName(QStringLiteral("REPEAT" )); |
1476 | property.setValue(3); |
1477 | valarmProperties << property; |
1478 | property.setName(QStringLiteral("TRIGGER" )); |
1479 | property.setValue(QStringLiteral("20100102T030400" )); |
1480 | property.insertParameter(QStringLiteral("VALUE" ), QStringLiteral("DATE-TIME" )); |
1481 | valarmProperties << property; |
1482 | property.clear(); |
1483 | |
1484 | valarmDocument.setComponentType("VALARM" ); |
1485 | valarmDocument.setProperties(valarmProperties); |
1486 | property.setValueType(QVersitProperty::VersitDocumentType); |
1487 | property.setName(QStringLiteral("VALARM" )); |
1488 | property.setValue(QVariant::fromValue(value: valarmDocument)); |
1489 | QOrganizerItemAudibleReminder audibleReminder; |
1490 | audibleReminder.setDataUrl(QUrl("http://qt.nokia.com" )); |
1491 | audibleReminder.setRepetition(count: 3, delaySeconds: 10); |
1492 | audibleReminder.setSecondsBeforeStart(15); |
1493 | QTest::newRow(dataTag: "audible reminder with absolute trigger" ) |
1494 | << (QList<QVersitProperty>() << dtstart << dtend << property) |
1495 | << (QList<QOrganizerItemDetail>() << todoTime << audibleReminder); |
1496 | } |
1497 | |
1498 | { |
1499 | QVersitProperty property; |
1500 | QVersitDocument valarmDocument(QVersitDocument::ICalendar20Type); |
1501 | QList<QVersitProperty> valarmProperties; |
1502 | |
1503 | property.setName(QStringLiteral("ACTION" )); |
1504 | property.setValue(QStringLiteral("DISPLAY" )); |
1505 | valarmProperties << property; |
1506 | property.setName(QStringLiteral("DURATION" )); |
1507 | property.setValue(QStringLiteral("PT5S" )); |
1508 | valarmProperties << property; |
1509 | property.setName(QStringLiteral("REPEAT" )); |
1510 | property.setValue(3); |
1511 | valarmProperties << property; |
1512 | property.setName(QStringLiteral("TRIGGER" )); |
1513 | property.setValue(QStringLiteral("-PT90S" )); |
1514 | valarmProperties << property; |
1515 | property.setName(QStringLiteral("DESCRIPTION" )); |
1516 | property.setValue(QStringLiteral("Test visual reminder" )); |
1517 | valarmProperties << property; |
1518 | |
1519 | valarmDocument.setComponentType("VALARM" ); |
1520 | valarmDocument.setProperties(valarmProperties); |
1521 | property.setValueType(QVersitProperty::VersitDocumentType); |
1522 | property.setName(QStringLiteral("VALARM" )); |
1523 | property.setValue(QVariant::fromValue(value: valarmDocument)); |
1524 | QOrganizerItemVisualReminder visualReminder; |
1525 | visualReminder.setMessage(QStringLiteral("Test visual reminder" )); |
1526 | visualReminder.setRepetition(count: 3, delaySeconds: 5); |
1527 | visualReminder.setSecondsBeforeStart(90); |
1528 | QTest::newRow(dataTag: "visual reminder" ) << (QList<QVersitProperty>() << property) |
1529 | << (QList<QOrganizerItemDetail>() << visualReminder); |
1530 | } |
1531 | |
1532 | { |
1533 | QVersitProperty property; |
1534 | QVersitDocument valarmDocument; |
1535 | QList<QVersitProperty> valarmProperties; |
1536 | |
1537 | property.setName(QStringLiteral("ACTION" )); |
1538 | property.setValue(QStringLiteral("EMAIL" )); |
1539 | valarmProperties << property; |
1540 | property.setName(QStringLiteral("DURATION" )); |
1541 | property.setValue(QStringLiteral("PT5S" )); |
1542 | valarmProperties << property; |
1543 | property.setName(QStringLiteral("REPEAT" )); |
1544 | property.setValue(3); |
1545 | valarmProperties << property; |
1546 | property.setName(QStringLiteral("TRIGGER" )); |
1547 | property.setValue(QStringLiteral("-PT90S" )); |
1548 | valarmProperties << property; |
1549 | property.setName(QStringLiteral("DESCRIPTION" )); |
1550 | property.setValue(QStringLiteral("Test email body" )); |
1551 | valarmProperties << property; |
1552 | property.setName(QStringLiteral("SUMMARY" )); |
1553 | property.setValue(QStringLiteral("Test email subject" )); |
1554 | valarmProperties << property; |
1555 | property.setName(QStringLiteral("ATTENDEE" )); |
1556 | property.setValue(QStringLiteral("First email recipient" )); |
1557 | valarmProperties << property; |
1558 | property.setValue(QStringLiteral("Second email recipient" )); |
1559 | valarmProperties << property; |
1560 | |
1561 | valarmDocument.setComponentType("VALARM" ); |
1562 | valarmDocument.setProperties(valarmProperties); |
1563 | property.setValueType(QVersitProperty::VersitDocumentType); |
1564 | property.setName(QStringLiteral("VALARM" )); |
1565 | property.setValue(QVariant::fromValue(value: valarmDocument)); |
1566 | QOrganizerItemEmailReminder emailReminder; |
1567 | emailReminder.setContents(QStringLiteral("Test email subject" ), |
1568 | QStringLiteral("Test email body" ), |
1569 | attachments: QVariantList()); |
1570 | emailReminder.setRepetition(count: 3, delaySeconds: 5); |
1571 | emailReminder.setSecondsBeforeStart(90); |
1572 | emailReminder.setRecipients(QStringList() |
1573 | << QStringLiteral("First email recipient" ) |
1574 | << QStringLiteral("Second email recipient" )); |
1575 | QTest::newRow(dataTag: "email reminder" ) << (QList<QVersitProperty>() << property) |
1576 | << (QList<QOrganizerItemDetail>() << emailReminder); |
1577 | } |
1578 | |
1579 | { |
1580 | QVersitProperty property; |
1581 | property.setName(QStringLiteral("STATUS" )); |
1582 | property.setValue(QStringLiteral("COMPLETED" )); |
1583 | QOrganizerTodoProgress progress; |
1584 | progress.setStatus(QOrganizerTodoProgress::StatusComplete); |
1585 | QTest::newRow(dataTag: "status completed" ) |
1586 | << (QList<QVersitProperty>() << property) |
1587 | << (QList<QOrganizerItemDetail>() << progress); |
1588 | |
1589 | property.setValue(QStringLiteral("NEEDS-ACTION" )); |
1590 | progress.setStatus(QOrganizerTodoProgress::StatusNotStarted); |
1591 | QTest::newRow(dataTag: "status needs-action" ) |
1592 | << (QList<QVersitProperty>() << property) |
1593 | << (QList<QOrganizerItemDetail>() << progress); |
1594 | |
1595 | property.setValue(QStringLiteral("IN-PROCESS" )); |
1596 | progress.setStatus(QOrganizerTodoProgress::StatusInProgress); |
1597 | QTest::newRow(dataTag: "status in-process" ) |
1598 | << (QList<QVersitProperty>() << property) |
1599 | << (QList<QOrganizerItemDetail>() << progress); |
1600 | } |
1601 | |
1602 | { |
1603 | QVersitProperty property; |
1604 | property.setName(QStringLiteral("PERCENT-COMPLETE" )); |
1605 | property.setValue(QStringLiteral("42" )); |
1606 | QOrganizerTodoProgress progress; |
1607 | progress.setPercentageComplete(42); |
1608 | QTest::newRow(dataTag: "percent-complete" ) |
1609 | << (QList<QVersitProperty>() << property) |
1610 | << (QList<QOrganizerItemDetail>() << progress); |
1611 | } |
1612 | |
1613 | { |
1614 | QVersitProperty property; |
1615 | property.setName(QStringLiteral("COMPLETED" )); |
1616 | property.setValue(QStringLiteral("20100609T161500" )); |
1617 | QOrganizerTodoProgress progress; |
1618 | progress.setFinishedDateTime(QDateTime(QDate(2010, 6, 9), QTime(16, 15, 0))); |
1619 | QTest::newRow(dataTag: "completed" ) |
1620 | << (QList<QVersitProperty>() << property) |
1621 | << (QList<QOrganizerItemDetail>() << progress); |
1622 | } |
1623 | |
1624 | { |
1625 | QVersitProperty property; |
1626 | property.setName(QStringLiteral("CATEGORIES" )); |
1627 | property.setValue(QStringLiteral("Important Event" )); |
1628 | QOrganizerItemTag tag; |
1629 | tag.setTag(QStringLiteral("Important Event" )); |
1630 | QTest::newRow(dataTag: "tag 1" ) |
1631 | << (QList<QVersitProperty>() << property) |
1632 | << (QList<QOrganizerItemDetail>() << tag); |
1633 | |
1634 | // Set another one for multiple handling test |
1635 | property.setValue(QStringLiteral("Important Event 2" )); |
1636 | tag.setTag(QStringLiteral("Important Event 2" )); |
1637 | QTest::newRow(dataTag: "tag 2" ) |
1638 | << (QList<QVersitProperty>() << property) |
1639 | << (QList<QOrganizerItemDetail>() << tag); |
1640 | |
1641 | // Empty tag |
1642 | property.clear(); |
1643 | property.setName("CATEGORIES" ); |
1644 | tag.removeValue(field: QOrganizerItemTag::FieldTag); |
1645 | QTest::newRow(dataTag: "empty tag" ) |
1646 | << (QList<QVersitProperty>() << property) |
1647 | << (QList<QOrganizerItemDetail>() ); // Detail side should be empty |
1648 | } |
1649 | |
1650 | { |
1651 | QVersitProperty property = createExtendedDetailPropertyForStringData(name: "name" , data: "data" ); |
1652 | QOrganizerItemExtendedDetail extendedDetail = createExtendedDetail(name: "name" , data: "data" ); |
1653 | QTest::newRow(dataTag: "extended detail" ) |
1654 | << (QList<QVersitProperty>() << property) |
1655 | << (QList<QOrganizerItemDetail>() << extendedDetail); |
1656 | } |
1657 | } |
1658 | |
1659 | void tst_QVersitOrganizerImporter::testExtendedDetail() |
1660 | { |
1661 | QFETCH(QString, extendedDetailName); |
1662 | QFETCH(QVariant, extendedDetailData); |
1663 | QFETCH(QString, extendedDetailDataInProperty); |
1664 | QFETCH(bool, extendedDetailCreated); |
1665 | |
1666 | QVersitDocument document(QVersitDocument::ICalendar20Type); |
1667 | document.setComponentType(QStringLiteral("VCALENDAR" )); |
1668 | QVersitDocument nested(QVersitDocument::ICalendar20Type); |
1669 | nested.setComponentType(QStringLiteral("VEVENT" )); |
1670 | nested.addProperty(property: createExtendedDetailProperty(name: extendedDetailName, |
1671 | data: extendedDetailDataInProperty)); |
1672 | document.addSubDocument(subdocument: nested); |
1673 | |
1674 | QOrganizerItemExtendedDetail expectedDetail = |
1675 | createExtendedDetail(name: extendedDetailName, data: extendedDetailData); |
1676 | |
1677 | QVersitOrganizerImporter importer; |
1678 | QVERIFY(importer.importDocument(document)); |
1679 | |
1680 | QList<QOrganizerItem> items = importer.items(); |
1681 | QList<QOrganizerItemDetail> actualDetails = items.first().details(detailType: expectedDetail.type()); |
1682 | if (!extendedDetailCreated) { |
1683 | QCOMPARE(actualDetails.size(), 0); |
1684 | } else { |
1685 | QCOMPARE(actualDetails.size(), 1); |
1686 | if (static_cast<QMetaType::Type>(extendedDetailData.type()) == QMetaType::Double |
1687 | || static_cast<QMetaType::Type>(extendedDetailData.type()) == QMetaType::Float) { |
1688 | QCOMPARE(actualDetails.first().values().keys(), expectedDetail.values().keys()); |
1689 | QCOMPARE(actualDetails.first().values().keys().size(), 2); // name + value |
1690 | int nameKey = actualDetails.first().values().keys().at(i: 0); |
1691 | int valueKey = actualDetails.first().values().keys().at(i: 1); |
1692 | QCOMPARE(actualDetails.first().value(nameKey), expectedDetail.value(nameKey)); |
1693 | QVariant actualValue = actualDetails.first().value(field: valueKey); |
1694 | QVariant expectedValue = expectedDetail.value(field: valueKey); |
1695 | if (static_cast<QMetaType::Type>(extendedDetailData.type()) == QMetaType::Float) { |
1696 | float actualF = actualValue.value<float>(); |
1697 | float expectedF = expectedValue.value<float>(); |
1698 | QCOMPARE(actualF, expectedF); |
1699 | } else { |
1700 | double actualD = actualValue.value<double>(); |
1701 | double expectedD = expectedValue.value<double>(); |
1702 | QCOMPARE(actualD, expectedD); |
1703 | } |
1704 | } else if (!actualDetails.contains(t: expectedDetail)) { |
1705 | qDebug() << "Actual:" << actualDetails; |
1706 | qDebug() << "Expected to find:" << expectedDetail; |
1707 | QVERIFY(false); |
1708 | } |
1709 | } |
1710 | } |
1711 | |
1712 | void tst_QVersitOrganizerImporter::testExtendedDetail_data() |
1713 | { |
1714 | QTest::addColumn<QString>(name: "extendedDetailName" ); |
1715 | QTest::addColumn<QVariant>(name: "extendedDetailData" ); |
1716 | QTest::addColumn<QString>(name: "extendedDetailDataInProperty" ); |
1717 | QTest::addColumn<bool>(name: "extendedDetailCreated" ); |
1718 | |
1719 | QString jsonArrayWith("[\n %1\n]\n" ); |
1720 | QString jsonArrayWithString = jsonArrayWith.arg(a: "\"%1\"" ); |
1721 | { |
1722 | QTest::newRow(dataTag: "string data" ) |
1723 | << QString("name" ) |
1724 | << QVariant(QString("data" )) |
1725 | << jsonArrayWithString.arg(a: "data" ) |
1726 | << true; |
1727 | QTest::newRow(dataTag: "string data, empty" ) |
1728 | << QString("name" ) |
1729 | << QVariant(QString("" )) |
1730 | << jsonArrayWithString.arg(a: "" ) |
1731 | << true; |
1732 | QTest::newRow(dataTag: "string data, containing reserved characters" ) |
1733 | << QString("name" ) |
1734 | << QVariant(QString(",;:\\" )) |
1735 | << jsonArrayWithString.arg(a: ",;:\\\\" ) |
1736 | << true; |
1737 | } |
1738 | |
1739 | { |
1740 | QTest::newRow(dataTag: "double data" ) |
1741 | << QString("name" ) |
1742 | << QVariant((double)2.0) |
1743 | << jsonArrayWith.arg(a: "2" ) |
1744 | << true; |
1745 | QTest::newRow(dataTag: "double data, negative" ) |
1746 | << QString("name" ) |
1747 | << QVariant((double)-1.0) |
1748 | << jsonArrayWith.arg(a: "-1" ) |
1749 | << true; |
1750 | QTest::newRow(dataTag: "double data, multiple digits" ) |
1751 | << QString("name" ) |
1752 | << QVariant((double)10.2) |
1753 | << jsonArrayWith.arg(a: "10.2" ) |
1754 | << true; |
1755 | } |
1756 | |
1757 | { |
1758 | QTest::newRow(dataTag: "boolean data" ) |
1759 | << QString("name" ) |
1760 | << QVariant(true) |
1761 | << jsonArrayWith.arg(a: "true" ) |
1762 | << true; |
1763 | } |
1764 | |
1765 | { |
1766 | QTest::newRow(dataTag: "datetime data, imported as a string" ) |
1767 | << QString("name" ) |
1768 | << QVariant(QString("1997-07-16T19:20:30+01:00" )) |
1769 | << jsonArrayWithString.arg(a: "1997-07-16T19:20:30+01:00" ) |
1770 | << true; |
1771 | } |
1772 | |
1773 | { |
1774 | QTest::newRow(dataTag: "list data" ) |
1775 | << QString("name" ) |
1776 | << QVariant(QVariantList() << QString("string 1" ) << QString("string 2" )) |
1777 | << QString("[\n [\n \"string 1\",\n \"string 2\"\n ]\n]\n" ) |
1778 | << true; |
1779 | } |
1780 | |
1781 | { |
1782 | QVariantMap map; |
1783 | map["key 1" ] = QString("string 1" ); |
1784 | map["key 2" ] = QString("string 2" ); |
1785 | QTest::newRow(dataTag: "map data" ) |
1786 | << QString("name" ) |
1787 | << QVariant(map) |
1788 | << QString("[\n {\n \"key 1\": \"string 1\",\n \"key 2\": \"string 2\"\n }\n]\n" ) |
1789 | << true; |
1790 | } |
1791 | |
1792 | { |
1793 | QVariantMap map; |
1794 | map["key" ] = QVariantList() << (double)1 << (double)2; |
1795 | QTest::newRow(dataTag: "map data, containing a nested list" ) |
1796 | << QString("name" ) |
1797 | << QVariant(map) |
1798 | << QString("[\n {\n \"key\": [\n 1,\n 2\n ]\n }\n]\n" ) |
1799 | << true; |
1800 | } |
1801 | |
1802 | { |
1803 | QTest::newRow(dataTag: "empty string as name" ) |
1804 | << QString("" ) |
1805 | << QVariant(QString("data" )) |
1806 | << jsonArrayWithString.arg(a: "data" ) |
1807 | << true; |
1808 | QTest::newRow(dataTag: "name containing reserved characters" ) |
1809 | << QString(",;:\\" ) |
1810 | << QVariant(QString("data" )) |
1811 | << jsonArrayWithString.arg(a: "data" ) |
1812 | << true; |
1813 | } |
1814 | |
1815 | { |
1816 | QTest::newRow(dataTag: "null denoting an empty variant" ) |
1817 | << QString("name" ) |
1818 | << QVariant() |
1819 | << jsonArrayWith.arg(a: "null" ) |
1820 | << true; |
1821 | QTest::newRow(dataTag: "compact json with extra whitespace removed" ) |
1822 | << QString("name" ) |
1823 | << QVariant(QString("data" )) |
1824 | << QString("[\"data\"]" ) |
1825 | << true; |
1826 | } |
1827 | |
1828 | { |
1829 | QTest::newRow(dataTag: "invalid property value: empty json array as property value" ) |
1830 | << QString("name" ) |
1831 | << QVariant() |
1832 | << jsonArrayWith.arg(a: "" ) |
1833 | << false; |
1834 | QTest::newRow(dataTag: "invalid property value: invalid json value" ) |
1835 | << QString("name" ) |
1836 | << QVariant() |
1837 | << jsonArrayWith.arg(a: "invalid" ) |
1838 | << false; |
1839 | } |
1840 | } |
1841 | |
1842 | void tst_QVersitOrganizerImporter::testMultipleExtendedDetails() |
1843 | { |
1844 | QVersitDocument document(QVersitDocument::ICalendar20Type); |
1845 | document.setComponentType(QStringLiteral("VCALENDAR" )); |
1846 | QVersitDocument nested(QVersitDocument::ICalendar20Type); |
1847 | nested.setComponentType(QStringLiteral("VEVENT" )); |
1848 | nested.addProperty(property: createExtendedDetailPropertyForStringData(name: "detailName1" , data: "detailData1" )); |
1849 | nested.addProperty(property: createExtendedDetailPropertyForStringData(name: "detailName2" , data: "detailData2" )); |
1850 | document.addSubDocument(subdocument: nested); |
1851 | |
1852 | QList<QOrganizerItemExtendedDetail> expectedDetails; |
1853 | expectedDetails << createExtendedDetail(name: "detailName1" , data: "detailData1" ); |
1854 | expectedDetails << createExtendedDetail(name: "detailName2" , data: "detailData2" ); |
1855 | |
1856 | QVersitOrganizerImporter importer; |
1857 | QVERIFY(importer.importDocument(document)); |
1858 | |
1859 | QList<QOrganizerItem> items = importer.items(); |
1860 | QList<QOrganizerItemDetail> actualDetails = items.first().details(detailType: QOrganizerItemDetail::TypeExtendedDetail); |
1861 | QCOMPARE(actualDetails.size(), 2); |
1862 | foreach (const QOrganizerItemDetail& expectedDetail, expectedDetails) { |
1863 | if (!actualDetails.contains(t: expectedDetail)) { |
1864 | qDebug() << "Actual:" << actualDetails; |
1865 | qDebug() << "Expected to find:" << expectedDetail; |
1866 | QVERIFY(false); |
1867 | } |
1868 | } |
1869 | } |
1870 | |
1871 | QOrganizerItemExtendedDetail tst_QVersitOrganizerImporter::createExtendedDetail( |
1872 | const QString &name, |
1873 | const QVariant &data) |
1874 | { |
1875 | QOrganizerItemExtendedDetail extendedDetail; |
1876 | extendedDetail.setName(name); |
1877 | extendedDetail.setData(data); |
1878 | return extendedDetail; |
1879 | } |
1880 | |
1881 | QVersitProperty tst_QVersitOrganizerImporter::createExtendedDetailProperty( |
1882 | const QString &name, |
1883 | const QVariant &data) |
1884 | { |
1885 | QVersitProperty property; |
1886 | property.setName(QStringLiteral("X-QTPROJECT-EXTENDED-DETAIL" )); |
1887 | property.setValue(QStringList() << name << data.toString()); |
1888 | property.setValueType(QVersitProperty::CompoundType); |
1889 | return property; |
1890 | } |
1891 | |
1892 | QVersitProperty tst_QVersitOrganizerImporter::createExtendedDetailPropertyForStringData( |
1893 | const QString &name, |
1894 | const QString &data) |
1895 | { |
1896 | QString jsonArrayWith("[\n %1\n]\n" ); |
1897 | QString jsonArrayWithString = jsonArrayWith.arg(a: "\"%1\"" ); |
1898 | return createExtendedDetailProperty(name, data: jsonArrayWithString.arg(a: data)); |
1899 | } |
1900 | |
1901 | void tst_QVersitOrganizerImporter::testTimeZones() |
1902 | { |
1903 | QFETCH(QString, tzid); |
1904 | QFETCH(QVersitDocument, timezoneSpec); |
1905 | QFETCH(QString, datetimeString); |
1906 | QFETCH(QDateTime, expected); |
1907 | |
1908 | QVersitDocument document(QVersitDocument::ICalendar20Type); |
1909 | document.setComponentType(QStringLiteral("VCALENDAR" )); |
1910 | if (!tzid.isEmpty()) { |
1911 | document.addSubDocument(subdocument: timezoneSpec); |
1912 | } |
1913 | QVersitDocument vevent(QVersitDocument::ICalendar20Type); |
1914 | vevent.setComponentType(QStringLiteral("VEVENT" )); |
1915 | QVersitProperty property; |
1916 | property.setName(QStringLiteral("DTSTART" )); |
1917 | property.setValue(datetimeString); |
1918 | if (!tzid.isEmpty()) { |
1919 | property.insertParameter(QStringLiteral("TZID" ), value: tzid); |
1920 | } |
1921 | vevent.addProperty(property); |
1922 | document.addSubDocument(subdocument: vevent); |
1923 | |
1924 | QVersitOrganizerImporter importer; |
1925 | QVERIFY(importer.importDocument(document)); |
1926 | QVERIFY(importer.errorMap().isEmpty()); |
1927 | QList<QOrganizerItem> items = importer.items(); |
1928 | QCOMPARE(items.size(), 1); |
1929 | |
1930 | QOrganizerEvent event = static_cast<QOrganizerEvent>(items.first()); |
1931 | QCOMPARE(event.type(), QOrganizerItemType::TypeEvent); |
1932 | QDateTime actualDatetime = event.startDateTime(); |
1933 | QCOMPARE(actualDatetime, expected); |
1934 | QCOMPARE(actualDatetime.timeSpec(), expected.timeSpec()); |
1935 | } |
1936 | |
1937 | void tst_QVersitOrganizerImporter::testTimeZones_data() |
1938 | { |
1939 | QTest::addColumn<QString>(name: "tzid" ); // set this to empty if you don't want to associate a tzid |
1940 | QTest::addColumn<QVersitDocument>(name: "timezoneSpec" ); |
1941 | QTest::addColumn<QString>(name: "datetimeString" ); |
1942 | QTest::addColumn<QDateTime>(name: "expected" ); |
1943 | |
1944 | QVersitDocument vtimezone(QVersitDocument::ICalendar20Type); |
1945 | vtimezone.setComponentType(QStringLiteral("VTIMEZONE" )); |
1946 | QTest::newRow(dataTag: "utc" ) << QString() << QVersitDocument(QVersitDocument::ICalendar20Type) |
1947 | << QString::fromLatin1(str: "20100102T030405Z" ) |
1948 | << QDateTime(QDate(2010, 1, 2), QTime(3, 4, 5), Qt::UTC); |
1949 | |
1950 | QTest::newRow(dataTag: "floating" ) << QString() << QVersitDocument(QVersitDocument::ICalendar20Type) |
1951 | << QString::fromLatin1(str: "20100102T030405" ) |
1952 | << QDateTime(QDate(2010, 1, 2), QTime(3, 4, 5), Qt::LocalTime); |
1953 | |
1954 | { |
1955 | QVersitDocument vtimezone(QVersitDocument::ICalendar20Type); |
1956 | vtimezone.setComponentType(QStringLiteral("VTIMEZONE" )); |
1957 | |
1958 | QVersitProperty property; |
1959 | property.setName(QStringLiteral("TZID" )); |
1960 | property.setValue(QStringLiteral("Asia/Singapore" )); |
1961 | vtimezone.addProperty(property); |
1962 | property.setName(QStringLiteral("X-LIC-LOCATION" )); |
1963 | property.setValue(QStringLiteral("Asia/Singapore" )); |
1964 | vtimezone.addProperty(property); |
1965 | |
1966 | QVersitDocument standard(QVersitDocument::ICalendar20Type); |
1967 | standard.setComponentType(QStringLiteral("STANDARD" )); |
1968 | property.setName(QStringLiteral("TZOFFSETFROM" )); |
1969 | property.setValue(QStringLiteral("+0800" )); |
1970 | standard.addProperty(property); |
1971 | property.setName(QStringLiteral("TZOFFSETTO" )); |
1972 | property.setValue(QStringLiteral("+0800" )); |
1973 | standard.addProperty(property); |
1974 | property.setName(QStringLiteral("TZNAME" )); |
1975 | property.setValue(QStringLiteral("EST" )); |
1976 | standard.addProperty(property); |
1977 | property.setName(QStringLiteral("DTSTART" )); |
1978 | property.setValue(QStringLiteral("19700101T000000" )); |
1979 | standard.addProperty(property); |
1980 | vtimezone.addSubDocument(subdocument: standard); |
1981 | |
1982 | QTest::newRow(dataTag: "no dst" ) << QString::fromLatin1(str: "Asia/Singapore" ) |
1983 | << vtimezone << QString::fromLatin1(str: "20100102T100405" ) |
1984 | << QDateTime(QDate(2010, 1, 2), QTime(2, 4, 5), Qt::UTC); |
1985 | } |
1986 | |
1987 | { |
1988 | QVersitDocument vtimezone(QVersitDocument::ICalendar20Type); |
1989 | vtimezone.setComponentType(QStringLiteral("VTIMEZONE" )); |
1990 | |
1991 | QVersitProperty property; |
1992 | property.setName(QStringLiteral("TZID" )); |
1993 | property.setValue(QStringLiteral("Australia/Sydney" )); |
1994 | vtimezone.addProperty(property); |
1995 | property.setName(QStringLiteral("X-LIC-LOCATION" )); |
1996 | property.setValue(QStringLiteral("Australia/Sydney" )); |
1997 | vtimezone.addProperty(property); |
1998 | |
1999 | QVersitDocument standard(QVersitDocument::ICalendar20Type); |
2000 | standard.setComponentType(QStringLiteral("STANDARD" )); |
2001 | property.setName(QStringLiteral("TZOFFSETFROM" )); |
2002 | property.setValue(QStringLiteral("+1100" )); |
2003 | standard.addProperty(property); |
2004 | property.setName(QStringLiteral("TZOFFSETTO" )); |
2005 | property.setValue(QStringLiteral("+1000" )); |
2006 | standard.addProperty(property); |
2007 | property.setName(QStringLiteral("TZNAME" )); |
2008 | property.setValue(QStringLiteral("EST" )); |
2009 | standard.addProperty(property); |
2010 | property.setName(QStringLiteral("DTSTART" )); |
2011 | property.setValue(QStringLiteral("19700405T030000" )); |
2012 | standard.addProperty(property); |
2013 | property.setName(QStringLiteral("RRULE" )); |
2014 | property.setValue(QStringLiteral("FREQ=YEARLY;BYMONTH=4;BYDAY=1SU" )); |
2015 | standard.addProperty(property); |
2016 | vtimezone.addSubDocument(subdocument: standard); |
2017 | |
2018 | QVersitDocument daylight(QVersitDocument::ICalendar20Type); |
2019 | daylight.setComponentType(QStringLiteral("DAYLIGHT" )); |
2020 | property.setName(QStringLiteral("TZOFFSETFROM" )); |
2021 | property.setValue(QStringLiteral("+1000" )); |
2022 | daylight.addProperty(property); |
2023 | property.setName(QStringLiteral("TZOFFSETTO" )); |
2024 | property.setValue(QStringLiteral("+1100" )); |
2025 | daylight.addProperty(property); |
2026 | property.setName(QStringLiteral("TZNAME" )); |
2027 | property.setValue(QStringLiteral("EST" )); |
2028 | daylight.addProperty(property); |
2029 | property.setName(QStringLiteral("DTSTART" )); |
2030 | property.setValue(QStringLiteral("19701004T020000" )); |
2031 | daylight.addProperty(property); |
2032 | property.setName(QStringLiteral("RRULE" )); |
2033 | property.setValue(QStringLiteral("FREQ=YEARLY;BYMONTH=10;BYDAY=1SU" )); |
2034 | daylight.addProperty(property); |
2035 | vtimezone.addSubDocument(subdocument: daylight); |
2036 | |
2037 | QTest::newRow(dataTag: "dst area in standard time" ) << QString::fromLatin1(str: "Australia/Sydney" ) |
2038 | << vtimezone << QString::fromLatin1(str: "20100502T100405" ) |
2039 | << QDateTime(QDate(2010, 5, 2), QTime(0, 4, 5), Qt::UTC); |
2040 | |
2041 | QTest::newRow(dataTag: "dst" ) << QString::fromLatin1(str: "Australia/Sydney" ) |
2042 | << vtimezone << QString::fromLatin1(str: "20100102T100405" ) |
2043 | << QDateTime(QDate(2010, 1, 1), QTime(23, 4, 5), Qt::UTC); |
2044 | } |
2045 | |
2046 | { |
2047 | QVersitDocument vtimezone(QVersitDocument::ICalendar20Type); |
2048 | vtimezone.setComponentType(QStringLiteral("VTIMEZONE" )); |
2049 | |
2050 | QVersitProperty property; |
2051 | property.setName(QStringLiteral("TZID" )); |
2052 | property.setValue(QStringLiteral("US-Eastern" )); |
2053 | vtimezone.addProperty(property); |
2054 | |
2055 | QVersitDocument standard(QVersitDocument::ICalendar20Type); |
2056 | standard.setComponentType(QStringLiteral("STANDARD" )); |
2057 | property.setName(QStringLiteral("DTSTART" )); |
2058 | property.setValue(QStringLiteral("19961026T020000" )); |
2059 | standard.addProperty(property); |
2060 | property.setName(QStringLiteral("RDATE" )); |
2061 | property.setValue(QStringLiteral("19971026T020000" )); |
2062 | standard.addProperty(property); |
2063 | property.setName(QStringLiteral("TZOFFSETFROM" )); |
2064 | property.setValue(QStringLiteral("-0400" )); |
2065 | standard.addProperty(property); |
2066 | property.setName(QStringLiteral("TZOFFSETTO" )); |
2067 | property.setValue(QStringLiteral("-0500" )); |
2068 | standard.addProperty(property); |
2069 | vtimezone.addSubDocument(subdocument: standard); |
2070 | |
2071 | QVersitDocument daylight(QVersitDocument::ICalendar20Type); |
2072 | daylight.setComponentType(QStringLiteral("DAYLIGHT" )); |
2073 | property.setName(QStringLiteral("DTSTART" )); |
2074 | property.setValue(QStringLiteral("19960406T020000" )); |
2075 | daylight.addProperty(property); |
2076 | property.setName(QStringLiteral("RDATE" )); |
2077 | property.setValue(QStringLiteral("19970406T020000" )); |
2078 | daylight.addProperty(property); |
2079 | property.setName(QStringLiteral("TZOFFSETFROM" )); |
2080 | property.setValue(QStringLiteral("-0500" )); |
2081 | daylight.addProperty(property); |
2082 | property.setName(QStringLiteral("TZOFFSETTO" )); |
2083 | property.setValue(QStringLiteral("-0400" )); |
2084 | daylight.addProperty(property); |
2085 | vtimezone.addSubDocument(subdocument: daylight); |
2086 | |
2087 | QTest::newRow(dataTag: "dst specified with rdate - daylight" ) << QString::fromLatin1(str: "US-Eastern" ) |
2088 | << vtimezone << QString::fromLatin1(str: "19970615T100000" ) |
2089 | << QDateTime(QDate(1997, 6, 15), QTime(14, 0, 0), Qt::UTC); |
2090 | |
2091 | QTest::newRow(dataTag: "dst specified with rdate - standard" ) << QString::fromLatin1(str: "US-Eastern" ) |
2092 | << vtimezone << QString::fromLatin1(str: "19971215T100000" ) |
2093 | << QDateTime(QDate(1997, 12, 15), QTime(15, 0, 0), Qt::UTC); |
2094 | } |
2095 | } |
2096 | |
2097 | QTEST_MAIN(tst_QVersitOrganizerImporter) |
2098 | |