Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Disable unit tests to be fixed in a future version
[xestiacalendar/.git] / source / tests / xestiacalendar_populate.cpp
1 // xestiacalendar_populate.cpp - Xestia Calendar Unit Testing Suite Populate Functions
2 //
3 // (c) 2016-2017 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
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.
10 //
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.
15 //
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/> 
18  
19 #include "xestiacalendar_populate.h"
20  
21 void populatecaldav(){
22         
23         CalDAV populateCalDAV;
24         
25         // Load the connection settings.
26         
27         CalDAVConnectionData connNormal;
28         ProcessConnectionDataFileResult dataFileResult;
29         bool validDataNormal = false;
30         
31         dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
32         if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
33                 validDataNormal = true;
34         } else {
35                 
36                 // Cannot read the caldavtest.auth file properly.
37                 
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;
46                 
47         }
48         
49         // Connect to the server and create
50         // the calendar.
51         
52         string serverAddress = "";
53         string serverUserPass = "";
54         
55         // Setup the server address.
56         
57         string calendarName = "Unit Testing Calendar";
58         string calendarShortName = "unittestcal";
59         
60         populateCalDAV.SetupConnectionData(&connNormal);
61         
62         CalDAVServerResult serverResult;
63         
64         serverResult = populateCalDAV.Connect();
65         
66         if (serverResult.code != CURLE_OK){
67                 
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;
72                 return;
73                 
74         }
75         
76         // Get the list of calendars.
77         
78         CalDAVCalendarList calendarList = populateCalDAV.GetCalendars();
80         if (calendarList.name.size() == 0){
81                 
82                 cout << "Error while getting the list of calendars." << endl;
83                 return;
84                 
85         }
86         
87         string calendarURI = "";
89         // Look for the Unit testing calendar.
90         
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;
96                         break;
97                 }
98         
99         }
100         
101         if (calendarURI == ""){
102                 
103                 cout << "Error while getting the unit testing calendar URI" << endl;
104                 return;
105                 
106         }
107         
108         // Delete the previous calendar.
109         
110         serverResult = populateCalDAV.DeleteCalendar(&calendarURI);
111         
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;
118                 return;
119                 
120         }
121         
122         // Create the calendar.
123         
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;
132                 return;
133                 
134         }
135         
136         // Get the list of calendars with the new calendar added.
137         
138         calendarList = populateCalDAV.GetCalendars();
140         if (calendarList.name.size() == 0){
141                 
142                 cout << "Error while getting the list of calendars." << endl;
143                 return;
144                 
145         }
147         calendarURI = "";
149         // Look for the Unit testing calendar.
150         
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;
156                         break;
157                 }
158         
159         }
160         
161         if (calendarURI == ""){
162                 
163                 cout << "Error while getting the unit testing calendar URI" << endl;
164                 return;
165                 
166         }
167         
168         // Create five entries.
169         
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] = { 
173                 
174                 "BEGIN:VCALENDAR\n"
175                 "VERSION:2.0\n"
176                 "PRODID:-//Xestia//Calendar Unit Testing Application//KW\n"
177                 "BEGIN:VEVENT\n"
178                 "UID:XC-UT1\n"
179                 "DTSTAMP:20160116T190200Z\n"
180                 "DTSTART:20160116T190200Z\n"
181                 "DTEND:20160116T190200Z\n"
182                 "SUMMARY: Xestia Calendar Unit Test Event 1\n"
183                 "END:VEVENT\n"
184                 "END:VCALENDAR\n",
185                 
186                 "BEGIN:VCALENDAR\n"
187                 "VERSION:2.0\n"
188                 "PRODID:-//Xestia//Calendar Unit Testing Application//KW\n"
189                 "BEGIN:VEVENT\n"
190                 "UID:XC-UT2\n"
191                 "DTSTAMP:20160116T190200Z\n"
192                 "DTSTART:20160116T190200Z\n"
193                 "DTEND:20160116T190200Z\n"
194                 "SUMMARY: Xestia Calendar Unit Test Event 2\n"
195                 "END:VEVENT\n"
196                 "END:VCALENDAR",
197                 
198                 "BEGIN:VCALENDAR\n"
199                 "VERSION:2.0\n"
200                 "PRODID:-//Xestia//Calendar Unit Testing Application//KW\n"
201                 "BEGIN:VEVENT\n"
202                 "UID:XC-UT3\n"
203                 "DTSTAMP:20160116T190200Z\n"
204                 "DTSTART:20160116T190200Z\n"
205                 "DTEND:20160116T190200Z\n"
206                 "SUMMARY: Xestia Calendar Unit Test Event 3\n"
207                 "END:VEVENT\n"
208                 "END:VCALENDAR",
209                 
210                 "BEGIN:VCALENDAR\n"
211                 "VERSION:2.0\n"
212                 "PRODID:-//Xestia//Calendar Unit Testing Application//KW\n"
213                 "BEGIN:VEVENT\n"
214                 "UID:XC-UT4\n"
215                 "DTSTAMP:20160116T190200Z\n"
216                 "DTSTART:20160116T190200Z\n"
217                 "DTEND:20160116T190200Z\n"
218                 "SUMMARY: Xestia Calendar Unit Test Event 4\n"
219                 "END:VEVENT\n"
220                 "END:VCALENDAR",
221                 
222                 "BEGIN:VCALENDAR\n"
223                 "VERSION:2.0\n"
224                 "PRODID:-//Xestia//Calendar Unit Testing Application//KW\n"
225                 "BEGIN:VEVENT\n"
226                 "UID:XC-UT5\n"
227                 "DTSTAMP:20160116T190200Z\n"
228                 "DTSTART:20160116T190200Z\n"
229                 "DTEND:20160116T190200Z\n"
230                 "SUMMARY: Xestia Calendar Unit Test Event 5\n"
231                 "END:VEVENT\n"
232                 "END:VCALENDAR"
233                 
234         };
235         
236         // Place the entries into the calendar.
237         
238         string calendarEntryURI = "";
239         
240         for (int entrySeek = 0; entrySeek < 5; entrySeek++){
241                 
242                 calendarEntryURI = calendarURI;
243                 calendarEntryURI += entryFilename[entrySeek];
244                 
245                 serverResult = populateCalDAV.AddEntry(&calendarEntryURI, &entryData[entrySeek]);
246                 
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;
254                         return;
255                 
256                 }
257                 
258                 calendarEntryURI.clear();
259                 
260         }
261         
262         cout << "CalDAV calendar populating completed." << endl;
263         
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy