From dae9e1905adedbc2462ba3f869453d10642722b9 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Wed, 2 Mar 2016 11:26:34 +0000 Subject: [PATCH] Added code to build server address from subroutine and also unit tests. --- source/objects/CalDAV/CalDAV.cpp | 46 ++++++++++++++-------- source/objects/CalDAV/CalDAV.h | 1 + source/tests/xestiacalendar_caldav.h | 58 ++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 17 deletions(-) diff --git a/source/objects/CalDAV/CalDAV.cpp b/source/objects/CalDAV/CalDAV.cpp index 27bc692..21e8ddc 100644 --- a/source/objects/CalDAV/CalDAV.cpp +++ b/source/objects/CalDAV/CalDAV.cpp @@ -92,23 +92,7 @@ CalDAVServerResult CalDAV::Connect(){ // Setup the server address. - if (ConnectionData.UseSSL == true){ - ServerAddress += "https://"; - } else { - ServerAddress += "http://"; - } - - ServerAddress += ConnectionData.Hostname; - - // Check if server port is 80, otherwise - // specifiy the port number in the address. - - if (ConnectionData.Port != 80){ - ServerAddress += ":"; - ServerAddress += to_string(ConnectionData.Port); - } - - ServerAddress += "/principals/"; + ServerAddress = BuildServerAddress(&ConnectionData, "/principals/"); // Setup the server password. @@ -208,4 +192,32 @@ bool CalDAVObjectValidSettings(CalDAVConnectionData *ConnData){ return true; +} + +string BuildServerAddress(CalDAVConnectionData *ConnData, string URIAddress){ + + string ServerAddress; + + // Setup the server address. + + if (ConnData->UseSSL == true){ + ServerAddress += "https://"; + } else { + ServerAddress += "http://"; + } + + ServerAddress += ConnData->Hostname; + + // Check if server port is 80, otherwise + // specifiy the port number in the address. + + if (ConnData->Port != 80){ + ServerAddress += ":"; + ServerAddress += to_string(ConnData->Port); + } + + ServerAddress += URIAddress; + + return ServerAddress; + } \ No newline at end of file diff --git a/source/objects/CalDAV/CalDAV.h b/source/objects/CalDAV/CalDAV.h index 9fe29b8..47b9617 100644 --- a/source/objects/CalDAV/CalDAV.h +++ b/source/objects/CalDAV/CalDAV.h @@ -97,5 +97,6 @@ class CalDAV{ // CalDAVConnectionData struct. bool CalDAVObjectValidSettings(CalDAVConnectionData *ConnData); +string BuildServerAddress(CalDAVConnectionData *ConnData, string URIAddress); #endif diff --git a/source/tests/xestiacalendar_caldav.h b/source/tests/xestiacalendar_caldav.h index 3dff68b..1557685 100644 --- a/source/tests/xestiacalendar_caldav.h +++ b/source/tests/xestiacalendar_caldav.h @@ -263,6 +263,64 @@ TEST(CalDAV, BasicTests){ } +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, ListCalendars){ CalDAVConnectionData ConnNormal; -- 2.39.5