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)
31 CalDAVConnectionData connPlain;
32 CalDAVConnectionData connNormal;
33 CalDAVConnectionData connInvalidSSL;
34 CalDAVConnectionData connTimeout;
35 ProcessConnectionDataFileResult dataFileResult;
37 bool validDataPlain = false;
38 bool validDataNormal = false;
39 bool validDataInvalidSSL = false;
40 bool validDataTimeout = false;
42 // Attempt to read the caldavtest-plain.auth file.
44 dataFileResult = ProcessConnectionDataFile("caldavtest-plain.auth", &connPlain);
45 if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
46 validDataPlain = true;
49 // Attempt to read the caldavtest.auth file.
51 dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
52 if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
53 validDataNormal = true;
56 // Attempt to read the caldavtest-fail.auth file.
58 dataFileResult = ProcessConnectionDataFile("caldavtest-fail.auth", &connInvalidSSL);
59 if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
60 validDataInvalidSSL = true;
63 // Attempt to read the caldavtest-timeout.auth file.
65 dataFileResult = ProcessConnectionDataFile("caldavtest-timeout.auth", &connTimeout);
66 if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
67 validDataTimeout = true;
70 if (validDataPlain == false){
72 // Cannot read the caldavtest-plain.auth file properly.
74 cout << "The caldavtest-plain.auth file does not exist or is invalid!" << endl;
75 cout << "Please create the caldavtest-plain.auth file using the following format:" << endl << endl;
76 cout << "server=localname" << endl;
77 cout << "port=8080" << endl;
78 cout << "user=username" << endl;
79 cout << "pass=password" << endl;
80 cout << "ssl=false" << endl;
81 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
85 if (validDataNormal == false){
87 // Cannot read the caldavtest.auth file properly.
89 cout << "The caldavtest.auth file does not exist or is invalid!" << endl;
90 cout << "Please create the caldavtest.auth file using the following format:" << endl << endl;
91 cout << "server=localname" << endl;
92 cout << "port=8080" << endl;
93 cout << "user=username" << endl;
94 cout << "pass=password" << endl;
95 cout << "ssl=false" << endl;
96 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
100 if (validDataInvalidSSL == false){
102 // Cannot read the caldavtest-fail.auth file properly.
104 cout << "The caldavtest-fail.auth file does not exist or is invalid!" << endl;
105 cout << "Please create the caldavtest-fail.auth file using the following format:" << endl << endl;
106 cout << "server=fail.localname" << endl;
107 cout << "port=8080" << endl;
108 cout << "user=username" << endl;
109 cout << "pass=password" << endl;
110 cout << "ssl=false" << endl;
111 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
115 if (validDataTimeout == false){
117 // Cannot read the caldavtest-timeout.auth file properly.
119 cout << "The caldavtest-timeout.auth file does not exist or is invalid!" << endl;
120 cout << "Please create the caldavtest-timeout.auth file using the following format:" << endl << endl;
121 cout << "server=fail.localname" << endl;
122 cout << "port=8080" << endl;
123 cout << "user=username" << endl;
124 cout << "pass=password" << endl;
125 cout << "ssl=false" << endl;
126 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
130 ASSERT_EQ(true, validDataPlain);
131 ASSERT_EQ(true, validDataNormal);
132 ASSERT_EQ(true, validDataInvalidSSL);
133 ASSERT_EQ(true, validDataTimeout);
135 // (*nix version) Setup an initial connection (just plain
139 calDAVPlain.SetupConnectionData(&connPlain);
141 // Verify that the settings match with the CalDAVConnectionData
144 CalDAVStatus calDAVPlainStatus = calDAVPlain.GetConnectionData();
146 ASSERT_EQ(calDAVPlainStatus.hostname, connPlain.hostname);
147 ASSERT_EQ(calDAVPlainStatus.username, connPlain.username);
148 ASSERT_EQ(calDAVPlainStatus.port, connPlain.port);
149 ASSERT_EQ(calDAVPlainStatus.prefix, connPlain.prefix);
150 ASSERT_EQ(calDAVPlainStatus.useSSL, connPlain.useSSL);
152 // Verify that the connection was successful.
154 CalDAVServerResult connResult = calDAVPlain.Connect();
156 ASSERT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
157 ASSERT_EQ(200, connResult.httpCode);
158 ASSERT_EQ(CURLE_OK, connResult.code);
160 // Do another connection and this time the connection should
161 // fail due to being an invalid host name.
163 CalDAVConnectionData connPlainFail;
164 connPlainFail.hostname = "server.invalid";
165 connPlainFail.username = "fail";
166 connPlainFail.password = "fail";
167 connPlainFail.port = 80;
168 connPlainFail.useSSL = false;
170 // Setup the CalDAV connection object.
172 CalDAV calDAVPlainFail;
173 calDAVPlainFail.SetupConnectionData(&connPlainFail);
175 // Setup the CalDAVStatus object.
177 CalDAVStatus calDAVPlainFailStatus = calDAVPlain.GetConnectionData();
181 connResult = calDAVPlainFail.Connect();
183 ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, connResult.result);
184 ASSERT_EQ(0, connResult.httpCode);
185 ASSERT_EQ(CURLE_COULDNT_RESOLVE_HOST, connResult.code);
187 // (*nix version) Setup an initial connection (with a valid
191 calDAVNormal.SetupConnectionData(&connNormal);
193 // Verify that the settings match with the CalDAVConnectionData
196 CalDAVStatus calDAVNormalStatus = calDAVNormal.GetConnectionData();
198 ASSERT_EQ(calDAVNormalStatus.hostname, connNormal.hostname);
199 ASSERT_EQ(calDAVNormalStatus.username, connNormal.username);
200 ASSERT_EQ(calDAVNormalStatus.port, connNormal.port);
201 ASSERT_EQ(calDAVNormalStatus.prefix, connNormal.prefix);
202 ASSERT_EQ(calDAVNormalStatus.useSSL, connNormal.useSSL);
204 // Verify that the connection was successful (with a valid
207 connResult = calDAVNormal.Connect();
209 ASSERT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
210 ASSERT_EQ(200, connResult.httpCode);
211 ASSERT_EQ(CURLE_OK, connResult.code);
213 // (*nix version) Setup an initial connection on a server that
214 // will fail due to having an invalid SSL certificate.
216 CalDAV calDAVInvalidSSL;
217 calDAVInvalidSSL.SetupConnectionData(&connInvalidSSL);
219 // Verify that the settings match with the CalDAVConnectionData
222 CalDAVStatus calDAVInvalidSSLStatus = calDAVInvalidSSL.GetConnectionData();
224 ASSERT_EQ(calDAVInvalidSSLStatus.hostname, connInvalidSSL.hostname);
225 ASSERT_EQ(calDAVInvalidSSLStatus.username, connInvalidSSL.username);
226 ASSERT_EQ(calDAVInvalidSSLStatus.port, connInvalidSSL.port);
227 ASSERT_EQ(calDAVInvalidSSLStatus.prefix, connInvalidSSL.prefix);
228 ASSERT_EQ(calDAVInvalidSSLStatus.useSSL, connInvalidSSL.useSSL);
230 // Verify that the connection had failed. (with an invalid
233 connResult = calDAVInvalidSSL.Connect();
235 ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, connResult.result);
236 ASSERT_EQ(0, connResult.httpCode);
237 ASSERT_EQ(CURLE_SSL_CACERT, connResult.code);
239 // (*nix version) Setup an inital connection on a server where
242 connTimeout.timeout = 5;
244 CalDAV calDAVTimeout;
245 calDAVTimeout.SetupConnectionData(&connTimeout);
247 // Verify that the settings match with the CalDAVConnectionData
250 CalDAVStatus calDAVTimeoutStatus = calDAVTimeout.GetConnectionData();
252 ASSERT_EQ(calDAVTimeoutStatus.hostname, connTimeout.hostname);
253 ASSERT_EQ(calDAVTimeoutStatus.username, connTimeout.username);
254 ASSERT_EQ(calDAVTimeoutStatus.port, connTimeout.port);
255 ASSERT_EQ(calDAVTimeoutStatus.prefix, connTimeout.prefix);
256 ASSERT_EQ(calDAVTimeoutStatus.timeout, connTimeout.timeout);
257 ASSERT_EQ(calDAVTimeoutStatus.useSSL, connTimeout.useSSL);
259 // Verify that the connection had timed out.
261 connResult = calDAVTimeout.Connect();
263 ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, connResult.result);
264 ASSERT_EQ(0, connResult.httpCode);
265 ASSERT_EQ(CURLE_OPERATION_TIMEDOUT, connResult.code);
269 TEST(CalDAV, BuildServerAddress)
272 CalDAVConnectionData connNormal;
273 ProcessConnectionDataFileResult dataFileResult;
274 bool validDataNormal = false;
276 // Attempt to read the caldavtest.auth file.
278 dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
279 if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
280 validDataNormal = true;
283 if (validDataNormal == false){
285 // Cannot read the caldavtest.auth file properly.
287 cout << "The caldavtest.auth file does not exist or is invalid!" << endl;
288 cout << "Please create the caldavtest.auth file using the following format:" << endl << endl;
289 cout << "server=localname" << endl;
290 cout << "port=8080" << endl;
291 cout << "user=username" << endl;
292 cout << "pass=password" << endl;
293 cout << "ssl=false" << endl;
294 cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl;
298 ASSERT_EQ(true, validDataNormal);
300 // Setup the server address to check.
302 string serverAddress;
304 // Setup the server address.
306 if (connNormal.useSSL == true){
307 serverAddress += "https://";
309 serverAddress += "http://";
312 serverAddress += connNormal.hostname;
314 // Check if server port is 80, otherwise
315 // specifiy the port number in the address.
317 if (connNormal.port != 80){
318 serverAddress += ":";
319 serverAddress += to_string(connNormal.port);
322 serverAddress += "/principals/";
324 ASSERT_EQ(serverAddress, BuildServerAddress(&connNormal, "/principals/"));
328 TEST(CalDAV, CalendarServerSupport)
331 CalDAVConnectionData connNormal;
333 bool validDataNormal = false;
335 // Attempt to read the caldavtest.auth file.
337 ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
338 if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
339 validDataNormal = true;
342 ASSERT_EQ(true, validDataNormal);
344 // Setup the connection.
346 CalDAV serverConnection;
348 serverConnection.SetupConnectionData(&connNormal);
350 // Verify the connection settings.
352 CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
354 ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
355 ASSERT_EQ(calDAVStatus.username, connNormal.username);
356 ASSERT_EQ(calDAVStatus.port, connNormal.port);
357 ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
358 ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
360 // Connect to the server.
362 CalDAVServerResult connResult = serverConnection.Connect();
364 ASSERT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
365 ASSERT_EQ(200, connResult.httpCode);
366 ASSERT_EQ(CURLE_OK, connResult.code);
368 // Check for basic support of the calendar server.
370 CalDAVServerSupport connSupport = serverConnection.GetServerSupport();
372 ASSERT_EQ(true, connSupport.basicSupport);
376 TEST(CalDAV, GetCalendarHome)
379 CalDAVConnectionData connNormal;
381 bool validDataNormal = false;
383 // Attempt to read the caldavtest.auth file.
385 ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
386 if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
387 validDataNormal = true;
390 ASSERT_EQ(true, validDataNormal);
392 // Setup the connection.
394 CalDAV serverConnection;
396 serverConnection.SetupConnectionData(&connNormal);
398 // Verify the connection settings.
400 CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
402 ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
403 ASSERT_EQ(calDAVStatus.username, connNormal.username);
404 ASSERT_EQ(calDAVStatus.port, connNormal.port);
405 ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
406 ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
408 // Connect to the server.
410 CalDAVServerResult connResult = serverConnection.Connect();
412 ASSERT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
413 ASSERT_EQ(200, connResult.httpCode);
414 ASSERT_EQ(CURLE_OK, connResult.code);
416 // Check for basic support of the calendar server.
418 CalDAVServerSupport connSupport = serverConnection.GetServerSupport();
420 ASSERT_EQ(true, connSupport.basicSupport);
422 // Get the user principal.
424 string currentUserPrincipal = serverConnection.GetUserPrincipal();
426 // Check the response from the server.
428 connResult = serverConnection.GetServerResult();
430 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
431 ASSERT_EQ(207, connResult.httpCode);
432 ASSERT_EQ(CURLE_OK, connResult.code);
434 // Get the calendar home.
436 string calendarHome = serverConnection.GetCalendarHome(currentUserPrincipal);
438 // Check the response from the server.
440 connResult = serverConnection.GetServerResult();
442 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
443 ASSERT_EQ(207, connResult.httpCode);
444 ASSERT_EQ(CURLE_OK, connResult.code);
448 TEST(CalDAV, ListCalendars)
451 CalDAVConnectionData connNormal;
452 string currentUserPrincipal;
454 bool validDataNormal = false;
456 // Attempt to read the caldavtest.auth file.
458 ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
459 if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
460 validDataNormal = true;
463 ASSERT_EQ(true, validDataNormal);
465 // Setup the connection.
467 CalDAV serverConnection;
469 serverConnection.SetupConnectionData(&connNormal);
471 // Verify the connection settings.
473 CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
475 ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
476 ASSERT_EQ(calDAVStatus.username, connNormal.username);
477 ASSERT_EQ(calDAVStatus.port, connNormal.port);
478 ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
479 ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
481 // Connect to the server.
483 CalDAVServerResult connResult = serverConnection.Connect();
485 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
486 ASSERT_EQ(200, connResult.httpCode);
487 ASSERT_EQ(CURLE_OK, connResult.code);
489 // Check that the server supports CalDAV.
491 CalDAVServerSupport connSupport = serverConnection.GetServerSupport();
492 connResult = serverConnection.GetServerResult();
494 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
495 ASSERT_EQ(200, connResult.httpCode);
496 ASSERT_EQ(CURLE_OK, connResult.code);
497 ASSERT_EQ(true, connSupport.basicSupport);
499 // Get the list of calendars.
501 CalDAVCalendarList calendarList = serverConnection.GetCalendars();
503 // Check the response result from the server.
505 connResult = serverConnection.GetServerResult();
507 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
508 ASSERT_EQ(207, connResult.httpCode);
509 ASSERT_EQ(CURLE_OK, connResult.code);
513 TEST(CalDAV, AddCalendar)
516 CalDAVConnectionData connNormal;
517 string currentUserPrincipal;
519 bool validDataNormal = false;
521 // Attempt to read the caldavtest.auth file.
523 ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
524 if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
525 validDataNormal = true;
528 ASSERT_EQ(true, validDataNormal);
530 // Setup the connection.
532 CalDAV serverConnection;
534 serverConnection.SetupConnectionData(&connNormal);
536 // Verify the connection settings.
538 CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
540 ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
541 ASSERT_EQ(calDAVStatus.username, connNormal.username);
542 ASSERT_EQ(calDAVStatus.port, connNormal.port);
543 ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
544 ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
546 // Connect to the server.
548 CalDAVServerResult connResult = serverConnection.Connect();
550 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
551 ASSERT_EQ(200, connResult.httpCode);
552 ASSERT_EQ(CURLE_OK, connResult.code);
554 // Add a calendar to the server.
556 connResult = serverConnection.AddCalendar("New Calendar");
558 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
559 ASSERT_EQ(201, connResult.httpCode);
560 ASSERT_EQ(CURLE_OK, connResult.code);
564 TEST(CalDAV, EditCalendar)
567 CalDAVConnectionData connNormal;
568 string currentUserPrincipal;
570 bool validDataNormal = false;
572 // Attempt to read the caldavtest.auth file.
574 ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
575 if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
576 validDataNormal = true;
579 ASSERT_EQ(true, validDataNormal);
581 // Setup the connection.
583 CalDAV serverConnection;
585 serverConnection.SetupConnectionData(&connNormal);
587 // Verify the connection settings.
589 CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
591 ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
592 ASSERT_EQ(calDAVStatus.username, connNormal.username);
593 ASSERT_EQ(calDAVStatus.port, connNormal.port);
594 ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
595 ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
597 // Connect to the server.
599 CalDAVServerResult connResult = serverConnection.Connect();
601 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
602 ASSERT_EQ(200, connResult.httpCode);
603 ASSERT_EQ(CURLE_OK, connResult.code);
605 // Check that the server supports CalDAV.
607 CalDAVServerSupport connSupport = serverConnection.GetServerSupport();
608 connResult = serverConnection.GetServerResult();
610 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
611 ASSERT_EQ(200, connResult.httpCode);
612 ASSERT_EQ(CURLE_OK, connResult.code);
613 ASSERT_EQ(true, connSupport.basicSupport);
615 // Add a calendar to the server.
617 connResult = serverConnection.AddCalendar("Calendar To Edit");
619 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
620 ASSERT_EQ(201, connResult.httpCode);
621 ASSERT_EQ(CURLE_OK, connResult.code);
623 // Get the list of calendars.
625 CalDAVCalendarList calendarList = serverConnection.GetCalendars();
627 // Check the response result from the server.
629 connResult = serverConnection.GetServerResult();
631 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
632 ASSERT_EQ(207, connResult.httpCode);
633 ASSERT_EQ(CURLE_OK, connResult.code);
635 // Find the calendar containing the name "Calendar To Edit"
639 bool itemFound = false;
641 for (map<int,string>::iterator calendarNameIter = calendarList.name.begin();
642 calendarNameIter != calendarList.name.end(); calendarNameIter++){
644 if (calendarNameIter->second == "Calendar To Edit"){
653 ASSERT_NE(false, itemFound);
655 // Edit the name of the calendar.
657 string calendarEditHREF = calendarList.href[itemSeek];
658 string newCalendarName = "Edited Calendar";
660 connResult = serverConnection.EditCalendar(&calendarEditHREF, &newCalendarName);
662 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
663 ASSERT_EQ(207, connResult.httpCode);
664 ASSERT_EQ(CURLE_OK, connResult.code);
666 // Edit the colour of the calendar.
675 connResult = serverConnection.EditCalendar(&calendarEditHREF, &newColour);
677 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
678 ASSERT_EQ(207, connResult.httpCode);
679 ASSERT_EQ(CURLE_OK, connResult.code);
681 // Edit the description of the calendar.
683 string newCalendarDescription = "Update Calendar Description";
685 connResult = serverConnection.EditCalendarDescription(&calendarEditHREF, &newCalendarDescription);
687 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
688 ASSERT_EQ(207, connResult.httpCode);
689 ASSERT_EQ(CURLE_OK, connResult.code);
691 // Edit the order of the calendar.
693 int newCalendarOrder = 30;
695 connResult = serverConnection.EditCalendar(&calendarEditHREF, &newCalendarOrder);
697 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
698 ASSERT_EQ(207, connResult.httpCode);
699 ASSERT_EQ(CURLE_OK, connResult.code);
701 // Edit all of the available properties of the calendar.
703 newCalendarName = "Calendar Edited Again";
704 newCalendarDescription = "Another updated calendar description";
706 newColour.green = 255;
709 newCalendarOrder = 40;
711 connResult = serverConnection.EditCalendar(&calendarEditHREF,
714 &newCalendarDescription,
717 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
718 ASSERT_EQ(207, connResult.httpCode);
719 ASSERT_EQ(CURLE_OK, connResult.code);
723 TEST(CalDAV, DeleteCalendar)
726 CalDAVConnectionData connNormal;
727 string currentUserPrincipal;
729 bool validDataNormal = false;
731 // Attempt to read the caldavtest.auth file.
733 ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
734 if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
735 validDataNormal = true;
738 ASSERT_EQ(true, validDataNormal);
740 // Setup the connection.
742 CalDAV serverConnection;
744 serverConnection.SetupConnectionData(&connNormal);
746 // Verify the connection settings.
748 CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
750 ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
751 ASSERT_EQ(calDAVStatus.username, connNormal.username);
752 ASSERT_EQ(calDAVStatus.port, connNormal.port);
753 ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
754 ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
756 // Connect to the server.
758 CalDAVServerResult connResult = serverConnection.Connect();
760 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
761 ASSERT_EQ(200, connResult.httpCode);
762 ASSERT_EQ(CURLE_OK, connResult.code);
764 // Check that the server supports CalDAV.
766 CalDAVServerSupport connSupport = serverConnection.GetServerSupport();
767 connResult = serverConnection.GetServerResult();
769 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
770 ASSERT_EQ(200, connResult.httpCode);
771 ASSERT_EQ(CURLE_OK, connResult.code);
772 ASSERT_EQ(true, connSupport.basicSupport);
774 // Get the list of calendars.
776 CalDAVCalendarList calendarList = serverConnection.GetCalendars();
778 // Check the response result from the server.
780 connResult = serverConnection.GetServerResult();
782 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
783 ASSERT_EQ(207, connResult.httpCode);
784 ASSERT_EQ(CURLE_OK, connResult.code);
786 // Get the calendar with the matching name.
789 bool itemFound = false;
791 for (map<int,string>::iterator calendarNameIter = calendarList.name.begin();
792 calendarNameIter != calendarList.name.end(); calendarNameIter++){
794 if (calendarNameIter->second == "Calendar Edited Again"){
803 ASSERT_NE(false, itemFound);
805 // Delete some calendars.
807 string calendarEditHREF = calendarList.href[itemSeek];
809 connResult = serverConnection.DeleteCalendar(&calendarEditHREF);
811 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
812 ASSERT_EQ(204, connResult.httpCode);
813 ASSERT_EQ(CURLE_OK, connResult.code);
817 TEST(CalDAV, AddEntry)
820 CalDAVConnectionData connNormal;
821 string currentUserPrincipal;
823 bool validDataNormal = false;
825 // Attempt to read the caldavtest.auth file.
827 ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
828 if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
829 validDataNormal = true;
832 ASSERT_EQ(true, validDataNormal);
834 // Setup the connection.
836 CalDAV serverConnection;
838 serverConnection.SetupConnectionData(&connNormal);
840 // Verify the connection settings.
842 CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
844 ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
845 ASSERT_EQ(calDAVStatus.username, connNormal.username);
846 ASSERT_EQ(calDAVStatus.port, connNormal.port);
847 ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
848 ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
850 // Connect to the server.
852 CalDAVServerResult connResult = serverConnection.Connect();
854 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
855 ASSERT_EQ(200, connResult.httpCode);
856 ASSERT_EQ(CURLE_OK, connResult.code);
858 // Check that the server supports CalDAV.
860 CalDAVServerSupport connSupport = serverConnection.GetServerSupport();
861 connResult = serverConnection.GetServerResult();
863 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
864 ASSERT_EQ(200, connResult.httpCode);
865 ASSERT_EQ(CURLE_OK, connResult.code);
866 ASSERT_EQ(true, connSupport.basicSupport);
868 // Get the list of calendars.
870 CalDAVCalendarList calendarList = serverConnection.GetCalendars();
872 // Check the response result from the server.
874 connResult = serverConnection.GetServerResult();
876 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
877 ASSERT_EQ(207, connResult.httpCode);
878 ASSERT_EQ(CURLE_OK, connResult.code);
880 // Get the calendar with the matching name.
883 bool itemFound = false;
885 for (map<int,string>::iterator calendarNameIter = calendarList.name.begin();
886 calendarNameIter != calendarList.name.end(); calendarNameIter++){
888 if (calendarNameIter->second == "Scratching Calendar"){
897 ASSERT_NE(false, itemFound);
899 string entryAddHREF = calendarList.href[itemSeek];
901 entryUUID = GenerateUUID();
902 entryUUID.erase(entryUUID.end()-1);
904 entryAddHREF.append(entryUUID);
905 entryAddHREF.append(".ics");
907 string addEntryData = "BEGIN:VCALENDAR\n"
909 "PRODID:-//Xestia//Calendar Unit Testing//KW\n"
912 addEntryData += entryUUID;
914 "DTSTAMP:20160116T190200Z\n"
915 "DTSTART:20160116T190200Z\n"
916 "DTEND:20160116T190200Z\n"
917 "SUMMARY:Unit Test Event 1 which has to be a really long summary as we don't k\n"
918 " now if multiple line processing is going to work without it. I mean seriousl\n"
919 " y, how annoying can this potentially be?\n"
923 connResult = serverConnection.AddEntry(&entryAddHREF, &addEntryData);
925 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
926 ASSERT_EQ(201, connResult.httpCode);
927 ASSERT_EQ(CURLE_OK, connResult.code);
929 // Set the EntryCalendarHREFProcessing for later on.
931 entryCalendarHREFProcessing = entryAddHREF;
935 TEST(CalDAV, GetEntryETag)
938 CalDAVConnectionData connNormal;
939 string currentUserPrincipal;
941 bool validDataNormal = false;
943 // Attempt to read the caldavtest.auth file.
945 ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
946 if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
947 validDataNormal = true;
950 ASSERT_EQ(true, validDataNormal);
952 // Setup the connection.
954 CalDAV serverConnection;
956 serverConnection.SetupConnectionData(&connNormal);
958 // Verify the connection settings.
960 CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
962 ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
963 ASSERT_EQ(calDAVStatus.username, connNormal.username);
964 ASSERT_EQ(calDAVStatus.port, connNormal.port);
965 ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
966 ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
968 // Connect to the server.
970 CalDAVServerResult connResult = serverConnection.Connect();
972 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
973 ASSERT_EQ(200, connResult.httpCode);
974 ASSERT_EQ(CURLE_OK, connResult.code);
976 // Check that the server supports CalDAV.
978 CalDAVServerSupport connSupport = serverConnection.GetServerSupport();
979 connResult = serverConnection.GetServerResult();
981 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
982 ASSERT_EQ(200, connResult.httpCode);
983 ASSERT_EQ(CURLE_OK, connResult.code);
984 ASSERT_EQ(true, connSupport.basicSupport);
986 // Get the list of calendars.
988 CalDAVCalendarList calendarList = serverConnection.GetCalendars();
990 // Check the response result from the server.
992 connResult = serverConnection.GetServerResult();
994 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
995 ASSERT_EQ(207, connResult.httpCode);
996 ASSERT_EQ(CURLE_OK, connResult.code);
998 // Get the entry entity tag.
1002 connResult = serverConnection.GetEntryETag(&entryCalendarHREFProcessing, &eTagValue);
1004 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1005 ASSERT_EQ(207, connResult.httpCode);
1006 ASSERT_EQ(CURLE_OK, connResult.code);
1010 TEST(CalDAV, EditEntry)
1013 // Check that EntryCalendarHREFProcessing is not blank.
1015 ASSERT_NE("", entryCalendarHREFProcessing);
1017 CalDAVConnectionData connNormal;
1018 string currentUserPrincipal;
1020 bool validDataNormal = false;
1022 // Attempt to read the caldavtest.auth file.
1024 ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
1025 if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
1026 validDataNormal = true;
1029 ASSERT_EQ(true, validDataNormal);
1031 // Setup the connection.
1033 CalDAV serverConnection;
1035 serverConnection.SetupConnectionData(&connNormal);
1037 // Verify the connection settings.
1039 CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
1041 ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
1042 ASSERT_EQ(calDAVStatus.username, connNormal.username);
1043 ASSERT_EQ(calDAVStatus.port, connNormal.port);
1044 ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
1045 ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
1047 // Connect to the server.
1049 CalDAVServerResult connResult = serverConnection.Connect();
1051 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1052 ASSERT_EQ(200, connResult.httpCode);
1053 ASSERT_EQ(CURLE_OK, connResult.code);
1055 // Check that the server supports CalDAV.
1057 CalDAVServerSupport connSupport = serverConnection.GetServerSupport();
1058 connResult = serverConnection.GetServerResult();
1060 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1061 ASSERT_EQ(200, connResult.httpCode);
1062 ASSERT_EQ(CURLE_OK, connResult.code);
1063 ASSERT_EQ(true, connSupport.basicSupport);
1065 // Get the list of calendars.
1067 CalDAVCalendarList calendarList = serverConnection.GetCalendars();
1069 // Check the response result from the server.
1071 connResult = serverConnection.GetServerResult();
1073 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1074 ASSERT_EQ(207, connResult.httpCode);
1075 ASSERT_EQ(CURLE_OK, connResult.code);
1077 // Get the entry entity tag.
1081 connResult = serverConnection.GetEntryETag(&entryCalendarHREFProcessing, &eTagValue);
1083 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1084 ASSERT_EQ(207, connResult.httpCode);
1085 ASSERT_EQ(CURLE_OK, connResult.code);
1087 // Update the contact with new information.
1089 string editEntryData = "BEGIN:VCALENDAR\n"
1091 "PRODID:-//Xestia//Calendar Unit Testing//KW\n"
1094 editEntryData += entryUUID;
1095 editEntryData += "\n"
1096 "DTSTAMP:20160116T190200Z\n"
1097 "DTSTART:20160116T190200Z\n"
1098 "DTEND:20160116T190200Z\n"
1099 "SUMMARY:Unit Test Event 1 which has to be a really long summary as we don't k\n"
1100 " now if multiple line processing is going to work without it. I mean seriousl\n"
1101 " y, how annoying can this potentially be?\n"
1105 connResult = serverConnection.EditEntry(&entryCalendarHREFProcessing, &editEntryData, &eTagValue);
1107 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1108 ASSERT_EQ(204, connResult.httpCode);
1109 ASSERT_EQ(CURLE_OK, connResult.code);
1113 TEST(CalDAV, DeleteEntry)
1116 // Check that EntryCalendarHREFProcessing is not blank.
1118 ASSERT_NE("", entryCalendarHREFProcessing);
1120 CalDAVConnectionData connNormal;
1121 string currentUserPrincipal;
1123 bool validDataNormal = false;
1125 // Attempt to read the caldavtest.auth file.
1127 ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
1128 if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
1129 validDataNormal = true;
1132 ASSERT_EQ(true, validDataNormal);
1134 // Setup the connection.
1136 CalDAV serverConnection;
1138 serverConnection.SetupConnectionData(&connNormal);
1140 // Verify the connection settings.
1142 CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
1144 ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
1145 ASSERT_EQ(calDAVStatus.username, connNormal.username);
1146 ASSERT_EQ(calDAVStatus.port, connNormal.port);
1147 ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
1148 ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
1150 // Connect to the server.
1152 CalDAVServerResult connResult = serverConnection.Connect();
1154 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1155 ASSERT_EQ(200, connResult.httpCode);
1156 ASSERT_EQ(CURLE_OK, connResult.code);
1158 // Check that the server supports CalDAV.
1160 CalDAVServerSupport connSupport = serverConnection.GetServerSupport();
1161 connResult = serverConnection.GetServerResult();
1163 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1164 ASSERT_EQ(200, connResult.httpCode);
1165 ASSERT_EQ(CURLE_OK, connResult.code);
1166 ASSERT_EQ(true, connSupport.basicSupport);
1168 // Delete the calendar entry.
1170 connResult = serverConnection.DeleteCalendar(&entryCalendarHREFProcessing);
1172 // Check the response result from the server.
1174 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1175 ASSERT_EQ(204, connResult.httpCode);
1176 ASSERT_EQ(CURLE_OK, connResult.code);
1180 TEST(CalDAV, GetEntryList)
1183 // Check that EntryCalendarHREFProcessing is not blank.
1185 ASSERT_NE("", entryCalendarHREFProcessing);
1187 CalDAVConnectionData connNormal;
1188 string currentUserPrincipal;
1190 bool validDataNormal = false;
1192 // Attempt to read the caldavtest.auth file.
1194 ProcessConnectionDataFileResult dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal);
1195 if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){
1196 validDataNormal = true;
1199 ASSERT_EQ(true, validDataNormal);
1201 // Setup the connection.
1203 CalDAV serverConnection;
1205 serverConnection.SetupConnectionData(&connNormal);
1207 // Verify the connection settings.
1209 CalDAVStatus calDAVStatus = serverConnection.GetConnectionData();
1211 ASSERT_EQ(calDAVStatus.hostname, connNormal.hostname);
1212 ASSERT_EQ(calDAVStatus.username, connNormal.username);
1213 ASSERT_EQ(calDAVStatus.port, connNormal.port);
1214 ASSERT_EQ(calDAVStatus.prefix, connNormal.prefix);
1215 ASSERT_EQ(calDAVStatus.useSSL, connNormal.useSSL);
1217 // Connect to the server.
1219 CalDAVServerResult connResult = serverConnection.Connect();
1221 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1222 ASSERT_EQ(200, connResult.httpCode);
1223 ASSERT_EQ(CURLE_OK, connResult.code);
1225 // Check that the server supports CalDAV.
1227 CalDAVServerSupport connSupport = serverConnection.GetServerSupport();
1228 connResult = serverConnection.GetServerResult();
1230 EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result);
1231 ASSERT_EQ(200, connResult.httpCode);
1232 ASSERT_EQ(CURLE_OK, connResult.code);
1233 ASSERT_EQ(true, connSupport.basicSupport);
1235 // Get the user principal.
1237 string userPrincipalURI = serverConnection.GetUserPrincipal();
1239 // Get the calendar home.
1241 string calendarHomeURL = serverConnection.GetCalendarHome(userPrincipalURI);
1243 string calendarHREF = calendarHomeURL;
1244 calendarHREF += "unittestcal/";
1246 // Get the entry list without a calendar tag set.
1248 CalDAVEntryList entryList = serverConnection.GetEntryList(&calendarHREF);
1250 EXPECT_GE(entryList.href.size(), 1);
1252 // Get the list of calendars.
1254 CalDAVCalendarList calendarList = serverConnection.GetCalendars();
1256 string calendarTagURL = "";
1258 for (std::map<int,string>::iterator calHREFIter = calendarList.href.begin();
1259 calHREFIter != calendarList.href.end(); calHREFIter++){
1261 if (calHREFIter->second.substr(calHREFIter->second.length() - 13) == "/unittestcal/"){
1263 calendarTagURL = calendarList.tagURL.find(calHREFIter->first)->second;
1269 // Get the entry list without a calendar tag set (shouldn't be empty).
1271 entryList = serverConnection.GetEntryList(&calendarHREF, nullptr);
1273 EXPECT_GE(entryList.href.size(), 1);
1275 // Get the entry list with a calendar tag set (should be empty).
1277 entryList = serverConnection.GetEntryList(&calendarHREF, &calendarTagURL);
1279 EXPECT_EQ(entryList.href.size(), 0);