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