1 // xestiacalendar_populate.cpp - Xestia Calendar Unit Testing Suite Populate Functions
3 // (c) 2016-2017 Xestia Software Development.
5 // This file is part of Xestia Calendar.
7 // Xestia Calendar 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 Calendar 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 "xestiacalendar_populate.h"
21 void populatecaldav(){
23 CalDAV populateCalDAV;
25 // Load the connection settings.
27 CalDAVConnectionData connNormal;
28 ProcessConnectionDataFileResult dataFileResult;
29 bool validDataNormal = false;
31 dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
32 if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
33 validDataNormal = true;
36 // Cannot read the caldavtest.auth file properly.
38 cout << "The caldavtest.auth file does not exist or is invalid!" << endl;
39 cout << "Please create the caldavtest.auth file using the following format:" << endl << endl;
40 cout << "server=localname" << endl;
41 cout << "port=8080" << endl;
42 cout << "user=username" << endl;
43 cout << "pass=password" << endl;
44 cout << "ssl=false" << endl;
45 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
49 // Connect to the server and create
52 string serverAddress = "";
53 string serverUserPass = "";
55 // Setup the server address.
57 string calendarName = "Unit Testing Calendar";
58 string calendarShortName = "unittestcal";
60 populateCalDAV.SetupConnectionData(&connNormal);
62 CalDAVServerResult serverResult;
64 serverResult = populateCalDAV.Connect();
66 if (serverResult.code != CURLE_OK){
68 cout << "Error while connecting to the CalDAV server." << endl;
69 cout << "Xestia Calendar Code: " << serverResult.result << endl;
70 cout << "cURL Code: " << serverResult.code << endl;
71 cout << "HTTP Code: " << serverResult.httpCode << endl;
76 // Get the list of calendars.
78 CalDAVCalendarList calendarList = populateCalDAV.GetCalendars();
80 if (calendarList.name.size() == 0){
82 cout << "Error while getting the list of calendars." << endl;
87 string calendarURI = "";
89 // Look for the Unit testing calendar.
91 for (std::map<int,string>::iterator calNameIter = calendarList.name.begin();
92 calNameIter != calendarList.name.end(); calNameIter++){
94 if (calNameIter->second == "Unit Testing Calendar"){
95 calendarURI = calendarList.href.find(calNameIter->first)->second;
101 if (calendarURI == ""){
103 cout << "Error while getting the unit testing calendar URI" << endl;
108 // Delete the previous calendar.
110 serverResult = populateCalDAV.DeleteCalendar(&calendarURI);
112 if (serverResult.code != CURLE_OK){
114 cout << "Error while deleting a calendar." << endl;
115 cout << "Xestia Calendar Code: " << serverResult.result << endl;
116 cout << "cURL Code: " << serverResult.code << endl;
117 cout << "HTTP Code: " << serverResult.httpCode << endl;
122 // Create the calendar.
124 serverResult = populateCalDAV.AddCalendar(&calendarName, &calendarShortName);
126 if (serverResult.code != CURLE_OK){
128 cout << "Error while adding a calendar." << endl;
129 cout << "Xestia Calendar Code: " << serverResult.result << endl;
130 cout << "cURL Code: " << serverResult.code << endl;
131 cout << "HTTP Code: " << serverResult.httpCode << endl;
136 // Get the list of calendars with the new calendar added.
138 calendarList = populateCalDAV.GetCalendars();
140 if (calendarList.name.size() == 0){
142 cout << "Error while getting the list of calendars." << endl;
149 // Look for the Unit testing calendar.
151 for (std::map<int,string>::iterator calNameIter = calendarList.name.begin();
152 calNameIter != calendarList.name.end(); calNameIter++){
154 if (calNameIter->second == "Unit Testing Calendar"){
155 calendarURI = calendarList.href.find(calNameIter->first)->second;
161 if (calendarURI == ""){
163 cout << "Error while getting the unit testing calendar URI" << endl;
168 // Create five entries.
170 string entryUUIDs[5] = { "XC-UT1", "XC-UT2", "XC-UT3", "XC-UT4", "XC-UT5" };
171 string entryFilename[5] = { "xc-ut1.ics", "xc-ut2.ics", "xc-ut3.ics", "xc-ut4.ics", "xc-ut5.ics" };
172 string entryData[5] = {
176 "PRODID:-//Xestia//Calendar Unit Testing Application//KW\n"
179 "DTSTAMP:20160116T190200Z\n"
180 "DTSTART:20160116T190200Z\n"
181 "DTEND:20160116T190200Z\n"
182 "SUMMARY: Xestia Calendar Unit Test Event 1\n"
188 "PRODID:-//Xestia//Calendar Unit Testing Application//KW\n"
191 "DTSTAMP:20160116T190200Z\n"
192 "DTSTART:20160116T190200Z\n"
193 "DTEND:20160116T190200Z\n"
194 "SUMMARY: Xestia Calendar Unit Test Event 2\n"
200 "PRODID:-//Xestia//Calendar Unit Testing Application//KW\n"
203 "DTSTAMP:20160116T190200Z\n"
204 "DTSTART:20160116T190200Z\n"
205 "DTEND:20160116T190200Z\n"
206 "SUMMARY: Xestia Calendar Unit Test Event 3\n"
212 "PRODID:-//Xestia//Calendar Unit Testing Application//KW\n"
215 "DTSTAMP:20160116T190200Z\n"
216 "DTSTART:20160116T190200Z\n"
217 "DTEND:20160116T190200Z\n"
218 "SUMMARY: Xestia Calendar Unit Test Event 4\n"
224 "PRODID:-//Xestia//Calendar Unit Testing Application//KW\n"
227 "DTSTAMP:20160116T190200Z\n"
228 "DTSTART:20160116T190200Z\n"
229 "DTEND:20160116T190200Z\n"
230 "SUMMARY: Xestia Calendar Unit Test Event 5\n"
236 // Place the entries into the calendar.
238 string calendarEntryURI = "";
240 for (int entrySeek = 0; entrySeek < 5; entrySeek++){
242 calendarEntryURI = calendarURI;
243 calendarEntryURI += entryFilename[entrySeek];
245 serverResult = populateCalDAV.AddEntry(&calendarEntryURI, &entryData[entrySeek]);
247 if (serverResult.code != CURLE_OK){
249 cout << "Error while adding an entry to the unit testing calendar." << endl;
250 cout << "Xestia Calendar Code: " << serverResult.result << endl;
251 cout << "cURL Code: " << serverResult.code << endl;
252 cout << "HTTP Code: " << serverResult.httpCode << endl;
253 cout << "URI address: " << calendarEntryURI << endl;
258 calendarEntryURI.clear();
262 cout << "CalDAV calendar populating completed." << endl;