// xestiacalendar_caldav.h - Xestia Calendar CalDAV Object Unit Tests // // (c) 2016-2017 Xestia Software Development. // // This file is part of Xestia Calendar. // // Xestia Calendar is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by the // Free Software Foundation, version 3 of the license. // // Xestia Calendar is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with Xestia Calendar. If not, see #include "../objects/CalDAV/CalDAV.h" #include "xestiacalendar_testcommon.h" #include #include using namespace std; string EntryCalendarHREFProcessing = ""; string EntryUUID = ""; TEST(CalDAV, BasicTests){ CalDAVConnectionData ConnPlain; CalDAVConnectionData ConnNormal; CalDAVConnectionData ConnInvalidSSL; CalDAVConnectionData ConnTimeout; ProcessConnectionDataFileResult DataFileResult; bool ValidDataPlain = false; bool ValidDataNormal = false; bool ValidDataInvalidSSL = false; bool ValidDataTimeout = false; // Attempt to read the caldavtest-plain.auth file. DataFileResult = ProcessConnectionDataFile("caldavtest-plain.auth", &ConnPlain); if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){ ValidDataPlain = true; } // Attempt to read the caldavtest.auth file. DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal); if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){ ValidDataNormal = true; } // Attempt to read the caldavtest-fail.auth file. DataFileResult = ProcessConnectionDataFile("caldavtest-fail.auth", &ConnInvalidSSL); if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){ ValidDataInvalidSSL = true; } // Attempt to read the caldavtest-timeout.auth file. DataFileResult = ProcessConnectionDataFile("caldavtest-timeout.auth", &ConnTimeout); if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){ ValidDataTimeout = true; } if (ValidDataPlain == false){ // Cannot read the caldavtest-plain.auth file properly. cout << "The caldavtest-plain.auth file does not exist or is invalid!" << endl; cout << "Please create the caldavtest-plain.auth file using the following format:" << endl << endl; cout << "server=localname" << endl; cout << "port=8080" << endl; cout << "user=username" << endl; cout << "pass=password" << endl; cout << "ssl=false" << endl; cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl; } if (ValidDataNormal == false){ // Cannot read the caldavtest.auth file properly. cout << "The caldavtest.auth file does not exist or is invalid!" << endl; cout << "Please create the caldavtest.auth file using the following format:" << endl << endl; cout << "server=localname" << endl; cout << "port=8080" << endl; cout << "user=username" << endl; cout << "pass=password" << endl; cout << "ssl=false" << endl; cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl; } if (ValidDataInvalidSSL == false){ // Cannot read the caldavtest-fail.auth file properly. cout << "The caldavtest-fail.auth file does not exist or is invalid!" << endl; cout << "Please create the caldavtest-fail.auth file using the following format:" << endl << endl; cout << "server=fail.localname" << endl; cout << "port=8080" << endl; cout << "user=username" << endl; cout << "pass=password" << endl; cout << "ssl=false" << endl; cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl; } if (ValidDataTimeout == false){ // Cannot read the caldavtest-timeout.auth file properly. cout << "The caldavtest-timeout.auth file does not exist or is invalid!" << endl; cout << "Please create the caldavtest-timeout.auth file using the following format:" << endl << endl; cout << "server=fail.localname" << endl; cout << "port=8080" << endl; cout << "user=username" << endl; cout << "pass=password" << endl; cout << "ssl=false" << endl; cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl; } ASSERT_EQ(true, ValidDataPlain); ASSERT_EQ(true, ValidDataNormal); ASSERT_EQ(true, ValidDataInvalidSSL); ASSERT_EQ(true, ValidDataTimeout); // (*nix version) Setup an initial connection (just plain // text). CalDAV CalDAVPlain; CalDAVPlain.SetupConnectionData(&ConnPlain); // Verify that the settings match with the CalDAVConnectionData // passed. CalDAVStatus CalDAVPlainStatus = CalDAVPlain.GetConnectionData(); ASSERT_EQ(CalDAVPlainStatus.Hostname, ConnPlain.Hostname); ASSERT_EQ(CalDAVPlainStatus.Username, ConnPlain.Username); ASSERT_EQ(CalDAVPlainStatus.Port, ConnPlain.Port); ASSERT_EQ(CalDAVPlainStatus.Prefix, ConnPlain.Prefix); ASSERT_EQ(CalDAVPlainStatus.UseSSL, ConnPlain.UseSSL); // Verify that the connection was successful. CalDAVServerResult ConnResult = CalDAVPlain.Connect(); ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Do another connection and this time the connection should // fail due to being an invalid host name. CalDAVConnectionData ConnPlainFail; ConnPlainFail.Hostname = "server.invalid"; ConnPlainFail.Username = "fail"; ConnPlainFail.Password = "fail"; ConnPlainFail.Port = 80; ConnPlainFail.UseSSL = false; // Setup the CalDAV connection object. CalDAV CalDAVPlainFail; CalDAVPlainFail.SetupConnectionData(&ConnPlainFail); // Setup the CalDAVStatus object. CalDAVStatus CalDAVPlainFailStatus = CalDAVPlain.GetConnectionData(); // Connect and fail. ConnResult = CalDAVPlainFail.Connect(); ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, ConnResult.Result); ASSERT_EQ(0, ConnResult.HTTPCode); ASSERT_EQ(CURLE_COULDNT_RESOLVE_HOST, ConnResult.Code); // (*nix version) Setup an initial connection (with a valid // SSL certificate). CalDAV CalDAVNormal; CalDAVNormal.SetupConnectionData(&ConnNormal); // Verify that the settings match with the CalDAVConnectionData // passed. CalDAVStatus CalDAVNormalStatus = CalDAVNormal.GetConnectionData(); ASSERT_EQ(CalDAVNormalStatus.Hostname, ConnNormal.Hostname); ASSERT_EQ(CalDAVNormalStatus.Username, ConnNormal.Username); ASSERT_EQ(CalDAVNormalStatus.Port, ConnNormal.Port); ASSERT_EQ(CalDAVNormalStatus.Prefix, ConnNormal.Prefix); ASSERT_EQ(CalDAVNormalStatus.UseSSL, ConnNormal.UseSSL); // Verify that the connection was successful (with a valid // SSL certificate). ConnResult = CalDAVNormal.Connect(); ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // (*nix version) Setup an initial connection on a server that // will fail due to having an invalid SSL certificate. CalDAV CalDAVInvalidSSL; CalDAVInvalidSSL.SetupConnectionData(&ConnInvalidSSL); // Verify that the settings match with the CalDAVConnectionData // passed. CalDAVStatus CalDAVInvalidSSLStatus = CalDAVInvalidSSL.GetConnectionData(); ASSERT_EQ(CalDAVInvalidSSLStatus.Hostname, ConnInvalidSSL.Hostname); ASSERT_EQ(CalDAVInvalidSSLStatus.Username, ConnInvalidSSL.Username); ASSERT_EQ(CalDAVInvalidSSLStatus.Port, ConnInvalidSSL.Port); ASSERT_EQ(CalDAVInvalidSSLStatus.Prefix, ConnInvalidSSL.Prefix); ASSERT_EQ(CalDAVInvalidSSLStatus.UseSSL, ConnInvalidSSL.UseSSL); // Verify that the connection had failed. (with an invalid // SSL certificate). ConnResult = CalDAVInvalidSSL.Connect(); ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, ConnResult.Result); ASSERT_EQ(0, ConnResult.HTTPCode); ASSERT_EQ(CURLE_SSL_CACERT, ConnResult.Code); // (*nix version) Setup an inital connection on a server where // a timeout occurs. ConnTimeout.Timeout = 5; CalDAV CalDAVTimeout; CalDAVTimeout.SetupConnectionData(&ConnTimeout); // Verify that the settings match with the CalDAVConnectionData // passed. CalDAVStatus CalDAVTimeoutStatus = CalDAVTimeout.GetConnectionData(); ASSERT_EQ(CalDAVTimeoutStatus.Hostname, ConnTimeout.Hostname); ASSERT_EQ(CalDAVTimeoutStatus.Username, ConnTimeout.Username); ASSERT_EQ(CalDAVTimeoutStatus.Port, ConnTimeout.Port); ASSERT_EQ(CalDAVTimeoutStatus.Prefix, ConnTimeout.Prefix); ASSERT_EQ(CalDAVTimeoutStatus.Timeout, ConnTimeout.Timeout); ASSERT_EQ(CalDAVTimeoutStatus.UseSSL, ConnTimeout.UseSSL); // Verify that the connection had timed out. ConnResult = CalDAVTimeout.Connect(); ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, ConnResult.Result); ASSERT_EQ(0, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OPERATION_TIMEDOUT, ConnResult.Code); } TEST(CalDAV, BuildServerAddress){ CalDAVConnectionData ConnNormal; ProcessConnectionDataFileResult DataFileResult; bool ValidDataNormal = false; // Attempt to read the caldavtest.auth file. DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal); if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){ ValidDataNormal = true; } if (ValidDataNormal == false){ // Cannot read the caldavtest.auth file properly. cout << "The caldavtest.auth file does not exist or is invalid!" << endl; cout << "Please create the caldavtest.auth file using the following format:" << endl << endl; cout << "server=localname" << endl; cout << "port=8080" << endl; cout << "user=username" << endl; cout << "pass=password" << endl; cout << "ssl=false" << endl; cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl; } ASSERT_EQ(true, ValidDataNormal); // Setup the server address to check. string ServerAddress; // Setup the server address. if (ConnNormal.UseSSL == true){ ServerAddress += "https://"; } else { ServerAddress += "http://"; } ServerAddress += ConnNormal.Hostname; // Check if server port is 80, otherwise // specifiy the port number in the address. if (ConnNormal.Port != 80){ ServerAddress += ":"; ServerAddress += to_string(ConnNormal.Port); } ServerAddress += "/principals/"; ASSERT_EQ(ServerAddress, BuildServerAddress(&ConnNormal, "/principals/")); } TEST(CalDAV, CalendarServerSupport){ CalDAVConnectionData ConnNormal; bool ValidDataNormal = false; // Attempt to read the caldavtest.auth file. ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal); if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){ ValidDataNormal = true; } ASSERT_EQ(true, ValidDataNormal); // Setup the connection. CalDAV ServerConnection; ServerConnection.SetupConnectionData(&ConnNormal); // Verify the connection settings. CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData(); ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname); ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username); ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port); ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix); ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL); // Connect to the server. CalDAVServerResult ConnResult = ServerConnection.Connect(); ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Check for basic support of the calendar server. CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport(); ASSERT_EQ(true, ConnSupport.BasicSupport); } TEST(CalDAV, GetCalendarHome){ CalDAVConnectionData ConnNormal; bool ValidDataNormal = false; // Attempt to read the caldavtest.auth file. ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal); if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){ ValidDataNormal = true; } ASSERT_EQ(true, ValidDataNormal); // Setup the connection. CalDAV ServerConnection; ServerConnection.SetupConnectionData(&ConnNormal); // Verify the connection settings. CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData(); ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname); ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username); ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port); ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix); ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL); // Connect to the server. CalDAVServerResult ConnResult = ServerConnection.Connect(); ASSERT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Check for basic support of the calendar server. CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport(); ASSERT_EQ(true, ConnSupport.BasicSupport); // Get the user principal. string CurrentUserPrincipal = ServerConnection.GetUserPrincipal(); // Check the response from the server. ConnResult = ServerConnection.GetServerResult(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(207, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Get the calendar home. string CalendarHome = ServerConnection.GetCalendarHome(CurrentUserPrincipal); // Check the response from the server. ConnResult = ServerConnection.GetServerResult(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(207, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); } TEST(CalDAV, ListCalendars){ CalDAVConnectionData ConnNormal; string CurrentUserPrincipal; bool ValidDataNormal = false; // Attempt to read the caldavtest.auth file. ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal); if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){ ValidDataNormal = true; } ASSERT_EQ(true, ValidDataNormal); // Setup the connection. CalDAV ServerConnection; ServerConnection.SetupConnectionData(&ConnNormal); // Verify the connection settings. CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData(); ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname); ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username); ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port); ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix); ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL); // Connect to the server. CalDAVServerResult ConnResult = ServerConnection.Connect(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Check that the server supports CalDAV. CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport(); ConnResult = ServerConnection.GetServerResult(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); ASSERT_EQ(true, ConnSupport.BasicSupport); // Get the list of calendars. CalDAVCalendarList CalendarList = ServerConnection.GetCalendars(); // Check the response result from the server. ConnResult = ServerConnection.GetServerResult(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(207, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); } TEST(CalDAV, AddCalendar){ CalDAVConnectionData ConnNormal; string CurrentUserPrincipal; bool ValidDataNormal = false; // Attempt to read the caldavtest.auth file. ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal); if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){ ValidDataNormal = true; } ASSERT_EQ(true, ValidDataNormal); // Setup the connection. CalDAV ServerConnection; ServerConnection.SetupConnectionData(&ConnNormal); // Verify the connection settings. CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData(); ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname); ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username); ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port); ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix); ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL); // Connect to the server. CalDAVServerResult ConnResult = ServerConnection.Connect(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Add a calendar to the server. ConnResult = ServerConnection.AddCalendar("New Calendar"); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(201, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); } TEST(CalDAV, EditCalendar){ CalDAVConnectionData ConnNormal; string CurrentUserPrincipal; bool ValidDataNormal = false; // Attempt to read the caldavtest.auth file. ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal); if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){ ValidDataNormal = true; } ASSERT_EQ(true, ValidDataNormal); // Setup the connection. CalDAV ServerConnection; ServerConnection.SetupConnectionData(&ConnNormal); // Verify the connection settings. CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData(); ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname); ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username); ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port); ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix); ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL); // Connect to the server. CalDAVServerResult ConnResult = ServerConnection.Connect(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Check that the server supports CalDAV. CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport(); ConnResult = ServerConnection.GetServerResult(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); ASSERT_EQ(true, ConnSupport.BasicSupport); // Add a calendar to the server. ConnResult = ServerConnection.AddCalendar("Calendar To Edit"); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(201, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Get the list of calendars. CalDAVCalendarList CalendarList = ServerConnection.GetCalendars(); // Check the response result from the server. ConnResult = ServerConnection.GetServerResult(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(207, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Find the calendar containing the name "Calendar To Edit" // created earlier. int ItemSeek = 0; bool ItemFound = false; for (map::iterator CalendarNameIter = CalendarList.Name.begin(); CalendarNameIter != CalendarList.Name.end(); CalendarNameIter++){ if (CalendarNameIter->second == "Calendar To Edit"){ ItemFound = true; break; } ItemSeek++; } ASSERT_NE(false, ItemFound); // Edit the name of the calendar. string CalendarEditHREF = CalendarList.HREF[ItemSeek]; string NewCalendarName = "Edited Calendar"; ConnResult = ServerConnection.EditCalendar(&CalendarEditHREF, &NewCalendarName); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(207, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Edit the colour of the calendar. Colour NewColour; NewColour.red = 255; NewColour.green = 0; NewColour.blue = 0; NewColour.alpha = 0; ConnResult = ServerConnection.EditCalendar(&CalendarEditHREF, &NewColour); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(207, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Edit the description of the calendar. string NewCalendarDescription = "Update Calendar Description"; ConnResult = ServerConnection.EditCalendarDescription(&CalendarEditHREF, &NewCalendarDescription); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(207, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Edit the order of the calendar. int NewCalendarOrder = 30; ConnResult = ServerConnection.EditCalendar(&CalendarEditHREF, &NewCalendarOrder); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(207, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Edit all of the available properties of the calendar. NewCalendarName = "Calendar Edited Again"; NewCalendarDescription = "Another updated calendar description"; NewColour.red = 0; NewColour.green = 255; NewColour.blue = 0; NewColour.alpha = 0; NewCalendarOrder = 40; ConnResult = ServerConnection.EditCalendar(&CalendarEditHREF, &NewCalendarName, &NewColour, &NewCalendarDescription, &NewCalendarOrder); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(207, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); } TEST(CalDAV, DeleteCalendar){ CalDAVConnectionData ConnNormal; string CurrentUserPrincipal; bool ValidDataNormal = false; // Attempt to read the caldavtest.auth file. ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal); if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){ ValidDataNormal = true; } ASSERT_EQ(true, ValidDataNormal); // Setup the connection. CalDAV ServerConnection; ServerConnection.SetupConnectionData(&ConnNormal); // Verify the connection settings. CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData(); ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname); ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username); ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port); ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix); ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL); // Connect to the server. CalDAVServerResult ConnResult = ServerConnection.Connect(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Check that the server supports CalDAV. CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport(); ConnResult = ServerConnection.GetServerResult(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); ASSERT_EQ(true, ConnSupport.BasicSupport); // Get the list of calendars. CalDAVCalendarList CalendarList = ServerConnection.GetCalendars(); // Check the response result from the server. ConnResult = ServerConnection.GetServerResult(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(207, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Get the calendar with the matching name. int ItemSeek = 0; bool ItemFound = false; for (map::iterator CalendarNameIter = CalendarList.Name.begin(); CalendarNameIter != CalendarList.Name.end(); CalendarNameIter++){ if (CalendarNameIter->second == "Calendar Edited Again"){ ItemFound = true; break; } ItemSeek++; } ASSERT_NE(false, ItemFound); // Delete some calendars. string CalendarEditHREF = CalendarList.HREF[ItemSeek]; ConnResult = ServerConnection.DeleteCalendar(&CalendarEditHREF); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(204, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); } TEST(CalDAV, AddEntry){ CalDAVConnectionData ConnNormal; string CurrentUserPrincipal; bool ValidDataNormal = false; // Attempt to read the caldavtest.auth file. ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal); if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){ ValidDataNormal = true; } ASSERT_EQ(true, ValidDataNormal); // Setup the connection. CalDAV ServerConnection; ServerConnection.SetupConnectionData(&ConnNormal); // Verify the connection settings. CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData(); ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname); ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username); ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port); ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix); ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL); // Connect to the server. CalDAVServerResult ConnResult = ServerConnection.Connect(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Check that the server supports CalDAV. CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport(); ConnResult = ServerConnection.GetServerResult(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); ASSERT_EQ(true, ConnSupport.BasicSupport); // Get the list of calendars. CalDAVCalendarList CalendarList = ServerConnection.GetCalendars(); // Check the response result from the server. ConnResult = ServerConnection.GetServerResult(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(207, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Get the calendar with the matching name. int ItemSeek = 0; bool ItemFound = false; for (map::iterator CalendarNameIter = CalendarList.Name.begin(); CalendarNameIter != CalendarList.Name.end(); CalendarNameIter++){ if (CalendarNameIter->second == "Scratching Calendar"){ ItemFound = true; break; } ItemSeek++; } ASSERT_NE(false, ItemFound); string EntryAddHREF = CalendarList.HREF[ItemSeek]; EntryUUID = GenerateUUID(); EntryUUID.erase(EntryUUID.end()-1); EntryAddHREF.append(EntryUUID); EntryAddHREF.append(".ics"); string AddEntryData = "BEGIN:VCALENDAR\n" "VERSION:2.0\n" "PRODID:-//Xestia//Calendar Unit Testing//KW\n" "BEGIN:VEVENT\n" "UID:"; AddEntryData += EntryUUID; AddEntryData += "\n" "DTSTAMP:20160116T190200Z\n" "DTSTART:20160116T190200Z\n" "DTEND:20160116T190200Z\n" "SUMMARY:Unit Test Event 1 which has to be a really long summary as we don't k\n" " now if multiple line processing is going to work without it. I mean seriousl\n" " y, how annoying can this potentially be?\n" "END:VEVENT\n" "END:VCALENDAR\n"; ConnResult = ServerConnection.AddEntry(&EntryAddHREF, &AddEntryData); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(201, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Set the EntryCalendarHREFProcessing for later on. EntryCalendarHREFProcessing = EntryAddHREF; } TEST(CalDAV, GetEntryETag){ CalDAVConnectionData ConnNormal; string CurrentUserPrincipal; bool ValidDataNormal = false; // Attempt to read the caldavtest.auth file. ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal); if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){ ValidDataNormal = true; } ASSERT_EQ(true, ValidDataNormal); // Setup the connection. CalDAV ServerConnection; ServerConnection.SetupConnectionData(&ConnNormal); // Verify the connection settings. CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData(); ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname); ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username); ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port); ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix); ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL); // Connect to the server. CalDAVServerResult ConnResult = ServerConnection.Connect(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Check that the server supports CalDAV. CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport(); ConnResult = ServerConnection.GetServerResult(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); ASSERT_EQ(true, ConnSupport.BasicSupport); // Get the list of calendars. CalDAVCalendarList CalendarList = ServerConnection.GetCalendars(); // Check the response result from the server. ConnResult = ServerConnection.GetServerResult(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(207, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Get the entry entity tag. string ETagValue; ConnResult = ServerConnection.GetEntryETag(&EntryCalendarHREFProcessing, &ETagValue); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(207, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); } TEST(CalDAV, EditEntry){ // Check that EntryCalendarHREFProcessing is not blank. ASSERT_NE("", EntryCalendarHREFProcessing); CalDAVConnectionData ConnNormal; string CurrentUserPrincipal; bool ValidDataNormal = false; // Attempt to read the caldavtest.auth file. ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal); if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){ ValidDataNormal = true; } ASSERT_EQ(true, ValidDataNormal); // Setup the connection. CalDAV ServerConnection; ServerConnection.SetupConnectionData(&ConnNormal); // Verify the connection settings. CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData(); ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname); ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username); ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port); ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix); ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL); // Connect to the server. CalDAVServerResult ConnResult = ServerConnection.Connect(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Check that the server supports CalDAV. CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport(); ConnResult = ServerConnection.GetServerResult(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); ASSERT_EQ(true, ConnSupport.BasicSupport); // Get the list of calendars. CalDAVCalendarList CalendarList = ServerConnection.GetCalendars(); // Check the response result from the server. ConnResult = ServerConnection.GetServerResult(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(207, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Get the entry entity tag. string ETagValue; ConnResult = ServerConnection.GetEntryETag(&EntryCalendarHREFProcessing, &ETagValue); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(207, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Update the contact with new information. string EditEntryData = "BEGIN:VCALENDAR\n" "VERSION:2.0\n" "PRODID:-//Xestia//Calendar Unit Testing//KW\n" "BEGIN:VEVENT\n" "UID:"; EditEntryData += EntryUUID; EditEntryData += "\n" "DTSTAMP:20160116T190200Z\n" "DTSTART:20160116T190200Z\n" "DTEND:20160116T190200Z\n" "SUMMARY:Unit Test Event 1 which has to be a really long summary as we don't k\n" " now if multiple line processing is going to work without it. I mean seriousl\n" " y, how annoying can this potentially be?\n" "END:VEVENT\n" "END:VCALENDAR\n"; ConnResult = ServerConnection.EditEntry(&EntryCalendarHREFProcessing, &EditEntryData, &ETagValue); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(204, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); } TEST(CalDAV, DeleteEntry){ // Check that EntryCalendarHREFProcessing is not blank. ASSERT_NE("", EntryCalendarHREFProcessing); CalDAVConnectionData ConnNormal; string CurrentUserPrincipal; bool ValidDataNormal = false; // Attempt to read the caldavtest.auth file. ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal); if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){ ValidDataNormal = true; } ASSERT_EQ(true, ValidDataNormal); // Setup the connection. CalDAV ServerConnection; ServerConnection.SetupConnectionData(&ConnNormal); // Verify the connection settings. CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData(); ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname); ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username); ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port); ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix); ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL); // Connect to the server. CalDAVServerResult ConnResult = ServerConnection.Connect(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Check that the server supports CalDAV. CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport(); ConnResult = ServerConnection.GetServerResult(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); ASSERT_EQ(true, ConnSupport.BasicSupport); // Delete the calendar entry. ConnResult = ServerConnection.DeleteCalendar(&EntryCalendarHREFProcessing); // Check the response result from the server. EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(204, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); } TEST(CalDAV, GetEntryList){ // Check that EntryCalendarHREFProcessing is not blank. ASSERT_NE("", EntryCalendarHREFProcessing); CalDAVConnectionData ConnNormal; string CurrentUserPrincipal; bool ValidDataNormal = false; // Attempt to read the caldavtest.auth file. ProcessConnectionDataFileResult DataFileResult = ProcessConnectionDataFile("caldavtest.auth", &ConnNormal); if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){ ValidDataNormal = true; } ASSERT_EQ(true, ValidDataNormal); // Setup the connection. CalDAV ServerConnection; ServerConnection.SetupConnectionData(&ConnNormal); // Verify the connection settings. CalDAVStatus CalDAVStatus = ServerConnection.GetConnectionData(); ASSERT_EQ(CalDAVStatus.Hostname, ConnNormal.Hostname); ASSERT_EQ(CalDAVStatus.Username, ConnNormal.Username); ASSERT_EQ(CalDAVStatus.Port, ConnNormal.Port); ASSERT_EQ(CalDAVStatus.Prefix, ConnNormal.Prefix); ASSERT_EQ(CalDAVStatus.UseSSL, ConnNormal.UseSSL); // Connect to the server. CalDAVServerResult ConnResult = ServerConnection.Connect(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); // Check that the server supports CalDAV. CalDAVServerSupport ConnSupport = ServerConnection.GetServerSupport(); ConnResult = ServerConnection.GetServerResult(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); ASSERT_EQ(200, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); ASSERT_EQ(true, ConnSupport.BasicSupport); // Get the user principal. string UserPrincipalURI = ServerConnection.GetUserPrincipal(); // Get the calendar home. string CalendarHomeURL = ServerConnection.GetCalendarHome(UserPrincipalURI); string CalendarHREF = CalendarHomeURL; CalendarHREF += "unittestcal/"; // Get the entry list without a calendar tag set. CalDAVEntryList EntryList = ServerConnection.GetEntryList(&CalendarHREF); EXPECT_GE(EntryList.HREF.size(), 1); // Get the list of calendars. CalDAVCalendarList CalendarList = ServerConnection.GetCalendars(); string CalendarTagURL = ""; for (std::map::iterator CalHREFIter = CalendarList.HREF.begin(); CalHREFIter != CalendarList.HREF.end(); CalHREFIter++){ if (CalHREFIter->second.substr(CalHREFIter->second.length() - 13) == "/unittestcal/"){ CalendarTagURL = CalendarList.TagURL.find(CalHREFIter->first)->second; } } // Get the entry list without a calendar tag set (shouldn't be empty). EntryList = ServerConnection.GetEntryList(&CalendarHREF, nullptr); EXPECT_GE(EntryList.HREF.size(), 1); // Get the entry list with a calendar tag set (should be empty). EntryList = ServerConnection.GetEntryList(&CalendarHREF, &CalendarTagURL); EXPECT_EQ(EntryList.HREF.size(), 0); }