X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;f=source%2Ftests%2Fxestiacalendar_caldav.h;h=4e4b638ecce9a14c7f2e351dfa7ddb3aa2382131;hb=b21ea336e08289c984eccd4baeefdb67e5901281;hp=0ecf48525bc26f87f902a1638e350e57d5f57e17;hpb=91fbe7fbe1eb9b7dd98faccb64102c7b0e7beeeb;p=xestiacalendar%2F.git diff --git a/source/tests/xestiacalendar_caldav.h b/source/tests/xestiacalendar_caldav.h index 0ecf485..4e4b638 100644 --- a/source/tests/xestiacalendar_caldav.h +++ b/source/tests/xestiacalendar_caldav.h @@ -22,6 +22,8 @@ #include using namespace std; +string EntryCalendarHREFProcessing = ""; +string EntryUUID = ""; TEST(CalDAV, BasicTests){ @@ -761,14 +763,99 @@ TEST(CalDAV, DeleteCalendar){ ASSERT_EQ(CURLE_OK, ConnResult.Code); ASSERT_EQ(true, ConnSupport.BasicSupport); - // Add a calendar to the server. + // Get the list of calendars. - ConnResult = ServerConnection.AddCalendar("Calendar To Edit"); + CalDAVCalendarList CalendarList = ServerConnection.GetCalendars(); + + // Check the response result from the server. + + ConnResult = ServerConnection.GetServerResult(); EXPECT_EQ(CALDAVQUERYRESULT_OK, ConnResult.Result); - ASSERT_EQ(201, ConnResult.HTTPCode); + 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(); @@ -789,7 +876,7 @@ TEST(CalDAV, DeleteCalendar){ for (map::iterator CalendarNameIter = CalendarList.Name.begin(); CalendarNameIter != CalendarList.Name.end(); CalendarNameIter++){ - if (CalendarNameIter->second == "Calendar Edited Again"){ + if (CalendarNameIter->second == "Scratching Calendar"){ ItemFound = true; break; } @@ -800,13 +887,275 @@ TEST(CalDAV, DeleteCalendar){ ASSERT_NE(false, ItemFound); - // Delete some calendars. + string EntryAddHREF = CalendarList.HREF[ItemSeek]; - string CalendarEditHREF = CalendarList.HREF[ItemSeek]; + EntryUUID = GenerateUUID(); + EntryUUID.erase(EntryUUID.end()-1); - cout << CalendarEditHREF << endl; + EntryAddHREF.append(EntryUUID); + EntryAddHREF.append(".ics"); - ConnResult = ServerConnection.DeleteCalendar(&CalendarEditHREF); + 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); + + 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);