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