// xestiacalendar_populate.cpp - Xestia Calendar Unit Testing Suite Populate Functions // // (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 "xestiacalendar_populate.h" void populatecaldav(){ CalDAV populateCalDAV; // Load the connection settings. CalDAVConnectionData connNormal; ProcessConnectionDataFileResult dataFileResult; bool validDataNormal = false; dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal); if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){ validDataNormal = true; } else { // Cannot read the caldavtest.auth file properly. cout << "The caldavtest.auth file does not exist or is invalid!" << endl; cout << "Please create the caldavtest.auth file using the following format:" << endl << endl; cout << "server=localname" << endl; cout << "port=8080" << endl; cout << "user=username" << endl; cout << "pass=password" << endl; cout << "ssl=false" << endl; cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl; } // Connect to the server and create // the calendar. string serverAddress = ""; string serverUserPass = ""; // Setup the server address. string calendarName = "Unit Testing Calendar"; string calendarShortName = "unittestcal"; populateCalDAV.SetupConnectionData(&connNormal); CalDAVServerResult serverResult; serverResult = populateCalDAV.Connect(); if (serverResult.code != CURLE_OK){ cout << "Error while connecting to the CalDAV server." << endl; cout << "Xestia Calendar Code: " << serverResult.result << endl; cout << "cURL Code: " << serverResult.code << endl; cout << "HTTP Code: " << serverResult.httpCode << endl; return; } // Get the list of calendars. CalDAVCalendarList calendarList = populateCalDAV.GetCalendars(); if (calendarList.name.size() == 0){ cout << "Error while getting the list of calendars." << endl; return; } string calendarURI = ""; // Look for the Unit testing calendar. for (std::map::iterator calNameIter = calendarList.name.begin(); calNameIter != calendarList.name.end(); calNameIter++){ if (calNameIter->second == "Unit Testing Calendar"){ calendarURI = calendarList.href.find(calNameIter->first)->second; break; } } if (calendarURI == ""){ cout << "Error while getting the unit testing calendar URI" << endl; return; } // Delete the previous calendar. serverResult = populateCalDAV.DeleteCalendar(&calendarURI); if (serverResult.code != CURLE_OK){ cout << "Error while deleting a calendar." << endl; cout << "Xestia Calendar Code: " << serverResult.result << endl; cout << "cURL Code: " << serverResult.code << endl; cout << "HTTP Code: " << serverResult.httpCode << endl; return; } // Create the calendar. serverResult = populateCalDAV.AddCalendar(&calendarName, &calendarShortName); if (serverResult.code != CURLE_OK){ cout << "Error while adding a calendar." << endl; cout << "Xestia Calendar Code: " << serverResult.result << endl; cout << "cURL Code: " << serverResult.code << endl; cout << "HTTP Code: " << serverResult.httpCode << endl; return; } // Get the list of calendars with the new calendar added. calendarList = populateCalDAV.GetCalendars(); if (calendarList.name.size() == 0){ cout << "Error while getting the list of calendars." << endl; return; } calendarURI = ""; // Look for the Unit testing calendar. for (std::map::iterator calNameIter = calendarList.name.begin(); calNameIter != calendarList.name.end(); calNameIter++){ if (calNameIter->second == "Unit Testing Calendar"){ calendarURI = calendarList.href.find(calNameIter->first)->second; break; } } if (calendarURI == ""){ cout << "Error while getting the unit testing calendar URI" << endl; return; } // Create five entries. string entryUUIDs[5] = { "XC-UT1", "XC-UT2", "XC-UT3", "XC-UT4", "XC-UT5" }; string entryFilename[5] = { "xc-ut1.ics", "xc-ut2.ics", "xc-ut3.ics", "xc-ut4.ics", "xc-ut5.ics" }; string entryData[5] = { "BEGIN:VCALENDAR\n" "VERSION:2.0\n" "PRODID:-//Xestia//Calendar Unit Testing Application//KW\n" "BEGIN:VEVENT\n" "UID:XC-UT1\n" "DTSTAMP:20160116T190200Z\n" "DTSTART:20160116T190200Z\n" "DTEND:20160116T190200Z\n" "SUMMARY: Xestia Calendar Unit Test Event 1\n" "END:VEVENT\n" "END:VCALENDAR\n", "BEGIN:VCALENDAR\n" "VERSION:2.0\n" "PRODID:-//Xestia//Calendar Unit Testing Application//KW\n" "BEGIN:VEVENT\n" "UID:XC-UT2\n" "DTSTAMP:20160116T190200Z\n" "DTSTART:20160116T190200Z\n" "DTEND:20160116T190200Z\n" "SUMMARY: Xestia Calendar Unit Test Event 2\n" "END:VEVENT\n" "END:VCALENDAR", "BEGIN:VCALENDAR\n" "VERSION:2.0\n" "PRODID:-//Xestia//Calendar Unit Testing Application//KW\n" "BEGIN:VEVENT\n" "UID:XC-UT3\n" "DTSTAMP:20160116T190200Z\n" "DTSTART:20160116T190200Z\n" "DTEND:20160116T190200Z\n" "SUMMARY: Xestia Calendar Unit Test Event 3\n" "END:VEVENT\n" "END:VCALENDAR", "BEGIN:VCALENDAR\n" "VERSION:2.0\n" "PRODID:-//Xestia//Calendar Unit Testing Application//KW\n" "BEGIN:VEVENT\n" "UID:XC-UT4\n" "DTSTAMP:20160116T190200Z\n" "DTSTART:20160116T190200Z\n" "DTEND:20160116T190200Z\n" "SUMMARY: Xestia Calendar Unit Test Event 4\n" "END:VEVENT\n" "END:VCALENDAR", "BEGIN:VCALENDAR\n" "VERSION:2.0\n" "PRODID:-//Xestia//Calendar Unit Testing Application//KW\n" "BEGIN:VEVENT\n" "UID:XC-UT5\n" "DTSTAMP:20160116T190200Z\n" "DTSTART:20160116T190200Z\n" "DTEND:20160116T190200Z\n" "SUMMARY: Xestia Calendar Unit Test Event 5\n" "END:VEVENT\n" "END:VCALENDAR" }; // Place the entries into the calendar. string calendarEntryURI = ""; for (int entrySeek = 0; entrySeek < 5; entrySeek++){ calendarEntryURI = calendarURI; calendarEntryURI += entryFilename[entrySeek]; serverResult = populateCalDAV.AddEntry(&calendarEntryURI, &entryData[entrySeek]); if (serverResult.code != CURLE_OK){ cout << "Error while adding an entry to the unit testing calendar." << endl; cout << "Xestia Calendar Code: " << serverResult.result << endl; cout << "cURL Code: " << serverResult.code << endl; cout << "HTTP Code: " << serverResult.httpCode << endl; cout << "URI address: " << calendarEntryURI << endl; return; } calendarEntryURI.clear(); } cout << "CalDAV calendar populating completed." << endl; }