Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added code and more unit tests for FakeConnectionObject
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Fri, 29 Jul 2016 11:32:15 +0000 (12:32 +0100)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Fri, 29 Jul 2016 11:32:15 +0000 (12:32 +0100)
Testing of the Connect function.

source/connobject/ConnectionObject.h
source/tests/classes/FakeConnectionObject.cpp
source/tests/classes/FakeConnectionObject.h
source/tests/xestiaab_carddav.cpp
source/tests/xestiaab_test.cpp

index c668814..c8d1466 100644 (file)
 
 #include <string>
 
+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;
index 02a20dc..fa8f39d 100644 (file)
 
 #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
index 02924f9..c26bfd4 100644 (file)
@@ -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:
index 9e69d23..e3ae7ae 100644 (file)
 // 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
index 5f654f4..7dc8491 100644 (file)
@@ -19,7 +19,6 @@
 #include <gtest/gtest.h>
 #include <iostream>
 #include <string>
-#include "xestiaab_carddav.h"
 #include "xestiaab_contactload.h"
 #include "xestiaab_contactsave.h"
 #include "xestiaab_convert.h"
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