Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added ATTACH property for saving data from a CalendarEventObject.
[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 = "";
26 string EntryUUID = "";
28 TEST(CalDAV, BasicTests){
30         CalDAVConnectionData ConnPlain;
31         CalDAVConnectionData ConnNormal;
32         CalDAVConnectionData ConnInvalidSSL;
33         CalDAVConnectionData ConnTimeout;
34         ProcessConnectionDataFileResult DataFileResult;
36         bool ValidDataPlain = false;
37         bool ValidDataNormal = false;
38         bool ValidDataInvalidSSL = false;
39         bool ValidDataTimeout = false;
41         // Attempt to read the caldavtest-plain.auth file.
42         
43         DataFileResult = ProcessConnectionDataFile("caldavtest-plain.auth", &ConnPlain);
44         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
45                 ValidDataPlain = true;
46         }
47         
48         // Attempt to read the caldavtest.auth file.
50         DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
51         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
52                 ValidDataNormal = true;
53         }
54         
55         // Attempt to read the caldavtest-fail.auth file.
56         
57         DataFileResult = ProcessConnectionDataFile("caldavtest-fail.auth", &ConnInvalidSSL);
58         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
59                 ValidDataInvalidSSL = true;
60         }
61         
62         // Attempt to read the caldavtest-timeout.auth file.
63         
64         DataFileResult = ProcessConnectionDataFile("caldavtest-timeout.auth", &ConnTimeout);
65         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
66                 ValidDataTimeout = true;
67         }
69         if (ValidDataPlain == false){
70         
71                 // Cannot read the caldavtest-plain.auth file properly.
72                 
73                 cout << "The caldavtest-plain.auth file does not exist or is invalid!" << endl;
74                 cout << "Please create the caldavtest-plain.auth file using the following format:" << endl << endl;
75                 cout << "server=localname" << endl;
76                 cout << "port=8080" << endl;
77                 cout << "user=username" << endl;
78                 cout << "pass=password" << endl;
79                 cout << "ssl=false" << endl;
80                 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
81                 
82         }
83         
84         if (ValidDataNormal == false){
85         
86                 // Cannot read the caldavtest.auth file properly.
87                 
88                 cout << "The caldavtest.auth file does not exist or is invalid!" << endl;
89                 cout << "Please create the caldavtest.auth file using the following format:" << endl << endl;
90                 cout << "server=localname" << endl;
91                 cout << "port=8080" << endl;
92                 cout << "user=username" << endl;
93                 cout << "pass=password" << endl;
94                 cout << "ssl=false" << endl;
95                 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
96                 
97         }
98         
99         if (ValidDataInvalidSSL == false){
100         
101                 // Cannot read the caldavtest-fail.auth file properly.
102                 
103                 cout << "The caldavtest-fail.auth file does not exist or is invalid!" << endl;
104                 cout << "Please create the caldavtest-fail.auth file using the following format:" << endl << endl;
105                 cout << "server=fail.localname" << endl;
106                 cout << "port=8080" << endl;
107                 cout << "user=username" << endl;
108                 cout << "pass=password" << endl;
109                 cout << "ssl=false" << endl;
110                 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
111                 
112         }
113         
114         if (ValidDataTimeout == false){
115         
116                 // Cannot read the caldavtest-timeout.auth file properly.
117                 
118                 cout << "The caldavtest-timeout.auth file does not exist or is invalid!" << endl;
119                 cout << "Please create the caldavtest-timeout.auth file using the following format:" << endl << endl;
120                 cout << "server=fail.localname" << endl;
121                 cout << "port=8080" << endl;
122                 cout << "user=username" << endl;
123                 cout << "pass=password" << endl;
124                 cout << "ssl=false" << endl;
125                 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
126                 
127         }
128         
129         ASSERT_EQ(true, ValidDataPlain);
130         ASSERT_EQ(true, ValidDataNormal);
131         ASSERT_EQ(true, ValidDataInvalidSSL);
132         ASSERT_EQ(true, ValidDataTimeout);
134         // (*nix version) Setup an initial connection (just plain
135         // text).
136         
137         CalDAV CalDAVPlain;
138         CalDAVPlain.SetupConnectionData(&ConnPlain);
139         
140         // Verify that the settings match with the CalDAVConnectionData
141         // passed.
142         
143         CalDAVStatus CalDAVPlainStatus = CalDAVPlain.GetConnectionData();
144         
145         ASSERT_EQ(CalDAVPlainStatus.Hostname, ConnPlain.Hostname);
146         ASSERT_EQ(CalDAVPlainStatus.Username, ConnPlain.Username);
147         ASSERT_EQ(CalDAVPlainStatus.Port, ConnPlain.Port);
148         ASSERT_EQ(CalDAVPlainStatus.Prefix, ConnPlain.Prefix);
149         ASSERT_EQ(CalDAVPlainStatus.UseSSL, ConnPlain.UseSSL);
150         
151         // Verify that the connection was successful.
152         
153         CalDAVServerResult ConnResult = CalDAVPlain.Connect();
154         
155         ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
156         ASSERT_EQ(200, ConnResult.HTTPCode);
157         ASSERT_EQ(CURLE_OK, ConnResult.Code);
158         
159         // Do another connection and this time the connection should
160         // fail due to being an invalid host name.
161         
162         CalDAVConnectionData ConnPlainFail;
163         ConnPlainFail.Hostname = "server.invalid";
164         ConnPlainFail.Username = "fail";
165         ConnPlainFail.Password = "fail";
166         ConnPlainFail.Port = 80;
167         ConnPlainFail.UseSSL = false;
168         
169         // Setup the CalDAV connection object.
170         
171         CalDAV CalDAVPlainFail;
172         CalDAVPlainFail.SetupConnectionData(&ConnPlainFail);
173         
174         // Setup the CalDAVStatus object.
175         
176         CalDAVStatus CalDAVPlainFailStatus = CalDAVPlain.GetConnectionData();
177         
178         // Connect and fail.
179         
180         ConnResult = CalDAVPlainFail.Connect();
181         
182         ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, ConnResult.Result);
183         ASSERT_EQ(0, ConnResult.HTTPCode);
184         ASSERT_EQ(CURLE_COULDNT_RESOLVE_HOST, ConnResult.Code);
185         
186         // (*nix version) Setup an initial connection (with a valid
187         // SSL certificate).
189         CalDAV CalDAVNormal;
190         CalDAVNormal.SetupConnectionData(&ConnNormal);
192         // Verify that the settings match with the CalDAVConnectionData
193         // passed.
194         
195         CalDAVStatus CalDAVNormalStatus = CalDAVNormal.GetConnectionData();
196         
197         ASSERT_EQ(CalDAVNormalStatus.Hostname, ConnNormal.Hostname);
198         ASSERT_EQ(CalDAVNormalStatus.Username, ConnNormal.Username);
199         ASSERT_EQ(CalDAVNormalStatus.Port, ConnNormal.Port);
200         ASSERT_EQ(CalDAVNormalStatus.Prefix, ConnNormal.Prefix);
201         ASSERT_EQ(CalDAVNormalStatus.UseSSL, ConnNormal.UseSSL);
203         // Verify that the connection was successful (with a valid
204         // SSL certificate).
205         
206         ConnResult = CalDAVNormal.Connect();
207         
208         ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
209         ASSERT_EQ(200, ConnResult.HTTPCode);
210         ASSERT_EQ(CURLE_OK, ConnResult.Code);
211         
212         // (*nix version) Setup an initial connection on a server that
213         // will fail due to having an invalid SSL certificate.
215         CalDAV CalDAVInvalidSSL;
216         CalDAVInvalidSSL.SetupConnectionData(&ConnInvalidSSL);
218         // Verify that the settings match with the CalDAVConnectionData
219         // passed.
220         
221         CalDAVStatus CalDAVInvalidSSLStatus = CalDAVInvalidSSL.GetConnectionData();
222         
223         ASSERT_EQ(CalDAVInvalidSSLStatus.Hostname, ConnInvalidSSL.Hostname);
224         ASSERT_EQ(CalDAVInvalidSSLStatus.Username, ConnInvalidSSL.Username);
225         ASSERT_EQ(CalDAVInvalidSSLStatus.Port, ConnInvalidSSL.Port);
226         ASSERT_EQ(CalDAVInvalidSSLStatus.Prefix, ConnInvalidSSL.Prefix);
227         ASSERT_EQ(CalDAVInvalidSSLStatus.UseSSL, ConnInvalidSSL.UseSSL);
228         
229         // Verify that the connection had failed. (with an invalid
230         // SSL certificate).
231         
232         ConnResult = CalDAVInvalidSSL.Connect();
233         
234         ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, ConnResult.Result);
235         ASSERT_EQ(0, ConnResult.HTTPCode);
236         ASSERT_EQ(CURLE_SSL_CACERT, ConnResult.Code);
237         
238         // (*nix version) Setup an inital connection on a server where
239         // a timeout occurs.
240         
241         ConnTimeout.Timeout = 5;
242         
243         CalDAV CalDAVTimeout;
244         CalDAVTimeout.SetupConnectionData(&ConnTimeout);
246         // Verify that the settings match with the CalDAVConnectionData
247         // passed.
248         
249         CalDAVStatus CalDAVTimeoutStatus = CalDAVTimeout.GetConnectionData();
250         
251         ASSERT_EQ(CalDAVTimeoutStatus.Hostname, ConnTimeout.Hostname);
252         ASSERT_EQ(CalDAVTimeoutStatus.Username, ConnTimeout.Username);
253         ASSERT_EQ(CalDAVTimeoutStatus.Port, ConnTimeout.Port);
254         ASSERT_EQ(CalDAVTimeoutStatus.Prefix, ConnTimeout.Prefix);
255         ASSERT_EQ(CalDAVTimeoutStatus.Timeout, ConnTimeout.Timeout);
256         ASSERT_EQ(CalDAVTimeoutStatus.UseSSL, ConnTimeout.UseSSL);
257         
258         // Verify that the connection had timed out.
259         
260         ConnResult = CalDAVTimeout.Connect();
261         
262         ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, ConnResult.Result);
263         ASSERT_EQ(0, ConnResult.HTTPCode);
264         ASSERT_EQ(CURLE_OPERATION_TIMEDOUT, ConnResult.Code);
265         
268 TEST(CalDAV, BuildServerAddress){
270         CalDAVConnectionData ConnNormal;
271         ProcessConnectionDataFileResult DataFileResult;
272         bool ValidDataNormal = false;
273         
274         // Attempt to read the caldavtest.auth file.
276         DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
277         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
278                 ValidDataNormal = true;
279         }
280         
281         if (ValidDataNormal == false){
282         
283                 // Cannot read the caldavtest.auth file properly.
284                 
285                 cout << "The caldavtest.auth file does not exist or is invalid!" << endl;
286                 cout << "Please create the caldavtest.auth file using the following format:" << endl << endl;
287                 cout << "server=localname" << endl;
288                 cout << "port=8080" << endl;
289                 cout << "user=username" << endl;
290                 cout << "pass=password" << endl;
291                 cout << "ssl=false" << endl;
292                 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
293                 
294         }
295         
296         ASSERT_EQ(true, ValidDataNormal);
297         
298         // Setup the server address to check.
299         
300         string ServerAddress;
301         
302         // Setup the server address.
303         
304         if (ConnNormal.UseSSL == true){
305                 ServerAddress += "https://";
306         } else {
307                 ServerAddress += "http://";
308         }
309         
310         ServerAddress += ConnNormal.Hostname;
311         
312         // Check if server port is 80, otherwise
313         // specifiy the port number in the address.
314         
315         if (ConnNormal.Port != 80){
316                 ServerAddress += ":";
317                 ServerAddress += to_string(ConnNormal.Port);
318         }
319         
320         ServerAddress += "/principals/";
321         
322         ASSERT_EQ(ServerAddress, BuildServerAddress(&ConnNormal, "/principals/"));
323         
326 TEST(CalDAV, CalendarServerSupport){
327         
328         CalDAVConnectionData ConnNormal;        
330         bool ValidDataNormal = false;
331         
332         // Attempt to read the caldavtest.auth file.
334         ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
335         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
336                 ValidDataNormal = true;
337         }
339         ASSERT_EQ(true, ValidDataNormal);
340         
341         // Setup the connection.
342         
343         CalDAV ServerConnection;
344         
345         ServerConnection.SetupConnectionData(&ConnNormal);
346         
347         // Verify the connection settings.
348         
349         CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
350         
351         ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
352         ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
353         ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
354         ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
355         ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
356         
357         // Connect to the server.
358         
359         CalDAVServerResult ConnResult = ServerConnection.Connect();
360         
361         ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
362         ASSERT_EQ(200, ConnResult.HTTPCode);
363         ASSERT_EQ(CURLE_OK, ConnResult.Code);
364         
365         // Check for basic support of the calendar server.
366         
367         CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
368         
369         ASSERT_EQ(true, ConnSupport.BasicSupport);
370         
373 TEST(CalDAV, GetCalendarHome){
374  
375         CalDAVConnectionData ConnNormal;        
377         bool ValidDataNormal = false;
378         
379         // Attempt to read the caldavtest.auth file.
381         ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
382         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
383                 ValidDataNormal = true;
384         }
386         ASSERT_EQ(true, ValidDataNormal);
387         
388         // Setup the connection.
389         
390         CalDAV ServerConnection;
391         
392         ServerConnection.SetupConnectionData(&ConnNormal);
393         
394         // Verify the connection settings.
395         
396         CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
397         
398         ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
399         ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
400         ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
401         ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
402         ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
403         
404         // Connect to the server.
405         
406         CalDAVServerResult ConnResult = ServerConnection.Connect();
407         
408         ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
409         ASSERT_EQ(200, ConnResult.HTTPCode);
410         ASSERT_EQ(CURLE_OK, ConnResult.Code);
411         
412         // Check for basic support of the calendar server.
413         
414         CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
415         
416         ASSERT_EQ(true, ConnSupport.BasicSupport);
417         
418         // Get the user principal.
419         
420         string CurrentUserPrincipal = ServerConnection.GetUserPrincipal();
421         
422         // Check the response from the server.
423         
424         ConnResult = ServerConnection.GetServerResult();
425         
426         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
427         ASSERT_EQ(207, ConnResult.HTTPCode);
428         ASSERT_EQ(CURLE_OK, ConnResult.Code);
429         
430         // Get the calendar home.
431         
432         string CalendarHome = ServerConnection.GetCalendarHome(CurrentUserPrincipal);
433         
434         // Check the response from the server.
435         
436         ConnResult = ServerConnection.GetServerResult();
437         
438         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
439         ASSERT_EQ(207, ConnResult.HTTPCode);
440         ASSERT_EQ(CURLE_OK, ConnResult.Code);
441   
444 TEST(CalDAV, ListCalendars){
445         
446         CalDAVConnectionData ConnNormal;
447         string CurrentUserPrincipal;
449         bool ValidDataNormal = false;
450         
451         // Attempt to read the caldavtest.auth file.
453         ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
454         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
455                 ValidDataNormal = true;
456         }
458         ASSERT_EQ(true, ValidDataNormal);
459         
460         // Setup the connection.
461         
462         CalDAV ServerConnection;
463         
464         ServerConnection.SetupConnectionData(&ConnNormal);
465         
466         // Verify the connection settings.
467         
468         CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
469         
470         ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
471         ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
472         ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
473         ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
474         ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
475         
476         // Connect to the server.
477         
478         CalDAVServerResult ConnResult = ServerConnection.Connect();
479         
480         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
481         ASSERT_EQ(200, ConnResult.HTTPCode);
482         ASSERT_EQ(CURLE_OK, ConnResult.Code);
483         
484         // Check that the server supports CalDAV.
485         
486         CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
487         ConnResult = ServerConnection.GetServerResult();
488         
489         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
490         ASSERT_EQ(200, ConnResult.HTTPCode);
491         ASSERT_EQ(CURLE_OK, ConnResult.Code);
492         ASSERT_EQ(true, ConnSupport.BasicSupport);
493         
494         // Get the list of calendars.
495         
496         CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
497         
498         // Check the response result from the server.
499         
500         ConnResult = ServerConnection.GetServerResult();
501         
502         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
503         ASSERT_EQ(207, ConnResult.HTTPCode);
504         ASSERT_EQ(CURLE_OK, ConnResult.Code);
505         
508 TEST(CalDAV, AddCalendar){
509         
510         CalDAVConnectionData ConnNormal;
511         string CurrentUserPrincipal;
513         bool ValidDataNormal = false;
514         
515         // Attempt to read the caldavtest.auth file.
517         ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
518         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
519                 ValidDataNormal = true;
520         }
522         ASSERT_EQ(true, ValidDataNormal);
523         
524         // Setup the connection.
525         
526         CalDAV ServerConnection;
527         
528         ServerConnection.SetupConnectionData(&ConnNormal);
529         
530         // Verify the connection settings.
531         
532         CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
533         
534         ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
535         ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
536         ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
537         ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
538         ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
539         
540         // Connect to the server.
541         
542         CalDAVServerResult ConnResult = ServerConnection.Connect();
543         
544         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
545         ASSERT_EQ(200, ConnResult.HTTPCode);
546         ASSERT_EQ(CURLE_OK, ConnResult.Code);
547         
548         // Add a calendar to the server.
549         
550         ConnResult = ServerConnection.AddCalendar("New Calendar");
551         
552         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
553         ASSERT_EQ(201, ConnResult.HTTPCode);
554         ASSERT_EQ(CURLE_OK, ConnResult.Code);
555         
558 TEST(CalDAV, EditCalendar){
559         
560         CalDAVConnectionData ConnNormal;
561         string CurrentUserPrincipal;
563         bool ValidDataNormal = false;
564         
565         // Attempt to read the caldavtest.auth file.
567         ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
568         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
569                 ValidDataNormal = true;
570         }
572         ASSERT_EQ(true, ValidDataNormal);
573         
574         // Setup the connection.
575         
576         CalDAV ServerConnection;
577         
578         ServerConnection.SetupConnectionData(&ConnNormal);
579         
580         // Verify the connection settings.
581         
582         CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
583         
584         ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
585         ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
586         ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
587         ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
588         ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
589         
590         // Connect to the server.
591         
592         CalDAVServerResult ConnResult = ServerConnection.Connect();
593         
594         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
595         ASSERT_EQ(200, ConnResult.HTTPCode);
596         ASSERT_EQ(CURLE_OK, ConnResult.Code);
597         
598         // Check that the server supports CalDAV.
599         
600         CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
601         ConnResult = ServerConnection.GetServerResult();
602         
603         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
604         ASSERT_EQ(200, ConnResult.HTTPCode);
605         ASSERT_EQ(CURLE_OK, ConnResult.Code);
606         ASSERT_EQ(true, ConnSupport.BasicSupport);
607         
608         // Add a calendar to the server.
609         
610         ConnResult = ServerConnection.AddCalendar("Calendar To Edit");
611         
612         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
613         ASSERT_EQ(201, ConnResult.HTTPCode);
614         ASSERT_EQ(CURLE_OK, ConnResult.Code);
615         
616         // Get the list of calendars.
617         
618         CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
619         
620         // Check the response result from the server.
621         
622         ConnResult = ServerConnection.GetServerResult();
623         
624         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
625         ASSERT_EQ(207, ConnResult.HTTPCode);
626         ASSERT_EQ(CURLE_OK, ConnResult.Code);
627         
628         // Find the calendar containing the name "Calendar To Edit"
629         // created earlier.
630         
631         int ItemSeek = 0;
632         bool ItemFound = false;
633         
634         for (map<int,string>::iterator CalendarNameIter = CalendarList.Name.begin();
635                 CalendarNameIter != CalendarList.Name.end(); CalendarNameIter++){
636                 
637                 if (CalendarNameIter->second == "Calendar To Edit"){
638                         ItemFound = true;
639                         break;
640                 }
641                         
642                 ItemSeek++;
643                         
644         }
645         
646         ASSERT_NE(false, ItemFound);
647         
648         // Edit the name of the calendar.
649         
650         string CalendarEditHREF = CalendarList.HREF[ItemSeek];
651         string NewCalendarName = "Edited Calendar";
652         
653         ConnResult = ServerConnection.EditCalendar(&CalendarEditHREF, &NewCalendarName);
654         
655         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
656         ASSERT_EQ(207, ConnResult.HTTPCode);
657         ASSERT_EQ(CURLE_OK, ConnResult.Code);
658         
659         // Edit the colour of the calendar.
661         Colour NewColour;
662         
663         NewColour.red = 255;
664         NewColour.green = 0;
665         NewColour.blue = 0;
666         NewColour.alpha = 0;
667         
668         ConnResult = ServerConnection.EditCalendar(&CalendarEditHREF, &NewColour);
669         
670         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
671         ASSERT_EQ(207, ConnResult.HTTPCode);
672         ASSERT_EQ(CURLE_OK, ConnResult.Code);   
673         
674         // Edit the description of the calendar.
676         string NewCalendarDescription = "Update Calendar Description";
678         ConnResult = ServerConnection.EditCalendarDescription(&CalendarEditHREF, &NewCalendarDescription);
679         
680         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
681         ASSERT_EQ(207, ConnResult.HTTPCode);
682         ASSERT_EQ(CURLE_OK, ConnResult.Code);   
683         
684         // Edit the order of the calendar.
685         
686         int NewCalendarOrder = 30;
687         
688         ConnResult = ServerConnection.EditCalendar(&CalendarEditHREF, &NewCalendarOrder);
689         
690         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
691         ASSERT_EQ(207, ConnResult.HTTPCode);
692         ASSERT_EQ(CURLE_OK, ConnResult.Code);
693         
694         // Edit all of the available properties of the calendar.
695         
696         NewCalendarName = "Calendar Edited Again";
697         NewCalendarDescription = "Another updated calendar description";
698         NewColour.red = 0;
699         NewColour.green = 255;
700         NewColour.blue = 0;
701         NewColour.alpha = 0;
702         NewCalendarOrder = 40;
703         
704         ConnResult = ServerConnection.EditCalendar(&CalendarEditHREF, 
705                 &NewCalendarName,
706                 &NewColour,
707                 &NewCalendarDescription,
708                 &NewCalendarOrder);
709         
710         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
711         ASSERT_EQ(207, ConnResult.HTTPCode);
712         ASSERT_EQ(CURLE_OK, ConnResult.Code);
713         
716 TEST(CalDAV, DeleteCalendar){
718         CalDAVConnectionData ConnNormal;
719         string CurrentUserPrincipal;
721         bool ValidDataNormal = false;
722         
723         // Attempt to read the caldavtest.auth file.
725         ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
726         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
727                 ValidDataNormal = true;
728         }
730         ASSERT_EQ(true, ValidDataNormal);
731         
732         // Setup the connection.
733         
734         CalDAV ServerConnection;
735         
736         ServerConnection.SetupConnectionData(&ConnNormal);
737         
738         // Verify the connection settings.
739         
740         CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
741         
742         ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
743         ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
744         ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
745         ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
746         ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
747         
748         // Connect to the server.
749         
750         CalDAVServerResult ConnResult = ServerConnection.Connect();
751         
752         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
753         ASSERT_EQ(200, ConnResult.HTTPCode);
754         ASSERT_EQ(CURLE_OK, ConnResult.Code);
755         
756         // Check that the server supports CalDAV.
757         
758         CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
759         ConnResult = ServerConnection.GetServerResult();
760         
761         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
762         ASSERT_EQ(200, ConnResult.HTTPCode);
763         ASSERT_EQ(CURLE_OK, ConnResult.Code);
764         ASSERT_EQ(true, ConnSupport.BasicSupport);
765         
766         // Get the list of calendars.
767         
768         CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
769         
770         // Check the response result from the server.
771         
772         ConnResult = ServerConnection.GetServerResult();
773         
774         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
775         ASSERT_EQ(207, ConnResult.HTTPCode);
776         ASSERT_EQ(CURLE_OK, ConnResult.Code);
777         
778         // Get the calendar with the matching name.
779         
780         int ItemSeek = 0;
781         bool ItemFound = false;
782         
783         for (map<int,string>::iterator CalendarNameIter = CalendarList.Name.begin();
784                 CalendarNameIter != CalendarList.Name.end(); CalendarNameIter++){
785                 
786                 if (CalendarNameIter->second == "Calendar Edited Again"){
787                         ItemFound = true;
788                         break;
789                 }
790                         
791                 ItemSeek++;
792                         
793         }
795         ASSERT_NE(false, ItemFound);
796         
797         // Delete some calendars.
798         
799         string CalendarEditHREF = CalendarList.HREF[ItemSeek];
800         
801         ConnResult = ServerConnection.DeleteCalendar(&CalendarEditHREF);
802         
803         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
804         ASSERT_EQ(204, ConnResult.HTTPCode);
805         ASSERT_EQ(CURLE_OK, ConnResult.Code);
806         
809 TEST(CalDAV, AddEntry){
810         
811         CalDAVConnectionData ConnNormal;
812         string CurrentUserPrincipal;
814         bool ValidDataNormal = false;
815         
816         // Attempt to read the caldavtest.auth file.
818         ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
819         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
820                 ValidDataNormal = true;
821         }
823         ASSERT_EQ(true, ValidDataNormal);
824         
825         // Setup the connection.
826         
827         CalDAV ServerConnection;
828         
829         ServerConnection.SetupConnectionData(&ConnNormal);
830         
831         // Verify the connection settings.
832         
833         CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
834         
835         ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
836         ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
837         ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
838         ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
839         ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
840         
841         // Connect to the server.
842         
843         CalDAVServerResult ConnResult = ServerConnection.Connect();
844         
845         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
846         ASSERT_EQ(200, ConnResult.HTTPCode);
847         ASSERT_EQ(CURLE_OK, ConnResult.Code);
848         
849         // Check that the server supports CalDAV.
850         
851         CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
852         ConnResult = ServerConnection.GetServerResult();
853         
854         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
855         ASSERT_EQ(200, ConnResult.HTTPCode);
856         ASSERT_EQ(CURLE_OK, ConnResult.Code);
857         ASSERT_EQ(true, ConnSupport.BasicSupport);
858         
859         // Get the list of calendars.
860         
861         CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
862         
863         // Check the response result from the server.
864         
865         ConnResult = ServerConnection.GetServerResult();
866         
867         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
868         ASSERT_EQ(207, ConnResult.HTTPCode);
869         ASSERT_EQ(CURLE_OK, ConnResult.Code);
870         
871         // Get the calendar with the matching name.
872         
873         int ItemSeek = 0;
874         bool ItemFound = false;
875         
876         for (map<int,string>::iterator CalendarNameIter = CalendarList.Name.begin();
877                 CalendarNameIter != CalendarList.Name.end(); CalendarNameIter++){
878                 
879                 if (CalendarNameIter->second == "Scratching Calendar"){
880                         ItemFound = true;
881                         break;
882                 }
883                         
884                 ItemSeek++;
885                         
886         }
888         ASSERT_NE(false, ItemFound);
889         
890         string EntryAddHREF = CalendarList.HREF[ItemSeek];
891         
892         EntryUUID = GenerateUUID();
893         EntryUUID.erase(EntryUUID.end()-1);
894         
895         EntryAddHREF.append(EntryUUID);
896         EntryAddHREF.append(".ics");
897         
898         string AddEntryData = "BEGIN:VCALENDAR\n"
899         "VERSION:2.0\n"
900         "PRODID:-//Xestia//Calendar Unit Testing//KW\n"
901         "BEGIN:VEVENT\n"
902         "UID:";
903         AddEntryData += EntryUUID;
904         AddEntryData += "\n"
905         "DTSTAMP:20160116T190200Z\n"
906         "DTSTART:20160116T190200Z\n"
907         "DTEND:20160116T190200Z\n"
908         "SUMMARY:Unit Test Event 1 which has to be a really long summary as we don't k\n"
909         " now if multiple line processing is going to work without it. I mean seriousl\n"
910         " y, how annoying can this potentially be?\n"
911         "END:VEVENT\n"
912         "END:VCALENDAR\n";
913         
914         ConnResult = ServerConnection.AddEntry(&EntryAddHREF, &AddEntryData);
915         
916         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
917         ASSERT_EQ(201, ConnResult.HTTPCode);
918         ASSERT_EQ(CURLE_OK, ConnResult.Code);
919         
920         // Set the EntryCalendarHREFProcessing for later on.
921         
922         EntryCalendarHREFProcessing = EntryAddHREF;
923         
926 TEST(CalDAV, GetEntryETag){
927         
928         CalDAVConnectionData ConnNormal;
929         string CurrentUserPrincipal;
931         bool ValidDataNormal = false;
932         
933         // Attempt to read the caldavtest.auth file.
935         ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
936         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
937                 ValidDataNormal = true;
938         }
940         ASSERT_EQ(true, ValidDataNormal);
941         
942         // Setup the connection.
943         
944         CalDAV ServerConnection;
945         
946         ServerConnection.SetupConnectionData(&ConnNormal);
947         
948         // Verify the connection settings.
949         
950         CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
951         
952         ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
953         ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
954         ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
955         ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
956         ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
957         
958         // Connect to the server.
959         
960         CalDAVServerResult ConnResult = ServerConnection.Connect();
961         
962         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
963         ASSERT_EQ(200, ConnResult.HTTPCode);
964         ASSERT_EQ(CURLE_OK, ConnResult.Code);
965         
966         // Check that the server supports CalDAV.
967         
968         CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
969         ConnResult = ServerConnection.GetServerResult();
970         
971         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
972         ASSERT_EQ(200, ConnResult.HTTPCode);
973         ASSERT_EQ(CURLE_OK, ConnResult.Code);
974         ASSERT_EQ(true, ConnSupport.BasicSupport);
975         
976         // Get the list of calendars.
977         
978         CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
979         
980         // Check the response result from the server.
981         
982         ConnResult = ServerConnection.GetServerResult();
983         
984         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
985         ASSERT_EQ(207, ConnResult.HTTPCode);
986         ASSERT_EQ(CURLE_OK, ConnResult.Code);
987         
988         // Get the entry entity tag.
989         
990         string ETagValue;
991         
992         ConnResult = ServerConnection.GetEntryETag(&EntryCalendarHREFProcessing, &ETagValue);
993         
994         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
995         ASSERT_EQ(207, ConnResult.HTTPCode);
996         ASSERT_EQ(CURLE_OK, ConnResult.Code);
997         
1000 TEST(CalDAV, EditEntry){
1001         
1002         // Check that EntryCalendarHREFProcessing is not blank. 
1003         
1004         ASSERT_NE("", EntryCalendarHREFProcessing);
1005         
1006         CalDAVConnectionData ConnNormal;
1007         string CurrentUserPrincipal;
1009         bool ValidDataNormal = false;
1010         
1011         // Attempt to read the caldavtest.auth file.
1013         ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
1014         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
1015                 ValidDataNormal = true;
1016         }
1018         ASSERT_EQ(true, ValidDataNormal);
1019         
1020         // Setup the connection.
1021         
1022         CalDAV ServerConnection;
1023         
1024         ServerConnection.SetupConnectionData(&ConnNormal);
1025         
1026         // Verify the connection settings.
1027         
1028         CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
1029         
1030         ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
1031         ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
1032         ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
1033         ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
1034         ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
1035         
1036         // Connect to the server.
1037         
1038         CalDAVServerResult ConnResult = ServerConnection.Connect();
1039         
1040         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
1041         ASSERT_EQ(200, ConnResult.HTTPCode);
1042         ASSERT_EQ(CURLE_OK, ConnResult.Code);
1043         
1044         // Check that the server supports CalDAV.
1045         
1046         CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
1047         ConnResult = ServerConnection.GetServerResult();
1048         
1049         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
1050         ASSERT_EQ(200, ConnResult.HTTPCode);
1051         ASSERT_EQ(CURLE_OK, ConnResult.Code);
1052         ASSERT_EQ(true, ConnSupport.BasicSupport);
1053         
1054         // Get the list of calendars.
1055         
1056         CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
1057         
1058         // Check the response result from the server.
1059         
1060         ConnResult = ServerConnection.GetServerResult();
1061         
1062         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
1063         ASSERT_EQ(207, ConnResult.HTTPCode);
1064         ASSERT_EQ(CURLE_OK, ConnResult.Code);
1066         // Get the entry entity tag.
1067         
1068         string ETagValue;
1069         
1070         ConnResult = ServerConnection.GetEntryETag(&EntryCalendarHREFProcessing, &ETagValue);
1071         
1072         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
1073         ASSERT_EQ(207, ConnResult.HTTPCode);
1074         ASSERT_EQ(CURLE_OK, ConnResult.Code);
1076         // Update the contact with new information.
1078         string EditEntryData = "BEGIN:VCALENDAR\n"
1079         "VERSION:2.0\n"
1080         "PRODID:-//Xestia//Calendar Unit Testing//KW\n"
1081         "BEGIN:VEVENT\n"
1082         "UID:";
1083         EditEntryData += EntryUUID;
1084         EditEntryData += "\n"
1085         "DTSTAMP:20160116T190200Z\n"
1086         "DTSTART:20160116T190200Z\n"
1087         "DTEND:20160116T190200Z\n"
1088         "SUMMARY:Unit Test Event 1 which has to be a really long summary as we don't k\n"
1089         " now if multiple line processing is going to work without it. I mean seriousl\n"
1090         " y, how annoying can this potentially be?\n"
1091         "END:VEVENT\n"
1092         "END:VCALENDAR\n";
1093         
1094         ConnResult = ServerConnection.EditEntry(&EntryCalendarHREFProcessing, &EditEntryData, &ETagValue);
1095         
1096         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
1097         ASSERT_EQ(204, ConnResult.HTTPCode);
1098         ASSERT_EQ(CURLE_OK, ConnResult.Code);
1099         
1102 TEST(CalDAV, DeleteEntry){
1104         // Check that EntryCalendarHREFProcessing is not blank. 
1105         
1106         ASSERT_NE("", EntryCalendarHREFProcessing);
1107         
1108         CalDAVConnectionData ConnNormal;
1109         string CurrentUserPrincipal;
1111         bool ValidDataNormal = false;
1112         
1113         // Attempt to read the caldavtest.auth file.
1115         ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
1116         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
1117                 ValidDataNormal = true;
1118         }
1120         ASSERT_EQ(true, ValidDataNormal);
1121         
1122         // Setup the connection.
1123         
1124         CalDAV ServerConnection;
1125         
1126         ServerConnection.SetupConnectionData(&ConnNormal);
1127         
1128         // Verify the connection settings.
1129         
1130         CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
1131         
1132         ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
1133         ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
1134         ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
1135         ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
1136         ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
1137         
1138         // Connect to the server.
1139         
1140         CalDAVServerResult ConnResult = ServerConnection.Connect();
1141         
1142         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
1143         ASSERT_EQ(200, ConnResult.HTTPCode);
1144         ASSERT_EQ(CURLE_OK, ConnResult.Code);
1145         
1146         // Check that the server supports CalDAV.
1147         
1148         CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
1149         ConnResult = ServerConnection.GetServerResult();
1150         
1151         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
1152         ASSERT_EQ(200, ConnResult.HTTPCode);
1153         ASSERT_EQ(CURLE_OK, ConnResult.Code);
1154         ASSERT_EQ(true, ConnSupport.BasicSupport);
1155         
1156         // Delete the calendar entry.
1157         
1158         ConnResult = ServerConnection.DeleteCalendar(&EntryCalendarHREFProcessing);
1159         
1160         // Check the response result from the server.
1161         
1162         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
1163         ASSERT_EQ(204, ConnResult.HTTPCode);
1164         ASSERT_EQ(CURLE_OK, ConnResult.Code);
1165         
1168 TEST(CalDAV, GetEntryList){
1169         
1170         // Check that EntryCalendarHREFProcessing is not blank. 
1171         
1172         ASSERT_NE("", EntryCalendarHREFProcessing);
1173         
1174         CalDAVConnectionData ConnNormal;
1175         string CurrentUserPrincipal;
1177         bool ValidDataNormal = false;
1178         
1179         // Attempt to read the caldavtest.auth file.
1181         ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
1182         if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
1183                 ValidDataNormal = true;
1184         }
1186         ASSERT_EQ(true, ValidDataNormal);
1187         
1188         // Setup the connection.
1189         
1190         CalDAV ServerConnection;
1191         
1192         ServerConnection.SetupConnectionData(&ConnNormal);
1193         
1194         // Verify the connection settings.
1195         
1196         CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
1197         
1198         ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
1199         ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
1200         ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
1201         ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
1202         ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
1203         
1204         // Connect to the server.
1205         
1206         CalDAVServerResult ConnResult = ServerConnection.Connect();
1207         
1208         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
1209         ASSERT_EQ(200, ConnResult.HTTPCode);
1210         ASSERT_EQ(CURLE_OK, ConnResult.Code);
1211         
1212         // Check that the server supports CalDAV.
1213         
1214         CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
1215         ConnResult = ServerConnection.GetServerResult();
1216         
1217         EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
1218         ASSERT_EQ(200, ConnResult.HTTPCode);
1219         ASSERT_EQ(CURLE_OK, ConnResult.Code);
1220         ASSERT_EQ(true, ConnSupport.BasicSupport);
1221         
1222         // Get the user principal.
1223         
1224         string UserPrincipalURI = ServerConnection.GetUserPrincipal();
1225         
1226         // Get the calendar home.
1227         
1228         string CalendarHomeURL = ServerConnection.GetCalendarHome(UserPrincipalURI);
1230         string CalendarHREF = CalendarHomeURL;
1231         CalendarHREF += "unittestcal/";
1233         // Get the entry list without a calendar tag set.
1234         
1235         CalDAVEntryList EntryList = ServerConnection.GetEntryList(&CalendarHREF);
1237         EXPECT_GE(EntryList.HREF.size(), 1);
1239         // Get the list of calendars.
1240         
1241         CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
1243         string CalendarTagURL = "";
1245         for (std::map<int,string>::iterator CalHREFIter = CalendarList.HREF.begin();
1246                 CalHREFIter != CalendarList.HREF.end(); CalHREFIter++){
1247                         
1248                 if (CalHREFIter->second.substr(CalHREFIter->second.length() - 13) == "/unittestcal/"){
1249                         
1250                         CalendarTagURL = CalendarList.TagURL.find(CalHREFIter->first)->second;
1251                         
1252                 }
1253                         
1254         }
1256         // Get the entry list without a calendar tag set (shouldn't be empty).
1257         
1258         EntryList = ServerConnection.GetEntryList(&CalendarHREF, nullptr);
1260         EXPECT_GE(EntryList.HREF.size(), 1);
1261         
1262         // Get the entry list with a calendar tag set (should be empty).
1263         
1264         EntryList = ServerConnection.GetEntryList(&CalendarHREF, &CalendarTagURL);
1266         EXPECT_EQ(EntryList.HREF.size(), 0);
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