// with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
#include <gtest/gtest.h>
-//#include "../carddav/carddav.h"
+#include "classes/FakeConnectionObject.h"
-// TODO: Add tests for the CardDAV object.
\ No newline at end of file
+// TODO: Add tests for the CardDAV object.
+
+TEST(CardDAV, Use_Fake_To_Setup_And_Check_Connection_Settings_With_TestMode_True){
+
+ std::string ServerAddress1 = "gibberish.invalid";
+ std::string ServerUser1 = "user";
+ std::string ServerPass1 = "pass";
+
+ std::string ServerAddress2 = "gibberish2.invalid";
+ std::string ServerUser2 = "user2";
+ std::string ServerPass2 = "pass2";
+
+ std::string ServerAddress3 = "gibberish3.invalid";
+ std::string ServerUser3 = "user3";
+ std::string ServerPass3 = "pass3";
+
+ FakeConnectionObject FakeConnection1(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
+ FakeConnectionObject FakeConnection2(ServerAddress2, 8800, ServerUser2, ServerPass2, true);
+ FakeConnectionObject FakeConnection3(ServerAddress3, 8008, ServerUser3, ServerPass3, false);
+
+ EXPECT_EQ("gibberish.invalid", FakeConnection1.GetServerAddress());
+ EXPECT_EQ(8080, FakeConnection1.GetServerPort());
+ EXPECT_EQ("user", FakeConnection1.GetServerUser());
+ EXPECT_EQ("pass", FakeConnection1.GetServerPass());
+ EXPECT_EQ(true, FakeConnection1.GetServerSSL());
+ EXPECT_EQ(true, FakeConnection1.GetTestMode());
+
+ EXPECT_EQ("gibberish2.invalid", FakeConnection2.GetServerAddress());
+ EXPECT_EQ(8800, FakeConnection2.GetServerPort());
+ EXPECT_EQ("user2", FakeConnection2.GetServerUser());
+ EXPECT_EQ("pass2", FakeConnection2.GetServerPass());
+ EXPECT_EQ(true, FakeConnection2.GetServerSSL());
+ EXPECT_EQ(true, FakeConnection2.GetTestMode());
+
+ EXPECT_EQ("gibberish3.invalid", FakeConnection3.GetServerAddress());
+ EXPECT_EQ(8008, FakeConnection3.GetServerPort());
+ EXPECT_EQ("user3", FakeConnection3.GetServerUser());
+ EXPECT_EQ("pass3", FakeConnection3.GetServerPass());
+ EXPECT_EQ(false, FakeConnection3.GetServerSSL());
+ EXPECT_EQ(true, FakeConnection3.GetTestMode());
+
+}
+
+TEST(CardDAV, Use_Fake_To_Setup_And_Check_Connection_Settings_With_TestMode_False){
+
+ std::string ServerAddress1 = "gibberish.invalid";
+ std::string ServerUser1 = "user";
+ std::string ServerPass1 = "pass";
+ std::string ServerPrefix1 = "/prefix";
+ std::string ServerAccount1 = "Account1";
+
+ std::string ServerAddress2 = "gibberish2.invalid";
+ std::string ServerUser2 = "user2";
+ std::string ServerPass2 = "pass2";
+ std::string ServerPrefix2 = "/prefix2";
+ std::string ServerAccount2 = "Account2";
+
+ std::string ServerAddress3 = "gibberish3.invalid";
+ std::string ServerUser3 = "user3";
+ std::string ServerPass3 = "pass3";
+ std::string ServerPrefix3 = "/prefix3";
+ std::string ServerAccount3 = "Account3";
+
+ FakeConnectionObject FakeConnection1(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1");
+ FakeConnectionObject FakeConnection2(ServerAddress2, 8800, ServerUser2, ServerPass2, true, "/prefix2", "Account2");
+ FakeConnectionObject FakeConnection3(ServerAddress3, 8008, ServerUser3, ServerPass3, false, "/prefix3", "Account3");
+
+ EXPECT_EQ("gibberish.invalid", FakeConnection1.GetServerAddress());
+ EXPECT_EQ(8080, FakeConnection1.GetServerPort());
+ EXPECT_EQ("user", FakeConnection1.GetServerUser());
+ EXPECT_EQ("pass", FakeConnection1.GetServerPass());
+ EXPECT_EQ(true, FakeConnection1.GetServerSSL());
+ EXPECT_EQ(false, FakeConnection1.GetTestMode());
+ EXPECT_EQ("/prefix", FakeConnection1.GetServerPrefix());
+ EXPECT_EQ("Account1", FakeConnection1.GetServerAccount());
+
+ EXPECT_EQ("gibberish2.invalid", FakeConnection2.GetServerAddress());
+ EXPECT_EQ(8800, FakeConnection2.GetServerPort());
+ EXPECT_EQ("user2", FakeConnection2.GetServerUser());
+ EXPECT_EQ("pass2", FakeConnection2.GetServerPass());
+ EXPECT_EQ(true, FakeConnection2.GetServerSSL());
+ EXPECT_EQ(false, FakeConnection2.GetTestMode());
+ EXPECT_EQ("/prefix2", FakeConnection2.GetServerPrefix());
+ EXPECT_EQ("Account2", FakeConnection2.GetServerAccount());
+
+ EXPECT_EQ("gibberish3.invalid", FakeConnection3.GetServerAddress());
+ EXPECT_EQ(8008, FakeConnection3.GetServerPort());
+ EXPECT_EQ("user3", FakeConnection3.GetServerUser());
+ EXPECT_EQ("pass3", FakeConnection3.GetServerPass());
+ EXPECT_EQ(false, FakeConnection3.GetServerSSL());
+ EXPECT_EQ(false, FakeConnection3.GetTestMode());
+ EXPECT_EQ("/prefix3", FakeConnection3.GetServerPrefix());
+ EXPECT_EQ("Account3", FakeConnection3.GetServerAccount());
+
+}
+
+TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_Returning_Success){
+
+ std::string ServerAddress1 = "gibberish.invalid";
+ std::string ServerUser1 = "user";
+ std::string ServerPass1 = "pass";
+ std::string ServerPrefix1 = "/prefix";
+ std::string ServerAccount1 = "Account1";
+
+ FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
+ FakeConnection.ResultStatus = COCONNECT_OK;
+
+ EXPECT_EQ(COCONNECT_OK, FakeConnection.Connect());
+
+}
+
+TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_Returning_InvalidAddress){
+
+ std::string ServerAddress1 = "gibberish.invalid";
+ std::string ServerUser1 = "user";
+ std::string ServerPass1 = "pass";
+ std::string ServerPrefix1 = "/prefix";
+ std::string ServerAccount1 = "Account1";
+
+ FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
+ FakeConnection.ResultStatus = COCONNECT_INVALID;
+
+ EXPECT_EQ(COCONNECT_INVALID, FakeConnection.Connect());
+
+}
+
+TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_Returning_Timeout){
+
+ std::string ServerAddress1 = "gibberish.invalid";
+ std::string ServerUser1 = "user";
+ std::string ServerPass1 = "pass";
+ std::string ServerPrefix1 = "/prefix";
+ std::string ServerAccount1 = "Account1";
+
+ FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
+ FakeConnection.ResultStatus = COCONNECT_TIMEOUT;
+
+ EXPECT_EQ(COCONNECT_TIMEOUT, FakeConnection.Connect());
+
+}
+
+TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_Returning_Authentication_Failure){
+
+ std::string ServerAddress1 = "gibberish.invalid";
+ std::string ServerUser1 = "user";
+ std::string ServerPass1 = "pass";
+ std::string ServerPrefix1 = "/prefix";
+ std::string ServerAccount1 = "Account1";
+
+ FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
+ FakeConnection.ResultStatus = COCONNECT_AUTHFAIL;
+
+ EXPECT_EQ(COCONNECT_AUTHFAIL, FakeConnection.Connect());
+
+}
\ No newline at end of file