Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added unit tests for ConnectionObject interface and FakeConnectionObject class
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Thu, 11 Aug 2016 12:54:14 +0000 (13:54 +0100)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Thu, 11 Aug 2016 12:54:14 +0000 (13:54 +0100)
source/connobject/ConnectionObject.h
source/tests/classes/FakeConnectionObject.cpp
source/tests/classes/FakeConnectionObject.h
source/tests/xestiaab_carddav.cpp

index 90eb0cb..9ffbe4d 100644 (file)
@@ -16,6 +16,9 @@
 // You should have received a copy of the GNU General Public License along
 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
 
+#ifndef __CONNOBJECT_CONNECTIONOBJECT_H__
+#define __CONNOBJECT_CONNECTIONOBJECT_H__
+
 #include <string>
 #include <vector>
 
@@ -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
index 6e70fbf..7257640 100644 (file)
@@ -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;
 }
 
index a9eba6d..a72a993 100644 (file)
 // You should have received a copy of the GNU General Public License along
 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
  
+#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
index eb9acf5..2ef1225 100644 (file)
@@ -18,6 +18,8 @@
 
 #include <gtest/gtest.h>
 #include "classes/FakeConnectionObject.h"
+#include <chrono>
+#include <thread>
 
 // 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
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