Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
56f321717d4ac2426727f8ae110251c9c48a8a4f
[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){
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