// Attempt to read the caldavtest-timeout.auth file.
- DataFileResult = ProcessConnectionDataFile("caldavtest-fail.auth", &ConnTimeout);
+ DataFileResult = ProcessConnectionDataFile("caldavtest-timeout.auth", &ConnTimeout);
if (DataFileResult == PROCESSCONNECTIONDATAFILE_OK){
ValidDataTimeout = true;
}
// (*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 = ServerConnection.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);
+
}
\ No newline at end of file