1 // xestiacalendar_icalfreebusyload.h - Xestia Calendar iCalendar FreeBusy Component Unit Tests
3 // (c) 2016 Xestia Software Development.
5 // This file is part of Xestia Calendar.
7 // Xestia Address Book 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 Address Book 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);