// xestiacalendar_populate.cpp - Xestia Calendar Unit Testing Suite Populate Functions
//
// (c) 2016 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;
}