Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added code and unit tests for deleting entries in the CalDAV object
[xestiacalendar/.git] / source / tests / xestiacalendar_caldav.h
1 // xestiacalendar_caldav.h - Xestia Calendar CalDAV Object Unit Tests
2 //
3 // (c) 2016 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
7 // Xestia Address Book 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 Address Book 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/>
19 #include "../objects/CalDAV/CalDAV.h"
20 #include "xestiacalendar_testcommon.h"
21 #include <iostream>
22 #include <map>
24 using namespace std;
25 string EntryCalendarHREFProcessing = "";
27 TEST(CalDAV, BasicTests){
29         CalDAVConnectionData ConnPlain;
30         CalDAVConnectionData ConnNormal;
31         CalDAVConnectionData ConnInvalidSSL;
32         CalDAVConnectionData ConnTimeout;
33         ProcessConnectionDataFileResult DataFileResult;
35         bool ValidDataPlain = false;
36         bool ValidDataNormal = false;
37         bool ValidDataInvalidSSL = false;
38         bool ValidDataTimeout = false;
40         // Attempt to read the caldavtest-plain.auth file.
41         
42         DataFileResult = ProcessConnectionDataFile("caldavtest-plain.auth", &ConnPlain);
43         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
44                 ValidDataPlain = true;
45         }
46         
47         // Attempt to read the caldavtest.auth file.
49         DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
50         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
51                 ValidDataNormal = true;
52         }
53         
54         // Attempt to read the caldavtest-fail.auth file.
55         
56         DataFileResult = ProcessConnectionDataFile("caldavtest-fail.auth", &ConnInvalidSSL);
57         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
58                 ValidDataInvalidSSL = true;
59         }
60         
61         // Attempt to read the caldavtest-timeout.auth file.
62         
63         DataFileResult = ProcessConnectionDataFile("caldavtest-timeout.auth", &ConnTimeout);
64         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
65                 ValidDataTimeout = true;
66         }
68         if (ValidDataPlain == false){
69         
70                 // Cannot read the caldavtest-plain.auth file properly.
71                 
72                 cout << "The caldavtest-plain.auth file does not exist or is invalid!" << endl;
73                 cout << "Please create the caldavtest-plain.auth file using the following format:" << endl << endl;
74                 cout << "server=localname" << endl;
75                 cout << "port=8080" << endl;
76                 cout << "user=username" << endl;
77                 cout << "pass=password" << endl;
78                 cout << "ssl=false" << endl;
79                 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
80                 
81         }
82         
83         if (ValidDataNormal == false){
84         
85                 // Cannot read the caldavtest.auth file properly.
86                 
87                 cout << "The caldavtest.auth file does not exist or is invalid!" << endl;
88                 cout << "Please create the caldavtest.auth file using the following format:" << endl << endl;
89                 cout << "server=localname" << endl;
90                 cout << "port=8080" << endl;
91                 cout << "user=username" << endl;
92                 cout << "pass=password" << endl;
93                 cout << "ssl=false" << endl;
94                 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
95                 
96         }
97         
98         if (ValidDataInvalidSSL == false){
99         
100                 // Cannot read the caldavtest-fail.auth file properly.
101                 
102                 cout << "The caldavtest-fail.auth file does not exist or is invalid!" << endl;
103                 cout << "Please create the caldavtest-fail.auth file using the following format:" << endl << endl;
104                 cout << "server=fail.localname" << endl;
105                 cout << "port=8080" << endl;
106                 cout << "user=username" << endl;
107                 cout << "pass=password" << endl;
108                 cout << "ssl=false" << endl;
109                 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
110                 
111         }
112         
113         if (ValidDataTimeout == false){
114         
115                 // Cannot read the caldavtest-timeout.auth file properly.
116                 
117                 cout << "The caldavtest-timeout.auth file does not exist or is invalid!" << endl;
118                 cout << "Please create the caldavtest-timeout.auth file using the following format:" << endl << endl;
119                 cout << "server=fail.localname" << endl;
120                 cout << "port=8080" << endl;
121                 cout << "user=username" << endl;
122                 cout << "pass=password" << endl;
123                 cout << "ssl=false" << endl;
124                 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
125                 
126         }
127         
128         ASSERT_EQ(true, ValidDataPlain);
129         ASSERT_EQ(true, ValidDataNormal);
130         ASSERT_EQ(true, ValidDataInvalidSSL);
131         ASSERT_EQ(true, ValidDataTimeout);
133         // (*nix version) Setup an initial connection (just plain
134         // text).
135         
136         CalDAV CalDAVPlain;
137         CalDAVPlain.SetupConnectionData(&ConnPlain);
138         
139         // Verify that the settings match with the CalDAVConnectionData
140         // passed.
141         
142         CalDAVStatus CalDAVPlainStatus = CalDAVPlain.GetConnectionData();
143         
144         ASSERT_EQ(CalDAVPlainStatus.Hostname, ConnPlain.Hostname);
145         ASSERT_EQ(CalDAVPlainStatus.Username, ConnPlain.Username);
146         ASSERT_EQ(CalDAVPlainStatus.Port, ConnPlain.Port);
147         ASSERT_EQ(CalDAVPlainStatus.Prefix, ConnPlain.Prefix);
148         ASSERT_EQ(CalDAVPlainStatus.UseSSL, ConnPlain.UseSSL);
149         
150         // Verify that the connection was successful.
151         
152         CalDAVServerResult ConnResult = CalDAVPlain.Connect();
153         
154         ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
155         ASSERT_EQ(200, ConnResult.HTTPCode);
156         ASSERT_EQ(CURLE_OK, ConnResult.Code);
157         
158         // Do another connection and this time the connection should
159         // fail due to being an invalid host name.
160         
161         CalDAVConnectionData ConnPlainFail;
162         ConnPlainFail.Hostname = "server.invalid";
163         ConnPlainFail.Username = "fail";
164         ConnPlainFail.Password = "fail";
165         ConnPlainFail.Port = 80;
166         ConnPlainFail.UseSSL = false;
167         
168         // Setup the CalDAV connection object.
169         
170         CalDAV CalDAVPlainFail;
171         CalDAVPlainFail.SetupConnectionData(&ConnPlainFail);
172         
173         // Setup the CalDAVStatus object.
174         
175         CalDAVStatus CalDAVPlainFailStatus = CalDAVPlain.GetConnectionData();
176         
177         // Connect and fail.
178         
179         ConnResult = CalDAVPlainFail.Connect();
180         
181         ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, ConnResult.Result);
182         ASSERT_EQ(0, ConnResult.HTTPCode);
183         ASSERT_EQ(CURLE_COULDNT_RESOLVE_HOST, ConnResult.Code);
184         
185         // (*nix version) Setup an initial connection (with a valid
186         // SSL certificate).
188         CalDAV CalDAVNormal;
189         CalDAVNormal.SetupConnectionData(&ConnNormal);
191         // Verify that the settings match with the CalDAVConnectionData
192         // passed.
193         
194         CalDAVStatus CalDAVNormalStatus = CalDAVNormal.GetConnectionData();
195         
196         ASSERT_EQ(CalDAVNormalStatus.Hostname, ConnNormal.Hostname);
197         ASSERT_EQ(CalDAVNormalStatus.Username, ConnNormal.Username);
198         ASSERT_EQ(CalDAVNormalStatus.Port, ConnNormal.Port);
199         ASSERT_EQ(CalDAVNormalStatus.Prefix, ConnNormal.Prefix);
200         ASSERT_EQ(CalDAVNormalStatus.UseSSL, ConnNormal.UseSSL);
202         // Verify that the connection was successful (with a valid
203         // SSL certificate).
204         
205         ConnResult = CalDAVNormal.Connect();
206         
207         ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
208         ASSERT_EQ(200, ConnResult.HTTPCode);
209         ASSERT_EQ(CURLE_OK, ConnResult.Code);
210         
211         // (*nix version) Setup an initial connection on a server that
212         // will fail due to having an invalid SSL certificate.
214         CalDAV CalDAVInvalidSSL;
215         CalDAVInvalidSSL.SetupConnectionData(&ConnInvalidSSL);
217         // Verify that the settings match with the CalDAVConnectionData
218         // passed.
219         
220         CalDAVStatus CalDAVInvalidSSLStatus = CalDAVInvalidSSL.GetConnectionData();
221         
222         ASSERT_EQ(CalDAVInvalidSSLStatus.Hostname, ConnInvalidSSL.Hostname);
223         ASSERT_EQ(CalDAVInvalidSSLStatus.Username, ConnInvalidSSL.Username);
224         ASSERT_EQ(CalDAVInvalidSSLStatus.Port, ConnInvalidSSL.Port);
225         ASSERT_EQ(CalDAVInvalidSSLStatus.Prefix, ConnInvalidSSL.Prefix);
226         ASSERT_EQ(CalDAVInvalidSSLStatus.UseSSL, ConnInvalidSSL.UseSSL);
227         
228         // Verify that the connection had failed. (with an invalid
229         // SSL certificate).
230         
231         ConnResult = CalDAVInvalidSSL.Connect();
232         
233         ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, ConnResult.Result);
234         ASSERT_EQ(0, ConnResult.HTTPCode);
235         ASSERT_EQ(CURLE_SSL_CACERT, ConnResult.Code);
236         
237         // (*nix version) Setup an inital connection on a server where
238         // a timeout occurs.
239         
240         ConnTimeout.Timeout = 5;
241         
242         CalDAV CalDAVTimeout;
243         CalDAVTimeout.SetupConnectionData(&ConnTimeout);
245         // Verify that the settings match with the CalDAVConnectionData
246         // passed.
247         
248         CalDAVStatus CalDAVTimeoutStatus = CalDAVTimeout.GetConnectionData();
249         
250         ASSERT_EQ(CalDAVTimeoutStatus.Hostname, ConnTimeout.Hostname);
251         ASSERT_EQ(CalDAVTimeoutStatus.Username, ConnTimeout.Username);
252         ASSERT_EQ(CalDAVTimeoutStatus.Port, ConnTimeout.Port);
253         ASSERT_EQ(CalDAVTimeoutStatus.Prefix, ConnTimeout.Prefix);
254         ASSERT_EQ(CalDAVTimeoutStatus.Timeout, ConnTimeout.Timeout);
255         ASSERT_EQ(CalDAVTimeoutStatus.UseSSL, ConnTimeout.UseSSL);
256         
257         // Verify that the connection had timed out.
258         
259         ConnResult = CalDAVTimeout.Connect();
260         
261         ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, ConnResult.Result);
262         ASSERT_EQ(0, ConnResult.HTTPCode);
263         ASSERT_EQ(CURLE_OPERATION_TIMEDOUT, ConnResult.Code);
264         
267 TEST(CalDAV, BuildServerAddress){
269         CalDAVConnectionData ConnNormal;
270         ProcessConnectionDataFileResult DataFileResult;
271         bool ValidDataNormal = false;
272         
273         // Attempt to read the caldavtest.auth file.
275         DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
276         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
277                 ValidDataNormal = true;
278         }
279         
280         if (ValidDataNormal == false){
281         
282                 // Cannot read the caldavtest.auth file properly.
283                 
284                 cout << "The caldavtest.auth file does not exist or is invalid!" << endl;
285                 cout << "Please create the caldavtest.auth file using the following format:" << endl << endl;
286                 cout << "server=localname" << endl;
287                 cout << "port=8080" << endl;
288                 cout << "user=username" << endl;
289                 cout << "pass=password" << endl;
290                 cout << "ssl=false" << endl;
291                 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
292                 
293         }
294         
295         ASSERT_EQ(true, ValidDataNormal);
296         
297         // Setup the server address to check.
298         
299         string ServerAddress;
300         
301         // Setup the server address.
302         
303         if (ConnNormal.UseSSL == true){
304                 ServerAddress += "https://";
305         } else {
306                 ServerAddress += "http://";
307         }
308         
309         ServerAddress += ConnNormal.Hostname;
310         
311         // Check if server port is 80, otherwise
312         // specifiy the port number in the address.
313         
314         if (ConnNormal.Port != 80){
315                 ServerAddress += ":";
316                 ServerAddress += to_string(ConnNormal.Port);
317         }
318         
319         ServerAddress += "/principals/";
320         
321         ASSERT_EQ(ServerAddress, BuildServerAddress(&ConnNormal, "/principals/"));
322         
325 TEST(CalDAV, CalendarServerSupport){
326         
327         CalDAVConnectionData ConnNormal;        
329         bool ValidDataNormal = false;
330         
331         // Attempt to read the caldavtest.auth file.
333         ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
334         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
335                 ValidDataNormal = true;
336         }
338         ASSERT_EQ(true, ValidDataNormal);
339         
340         // Setup the connection.
341         
342         CalDAV ServerConnection;
343         
344         ServerConnection.SetupConnectionData(&ConnNormal);
345         
346         // Verify the connection settings.
347         
348         CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
349         
350         ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
351         ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
352         ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
353         ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
354         ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
355         
356         // Connect to the server.
357         
358         CalDAVServerResult ConnResult = ServerConnection.Connect();
359         
360         ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
361         ASSERT_EQ(200, ConnResult.HTTPCode);
362         ASSERT_EQ(CURLE_OK, ConnResult.Code);
363         
364         // Check for basic support of the calendar server.
365         
366         CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
367         
368         ASSERT_EQ(true, ConnSupport.BasicSupport);
369         
372 TEST(CalDAV, GetCalendarHome){
373  
374         CalDAVConnectionData ConnNormal;        
376         bool ValidDataNormal = false;
377         
378         // Attempt to read the caldavtest.auth file.
380         ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
381         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
382                 ValidDataNormal = true;
383         }
385         ASSERT_EQ(true, ValidDataNormal);
386         
387         // Setup the connection.
388         
389         CalDAV ServerConnection;
390         
391         ServerConnection.SetupConnectionData(&ConnNormal);
392         
393         // Verify the connection settings.
394         
395         CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
396         
397         ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
398         ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
399         ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
400         ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
401         ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
402         
403         // Connect to the server.
404         
405         CalDAVServerResult ConnResult = ServerConnection.Connect();
406         
407         ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
408         ASSERT_EQ(200, ConnResult.HTTPCode);
409         ASSERT_EQ(CURLE_OK, ConnResult.Code);
410         
411         // Check for basic support of the calendar server.
412         
413         CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
414         
415         ASSERT_EQ(true, ConnSupport.BasicSupport);
416         
417         // Get the user principal.
418         
419         string CurrentUserPrincipal = ServerConnection.GetUserPrincipal();
420         
421         // Check the response from the server.
422         
423         ConnResult = ServerConnection.GetServerResult();
424         
425         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
426         ASSERT_EQ(207, ConnResult.HTTPCode);
427         ASSERT_EQ(CURLE_OK, ConnResult.Code);
428         
429         // Get the calendar home.
430         
431         string CalendarHome = ServerConnection.GetCalendarHome(CurrentUserPrincipal);
432         
433         // Check the response from the server.
434         
435         ConnResult = ServerConnection.GetServerResult();
436         
437         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
438         ASSERT_EQ(207, ConnResult.HTTPCode);
439         ASSERT_EQ(CURLE_OK, ConnResult.Code);
440   
443 TEST(CalDAV, ListCalendars){
444         
445         CalDAVConnectionData ConnNormal;
446         string CurrentUserPrincipal;
448         bool ValidDataNormal = false;
449         
450         // Attempt to read the caldavtest.auth file.
452         ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
453         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
454                 ValidDataNormal = true;
455         }
457         ASSERT_EQ(true, ValidDataNormal);
458         
459         // Setup the connection.
460         
461         CalDAV ServerConnection;
462         
463         ServerConnection.SetupConnectionData(&ConnNormal);
464         
465         // Verify the connection settings.
466         
467         CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
468         
469         ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
470         ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
471         ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
472         ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
473         ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
474         
475         // Connect to the server.
476         
477         CalDAVServerResult ConnResult = ServerConnection.Connect();
478         
479         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
480         ASSERT_EQ(200, ConnResult.HTTPCode);
481         ASSERT_EQ(CURLE_OK, ConnResult.Code);
482         
483         // Check that the server supports CalDAV.
484         
485         CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
486         ConnResult = ServerConnection.GetServerResult();
487         
488         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
489         ASSERT_EQ(200, ConnResult.HTTPCode);
490         ASSERT_EQ(CURLE_OK, ConnResult.Code);
491         ASSERT_EQ(true, ConnSupport.BasicSupport);
492         
493         // Get the list of calendars.
494         
495         CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
496         
497         // Check the response result from the server.
498         
499         ConnResult = ServerConnection.GetServerResult();
500         
501         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
502         ASSERT_EQ(207, ConnResult.HTTPCode);
503         ASSERT_EQ(CURLE_OK, ConnResult.Code);
504         
507 TEST(CalDAV, AddCalendar){
508         
509         CalDAVConnectionData ConnNormal;
510         string CurrentUserPrincipal;
512         bool ValidDataNormal = false;
513         
514         // Attempt to read the caldavtest.auth file.
516         ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
517         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
518                 ValidDataNormal = true;
519         }
521         ASSERT_EQ(true, ValidDataNormal);
522         
523         // Setup the connection.
524         
525         CalDAV ServerConnection;
526         
527         ServerConnection.SetupConnectionData(&ConnNormal);
528         
529         // Verify the connection settings.
530         
531         CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
532         
533         ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
534         ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
535         ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
536         ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
537         ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
538         
539         // Connect to the server.
540         
541         CalDAVServerResult ConnResult = ServerConnection.Connect();
542         
543         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
544         ASSERT_EQ(200, ConnResult.HTTPCode);
545         ASSERT_EQ(CURLE_OK, ConnResult.Code);
546         
547         // Add a calendar to the server.
548         
549         ConnResult = ServerConnection.AddCalendar("New Calendar");
550         
551         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
552         ASSERT_EQ(201, ConnResult.HTTPCode);
553         ASSERT_EQ(CURLE_OK, ConnResult.Code);
554         
557 TEST(CalDAV, EditCalendar){
558         
559         CalDAVConnectionData ConnNormal;
560         string CurrentUserPrincipal;
562         bool ValidDataNormal = false;
563         
564         // Attempt to read the caldavtest.auth file.
566         ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
567         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
568                 ValidDataNormal = true;
569         }
571         ASSERT_EQ(true, ValidDataNormal);
572         
573         // Setup the connection.
574         
575         CalDAV ServerConnection;
576         
577         ServerConnection.SetupConnectionData(&ConnNormal);
578         
579         // Verify the connection settings.
580         
581         CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
582         
583         ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
584         ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
585         ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
586         ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
587         ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
588         
589         // Connect to the server.
590         
591         CalDAVServerResult ConnResult = ServerConnection.Connect();
592         
593         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
594         ASSERT_EQ(200, ConnResult.HTTPCode);
595         ASSERT_EQ(CURLE_OK, ConnResult.Code);
596         
597         // Check that the server supports CalDAV.
598         
599         CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
600         ConnResult = ServerConnection.GetServerResult();
601         
602         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
603         ASSERT_EQ(200, ConnResult.HTTPCode);
604         ASSERT_EQ(CURLE_OK, ConnResult.Code);
605         ASSERT_EQ(true, ConnSupport.BasicSupport);
606         
607         // Add a calendar to the server.
608         
609         ConnResult = ServerConnection.AddCalendar("Calendar To Edit");
610         
611         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
612         ASSERT_EQ(201, ConnResult.HTTPCode);
613         ASSERT_EQ(CURLE_OK, ConnResult.Code);
614         
615         // Get the list of calendars.
616         
617         CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
618         
619         // Check the response result from the server.
620         
621         ConnResult = ServerConnection.GetServerResult();
622         
623         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
624         ASSERT_EQ(207, ConnResult.HTTPCode);
625         ASSERT_EQ(CURLE_OK, ConnResult.Code);
626         
627         // Find the calendar containing the name "Calendar To Edit"
628         // created earlier.
629         
630         int ItemSeek = 0;
631         bool ItemFound = false;
632         
633         for (map<int,string>::iterator CalendarNameIter = CalendarList.Name.begin();
634                 CalendarNameIter != CalendarList.Name.end(); CalendarNameIter++){
635                 
636                 if (CalendarNameIter->second == "Calendar To Edit"){
637                         ItemFound = true;
638                         break;
639                 }
640                         
641                 ItemSeek++;
642                         
643         }
644         
645         ASSERT_NE(false, ItemFound);
646         
647         // Edit the name of the calendar.
648         
649         string CalendarEditHREF = CalendarList.HREF[ItemSeek];
650         string NewCalendarName = "Edited Calendar";
651         
652         ConnResult = ServerConnection.EditCalendar(&CalendarEditHREF, &NewCalendarName);
653         
654         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
655         ASSERT_EQ(207, ConnResult.HTTPCode);
656         ASSERT_EQ(CURLE_OK, ConnResult.Code);
657         
658         // Edit the colour of the calendar.
660         Colour NewColour;
661         
662         NewColour.red = 255;
663         NewColour.green = 0;
664         NewColour.blue = 0;
665         NewColour.alpha = 0;
666         
667         ConnResult = ServerConnection.EditCalendar(&CalendarEditHREF, &NewColour);
668         
669         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
670         ASSERT_EQ(207, ConnResult.HTTPCode);
671         ASSERT_EQ(CURLE_OK, ConnResult.Code);   
672         
673         // Edit the description of the calendar.
675         string NewCalendarDescription = "Update Calendar Description";
677         ConnResult = ServerConnection.EditCalendarDescription(&CalendarEditHREF, &NewCalendarDescription);
678         
679         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
680         ASSERT_EQ(207, ConnResult.HTTPCode);
681         ASSERT_EQ(CURLE_OK, ConnResult.Code);   
682         
683         // Edit the order of the calendar.
684         
685         int NewCalendarOrder = 30;
686         
687         ConnResult = ServerConnection.EditCalendar(&CalendarEditHREF, &NewCalendarOrder);
688         
689         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
690         ASSERT_EQ(207, ConnResult.HTTPCode);
691         ASSERT_EQ(CURLE_OK, ConnResult.Code);
692         
693         // Edit all of the available properties of the calendar.
694         
695         NewCalendarName = "Calendar Edited Again";
696         NewCalendarDescription = "Another updated calendar description";
697         NewColour.red = 0;
698         NewColour.green = 255;
699         NewColour.blue = 0;
700         NewColour.alpha = 0;
701         NewCalendarOrder = 40;
702         
703         ConnResult = ServerConnection.EditCalendar(&CalendarEditHREF, 
704                 &NewCalendarName,
705                 &NewColour,
706                 &NewCalendarDescription,
707                 &NewCalendarOrder);
708         
709         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
710         ASSERT_EQ(207, ConnResult.HTTPCode);
711         ASSERT_EQ(CURLE_OK, ConnResult.Code);
712         
715 TEST(CalDAV, DeleteCalendar){
717         CalDAVConnectionData ConnNormal;
718         string CurrentUserPrincipal;
720         bool ValidDataNormal = false;
721         
722         // Attempt to read the caldavtest.auth file.
724         ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
725         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
726                 ValidDataNormal = true;
727         }
729         ASSERT_EQ(true, ValidDataNormal);
730         
731         // Setup the connection.
732         
733         CalDAV ServerConnection;
734         
735         ServerConnection.SetupConnectionData(&ConnNormal);
736         
737         // Verify the connection settings.
738         
739         CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
740         
741         ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
742         ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
743         ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
744         ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
745         ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
746         
747         // Connect to the server.
748         
749         CalDAVServerResult ConnResult = ServerConnection.Connect();
750         
751         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
752         ASSERT_EQ(200, ConnResult.HTTPCode);
753         ASSERT_EQ(CURLE_OK, ConnResult.Code);
754         
755         // Check that the server supports CalDAV.
756         
757         CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
758         ConnResult = ServerConnection.GetServerResult();
759         
760         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
761         ASSERT_EQ(200, ConnResult.HTTPCode);
762         ASSERT_EQ(CURLE_OK, ConnResult.Code);
763         ASSERT_EQ(true, ConnSupport.BasicSupport);
764         
765         // Get the list of calendars.
766         
767         CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
768         
769         // Check the response result from the server.
770         
771         ConnResult = ServerConnection.GetServerResult();
772         
773         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
774         ASSERT_EQ(207, ConnResult.HTTPCode);
775         ASSERT_EQ(CURLE_OK, ConnResult.Code);
776         
777         // Get the calendar with the matching name.
778         
779         int ItemSeek = 0;
780         bool ItemFound = false;
781         
782         for (map<int,string>::iterator CalendarNameIter = CalendarList.Name.begin();
783                 CalendarNameIter != CalendarList.Name.end(); CalendarNameIter++){
784                 
785                 if (CalendarNameIter->second == "Calendar Edited Again"){
786                         ItemFound = true;
787                         break;
788                 }
789                         
790                 ItemSeek++;
791                         
792         }
794         ASSERT_NE(false, ItemFound);
795         
796         // Delete some calendars.
797         
798         string CalendarEditHREF = CalendarList.HREF[ItemSeek];
799         
800         ConnResult = ServerConnection.DeleteCalendar(&CalendarEditHREF);
801         
802         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
803         ASSERT_EQ(204, ConnResult.HTTPCode);
804         ASSERT_EQ(CURLE_OK, ConnResult.Code);
805         
808 TEST(CalDAV, AddEntry){
809         
810         CalDAVConnectionData ConnNormal;
811         string CurrentUserPrincipal;
813         bool ValidDataNormal = false;
814         
815         // Attempt to read the caldavtest.auth file.
817         ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
818         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
819                 ValidDataNormal = true;
820         }
822         ASSERT_EQ(true, ValidDataNormal);
823         
824         // Setup the connection.
825         
826         CalDAV ServerConnection;
827         
828         ServerConnection.SetupConnectionData(&ConnNormal);
829         
830         // Verify the connection settings.
831         
832         CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
833         
834         ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
835         ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
836         ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
837         ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
838         ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
839         
840         // Connect to the server.
841         
842         CalDAVServerResult ConnResult = ServerConnection.Connect();
843         
844         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
845         ASSERT_EQ(200, ConnResult.HTTPCode);
846         ASSERT_EQ(CURLE_OK, ConnResult.Code);
847         
848         // Check that the server supports CalDAV.
849         
850         CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
851         ConnResult = ServerConnection.GetServerResult();
852         
853         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
854         ASSERT_EQ(200, ConnResult.HTTPCode);
855         ASSERT_EQ(CURLE_OK, ConnResult.Code);
856         ASSERT_EQ(true, ConnSupport.BasicSupport);
857         
858         // Get the list of calendars.
859         
860         CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
861         
862         // Check the response result from the server.
863         
864         ConnResult = ServerConnection.GetServerResult();
865         
866         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
867         ASSERT_EQ(207, ConnResult.HTTPCode);
868         ASSERT_EQ(CURLE_OK, ConnResult.Code);
869         
870         // Get the calendar with the matching name.
871         
872         int ItemSeek = 0;
873         bool ItemFound = false;
874         
875         for (map<int,string>::iterator CalendarNameIter = CalendarList.Name.begin();
876                 CalendarNameIter != CalendarList.Name.end(); CalendarNameIter++){
877                 
878                 if (CalendarNameIter->second == "Scratching Calendar"){
879                         ItemFound = true;
880                         break;
881                 }
882                         
883                 ItemSeek++;
884                         
885         }
887         ASSERT_NE(false, ItemFound);
888         
889         string EntryAddHREF = CalendarList.HREF[ItemSeek];
890         
891         string EntryUUID = GenerateUUID();
892         EntryUUID.erase(EntryUUID.end()-1);
893         
894         EntryAddHREF.append(EntryUUID);
895         EntryAddHREF.append(".ics");
896         
897         string AddEntryData = "BEGIN:VCALENDAR\n"
898         "VERSION:2.0\n"
899         "PRODID:-//Xestia//Calendar Unit Testing//KW\n"
900         "BEGIN:VEVENT\n"
901         "UID:";
902         AddEntryData += EntryUUID;
903         AddEntryData += "\n"
904         "DTSTAMP:20160116T190200Z\n"
905         "DTSTART:20160116T190200Z\n"
906         "DTEND:20160116T190200Z\n"
907         "SUMMARY:Unit Test Event 1 which has to be a really long summary as we don't k\n"
908         " now if multiple line processing is going to work without it. I mean seriousl\n"
909         " y, how annoying can this potentially be?\n"
910         "END:VEVENT\n"
911         "END:VCALENDAR\n";
912         
913         ConnResult = ServerConnection.AddEntry(&EntryAddHREF, &AddEntryData);
914         
915         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
916         ASSERT_EQ(201, ConnResult.HTTPCode);
917         ASSERT_EQ(CURLE_OK, ConnResult.Code);
918         
919         // Set the EntryCalendarHREFProcessing for later on.
920         
921         EntryCalendarHREFProcessing = EntryAddHREF;
922         
924         
927 TEST(CalDAV, DeleteEntry){
929         // Check that EntryCalendarHREFProcessing is not blank. 
930         
931         ASSERT_NE("", EntryCalendarHREFProcessing);
932         
933         CalDAVConnectionData ConnNormal;
934         string CurrentUserPrincipal;
936         bool ValidDataNormal = false;
937         
938         // Attempt to read the caldavtest.auth file.
940         ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
941         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
942                 ValidDataNormal = true;
943         }
945         ASSERT_EQ(true, ValidDataNormal);
946         
947         // Setup the connection.
948         
949         CalDAV ServerConnection;
950         
951         ServerConnection.SetupConnectionData(&ConnNormal);
952         
953         // Verify the connection settings.
954         
955         CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
956         
957         ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
958         ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
959         ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
960         ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
961         ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
962         
963         // Connect to the server.
964         
965         CalDAVServerResult ConnResult = ServerConnection.Connect();
966         
967         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
968         ASSERT_EQ(200, ConnResult.HTTPCode);
969         ASSERT_EQ(CURLE_OK, ConnResult.Code);
970         
971         // Check that the server supports CalDAV.
972         
973         CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
974         ConnResult = ServerConnection.GetServerResult();
975         
976         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
977         ASSERT_EQ(200, ConnResult.HTTPCode);
978         ASSERT_EQ(CURLE_OK, ConnResult.Code);
979         ASSERT_EQ(true, ConnSupport.BasicSupport);
980         
981         // Delete the calendar entry.
982         
983         ConnResult = ServerConnection.DeleteCalendar(&EntryCalendarHREFProcessing);
984         
985         // Check the response result from the server.
986         
987         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
988         ASSERT_EQ(204, ConnResult.HTTPCode);
989         ASSERT_EQ(CURLE_OK, ConnResult.Code);
990         
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