1 // xestiacalendar_icaleventload.h - Xestia Calendar iCalendar Journal 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/calendarjournal/CalendarJournal.h"
21 TEST(iCalendarJournal, BasicTests){
23 CalendarJournalObject TestJournal;
25 ASSERT_EQ(CALENDAROBJECTLOAD_MISSING, TestJournal.LoadFile("iCalendarJournal-Missing.vcf"));
26 ASSERT_EQ(CALENDAROBJECTLOAD_CANNOTOPEN, TestJournal.LoadFile("iCalendarJournal-InvalidPermissions.vcf"));
27 ASSERT_EQ(CALENDAROBJECTLOAD_OK, TestJournal.LoadFile("iCalendarJournal-Load1.vcf"));
31 TEST(iCalendarJournal, ObjectDataTests){
33 CalendarJournalObject TestJournal;
34 ASSERT_EQ(CALENDAROBJECTLOAD_OK, TestJournal.LoadFile("iCalendarJournal-Load2.vcf"));
35 ASSERT_EQ(CALENDAROBJECTVALID_OK, TestJournal.ValidBaseObject());
39 ASSERT_EQ("20160131T141500Z", TestJournal.DateTimeStampData);
40 ASSERT_EQ("OTHER=PARAM", TestJournal.DateTimeStampTokens);
44 ASSERT_EQ("b3a16392-ad86-4061-be53-c215af2306c1", TestJournal.UniqueID);
45 ASSERT_EQ("UNIQUEPARAM=CERTAINLY;OKAY=MAYBENOT", TestJournal.UniqueIDTokens);
49 ASSERT_EQ("PUBLIC", TestJournal.ClassData);
50 ASSERT_EQ("CHOCOLATE=BAR", TestJournal.ClassDataTokens);
54 ASSERT_EQ("20160131T143500Z", TestJournal.DateTimeStartData);
55 ASSERT_EQ("DATE-TIME", TestJournal.DateTimeStartDataValue);
56 ASSERT_EQ("Europe/Truro", TestJournal.DateTimeStartDataTimeZoneID);
57 ASSERT_EQ("PARAMONE=YES;PARAMTWO=NO", TestJournal.DateTimeStartDataTokens);
59 // Tests for LAST-MODIFIED.
61 ASSERT_EQ("20160131T143700Z", TestJournal.LastModifiedData);
62 ASSERT_EQ("FUTURE=YES", TestJournal.LastModifiedTokens);
64 // Tests for ORGANIZER.
66 ASSERT_EQ("mailto:organiser@example.com", TestJournal.OrganiserData);
67 ASSERT_EQ("ExampleOrganiser", TestJournal.OrganiserDataCommonName);
68 ASSERT_EQ("null:nodata", TestJournal.OrganiserDataDirectoryEntry);
69 ASSERT_EQ("mailto:organiser.noreply@example.com", TestJournal.OrganiserDataSentByParam);
70 ASSERT_EQ("kw", TestJournal.OrganiserDataLanguage);
71 ASSERT_EQ("HAPPY=DAYS", TestJournal.OrganiserDataTokens);
73 // Tests for RECURRENCE-ID.
75 ASSERT_EQ("20160131", TestJournal.RecurranceIDData);
76 ASSERT_EQ("Europe/Truro", TestJournal.RecurranceIDDataTimeZoneParam);
77 ASSERT_EQ("THISANDFUTURE", TestJournal.RecurranceIDDataRangeParam);
78 ASSERT_EQ("DATE", TestJournal.RecurranceIDDataValue);
79 ASSERT_EQ("EXAMPLE=DATA", TestJournal.RecurranceIDDataTokens);
81 // Tests for SEQUENCE.
83 ASSERT_EQ(7, TestJournal.SequenceData);
84 ASSERT_EQ("TEST=YAY", TestJournal.SequenceTokens);
88 ASSERT_EQ("2.0;Success", TestJournal.StatusData);
89 ASSERT_EQ("kw", TestJournal.StatusLanguage);
90 ASSERT_EQ("FAVOURITE=RICHTEA;NOTLIKE=UNKNOWN", TestJournal.StatusTokens);
94 ASSERT_EQ("A summary of the journal entry.", TestJournal.SummaryData);
95 ASSERT_EQ("null:nodata", TestJournal.SummaryDataAltRep);
96 ASSERT_EQ("kw", TestJournal.SummaryDataLanguage);
97 ASSERT_EQ("FAVOURITE=TOFU;NOTLIKE=NONE", TestJournal.SummaryDataTokens);
101 ASSERT_EQ("http://www.example.com/", TestJournal.URLData);
102 ASSERT_EQ("EXTERNAL=YES", TestJournal.URLDataTokens);
106 ASSERT_EQ("FREQ=DAILY;COUNT=10", TestJournal.RecurranceRuleData);
107 ASSERT_EQ("TEST=DATA", TestJournal.RecurranceRuleDataTokens);
109 // Tests for ATTACH. First ATTACH property.
111 std::string AttachData;
112 std::string AttachDataFormatType;
113 std::string AttachDataValue;
114 std::string AttachDataEncoding;
115 std::string AttachDataTokens;
117 if (TestJournal.AttachList.begin() != TestJournal.AttachList.end()){
119 AttachData = TestJournal.AttachList[0];
123 if (TestJournal.AttachListFormatType.begin() != TestJournal.AttachListFormatType.end()){
125 AttachDataFormatType = TestJournal.AttachListFormatType[0];
129 ASSERT_EQ("http://www.example.com/", AttachData);
130 ASSERT_EQ("application/internet-shortcut", AttachDataFormatType);
132 // Second ATTACH property.
135 AttachDataFormatType.clear();
136 AttachDataValue.clear();
137 AttachDataEncoding.clear();
139 if (TestJournal.AttachList.size() > 1){
141 AttachData = TestJournal.AttachList[1];
145 if (TestJournal.AttachListFormatType.size() > 1){
147 AttachDataFormatType = TestJournal.AttachListFormatType[1];
151 ASSERT_EQ("http://www.example.com/page2.html", AttachData);
152 ASSERT_EQ("application/internet-shortcut", AttachDataFormatType);
154 // Third ATTACH property.
157 AttachDataFormatType.clear();
158 AttachDataValue.clear();
159 AttachDataEncoding.clear();
160 AttachDataTokens.clear();
162 if (TestJournal.AttachList.size() > 2){
164 AttachData = TestJournal.AttachList[2];
168 if (TestJournal.AttachListFormatType.size() > 2){
170 AttachDataFormatType = TestJournal.AttachListFormatType[2];
174 if (TestJournal.AttachListValue.size() > 2){
176 AttachDataValue = TestJournal.AttachListValue[2];
180 if (TestJournal.AttachListFormatType.size() > 2){
182 AttachDataEncoding = TestJournal.AttachListEncoding[2];
186 if (TestJournal.AttachListTokens.size() > 2){
188 AttachDataTokens = TestJournal.AttachListTokens[2];
192 ASSERT_EQ("VGhpcyBpcyBhbiBleGFtcGxlIGZpbGU=", AttachData);
193 ASSERT_EQ("text/plain", AttachDataFormatType);
194 ASSERT_EQ("BASE64", AttachDataEncoding);
195 ASSERT_EQ("BINARY", AttachDataValue);
196 ASSERT_EQ("STUPID=EXAMPLE", AttachDataTokens);
198 // Tests for ATTENDEE. First ATTENDEE property.
200 std::string AttendeeDataMember;
201 std::string AttendeeDataDelegatedFrom;
202 std::string AttendeeDataDelegatedTo;
203 std::string AttendeeDataRole;
204 std::string AttendeeDataRSVP;
205 std::string AttendeeDataDirectoryEntry;
206 std::string AttendeeDataSentBy;
207 std::string AttendeeDataCommonName;
208 std::string AttendeeDataCalendarUserType;
209 std::string AttendeeDataParticipationStatus;
210 std::string AttendeeDataLanguage;
211 std::string AttendeeDataTokens;
212 std::string AttendeeData;
214 if (TestJournal.AttendeeList.begin() != TestJournal.AttendeeList.end()){
216 AttendeeData = TestJournal.AttendeeList[0];
220 ASSERT_EQ("Attendee One", AttendeeData);
222 // Second ATTENDEE property.
224 AttendeeData.clear();
226 if (TestJournal.AttendeeList.size() > 1){
228 AttendeeData = TestJournal.AttendeeList[1];
232 if (TestJournal.AttendeeList.size() > 1){
234 AttendeeDataDelegatedFrom = TestJournal.AttendeeListDelegatedFrom[1];
238 if (TestJournal.AttendeeList.size() > 1){
240 AttendeeDataDelegatedTo = TestJournal.AttendeeListDelegatedTo[1];
244 if (TestJournal.AttendeeList.size() > 1){
246 AttendeeDataRole = TestJournal.AttendeeListRole[1];
250 if (TestJournal.AttendeeList.size() > 1){
252 AttendeeDataRSVP = TestJournal.AttendeeListRSVP[1];
256 ASSERT_EQ("Attendee Two", AttendeeData);
257 ASSERT_EQ("mailto:delegated.from@example.com", AttendeeDataDelegatedFrom);
258 ASSERT_EQ("mailto:delegated.to@example.com", AttendeeDataDelegatedTo);
259 ASSERT_EQ("CHAIR", AttendeeDataRole);
260 ASSERT_EQ("TRUE", AttendeeDataRSVP);
262 // Third ATTENDEE property.
264 AttendeeData.clear();
266 if (TestJournal.AttendeeList.size() > 2){
268 AttendeeData = TestJournal.AttendeeList[2];
272 if (TestJournal.AttendeeList.size() > 2){
274 AttendeeDataDirectoryEntry = TestJournal.AttendeeListDirectoryEntry[2];
278 if (TestJournal.AttendeeList.size() > 2){
280 AttendeeDataSentBy = TestJournal.AttendeeListSentBy[2];
284 if (TestJournal.AttendeeList.size() > 2){
286 AttendeeDataCommonName = TestJournal.AttendeeListCommonName[2];
290 if (TestJournal.AttendeeList.size() > 2){
292 AttendeeDataCalendarUserType = TestJournal.AttendeeListCalendarUserType[2];
296 if (TestJournal.AttendeeList.size() > 2){
298 AttendeeDataParticipationStatus = TestJournal.AttendeeListParticipationStatus[2];
302 if (TestJournal.AttendeeList.size() > 2){
304 AttendeeDataLanguage = TestJournal.AttendeeListLanguage[2];
308 if (TestJournal.AttendeeList.size() > 2){
310 AttendeeDataTokens = TestJournal.AttendeeListTokens[2];
314 ASSERT_EQ("Attendee Three", AttendeeData);
315 ASSERT_EQ("null:nodata", AttendeeDataDirectoryEntry);
316 ASSERT_EQ("mailto:sent.by@example.com", AttendeeDataSentBy);
317 ASSERT_EQ("Attendee The Third", AttendeeDataCommonName);
318 ASSERT_EQ("INDIVIDUAL", AttendeeDataCalendarUserType);
319 ASSERT_EQ("ACCEPTED", AttendeeDataParticipationStatus);
320 ASSERT_EQ("kw", AttendeeDataLanguage);
321 ASSERT_EQ("EXAMPLE=DATA", AttendeeDataTokens);
323 // Get the first CATEGORIES.
325 std::string CategoryData;
327 if (TestJournal.CategoriesList.begin() != TestJournal.CategoriesList.end()){
329 CategoryData = TestJournal.CategoriesList[0];
333 ASSERT_EQ("CATEGORY ONE, CATEGORY TWO", CategoryData);
335 CategoryData.clear();
337 std::string CategoryLanguage;
339 // Get the second CATEGORIES.
341 if (TestJournal.CategoriesList.size() > 1){
343 CategoryData = TestJournal.CategoriesList[1];
347 if (TestJournal.CategoriesList.size() > 1){
349 CategoryLanguage = TestJournal.CategoriesListLanguage[1];
353 ASSERT_EQ("CATEGORY THREE, CATEGORY FOUR", CategoryData);
354 ASSERT_EQ("en", CategoryLanguage);
356 CategoryData.clear();
357 CategoryLanguage.clear();
359 // Get the third CATEGORIES.
361 std::string CategoryTokens;
363 if (TestJournal.CategoriesList.size() > 2){
365 CategoryData = TestJournal.CategoriesList[2];
369 if (TestJournal.CategoriesList.size() > 2){
371 CategoryLanguage = TestJournal.CategoriesListLanguage[2];
375 if (TestJournal.CategoriesList.size() > 2){
377 CategoryTokens = TestJournal.CategoriesListTokens[2];
381 ASSERT_EQ("CATEGORY FIVE, CATEGORY SIX, CATEGORY SEVEN", CategoryData);
382 ASSERT_EQ("en-GB", CategoryLanguage);
383 ASSERT_EQ("SAMPLE=TOKEN", CategoryTokens);
385 // Get the first COMMENT.
387 std::string CommentData;
389 if (TestJournal.CommentList.begin() != TestJournal.CommentList.end()){
391 CommentData = TestJournal.CommentList[0];
395 ASSERT_EQ("This is the first comment.", CommentData);
397 // Get the second COMMENT.
401 std::string CommentDataAltRep;
402 std::string CommentDataLanguage;
404 if (TestJournal.CommentList.size() > 1){
406 CommentData = TestJournal.CommentList[1];
410 if (TestJournal.CommentList.size() > 1){
412 CommentDataAltRep = TestJournal.CommentListAltRep[1];
416 if (TestJournal.CommentList.size() > 1){
418 CommentDataLanguage = TestJournal.CommentListLanguage[1];
422 ASSERT_EQ("This is the second comment.", CommentData);
423 ASSERT_EQ("null:nodata", CommentDataAltRep);
424 ASSERT_EQ("en", CommentDataLanguage);
426 // Get the third COMMENT.
430 std::string CommentDataTokens;
432 if (TestJournal.CommentList.size() > 2){
434 CommentData = TestJournal.CommentList[2];
438 if (TestJournal.CommentList.size() > 2){
440 CommentDataTokens = TestJournal.CommentListTokens[2];
444 ASSERT_EQ("This is the third comment.", CommentData);
445 ASSERT_EQ("ZEBRAS=YES", CommentDataTokens);
447 // Get the first CONTACT.
449 std::string ContactData;
451 if (TestJournal.ContactList.begin() != TestJournal.ContactList.end()){
453 ContactData = TestJournal.ContactList[0];
457 ASSERT_EQ("First Contact", ContactData);
459 // Get the second CONTACT.
463 std::string ContactDataAltRep;
464 std::string ContactDataLanguage;
466 if (TestJournal.ContactList.size() > 1){
468 ContactData = TestJournal.ContactList[1];
472 if (TestJournal.ContactList.size() > 1){
474 ContactDataAltRep = TestJournal.ContactListAltRep[1];
478 if (TestJournal.ContactList.size() > 1){
480 ContactDataLanguage = TestJournal.ContactListLanguage[1];
484 ASSERT_EQ("Second Contact", ContactData);
485 ASSERT_EQ("null:nodata", ContactDataAltRep);
486 ASSERT_EQ("en-GB", ContactDataLanguage);
488 // Get the third CONTACT.
492 std::string ContactDataTokens;
494 if (TestJournal.ContactList.size() > 2){
496 ContactData = TestJournal.ContactList[2];
500 if (TestJournal.ContactList.size() > 2){
502 ContactDataTokens = TestJournal.ContactListTokens[2];
506 ASSERT_EQ("Third Contact", ContactData);
507 ASSERT_EQ("ZEBRAS=NO", ContactDataTokens);
509 // Get the first DESCRIPTION.
511 std::string DescriptionData;
513 if (TestJournal.DescriptionList.begin() != TestJournal.DescriptionList.end()){
515 DescriptionData = TestJournal.DescriptionList[0];
519 ASSERT_EQ("First Journal Entry Description", DescriptionData);
521 // Get the second DESCRIPTION.
523 DescriptionData.clear();
525 std::string DescriptionAltRep;
526 std::string DescriptionLanguage;
528 if (TestJournal.DescriptionList.size() > 1){
530 DescriptionData = TestJournal.DescriptionList[1];
534 if (TestJournal.DescriptionList.size() > 1){
536 DescriptionAltRep = TestJournal.DescriptionListAltRep[1];
540 if (TestJournal.DescriptionList.size() > 1){
542 DescriptionLanguage = TestJournal.DescriptionListLanguage[1];
546 ASSERT_EQ("This is the second journal description.", DescriptionData);
547 ASSERT_EQ("null:nodata", DescriptionAltRep);
548 ASSERT_EQ("en-GB", DescriptionLanguage);
550 // Get the third DESCRIPTION.
552 DescriptionData.clear();
554 std::string DescriptionDataTokens;
556 if (TestJournal.DescriptionList.size() > 2){
558 DescriptionData = TestJournal.DescriptionList[2];
562 if (TestJournal.DescriptionList.size() > 2){
564 DescriptionDataTokens = TestJournal.DescriptionListTokens[2];
568 ASSERT_EQ("This is the third journal description.", DescriptionData);
569 ASSERT_EQ("ZEBRAS=NO", DescriptionDataTokens);