// 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>
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;
// Virtual functions to be setup by the inheriting classes.
virtual void SetupConnectionObject() {};
- virtual ~ConnectionObject() {};
+ //virtual ~ConnectionObject() {};
+
+ virtual bool IsTaskCompleted() {};
virtual COConnectResult Connect() {};
virtual bool CanDoProcessing() {};
virtual bool CanDoSSL() {};
- virtual bool SSLVerify() {};
+ virtual COSSLVerified SSLVerify() {};
virtual bool AbleToLogin() {};
virtual bool HasValidResponse() {};
// 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
// 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();
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();
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;
protected:
private:
-};
\ No newline at end of file
+};
+
+#endif
\ No newline at end of file
#include <gtest/gtest.h>
#include "classes/FakeConnectionObject.h"
+#include <chrono>
+#include <thread>
// TODO: Add tests for the CardDAV object.
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());
}
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());
}
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