Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added code and unit tests to FakeConnectionObject class
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Fri, 29 Jul 2016 17:42:47 +0000 (18:42 +0100)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Fri, 29 Jul 2016 17:42:47 +0000 (18:42 +0100)
source/connobject/ConnectionObject.h
source/tests/classes/FakeConnectionObject.cpp
source/tests/classes/FakeConnectionObject.h
source/tests/xestiaab_carddav.cpp

index c8d1466..798ebae 100644 (file)
@@ -26,6 +26,20 @@ enum COConnectResult {
        COCONNECT_AUTHFAIL
 };
 
+enum CORequestResult {
+       COREQUEST_UNITTESTFAIL = -1,
+       COREQUEST_OK,
+       COREQUEST_ERROR_NOTCONNECTED,
+       COREQUEST_ERROR_SERVER
+};
+
+struct COServerResponse {
+       CORequestResult RequestResult;
+       std::string EntityTag;
+       int ResultCode;
+       std::string ResultMessage;
+};
+
 class ConnectionObject{
        
        public:
@@ -39,14 +53,23 @@ class ConnectionObject{
                
                virtual COConnectResult Connect() {};
                
+               virtual std::string GetDefaultPrefix() {};
+               //virtual void SetupData(std::string Method, std::string Location, std::string Data) {};
+               virtual COServerResponse AddContact(std::string Location, std::string Data) {};
+               
                virtual bool CanDoProcessing() {};
                virtual bool CanDoSSL() {};
                virtual bool SSLVerify() {};
                virtual bool AbleToLogin() {};
                virtual bool HasValidResponse() {};
-               virtual bool IsSelfSigned() {};
                
        protected:
+               // Test Mode.
+       
+               bool TestMode = false;
+       
+               // Server variables.
+       
                std::string ServerAddress = "";
                unsigned int ServerPort = 8080;
                std::string ServerUser = "";
@@ -56,7 +79,16 @@ class ConnectionObject{
                bool ServerSSL = true;
                std::string ErrorMessage = "";
                std::string ErrorBufferMessage = "";
-               bool TestMode = false;
+       
+               // Connect results.
+       
+               bool SSLStatus = false;
+               bool SSLVerified = false;
+               bool ValidResponse = false;
+               bool AuthPassed = false;
+               bool CanProcess = false;
+               bool SSLSelfSigned = false;
+               
        private:
 
 };
\ No newline at end of file
index fa8f39d..147b01c 100644 (file)
 #include "FakeConnectionObject.h"
 
 COConnectResult FakeConnectionObject::Connect(){
+       
        COConnectResult ConnectResult = ResultStatus;
+       AuthPassed = ResultAuthPassed;
+       CanProcess = ResultCanProcess;
+       SSLStatus = ResultSSLStatus;
+       SSLVerified = ResultSSLVerified;
+       ValidResponse = ResultValidResponse;
+       SSLSelfSigned = ResultSelfSigned;
+       ServerPrefix = ResultServerPrefix;
        return ConnectResult;
 }
 
+std::string FakeConnectionObject::GetDefaultPrefix(){
+       return ServerPrefix;
+}
+
+COServerResponse FakeConnectionObject::AddContact(std::string Location, std::string Data){
+       
+       COServerResponse AddContactResult;
+       
+       AddContactResult.RequestResult = TestRequestResult;
+       AddContactResult.EntityTag = TestEntityTag;
+       AddContactResult.ResultCode = TestResultCode;
+       AddContactResult.ResultMessage = TestResultMessage;
+       
+       return AddContactResult;
+       
+}
+
 std::string FakeConnectionObject::GetServerAddress(){
        return ServerAddress;
 }
@@ -56,25 +81,25 @@ bool FakeConnectionObject::GetTestMode(){
 }
 
 bool FakeConnectionObject::CanDoProcessing(){
-       return false;
+       return CanProcess;
 }
 
 bool FakeConnectionObject::CanDoSSL(){
-       return false;   
+       return SSLStatus;       
 }
 
 bool FakeConnectionObject::SSLVerify(){
-       return false;
+       return SSLVerified;
 }
 
 bool FakeConnectionObject::AbleToLogin(){
-       return false;
+       return AuthPassed;
 }
 
 bool FakeConnectionObject::HasValidResponse(){
-       return false;
+       return ValidResponse;
 }
 
 bool FakeConnectionObject::IsSelfSigned(){
-       return false;
+       return SSLSelfSigned;
 }
\ No newline at end of file
index c26bfd4..96f03d0 100644 (file)
@@ -37,6 +37,11 @@ class FakeConnectionObject : public ConnectionObject {
                // Functions from the ConnectionObject interface.
        
                COConnectResult Connect();
+               std::string GetDefaultPrefix();
+               COServerResponse AddContact(std::string Location, std::string Data);
+
+               void SetupData(std::string Method, std::string Location, std::string Data);
+       
                bool CanDoProcessing();
                bool CanDoSSL();
                bool SSLVerify();
@@ -46,8 +51,19 @@ class FakeConnectionObject : public ConnectionObject {
        
                // Variables to set for fake connection object.
        
-               std::string ServerPrefixInput = "";
-               COConnectResult ResultStatus;
+               std::string ResultServerPrefix = "";
+               COConnectResult ResultStatus = COCONNECT_UNITTESTFAIL;
+               bool ResultAuthPassed = false;
+               bool ResultCanProcess = false;
+               bool ResultSSLStatus = false;
+               bool ResultSSLVerified = false;
+               bool ResultValidResponse = false;
+               bool ResultSelfSigned = false;
+               bool NoConnection = false;
+               CORequestResult TestRequestResult;
+               std::string TestEntityTag;
+               int TestResultCode;
+               std::string TestResultMessage;
        
        protected:
        private:
index e3ae7ae..e71f4d5 100644 (file)
@@ -120,8 +120,6 @@ 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;
@@ -135,8 +133,6 @@ 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;
@@ -150,8 +146,6 @@ 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;
@@ -165,12 +159,224 @@ 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());
        
+}
+
+TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Is_Able_To_Login){
+       
+       std::string ServerAddress1 = "gibberish.invalid";
+       std::string ServerUser1 = "user";
+       std::string ServerPass1 = "pass";
+       
+       FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
+       FakeConnection.ResultAuthPassed = true;
+       FakeConnection.Connect();
+       
+       EXPECT_EQ(true, FakeConnection.AbleToLogin());
+       
+}
+
+TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Is_Unable_To_Login){
+       
+       std::string ServerAddress1 = "gibberish.invalid";
+       std::string ServerUser1 = "user";
+       std::string ServerPass1 = "pass";
+       
+       FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
+       FakeConnection.ResultAuthPassed = false;
+       FakeConnection.Connect();
+       
+       EXPECT_EQ(false, FakeConnection.AbleToLogin());
+       
+}
+
+TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Can_Do_Processing){
+       
+       std::string ServerAddress1 = "gibberish.invalid";
+       std::string ServerUser1 = "user";
+       std::string ServerPass1 = "pass";
+       
+       FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
+       FakeConnection.ResultCanProcess = true;
+       FakeConnection.Connect();
+       
+       EXPECT_EQ(true, FakeConnection.CanDoProcessing());
+       
+}
+
+TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Supports_SSL){
+       
+       std::string ServerAddress1 = "gibberish.invalid";
+       std::string ServerUser1 = "user";
+       std::string ServerPass1 = "pass";
+       
+       FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
+       FakeConnection.ResultSSLStatus  = true;
+       FakeConnection.Connect();
+       
+       EXPECT_EQ(true, FakeConnection.CanDoSSL());
+       
+}
+
+TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Does_Not_Support_SSL){
+       
+       std::string ServerAddress1 = "gibberish.invalid";
+       std::string ServerUser1 = "user";
+       std::string ServerPass1 = "pass";
+       
+       FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
+       FakeConnection.ResultSSLStatus  = false;
+       FakeConnection.Connect();
+       
+       EXPECT_EQ(false, FakeConnection.CanDoSSL());
+       
+}
+
+TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_Valid_SSL_Certificate_Data){
+       
+       std::string ServerAddress1 = "gibberish.invalid";
+       std::string ServerUser1 = "user";
+       std::string ServerPass1 = "pass";
+       
+       FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
+       FakeConnection.ResultSSLVerified = true;
+       FakeConnection.Connect();
+       
+       EXPECT_EQ(true, FakeConnection.SSLVerify());
+       
+}
+
+TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_Invalid_SSL_Certificate_Data){
+       
+       std::string ServerAddress1 = "gibberish.invalid";
+       std::string ServerUser1 = "user";
+       std::string ServerPass1 = "pass";
+       
+       FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
+       FakeConnection.ResultSSLVerified = false;
+       FakeConnection.Connect();
+       
+       EXPECT_EQ(false, FakeConnection.SSLVerify());
+       
+}
+
+TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_A_Valid_Response){
+       
+       std::string ServerAddress1 = "gibberish.invalid";
+       std::string ServerUser1 = "user";
+       std::string ServerPass1 = "pass";
+       
+       FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
+       FakeConnection.ResultValidResponse = true;
+       FakeConnection.Connect();
+       
+       EXPECT_EQ(true, FakeConnection.HasValidResponse());
+       
+}
+
+TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Has_A_Invalid_Response){
+       
+       std::string ServerAddress1 = "gibberish.invalid";
+       std::string ServerUser1 = "user";
+       std::string ServerPass1 = "pass";
+       
+       FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
+       FakeConnection.ResultValidResponse = false;
+       FakeConnection.Connect();
+       
+       EXPECT_EQ(false, FakeConnection.HasValidResponse());
+       
+}
+
+TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Uses_A_Self_Signed_SSL_Certificate){
+       
+       std::string ServerAddress1 = "gibberish.invalid";
+       std::string ServerUser1 = "user";
+       std::string ServerPass1 = "pass";
+       
+       FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
+       FakeConnection.ResultSelfSigned = true;
+       FakeConnection.Connect();
+       
+       EXPECT_EQ(true, FakeConnection.IsSelfSigned());
+       
+}
+
+TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Doesnt_Use_A_Self_Signed_SSL_Certificate){
+       
+       std::string ServerAddress1 = "gibberish.invalid";
+       std::string ServerUser1 = "user";
+       std::string ServerPass1 = "pass";
+       
+       FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
+       FakeConnection.ResultSelfSigned = false;
+       FakeConnection.Connect();
+       
+       EXPECT_EQ(false, FakeConnection.IsSelfSigned());
+       
+}
+
+TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_The_Server_Prefix_Of_Prefix_Test_A){
+       
+       std::string ServerAddress1 = "gibberish.invalid";
+       std::string ServerUser1 = "user";
+       std::string ServerPass1 = "pass";
+       
+       FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
+       FakeConnection.ResultServerPrefix = "/prefix/test/a";
+       FakeConnection.Connect();
+       
+       EXPECT_EQ("/prefix/test/a", FakeConnection.GetDefaultPrefix());
+       
+}
+
+TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_The_Server_Prefix_Of_Prefix_Test_B){
+       
+       std::string ServerAddress1 = "gibberish.invalid";
+       std::string ServerUser1 = "user";
+       std::string ServerPass1 = "pass";
+       
+       FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
+       FakeConnection.ResultServerPrefix = "/prefix/test/b";
+       FakeConnection.Connect();
+       
+       EXPECT_EQ("/prefix/test/b", FakeConnection.GetDefaultPrefix());
+       
+}
+
+TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Adds_A_Contact_Successfully){
+       
+       std::string ServerAddress1 = "gibberish.invalid";
+       std::string ServerUser1 = "user";
+       std::string ServerPass1 = "pass";
+       
+       FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
+       FakeConnection.ResultServerPrefix = "/prefix/test/b";
+       FakeConnection.Connect();
+       
+       std::string ContactFile =
+       "BEGIN:VCARD\n"
+       "VERSION:4.0\n"
+       "UID:84q2ioj13jofiujqwr\n"
+       "N:;;Meep;Moop;;\n"
+       "FN:The Meep Moop\n"
+       "END:VCARD";
+       
+       FakeConnection.TestRequestResult = COREQUEST_OK;
+       FakeConnection.TestEntityTag = "4324svafhuiaffsdhui";
+       FakeConnection.TestResultCode = 200;
+       FakeConnection.TestResultMessage = "";
+       
+       COServerResponse AddContactResult = FakeConnection.AddContact("testfile.vcf", ContactFile);
+       
+       EXPECT_EQ(COREQUEST_OK, AddContactResult.RequestResult);
+       EXPECT_EQ("4324svafhuiaffsdhui", AddContactResult.EntityTag);
+       EXPECT_EQ(200, AddContactResult.ResultCode);
+       EXPECT_EQ("", AddContactResult.ResultMessage);
+       
 }
\ No newline at end of file
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy