1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2015 The Qt Company Ltd. |
4 | ** Contact: http://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the test suite of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL21$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at http://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 or version 3 as published by the Free |
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and |
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the |
22 | ** following information to ensure the GNU Lesser General Public License |
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and |
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
25 | ** |
26 | ** As a special exception, The Qt Company gives you certain additional |
27 | ** rights. These rights are described in The Qt Company LGPL Exception |
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
29 | ** |
30 | ** $QT_END_LICENSE$ |
31 | ** |
32 | ****************************************************************************/ |
33 | |
34 | #include <QtTest/QtTest> |
35 | |
36 | #include <QtOrganizer/qorganizeritemdetails.h> |
37 | #include <QtOrganizer/qorganizeritems.h> |
38 | #include <QtOrganizer/qorganizermanager.h> |
39 | |
40 | QTORGANIZER_USE_NAMESPACE |
41 | |
42 | class tst_QOrganizerE2E : public QObject |
43 | { |
44 | Q_OBJECT |
45 | |
46 | private slots: |
47 | void initTestCase(); |
48 | void cleanupTestCase(); |
49 | |
50 | void testMegaItem_data() { addManager(); } |
51 | void testMegaItem(); |
52 | |
53 | void testUnsupportedItemType_data() { addManager(); } |
54 | void testUnsupportedItemType(); |
55 | |
56 | void testInvalidParentId_data() { addManager(); } |
57 | void testInvalidParentId(); |
58 | |
59 | private: |
60 | void addManager(); |
61 | |
62 | QOrganizerItem createItem(QOrganizerItemType::ItemType itemType); |
63 | QOrganizerItemDetail createDetail(QOrganizerItemDetail::DetailType detailType); |
64 | |
65 | // <manager, items> pair for existing items |
66 | QMap<QString, QList<QOrganizerItem> > existingItems; |
67 | }; |
68 | |
69 | void tst_QOrganizerE2E::initTestCase() |
70 | { |
71 | // back-up all existing items |
72 | QStringList availableManagers(QOrganizerManager::availableManagers()); |
73 | foreach (const QString &manager, availableManagers) { |
74 | QOrganizerManager organizerManager(manager); |
75 | QList<QOrganizerItem> items(organizerManager.items()); |
76 | if (items.size() > 0) { |
77 | existingItems.insert(akey: manager, avalue: items); |
78 | QList<QOrganizerItemId> itemIds(organizerManager.itemIds()); |
79 | organizerManager.removeItems(itemIds); |
80 | } |
81 | } |
82 | } |
83 | |
84 | void tst_QOrganizerE2E::cleanupTestCase() |
85 | { |
86 | // remove all items generated when running tests |
87 | QStringList availableManagers(QOrganizerManager::availableManagers()); |
88 | foreach (const QString &manager, availableManagers) { |
89 | QOrganizerManager organizerManager(manager); |
90 | organizerManager.removeItems(itemIds: organizerManager.itemIds()); |
91 | } |
92 | |
93 | // restore all existing items |
94 | QMap<QString, QList<QOrganizerItem> >::iterator i = existingItems.begin(); |
95 | while (i != existingItems.end()) { |
96 | QOrganizerManager organizerManager(i.key()); |
97 | organizerManager.saveItems(items: &(i.value())); |
98 | ++i; |
99 | } |
100 | } |
101 | |
102 | void tst_QOrganizerE2E::testMegaItem() |
103 | { |
104 | QFETCH(QString, managerName); |
105 | QOrganizerManager organizerManager(managerName); |
106 | |
107 | QList<QOrganizerItemType::ItemType> supportedItemTypes(organizerManager.supportedItemTypes()); |
108 | foreach (QOrganizerItemType::ItemType itemType, supportedItemTypes) { |
109 | QOrganizerItem referenceItem = createItem(itemType); |
110 | QCOMPARE(referenceItem.type(), itemType); |
111 | |
112 | QList<QOrganizerItemDetail::DetailType> supportedDetails(organizerManager.supportedItemDetails(itemType)); |
113 | foreach (QOrganizerItemDetail::DetailType supportedDetail, supportedDetails) { |
114 | QOrganizerItemDetail detail = createDetail(detailType: supportedDetail); |
115 | if (detail.type() != supportedDetail) |
116 | continue; |
117 | |
118 | QVERIFY(referenceItem.saveDetail(&detail)); |
119 | } |
120 | |
121 | // set parent for occurrence |
122 | if (itemType == QOrganizerItemType::TypeEventOccurrence || itemType == QOrganizerItemType::TypeTodoOccurrence) { |
123 | bool parentItemAvailable(false); |
124 | QList<QOrganizerItem> items(organizerManager.items()); |
125 | foreach (const QOrganizerItem &item, items) { |
126 | if ((itemType == QOrganizerItemType::TypeEventOccurrence && item.type() == QOrganizerItemType::TypeEvent) |
127 | || (itemType == QOrganizerItemType::TypeTodoOccurrence && item.type() == QOrganizerItemType::TypeTodo)) { |
128 | QOrganizerItemParent parent; |
129 | parent.setOriginalDate(QDate(1996, 9, 24)); |
130 | parent.setParentId(item.id()); |
131 | QVERIFY(referenceItem.saveDetail(&parent)); |
132 | parentItemAvailable = true; |
133 | break; |
134 | } |
135 | } |
136 | if (!parentItemAvailable) |
137 | continue; |
138 | } |
139 | |
140 | // so that the referenceItem stays the same |
141 | QOrganizerItem itemToSave(referenceItem); |
142 | QVERIFY(organizerManager.saveItem(&itemToSave)); |
143 | |
144 | QOrganizerItem itemRead = organizerManager.item(itemId: itemToSave.id()); |
145 | |
146 | // special details |
147 | QCOMPARE(itemRead.type(), referenceItem.type()); |
148 | |
149 | if (organizerManager.supportedItemDetails(itemType).contains(t: QOrganizerItemDetail::TypeGuid)) |
150 | QCOMPARE(itemRead.details(QOrganizerItemDetail::TypeGuid).size(), 1); |
151 | |
152 | if (organizerManager.supportedItemDetails(itemType).contains(t: QOrganizerItemDetail::TypeTimestamp)) |
153 | QCOMPARE(itemRead.details(QOrganizerItemDetail::TypeTimestamp).size(), 1); |
154 | |
155 | QCOMPARE(itemRead.details(QOrganizerItemDetail::TypeReminder).size(), 0); |
156 | |
157 | // all details should saved and loaded correctly |
158 | foreach (const QOrganizerItemDetail &detail, referenceItem.details()) |
159 | QCOMPARE(itemRead.detail(detail.type()), detail); |
160 | } |
161 | } |
162 | |
163 | void tst_QOrganizerE2E::testUnsupportedItemType() |
164 | { |
165 | QFETCH(QString, managerName); |
166 | QOrganizerManager organizerManager(managerName); |
167 | |
168 | QList<QOrganizerItemType::ItemType> supportedItemTypes(organizerManager.supportedItemTypes()); |
169 | if (!supportedItemTypes.contains(t: QOrganizerItemType::TypeEvent)) { |
170 | QOrganizerItem event = createItem(itemType: QOrganizerItemType::TypeEvent); |
171 | QVERIFY(!organizerManager.saveItem(&event)); |
172 | } |
173 | if (!supportedItemTypes.contains(t: QOrganizerItemType::TypeEventOccurrence)) { |
174 | QOrganizerItem eventOccurence = createItem(itemType: QOrganizerItemType::TypeEventOccurrence); |
175 | QVERIFY(!organizerManager.saveItem(&eventOccurence)); |
176 | } |
177 | if (!supportedItemTypes.contains(t: QOrganizerItemType::TypeTodo)) { |
178 | QOrganizerItem todo = createItem(itemType: QOrganizerItemType::TypeTodo); |
179 | QVERIFY(!organizerManager.saveItem(&todo)); |
180 | } |
181 | if (!supportedItemTypes.contains(t: QOrganizerItemType::TypeTodoOccurrence)) { |
182 | QOrganizerItem todoOccurence = createItem(itemType: QOrganizerItemType::TypeTodoOccurrence); |
183 | QVERIFY(!organizerManager.saveItem(&todoOccurence)); |
184 | } |
185 | if (!supportedItemTypes.contains(t: QOrganizerItemType::TypeJournal)) { |
186 | QOrganizerItem journal = createItem(itemType: QOrganizerItemType::TypeJournal); |
187 | QVERIFY(!organizerManager.saveItem(&journal)); |
188 | } |
189 | if (!supportedItemTypes.contains(t: QOrganizerItemType::TypeNote)) { |
190 | QOrganizerItem note = createItem(itemType: QOrganizerItemType::TypeNote); |
191 | QVERIFY(!organizerManager.saveItem(¬e)); |
192 | } |
193 | } |
194 | |
195 | void tst_QOrganizerE2E::testInvalidParentId() |
196 | { |
197 | QFETCH(QString, managerName); |
198 | QOrganizerManager organizerManager(managerName); |
199 | |
200 | QList<QOrganizerItemType::ItemType> supportedItemTypes(organizerManager.supportedItemTypes()); |
201 | foreach (QOrganizerItemType::ItemType itemType, supportedItemTypes) { |
202 | if (itemType == QOrganizerItemType::TypeEventOccurrence || itemType == QOrganizerItemType::TypeTodoOccurrence) { |
203 | QOrganizerItem item = createItem(itemType); |
204 | QCOMPARE(item.type(), itemType); |
205 | |
206 | QOrganizerItemParent parent; |
207 | parent.setParentId(QOrganizerItemId()); |
208 | |
209 | QVERIFY(item.saveDetail(&parent)); |
210 | QVERIFY(!organizerManager.saveItem(&item)); |
211 | } |
212 | } |
213 | } |
214 | |
215 | void tst_QOrganizerE2E::addManager() |
216 | { |
217 | QTest::addColumn<QString>(name: "managerName" ); |
218 | |
219 | QStringList availableManagers = QOrganizerManager::availableManagers(); |
220 | availableManagers.removeAll(t: "invalid" ); |
221 | availableManagers.removeAll(t: "skeleton" ); |
222 | |
223 | foreach (const QString &manager, availableManagers) |
224 | QTest::newRow(dataTag: manager.toLatin1().constData()) << manager; |
225 | } |
226 | |
227 | QOrganizerItem tst_QOrganizerE2E::createItem(QOrganizerItemType::ItemType itemType) |
228 | { |
229 | if (itemType == QOrganizerItemType::TypeEvent) |
230 | return QOrganizerEvent(); |
231 | else if (itemType == QOrganizerItemType::TypeEventOccurrence) |
232 | return QOrganizerEventOccurrence(); |
233 | else if (itemType == QOrganizerItemType::TypeTodo) |
234 | return QOrganizerTodo(); |
235 | else if (itemType == QOrganizerItemType::TypeTodoOccurrence) |
236 | return QOrganizerTodoOccurrence(); |
237 | else if (itemType == QOrganizerItemType::TypeJournal) |
238 | return QOrganizerJournal(); |
239 | else if (itemType == QOrganizerItemType::TypeNote) |
240 | return QOrganizerNote(); |
241 | |
242 | return QOrganizerItem(); |
243 | } |
244 | |
245 | QOrganizerItemDetail tst_QOrganizerE2E::createDetail(QOrganizerItemDetail::DetailType detailType) |
246 | { |
247 | if (detailType == QOrganizerItemDetail::TypeEventTime) { |
248 | QOrganizerEventTime eventTime; |
249 | eventTime.setAllDay(false); |
250 | eventTime.setStartDateTime(QDateTime::fromString(QStringLiteral("1991-08-25T20:57:08+00:00" ), f: Qt::ISODate)); |
251 | eventTime.setEndDateTime(QDateTime::fromString(QStringLiteral("1995-05-20T11:22:33+02:00" ), f: Qt::ISODate)); |
252 | return eventTime; |
253 | } else if (detailType == QOrganizerItemDetail::TypeJournalTime) { |
254 | QOrganizerJournalTime journalTime; |
255 | journalTime.setEntryDateTime(QDateTime::fromString(QStringLiteral("1991-08-25T20:57:08+00:00" ), f: Qt::ISODate)); |
256 | return journalTime; |
257 | } else if (detailType == QOrganizerItemDetail::TypeTodoTime) { |
258 | QOrganizerTodoTime todoTime; |
259 | todoTime.setAllDay(true); |
260 | todoTime.setStartDateTime(QDateTime::fromString(QStringLiteral("1991-08-25T20:57:08+00:00" ), f: Qt::ISODate)); |
261 | todoTime.setDueDateTime(QDateTime::fromString(QStringLiteral("1995-05-20T11:22:33+02:00" ), f: Qt::ISODate)); |
262 | return todoTime; |
263 | } else if (detailType == QOrganizerItemDetail::TypeTodoProgress) { |
264 | QOrganizerTodoProgress todoProgress; |
265 | todoProgress.setFinishedDateTime(QDateTime::fromString(QStringLiteral("1995-05-20T11:22:33+02:00" ), f: Qt::ISODate)); |
266 | todoProgress.setPercentageComplete(64); |
267 | todoProgress.setStatus(QOrganizerTodoProgress::StatusInProgress); |
268 | return todoProgress; |
269 | } else if (detailType == QOrganizerItemDetail::TypeReminder) { |
270 | // do nothing, because noboday should directly use this |
271 | } else if (detailType == QOrganizerItemDetail::TypeAudibleReminder) { |
272 | QOrganizerItemAudibleReminder audibleReminder; |
273 | audibleReminder.setDataUrl(QUrl::fromLocalFile(QStringLiteral("some_random_path" ))); |
274 | audibleReminder.setRepetition(count: 6, delaySeconds: 4); |
275 | audibleReminder.setSecondsBeforeStart(1989); |
276 | return audibleReminder; |
277 | } else if (detailType == QOrganizerItemDetail::TypeVisualReminder) { |
278 | QOrganizerItemVisualReminder visualReminder; |
279 | visualReminder.setDataUrl(QUrl::fromLocalFile(QStringLiteral("yet_another_path" ))); |
280 | visualReminder.setMessage(QStringLiteral("Qt!!" )); |
281 | visualReminder.setRepetition(count: 6, delaySeconds: 4); |
282 | visualReminder.setSecondsBeforeStart(1989); |
283 | return visualReminder; |
284 | } else if (detailType == QOrganizerItemDetail::TypeEmailReminder) { |
285 | QOrganizerItemEmailReminder emailReminder; |
286 | emailReminder.setContents(QStringLiteral("Qt Rocks!!" ), |
287 | QStringLiteral("Qt - Cross-platform application and UI framework" ), |
288 | attachments: QVariantList() << QVariant(QStringLiteral("Code once" )) |
289 | << QVariant(QStringLiteral("Create more" )) |
290 | << QVariant(QStringLiteral("Deploy everywhere" ))); |
291 | emailReminder.setRecipients(QStringList() << QStringLiteral("Berlin" ) |
292 | << QStringLiteral("Brisbane" ) |
293 | << QStringLiteral("Oslo" ) |
294 | << QStringLiteral("Tampere" )); |
295 | emailReminder.setRepetition(count: 6, delaySeconds: 4); |
296 | emailReminder.setSecondsBeforeStart(1989); |
297 | return emailReminder; |
298 | } else if (detailType == QOrganizerItemDetail::TypeComment) { |
299 | QOrganizerItemComment ; |
300 | comment.setComment(QStringLiteral("Qt Everywhere!" )); |
301 | return comment; |
302 | } else if (detailType == QOrganizerItemDetail::TypeDescription) { |
303 | QOrganizerItemDescription description; |
304 | description.setDescription(QStringLiteral("Qt is cute!" )); |
305 | return description; |
306 | } else if (detailType == QOrganizerItemDetail::TypeDisplayLabel) { |
307 | QOrganizerItemDisplayLabel displayLabel; |
308 | displayLabel.setLabel(QStringLiteral("Qt - Cross-platform application and UI framework" )); |
309 | return displayLabel; |
310 | } else if (detailType == QOrganizerItemDetail::TypeGuid) { |
311 | // do nothing, because it should be set by the back-end engine |
312 | } else if (detailType == QOrganizerItemDetail::TypeLocation) { |
313 | QOrganizerItemLocation location; |
314 | location.setLabel(QStringLiteral("In the middle of nowhere" )); |
315 | location.setLatitude(19.84); |
316 | location.setLongitude(6.4); |
317 | return location; |
318 | } else if (detailType == QOrganizerItemDetail::TypeParent) { |
319 | // do nothing, because it's handled specially |
320 | } else if (detailType == QOrganizerItemDetail::TypePriority) { |
321 | QOrganizerItemPriority priority; |
322 | priority.setPriority(QOrganizerItemPriority::HighPriority); |
323 | return priority; |
324 | } else if (detailType == QOrganizerItemDetail::TypeRecurrence) { |
325 | QOrganizerItemRecurrence recurrence; |
326 | |
327 | recurrence.setRecurrenceDates(QSet<QDate>() << QDate(2005, 6, 28) << QDate(2005, 12, 19) << QDate(2006, 10, 4) |
328 | << QDate(2007, 5, 30) << QDate(2008, 5, 6) << QDate(2009, 3, 3) |
329 | << QDate(2009, 12, 1) << QDate(2010, 9, 21)); |
330 | |
331 | QOrganizerRecurrenceRule recurrenceRule; |
332 | recurrenceRule.setFrequency(QOrganizerRecurrenceRule::Yearly); |
333 | recurrenceRule.setInterval(1); |
334 | recurrenceRule.setLimit(QOrganizerRecurrenceRule::NoLimit); |
335 | recurrenceRule.setMonthsOfYear(QSet<QOrganizerRecurrenceRule::Month>() << QOrganizerRecurrenceRule::September); |
336 | recurrenceRule.setDaysOfMonth(QSet<int>() << 24); |
337 | recurrence.setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << recurrenceRule); |
338 | |
339 | recurrence.setExceptionDates(QSet<QDate>() << QDate(2008, 9, 24) << QDate(2009, 9, 24) << QDate(2010, 9, 24)); |
340 | |
341 | QOrganizerRecurrenceRule exceptionRule; |
342 | exceptionRule.setFrequency(QOrganizerRecurrenceRule::Yearly); |
343 | exceptionRule.setInterval(2); |
344 | exceptionRule.setLimit(QOrganizerRecurrenceRule::NoLimit); |
345 | exceptionRule.setMonthsOfYear(QSet<QOrganizerRecurrenceRule::Month>() << QOrganizerRecurrenceRule::September); |
346 | exceptionRule.setDaysOfMonth(QSet<int>() << 24); |
347 | recurrence.setExceptionRules(QSet<QOrganizerRecurrenceRule>() << exceptionRule); |
348 | |
349 | return recurrence; |
350 | } else if (detailType == QOrganizerItemDetail::TypeTimestamp) { |
351 | // do nothing, because it should be maintained by the back-end engine |
352 | } else if (detailType == QOrganizerItemDetail::TypeItemType) { |
353 | // do nothing, because it should not be changed |
354 | } else if (detailType == QOrganizerItemDetail::TypeTag) { |
355 | QOrganizerItemTag tag; |
356 | tag.setTag(QStringLiteral("Qt Open Governance" )); |
357 | } else if (detailType == QOrganizerItemDetail::TypeExtendedDetail) { |
358 | QOrganizerItemExtendedDetail extendedDetail; |
359 | extendedDetail.setName(QStringLiteral("My-Stupid-Extended-Detail" )); |
360 | extendedDetail.setData(QVariantList() << QVariant(QStringLiteral("Code once" )) |
361 | << QVariant(QStringLiteral("Create more" )) |
362 | << QVariant(QStringLiteral("Deploy everywhere" ))); |
363 | return extendedDetail; |
364 | } else if (detailType == QOrganizerItemDetail::TypeEventAttendee) { |
365 | QOrganizerEventAttendee attendee; |
366 | attendee.setName(QStringLiteral("people" )); |
367 | attendee.setAttendeeId(QStringLiteral("123456" )); |
368 | attendee.setEmailAddress(QStringLiteral("people@nokia.com" )); |
369 | attendee.setParticipationRole(QOrganizerEventAttendee::RoleRequiredParticipant); |
370 | attendee.setParticipationStatus(QOrganizerEventAttendee::StatusAccepted); |
371 | return attendee; |
372 | } else if (detailType == QOrganizerItemDetail::TypeVersion) { |
373 | // do nothing, because it should be maintained by the back-end engine |
374 | } |
375 | |
376 | return QOrganizerItemDetail(); |
377 | } |
378 | |
379 | QTEST_MAIN(tst_QOrganizerE2E) |
380 | #include "tst_qorganizere2e.moc" |
381 | |