1 // xestiacalendar_icalfreebusyload.h - Xestia Calendar iCalendar FreeBusy Component Unit Tests
3 // (c) 2016-2017 Xestia Software Development.
5 // This file is part of Xestia Calendar.
7 // Xestia Calendar is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Calendar is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Calendar. If not, see <http://www.gnu.org/licenses/>
19 #include "../objects/calendarfreebusy/CalendarFreeBusy.h"
21 TEST(iCalendarFreeBusy, BasicTests){
23 CalendarFreeBusyObject testFreeBusy;
25 ASSERT_EQ(CALENDAROBJECTLOAD_MISSING, testFreeBusy.LoadFile("iCalendarFreeBusy-Missing.vcf"));
26 ASSERT_EQ(CALENDAROBJECTLOAD_CANNOTOPEN, testFreeBusy.LoadFile("iCalendarFreeBusy-InvalidPermissions.vcf"));
27 ASSERT_EQ(CALENDAROBJECTLOAD_OK, testFreeBusy.LoadFile("iCalendarFreeBusy-Load1.vcf"));
31 TEST(iCalendarFreeBusy, ObjectDataTests){
33 CalendarFreeBusyObject testFreeBusy;
34 ASSERT_EQ(CALENDAROBJECTLOAD_OK, testFreeBusy.LoadFile("iCalendarFreeBusy-Load2.vcf"));
35 ASSERT_EQ(CALENDAROBJECTVALID_OK, testFreeBusy.ValidBaseObject());
39 ASSERT_EQ("20160131T173000Z", testFreeBusy.dateTimeStampData);
40 ASSERT_EQ("OTHER=PARAM", testFreeBusy.dateTimeStampTokens);
44 ASSERT_EQ("b3a16392-ad86-4061-be53-c215af2306ff", testFreeBusy.uniqueID);
45 ASSERT_EQ("UNIQUEPARAM=CERTAINLY;OKAY=MAYBENOT", testFreeBusy.uniqueIDTokens);
49 std::string contactData;
50 std::string contactDataAltRep;
51 std::string contactDataLanguage;
52 std::string contactDataTokens;
54 if (testFreeBusy.contactList.size() > 0){
56 contactData = testFreeBusy.contactList[0];
60 if (testFreeBusy.contactList.size() > 0){
62 contactDataAltRep = testFreeBusy.contactListAltRep[0];
66 if (testFreeBusy.contactList.size() > 0){
68 contactDataLanguage = testFreeBusy.contactListLanguage[0];
72 if (testFreeBusy.contactList.size() > 0){
74 contactDataTokens = testFreeBusy.contactListTokens[0];
78 ASSERT_EQ("Contact Person", contactData);
79 ASSERT_EQ("null:nodata", contactDataAltRep);
80 ASSERT_EQ("en-GB", contactDataLanguage);
81 ASSERT_EQ("EXAMPLE=TOKEN", contactDataTokens);
85 ASSERT_EQ("20160131T103000Z", testFreeBusy.dateTimeStartData);
86 ASSERT_EQ("DATE-TIME", testFreeBusy.dateTimeStartDataValue);
87 ASSERT_EQ("Europe/Truro", testFreeBusy.dateTimeStartDataTimeZoneID);
88 ASSERT_EQ("PARAMONE=YES;PARAMTWO=NO", testFreeBusy.dateTimeStartDataTokens);
92 ASSERT_EQ("20160131T183000Z", testFreeBusy.dateTimeEndData);
93 ASSERT_EQ("DATE-TIME", testFreeBusy.dateTimeEndDataValue);
94 ASSERT_EQ("Europe/Truro", testFreeBusy.dateTimeEndDataTimeZoneID);
95 ASSERT_EQ("PARAMFOUR=YES;PARAMTHREE=NO", testFreeBusy.dateTimeEndDataTokens);
97 // Tests for ORGANIZER.
99 ASSERT_EQ("mailto:organiser@example.com", testFreeBusy.organiserData);
100 ASSERT_EQ("ExampleOrganiser", testFreeBusy.organiserDataCommonName);
101 ASSERT_EQ("null:nodata", testFreeBusy.organiserDataDirectoryEntry);
102 ASSERT_EQ("mailto:organiser.noreply@example.com", testFreeBusy.organiserDataSentByParam);
103 ASSERT_EQ("kw", testFreeBusy.organiserDataLanguage);
104 ASSERT_EQ("HAPPY=DAYS", testFreeBusy.organiserDataTokens);
108 ASSERT_EQ("http://www.example.com/", testFreeBusy.urlData);
109 ASSERT_EQ("EXTERNAL=YES", testFreeBusy.urlDataTokens);
111 // Tests for ATTENDEE. First ATTENDEE property.
113 std::string attendeeDataMember;
114 std::string attendeeDataDelegatedFrom;
115 std::string attendeeDataDelegatedTo;
116 std::string attendeeDataRole;
117 std::string attendeeDataRSVP;
118 std::string attendeeDataDirectoryEntry;
119 std::string attendeeDataSentBy;
120 std::string attendeeDataCommonName;
121 std::string attendeeDataCalendarUserType;
122 std::string attendeeDataParticipationStatus;
123 std::string attendeeDataLanguage;
124 std::string attendeeDataTokens;
125 std::string attendeeData;
127 if (testFreeBusy.attendeeList.begin() != testFreeBusy.attendeeList.end()){
129 attendeeData = testFreeBusy.attendeeList[0];
133 ASSERT_EQ("Attendee One", attendeeData);
135 // Second ATTENDEE property.
137 attendeeData.clear();
139 if (testFreeBusy.attendeeList.size() > 1){
141 attendeeData = testFreeBusy.attendeeList[1];
145 if (testFreeBusy.attendeeList.size() > 1){
147 attendeeDataDelegatedFrom = testFreeBusy.attendeeListDelegatedFrom[1];
151 if (testFreeBusy.attendeeList.size() > 1){
153 attendeeDataDelegatedTo = testFreeBusy.attendeeListDelegatedTo[1];
157 if (testFreeBusy.attendeeList.size() > 1){
159 attendeeDataRole = testFreeBusy.attendeeListRole[1];
163 if (testFreeBusy.attendeeList.size() > 1){
165 attendeeDataRSVP = testFreeBusy.attendeeListRSVP[1];
169 ASSERT_EQ("Attendee Two", attendeeData);
170 ASSERT_EQ("mailto:delegated.from@example.com", attendeeDataDelegatedFrom);
171 ASSERT_EQ("mailto:delegated.to@example.com", attendeeDataDelegatedTo);
172 ASSERT_EQ("CHAIR", attendeeDataRole);
173 ASSERT_EQ("TRUE", attendeeDataRSVP);
175 // Third ATTENDEE property.
177 attendeeData.clear();
179 if (testFreeBusy.attendeeList.size() > 2){
181 attendeeData = testFreeBusy.attendeeList[2];
185 if (testFreeBusy.attendeeList.size() > 2){
187 attendeeDataDirectoryEntry = testFreeBusy.attendeeListDirectoryEntry[2];
191 if (testFreeBusy.attendeeList.size() > 2){
193 attendeeDataSentBy = testFreeBusy.attendeeListSentBy[2];
197 if (testFreeBusy.attendeeList.size() > 2){
199 attendeeDataCommonName = testFreeBusy.attendeeListCommonName[2];
203 if (testFreeBusy.attendeeList.size() > 2){
205 attendeeDataCalendarUserType = testFreeBusy.attendeeListCalendarUserType[2];
209 if (testFreeBusy.attendeeList.size() > 2){
211 attendeeDataParticipationStatus = testFreeBusy.attendeeListParticipationStatus[2];
215 if (testFreeBusy.attendeeList.size() > 2){
217 attendeeDataLanguage = testFreeBusy.attendeeListLanguage[2];
221 if (testFreeBusy.attendeeList.size() > 2){
223 attendeeDataTokens = testFreeBusy.attendeeListTokens[2];
227 ASSERT_EQ("Attendee Three", attendeeData);
228 ASSERT_EQ("null:nodata", attendeeDataDirectoryEntry);
229 ASSERT_EQ("mailto:sent.by@example.com", attendeeDataSentBy);
230 ASSERT_EQ("Attendee The Third", attendeeDataCommonName);
231 ASSERT_EQ("INDIVIDUAL", attendeeDataCalendarUserType);
232 ASSERT_EQ("ACCEPTED", attendeeDataParticipationStatus);
233 ASSERT_EQ("kw", attendeeDataLanguage);
234 ASSERT_EQ("EXAMPLE=DATA", attendeeDataTokens);
236 // Get the first COMMENT.
238 std::string commentData;
240 if (testFreeBusy.commentList.begin() != testFreeBusy.commentList.end()){
242 commentData = testFreeBusy.commentList[0];
246 ASSERT_EQ("This is the first comment.", commentData);
248 // Get the second COMMENT.
252 std::string commentDataAltRep;
253 std::string commentDataLanguage;
255 if (testFreeBusy.commentList.size() > 1){
257 commentData = testFreeBusy.commentList[1];
261 if (testFreeBusy.commentList.size() > 1){
263 commentDataAltRep = testFreeBusy.commentListAltRep[1];
267 if (testFreeBusy.commentList.size() > 1){
269 commentDataLanguage = testFreeBusy.commentListLanguage[1];
273 ASSERT_EQ("This is the second comment.", commentData);
274 ASSERT_EQ("null:nodata", commentDataAltRep);
275 ASSERT_EQ("en", commentDataLanguage);
277 // Get the third COMMENT.
281 std::string commentDataTokens;
283 if (testFreeBusy.commentList.size() > 2){
285 commentData = testFreeBusy.commentList[2];
289 if (testFreeBusy.commentList.size() > 2){
291 commentDataTokens = testFreeBusy.commentListTokens[2];
295 ASSERT_EQ("This is the third comment.", commentData);
296 ASSERT_EQ("ZEBRAS=YES", commentDataTokens);
298 // Get the first FREEBUSY.
300 std::string freeBusyData;
302 if (testFreeBusy.freeBusyList.begin() != testFreeBusy.freeBusyList.end()){
304 freeBusyData = testFreeBusy.freeBusyList[0];
308 ASSERT_EQ("20160202T210000Z/PT1H", freeBusyData);
310 // Get the second FREEBUSY.
312 freeBusyData.clear();
314 std::string freeBusyType;
316 if (testFreeBusy.freeBusyList.size() > 1){
318 freeBusyData = testFreeBusy.freeBusyList[1];
322 if (testFreeBusy.freeBusyListType.size() > 1){
324 freeBusyType = testFreeBusy.freeBusyListType[1];
328 ASSERT_EQ("FREE", freeBusyType);
329 ASSERT_EQ("20160202T220000Z/PT1H", freeBusyData);
331 // Get the third FREEBUSY.
333 freeBusyData.clear();
334 freeBusyType.clear();
336 std::string FreeBusyTokens;
338 if (testFreeBusy.freeBusyList.size() > 2){
340 freeBusyData = testFreeBusy.freeBusyList[2];
344 if (testFreeBusy.freeBusyListType.size() > 2){
346 freeBusyType = testFreeBusy.freeBusyListType[2];
350 if (testFreeBusy.freeBusyListTokens.size() > 2){
352 FreeBusyTokens = testFreeBusy.freeBusyListTokens[2];
356 ASSERT_EQ("BUSY-UNAVAILABLE", freeBusyType);
357 ASSERT_EQ("20160202T230000Z/PT9H", freeBusyData);
358 ASSERT_EQ("RESULT=ARGH;TEST=YES", FreeBusyTokens);
360 // Get the first REQUEST-STATUS.
362 std::string requestStatus;
364 if (testFreeBusy.requestStatusData.begin() != testFreeBusy.requestStatusData.end()){
366 requestStatus = testFreeBusy.requestStatusData[0];
370 ASSERT_EQ("2.0;Success", requestStatus);
372 // Get the second REQUEST-STATUS.
374 requestStatus.clear();
376 std::string requestLanguage;
378 if (testFreeBusy.requestStatusData.size() > 1){
380 requestStatus = testFreeBusy.requestStatusData[1];
384 if (testFreeBusy.requestStatusData.size() > 1){
386 requestLanguage = testFreeBusy.requestStatusLanguage[1];
390 ASSERT_EQ("3.42;Really big irrecoverable error caused by the user", requestStatus);
391 ASSERT_EQ("en", requestLanguage);
393 // Get the third REQUEST-STATUS.
395 requestStatus.clear();
397 std::string requestTokens;
399 if (testFreeBusy.requestStatusData.size() > 2){
401 requestStatus = testFreeBusy.requestStatusData[2];
405 if (testFreeBusy.requestStatusData.size() > 2){
407 requestTokens = testFreeBusy.requestStatusTokens[2];
411 ASSERT_EQ("3.7;Invalid calendar user", requestStatus);
412 ASSERT_EQ("USER=MISSING", requestTokens);
414 // Get the first X-EXAMPLE1 token.
416 std::string xTokenName;
417 std::string xTokenData;
419 if (testFreeBusy.xTokensData.size() != 0 ){
421 xTokenData = testFreeBusy.xTokensData[0];
425 if (testFreeBusy.xTokensData.size() != 0){
427 xTokenName = testFreeBusy.xTokensDataTokens[0];
431 ASSERT_EQ("Moo", xTokenData);
432 ASSERT_EQ("X-EXAMPLE1", xTokenName);
434 // Get the second X-EXAMPLE1 token.
439 if (testFreeBusy.xTokensData.size() > 1){
441 xTokenData = testFreeBusy.xTokensData[1];
445 if (testFreeBusy.xTokensData.size() > 1){
447 xTokenName = testFreeBusy.xTokensDataTokens[1];
451 ASSERT_EQ("Meep", xTokenData);
452 ASSERT_EQ("X-EXAMPLE1;ANIMAL=NOPE", xTokenName);
454 // Get the third X-EXAMPLE1 token.
459 if (testFreeBusy.xTokensData.size() > 2){
461 xTokenData = testFreeBusy.xTokensData[2];
465 if (testFreeBusy.xTokensData.size() > 2){
467 xTokenName = testFreeBusy.xTokensDataTokens[2];
471 ASSERT_EQ("Meow", xTokenData);
472 ASSERT_EQ("X-EXAMPLE1;ANIMAL=CAT", xTokenName);
474 // Get the first X-EXAMPLE2 token.
479 if (testFreeBusy.xTokensData.size() > 3){
481 xTokenData = testFreeBusy.xTokensData[3];
485 if (testFreeBusy.xTokensData.size() > 3){
487 xTokenName = testFreeBusy.xTokensDataTokens[3];
491 ASSERT_EQ("Dish", xTokenData);
492 ASSERT_EQ("X-EXAMPLE2", xTokenName);
494 // Get the second X-EXAMPLE2 token.
499 if (testFreeBusy.xTokensData.size() > 4){
501 xTokenData = testFreeBusy.xTokensData[4];
505 if (testFreeBusy.xTokensData.size() > 4){
507 xTokenName = testFreeBusy.xTokensDataTokens[4];
511 ASSERT_EQ("Fork", xTokenData);
512 ASSERT_EQ("X-EXAMPLE2;OBJECT=KITCHEN", xTokenName);
514 // Get the third X-EXAMPLE2 token.
519 if (testFreeBusy.xTokensData.size() > 5){
521 xTokenData = testFreeBusy.xTokensData[5];
525 if (testFreeBusy.xTokensData.size() > 5){
527 xTokenName = testFreeBusy.xTokensDataTokens[5];
531 ASSERT_EQ("Table", xTokenData);
532 ASSERT_EQ("X-EXAMPLE2;OBJECT=LIVINGROOM", xTokenName);
534 // Get the X-STATUS token.
539 if (testFreeBusy.xTokensData.size() > 6){
541 xTokenData = testFreeBusy.xTokensData[6];
545 if (testFreeBusy.xTokensData.size() > 6){
547 xTokenName = testFreeBusy.xTokensDataTokens[6];
551 ASSERT_EQ("Idle", xTokenData);
552 ASSERT_EQ("X-STATUS;HOLIDAY=YES", xTokenName);
554 // Get the X-TRANSPORT token.
559 if (testFreeBusy.xTokensData.size() > 7){
561 xTokenData = testFreeBusy.xTokensData[7];
565 if (testFreeBusy.xTokensData.size() > 7){
567 xTokenName = testFreeBusy.xTokensDataTokens[7];
571 ASSERT_EQ("Private Hire", xTokenData);
572 ASSERT_EQ("X-TRANSPORT;PUBLIC=NO", xTokenName);
574 // Get the X-PHANTOM-STATUS token.
579 if (testFreeBusy.xTokensData.size() > 8){
581 xTokenData = testFreeBusy.xTokensData[8];
585 if (testFreeBusy.xTokensData.size() > 8){
587 xTokenName = testFreeBusy.xTokensDataTokens[8];
591 ASSERT_EQ("None", xTokenData);
592 ASSERT_EQ("X-PHANTOM-STATUS;HELP=NONE", xTokenName);