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 = "";
27 TEST(CalDAV, BasicTests){
29 CalDAVConnectionData ConnPlain;
30 CalDAVConnectionData ConnNormal;
31 CalDAVConnectionData ConnInvalidSSL;
32 CalDAVConnectionData ConnTimeout;
33 ProcessConnectionDataFileResult DataFileResult;
35 bool ValidDataPlain = false;
36 bool ValidDataNormal = false;
37 bool ValidDataInvalidSSL = false;
38 bool ValidDataTimeout = false;
40 // Attempt to read the caldavtest-plain.auth file.
42 DataFileResult = ProcessConnectionDataFile("caldavtest-plain.auth", &ConnPlain);
43 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
44 ValidDataPlain = true;
47 // Attempt to read the caldavtest.auth file.
49 DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
50 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
51 ValidDataNormal = true;
54 // Attempt to read the caldavtest-fail.auth file.
56 DataFileResult = ProcessConnectionDataFile("caldavtest-fail.auth", &ConnInvalidSSL);
57 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
58 ValidDataInvalidSSL = true;
61 // Attempt to read the caldavtest-timeout.auth file.
63 DataFileResult = ProcessConnectionDataFile("caldavtest-timeout.auth", &ConnTimeout);
64 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
65 ValidDataTimeout = true;
68 if (ValidDataPlain == false){
70 // Cannot read the caldavtest-plain.auth file properly.
72 cout << "The caldavtest-plain.auth file does not exist or is invalid!" << endl;
73 cout << "Please create the caldavtest-plain.auth file using the following format:" << endl << endl;
74 cout << "server=localname" << endl;
75 cout << "port=8080" << endl;
76 cout << "user=username" << endl;
77 cout << "pass=password" << endl;
78 cout << "ssl=false" << endl;
79 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
83 if (ValidDataNormal == false){
85 // Cannot read the caldavtest.auth file properly.
87 cout << "The caldavtest.auth file does not exist or is invalid!" << endl;
88 cout << "Please create the caldavtest.auth file using the following format:" << endl << endl;
89 cout << "server=localname" << endl;
90 cout << "port=8080" << endl;
91 cout << "user=username" << endl;
92 cout << "pass=password" << endl;
93 cout << "ssl=false" << endl;
94 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
98 if (ValidDataInvalidSSL == false){
100 // Cannot read the caldavtest-fail.auth file properly.
102 cout << "The caldavtest-fail.auth file does not exist or is invalid!" << endl;
103 cout << "Please create the caldavtest-fail.auth file using the following format:" << endl << endl;
104 cout << "server=fail.localname" << endl;
105 cout << "port=8080" << endl;
106 cout << "user=username" << endl;
107 cout << "pass=password" << endl;
108 cout << "ssl=false" << endl;
109 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
113 if (ValidDataTimeout == false){
115 // Cannot read the caldavtest-timeout.auth file properly.
117 cout << "The caldavtest-timeout.auth file does not exist or is invalid!" << endl;
118 cout << "Please create the caldavtest-timeout.auth file using the following format:" << endl << endl;
119 cout << "server=fail.localname" << endl;
120 cout << "port=8080" << endl;
121 cout << "user=username" << endl;
122 cout << "pass=password" << endl;
123 cout << "ssl=false" << endl;
124 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
128 ASSERT_EQ(true, ValidDataPlain);
129 ASSERT_EQ(true, ValidDataNormal);
130 ASSERT_EQ(true, ValidDataInvalidSSL);
131 ASSERT_EQ(true, ValidDataTimeout);
133 // (*nix version) Setup an initial connection (just plain
137 CalDAVPlain.SetupConnectionData(&ConnPlain);
139 // Verify that the settings match with the CalDAVConnectionData
142 CalDAVStatus CalDAVPlainStatus = CalDAVPlain.GetConnectionData();
144 ASSERT_EQ(CalDAVPlainStatus.Hostname, ConnPlain.Hostname);
145 ASSERT_EQ(CalDAVPlainStatus.Username, ConnPlain.Username);
146 ASSERT_EQ(CalDAVPlainStatus.Port, ConnPlain.Port);
147 ASSERT_EQ(CalDAVPlainStatus.Prefix, ConnPlain.Prefix);
148 ASSERT_EQ(CalDAVPlainStatus.UseSSL, ConnPlain.UseSSL);
150 // Verify that the connection was successful.
152 CalDAVServerResult ConnResult = CalDAVPlain.Connect();
154 ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
155 ASSERT_EQ(200, ConnResult.HTTPCode);
156 ASSERT_EQ(CURLE_OK, ConnResult.Code);
158 // Do another connection and this time the connection should
159 // fail due to being an invalid host name.
161 CalDAVConnectionData ConnPlainFail;
162 ConnPlainFail.Hostname = "server.invalid";
163 ConnPlainFail.Username = "fail";
164 ConnPlainFail.Password = "fail";
165 ConnPlainFail.Port = 80;
166 ConnPlainFail.UseSSL = false;
168 // Setup the CalDAV connection object.
170 CalDAV CalDAVPlainFail;
171 CalDAVPlainFail.SetupConnectionData(&ConnPlainFail);
173 // Setup the CalDAVStatus object.
175 CalDAVStatus CalDAVPlainFailStatus = CalDAVPlain.GetConnectionData();
179 ConnResult = CalDAVPlainFail.Connect();
181 ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, ConnResult.Result);
182 ASSERT_EQ(0, ConnResult.HTTPCode);
183 ASSERT_EQ(CURLE_COULDNT_RESOLVE_HOST, ConnResult.Code);
185 // (*nix version) Setup an initial connection (with a valid
189 CalDAVNormal.SetupConnectionData(&ConnNormal);
191 // Verify that the settings match with the CalDAVConnectionData
194 CalDAVStatus CalDAVNormalStatus = CalDAVNormal.GetConnectionData();
196 ASSERT_EQ(CalDAVNormalStatus.Hostname, ConnNormal.Hostname);
197 ASSERT_EQ(CalDAVNormalStatus.Username, ConnNormal.Username);
198 ASSERT_EQ(CalDAVNormalStatus.Port, ConnNormal.Port);
199 ASSERT_EQ(CalDAVNormalStatus.Prefix, ConnNormal.Prefix);
200 ASSERT_EQ(CalDAVNormalStatus.UseSSL, ConnNormal.UseSSL);
202 // Verify that the connection was successful (with a valid
205 ConnResult = CalDAVNormal.Connect();
207 ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
208 ASSERT_EQ(200, ConnResult.HTTPCode);
209 ASSERT_EQ(CURLE_OK, ConnResult.Code);
211 // (*nix version) Setup an initial connection on a server that
212 // will fail due to having an invalid SSL certificate.
214 CalDAV CalDAVInvalidSSL;
215 CalDAVInvalidSSL.SetupConnectionData(&ConnInvalidSSL);
217 // Verify that the settings match with the CalDAVConnectionData
220 CalDAVStatus CalDAVInvalidSSLStatus = CalDAVInvalidSSL.GetConnectionData();
222 ASSERT_EQ(CalDAVInvalidSSLStatus.Hostname, ConnInvalidSSL.Hostname);
223 ASSERT_EQ(CalDAVInvalidSSLStatus.Username, ConnInvalidSSL.Username);
224 ASSERT_EQ(CalDAVInvalidSSLStatus.Port, ConnInvalidSSL.Port);
225 ASSERT_EQ(CalDAVInvalidSSLStatus.Prefix, ConnInvalidSSL.Prefix);
226 ASSERT_EQ(CalDAVInvalidSSLStatus.UseSSL, ConnInvalidSSL.UseSSL);
228 // Verify that the connection had failed. (with an invalid
231 ConnResult = CalDAVInvalidSSL.Connect();
233 ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, ConnResult.Result);
234 ASSERT_EQ(0, ConnResult.HTTPCode);
235 ASSERT_EQ(CURLE_SSL_CACERT, ConnResult.Code);
237 // (*nix version) Setup an inital connection on a server where
240 ConnTimeout.Timeout = 5;
242 CalDAV CalDAVTimeout;
243 CalDAVTimeout.SetupConnectionData(&ConnTimeout);
245 // Verify that the settings match with the CalDAVConnectionData
248 CalDAVStatus CalDAVTimeoutStatus = CalDAVTimeout.GetConnectionData();
250 ASSERT_EQ(CalDAVTimeoutStatus.Hostname, ConnTimeout.Hostname);
251 ASSERT_EQ(CalDAVTimeoutStatus.Username, ConnTimeout.Username);
252 ASSERT_EQ(CalDAVTimeoutStatus.Port, ConnTimeout.Port);
253 ASSERT_EQ(CalDAVTimeoutStatus.Prefix, ConnTimeout.Prefix);
254 ASSERT_EQ(CalDAVTimeoutStatus.Timeout, ConnTimeout.Timeout);
255 ASSERT_EQ(CalDAVTimeoutStatus.UseSSL, ConnTimeout.UseSSL);
257 // Verify that the connection had timed out.
259 ConnResult = CalDAVTimeout.Connect();
261 ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, ConnResult.Result);
262 ASSERT_EQ(0, ConnResult.HTTPCode);
263 ASSERT_EQ(CURLE_OPERATION_TIMEDOUT, ConnResult.Code);
267 TEST(CalDAV, BuildServerAddress){
269 CalDAVConnectionData ConnNormal;
270 ProcessConnectionDataFileResult DataFileResult;
271 bool ValidDataNormal = false;
273 // Attempt to read the caldavtest.auth file.
275 DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
276 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
277 ValidDataNormal = true;
280 if (ValidDataNormal == false){
282 // Cannot read the caldavtest.auth file properly.
284 cout << "The caldavtest.auth file does not exist or is invalid!" << endl;
285 cout << "Please create the caldavtest.auth file using the following format:" << endl << endl;
286 cout << "server=localname" << endl;
287 cout << "port=8080" << endl;
288 cout << "user=username" << endl;
289 cout << "pass=password" << endl;
290 cout << "ssl=false" << endl;
291 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
295 ASSERT_EQ(true, ValidDataNormal);
297 // Setup the server address to check.
299 string ServerAddress;
301 // Setup the server address.
303 if (ConnNormal.UseSSL == true){
304 ServerAddress += "https://";
306 ServerAddress += "http://";
309 ServerAddress += ConnNormal.Hostname;
311 // Check if server port is 80, otherwise
312 // specifiy the port number in the address.
314 if (ConnNormal.Port != 80){
315 ServerAddress += ":";
316 ServerAddress += to_string(ConnNormal.Port);
319 ServerAddress += "/principals/";
321 ASSERT_EQ(ServerAddress, BuildServerAddress(&ConnNormal, "/principals/"));
325 TEST(CalDAV, CalendarServerSupport){
327 CalDAVConnectionData ConnNormal;
329 bool ValidDataNormal = false;
331 // Attempt to read the caldavtest.auth file.
333 ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
334 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
335 ValidDataNormal = true;
338 ASSERT_EQ(true, ValidDataNormal);
340 // Setup the connection.
342 CalDAV ServerConnection;
344 ServerConnection.SetupConnectionData(&ConnNormal);
346 // Verify the connection settings.
348 CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
350 ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
351 ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
352 ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
353 ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
354 ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
356 // Connect to the server.
358 CalDAVServerResult ConnResult = ServerConnection.Connect();
360 ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
361 ASSERT_EQ(200, ConnResult.HTTPCode);
362 ASSERT_EQ(CURLE_OK, ConnResult.Code);
364 // Check for basic support of the calendar server.
366 CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
368 ASSERT_EQ(true, ConnSupport.BasicSupport);
372 TEST(CalDAV, GetCalendarHome){
374 CalDAVConnectionData ConnNormal;
376 bool ValidDataNormal = false;
378 // Attempt to read the caldavtest.auth file.
380 ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
381 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
382 ValidDataNormal = true;
385 ASSERT_EQ(true, ValidDataNormal);
387 // Setup the connection.
389 CalDAV ServerConnection;
391 ServerConnection.SetupConnectionData(&ConnNormal);
393 // Verify the connection settings.
395 CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
397 ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
398 ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
399 ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
400 ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
401 ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
403 // Connect to the server.
405 CalDAVServerResult ConnResult = ServerConnection.Connect();
407 ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
408 ASSERT_EQ(200, ConnResult.HTTPCode);
409 ASSERT_EQ(CURLE_OK, ConnResult.Code);
411 // Check for basic support of the calendar server.
413 CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
415 ASSERT_EQ(true, ConnSupport.BasicSupport);
417 // Get the user principal.
419 string CurrentUserPrincipal = ServerConnection.GetUserPrincipal();
421 // Check the response from the server.
423 ConnResult = ServerConnection.GetServerResult();
425 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
426 ASSERT_EQ(207, ConnResult.HTTPCode);
427 ASSERT_EQ(CURLE_OK, ConnResult.Code);
429 // Get the calendar home.
431 string CalendarHome = ServerConnection.GetCalendarHome(CurrentUserPrincipal);
433 // Check the response from the server.
435 ConnResult = ServerConnection.GetServerResult();
437 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
438 ASSERT_EQ(207, ConnResult.HTTPCode);
439 ASSERT_EQ(CURLE_OK, ConnResult.Code);
443 TEST(CalDAV, ListCalendars){
445 CalDAVConnectionData ConnNormal;
446 string CurrentUserPrincipal;
448 bool ValidDataNormal = false;
450 // Attempt to read the caldavtest.auth file.
452 ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
453 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
454 ValidDataNormal = true;
457 ASSERT_EQ(true, ValidDataNormal);
459 // Setup the connection.
461 CalDAV ServerConnection;
463 ServerConnection.SetupConnectionData(&ConnNormal);
465 // Verify the connection settings.
467 CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
469 ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
470 ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
471 ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
472 ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
473 ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
475 // Connect to the server.
477 CalDAVServerResult ConnResult = ServerConnection.Connect();
479 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
480 ASSERT_EQ(200, ConnResult.HTTPCode);
481 ASSERT_EQ(CURLE_OK, ConnResult.Code);
483 // Check that the server supports CalDAV.
485 CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
486 ConnResult = ServerConnection.GetServerResult();
488 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
489 ASSERT_EQ(200, ConnResult.HTTPCode);
490 ASSERT_EQ(CURLE_OK, ConnResult.Code);
491 ASSERT_EQ(true, ConnSupport.BasicSupport);
493 // Get the list of calendars.
495 CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
497 // Check the response result from the server.
499 ConnResult = ServerConnection.GetServerResult();
501 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
502 ASSERT_EQ(207, ConnResult.HTTPCode);
503 ASSERT_EQ(CURLE_OK, ConnResult.Code);
507 TEST(CalDAV, AddCalendar){
509 CalDAVConnectionData ConnNormal;
510 string CurrentUserPrincipal;
512 bool ValidDataNormal = false;
514 // Attempt to read the caldavtest.auth file.
516 ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
517 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
518 ValidDataNormal = true;
521 ASSERT_EQ(true, ValidDataNormal);
523 // Setup the connection.
525 CalDAV ServerConnection;
527 ServerConnection.SetupConnectionData(&ConnNormal);
529 // Verify the connection settings.
531 CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
533 ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
534 ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
535 ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
536 ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
537 ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
539 // Connect to the server.
541 CalDAVServerResult ConnResult = ServerConnection.Connect();
543 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
544 ASSERT_EQ(200, ConnResult.HTTPCode);
545 ASSERT_EQ(CURLE_OK, ConnResult.Code);
547 // Add a calendar to the server.
549 ConnResult = ServerConnection.AddCalendar("New Calendar");
551 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
552 ASSERT_EQ(201, ConnResult.HTTPCode);
553 ASSERT_EQ(CURLE_OK, ConnResult.Code);
557 TEST(CalDAV, EditCalendar){
559 CalDAVConnectionData ConnNormal;
560 string CurrentUserPrincipal;
562 bool ValidDataNormal = false;
564 // Attempt to read the caldavtest.auth file.
566 ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
567 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
568 ValidDataNormal = true;
571 ASSERT_EQ(true, ValidDataNormal);
573 // Setup the connection.
575 CalDAV ServerConnection;
577 ServerConnection.SetupConnectionData(&ConnNormal);
579 // Verify the connection settings.
581 CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
583 ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
584 ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
585 ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
586 ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
587 ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
589 // Connect to the server.
591 CalDAVServerResult ConnResult = ServerConnection.Connect();
593 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
594 ASSERT_EQ(200, ConnResult.HTTPCode);
595 ASSERT_EQ(CURLE_OK, ConnResult.Code);
597 // Check that the server supports CalDAV.
599 CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
600 ConnResult = ServerConnection.GetServerResult();
602 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
603 ASSERT_EQ(200, ConnResult.HTTPCode);
604 ASSERT_EQ(CURLE_OK, ConnResult.Code);
605 ASSERT_EQ(true, ConnSupport.BasicSupport);
607 // Add a calendar to the server.
609 ConnResult = ServerConnection.AddCalendar("Calendar To Edit");
611 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
612 ASSERT_EQ(201, ConnResult.HTTPCode);
613 ASSERT_EQ(CURLE_OK, ConnResult.Code);
615 // Get the list of calendars.
617 CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
619 // Check the response result from the server.
621 ConnResult = ServerConnection.GetServerResult();
623 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
624 ASSERT_EQ(207, ConnResult.HTTPCode);
625 ASSERT_EQ(CURLE_OK, ConnResult.Code);
627 // Find the calendar containing the name "Calendar To Edit"
631 bool ItemFound = false;
633 for (map<int,string>::iterator CalendarNameIter = CalendarList.Name.begin();
634 CalendarNameIter != CalendarList.Name.end(); CalendarNameIter++){
636 if (CalendarNameIter->second == "Calendar To Edit"){
645 ASSERT_NE(false, ItemFound);
647 // Edit the name of the calendar.
649 string CalendarEditHREF = CalendarList.HREF[ItemSeek];
650 string NewCalendarName = "Edited Calendar";
652 ConnResult = ServerConnection.EditCalendar(&CalendarEditHREF, &NewCalendarName);
654 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
655 ASSERT_EQ(207, ConnResult.HTTPCode);
656 ASSERT_EQ(CURLE_OK, ConnResult.Code);
658 // Edit the colour of the calendar.
667 ConnResult = ServerConnection.EditCalendar(&CalendarEditHREF, &NewColour);
669 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
670 ASSERT_EQ(207, ConnResult.HTTPCode);
671 ASSERT_EQ(CURLE_OK, ConnResult.Code);
673 // Edit the description of the calendar.
675 string NewCalendarDescription = "Update Calendar Description";
677 ConnResult = ServerConnection.EditCalendarDescription(&CalendarEditHREF, &NewCalendarDescription);
679 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
680 ASSERT_EQ(207, ConnResult.HTTPCode);
681 ASSERT_EQ(CURLE_OK, ConnResult.Code);
683 // Edit the order of the calendar.
685 int NewCalendarOrder = 30;
687 ConnResult = ServerConnection.EditCalendar(&CalendarEditHREF, &NewCalendarOrder);
689 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
690 ASSERT_EQ(207, ConnResult.HTTPCode);
691 ASSERT_EQ(CURLE_OK, ConnResult.Code);
693 // Edit all of the available properties of the calendar.
695 NewCalendarName = "Calendar Edited Again";
696 NewCalendarDescription = "Another updated calendar description";
698 NewColour.green = 255;
701 NewCalendarOrder = 40;
703 ConnResult = ServerConnection.EditCalendar(&CalendarEditHREF,
706 &NewCalendarDescription,
709 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
710 ASSERT_EQ(207, ConnResult.HTTPCode);
711 ASSERT_EQ(CURLE_OK, ConnResult.Code);
715 TEST(CalDAV, DeleteCalendar){
717 CalDAVConnectionData ConnNormal;
718 string CurrentUserPrincipal;
720 bool ValidDataNormal = false;
722 // Attempt to read the caldavtest.auth file.
724 ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
725 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
726 ValidDataNormal = true;
729 ASSERT_EQ(true, ValidDataNormal);
731 // Setup the connection.
733 CalDAV ServerConnection;
735 ServerConnection.SetupConnectionData(&ConnNormal);
737 // Verify the connection settings.
739 CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
741 ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
742 ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
743 ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
744 ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
745 ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
747 // Connect to the server.
749 CalDAVServerResult ConnResult = ServerConnection.Connect();
751 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
752 ASSERT_EQ(200, ConnResult.HTTPCode);
753 ASSERT_EQ(CURLE_OK, ConnResult.Code);
755 // Check that the server supports CalDAV.
757 CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
758 ConnResult = ServerConnection.GetServerResult();
760 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
761 ASSERT_EQ(200, ConnResult.HTTPCode);
762 ASSERT_EQ(CURLE_OK, ConnResult.Code);
763 ASSERT_EQ(true, ConnSupport.BasicSupport);
765 // Get the list of calendars.
767 CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
769 // Check the response result from the server.
771 ConnResult = ServerConnection.GetServerResult();
773 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
774 ASSERT_EQ(207, ConnResult.HTTPCode);
775 ASSERT_EQ(CURLE_OK, ConnResult.Code);
777 // Get the calendar with the matching name.
780 bool ItemFound = false;
782 for (map<int,string>::iterator CalendarNameIter = CalendarList.Name.begin();
783 CalendarNameIter != CalendarList.Name.end(); CalendarNameIter++){
785 if (CalendarNameIter->second == "Calendar Edited Again"){
794 ASSERT_NE(false, ItemFound);
796 // Delete some calendars.
798 string CalendarEditHREF = CalendarList.HREF[ItemSeek];
800 ConnResult = ServerConnection.DeleteCalendar(&CalendarEditHREF);
802 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
803 ASSERT_EQ(204, ConnResult.HTTPCode);
804 ASSERT_EQ(CURLE_OK, ConnResult.Code);
808 TEST(CalDAV, AddEntry){
810 CalDAVConnectionData ConnNormal;
811 string CurrentUserPrincipal;
813 bool ValidDataNormal = false;
815 // Attempt to read the caldavtest.auth file.
817 ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
818 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
819 ValidDataNormal = true;
822 ASSERT_EQ(true, ValidDataNormal);
824 // Setup the connection.
826 CalDAV ServerConnection;
828 ServerConnection.SetupConnectionData(&ConnNormal);
830 // Verify the connection settings.
832 CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
834 ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
835 ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
836 ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
837 ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
838 ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
840 // Connect to the server.
842 CalDAVServerResult ConnResult = ServerConnection.Connect();
844 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
845 ASSERT_EQ(200, ConnResult.HTTPCode);
846 ASSERT_EQ(CURLE_OK, ConnResult.Code);
848 // Check that the server supports CalDAV.
850 CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
851 ConnResult = ServerConnection.GetServerResult();
853 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
854 ASSERT_EQ(200, ConnResult.HTTPCode);
855 ASSERT_EQ(CURLE_OK, ConnResult.Code);
856 ASSERT_EQ(true, ConnSupport.BasicSupport);
858 // Get the list of calendars.
860 CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
862 // Check the response result from the server.
864 ConnResult = ServerConnection.GetServerResult();
866 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
867 ASSERT_EQ(207, ConnResult.HTTPCode);
868 ASSERT_EQ(CURLE_OK, ConnResult.Code);
870 // Get the calendar with the matching name.
873 bool ItemFound = false;
875 for (map<int,string>::iterator CalendarNameIter = CalendarList.Name.begin();
876 CalendarNameIter != CalendarList.Name.end(); CalendarNameIter++){
878 if (CalendarNameIter->second == "Scratching Calendar"){
887 ASSERT_NE(false, ItemFound);
889 string EntryAddHREF = CalendarList.HREF[ItemSeek];
891 string EntryUUID = GenerateUUID();
892 EntryUUID.erase(EntryUUID.end()-1);
894 EntryAddHREF.append(EntryUUID);
895 EntryAddHREF.append(".ics");
897 string AddEntryData = "BEGIN:VCALENDAR\n"
899 "PRODID:-//Xestia//Calendar Unit Testing//KW\n"
902 AddEntryData += EntryUUID;
904 "DTSTAMP:20160116T190200Z\n"
905 "DTSTART:20160116T190200Z\n"
906 "DTEND:20160116T190200Z\n"
907 "SUMMARY:Unit Test Event 1 which has to be a really long summary as we don't k\n"
908 " now if multiple line processing is going to work without it. I mean seriousl\n"
909 " y, how annoying can this potentially be?\n"
913 ConnResult = ServerConnection.AddEntry(&EntryAddHREF, &AddEntryData);
915 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
916 ASSERT_EQ(201, ConnResult.HTTPCode);
917 ASSERT_EQ(CURLE_OK, ConnResult.Code);
919 // Set the EntryCalendarHREFProcessing for later on.
921 EntryCalendarHREFProcessing = EntryAddHREF;
925 TEST(CalDAV, GetEntryETag){
927 CalDAVConnectionData ConnNormal;
928 string CurrentUserPrincipal;
930 bool ValidDataNormal = false;
932 // Attempt to read the caldavtest.auth file.
934 ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
935 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
936 ValidDataNormal = true;
939 ASSERT_EQ(true, ValidDataNormal);
941 // Setup the connection.
943 CalDAV ServerConnection;
945 ServerConnection.SetupConnectionData(&ConnNormal);
947 // Verify the connection settings.
949 CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
951 ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
952 ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
953 ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
954 ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
955 ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
957 // Connect to the server.
959 CalDAVServerResult ConnResult = ServerConnection.Connect();
961 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
962 ASSERT_EQ(200, ConnResult.HTTPCode);
963 ASSERT_EQ(CURLE_OK, ConnResult.Code);
965 // Check that the server supports CalDAV.
967 CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
968 ConnResult = ServerConnection.GetServerResult();
970 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
971 ASSERT_EQ(200, ConnResult.HTTPCode);
972 ASSERT_EQ(CURLE_OK, ConnResult.Code);
973 ASSERT_EQ(true, ConnSupport.BasicSupport);
975 // Get the list of calendars.
977 CalDAVCalendarList CalendarList = ServerConnection.GetCalendars();
979 // Check the response result from the server.
981 ConnResult = ServerConnection.GetServerResult();
983 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
984 ASSERT_EQ(207, ConnResult.HTTPCode);
985 ASSERT_EQ(CURLE_OK, ConnResult.Code);
989 ConnResult = ServerConnection.GetEntryETag(&EntryCalendarHREFProcessing, &ETagValue);
991 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
992 ASSERT_EQ(207, ConnResult.HTTPCode);
993 ASSERT_EQ(CURLE_OK, ConnResult.Code);
999 TEST(CalDAV, DeleteEntry){
1001 // Check that EntryCalendarHREFProcessing is not blank.
1003 ASSERT_NE("", EntryCalendarHREFProcessing);
1005 CalDAVConnectionData ConnNormal;
1006 string CurrentUserPrincipal;
1008 bool ValidDataNormal = false;
1010 // Attempt to read the caldavtest.auth file.
1012 ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal);
1013 if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
1014 ValidDataNormal = true;
1017 ASSERT_EQ(true, ValidDataNormal);
1019 // Setup the connection.
1021 CalDAV ServerConnection;
1023 ServerConnection.SetupConnectionData(&ConnNormal);
1025 // Verify the connection settings.
1027 CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData();
1029 ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname);
1030 ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username);
1031 ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port);
1032 ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix);
1033 ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL);
1035 // Connect to the server.
1037 CalDAVServerResult ConnResult = ServerConnection.Connect();
1039 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
1040 ASSERT_EQ(200, ConnResult.HTTPCode);
1041 ASSERT_EQ(CURLE_OK, ConnResult.Code);
1043 // Check that the server supports CalDAV.
1045 CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport();
1046 ConnResult = ServerConnection.GetServerResult();
1048 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
1049 ASSERT_EQ(200, ConnResult.HTTPCode);
1050 ASSERT_EQ(CURLE_OK, ConnResult.Code);
1051 ASSERT_EQ(true, ConnSupport.BasicSupport);
1053 // Delete the calendar entry.
1055 ConnResult = ServerConnection.DeleteCalendar(&EntryCalendarHREFProcessing);
1057 // Check the response result from the server.
1059 EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
1060 ASSERT_EQ(204, ConnResult.HTTPCode);
1061 ASSERT_EQ(CURLE_OK, ConnResult.Code);