From e242b4367fc5b62a2eab2d6c52529bf6fbd9546c Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Thu, 9 Jun 2016 22:04:12 +0100 Subject: [PATCH] Added TZID property for saving data from a CalendarTaskObject. Added the code and unit tests for the TZID property. --- .../CalendarTimezone-Save.cpp | 42 +++++++++++++++++++ .../calendartimezone/CalendarTimezone.h | 1 + .../tests/xestiacalendar_icaltimezonesave.h | 18 ++++++++ 3 files changed, 61 insertions(+) create mode 100644 source/objects/calendartimezone/CalendarTimezone-Save.cpp diff --git a/source/objects/calendartimezone/CalendarTimezone-Save.cpp b/source/objects/calendartimezone/CalendarTimezone-Save.cpp new file mode 100644 index 0000000..2bdadff --- /dev/null +++ b/source/objects/calendartimezone/CalendarTimezone-Save.cpp @@ -0,0 +1,42 @@ +#include "CalendarTimezone.h" + +using namespace std; + +void CalendarTimezoneObject::SaveObjectData(string *SaveData){ + + string DataLine = ""; + string DataLineProcessed = ""; + + *SaveData += "BEGIN:VTIMEZONE\n"; + + // Process the TZID. + + if (TimeZoneData.size() > 0){ + + if (TimeZoneDataTokens.size() > 0){ + + DataLine += "TZID;"; + DataLine += TimeZoneDataTokens; + + } else { + + DataLine += "TZID"; + + } + + DataLine += ":"; + DataLine += TimeZoneData; + DataLine += "\n"; + + DataLineProcessed = OutputText(&DataLine); + + *SaveData += DataLineProcessed; + + DataLine.clear(); + DataLineProcessed.clear(); + + } + + *SaveData += "END:VTIMEZONE\n"; + +} \ No newline at end of file diff --git a/source/objects/calendartimezone/CalendarTimezone.h b/source/objects/calendartimezone/CalendarTimezone.h index be3b176..21b9b69 100644 --- a/source/objects/calendartimezone/CalendarTimezone.h +++ b/source/objects/calendartimezone/CalendarTimezone.h @@ -51,6 +51,7 @@ class CalendarTimezoneObject: public CalendarObject{ void ProcessData(); void ProcessStandardDaylight(); + void SaveObjectData(string *SaveData); }; diff --git a/source/tests/xestiacalendar_icaltimezonesave.h b/source/tests/xestiacalendar_icaltimezonesave.h index 1cfd595..0bc4a3b 100644 --- a/source/tests/xestiacalendar_icaltimezonesave.h +++ b/source/tests/xestiacalendar_icaltimezonesave.h @@ -27,6 +27,24 @@ TEST(iCalendarSaveTimezone, SaveTimezoneTests){ ASSERT_EQ(CALENDAROBJECTLOAD_OK, TestTimezone.LoadFile("iCalendarTimezone-Load1.vcf")); ASSERT_EQ(CALENDAROBJECTVALID_OK, TestTimezone.ValidBaseObject()); + ASSERT_EQ(CALENDAROBJECTSAVE_CANNOTOPEN, TestTimezone.SaveFile("/stupidfilelocation/dontsavehere.ics")); + // Save the data to a string and compare the data. + + // First contact file. + + std::string SaveDataComparison = "BEGIN:VCALENDAR\n" + "VERSION:2.0\n" + "PRODID:-//Xestia//Calendar Unit Testing//KW\n" + "BEGIN:VTIMEZONE\n" + "TZID:Example/Starrgazy\n" + "END:VTIMEZONE\n" + "END:VCALENDAR"; + + std::string SaveData; + + TestTimezone.SaveString(&SaveData); + + ASSERT_EQ(SaveDataComparison, SaveData); } \ No newline at end of file -- 2.39.5