From: Steve Brokenshire Date: Thu, 11 Aug 2016 12:54:14 +0000 (+0100) Subject: Added unit tests for ConnectionObject interface and FakeConnectionObject class X-Git-Tag: release-0.15~29 X-Git-Url: http://Server1/repobrowser/?p=xestiaab%2F.git;a=commitdiff_plain;h=674d18f3054c0530a53c9586f9c2effa4dc5dfcb Added unit tests for ConnectionObject interface and FakeConnectionObject class --- diff --git a/source/connobject/ConnectionObject.h b/source/connobject/ConnectionObject.h index 90eb0cb..9ffbe4d 100644 --- a/source/connobject/ConnectionObject.h +++ b/source/connobject/ConnectionObject.h @@ -16,6 +16,9 @@ // You should have received a copy of the GNU General Public License along // with Xestia Address Book. If not, see +#ifndef __CONNOBJECT_CONNECTIONOBJECT_H__ +#define __CONNOBJECT_CONNECTIONOBJECT_H__ + #include #include @@ -34,6 +37,15 @@ enum CORequestResult { COREQUEST_ERROR_SERVER }; +enum COSSLVerified { + COSSL_UNITTESTFAIL = -1, + COSSL_VERIFIED, + COSSL_VERIFIED_USER, + COSSL_UNABLETOVERIFY, + COSSL_NOTAPPLICABLE, + COSSL_NORESULT +}; + struct COServerResponse { CORequestResult RequestResult; std::string EntityTag; @@ -62,7 +74,9 @@ class ConnectionObject{ // Virtual functions to be setup by the inheriting classes. virtual void SetupConnectionObject() {}; - virtual ~ConnectionObject() {}; + //virtual ~ConnectionObject() {}; + + virtual bool IsTaskCompleted() {}; virtual COConnectResult Connect() {}; @@ -76,7 +90,7 @@ class ConnectionObject{ virtual bool CanDoProcessing() {}; virtual bool CanDoSSL() {}; - virtual bool SSLVerify() {}; + virtual COSSLVerified SSLVerify() {}; virtual bool AbleToLogin() {}; virtual bool HasValidResponse() {}; @@ -100,12 +114,15 @@ class ConnectionObject{ // Connect results. bool SSLStatus = false; - bool SSLVerified = false; + COSSLVerified SSLVerified = COSSL_NORESULT; bool ValidResponse = false; bool AuthPassed = false; bool CanProcess = false; bool SSLSelfSigned = false; + bool TaskCompleted = false; private: -}; \ No newline at end of file +}; + +#endif \ No newline at end of file diff --git a/source/tests/classes/FakeConnectionObject.cpp b/source/tests/classes/FakeConnectionObject.cpp index 6e70fbf..7257640 100644 --- a/source/tests/classes/FakeConnectionObject.cpp +++ b/source/tests/classes/FakeConnectionObject.cpp @@ -31,6 +31,11 @@ COConnectResult FakeConnectionObject::Connect(){ return ConnectResult; } +bool FakeConnectionObject::IsTaskCompleted(){ + TaskCompleted = ResultTaskCompleted; + return TaskCompleted; +} + std::string FakeConnectionObject::GetDefaultPrefix(){ return ServerPrefix; } @@ -159,7 +164,7 @@ bool FakeConnectionObject::CanDoSSL(){ return SSLStatus; } -bool FakeConnectionObject::SSLVerify(){ +COSSLVerified FakeConnectionObject::SSLVerify(){ return SSLVerified; } diff --git a/source/tests/classes/FakeConnectionObject.h b/source/tests/classes/FakeConnectionObject.h index a9eba6d..a72a993 100644 --- a/source/tests/classes/FakeConnectionObject.h +++ b/source/tests/classes/FakeConnectionObject.h @@ -16,15 +16,19 @@ // You should have received a copy of the GNU General Public License along // with Xestia Address Book. If not, see +#ifndef __CONNOBJECT_FAKECONNECTIONOBJECT_H__ +#define __CONNOBJECT_FAKECONNECTIONOBJECT_H__ + #include "../../connobject/ConnectionObject.h" class FakeConnectionObject : public ConnectionObject { public: - - // Functions for fake connection object. using ConnectionObject::ConnectionObject; + + // Functions for fake connection object. + std::string GetServerAddress(); unsigned int GetServerPort(); std::string GetServerUser(); @@ -44,12 +48,13 @@ class FakeConnectionObject : public ConnectionObject { COServerResponse GetServerEntityTagValue(std::string Location); COServerResponse GetContact(std::string Location); COContactList GetContactList(std::string SyncToken); - + + bool IsTaskCompleted(); void SetupData(std::string Method, std::string Location, std::string Data); bool CanDoProcessing(); bool CanDoSSL(); - bool SSLVerify(); + COSSLVerified SSLVerify(); bool AbleToLogin(); bool HasValidResponse(); bool IsSelfSigned(); @@ -61,9 +66,10 @@ class FakeConnectionObject : public ConnectionObject { bool ResultAuthPassed = false; bool ResultCanProcess = false; bool ResultSSLStatus = false; - bool ResultSSLVerified = false; + COSSLVerified ResultSSLVerified = COSSL_NORESULT; bool ResultValidResponse = false; bool ResultSelfSigned = false; + bool ResultTaskCompleted = false; CORequestResult TestRequestResult; COContactList TestContactList; std::string TestEntityTag; @@ -74,4 +80,6 @@ class FakeConnectionObject : public ConnectionObject { protected: private: -}; \ No newline at end of file +}; + +#endif \ No newline at end of file diff --git a/source/tests/xestiaab_carddav.cpp b/source/tests/xestiaab_carddav.cpp index eb9acf5..2ef1225 100644 --- a/source/tests/xestiaab_carddav.cpp +++ b/source/tests/xestiaab_carddav.cpp @@ -18,6 +18,8 @@ #include #include "classes/FakeConnectionObject.h" +#include +#include // TODO: Add tests for the CardDAV object. @@ -244,10 +246,10 @@ TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_Valid_SSL_Certificate_D std::string ServerPass1 = "pass"; FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true); - FakeConnection.ResultSSLVerified = true; + FakeConnection.ResultSSLVerified = COSSL_VERIFIED; FakeConnection.Connect(); - EXPECT_EQ(true, FakeConnection.SSLVerify()); + EXPECT_EQ(COSSL_VERIFIED, FakeConnection.SSLVerify()); } @@ -258,10 +260,38 @@ TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_Invalid_SSL_Certificate std::string ServerPass1 = "pass"; FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true); - FakeConnection.ResultSSLVerified = false; + FakeConnection.ResultSSLVerified = COSSL_UNABLETOVERIFY; FakeConnection.Connect(); - EXPECT_EQ(false, FakeConnection.SSLVerify()); + EXPECT_EQ(COSSL_UNABLETOVERIFY, FakeConnection.SSLVerify()); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_User_Verified_SSL_Cerficiate_Data){ + + std::string ServerAddress1 = "gibberish.invalid"; + std::string ServerUser1 = "user"; + std::string ServerPass1 = "pass"; + + FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true); + FakeConnection.ResultSSLVerified = COSSL_VERIFIED_USER; + FakeConnection.Connect(); + + EXPECT_EQ(COSSL_VERIFIED_USER, FakeConnection.SSLVerify()); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Doesnt_Use_SSL_Return_Not_Applicable_SSL_Result){ + + std::string ServerAddress1 = "gibberish.invalid"; + std::string ServerUser1 = "user"; + std::string ServerPass1 = "pass"; + + FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, false); + FakeConnection.ResultSSLVerified = COSSL_NOTAPPLICABLE; + FakeConnection.Connect(); + + EXPECT_EQ(COSSL_NOTAPPLICABLE, FakeConnection.SSLVerify()); } @@ -1193,4 +1223,26 @@ TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_A_Contact_List EXPECT_EQ(0, ServerDataResult.ListData.size()); +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Wait_For_A_Completed_Task){ + + std::string ServerAddress1 = "gibberish.invalid"; + std::string ServerUser1 = "user"; + std::string ServerPass1 = "pass"; + + FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1"); + FakeConnection.ResultServerPrefix = "/prefix/test/b"; + FakeConnection.Connect(); + FakeConnection.ResultTaskCompleted = false; + + while (!FakeConnection.IsTaskCompleted()){ + + std::this_thread::sleep_for(std::chrono::milliseconds(250)); + FakeConnection.ResultTaskCompleted = true; + + } + + EXPECT_TRUE(FakeConnection.ResultTaskCompleted); + } \ No newline at end of file