1 // xestiacalendar_caldav.h - Xestia Calendar CalDAV Object Unit Tests
3 // (c) 2016 Xestia Software Development.
5 // This file is part of Xestia Calendar.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
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"
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.
43 DataFileResult = ProcessConnectionDataFile("caldavtest-plain.auth", &ConnPlain);
44 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
45 ValidDataPlain = true;
48 // Attempt to read the caldavtest.auth file.
50 DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
51 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
52 ValidDataNormal = true;
55 // Attempt to read the caldavtest-fail.auth file.
57 DataFileResult = ProcessConnectionDataFile("caldavtest-fail.auth", &ConnInvalidSSL);
58 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
59 ValidDataInvalidSSL = true;
62 // Attempt to read the caldavtest-timeout.auth file.
64 DataFileResult = ProcessConnectionDataFile("caldavtest-timeout.auth", &ConnTimeout);
65 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
66 ValidDataTimeout = true;
69 if (ValidDataPlain == false){
71 // Cannot read the caldavtest-plain.auth file properly.
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;
84 if (ValidDataNormal == false){
86 // Cannot read the caldavtest.auth file properly.
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;
99 if (ValidDataInvalidSSL == false){
101 // Cannot read the caldavtest-fail.auth file properly.
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;
114 if (ValidDataTimeout == false){
116 // Cannot read the caldavtest-timeout.auth file properly.
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;
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
138 CalDAVPlain.SetupConnectionData(&ConnPlain);
140 // Verify that the settings match with the CalDAVConnectionData
143 CalDAVStatus CalDAVPlainStatus = CalDAVPlain.GetConnectionData();
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);
151 // Verify that the connection was successful.
153 CalDAVServerResult ConnResult = CalDAVPlain.Connect();
155 ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
156 ASSERT_EQ(200, ConnResult.HTTPCode);
157 ASSERT_EQ(CURLE_OK, ConnResult.Code);
159 // Do another connection and this time the connection should
160 // fail due to being an invalid host name.
162 CalDAVConnectionData ConnPlainFail;
163 ConnPlainFail.Hostname = "server.invalid";
164 ConnPlainFail.Username = "fail";
165 ConnPlainFail.Password = "fail";
166 ConnPlainFail.Port = 80;
167 ConnPlainFail.UseSSL = false;
169 // Setup the CalDAV connection object.
171 CalDAV CalDAVPlainFail;
172 CalDAVPlainFail.SetupConnectionData(&ConnPlainFail);
174 // Setup the CalDAVStatus object.
176 CalDAVStatus CalDAVPlainFailStatus = CalDAVPlain.GetConnectionData();
180 ConnResult = CalDAVPlainFail.Connect();
182 ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, ConnResult.Result);
183 ASSERT_EQ(0, ConnResult.HTTPCode);
184 ASSERT_EQ(CURLE_COULDNT_RESOLVE_HOST, ConnResult.Code);
186 // (*nix version) Setup an initial connection (with a valid
190 CalDAVNormal.SetupConnectionData(&ConnNormal);
192 // Verify that the settings match with the CalDAVConnectionData
195 CalDAVStatus CalDAVNormalStatus = CalDAVNormal.GetConnectionData();
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
206 ConnResult = CalDAVNormal.Connect();
208 ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
209 ASSERT_EQ(200, ConnResult.HTTPCode);
210 ASSERT_EQ(CURLE_OK, ConnResult.Code);
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
221 CalDAVStatus CalDAVInvalidSSLStatus = CalDAVInvalidSSL.GetConnectionData();
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);
229 // Verify that the connection had failed. (with an invalid
232 ConnResult = CalDAVInvalidSSL.Connect();
234 ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, ConnResult.Result);
235 ASSERT_EQ(0, ConnResult.HTTPCode);
236 ASSERT_EQ(CURLE_SSL_CACERT, ConnResult.Code);
238 // (*nix version) Setup an inital connection on a server where
241 ConnTimeout.Timeout = 5;
243 CalDAV CalDAVTimeout;
244 CalDAVTimeout.SetupConnectionData(&ConnTimeout);
246 // Verify that the settings match with the CalDAVConnectionData
249 CalDAVStatus CalDAVTimeoutStatus = CalDAVTimeout.GetConnectionData();
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);
258 // Verify that the connection had timed out.
260 ConnResult = CalDAVTimeout.Connect();
262 ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, ConnResult.Result);
263 ASSERT_EQ(0, ConnResult.HTTPCode);
264 ASSERT_EQ(CURLE_OPERATION_TIMEDOUT, ConnResult.Code);
268 TEST(CalDAV, BuildServerAddress){
270 CalDAVConnectionData ConnNormal;
271 ProcessConnectionDataFileResult DataFileResult;
272 bool ValidDataNormal = false;
274 // Attempt to read the caldavtest.auth file.
276 DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
277 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
278 ValidDataNormal = true;
281 if (ValidDataNormal == false){
283 // Cannot read the caldavtest.auth file properly.
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;
296 ASSERT_EQ(true, ValidDataNormal);
298 // Setup the server address to check.
300 string ServerAddress;
302 // Setup the server address.
304 if (ConnNormal.UseSSL == true){
305 ServerAddress += "https://";
307 ServerAddress += "http://";
310 ServerAddress += ConnNormal.Hostname;
312 // Check if server port is 80, otherwise
313 // specifiy the port number in the address.
315 if (ConnNormal.Port != 80){
316 ServerAddress += ":";
317 ServerAddress += to_string(ConnNormal.Port);
320 ServerAddress += "/principals/";
322 ASSERT_EQ(ServerAddress, BuildServerAddress(&ConnNormal, "/principals/"));
326 TEST(CalDAV, CalendarServerSupport){
328 CalDAVConnectionData ConnNormal;
330 bool ValidDataNormal = false;
332 // Attempt to read the caldavtest.auth file.
334 ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
335 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
336 ValidDataNormal = true;
339 ASSERT_EQ(true, ValidDataNormal);
341 // Setup the connection.
343 CalDAV ServerConnection;
345 ServerConnection.SetupConnectionData(&ConnNormal);
347 // Verify the connection settings.
349 CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
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);
357 // Connect to the server.
359 CalDAVServerResult ConnResult = ServerConnection.Connect();
361 ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
362 ASSERT_EQ(200, ConnResult.HTTPCode);
363 ASSERT_EQ(CURLE_OK, ConnResult.Code);
365 // Check for basic support of the calendar server.
367 CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
369 ASSERT_EQ(true, ConnSupport.BasicSupport);
373 TEST(CalDAV, GetCalendarHome){
375 CalDAVConnectionData ConnNormal;
377 bool ValidDataNormal = false;
379 // Attempt to read the caldavtest.auth file.
381 ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
382 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
383 ValidDataNormal = true;
386 ASSERT_EQ(true, ValidDataNormal);
388 // Setup the connection.
390 CalDAV ServerConnection;
392 ServerConnection.SetupConnectionData(&ConnNormal);
394 // Verify the connection settings.
396 CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
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);
404 // Connect to the server.
406 CalDAVServerResult ConnResult = ServerConnection.Connect();
408 ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
409 ASSERT_EQ(200, ConnResult.HTTPCode);
410 ASSERT_EQ(CURLE_OK, ConnResult.Code);
412 // Check for basic support of the calendar server.
414 CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
416 ASSERT_EQ(true, ConnSupport.BasicSupport);
418 // Get the user principal.
420 string CurrentUserPrincipal = ServerConnection.GetUserPrincipal();
422 // Check the response from the server.
424 ConnResult = ServerConnection.GetServerResult();
426 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
427 ASSERT_EQ(207, ConnResult.HTTPCode);
428 ASSERT_EQ(CURLE_OK, ConnResult.Code);
430 // Get the calendar home.
432 string CalendarHome = ServerConnection.GetCalendarHome(CurrentUserPrincipal);
434 // Check the response from the server.
436 ConnResult = ServerConnection.GetServerResult();
438 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
439 ASSERT_EQ(207, ConnResult.HTTPCode);
440 ASSERT_EQ(CURLE_OK, ConnResult.Code);
444 TEST(CalDAV, ListCalendars){
446 CalDAVConnectionData ConnNormal;
447 string CurrentUserPrincipal;
449 bool ValidDataNormal = false;
451 // Attempt to read the caldavtest.auth file.
453 ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
454 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
455 ValidDataNormal = true;
458 ASSERT_EQ(true, ValidDataNormal);
460 // Setup the connection.
462 CalDAV ServerConnection;
464 ServerConnection.SetupConnectionData(&ConnNormal);
466 // Verify the connection settings.
468 CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
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);
476 // Connect to the server.
478 CalDAVServerResult ConnResult = ServerConnection.Connect();
480 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
481 ASSERT_EQ(200, ConnResult.HTTPCode);
482 ASSERT_EQ(CURLE_OK, ConnResult.Code);
484 // Check that the server supports CalDAV.
486 CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
487 ConnResult = ServerConnection.GetServerResult();
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);
494 // Get the list of calendars.
496 CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
498 // Check the response result from the server.
500 ConnResult = ServerConnection.GetServerResult();
502 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
503 ASSERT_EQ(207, ConnResult.HTTPCode);
504 ASSERT_EQ(CURLE_OK, ConnResult.Code);
508 TEST(CalDAV, AddCalendar){
510 CalDAVConnectionData ConnNormal;
511 string CurrentUserPrincipal;
513 bool ValidDataNormal = false;
515 // Attempt to read the caldavtest.auth file.
517 ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
518 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
519 ValidDataNormal = true;
522 ASSERT_EQ(true, ValidDataNormal);
524 // Setup the connection.
526 CalDAV ServerConnection;
528 ServerConnection.SetupConnectionData(&ConnNormal);
530 // Verify the connection settings.
532 CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
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);
540 // Connect to the server.
542 CalDAVServerResult ConnResult = ServerConnection.Connect();
544 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
545 ASSERT_EQ(200, ConnResult.HTTPCode);
546 ASSERT_EQ(CURLE_OK, ConnResult.Code);
548 // Add a calendar to the server.
550 ConnResult = ServerConnection.AddCalendar("New Calendar");
552 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
553 ASSERT_EQ(201, ConnResult.HTTPCode);
554 ASSERT_EQ(CURLE_OK, ConnResult.Code);
558 TEST(CalDAV, EditCalendar){
560 CalDAVConnectionData ConnNormal;
561 string CurrentUserPrincipal;
563 bool ValidDataNormal = false;
565 // Attempt to read the caldavtest.auth file.
567 ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
568 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
569 ValidDataNormal = true;
572 ASSERT_EQ(true, ValidDataNormal);
574 // Setup the connection.
576 CalDAV ServerConnection;
578 ServerConnection.SetupConnectionData(&ConnNormal);
580 // Verify the connection settings.
582 CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
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);
590 // Connect to the server.
592 CalDAVServerResult ConnResult = ServerConnection.Connect();
594 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
595 ASSERT_EQ(200, ConnResult.HTTPCode);
596 ASSERT_EQ(CURLE_OK, ConnResult.Code);
598 // Check that the server supports CalDAV.
600 CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
601 ConnResult = ServerConnection.GetServerResult();
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);
608 // Add a calendar to the server.
610 ConnResult = ServerConnection.AddCalendar("Calendar To Edit");
612 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
613 ASSERT_EQ(201, ConnResult.HTTPCode);
614 ASSERT_EQ(CURLE_OK, ConnResult.Code);
616 // Get the list of calendars.
618 CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
620 // Check the response result from the server.
622 ConnResult = ServerConnection.GetServerResult();
624 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
625 ASSERT_EQ(207, ConnResult.HTTPCode);
626 ASSERT_EQ(CURLE_OK, ConnResult.Code);
628 // Find the calendar containing the name "Calendar To Edit"
632 bool ItemFound = false;
634 for (map<int,string>::iterator CalendarNameIter = CalendarList.Name.begin();
635 CalendarNameIter != CalendarList.Name.end(); CalendarNameIter++){
637 if (CalendarNameIter->second == "Calendar To Edit"){
646 ASSERT_NE(false, ItemFound);
648 // Edit the name of the calendar.
650 string CalendarEditHREF = CalendarList.HREF[ItemSeek];
651 string NewCalendarName = "Edited Calendar";
653 ConnResult = ServerConnection.EditCalendar(&CalendarEditHREF, &NewCalendarName);
655 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
656 ASSERT_EQ(207, ConnResult.HTTPCode);
657 ASSERT_EQ(CURLE_OK, ConnResult.Code);
659 // Edit the colour of the calendar.
668 ConnResult = ServerConnection.EditCalendar(&CalendarEditHREF, &NewColour);
670 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
671 ASSERT_EQ(207, ConnResult.HTTPCode);
672 ASSERT_EQ(CURLE_OK, ConnResult.Code);
674 // Edit the description of the calendar.
676 string NewCalendarDescription = "Update Calendar Description";
678 ConnResult = ServerConnection.EditCalendarDescription(&CalendarEditHREF, &NewCalendarDescription);
680 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
681 ASSERT_EQ(207, ConnResult.HTTPCode);
682 ASSERT_EQ(CURLE_OK, ConnResult.Code);
684 // Edit the order of the calendar.
686 int NewCalendarOrder = 30;
688 ConnResult = ServerConnection.EditCalendar(&CalendarEditHREF, &NewCalendarOrder);
690 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
691 ASSERT_EQ(207, ConnResult.HTTPCode);
692 ASSERT_EQ(CURLE_OK, ConnResult.Code);
694 // Edit all of the available properties of the calendar.
696 NewCalendarName = "Calendar Edited Again";
697 NewCalendarDescription = "Another updated calendar description";
699 NewColour.green = 255;
702 NewCalendarOrder = 40;
704 ConnResult = ServerConnection.EditCalendar(&CalendarEditHREF,
707 &NewCalendarDescription,
710 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
711 ASSERT_EQ(207, ConnResult.HTTPCode);
712 ASSERT_EQ(CURLE_OK, ConnResult.Code);
716 TEST(CalDAV, DeleteCalendar){
718 CalDAVConnectionData ConnNormal;
719 string CurrentUserPrincipal;
721 bool ValidDataNormal = false;
723 // Attempt to read the caldavtest.auth file.
725 ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
726 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
727 ValidDataNormal = true;
730 ASSERT_EQ(true, ValidDataNormal);
732 // Setup the connection.
734 CalDAV ServerConnection;
736 ServerConnection.SetupConnectionData(&ConnNormal);
738 // Verify the connection settings.
740 CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
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);
748 // Connect to the server.
750 CalDAVServerResult ConnResult = ServerConnection.Connect();
752 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
753 ASSERT_EQ(200, ConnResult.HTTPCode);
754 ASSERT_EQ(CURLE_OK, ConnResult.Code);
756 // Check that the server supports CalDAV.
758 CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
759 ConnResult = ServerConnection.GetServerResult();
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);
766 // Get the list of calendars.
768 CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
770 // Check the response result from the server.
772 ConnResult = ServerConnection.GetServerResult();
774 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
775 ASSERT_EQ(207, ConnResult.HTTPCode);
776 ASSERT_EQ(CURLE_OK, ConnResult.Code);
778 // Get the calendar with the matching name.
781 bool ItemFound = false;
783 for (map<int,string>::iterator CalendarNameIter = CalendarList.Name.begin();
784 CalendarNameIter != CalendarList.Name.end(); CalendarNameIter++){
786 if (CalendarNameIter->second == "Calendar Edited Again"){
795 ASSERT_NE(false, ItemFound);
797 // Delete some calendars.
799 string CalendarEditHREF = CalendarList.HREF[ItemSeek];
801 ConnResult = ServerConnection.DeleteCalendar(&CalendarEditHREF);
803 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
804 ASSERT_EQ(204, ConnResult.HTTPCode);
805 ASSERT_EQ(CURLE_OK, ConnResult.Code);
809 TEST(CalDAV, AddEntry){
811 CalDAVConnectionData ConnNormal;
812 string CurrentUserPrincipal;
814 bool ValidDataNormal = false;
816 // Attempt to read the caldavtest.auth file.
818 ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
819 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
820 ValidDataNormal = true;
823 ASSERT_EQ(true, ValidDataNormal);
825 // Setup the connection.
827 CalDAV ServerConnection;
829 ServerConnection.SetupConnectionData(&ConnNormal);
831 // Verify the connection settings.
833 CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
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);
841 // Connect to the server.
843 CalDAVServerResult ConnResult = ServerConnection.Connect();
845 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
846 ASSERT_EQ(200, ConnResult.HTTPCode);
847 ASSERT_EQ(CURLE_OK, ConnResult.Code);
849 // Check that the server supports CalDAV.
851 CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
852 ConnResult = ServerConnection.GetServerResult();
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);
859 // Get the list of calendars.
861 CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
863 // Check the response result from the server.
865 ConnResult = ServerConnection.GetServerResult();
867 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
868 ASSERT_EQ(207, ConnResult.HTTPCode);
869 ASSERT_EQ(CURLE_OK, ConnResult.Code);
871 // Get the calendar with the matching name.
874 bool ItemFound = false;
876 for (map<int,string>::iterator CalendarNameIter = CalendarList.Name.begin();
877 CalendarNameIter != CalendarList.Name.end(); CalendarNameIter++){
879 if (CalendarNameIter->second == "Scratching Calendar"){
888 ASSERT_NE(false, ItemFound);
890 string EntryAddHREF = CalendarList.HREF[ItemSeek];
892 EntryUUID = GenerateUUID();
893 EntryUUID.erase(EntryUUID.end()-1);
895 EntryAddHREF.append(EntryUUID);
896 EntryAddHREF.append(".ics");
898 string AddEntryData = "BEGIN:VCALENDAR\n"
900 "PRODID:-//Xestia//Calendar Unit Testing//KW\n"
903 AddEntryData += EntryUUID;
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"
914 ConnResult = ServerConnection.AddEntry(&EntryAddHREF, &AddEntryData);
916 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
917 ASSERT_EQ(201, ConnResult.HTTPCode);
918 ASSERT_EQ(CURLE_OK, ConnResult.Code);
920 // Set the EntryCalendarHREFProcessing for later on.
922 EntryCalendarHREFProcessing = EntryAddHREF;
926 TEST(CalDAV, GetEntryETag){
928 CalDAVConnectionData ConnNormal;
929 string CurrentUserPrincipal;
931 bool ValidDataNormal = false;
933 // Attempt to read the caldavtest.auth file.
935 ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
936 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
937 ValidDataNormal = true;
940 ASSERT_EQ(true, ValidDataNormal);
942 // Setup the connection.
944 CalDAV ServerConnection;
946 ServerConnection.SetupConnectionData(&ConnNormal);
948 // Verify the connection settings.
950 CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
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);
958 // Connect to the server.
960 CalDAVServerResult ConnResult = ServerConnection.Connect();
962 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
963 ASSERT_EQ(200, ConnResult.HTTPCode);
964 ASSERT_EQ(CURLE_OK, ConnResult.Code);
966 // Check that the server supports CalDAV.
968 CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
969 ConnResult = ServerConnection.GetServerResult();
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);
976 // Get the list of calendars.
978 CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
980 // Check the response result from the server.
982 ConnResult = ServerConnection.GetServerResult();
984 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
985 ASSERT_EQ(207, ConnResult.HTTPCode);
986 ASSERT_EQ(CURLE_OK, ConnResult.Code);
988 // Get the entry entity tag.
992 ConnResult = ServerConnection.GetEntryETag(&EntryCalendarHREFProcessing, &ETagValue);
994 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
995 ASSERT_EQ(207, ConnResult.HTTPCode);
996 ASSERT_EQ(CURLE_OK, ConnResult.Code);
1000 TEST(CalDAV, EditEntry){
1002 // Check that EntryCalendarHREFProcessing is not blank.
1004 ASSERT_NE("", EntryCalendarHREFProcessing);
1006 CalDAVConnectionData ConnNormal;
1007 string CurrentUserPrincipal;
1009 bool ValidDataNormal = false;
1011 // Attempt to read the caldavtest.auth file.
1013 ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
1014 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
1015 ValidDataNormal = true;
1018 ASSERT_EQ(true, ValidDataNormal);
1020 // Setup the connection.
1022 CalDAV ServerConnection;
1024 ServerConnection.SetupConnectionData(&ConnNormal);
1026 // Verify the connection settings.
1028 CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
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);
1036 // Connect to the server.
1038 CalDAVServerResult ConnResult = ServerConnection.Connect();
1040 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
1041 ASSERT_EQ(200, ConnResult.HTTPCode);
1042 ASSERT_EQ(CURLE_OK, ConnResult.Code);
1044 // Check that the server supports CalDAV.
1046 CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
1047 ConnResult = ServerConnection.GetServerResult();
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);
1054 // Get the list of calendars.
1056 CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
1058 // Check the response result from the server.
1060 ConnResult = ServerConnection.GetServerResult();
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.
1070 ConnResult = ServerConnection.GetEntryETag(&EntryCalendarHREFProcessing, &ETagValue);
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"
1080 "PRODID:-//Xestia//Calendar Unit Testing//KW\n"
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"
1094 ConnResult = ServerConnection.EditEntry(&EntryCalendarHREFProcessing, &EditEntryData, &ETagValue);
1096 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
1097 ASSERT_EQ(204, ConnResult.HTTPCode);
1098 ASSERT_EQ(CURLE_OK, ConnResult.Code);
1102 TEST(CalDAV, DeleteEntry){
1104 // Check that EntryCalendarHREFProcessing is not blank.
1106 ASSERT_NE("", EntryCalendarHREFProcessing);
1108 CalDAVConnectionData ConnNormal;
1109 string CurrentUserPrincipal;
1111 bool ValidDataNormal = false;
1113 // Attempt to read the caldavtest.auth file.
1115 ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
1116 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
1117 ValidDataNormal = true;
1120 ASSERT_EQ(true, ValidDataNormal);
1122 // Setup the connection.
1124 CalDAV ServerConnection;
1126 ServerConnection.SetupConnectionData(&ConnNormal);
1128 // Verify the connection settings.
1130 CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
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);
1138 // Connect to the server.
1140 CalDAVServerResult ConnResult = ServerConnection.Connect();
1142 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
1143 ASSERT_EQ(200, ConnResult.HTTPCode);
1144 ASSERT_EQ(CURLE_OK, ConnResult.Code);
1146 // Check that the server supports CalDAV.
1148 CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
1149 ConnResult = ServerConnection.GetServerResult();
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);
1156 // Delete the calendar entry.
1158 ConnResult = ServerConnection.DeleteCalendar(&EntryCalendarHREFProcessing);
1160 // Check the response result from the server.
1162 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
1163 ASSERT_EQ(204, ConnResult.HTTPCode);
1164 ASSERT_EQ(CURLE_OK, ConnResult.Code);
1168 TEST(CalDAV, GetEntryList){
1170 // Check that EntryCalendarHREFProcessing is not blank.
1172 ASSERT_NE("", EntryCalendarHREFProcessing);
1174 CalDAVConnectionData ConnNormal;
1175 string CurrentUserPrincipal;
1177 bool ValidDataNormal = false;
1179 // Attempt to read the caldavtest.auth file.
1181 ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
1182 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
1183 ValidDataNormal = true;
1186 ASSERT_EQ(true, ValidDataNormal);
1188 // Setup the connection.
1190 CalDAV ServerConnection;
1192 ServerConnection.SetupConnectionData(&ConnNormal);
1194 // Verify the connection settings.
1196 CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
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);
1204 // Connect to the server.
1206 CalDAVServerResult ConnResult = ServerConnection.Connect();
1208 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
1209 ASSERT_EQ(200, ConnResult.HTTPCode);
1210 ASSERT_EQ(CURLE_OK, ConnResult.Code);
1212 // Check that the server supports CalDAV.
1214 CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
1215 ConnResult = ServerConnection.GetServerResult();
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);
1222 // Get the user principal.
1224 string UserPrincipalURI = ServerConnection.GetUserPrincipal();
1226 // Get the calendar home.
1228 string CalendarHomeURL = ServerConnection.GetCalendarHome(UserPrincipalURI);
1230 string CalendarHREF = CalendarHomeURL;
1231 CalendarHREF += "unittestcal/";
1233 // Get the entry list without a calendar tag set.
1235 CalDAVEntryList EntryList = ServerConnection.GetEntryList(&CalendarHREF);
1237 EXPECT_GE(EntryList.HREF.size(), 1);
1239 // Get the list of calendars.
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++){
1248 if (CalHREFIter->second.substr(CalHREFIter->second.length() - 13) == "/unittestcal/"){
1250 CalendarTagURL = CalendarList.TagURL.find(CalHREFIter->first)->second;
1256 // Get the entry list without a calendar tag set (shouldn't be empty).
1258 EntryList = ServerConnection.GetEntryList(&CalendarHREF, nullptr);
1260 EXPECT_GE(EntryList.HREF.size(), 1);
1262 // Get the entry list with a calendar tag set (should be empty).
1264 EntryList = ServerConnection.GetEntryList(&CalendarHREF, &CalendarTagURL);
1266 EXPECT_EQ(EntryList.HREF.size(), 0);