From 4990d9a3913f961e2978c06ba97a8ea79622aa7a Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Fri, 29 Jul 2016 12:32:15 +0100 Subject: [PATCH] Added code and more unit tests for FakeConnectionObject Testing of the Connect function. --- source/connobject/ConnectionObject.h | 17 ++ source/tests/classes/FakeConnectionObject.cpp | 29 ++++ source/tests/classes/FakeConnectionObject.h | 11 ++ source/tests/xestiaab_carddav.cpp | 158 +++++++++++++++++- source/tests/xestiaab_test.cpp | 1 - 5 files changed, 213 insertions(+), 3 deletions(-) diff --git a/source/connobject/ConnectionObject.h b/source/connobject/ConnectionObject.h index c668814..c8d1466 100644 --- a/source/connobject/ConnectionObject.h +++ b/source/connobject/ConnectionObject.h @@ -18,6 +18,14 @@ #include +enum COConnectResult { + COCONNECT_UNITTESTFAIL = -1, + COCONNECT_OK, + COCONNECT_INVALID, + COCONNECT_TIMEOUT, + COCONNECT_AUTHFAIL +}; + class ConnectionObject{ public: @@ -29,6 +37,15 @@ class ConnectionObject{ virtual void SetupConnectionObject() {}; virtual ~ConnectionObject() {}; + virtual COConnectResult Connect() {}; + + virtual bool CanDoProcessing() {}; + virtual bool CanDoSSL() {}; + virtual bool SSLVerify() {}; + virtual bool AbleToLogin() {}; + virtual bool HasValidResponse() {}; + virtual bool IsSelfSigned() {}; + protected: std::string ServerAddress = ""; unsigned int ServerPort = 8080; diff --git a/source/tests/classes/FakeConnectionObject.cpp b/source/tests/classes/FakeConnectionObject.cpp index 02a20dc..fa8f39d 100644 --- a/source/tests/classes/FakeConnectionObject.cpp +++ b/source/tests/classes/FakeConnectionObject.cpp @@ -18,6 +18,11 @@ #include "FakeConnectionObject.h" +COConnectResult FakeConnectionObject::Connect(){ + COConnectResult ConnectResult = ResultStatus; + return ConnectResult; +} + std::string FakeConnectionObject::GetServerAddress(){ return ServerAddress; } @@ -48,4 +53,28 @@ bool FakeConnectionObject::GetServerSSL(){ bool FakeConnectionObject::GetTestMode(){ return TestMode; +} + +bool FakeConnectionObject::CanDoProcessing(){ + return false; +} + +bool FakeConnectionObject::CanDoSSL(){ + return false; +} + +bool FakeConnectionObject::SSLVerify(){ + return false; +} + +bool FakeConnectionObject::AbleToLogin(){ + return false; +} + +bool FakeConnectionObject::HasValidResponse(){ + return false; +} + +bool FakeConnectionObject::IsSelfSigned(){ + return false; } \ No newline at end of file diff --git a/source/tests/classes/FakeConnectionObject.h b/source/tests/classes/FakeConnectionObject.h index 02924f9..c26bfd4 100644 --- a/source/tests/classes/FakeConnectionObject.h +++ b/source/tests/classes/FakeConnectionObject.h @@ -34,9 +34,20 @@ class FakeConnectionObject : public ConnectionObject { bool GetServerSSL(); bool GetTestMode(); + // Functions from the ConnectionObject interface. + + COConnectResult Connect(); + bool CanDoProcessing(); + bool CanDoSSL(); + bool SSLVerify(); + bool AbleToLogin(); + bool HasValidResponse(); + bool IsSelfSigned(); + // Variables to set for fake connection object. std::string ServerPrefixInput = ""; + COConnectResult ResultStatus; protected: private: diff --git a/source/tests/xestiaab_carddav.cpp b/source/tests/xestiaab_carddav.cpp index 9e69d23..e3ae7ae 100644 --- a/source/tests/xestiaab_carddav.cpp +++ b/source/tests/xestiaab_carddav.cpp @@ -17,6 +17,160 @@ // with Xestia Address Book. If not, see #include -//#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 diff --git a/source/tests/xestiaab_test.cpp b/source/tests/xestiaab_test.cpp index 5f654f4..7dc8491 100644 --- a/source/tests/xestiaab_test.cpp +++ b/source/tests/xestiaab_test.cpp @@ -19,7 +19,6 @@ #include #include #include -#include "xestiaab_carddav.h" #include "xestiaab_contactload.h" #include "xestiaab_contactsave.h" #include "xestiaab_convert.h" -- 2.39.5