1 // xestiacalendar_caldav.h - Xestia Calendar CalDAV Object Unit Tests
3 // (c) 2016-2017 Xestia Software Development.
5 // This file is part of Xestia Calendar.
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.
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.
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);