X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;f=source%2Ftests%2Fxestiacalendar_caldav.h;h=200d989f6651fa2634784db941a79586df03cf89;hb=2e304ff435c80c07daaf0d3fbe8a9ab7d1ae70b1;hp=1bb636650801b86331d2805a95de2a40f8c173fd;hpb=497e770ff0c01c48bb7212916de151f139f024e4;p=xestiacalendar%2F.git diff --git a/source/tests/xestiacalendar_caldav.h b/source/tests/xestiacalendar_caldav.h index 1bb6366..200d989 100644 --- a/source/tests/xestiacalendar_caldav.h +++ b/source/tests/xestiacalendar_caldav.h @@ -1,14 +1,14 @@ -// xestiacalendar_icaleventload.h - Xestia Calendar CalDAV Object Unit Tests +// 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. @@ -17,24 +17,56 @@ // with Xestia Calendar. If not, see #include "../objects/CalDAV/CalDAV.h" +#include "xestiacalendar_testcommon.h" #include #include using namespace std; +string EntryCalendarHREFProcessing = ""; +string EntryUUID = ""; TEST(CalDAV, BasicTests){ - bool ValidDataPlain = false; - bool ValidDataNormal = false; - bool ValidDataFail = false; - bool ValidDataTimeout = false; + CalDAVConnectionData connPlain; + CalDAVConnectionData connNormal; + CalDAVConnectionData connInvalidSSL; + CalDAVConnectionData connTimeout; + ProcessConnectionDataFileResult dataFileResult; + + bool validDataPlain = false; + bool validDataNormal = false; + bool validDataInvalidSSL = false; + bool validDataTimeout = false; // Attempt to read the caldavtest-plain.auth file. + + dataFileResult = ProcessConnectionDataFile("caldavtest-plain.auth", &connPlain); + if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){ + validDataPlain = true; + } + + // Attempt to read the caldavtest.auth file. + + dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal); + if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){ + validDataNormal = true; + } + // Attempt to read the caldavtest-fail.auth file. + + dataFileResult = ProcessConnectionDataFile("caldavtest-fail.auth", &connInvalidSSL); + if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){ + validDataInvalidSSL = true; + } + // Attempt to read the caldavtest-timeout.auth file. - // Attempt to read the caldavtest.auth file. + + dataFileResult = ProcessConnectionDataFile("caldavtest-timeout.auth", &connTimeout); + if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){ + validDataTimeout = true; + } - if (ValidDataPlain == false){ + if (validDataPlain == false){ // Cannot read the caldavtest-plain.auth file properly. @@ -49,7 +81,7 @@ TEST(CalDAV, BasicTests){ } - if (ValidDataNormal == false){ + if (validDataNormal == false){ // Cannot read the caldavtest.auth file properly. @@ -64,7 +96,7 @@ TEST(CalDAV, BasicTests){ } - if (ValidDataFail == false){ + if (validDataInvalidSSL == false){ // Cannot read the caldavtest-fail.auth file properly. @@ -79,7 +111,7 @@ TEST(CalDAV, BasicTests){ } - if (ValidDataTimeout == false){ + if (validDataTimeout == false){ // Cannot read the caldavtest-timeout.auth file properly. @@ -94,31 +126,1143 @@ TEST(CalDAV, BasicTests){ } - ASSERT_EQ(true, ValidDataPlain); - ASSERT_EQ(true, ValidDataNormal); - ASSERT_EQ(true, ValidDataFail); - ASSERT_EQ(true, ValidDataTimeout); + ASSERT_EQ(true, validDataPlain); + ASSERT_EQ(true, validDataNormal); + ASSERT_EQ(true, validDataInvalidSSL); + ASSERT_EQ(true, validDataTimeout); // (*nix version) Setup an initial connection (just plain // text). + CalDAV calDAVPlain; + calDAVPlain.SetupConnectionData(&connPlain); + + // Verify that the settings match with the CalDAVConnectionData + // passed. + + CalDAVStatus calDAVPlainStatus = calDAVPlain.GetConnectionData(); + + ASSERT_EQ(calDAVPlainStatus.Hostname, connPlain.Hostname); + ASSERT_EQ(calDAVPlainStatus.Username, connPlain.Username); + ASSERT_EQ(calDAVPlainStatus.Port, connPlain.Port); + ASSERT_EQ(calDAVPlainStatus.Prefix, connPlain.Prefix); + ASSERT_EQ(calDAVPlainStatus.UseSSL, connPlain.UseSSL); + // Verify that the connection was successful. + CalDAVServerResult connResult = CalDAVPlain.Connect(); + + ASSERT_EQ(CALDAVQUERYRESULT_OK, connResult.Result); + ASSERT_EQ(200, connResult.HTTPCode); + ASSERT_EQ(CURLE_OK, connResult.Code); + + // Do another connection and this time the connection should + // fail due to being an invalid host name. + + CalDAVConnectionData connPlainFail; + connPlainFail.Hostname = "server.invalid"; + connPlainFail.Username = "fail"; + connPlainFail.Password = "fail"; + connPlainFail.Port = 80; + connPlainFail.UseSSL = false; + + // Setup the CalDAV connection object. + + CalDAV calDAVPlainFail; + calDAVPlainFail.SetupConnectionData(&connPlainFail); + + // Setup the CalDAVStatus object. + + CalDAVStatus calDAVPlainFailStatus = calDAVPlain.GetConnectionData(); + + // Connect and fail. + + connResult = calDAVPlainFail.Connect(); + + ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, connResult.Result); + ASSERT_EQ(0, connResult.HTTPCode); + ASSERT_EQ(CURLE_COULDNT_RESOLVE_HOST, connResult.Code); + // (*nix version) Setup an initial connection (with a valid // SSL certificate). + + CalDAV calDAVNormal; + calDAVNormal.SetupConnectionData(&connNormal); + + // Verify that the settings match with the CalDAVConnectionData + // passed. + + CalDAVStatus calDAVNormalStatus = calDAVNormal.GetConnectionData(); + ASSERT_EQ(calDAVNormalStatus.Hostname, connNormal.Hostname); + ASSERT_EQ(calDAVNormalStatus.Username, connNormal.Username); + ASSERT_EQ(calDAVNormalStatus.Port, connNormal.Port); + ASSERT_EQ(calDAVNormalStatus.Prefix, connNormal.Prefix); + ASSERT_EQ(calDAVNormalStatus.UseSSL, connNormal.UseSSL); + // Verify that the connection was successful (with a valid // SSL certificate). + connResult = CalDAVNormal.Connect(); + + ASSERT_EQ(CALDAVQUERYRESULT_OK, connResult.Result); + ASSERT_EQ(200, connResult.HTTPCode); + ASSERT_EQ(CURLE_OK, connResult.Code); + // (*nix version) Setup an initial connection on a server that // will fail due to having an invalid SSL certificate. + CalDAV calDAVInvalidSSL; + calDAVInvalidSSL.SetupConnectionData(&connInvalidSSL); + + // Verify that the settings match with the CalDAVConnectionData + // passed. + + CalDAVStatus calDAVInvalidSSLStatus = calDAVInvalidSSL.GetConnectionData(); + + ASSERT_EQ(calDAVInvalidSSLStatus.Hostname, connInvalidSSL.Hostname); + ASSERT_EQ(calDAVInvalidSSLStatus.Username, connInvalidSSL.Username); + ASSERT_EQ(calDAVInvalidSSLStatus.Port, connInvalidSSL.Port); + ASSERT_EQ(calDAVInvalidSSLStatus.Prefix, connInvalidSSL.Prefix); + ASSERT_EQ(calDAVInvalidSSLStatus.UseSSL, connInvalidSSL.UseSSL); + // Verify that the connection had failed. (with an invalid // SSL certificate). + connResult = calDAVInvalidSSL.Connect(); + + ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, connResult.Result); + ASSERT_EQ(0, connResult.HTTPCode); + ASSERT_EQ(CURLE_SSL_CACERT, connResult.Code); + // (*nix version) Setup an inital connection on a server where // a timeout occurs. + connTimeout.Timeout = 5; + + CalDAV calDAVTimeout; + calDAVTimeout.SetupConnectionData(&connTimeout); + + // Verify that the settings match with the CalDAVConnectionData + // passed. + + CalDAVStatus calDAVTimeoutStatus = calDAVTimeout.GetConnectionData(); + + ASSERT_EQ(calDAVTimeoutStatus.Hostname, connTimeout.Hostname); + ASSERT_EQ(calDAVTimeoutStatus.Username, connTimeout.Username); + ASSERT_EQ(calDAVTimeoutStatus.Port, connTimeout.Port); + ASSERT_EQ(calDAVTimeoutStatus.Prefix, connTimeout.Prefix); + ASSERT_EQ(calDAVTimeoutStatus.Timeout, connTimeout.Timeout); + ASSERT_EQ(calDAVTimeoutStatus.UseSSL, connTimeout.UseSSL); + // Verify that the connection had timed out. + connResult = calDAVTimeout.Connect(); + + ASSERT_EQ(CALDAVQUERYRESULT_SERVERERROR, connResult.Result); + ASSERT_EQ(0, connResult.HTTPCode); + ASSERT_EQ(CURLE_OPERATION_TIMEDOUT, connResult.Code); + +} + +TEST(CalDAV, BuildServerAddress){ + + CalDAVConnectionData connNormal; + ProcessConnectionDataFileResult dataFileResult; + bool validDataNormal = false; + + // Attempt to read the caldavtest.auth file. + + dataFileResult = ProcessConnectionDataFile("caldavtest.auth", &connNormal); + if (dataFileResult == PROCESSCONNECTIONDATAFILE_OK){ + validDataNormal = true; + } + + if (validDataNormal == false){ + + // Cannot read the caldavtest.auth file properly. + + cout << "The caldavtest.auth file does not exist or is invalid!" << endl; + cout << "Please create the caldavtest.auth file using the following format:" << endl << endl; + cout << "server=localname" << endl; + cout << "port=8080" << endl; + cout << "user=username" << endl; + cout << "pass=password" << endl; + cout << "ssl=false" << endl; + cout << "prefix=/lalala/lookatme/thisisa/prefix" << endl << endl; + + } + + ASSERT_EQ(true, validDataNormal); + + // Setup the server address to check. + + string serverAddress; + + // Setup the server address. + + if (connNormal.UseSSL == true){ + serverAddress += "https://"; + } else { + serverAddress += "http://"; + } + + serverAddress += connNormal.hostname; + + // Check if server port is 80, otherwise + // specifiy the port number in the address. + + if (connNormal.port != 80){ + serverAddress += ":"; + serverAddress += to_string(ConnNormal.Port); + } + + serverAddress += "/principals/"; + + ASSERT_EQ(serverAddress, BuildServerAddress(&connNormal, "/principals/")); + +} + +TEST(CalDAV, CalendarServerSupport){ + + CalDAVConnectionData connNormal; + + 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(); + + ASSERT_EQ(CALDAVQUERYRESULT_OK, connResult.result); + ASSERT_EQ(200, connResult.httpCode); + ASSERT_EQ(CURLE_OK, connResult.code); + + // Check for basic support of the calendar server. + + CalDAVServerSupport connSupport = serverConnection.GetServerSupport(); + + ASSERT_EQ(true, connSupport.basicSupport); + +} + +TEST(CalDAV, GetCalendarHome){ + + CalDAVConnectionData connNormal; + + 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(); + + ASSERT_EQ(CALDAVQUERYRESULT_OK, connResult.result); + ASSERT_EQ(200, connResult.httpCode); + ASSERT_EQ(CURLE_OK, connResult.code); + + // Check for basic support of the calendar server. + + CalDAVServerSupport connSupport = serverConnection.GetServerSupport(); + + ASSERT_EQ(true, connSupport.basicSupport); + + // Get the user principal. + + string currentUserPrincipal = serverConnection.GetUserPrincipal(); + + // Check the response from the server. + + connResult = cerverConnection.GetServerResult(); + + EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.Result); + ASSERT_EQ(207, connResult.HTTPCode); + ASSERT_EQ(CURLE_OK, connResult.Code); + + // Get the calendar home. + + string calendarHome = serverConnection.GetCalendarHome(CurrentUserPrincipal); + + // Check the response from the server. + + connResult = serverConnection.GetServerResult(); + + EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result); + ASSERT_EQ(207, connResult.httpCode); + ASSERT_EQ(CURLE_OK, connResult.code); + +} + +TEST(CalDAV, ListCalendars){ + + 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); + +} + +TEST(CalDAV, AddCalendar){ + + 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); + + // Add a calendar to the server. + + connResult = serverConnection.AddCalendar("New Calendar"); + + EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result); + ASSERT_EQ(201, connResult.httpCode); + ASSERT_EQ(CURLE_OK, connResult.code); + +} + +TEST(CalDAV, EditCalendar){ + + 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); + + // Add a calendar to the server. + + connResult = serverConnection.AddCalendar("Calendar To Edit"); + + EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result); + ASSERT_EQ(201, connResult.httpCode); + ASSERT_EQ(CURLE_OK, connResult.code); + + // 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); + + // Find the calendar containing the name "Calendar To Edit" + // created earlier. + + int itemSeek = 0; + bool itemFound = false; + + for (map::iterator calendarNameIter = calendarList.name.begin(); + calendarNameIter != calendarList.name.end(); calendarNameIter++){ + + if (calendarNameIter->second == "Calendar To Edit"){ + itemFound = true; + break; + } + + itemSeek++; + + } + + ASSERT_NE(false, itemFound); + + // Edit the name of the calendar. + + string calendarEditHREF = calendarList.href[itemSeek]; + string newCalendarName = "Edited Calendar"; + + connResult = serverConnection.EditCalendar(&calendarEditHREF, &newCalendarName); + + EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result); + ASSERT_EQ(207, connResult.httpCode); + ASSERT_EQ(CURLE_OK, connResult.code); + + // Edit the colour of the calendar. + + Colour newColour; + + newColour.red = 255; + newColour.green = 0; + newColour.blue = 0; + newColour.alpha = 0; + + connResult = serverConnection.EditCalendar(&calendarEditHREF, &newColour); + + EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result); + ASSERT_EQ(207, connResult.httpCode); + ASSERT_EQ(CURLE_OK, connResult.code); + + // Edit the description of the calendar. + + string newCalendarDescription = "Update Calendar Description"; + + connResult = serverConnection.EditCalendarDescription(&calendarEditHREF, &newCalendarDescription); + + EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result); + ASSERT_EQ(207, connResult.httpCode); + ASSERT_EQ(CURLE_OK, connResult.code); + + // Edit the order of the calendar. + + int newCalendarOrder = 30; + + connResult = serverConnection.EditCalendar(&calendarEditHREF, &newCalendarOrder); + + EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result); + ASSERT_EQ(207, connResult.httpCode); + ASSERT_EQ(CURLE_OK, connResult.code); + + // Edit all of the available properties of the calendar. + + newCalendarName = "Calendar Edited Again"; + newCalendarDescription = "Another updated calendar description"; + newColour.red = 0; + newColour.green = 255; + newColour.blue = 0; + newColour.alpha = 0; + newCalendarOrder = 40; + + connResult = serverConnection.EditCalendar(&calendarEditHREF, + &newCalendarName, + &newColour, + &newCalendarDescription, + &newCalendarOrder); + + EXPECT_EQ(CALDAVQUERYRESULT_OK, connResult.result); + ASSERT_EQ(207, connResult.httpCode); + ASSERT_EQ(CURLE_OK, connResult.code); + +} + +TEST(CalDAV, DeleteCalendar){ + + 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 == "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(); + + // 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]; + + 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); + + // 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); + + // 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); + +} + +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); + +} + +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