From: Steve Brokenshire Date: Sun, 24 Apr 2016 20:53:24 +0000 (+0100) Subject: Forgot to add unit tests for AddEntry in CalDAV object. X-Git-Tag: release-0.02~283 X-Git-Url: http://Server1/repobrowser/?a=commitdiff_plain;h=3511800e4e2c6630a24a4a4945f252f976da75c8;p=xestiacalendar%2F.git Forgot to add unit tests for AddEntry in CalDAV object. --- diff --git a/source/tests/xestiacalendar_caldav.h b/source/tests/xestiacalendar_caldav.h index 8ce08dd..53e482d 100644 --- a/source/tests/xestiacalendar_caldav.h +++ b/source/tests/xestiacalendar_caldav.h @@ -804,4 +804,119 @@ TEST(CalDAV, DeleteCalendar){ 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]; + + string 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); + + +} } \ No newline at end of file