// xestiacalendar_icaljournalload.h - Xestia Calendar iCalendar Journal Component Unit Tests // // (c) 2016-2017 Xestia Software Development. // // This file is part of Xestia Calendar. // // Xestia Calendar is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by the // Free Software Foundation, version 3 of the license. // // Xestia Calendar is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with Xestia Calendar. If not, see #include "CalendarJournal.h" #include class iCalendarJournalLoadTests : public ::testing::Test { private: virtual void SetUp() { } virtual void TearDown() { } }; TEST_F(iCalendarJournalLoadTests, BasicTests){ CalendarJournalObject testJournal; ASSERT_EQ(CALENDAROBJECTLOAD_MISSING, testJournal.LoadFile("iCalendarJournal-Missing.vcf")); ASSERT_EQ(CALENDAROBJECTLOAD_CANNOTOPEN, testJournal.LoadFile("iCalendarJournal-InvalidPermissions.vcf")); ASSERT_EQ(CALENDAROBJECTLOAD_OK, testJournal.LoadFile("iCalendarJournal-Load1.vcf")); } TEST_F(iCalendarJournalLoadTests, ObjectDataTests){ CalendarJournalObject testJournal; ASSERT_EQ(CALENDAROBJECTLOAD_OK, testJournal.LoadFile("iCalendarJournal-Load2.vcf")); ASSERT_EQ(CALENDAROBJECTVALID_OK, testJournal.ValidBaseObject()); // Tests for DTSTAMP. ASSERT_EQ("20160131T141500Z", testJournal.dateTimeStampData); ASSERT_EQ("OTHER=PARAM", testJournal.dateTimeStampTokens); // Tests for UID. ASSERT_EQ("b3a16392-ad86-4061-be53-c215af2306c1", testJournal.uniqueID); ASSERT_EQ("UNIQUEPARAM=CERTAINLY;OKAY=MAYBENOT", testJournal.uniqueIDTokens); // Tests for CLASS. ASSERT_EQ("PUBLIC", testJournal.classData); ASSERT_EQ("CHOCOLATE=BAR", testJournal.classDataTokens); // Tests for DTSTART. ASSERT_EQ("20160131T143500Z", testJournal.dateTimeStartData); ASSERT_EQ("DATE-TIME", testJournal.dateTimeStartDataValue); ASSERT_EQ("Europe/Truro", testJournal.dateTimeStartDataTimeZoneID); ASSERT_EQ("PARAMONE=YES;PARAMTWO=NO", testJournal.dateTimeStartDataTokens); // Tests for LAST-MODIFIED. ASSERT_EQ("20160131T143700Z", testJournal.lastModifiedData); ASSERT_EQ("FUTURE=YES", testJournal.lastModifiedTokens); // Tests for ORGANIZER. ASSERT_EQ("mailto:organiser@example.com", testJournal.organiserData); ASSERT_EQ("ExampleOrganiser", testJournal.organiserDataCommonName); ASSERT_EQ("null:nodata", testJournal.organiserDataDirectoryEntry); ASSERT_EQ("mailto:organiser.noreply@example.com", testJournal.organiserDataSentByParam); ASSERT_EQ("kw", testJournal.organiserDataLanguage); ASSERT_EQ("HAPPY=DAYS", testJournal.organiserDataTokens); // Tests for RECURRENCE-ID. ASSERT_EQ("20160131", testJournal.recurranceIDData); ASSERT_EQ("Europe/Truro", testJournal.recurranceIDDataTimeZoneParam); ASSERT_EQ("THISANDFUTURE", testJournal.recurranceIDDataRangeParam); ASSERT_EQ("DATE", testJournal.recurranceIDDataValue); ASSERT_EQ("EXAMPLE=DATA", testJournal.recurranceIDDataTokens); // Tests for SEQUENCE. ASSERT_EQ(7, testJournal.sequenceData); ASSERT_EQ("TEST=YAY", testJournal.sequenceTokens); // Tests for STATUS. ASSERT_EQ("2.0;Success", testJournal.statusData); ASSERT_EQ("kw", testJournal.statusLanguage); ASSERT_EQ("FAVOURITE=RICHTEA;NOTLIKE=UNKNOWN", testJournal.statusTokens); // Tests for SUMMARY. ASSERT_EQ("A summary of the journal entry.", testJournal.summaryData); ASSERT_EQ("null:nodata", testJournal.summaryDataAltRep); ASSERT_EQ("kw", testJournal.summaryDataLanguage); ASSERT_EQ("FAVOURITE=TOFU;NOTLIKE=NONE", testJournal.summaryDataTokens); // Tests for URL. ASSERT_EQ("http://www.example.com/", testJournal.urlData); ASSERT_EQ("EXTERNAL=YES", testJournal.urlDataTokens); // Tests for RRULE. ASSERT_EQ("FREQ=DAILY;COUNT=10", testJournal.recurranceRuleData); ASSERT_EQ("TEST=DATA", testJournal.recurranceRuleDataTokens); // Tests for ATTACH. First ATTACH property. std::string attachData; std::string attachDataFormatType; std::string attachDataValue; std::string attachDataEncoding; std::string attachDataTokens; if (testJournal.attachList.begin() != testJournal.attachList.end()){ attachData = testJournal.attachList[0]; } if (testJournal.attachListFormatType.begin() != testJournal.attachListFormatType.end()){ attachDataFormatType = testJournal.attachListFormatType[0]; } ASSERT_EQ("http://www.example.com/", attachData); ASSERT_EQ("application/internet-shortcut", attachDataFormatType); // Second ATTACH property. attachData.clear(); attachDataFormatType.clear(); attachDataValue.clear(); attachDataEncoding.clear(); if (testJournal.attachList.size() > 1){ attachData = testJournal.attachList[1]; } if (testJournal.attachListFormatType.size() > 1){ attachDataFormatType = testJournal.attachListFormatType[1]; } ASSERT_EQ("http://www.example.com/page2.html", attachData); ASSERT_EQ("application/internet-shortcut", attachDataFormatType); // Third ATTACH property. attachData.clear(); attachDataFormatType.clear(); attachDataValue.clear(); attachDataEncoding.clear(); attachDataTokens.clear(); if (testJournal.attachList.size() > 2){ attachData = testJournal.attachList[2]; } if (testJournal.attachListFormatType.size() > 2){ attachDataFormatType = testJournal.attachListFormatType[2]; } if (testJournal.attachListValue.size() > 2){ attachDataValue = testJournal.attachListValue[2]; } if (testJournal.attachListFormatType.size() > 2){ attachDataEncoding = testJournal.attachListEncoding[2]; } if (testJournal.attachListTokens.size() > 2){ attachDataTokens = testJournal.attachListTokens[2]; } ASSERT_EQ("VGhpcyBpcyBhbiBleGFtcGxlIGZpbGU=", attachData); ASSERT_EQ("text/plain", attachDataFormatType); ASSERT_EQ("BASE64", attachDataEncoding); ASSERT_EQ("BINARY", attachDataValue); ASSERT_EQ("STUPID=EXAMPLE", attachDataTokens); // Tests for ATTENDEE. First ATTENDEE property. std::string attendeeDataMember; std::string attendeeDataDelegatedFrom; std::string attendeeDataDelegatedTo; std::string attendeeDataRole; std::string attendeeDataRSVP; std::string attendeeDataDirectoryEntry; std::string attendeeDataSentBy; std::string attendeeDataCommonName; std::string attendeeDataCalendarUserType; std::string attendeeDataParticipationStatus; std::string attendeeDataLanguage; std::string attendeeDataTokens; std::string attendeeData; if (testJournal.attendeeList.begin() != testJournal.attendeeList.end()){ attendeeData = testJournal.attendeeList[0]; } ASSERT_EQ("Attendee One", attendeeData); // Second ATTENDEE property. attendeeData.clear(); if (testJournal.attendeeList.size() > 1){ attendeeData = testJournal.attendeeList[1]; } if (testJournal.attendeeList.size() > 1){ attendeeDataDelegatedFrom = testJournal.attendeeListDelegatedFrom[1]; } if (testJournal.attendeeList.size() > 1){ attendeeDataDelegatedTo = testJournal.attendeeListDelegatedTo[1]; } if (testJournal.attendeeList.size() > 1){ attendeeDataRole = testJournal.attendeeListRole[1]; } if (testJournal.attendeeList.size() > 1){ attendeeDataRSVP = testJournal.attendeeListRSVP[1]; } ASSERT_EQ("Attendee Two", attendeeData); ASSERT_EQ("mailto:delegated.from@example.com", attendeeDataDelegatedFrom); ASSERT_EQ("mailto:delegated.to@example.com", attendeeDataDelegatedTo); ASSERT_EQ("CHAIR", attendeeDataRole); ASSERT_EQ("TRUE", attendeeDataRSVP); // Third ATTENDEE property. attendeeData.clear(); if (testJournal.attendeeList.size() > 2){ attendeeData = testJournal.attendeeList[2]; } if (testJournal.attendeeList.size() > 2){ attendeeDataDirectoryEntry = testJournal.attendeeListDirectoryEntry[2]; } if (testJournal.attendeeList.size() > 2){ attendeeDataSentBy = testJournal.attendeeListSentBy[2]; } if (testJournal.attendeeList.size() > 2){ attendeeDataCommonName = testJournal.attendeeListCommonName[2]; } if (testJournal.attendeeList.size() > 2){ attendeeDataCalendarUserType = testJournal.attendeeListCalendarUserType[2]; } if (testJournal.attendeeList.size() > 2){ attendeeDataParticipationStatus = testJournal.attendeeListParticipationStatus[2]; } if (testJournal.attendeeList.size() > 2){ attendeeDataLanguage = testJournal.attendeeListLanguage[2]; } if (testJournal.attendeeList.size() > 2){ attendeeDataTokens = testJournal.attendeeListTokens[2]; } ASSERT_EQ("Attendee Three", attendeeData); ASSERT_EQ("null:nodata", attendeeDataDirectoryEntry); ASSERT_EQ("mailto:sent.by@example.com", attendeeDataSentBy); ASSERT_EQ("Attendee The Third", attendeeDataCommonName); ASSERT_EQ("INDIVIDUAL", attendeeDataCalendarUserType); ASSERT_EQ("ACCEPTED", attendeeDataParticipationStatus); ASSERT_EQ("kw", attendeeDataLanguage); ASSERT_EQ("EXAMPLE=DATA", attendeeDataTokens); // Get the first CATEGORIES. std::string categoryData; if (testJournal.categoriesList.begin() != testJournal.categoriesList.end()){ categoryData = testJournal.categoriesList[0]; } ASSERT_EQ("CATEGORY ONE, CATEGORY TWO", categoryData); categoryData.clear(); std::string categoryLanguage; // Get the second CATEGORIES. if (testJournal.categoriesList.size() > 1){ categoryData = testJournal.categoriesList[1]; } if (testJournal.categoriesList.size() > 1){ categoryLanguage = testJournal.categoriesListLanguage[1]; } ASSERT_EQ("CATEGORY THREE, CATEGORY FOUR", categoryData); ASSERT_EQ("en", categoryLanguage); categoryData.clear(); categoryLanguage.clear(); // Get the third CATEGORIES. std::string categoryTokens; if (testJournal.categoriesList.size() > 2){ categoryData = testJournal.categoriesList[2]; } if (testJournal.categoriesList.size() > 2){ categoryLanguage = testJournal.categoriesListLanguage[2]; } if (testJournal.categoriesList.size() > 2){ categoryTokens = testJournal.categoriesListTokens[2]; } ASSERT_EQ("CATEGORY FIVE, CATEGORY SIX, CATEGORY SEVEN", categoryData); ASSERT_EQ("en-GB", categoryLanguage); ASSERT_EQ("SAMPLE=TOKEN", categoryTokens); // Get the first COMMENT. std::string commentData; if (testJournal.commentList.begin() != testJournal.commentList.end()){ commentData = testJournal.commentList[0]; } ASSERT_EQ("This is the first comment.", commentData); // Get the second COMMENT. commentData.clear(); std::string commentDataAltRep; std::string commentDataLanguage; if (testJournal.commentList.size() > 1){ commentData = testJournal.commentList[1]; } if (testJournal.commentList.size() > 1){ commentDataAltRep = testJournal.commentListAltRep[1]; } if (testJournal.commentList.size() > 1){ commentDataLanguage = testJournal.commentListLanguage[1]; } ASSERT_EQ("This is the second comment.", commentData); ASSERT_EQ("null:nodata", commentDataAltRep); ASSERT_EQ("en", commentDataLanguage); // Get the third COMMENT. commentData.clear(); std::string commentDataTokens; if (testJournal.commentList.size() > 2){ commentData = testJournal.commentList[2]; } if (testJournal.commentList.size() > 2){ commentDataTokens = testJournal.commentListTokens[2]; } ASSERT_EQ("This is the third comment.", commentData); ASSERT_EQ("ZEBRAS=YES", commentDataTokens); // Get the first CONTACT. std::string contactData; if (testJournal.contactList.begin() != testJournal.contactList.end()){ contactData = testJournal.contactList[0]; } ASSERT_EQ("First Contact", contactData); // Get the second CONTACT. contactData.clear(); std::string contactDataAltRep; std::string contactDataLanguage; if (testJournal.contactList.size() > 1){ contactData = testJournal.contactList[1]; } if (testJournal.contactList.size() > 1){ contactDataAltRep = testJournal.contactListAltRep[1]; } if (testJournal.contactList.size() > 1){ contactDataLanguage = testJournal.contactListLanguage[1]; } ASSERT_EQ("Second Contact", contactData); ASSERT_EQ("null:nodata", contactDataAltRep); ASSERT_EQ("en-GB", contactDataLanguage); // Get the third CONTACT. contactData.clear(); std::string contactDataTokens; if (testJournal.contactList.size() > 2){ contactData = testJournal.contactList[2]; } if (testJournal.contactList.size() > 2){ contactDataTokens = testJournal.contactListTokens[2]; } ASSERT_EQ("Third Contact", contactData); ASSERT_EQ("ZEBRAS=NO", contactDataTokens); // Get the first DESCRIPTION. std::string descriptionData; if (testJournal.descriptionList.begin() != testJournal.descriptionList.end()){ descriptionData = testJournal.descriptionList[0]; } ASSERT_EQ("First Journal Entry Description", descriptionData); // Get the second DESCRIPTION. descriptionData.clear(); std::string descriptionAltRep; std::string descriptionLanguage; if (testJournal.descriptionList.size() > 1){ descriptionData = testJournal.descriptionList[1]; } if (testJournal.descriptionList.size() > 1){ descriptionAltRep = testJournal.descriptionListAltRep[1]; } if (testJournal.descriptionList.size() > 1){ descriptionLanguage = testJournal.descriptionListLanguage[1]; } ASSERT_EQ("This is the second journal description.", descriptionData); ASSERT_EQ("null:nodata", descriptionAltRep); ASSERT_EQ("en-GB", descriptionLanguage); // Get the third DESCRIPTION. descriptionData.clear(); std::string descriptionDataTokens; if (testJournal.descriptionList.size() > 2){ descriptionData = testJournal.descriptionList[2]; } if (testJournal.descriptionList.size() > 2){ descriptionDataTokens = testJournal.descriptionListTokens[2]; } ASSERT_EQ("This is the third journal description.", descriptionData); ASSERT_EQ("ZEBRAS=NO", descriptionDataTokens); // Get the first EXDATE. std::string excludeDate; if (testJournal.excludeDateData.begin() != testJournal.excludeDateData.end()){ excludeDate = testJournal.excludeDateData[0]; } ASSERT_EQ("20160125T120000Z", excludeDate); // Get the second EXDATE. excludeDate.clear(); std::string excludeDataTimeZoneParam; std::string excludeDataValue; if (testJournal.contactList.size() > 1){ excludeDate = testJournal.excludeDateData[1]; } if (testJournal.contactList.size() > 1){ excludeDataTimeZoneParam = testJournal.excludeDateDataTimeZoneParam[1]; } if (testJournal.contactList.size() > 1){ excludeDataValue = testJournal.excludeDateDataValue[1]; } ASSERT_EQ("20160125T130000Z", excludeDate); ASSERT_EQ("DATE-TIME", excludeDataValue); ASSERT_EQ("Europe/Truro", excludeDataTimeZoneParam); // Get the third EXDATE. excludeDate.clear(); std::string excludeDataTokens; if (testJournal.contactList.size() > 2){ excludeDate = testJournal.excludeDateData[2]; } if (testJournal.contactList.size() > 2){ excludeDataTokens = testJournal.excludeDateDataTokens[2]; } ASSERT_EQ("20160125T133000Z", excludeDate); ASSERT_EQ("ZOOP=ZIPPO", excludeDataTokens); // Get the first RELATED-TO. std::string relatedTo; if (testJournal.relatedToData.begin() != testJournal.relatedToData.end()){ relatedTo = testJournal.relatedToData[0]; } ASSERT_EQ("person.1@example.com", relatedTo); // Get the second RELATED-TO. relatedTo.clear(); std::string relatedToType; if (testJournal.relatedToData.size() > 1){ relatedTo = testJournal.relatedToData[1]; } if (testJournal.relatedToData.size() > 1){ relatedToType = testJournal.relatedToDataRelationType[1]; } ASSERT_EQ("person.2@example.com", relatedTo); ASSERT_EQ("PARENT", relatedToType); // Get the third RELATED-TO. relatedTo.clear(); std::string relatedToTokens; if (testJournal.relatedToData.size() > 2){ relatedTo = testJournal.relatedToData[2]; } if (testJournal.relatedToData.size() > 2){ relatedToTokens = testJournal.relatedToDataTokens[2]; } ASSERT_EQ("person.3@example.com", relatedTo); ASSERT_EQ("SCHOOL=MEETING", relatedToTokens); // Get the first RDATE. std::string recurrenceDate; if (testJournal.recurranceDateData.begin() != testJournal.recurranceDateData.end()){ recurrenceDate = testJournal.recurranceDateData[0]; } ASSERT_EQ("20160120", recurrenceDate); // Get the second RDATE. recurrenceDate.clear(); std::string recurrenceDateTimeZoneParam; std::string recurrenceDateValue; if (testJournal.recurranceDateData.size() > 1){ recurrenceDate = testJournal.recurranceDateData[1]; } if (testJournal.recurranceDateData.size() > 1){ recurrenceDateTimeZoneParam = testJournal.recurranceDateDataTimeZoneParam[1]; } if (testJournal.recurranceDateData.size() > 1){ recurrenceDateValue = testJournal.recurranceDateDataValue[1]; } ASSERT_EQ("20160121", recurrenceDate); ASSERT_EQ("DATE", recurrenceDateValue); ASSERT_EQ("Europe/Truro", recurrenceDateTimeZoneParam); // Get the third RDATE. recurrenceDate.clear(); std::string RecurrenceTokens; if (testJournal.recurranceDateData.size() > 2){ recurrenceDate = testJournal.recurranceDateData[2]; } if (testJournal.recurranceDateData.size() > 2){ RecurrenceTokens = testJournal.recurranceDateDataTokens[2]; } ASSERT_EQ("20160520", recurrenceDate); ASSERT_EQ("ZILCH=DATA", RecurrenceTokens); // Get the first REQUEST-STATUS. std::string requestStatus; if (testJournal.requestStatusData.begin() != testJournal.requestStatusData.end()){ requestStatus = testJournal.requestStatusData[0]; } ASSERT_EQ("2.0;Success", requestStatus); // Get the second REQUEST-STATUS. requestStatus.clear(); std::string requestLanguage; if (testJournal.contactList.size() > 1){ requestStatus = testJournal.requestStatusData[1]; } if (testJournal.contactList.size() > 1){ requestLanguage = testJournal.requestStatusLanguage[1]; } ASSERT_EQ("3.42;Really big irrecoverable error caused by the user", requestStatus); ASSERT_EQ("en", requestLanguage); // Get the third REQUEST-STATUS. requestStatus.clear(); std::string requestTokens; if (testJournal.contactList.size() > 2){ requestStatus = testJournal.requestStatusData[2]; } if (testJournal.contactList.size() > 2){ requestTokens = testJournal.requestStatusTokens[2]; } ASSERT_EQ("3.7;Invalid calendar user", requestStatus); ASSERT_EQ("USER=MISSING", requestTokens); // Get the first X-EXAMPLE1 token. std::string xTokenName; std::string xTokenData; if (testJournal.xTokensData.size() != 0 ){ xTokenData = testJournal.xTokensData[0]; } if (testJournal.xTokensData.size() != 0){ xTokenName = testJournal.xTokensDataTokens[0]; } ASSERT_EQ("Moo", xTokenData); ASSERT_EQ("X-EXAMPLE1", xTokenName); // Get the second X-EXAMPLE1 token. xTokenName.clear(); xTokenData.clear(); if (testJournal.xTokensData.size() > 1){ xTokenData = testJournal.xTokensData[1]; } if (testJournal.xTokensData.size() > 1){ xTokenName = testJournal.xTokensDataTokens[1]; } ASSERT_EQ("Meep", xTokenData); ASSERT_EQ("X-EXAMPLE1;ANIMAL=NOPE", xTokenName); // Get the third X-EXAMPLE1 token. xTokenName.clear(); xTokenData.clear(); if (testJournal.xTokensData.size() > 2){ xTokenData = testJournal.xTokensData[2]; } if (testJournal.xTokensData.size() > 2){ xTokenName = testJournal.xTokensDataTokens[2]; } ASSERT_EQ("Meow", xTokenData); ASSERT_EQ("X-EXAMPLE1;ANIMAL=CAT", xTokenName); // Get the first X-EXAMPLE2 token. xTokenName.clear(); xTokenData.clear(); if (testJournal.xTokensData.size() > 3){ xTokenData = testJournal.xTokensData[3]; } if (testJournal.xTokensData.size() > 3){ xTokenName = testJournal.xTokensDataTokens[3]; } ASSERT_EQ("Dish", xTokenData); ASSERT_EQ("X-EXAMPLE2", xTokenName); // Get the second X-EXAMPLE2 token. xTokenName.clear(); xTokenData.clear(); if (testJournal.xTokensData.size() > 4){ xTokenData = testJournal.xTokensData[4]; } if (testJournal.xTokensData.size() > 4){ xTokenName = testJournal.xTokensDataTokens[4]; } ASSERT_EQ("Fork", xTokenData); ASSERT_EQ("X-EXAMPLE2;OBJECT=KITCHEN", xTokenName); // Get the third X-EXAMPLE2 token. xTokenName.clear(); xTokenData.clear(); if (testJournal.xTokensData.size() > 5){ xTokenData = testJournal.xTokensData[5]; } if (testJournal.xTokensData.size() > 5){ xTokenName = testJournal.xTokensDataTokens[5]; } ASSERT_EQ("Table", xTokenData); ASSERT_EQ("X-EXAMPLE2;OBJECT=LIVINGROOM", xTokenName); // Get the X-STATUS token. xTokenName.clear(); xTokenData.clear(); if (testJournal.xTokensData.size() > 6){ xTokenData = testJournal.xTokensData[6]; } if (testJournal.xTokensData.size() > 6){ xTokenName = testJournal.xTokensDataTokens[6]; } ASSERT_EQ("Idle", xTokenData); ASSERT_EQ("X-STATUS;HOLIDAY=YES", xTokenName); // Get the X-TRANSPORT token. xTokenName.clear(); xTokenData.clear(); if (testJournal.xTokensData.size() > 7){ xTokenData = testJournal.xTokensData[7]; } if (testJournal.xTokensData.size() > 7){ xTokenName = testJournal.xTokensDataTokens[7]; } ASSERT_EQ("Private Hire", xTokenData); ASSERT_EQ("X-TRANSPORT;PUBLIC=NO", xTokenName); // Get the X-PHANTOM-STATUS token. xTokenName.clear(); xTokenData.clear(); if (testJournal.xTokensData.size() > 8){ xTokenData = testJournal.xTokensData[8]; } if (testJournal.xTokensData.size() > 8){ xTokenName = testJournal.xTokensDataTokens[8]; } ASSERT_EQ("None", xTokenData); ASSERT_EQ("X-PHANTOM-STATUS;HELP=NONE", xTokenName); }