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;