Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
CalDAV: WIP CalDAV support
[xestiacalendar/.git] / source / tests / xestiacalendar_caldav.h
1 // xestiacalendar_caldav.h - Xestia Calendar CalDAV Object Unit Tests
2 //
3 // (c) 2016-2017 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
7 // Xestia Calendar is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Calendar is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Calendar. If not, see <http://www.gnu.org/licenses/>
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)
29 {
31         CalDAVConnectionData connPlain;
32         CalDAVConnectionData connNormal;
33         CalDAVConnectionData connInvalidSSL;
34         CalDAVConnectionData connTimeout;
35         ProcessConnectionDataFileResult dataFileResult;
37         bool validDataPlain = false;
38         bool validDataNormal = false;
39         bool validDataInvalidSSL = false;
40         bool validDataTimeout = false;
42         // Attempt to read the caldavtest-plain.auth file.
43         
44         dataFileResult = ProcessConnectionDataFile("caldavtest-plain.auth", &connPlain);
45         if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
46                 validDataPlain = true;
47         }
48         
49         // Attempt to read the caldavtest.auth file.
51         dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
52         if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
53                 validDataNormal = true;
54         }
55         
56         // Attempt to read the caldavtest-fail.auth file.
57         
58         dataFileResult = ProcessConnectionDataFile("caldavtest-fail.auth", &connInvalidSSL);
59         if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
60                 validDataInvalidSSL = true;
61         }
62         
63         // Attempt to read the caldavtest-timeout.auth file.
64         
65         dataFileResult = ProcessConnectionDataFile("caldavtest-timeout.auth", &connTimeout);
66         if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
67                 validDataTimeout = true;
68         }
70         if (validDataPlain == false){
71         
72                 // Cannot read the caldavtest-plain.auth file properly.
73                 
74                 cout << "The caldavtest-plain.auth file does not exist or is invalid!" << endl;
75                 cout << "Please create the caldavtest-plain.auth file using the following format:" << endl << endl;
76                 cout << "server=localname" << endl;
77                 cout << "port=8080" << endl;
78                 cout << "user=username" << endl;
79                 cout << "pass=password" << endl;
80                 cout << "ssl=false" << endl;
81                 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
82                 
83         }
84         
85         if (validDataNormal == false){
86         
87                 // Cannot read the caldavtest.auth file properly.
88                 
89                 cout << "The caldavtest.auth file does not exist or is invalid!" << endl;
90                 cout << "Please create the caldavtest.auth file using the following format:" << endl << endl;
91                 cout << "server=localname" << endl;
92                 cout << "port=8080" << endl;
93                 cout << "user=username" << endl;
94                 cout << "pass=password" << endl;
95                 cout << "ssl=false" << endl;
96                 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
97                 
98         }
99         
100         if (validDataInvalidSSL == false){
101         
102                 // Cannot read the caldavtest-fail.auth file properly.
103                 
104                 cout << "The caldavtest-fail.auth file does not exist or is invalid!" << endl;
105                 cout << "Please create the caldavtest-fail.auth file using the following format:" << endl << endl;
106                 cout << "server=fail.localname" << endl;
107                 cout << "port=8080" << endl;
108                 cout << "user=username" << endl;
109                 cout << "pass=password" << endl;
110                 cout << "ssl=false" << endl;
111                 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
112                 
113         }
114         
115         if (validDataTimeout == false){
116         
117                 // Cannot read the caldavtest-timeout.auth file properly.
118                 
119                 cout << "The caldavtest-timeout.auth file does not exist or is invalid!" << endl;
120                 cout << "Please create the caldavtest-timeout.auth file using the following format:" << endl << endl;
121                 cout << "server=fail.localname" << endl;
122                 cout << "port=8080" << endl;
123                 cout << "user=username" << endl;
124                 cout << "pass=password" << endl;
125                 cout << "ssl=false" << endl;
126                 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
127                 
128         }
129         
130         ASSERT_EQ(true, validDataPlain);
131         ASSERT_EQ(true, validDataNormal);
132         ASSERT_EQ(true, validDataInvalidSSL);
133         ASSERT_EQ(true, validDataTimeout);
135         // (*nix version) Setup an initial connection (just plain
136         // text).
137         
138         CalDAV calDAVPlain;
139         calDAVPlain.SetupConnectionData(&connPlain);
140         
141         // Verify that the settings match with the CalDAVConnectionData
142         // passed.
143         
144         CalDAVStatus calDAVPlainStatus = calDAVPlain.GetConnectionData();
145         
146         ASSERT_EQ(calDAVPlainStatus.hostname, connPlain.hostname);
147         ASSERT_EQ(calDAVPlainStatus.username, connPlain.username);
148         ASSERT_EQ(calDAVPlainStatus.port, connPlain.port);
149         ASSERT_EQ(calDAVPlainStatus.prefix, connPlain.prefix);
150         ASSERT_EQ(calDAVPlainStatus.useSSL, connPlain.useSSL);
151         
152         // Verify that the connection was successful.
153         
154         CalDAVServerResult connResult = calDAVPlain.Connect();
155         
156         ASSERT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
157         ASSERT_EQ(200, connResult.httpCode);
158         ASSERT_EQ(CURLE_OK, connResult.code);
159         
160         // Do another connection and this time the connection should
161         // fail due to being an invalid host name.
162         
163         CalDAVConnectionData connPlainFail;
164         connPlainFail.hostname = "server.invalid";
165         connPlainFail.username = "fail";
166         connPlainFail.password = "fail";
167         connPlainFail.port = 80;
168         connPlainFail.useSSL = false;
169         
170         // Setup the CalDAV connection object.
171         
172         CalDAV calDAVPlainFail;
173         calDAVPlainFail.SetupConnectionData(&connPlainFail);
174         
175         // Setup the CalDAVStatus object.
176         
177         CalDAVStatus calDAVPlainFailStatus = calDAVPlain.GetConnectionData();
178         
179         // Connect and fail.
180         
181         connResult = calDAVPlainFail.Connect();
182         
183         ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, connResult.result);
184         ASSERT_EQ(0, connResult.httpCode);
185         ASSERT_EQ(CURLE_COULDNT_RESOLVE_HOST, connResult.code);
186         
187         // (*nix version) Setup an initial connection (with a valid
188         // SSL certificate).
190         CalDAV calDAVNormal;
191         calDAVNormal.SetupConnectionData(&connNormal);
193         // Verify that the settings match with the CalDAVConnectionData
194         // passed.
195         
196         CalDAVStatus calDAVNormalStatus = calDAVNormal.GetConnectionData();
197         
198         ASSERT_EQ(calDAVNormalStatus.hostname, connNormal.hostname);
199         ASSERT_EQ(calDAVNormalStatus.username, connNormal.username);
200         ASSERT_EQ(calDAVNormalStatus.port, connNormal.port);
201         ASSERT_EQ(calDAVNormalStatus.prefix, connNormal.prefix);
202         ASSERT_EQ(calDAVNormalStatus.useSSL, connNormal.useSSL);
204         // Verify that the connection was successful (with a valid
205         // SSL certificate).
206         
207         connResult = calDAVNormal.Connect();
208         
209         ASSERT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
210         ASSERT_EQ(200, connResult.httpCode);
211         ASSERT_EQ(CURLE_OK, connResult.code);
212         
213         // (*nix version) Setup an initial connection on a server that
214         // will fail due to having an invalid SSL certificate.
216         CalDAV calDAVInvalidSSL;
217         calDAVInvalidSSL.SetupConnectionData(&connInvalidSSL);
219         // Verify that the settings match with the CalDAVConnectionData
220         // passed.
221         
222         CalDAVStatus calDAVInvalidSSLStatus = calDAVInvalidSSL.GetConnectionData();
223         
224         ASSERT_EQ(calDAVInvalidSSLStatus.hostname, connInvalidSSL.hostname);
225         ASSERT_EQ(calDAVInvalidSSLStatus.username, connInvalidSSL.username);
226         ASSERT_EQ(calDAVInvalidSSLStatus.port, connInvalidSSL.port);
227         ASSERT_EQ(calDAVInvalidSSLStatus.prefix, connInvalidSSL.prefix);
228         ASSERT_EQ(calDAVInvalidSSLStatus.useSSL, connInvalidSSL.useSSL);
229         
230         // Verify that the connection had failed. (with an invalid
231         // SSL certificate).
232         
233         connResult = calDAVInvalidSSL.Connect();
234         
235         ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, connResult.result);
236         ASSERT_EQ(0, connResult.httpCode);
237         ASSERT_EQ(CURLE_SSL_CACERT, connResult.code);
238         
239         // (*nix version) Setup an inital connection on a server where
240         // a timeout occurs.
241         
242         connTimeout.timeout = 5;
243         
244         CalDAV calDAVTimeout;
245         calDAVTimeout.SetupConnectionData(&connTimeout);
247         // Verify that the settings match with the CalDAVConnectionData
248         // passed.
249         
250         CalDAVStatus calDAVTimeoutStatus = calDAVTimeout.GetConnectionData();
251         
252         ASSERT_EQ(calDAVTimeoutStatus.hostname, connTimeout.hostname);
253         ASSERT_EQ(calDAVTimeoutStatus.username, connTimeout.username);
254         ASSERT_EQ(calDAVTimeoutStatus.port, connTimeout.port);
255         ASSERT_EQ(calDAVTimeoutStatus.prefix, connTimeout.prefix);
256         ASSERT_EQ(calDAVTimeoutStatus.timeout, connTimeout.timeout);
257         ASSERT_EQ(calDAVTimeoutStatus.useSSL, connTimeout.useSSL);
258         
259         // Verify that the connection had timed out.
260         
261         connResult = calDAVTimeout.Connect();
262         
263         ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, connResult.result);
264         ASSERT_EQ(0, connResult.httpCode);
265         ASSERT_EQ(CURLE_OPERATION_TIMEDOUT, connResult.code);
266         
269 TEST(CalDAV, BuildServerAddress)
272         CalDAVConnectionData connNormal;
273         ProcessConnectionDataFileResult dataFileResult;
274         bool validDataNormal = false;
275         
276         // Attempt to read the caldavtest.auth file.
278         dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
279         if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
280                 validDataNormal = true;
281         }
282         
283         if (validDataNormal == false){
284         
285                 // Cannot read the caldavtest.auth file properly.
286                 
287                 cout << "The caldavtest.auth file does not exist or is invalid!" << endl;
288                 cout << "Please create the caldavtest.auth file using the following format:" << endl << endl;
289                 cout << "server=localname" << endl;
290                 cout << "port=8080" << endl;
291                 cout << "user=username" << endl;
292                 cout << "pass=password" << endl;
293                 cout << "ssl=false" << endl;
294                 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
295                 
296         }
297         
298         ASSERT_EQ(true, validDataNormal);
299         
300         // Setup the server address to check.
301         
302         string serverAddress;
303         
304         // Setup the server address.
305         
306         if (connNormal.useSSL == true){
307                 serverAddress += "https://";
308         } else {
309                 serverAddress += "http://";
310         }
311         
312         serverAddress += connNormal.hostname;
313         
314         // Check if server port is 80, otherwise
315         // specifiy the port number in the address.
316         
317         if (connNormal.port != 80){
318                 serverAddress += ":";
319                 serverAddress += to_string(connNormal.port);
320         }
321         
322         serverAddress += "/principals/";
323         
324         ASSERT_EQ(serverAddress, BuildServerAddress(&connNormal, "/principals/"));
325         
328 TEST(CalDAV, CalendarServerSupport)
330         
331         CalDAVConnectionData connNormal;
333         bool validDataNormal = false;
334         
335         // Attempt to read the caldavtest.auth file.
337         ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
338         if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
339                 validDataNormal = true;
340         }
342         ASSERT_EQ(true, validDataNormal);
343         
344         // Setup the connection.
345         
346         CalDAV serverConnection;
347         
348         serverConnection.SetupConnectionData(&connNormal);
349         
350         // Verify the connection settings.
351         
352         CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
353         
354         ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
355         ASSERT_EQ(calDAVStatus.username, connNormal.username);
356         ASSERT_EQ(calDAVStatus.port, connNormal.port);
357         ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
358         ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
359         
360         // Connect to the server.
361         
362         CalDAVServerResult connResult = serverConnection.Connect();
363         
364         ASSERT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
365         ASSERT_EQ(200, connResult.httpCode);
366         ASSERT_EQ(CURLE_OK, connResult.code);
367         
368         // Check for basic support of the calendar server.
369         
370         CalDAVServerSupport connSupport = serverConnection.GetServerSupport();
371         
372         ASSERT_EQ(true, connSupport.basicSupport);
373         
376 TEST(CalDAV, GetCalendarHome)
378  
379         CalDAVConnectionData connNormal;        
381         bool validDataNormal = false;
382         
383         // Attempt to read the caldavtest.auth file.
385         ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
386         if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
387                 validDataNormal = true;
388         }
390         ASSERT_EQ(true, validDataNormal);
391         
392         // Setup the connection.
393         
394         CalDAV serverConnection;
395         
396         serverConnection.SetupConnectionData(&connNormal);
397         
398         // Verify the connection settings.
399         
400         CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
401         
402         ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
403         ASSERT_EQ(calDAVStatus.username, connNormal.username);
404         ASSERT_EQ(calDAVStatus.port, connNormal.port);
405         ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
406         ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
407         
408         // Connect to the server.
409         
410         CalDAVServerResult connResult = serverConnection.Connect();
411         
412         ASSERT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
413         ASSERT_EQ(200, connResult.httpCode);
414         ASSERT_EQ(CURLE_OK, connResult.code);
415         
416         // Check for basic support of the calendar server.
417         
418         CalDAVServerSupport connSupport = serverConnection.GetServerSupport();
419         
420         ASSERT_EQ(true, connSupport.basicSupport);
421         
422         // Get the user principal.
423         
424         string currentUserPrincipal = serverConnection.GetUserPrincipal();
425         
426         // Check the response from the server.
427         
428         connResult = serverConnection.GetServerResult();
429         
430         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
431         ASSERT_EQ(207, connResult.httpCode);
432         ASSERT_EQ(CURLE_OK, connResult.code);
433         
434         // Get the calendar home.
435         
436         string calendarHome = serverConnection.GetCalendarHome(currentUserPrincipal);
437         
438         // Check the response from the server.
439         
440         connResult = serverConnection.GetServerResult();
441         
442         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
443         ASSERT_EQ(207, connResult.httpCode);
444         ASSERT_EQ(CURLE_OK, connResult.code);
445   
448 TEST(CalDAV, ListCalendars)
450         
451         CalDAVConnectionData connNormal;
452         string currentUserPrincipal;
454         bool validDataNormal = false;
455         
456         // Attempt to read the caldavtest.auth file.
458         ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
459         if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
460                 validDataNormal = true;
461         }
463         ASSERT_EQ(true, validDataNormal);
464         
465         // Setup the connection.
466         
467         CalDAV serverConnection;
468         
469         serverConnection.SetupConnectionData(&connNormal);
470         
471         // Verify the connection settings.
472         
473         CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
474         
475         ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
476         ASSERT_EQ(calDAVStatus.username, connNormal.username);
477         ASSERT_EQ(calDAVStatus.port, connNormal.port);
478         ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
479         ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
480         
481         // Connect to the server.
482         
483         CalDAVServerResult connResult = serverConnection.Connect();
484         
485         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
486         ASSERT_EQ(200, connResult.httpCode);
487         ASSERT_EQ(CURLE_OK, connResult.code);
488         
489         // Check that the server supports CalDAV.
490         
491         CalDAVServerSupport connSupport = serverConnection.GetServerSupport();
492         connResult = serverConnection.GetServerResult();
493         
494         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
495         ASSERT_EQ(200, connResult.httpCode);
496         ASSERT_EQ(CURLE_OK, connResult.code);
497         ASSERT_EQ(true, connSupport.basicSupport);
498         
499         // Get the list of calendars.
500         
501         CalDAVCalendarList calendarList = serverConnection.GetCalendars();
502         
503         // Check the response result from the server.
504         
505         connResult = serverConnection.GetServerResult();
506         
507         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
508         ASSERT_EQ(207, connResult.httpCode);
509         ASSERT_EQ(CURLE_OK, connResult.code);
510         
513 TEST(CalDAV, AddCalendar)
515         
516         CalDAVConnectionData connNormal;
517         string currentUserPrincipal;
519         bool validDataNormal = false;
520         
521         // Attempt to read the caldavtest.auth file.
523         ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
524         if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
525                 validDataNormal = true;
526         }
528         ASSERT_EQ(true, validDataNormal);
529         
530         // Setup the connection.
531         
532         CalDAV serverConnection;
533         
534         serverConnection.SetupConnectionData(&connNormal);
535         
536         // Verify the connection settings.
537         
538         CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
539         
540         ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
541         ASSERT_EQ(calDAVStatus.username, connNormal.username);
542         ASSERT_EQ(calDAVStatus.port, connNormal.port);
543         ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
544         ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
545         
546         // Connect to the server.
547         
548         CalDAVServerResult connResult = serverConnection.Connect();
549         
550         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
551         ASSERT_EQ(200, connResult.httpCode);
552         ASSERT_EQ(CURLE_OK, connResult.code);
553         
554         // Add a calendar to the server.
555         
556         connResult = serverConnection.AddCalendar("New Calendar");
557         
558         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
559         ASSERT_EQ(201, connResult.httpCode);
560         ASSERT_EQ(CURLE_OK, connResult.code);
561         
564 TEST(CalDAV, EditCalendar)
566         
567         CalDAVConnectionData connNormal;
568         string currentUserPrincipal;
570         bool validDataNormal = false;
571         
572         // Attempt to read the caldavtest.auth file.
574         ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
575         if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
576                 validDataNormal = true;
577         }
579         ASSERT_EQ(true, validDataNormal);
580         
581         // Setup the connection.
582         
583         CalDAV serverConnection;
584         
585         serverConnection.SetupConnectionData(&connNormal);
586         
587         // Verify the connection settings.
588         
589         CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
590         
591         ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
592         ASSERT_EQ(calDAVStatus.username, connNormal.username);
593         ASSERT_EQ(calDAVStatus.port, connNormal.port);
594         ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
595         ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
596         
597         // Connect to the server.
598         
599         CalDAVServerResult connResult = serverConnection.Connect();
600         
601         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
602         ASSERT_EQ(200, connResult.httpCode);
603         ASSERT_EQ(CURLE_OK, connResult.code);
604         
605         // Check that the server supports CalDAV.
606         
607         CalDAVServerSupport connSupport = serverConnection.GetServerSupport();
608         connResult = serverConnection.GetServerResult();
609         
610         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
611         ASSERT_EQ(200, connResult.httpCode);
612         ASSERT_EQ(CURLE_OK, connResult.code);
613         ASSERT_EQ(true, connSupport.basicSupport);
614         
615         // Add a calendar to the server.
616         
617         connResult = serverConnection.AddCalendar("Calendar To Edit");
618         
619         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
620         ASSERT_EQ(201, connResult.httpCode);
621         ASSERT_EQ(CURLE_OK, connResult.code);
622         
623         // Get the list of calendars.
624         
625         CalDAVCalendarList calendarList = serverConnection.GetCalendars();
626         
627         // Check the response result from the server.
628         
629         connResult = serverConnection.GetServerResult();
630         
631         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
632         ASSERT_EQ(207, connResult.httpCode);
633         ASSERT_EQ(CURLE_OK, connResult.code);
634         
635         // Find the calendar containing the name "Calendar To Edit"
636         // created earlier.
637         
638         int itemSeek = 0;
639         bool itemFound = false;
640         
641         for (map<int,string>::iterator calendarNameIter = calendarList.name.begin();
642                 calendarNameIter != calendarList.name.end(); calendarNameIter++){
643                 
644                 if (calendarNameIter->second == "Calendar To Edit"){
645                         itemFound = true;
646                         break;
647                 }
648                         
649                 itemSeek++;
650                         
651         }
652         
653         ASSERT_NE(false, itemFound);
654         
655         // Edit the name of the calendar.
656         
657         string calendarEditHREF = calendarList.href[itemSeek];
658         string newCalendarName = "Edited Calendar";
659         
660         connResult = serverConnection.EditCalendar(&calendarEditHREF, &newCalendarName);
661         
662         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
663         ASSERT_EQ(207, connResult.httpCode);
664         ASSERT_EQ(CURLE_OK, connResult.code);
665         
666         // Edit the colour of the calendar.
668         Colour newColour;
669         
670         newColour.red = 255;
671         newColour.green = 0;
672         newColour.blue = 0;
673         newColour.alpha = 0;
674         
675         connResult = serverConnection.EditCalendar(&calendarEditHREF, &newColour);
676         
677         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
678         ASSERT_EQ(207, connResult.httpCode);
679         ASSERT_EQ(CURLE_OK, connResult.code);
680         
681         // Edit the description of the calendar.
683         string newCalendarDescription = "Update Calendar Description";
685         connResult = serverConnection.EditCalendarDescription(&calendarEditHREF, &newCalendarDescription);
686         
687         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
688         ASSERT_EQ(207, connResult.httpCode);
689         ASSERT_EQ(CURLE_OK, connResult.code);
690         
691         // Edit the order of the calendar.
692         
693         int newCalendarOrder = 30;
694         
695         connResult = serverConnection.EditCalendar(&calendarEditHREF, &newCalendarOrder);
696         
697         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
698         ASSERT_EQ(207, connResult.httpCode);
699         ASSERT_EQ(CURLE_OK, connResult.code);
700         
701         // Edit all of the available properties of the calendar.
702         
703         newCalendarName = "Calendar Edited Again";
704         newCalendarDescription = "Another updated calendar description";
705         newColour.red = 0;
706         newColour.green = 255;
707         newColour.blue = 0;
708         newColour.alpha = 0;
709         newCalendarOrder = 40;
710         
711         connResult = serverConnection.EditCalendar(&calendarEditHREF, 
712                 &newCalendarName,
713                 &newColour,
714                 &newCalendarDescription,
715                 &newCalendarOrder);
716         
717         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
718         ASSERT_EQ(207, connResult.httpCode);
719         ASSERT_EQ(CURLE_OK, connResult.code);
720         
723 TEST(CalDAV, DeleteCalendar)
726         CalDAVConnectionData connNormal;
727         string currentUserPrincipal;
729         bool validDataNormal = false;
730         
731         // Attempt to read the caldavtest.auth file.
733         ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
734         if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
735                 validDataNormal = true;
736         }
738         ASSERT_EQ(true, validDataNormal);
739         
740         // Setup the connection.
741         
742         CalDAV serverConnection;
743         
744         serverConnection.SetupConnectionData(&connNormal);
745         
746         // Verify the connection settings.
747         
748         CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
749         
750         ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
751         ASSERT_EQ(calDAVStatus.username, connNormal.username);
752         ASSERT_EQ(calDAVStatus.port, connNormal.port);
753         ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
754         ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
755         
756         // Connect to the server.
757         
758         CalDAVServerResult connResult = serverConnection.Connect();
759         
760         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
761         ASSERT_EQ(200, connResult.httpCode);
762         ASSERT_EQ(CURLE_OK, connResult.code);
763         
764         // Check that the server supports CalDAV.
765         
766         CalDAVServerSupport connSupport = serverConnection.GetServerSupport();
767         connResult = serverConnection.GetServerResult();
768         
769         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
770         ASSERT_EQ(200, connResult.httpCode);
771         ASSERT_EQ(CURLE_OK, connResult.code);
772         ASSERT_EQ(true, connSupport.basicSupport);
773         
774         // Get the list of calendars.
775         
776         CalDAVCalendarList calendarList = serverConnection.GetCalendars();
777         
778         // Check the response result from the server.
779         
780         connResult = serverConnection.GetServerResult();
781         
782         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
783         ASSERT_EQ(207, connResult.httpCode);
784         ASSERT_EQ(CURLE_OK, connResult.code);
785         
786         // Get the calendar with the matching name.
787         
788         int itemSeek = 0;
789         bool itemFound = false;
790         
791         for (map<int,string>::iterator calendarNameIter = calendarList.name.begin();
792                 calendarNameIter != calendarList.name.end(); calendarNameIter++){
793                 
794                 if (calendarNameIter->second == "Calendar Edited Again"){
795                         itemFound = true;
796                         break;
797                 }
798                         
799                 itemSeek++;
800                         
801         }
803         ASSERT_NE(false, itemFound);
804         
805         // Delete some calendars.
806         
807         string calendarEditHREF = calendarList.href[itemSeek];
808         
809         connResult = serverConnection.DeleteCalendar(&calendarEditHREF);
810         
811         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
812         ASSERT_EQ(204, connResult.httpCode);
813         ASSERT_EQ(CURLE_OK, connResult.code);
814         
817 TEST(CalDAV, AddEntry)
819         
820         CalDAVConnectionData connNormal;
821         string currentUserPrincipal;
823         bool validDataNormal = false;
824         
825         // Attempt to read the caldavtest.auth file.
827         ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
828         if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
829                 validDataNormal = true;
830         }
832         ASSERT_EQ(true, validDataNormal);
833         
834         // Setup the connection.
835         
836         CalDAV serverConnection;
837         
838         serverConnection.SetupConnectionData(&connNormal);
839         
840         // Verify the connection settings.
841         
842         CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
843         
844         ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
845         ASSERT_EQ(calDAVStatus.username, connNormal.username);
846         ASSERT_EQ(calDAVStatus.port, connNormal.port);
847         ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
848         ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
849         
850         // Connect to the server.
851         
852         CalDAVServerResult connResult = serverConnection.Connect();
853         
854         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
855         ASSERT_EQ(200, connResult.httpCode);
856         ASSERT_EQ(CURLE_OK, connResult.code);
857         
858         // Check that the server supports CalDAV.
859         
860         CalDAVServerSupport connSupport = serverConnection.GetServerSupport();
861         connResult = serverConnection.GetServerResult();
862         
863         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
864         ASSERT_EQ(200, connResult.httpCode);
865         ASSERT_EQ(CURLE_OK, connResult.code);
866         ASSERT_EQ(true, connSupport.basicSupport);
867         
868         // Get the list of calendars.
869         
870         CalDAVCalendarList calendarList = serverConnection.GetCalendars();
871         
872         // Check the response result from the server.
873         
874         connResult = serverConnection.GetServerResult();
875         
876         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
877         ASSERT_EQ(207, connResult.httpCode);
878         ASSERT_EQ(CURLE_OK, connResult.code);
879         
880         // Get the calendar with the matching name.
881         
882         int itemSeek = 0;
883         bool itemFound = false;
884         
885         for (map<int,string>::iterator calendarNameIter = calendarList.name.begin();
886                 calendarNameIter != calendarList.name.end(); calendarNameIter++){
887                 
888                 if (calendarNameIter->second == "Scratching Calendar"){
889                         itemFound = true;
890                         break;
891                 }
892                         
893                 itemSeek++;
894                         
895         }
897         ASSERT_NE(false, itemFound);
898         
899         string entryAddHREF = calendarList.href[itemSeek];
900         
901         entryUUID = GenerateUUID();
902         entryUUID.erase(entryUUID.end()-1);
903         
904         entryAddHREF.append(entryUUID);
905         entryAddHREF.append(".ics");
906         
907         string addEntryData = "BEGIN:VCALENDAR\n"
908         "VERSION:2.0\n"
909         "PRODID:-//Xestia//Calendar Unit Testing//KW\n"
910         "BEGIN:VEVENT\n"
911         "UID:";
912         addEntryData += entryUUID;
913         addEntryData += "\n"
914         "DTSTAMP:20160116T190200Z\n"
915         "DTSTART:20160116T190200Z\n"
916         "DTEND:20160116T190200Z\n"
917         "SUMMARY:Unit Test Event 1 which has to be a really long summary as we don't k\n"
918         " now if multiple line processing is going to work without it. I mean seriousl\n"
919         " y, how annoying can this potentially be?\n"
920         "END:VEVENT\n"
921         "END:VCALENDAR\n";
922         
923         connResult = serverConnection.AddEntry(&entryAddHREF, &addEntryData);
924         
925         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
926         ASSERT_EQ(201, connResult.httpCode);
927         ASSERT_EQ(CURLE_OK, connResult.code);
928         
929         // Set the EntryCalendarHREFProcessing for later on.
930         
931         entryCalendarHREFProcessing = entryAddHREF;
932         
935 TEST(CalDAV, GetEntryETag)
937         
938         CalDAVConnectionData connNormal;
939         string currentUserPrincipal;
941         bool validDataNormal = false;
942         
943         // Attempt to read the caldavtest.auth file.
945         ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
946         if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
947                 validDataNormal = true;
948         }
950         ASSERT_EQ(true, validDataNormal);
951         
952         // Setup the connection.
953         
954         CalDAV serverConnection;
955         
956         serverConnection.SetupConnectionData(&connNormal);
957         
958         // Verify the connection settings.
959         
960         CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
961         
962         ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
963         ASSERT_EQ(calDAVStatus.username, connNormal.username);
964         ASSERT_EQ(calDAVStatus.port, connNormal.port);
965         ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
966         ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
967         
968         // Connect to the server.
969         
970         CalDAVServerResult connResult = serverConnection.Connect();
971         
972         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
973         ASSERT_EQ(200, connResult.httpCode);
974         ASSERT_EQ(CURLE_OK, connResult.code);
975         
976         // Check that the server supports CalDAV.
977         
978         CalDAVServerSupport connSupport = serverConnection.GetServerSupport();
979         connResult = serverConnection.GetServerResult();
980         
981         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
982         ASSERT_EQ(200, connResult.httpCode);
983         ASSERT_EQ(CURLE_OK, connResult.code);
984         ASSERT_EQ(true, connSupport.basicSupport);
985         
986         // Get the list of calendars.
987         
988         CalDAVCalendarList calendarList = serverConnection.GetCalendars();
989         
990         // Check the response result from the server.
991         
992         connResult = serverConnection.GetServerResult();
993         
994         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
995         ASSERT_EQ(207, connResult.httpCode);
996         ASSERT_EQ(CURLE_OK, connResult.code);
997         
998         // Get the entry entity tag.
999         
1000         string eTagValue;
1001         
1002         connResult = serverConnection.GetEntryETag(&entryCalendarHREFProcessing, &eTagValue);
1003         
1004         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1005         ASSERT_EQ(207, connResult.httpCode);
1006         ASSERT_EQ(CURLE_OK, connResult.code);
1007         
1010 TEST(CalDAV, EditEntry)
1012         
1013         // Check that EntryCalendarHREFProcessing is not blank. 
1014         
1015         ASSERT_NE("", entryCalendarHREFProcessing);
1016         
1017         CalDAVConnectionData connNormal;
1018         string currentUserPrincipal;
1020         bool validDataNormal = false;
1021         
1022         // Attempt to read the caldavtest.auth file.
1024         ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
1025         if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
1026                 validDataNormal = true;
1027         }
1029         ASSERT_EQ(true, validDataNormal);
1030         
1031         // Setup the connection.
1032         
1033         CalDAV serverConnection;
1034         
1035         serverConnection.SetupConnectionData(&connNormal);
1036         
1037         // Verify the connection settings.
1038         
1039         CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
1040         
1041         ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
1042         ASSERT_EQ(calDAVStatus.username, connNormal.username);
1043         ASSERT_EQ(calDAVStatus.port, connNormal.port);
1044         ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
1045         ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
1046         
1047         // Connect to the server.
1048         
1049         CalDAVServerResult connResult = serverConnection.Connect();
1050         
1051         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1052         ASSERT_EQ(200, connResult.httpCode);
1053         ASSERT_EQ(CURLE_OK, connResult.code);
1054         
1055         // Check that the server supports CalDAV.
1056         
1057         CalDAVServerSupport connSupport = serverConnection.GetServerSupport();
1058         connResult = serverConnection.GetServerResult();
1059         
1060         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1061         ASSERT_EQ(200, connResult.httpCode);
1062         ASSERT_EQ(CURLE_OK, connResult.code);
1063         ASSERT_EQ(true, connSupport.basicSupport);
1064         
1065         // Get the list of calendars.
1066         
1067         CalDAVCalendarList calendarList = serverConnection.GetCalendars();
1068         
1069         // Check the response result from the server.
1070         
1071         connResult = serverConnection.GetServerResult();
1072         
1073         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1074         ASSERT_EQ(207, connResult.httpCode);
1075         ASSERT_EQ(CURLE_OK, connResult.code);
1077         // Get the entry entity tag.
1078         
1079         string eTagValue;
1080         
1081         connResult = serverConnection.GetEntryETag(&entryCalendarHREFProcessing, &eTagValue);
1082         
1083         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1084         ASSERT_EQ(207, connResult.httpCode);
1085         ASSERT_EQ(CURLE_OK, connResult.code);
1087         // Update the contact with new information.
1089         string editEntryData = "BEGIN:VCALENDAR\n"
1090         "VERSION:2.0\n"
1091         "PRODID:-//Xestia//Calendar Unit Testing//KW\n"
1092         "BEGIN:VEVENT\n"
1093         "UID:";
1094         editEntryData += entryUUID;
1095         editEntryData += "\n"
1096         "DTSTAMP:20160116T190200Z\n"
1097         "DTSTART:20160116T190200Z\n"
1098         "DTEND:20160116T190200Z\n"
1099         "SUMMARY:Unit Test Event 1 which has to be a really long summary as we don't k\n"
1100         " now if multiple line processing is going to work without it. I mean seriousl\n"
1101         " y, how annoying can this potentially be?\n"
1102         "END:VEVENT\n"
1103         "END:VCALENDAR\n";
1104         
1105         connResult = serverConnection.EditEntry(&entryCalendarHREFProcessing, &editEntryData, &eTagValue);
1106         
1107         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1108         ASSERT_EQ(204, connResult.httpCode);
1109         ASSERT_EQ(CURLE_OK, connResult.code);
1110         
1113 TEST(CalDAV, DeleteEntry)
1116         // Check that EntryCalendarHREFProcessing is not blank. 
1117         
1118         ASSERT_NE("", entryCalendarHREFProcessing);
1119         
1120         CalDAVConnectionData connNormal;
1121         string currentUserPrincipal;
1123         bool validDataNormal = false;
1124         
1125         // Attempt to read the caldavtest.auth file.
1127         ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
1128         if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
1129                 validDataNormal = true;
1130         }
1132         ASSERT_EQ(true, validDataNormal);
1133         
1134         // Setup the connection.
1135         
1136         CalDAV serverConnection;
1137         
1138         serverConnection.SetupConnectionData(&connNormal);
1139         
1140         // Verify the connection settings.
1141         
1142         CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
1143         
1144         ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
1145         ASSERT_EQ(calDAVStatus.username, connNormal.username);
1146         ASSERT_EQ(calDAVStatus.port, connNormal.port);
1147         ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
1148         ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
1149         
1150         // Connect to the server.
1151         
1152         CalDAVServerResult connResult = serverConnection.Connect();
1153         
1154         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1155         ASSERT_EQ(200, connResult.httpCode);
1156         ASSERT_EQ(CURLE_OK, connResult.code);
1157         
1158         // Check that the server supports CalDAV.
1159         
1160         CalDAVServerSupport connSupport = serverConnection.GetServerSupport();
1161         connResult = serverConnection.GetServerResult();
1162         
1163         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1164         ASSERT_EQ(200, connResult.httpCode);
1165         ASSERT_EQ(CURLE_OK, connResult.code);
1166         ASSERT_EQ(true, connSupport.basicSupport);
1167         
1168         // Delete the calendar entry.
1169         
1170         connResult = serverConnection.DeleteCalendar(&entryCalendarHREFProcessing);
1171         
1172         // Check the response result from the server.
1173         
1174         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1175         ASSERT_EQ(204, connResult.httpCode);
1176         ASSERT_EQ(CURLE_OK, connResult.code);
1177         
1180 TEST(CalDAV, GetEntryList)
1182         
1183         // Check that EntryCalendarHREFProcessing is not blank. 
1184         
1185         ASSERT_NE("", entryCalendarHREFProcessing);
1186         
1187         CalDAVConnectionData connNormal;
1188         string currentUserPrincipal;
1190         bool validDataNormal = false;
1191         
1192         // Attempt to read the caldavtest.auth file.
1194         ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
1195         if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
1196                 validDataNormal = true;
1197         }
1199         ASSERT_EQ(true, validDataNormal);
1200         
1201         // Setup the connection.
1202         
1203         CalDAV serverConnection;
1204         
1205         serverConnection.SetupConnectionData(&connNormal);
1206         
1207         // Verify the connection settings.
1208         
1209         CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
1210         
1211         ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
1212         ASSERT_EQ(calDAVStatus.username, connNormal.username);
1213         ASSERT_EQ(calDAVStatus.port, connNormal.port);
1214         ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
1215         ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
1216         
1217         // Connect to the server.
1218         
1219         CalDAVServerResult connResult = serverConnection.Connect();
1220         
1221         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1222         ASSERT_EQ(200, connResult.httpCode);
1223         ASSERT_EQ(CURLE_OK, connResult.code);
1224         
1225         // Check that the server supports CalDAV.
1226         
1227         CalDAVServerSupport connSupport = serverConnection.GetServerSupport();
1228         connResult = serverConnection.GetServerResult();
1229         
1230         EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1231         ASSERT_EQ(200, connResult.httpCode);
1232         ASSERT_EQ(CURLE_OK, connResult.code);
1233         ASSERT_EQ(true, connSupport.basicSupport);
1234         
1235         // Get the user principal.
1236         
1237         string userPrincipalURI = serverConnection.GetUserPrincipal();
1238         
1239         // Get the calendar home.
1240         
1241         string calendarHomeURL = serverConnection.GetCalendarHome(userPrincipalURI);
1243         string calendarHREF = calendarHomeURL;
1244         calendarHREF += "unittestcal/";
1246         // Get the entry list without a calendar tag set.
1247         
1248         CalDAVEntryList entryList = serverConnection.GetEntryList(&calendarHREF);
1250         EXPECT_GE(entryList.href.size(), 1);
1252         // Get the list of calendars.
1253         
1254         CalDAVCalendarList calendarList = serverConnection.GetCalendars();
1256         string calendarTagURL = "";
1258         for (std::map<int,string>::iterator calHREFIter = calendarList.href.begin();
1259                 calHREFIter != calendarList.href.end(); calHREFIter++){
1260                         
1261                 if (calHREFIter->second.substr(calHREFIter->second.length() - 13) == "/unittestcal/"){
1262                         
1263                         calendarTagURL = calendarList.tagURL.find(calHREFIter->first)->second;
1264                         
1265                 }
1266                         
1267         }
1269         // Get the entry list without a calendar tag set (shouldn't be empty).
1270         
1271         entryList = serverConnection.GetEntryList(&calendarHREF, nullptr);
1273         EXPECT_GE(entryList.href.size(), 1);
1274         
1275         // Get the entry list with a calendar tag set (should be empty).
1276         
1277         entryList = serverConnection.GetEntryList(&calendarHREF, &calendarTagURL);
1279         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