X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;f=source%2Ftests%2Fxestiacalendar_caldav.h;h=87090ff81f53f1242bf950b2f75805b519e66c68;hb=cba151c4b833a26c63984769f921bab5e755decd;hp=bbbef3d287649ecc93a0b5725e113d0c822aee36;hpb=05662d2300b9da67452a77011de669b88e22cd75;p=xestiacalendar%2F.git diff --git a/source/tests/xestiacalendar_caldav.h b/source/tests/xestiacalendar_caldav.h index bbbef3d..87090ff 100644 --- a/source/tests/xestiacalendar_caldav.h +++ b/source/tests/xestiacalendar_caldav.h @@ -1,14 +1,14 @@ // xestiacalendar_caldav.h - Xestia Calendar CalDAV Object Unit Tests // -// (c) 2016 Xestia Software Development. +// (c) 2016-2017 Xestia Software Development. // // This file is part of Xestia Calendar. // -// Xestia Address Book is free software: you can redistribute it and/or modify +// Xestia Calendar is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by the // Free Software Foundation, version 3 of the license. // -// Xestia Address Book is distributed in the hope that it will be useful, +// Xestia Calendar is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. @@ -23,6 +23,7 @@ using namespace std; string EntryCalendarHREFProcessing = ""; +string EntryUUID = ""; TEST(CalDAV, BasicTests){ @@ -888,7 +889,7 @@ TEST(CalDAV, AddEntry){ string EntryAddHREF = CalendarList.HREF[ItemSeek]; - string EntryUUID = GenerateUUID(); + EntryUUID = GenerateUUID(); EntryUUID.erase(EntryUUID.end()-1); EntryAddHREF.append(EntryUUID); @@ -921,6 +922,180 @@ TEST(CalDAV, AddEntry){ 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); + + // 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); + +} + +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); } @@ -988,4 +1163,106 @@ TEST(CalDAV, DeleteEntry){ ASSERT_EQ(204, ConnResult.HTTPCode); ASSERT_EQ(CURLE_OK, ConnResult.Code); +} + +TEST(CalDAV, GetEntryList){ + + // 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 user principal. + + string UserPrincipalURI = ServerConnection.GetUserPrincipal(); + + // Get the calendar home. + + string CalendarHomeURL = ServerConnection.GetCalendarHome(UserPrincipalURI); + + string CalendarHREF = CalendarHomeURL; + CalendarHREF += "unittestcal/"; + + // Get the entry list without a calendar tag set. + + CalDAVEntryList EntryList = ServerConnection.GetEntryList(&CalendarHREF); + + EXPECT_GE(EntryList.HREF.size(), 1); + + // Get the list of calendars. + + CalDAVCalendarList CalendarList = ServerConnection.GetCalendars(); + + string CalendarTagURL = ""; + + for (std::map::iterator CalHREFIter = CalendarList.HREF.begin(); + CalHREFIter != CalendarList.HREF.end(); CalHREFIter++){ + + if (CalHREFIter->second.substr(CalHREFIter->second.length() - 13) == "/unittestcal/"){ + + CalendarTagURL = CalendarList.TagURL.find(CalHREFIter->first)->second; + + } + + } + + // Get the entry list without a calendar tag set (shouldn't be empty). + + EntryList = ServerConnection.GetEntryList(&CalendarHREF, nullptr); + + EXPECT_GE(EntryList.HREF.size(), 1); + + // Get the entry list with a calendar tag set (should be empty). + + EntryList = ServerConnection.GetEntryList(&CalendarHREF, &CalendarTagURL); + + EXPECT_EQ(EntryList.HREF.size(), 0); + } \ No newline at end of file