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

DeleteEntry(*string);

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

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

index 467f3e1..bc62ff2 100644 (file)
@@ -961,6 +961,50 @@ CalDAVServerResult CalDAV::AddEntry(string *CalendarEntryHREF, string *EntryData
        return ServerResult;
        
 }
+
+CalDAVServerResult CalDAV::DeleteEntry(string *CalendarEntryHREF){
+       
+       // Delete an entry in the calendar collection.
+       
+       CalDAVServerResult ServerResult;
+       
+       // Build the calendar list address.
+       
+       string EntryDeleteURLAddress = BuildServerAddress(&ConnectionData, (*CalendarEntryHREF));
+       
+       curl_easy_setopt(ConnectionHandle, CURLOPT_HTTPHEADER, NULL);
+       curl_easy_setopt(ConnectionHandle, CURLOPT_URL, EntryDeleteURLAddress.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 0774cc0..f990b76 100644 (file)
@@ -168,6 +168,7 @@ class CalDAV{
                CalDAVServerResult DeleteCalendar(string *CalendarHREF);
                
                CalDAVServerResult AddEntry(string *CalendarEntryHREF, string *EntryData);
+               CalDAVServerResult DeleteEntry(string *CalendarEntryHREF);
        
                string GetUserPrincipal();
                string GetCalendarHome(string UserPrincipalURI);
index f20ef90..bbbef3d 100644 (file)
@@ -22,6 +22,7 @@
 #include <map>
 
 using namespace std;
+string EntryCalendarHREFProcessing = "";
 
 TEST(CalDAV, BasicTests){
 
@@ -915,6 +916,76 @@ TEST(CalDAV, AddEntry){
        ASSERT_EQ(201, ConnResult.HTTPCode);
        ASSERT_EQ(CURLE_OK, ConnResult.Code);
        
+       // Set the EntryCalendarHREFProcessing for later on.
+       
+       EntryCalendarHREFProcessing = EntryAddHREF;
+       
+}
        
 }
+
+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);
+       
 }
\ 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