Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added code and unit tests for deleting calendars in the CalDAV object
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sat, 23 Apr 2016 23:34:35 +0000 (00:34 +0100)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sat, 23 Apr 2016 23:34:35 +0000 (00:34 +0100)
Added the following subroutines to the CalDAV object:

DeleteCalendar(*string);

Unit tests setup for deleting calendars under CalDAV/DeleteCalendar
testing the above function.

source/objects/CalDAV/CalDAV.cpp
source/objects/CalDAV/CalDAV.h
source/tests/xestiacalendar_caldav.h

index 55ee65a..3d2e5de 100644 (file)
@@ -830,6 +830,75 @@ CalDAVServerResult CalDAV::EditCalendarDescription(string *CalendarHREF,
        return ServerResult;
        
 }
+
+CalDAVServerResult CalDAV::DeleteCalendar(string *CalendarHREF){
+
+       CalDAVServerResult ServerResult;
+       
+       // Build the server address.
+       
+       string UserPrincipalURI = "";
+       UserPrincipalURI = GetUserPrincipal();
+       
+       if (UserPrincipalURI.size() == 0){
+               
+               return ServerResult;
+               
+       }
+       
+       string CalendarHomeURI = "";
+       CalendarHomeURI = GetCalendarHome(UserPrincipalURI);
+       
+       // Generate the UUID.
+       
+       string UUIDValue = GenerateUUID();
+       UUIDValue.erase(UUIDValue.end()-1);
+       
+       string CalendarHomeURL = CalendarHomeURI;
+       CalendarHomeURL.append(UUIDValue);
+       CalendarHomeURL.append("/");
+       
+       // Build the calendar list address.
+       
+       struct curl_slist *DeleteRequestHeader = NULL;
+       
+       DeleteRequestHeader = curl_slist_append(DeleteRequestHeader, "Depth: infinity");
+       
+       string CalendarDeleteURLAddress = BuildServerAddress(&ConnectionData, (*CalendarHREF));
+       
+       curl_easy_setopt(ConnectionHandle, CURLOPT_HTTPHEADER, DeleteRequestHeader);
+       curl_easy_setopt(ConnectionHandle, CURLOPT_URL, CalendarDeleteURLAddress.c_str());
+       curl_easy_setopt(ConnectionHandle, CURLOPT_CUSTOMREQUEST, "DELETE");
+       
+       // Delete the calendar.
+       
+       ServerData.clear();
+       ServerHeader.clear();
+       
+       CURLcode ServerConnectionResult = curl_easy_perform(ConnectionHandle);
+       
+       if (ServerConnectionResult == CURLE_OK){
+               ServerResult.Result = CALDAVQUERYRESULT_OK;
+       } else {
+               ServerResult.Result = CALDAVQUERYRESULT_SERVERERROR;            
+       }
+       ServerResult.Code = ServerConnectionResult;
+       curl_easy_getinfo(ConnectionHandle, CURLINFO_RESPONSE_CODE, &ServerResult.HTTPCode);
+       
+       // Restore the original settings.
+       
+       string OriginalServerAddress = BuildServerAddress(&ConnectionData, "/principals/");
+       curl_easy_setopt(ConnectionHandle, CURLOPT_URL, OriginalServerAddress.c_str());
+       curl_easy_setopt(ConnectionHandle, CURLOPT_CUSTOMREQUEST, NULL);        
+       curl_easy_setopt(ConnectionHandle, CURLOPT_UPLOAD, 0L);
+       curl_easy_setopt(ConnectionHandle, CURLOPT_READDATA, NULL);
+       curl_easy_setopt(ConnectionHandle, CURLOPT_READFUNCTION, NULL);
+       curl_easy_setopt(ConnectionHandle, CURLOPT_HTTPHEADER, NULL);
+       
+       return ServerResult;
+       
+}
+
 bool CalDAVObjectValidSettings(CalDAVConnectionData *ConnData){
 
        // Check if the passed CalDAV Connection Data is has
index 9e9d553..208d11b 100644 (file)
@@ -162,6 +162,8 @@ class CalDAV{
                        int *CalendarOrder);
                CalDAVServerResult EditCalendarDescription(string *CalendarHREF,
                        string *CalendarDescription);
+               CalDAVServerResult DeleteCalendar(string *CalendarHREF);
+       
                string GetUserPrincipal();
                string GetCalendarHome(string UserPrincipalURI);
        
index f156b2a..0ecf485 100644 (file)
@@ -710,4 +710,106 @@ TEST(CalDAV, EditCalendar){
        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);
+       
+       // 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);
+       
+       // Get the calendar with the matching name.
+       
+       int ItemSeek = 0;
+       bool ItemFound = false;
+       
+       for (map<int,string>::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];
+       
+       cout << CalendarEditHREF << endl;
+       
+       ConnResult = ServerConnection.DeleteCalendar(&CalendarEditHREF);
+       
+       EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result);
+       ASSERT_EQ(204, ConnResult.HTTPCode);
+       ASSERT_EQ(CURLE_OK, ConnResult.Code);
+       
 }
\ No newline at end of file
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy