1 // xestiacalendar_icaleventsave.h - Xestia Calendar iCalendar Event Component Save 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/calendarevent/CalendarEvent.h"
21 TEST(iCalendarSaveEvent, SaveEventTests){
23 CalendarEventObject testEvent;
24 CalendarEventObject testEvent2;
25 CalendarEventObject testEvent3;
27 // Load the test event.
29 ASSERT_EQ(CALENDAROBJECTLOAD_OK, testEvent.LoadFile("iCalendarEvent-Load1.vcf"));
30 ASSERT_EQ(CALENDAROBJECTVALID_OK, testEvent.ValidBaseObject());
32 //ASSERT_EQ(CALENDAROBJECTSAVE_MISSING, testEvent.LoadFile("iCalendarEvent-Missing.vcf"));
33 //ASSERT_EQ(CALENDAROBJECTSAVE_CANNOTOPEN, testEvent.LoadFile("iCalendarEvent-InvalidPermissions.vcf"));
34 //ASSERT_EQ(CALENDAROBJECTSAVE_OK, testEvent.LoadFile("iCalendarEvent-Load1.vcf"));
36 ASSERT_EQ(CALENDAROBJECTSAVE_CANNOTOPEN, testEvent.SaveFile("/stupidfilelocation/dontsavehere.ics"));
38 // Save the data to a string and compare the data.
40 // First contact file.
42 std::string saveDataComparison = "BEGIN:VCALENDAR\n"
44 "METHOD;EXAMPLE=DATA:REQUEST\n"
45 "CALSCALE;MORE=YES:GREGORIAN\n"
46 "PRODID:-//Xestia//Calendar Unit Testing//KW\n"
48 "UID:329128-12939123-123123-13\n"
49 "DTSTAMP:20160116T190200Z\n"
50 "DTSTART:20160116T190200Z\n"
51 "DTEND:20160116T190200Z\n"
52 "SUMMARY:Unit Test Event 1 which has to be a really long summary as we don't k\n"
53 " now if multiple line processing is going to work without it. I mean seriousl\n"
54 " y, how annoying can this potentially be?\n"
60 testEvent.SaveString(&saveData);
62 ASSERT_EQ(saveDataComparison, saveData);
64 // Process the second calendar item.
66 ASSERT_EQ(CALENDAROBJECTLOAD_OK, testEvent2.LoadFile("iCalendarEvent-Load2.vcf"));
67 ASSERT_EQ(CALENDAROBJECTVALID_OK, testEvent2.ValidBaseObject());
70 saveDataComparison = "BEGIN:VCALENDAR\n"
72 "PRODID:-//Xestia//Calendar Unit Testing//KW\n"
74 "UID;UNIQUEPARAM=CERTAINLY;OKAY=MAYBENOT:b3a16392-ad86-4061-be53-c215af2306e0\n"
75 "DTSTAMP;OTHER=PARAM:20160122T124100Z\n"
76 "DTSTART;VALUE=DATE-TIME;TZID=Europe/Truro;PARAMONE=YES;PARAMTWO=NO:20160122T1\n"
78 "DTEND;VALUE=DATE-TIME;TZID=Europe/Truro;PARAMFOUR=YES;PARAMTHREE=NO:20160124T\n"
80 "SUMMARY;ALTREP=\"null:nodata\";LANGUAGE=kw;FAVOURITE=TOFU;NOTLIKE=NONE:A summar\n"
82 "CLASS;CHOCOLATE=BAR:PUBLIC\n"
83 "CREATED;CARAMEL=PLEASE:20160123T081100Z\n"
84 "DESCRIPTION;ALTREP=\"null:nodata\";LANGUAGE=kw;EXAMPLE=TOKEN;MOREDATA=YES:This \n"
85 " is a description of the event.\n"
86 "GEO;EXAMPLE=MEEP:5.0;5.0\n"
87 "LAST-MODIFIED;FUTURE=ODD:20160124T093000Z\n"
88 "LOCATION;ALTREP=\"null:nodata\";LANGUAGE=kw;EXACT=NO:The Basement, Truro\n"
89 "ORGANIZER;CN=ExampleOrganiser;DIR=\"null:nodata\";SENT-BY=\"mailto:organiser.nor\n"
90 " eply@example.com\";LANGUAGE=kw;HAPPY=DAYS:mailto:organiser@example.com\n"
91 "PRIORITY;STATUS=DEFAULT:5\n"
92 "SEQUENCE;TEST=YAY:3\n"
93 "STATUS;LANGUAGE=kw;FAVOURITE=RICHTEA;NOTLIKE=UNKNOWN:2.0;Success\n"
94 "TRANSP;OPAQUE=NOTYET:TRANSPARENT\n"
95 "URL;EXTERNAL=YES:http://www.example.com/\n"
96 "RECURRENCE-ID;TZID=Europe/Truro;RANGE=THISANDFUTURE;VALUE=DATE;EXAMPLE=DATA:2\n"
98 "RRULE;TEST=DATA:FREQ=DAILY;COUNT=10\n"
99 "ATTACH;FMTTYPE=application/internet-shortcut:http://www.example.com/\n"
100 "ATTACH;FMTTYPE=application/internet-shortcut:http://www.example.com/page2.htm\n"
102 "ATTACH;FMTTYPE=text/plain;VALUE=BINARY;ENCODING=BASE64;STUPID=EXAMPLE:VGhpcyB\n"
103 " pcyBhbiBleGFtcGxlIGZpbGU=\n"
104 "ATTENDEE:Attendee One\n"
105 "ATTENDEE;DELEGATED-FROM=\"mailto:delegated.from@example.com\";DELEGATED-TO=\"mai\n"
106 " lto:delegated.to@example.com\";ROLE=CHAIR;RSVP=TRUE:Attendee Two\n"
107 "ATTENDEE;DIR=\"null:nodata\";SENT-BY=\"mailto:sent.by@example.com\";CN=\"Attendee \n"
108 " The Third\";CUTYPE=INDIVIDUAL;PARTSTAT=ACCEPTED;LANGUAGE=kw;EXAMPLE=DATA:Atte\n"
110 "CATEGORIES:CATEGORY ONE, CATEGORY TWO\n"
111 "CATEGORIES;LANGUAGE=en:CATEGORY THREE, CATEGORY FOUR\n"
112 "CATEGORIES;LANGUAGE=en-GB;SAMPLE=TOKEN:CATEGORY FIVE, CATEGORY SIX, CATEGORY \n"
114 "COMMENT:This is the first comment.\n"
115 "COMMENT;ALTREP=\"null:nodata\";LANGUAGE=en:This is the second comment.\n"
116 "COMMENT;ZEBRAS=YES:This is the third comment.\n"
117 "CONTACT:First Contact\n"
118 "CONTACT;ALTREP=\"null:nodata\";LANGUAGE=en-GB:Second Contact\n"
119 "CONTACT;ZEBRAS=NO:Third Contact\n"
120 "EXDATE:20160125T120000Z\n"
121 "EXDATE;TZID=Europe/Truro;VALUE=DATE-TIME:20160125T130000Z\n"
122 "EXDATE;ZOOP=ZIPPO:20160125T133000Z\n"
123 "REQUEST-STATUS:2.0;Success\n"
124 "REQUEST-STATUS;LANGUAGE=en:3.42;Really big irrecoverable error caused by the \n"
126 "REQUEST-STATUS;USER=MISSING:3.7;Invalid calendar user\n"
127 "RELATED-TO:person.1@example.com\n"
128 "RELATED-TO;RELTYPE=PARENT:person.2@example.com\n"
129 "RELATED-TO;SCHOOL=MEETING:person.3@example.com\n"
130 "RESOURCES:DMAC RECEIVER\n"
131 "RESOURCES;LANGUAGE=en:PAL-I TELEVISION SET\n"
132 "RESOURCES;ALTREP=\"null:nodata\";STATUS=BROKEN:PAL/SECAM VCR\n"
134 "RDATE;VALUE=DATE;TZID=Europe/Truro:20160121\n"
135 "RDATE;ZILCH=DATA:20160520\n"
137 "ACTION;FUNKY=SOUNDS:AUDIO\n"
138 "TRIGGER;RELATED=END;VALUE=DATE-TIME;PUSH=BUTTON:20160220T160000Z\n"
139 "DURATION;FLYING=NO:PT5H\n"
140 "REPEAT;NEVER=SLEEP:PT5M\n"
141 "ATTACH;FMTTYPE=application/internet-shortcut:http://www.example.com/\n"
142 "ATTACH;FMTTYPE=application/internet-shortcut:http://www.example.com/page2.htm\n"
144 "ATTACH;FMTTYPE=text/plain;VALUE=BINARY;ENCODING=BASE64;STUPID=EXAMPLE:VGhpcyB\n"
145 " pcyBhbiBleGFtcGxlIGZpbGU=\n"
146 "X-EXAMPLE1;YAY=YES:Example Data 1\n"
147 "X-EXAMPLE2;NOPE=YEP:Example Data 2\n"
148 "X-EXAMPLE3;WORLD=NO:Example Data 3\n"
151 "ACTION;FLASHING=LIGHTS:DISPLAY\n"
152 "TRIGGER;RELATED=END;VALUE=DATE-TIME;PUSH=BUTTON:20160230T110000Z\n"
153 "DURATION;FLYING=YES:PT7H\n"
154 "DESCRIPTION;ALTREP=\"null:nodata\";LANGUAGE=kw;TERRIBLE=TOKEN:This is the secon\n"
156 "REPEAT;SLEEP=ALWAYS:PT3M\n"
157 "X-EXAMPLE1;YAY=YES:Example Data 1\n"
158 "X-EXAMPLE2;NOPE=YEP:Example Data 2\n"
159 "X-EXAMPLE3;WORLD=NO:Example Data 3\n"
162 "ACTION;FLASHING=LIGHTS:EMAIL\n"
163 "TRIGGER;RELATED=END;VALUE=DATE-TIME;PUSH=BUTTON:20160230T120000Z\n"
164 "DURATION;FLYING=YES:PT7H\n"
165 "DESCRIPTION;ALTREP=\"null:nodata\";LANGUAGE=kw;TERRIBLE=TOKEN:This is the third\n"
167 "SUMMARY;ALTREP=\"null:nodata\";LANGUAGE=en;MEEP=MOOP:This is the summary of the\n"
169 "REPEAT;SLEEP=ALWAYS:PT3M\n"
170 "ATTENDEE:Attendee One\n"
171 "ATTENDEE;DELEGATED-FROM=\"mailto:delegated.from@example.com\";DELEGATED-TO=\"mai\n"
172 " lto:delegated.to@example.com\";ROLE=CHAIR;RSVP=TRUE:Attendee Two\n"
173 "ATTENDEE;DIR=\"null:nodata\";SENT-BY=\"mailto:sent.by@example.com\";CN=\"Attendee \n"
174 " The Third\";CUTYPE=INDIVIDUAL;PARTSTAT=ACCEPTED;LANGUAGE=kw;EXAMPLE=DATA:Atte\n"
176 "ATTACH;FMTTYPE=application/internet-shortcut:http://www.example.com/\n"
177 "ATTACH;FMTTYPE=application/internet-shortcut:http://www.example.com/page2.htm\n"
179 "ATTACH;FMTTYPE=text/plain;VALUE=BINARY;ENCODING=BASE64;STUPID=EXAMPLE:VGhpcyB\n"
180 " pcyBhbiBleGFtcGxlIGZpbGU=\n"
181 "X-EXAMPLE1;YAY=YES:Example Data 1\n"
182 "X-EXAMPLE2;NOPE=YEP:Example Data 2\n"
183 "X-EXAMPLE3;WORLD=NO:Example Data 3\n"
186 "X-EXAMPLE1;ANIMAL=NOPE:Meep\n"
187 "X-EXAMPLE1;ANIMAL=CAT:Meow\n"
189 "X-EXAMPLE2;OBJECT=KITCHEN:Fork\n"
190 "X-EXAMPLE2;OBJECT=LIVINGROOM:Table\n"
191 "X-STATUS;HOLIDAY=YES:Idle\n"
192 "X-TRANSPORT;PUBLIC=NO:Private Hire\n"
193 "X-PHANTOM-STATUS;HELP=NONE:None\n"
197 testEvent2.SaveString(&saveData);
199 ASSERT_EQ(saveDataComparison, saveData);
201 ASSERT_EQ(CALENDAROBJECTLOAD_OK, testEvent3.LoadFile("iCalendarEvent-Load3.vcf"));
202 ASSERT_EQ(CALENDAROBJECTVALID_OK, testEvent3.ValidBaseObject());
206 saveDataComparison = "BEGIN:VCALENDAR\n"
208 "PRODID:-//Xestia//Calendar Unit Testing//KW\n"
210 "UID:b3a16392-ad86-4061-be53-c215af2306e1\n"
211 "DTSTAMP:20160127T111200Z\n"
212 "DTSTART:20160122T183000Z\n"
213 "DURATION;TEST=EXAMPLE:PT1H\n"
217 testEvent3.SaveString(&saveData);
219 ASSERT_EQ(saveDataComparison, saveData);