From: Steve Brokenshire Date: Wed, 2 Mar 2016 11:26:34 +0000 (+0000) Subject: Added code to build server address from subroutine and also unit tests. X-Git-Tag: release-0.02~317 X-Git-Url: http://Server1/repobrowser/?a=commitdiff_plain;h=dae9e1905adedbc2462ba3f869453d10642722b9;p=xestiacalendar%2F.git Added code to build server address from subroutine and also unit tests. --- 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;