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

CalDAVServerResult EditEntry(string *CalendarEntryHREF, string
*EntryData, string *EntryETag);

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

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

index ae416aa..a94640f 100644 (file)
@@ -1057,9 +1057,30 @@ CalDAVServerResult CalDAV::AddEntry(string *CalendarEntryHREF, string *EntryData
        
 }
 
+CalDAVServerResult CalDAV::EditEntry(string *CalendarEntryHREF, string *EntryData, string *EntryETag){
+       
+       // Edit an entry in the calendar collection.
+
+       // Add an entry to the calendar collection.
+       
+       CalDAVServerResult ServerResult;
+       CalDAVSendData EntryAddSendData;
+       
+       // Build the calendar list address.
+       
+       string EntryAddURLAddress = BuildServerAddress(&ConnectionData, (*CalendarEntryHREF));
+       
+       EntryAddSendData.readptr = EntryData;
+       EntryAddSendData.sizeleft = EntryData->size();
+       
+       string IfMatchHeader = "If-Match: \"";
+       IfMatchHeader.append(*EntryETag);
+       IfMatchHeader.append("\"");
+       
        struct curl_slist *CalendarRequestHeader = NULL;
        
        CalendarRequestHeader = curl_slist_append(CalendarRequestHeader, "Content-Type: text/calendar; charset=utf-8");
+       CalendarRequestHeader = curl_slist_append(CalendarRequestHeader, IfMatchHeader.c_str());        
        
        curl_easy_setopt(ConnectionHandle, CURLOPT_HTTPHEADER, CalendarRequestHeader);
        curl_easy_setopt(ConnectionHandle, CURLOPT_URL, EntryAddURLAddress.c_str());
index d632a60..080975c 100644 (file)
@@ -169,6 +169,7 @@ class CalDAV{
                CalDAVServerResult DeleteCalendar(string *CalendarHREF);
                
                CalDAVServerResult AddEntry(string *CalendarEntryHREF, string *EntryData);
+               CalDAVServerResult EditEntry(string *CalendarEntryHREF, string *EntryData, string *EntryETag);
                CalDAVServerResult DeleteEntry(string *CalendarEntryHREF);
        
                string GetUserPrincipal();
index 8df040a..4e4b638 100644 (file)
@@ -994,6 +994,106 @@ TEST(CalDAV, GetEntryETag){
        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);
        
 }
 
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