From e86dce6341aec3d350835e18c3791a644a313030 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Sun, 31 Jul 2016 14:05:32 +0100 Subject: [PATCH] Added more code and unit tests for ConnectionObject & FakeConnectionObject Added code and unit tests for the following functions in the ConnectionObject interface (and FakeConnectionObject class): EditContact(std::string, std::string); DeleteContact(std::string, std::string); GetServerEntityTagValue(std::string); GetContact(std::string); GetContactList(std::string); --- source/connobject/ConnectionObject.h | 19 +- source/tests/classes/FakeConnectionObject.cpp | 71 ++ source/tests/classes/FakeConnectionObject.h | 8 +- source/tests/xestiaab_carddav.cpp | 820 +++++++++++++++++- 4 files changed, 913 insertions(+), 5 deletions(-) diff --git a/source/connobject/ConnectionObject.h b/source/connobject/ConnectionObject.h index 798ebae..90eb0cb 100644 --- a/source/connobject/ConnectionObject.h +++ b/source/connobject/ConnectionObject.h @@ -17,6 +17,7 @@ // with Xestia Address Book. If not, see #include +#include enum COConnectResult { COCONNECT_UNITTESTFAIL = -1, @@ -36,10 +37,22 @@ enum CORequestResult { struct COServerResponse { CORequestResult RequestResult; std::string EntityTag; + int SessionCode; int ResultCode; std::string ResultMessage; }; +struct COContactData { + std::string Location; + std::string Data; +}; + +struct COContactList { + COServerResponse ServerResponse; + std::vector ListData; + std::string SyncToken; +}; + class ConnectionObject{ public: @@ -54,8 +67,12 @@ 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 COServerResponse EditContact(std::string Location, std::string Data) {}; + virtual COServerResponse DeleteContact(std::string Location, std::string EntityTag) {}; + virtual COServerResponse GetServerEntityTagValue(std::string Location) {}; + virtual COServerResponse GetContact(std::string Location) {}; + virtual COContactList GetContactList(std::string SyncToken) {}; virtual bool CanDoProcessing() {}; virtual bool CanDoSSL() {}; diff --git a/source/tests/classes/FakeConnectionObject.cpp b/source/tests/classes/FakeConnectionObject.cpp index 147b01c..6e70fbf 100644 --- a/source/tests/classes/FakeConnectionObject.cpp +++ b/source/tests/classes/FakeConnectionObject.cpp @@ -41,6 +41,7 @@ COServerResponse FakeConnectionObject::AddContact(std::string Location, std::str AddContactResult.RequestResult = TestRequestResult; AddContactResult.EntityTag = TestEntityTag; + AddContactResult.SessionCode = TestSessionCode; AddContactResult.ResultCode = TestResultCode; AddContactResult.ResultMessage = TestResultMessage; @@ -48,6 +49,76 @@ COServerResponse FakeConnectionObject::AddContact(std::string Location, std::str } +COServerResponse FakeConnectionObject::EditContact(std::string Location, std::string Data){ + + COServerResponse EditContactResult; + + EditContactResult.RequestResult = TestRequestResult; + EditContactResult.EntityTag = TestEntityTag; + EditContactResult.SessionCode = TestSessionCode; + EditContactResult.ResultCode = TestResultCode; + EditContactResult.ResultMessage = TestResultMessage; + + return EditContactResult; + +} + +COServerResponse FakeConnectionObject::DeleteContact(std::string Location, std::string EntityTag){ + + COServerResponse DeleteContactResult; + + DeleteContactResult.RequestResult = TestRequestResult; + DeleteContactResult.EntityTag = TestEntityTag; + DeleteContactResult.SessionCode = TestSessionCode; + DeleteContactResult.ResultCode = TestResultCode; + DeleteContactResult.ResultMessage = TestResultMessage; + + return DeleteContactResult; + +} + +COServerResponse FakeConnectionObject::GetServerEntityTagValue(std::string Location){ + + COServerResponse EntityTagResult; + + EntityTagResult.RequestResult = TestRequestResult; + EntityTagResult.EntityTag = TestEntityTag; + EntityTagResult.SessionCode = TestSessionCode; + EntityTagResult.ResultCode = TestResultCode; + EntityTagResult.ResultMessage = TestResultMessage; + + return EntityTagResult; + +} + +COServerResponse FakeConnectionObject::GetContact(std::string Location){ + + COServerResponse GetContactResult; + + GetContactResult.RequestResult = TestRequestResult; + GetContactResult.EntityTag = TestEntityTag; + GetContactResult.SessionCode = TestSessionCode; + GetContactResult.ResultCode = TestResultCode; + GetContactResult.ResultMessage = TestResultMessage; + + return GetContactResult; + +} + +COContactList FakeConnectionObject::GetContactList(std::string SyncToken){ + + COContactList GetContactListResult = TestContactList; + + GetContactListResult.ServerResponse.RequestResult = TestRequestResult; + GetContactListResult.ServerResponse.EntityTag = TestEntityTag; + GetContactListResult.ServerResponse.SessionCode = TestSessionCode; + GetContactListResult.ServerResponse.ResultCode = TestResultCode; + GetContactListResult.ServerResponse.ResultMessage = TestResultMessage; + + return GetContactListResult; + +} + std::string FakeConnectionObject::GetServerAddress(){ return ServerAddress; } diff --git a/source/tests/classes/FakeConnectionObject.h b/source/tests/classes/FakeConnectionObject.h index 96f03d0..a9eba6d 100644 --- a/source/tests/classes/FakeConnectionObject.h +++ b/source/tests/classes/FakeConnectionObject.h @@ -39,6 +39,11 @@ class FakeConnectionObject : public ConnectionObject { COConnectResult Connect(); std::string GetDefaultPrefix(); COServerResponse AddContact(std::string Location, std::string Data); + COServerResponse EditContact(std::string Location, std::string Data); + COServerResponse DeleteContact(std::string Location, std::string EntityTag); + COServerResponse GetServerEntityTagValue(std::string Location); + COServerResponse GetContact(std::string Location); + COContactList GetContactList(std::string SyncToken); void SetupData(std::string Method, std::string Location, std::string Data); @@ -59,9 +64,10 @@ class FakeConnectionObject : public ConnectionObject { bool ResultSSLVerified = false; bool ResultValidResponse = false; bool ResultSelfSigned = false; - bool NoConnection = false; CORequestResult TestRequestResult; + COContactList TestContactList; std::string TestEntityTag; + int TestSessionCode; int TestResultCode; std::string TestResultMessage; diff --git a/source/tests/xestiaab_carddav.cpp b/source/tests/xestiaab_carddav.cpp index e71f4d5..eb9acf5 100644 --- a/source/tests/xestiaab_carddav.cpp +++ b/source/tests/xestiaab_carddav.cpp @@ -355,7 +355,7 @@ TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Adds_A_Contact_Successfully std::string ServerUser1 = "user"; std::string ServerPass1 = "pass"; - FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true); + FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true, "/prefix", "Account1"); FakeConnection.ResultServerPrefix = "/prefix/test/b"; FakeConnection.Connect(); @@ -369,14 +369,828 @@ TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Adds_A_Contact_Successfully FakeConnection.TestRequestResult = COREQUEST_OK; FakeConnection.TestEntityTag = "4324svafhuiaffsdhui"; - FakeConnection.TestResultCode = 200; + FakeConnection.TestResultCode = 201; + FakeConnection.TestSessionCode = 0; 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(201, AddContactResult.ResultCode); + EXPECT_EQ(0, AddContactResult.SessionCode); EXPECT_EQ("", AddContactResult.ResultMessage); +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Add_A_Contact_Due_To_Permissions){ + + 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(); + + 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_ERROR_SERVER; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 403; + FakeConnection.TestSessionCode = 22; + FakeConnection.TestResultMessage = "You do not have permission to add this resource."; + + COServerResponse AddContactResult = FakeConnection.AddContact("testfile.vcf", ContactFile); + + EXPECT_EQ(COREQUEST_ERROR_SERVER, AddContactResult.RequestResult); + EXPECT_EQ("", AddContactResult.EntityTag); + EXPECT_EQ(403, AddContactResult.ResultCode); + EXPECT_EQ(22, AddContactResult.SessionCode); + EXPECT_EQ("You do not have permission to add this resource.", AddContactResult.ResultMessage); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Add_A_Contact_Due_To_Invalid_Path){ + + 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(); + + 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_ERROR_SERVER; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 404; + FakeConnection.TestSessionCode = 22; + FakeConnection.TestResultMessage = "The location cannot be found."; + + COServerResponse AddContactResult = FakeConnection.AddContact("testfile.vcf", ContactFile); + + EXPECT_EQ(COREQUEST_ERROR_SERVER, AddContactResult.RequestResult); + EXPECT_EQ("", AddContactResult.EntityTag); + EXPECT_EQ(404, AddContactResult.ResultCode); + EXPECT_EQ(22, AddContactResult.SessionCode); + EXPECT_EQ("The location cannot be found.", AddContactResult.ResultMessage); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Add_A_Contact_Due_To_No_Connection){ + + 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(); + + 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_ERROR_NOTCONNECTED; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 0; + FakeConnection.TestSessionCode = 0; + FakeConnection.TestResultMessage = ""; + + COServerResponse AddContactResult = FakeConnection.AddContact("testfile.vcf", ContactFile); + + EXPECT_EQ(COREQUEST_ERROR_NOTCONNECTED, AddContactResult.RequestResult); + EXPECT_EQ("", AddContactResult.EntityTag); + EXPECT_EQ(0, AddContactResult.ResultCode); + EXPECT_EQ(0, AddContactResult.SessionCode); + EXPECT_EQ("", AddContactResult.ResultMessage); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Edits_A_Server_Contact){ + + 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(); + + std::string ContactFile = + "BEGIN:VCARD\n" + "VERSION:4.0\n" + "UID:84q2ioj13jofiujqwrAAA\n" + "N:;;Meep;Moop;;\n" + "FN:The Meep Moop\n" + "END:VCARD"; + + FakeConnection.TestRequestResult = COREQUEST_OK; + FakeConnection.TestEntityTag = "a23124sfadfdvxc1646541bsdfaf"; + FakeConnection.TestResultCode = 200; + FakeConnection.TestSessionCode = 0; + FakeConnection.TestResultMessage = ""; + + COServerResponse EditContactResult = FakeConnection.EditContact("testfile.vcf", ContactFile); + + EXPECT_EQ(COREQUEST_OK, EditContactResult.RequestResult); + EXPECT_EQ("a23124sfadfdvxc1646541bsdfaf", EditContactResult.EntityTag); + EXPECT_EQ(200, EditContactResult.ResultCode); + EXPECT_EQ(0, EditContactResult.SessionCode); + EXPECT_EQ("", EditContactResult.ResultMessage); + + FakeConnection.TestRequestResult = COREQUEST_OK; + FakeConnection.TestEntityTag = "asf84sa484saf614as64asvada4s6fas"; + FakeConnection.TestResultCode = 204; + FakeConnection.TestSessionCode = 0; + FakeConnection.TestResultMessage = ""; + + EditContactResult = FakeConnection.EditContact("testfile.vcf", ContactFile); + + EXPECT_EQ(COREQUEST_OK, EditContactResult.RequestResult); + EXPECT_EQ("asf84sa484saf614as64asvada4s6fas", EditContactResult.EntityTag); + EXPECT_EQ(204, EditContactResult.ResultCode); + EXPECT_EQ(0, EditContactResult.SessionCode); + EXPECT_EQ("", EditContactResult.ResultMessage); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Edit_A_Server_Contact_Due_To_Invalid_Permissions){ + + 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(); + + std::string ContactFile = + "BEGIN:VCARD\n" + "VERSION:4.0\n" + "UID:84q2ioj13jofiujqwrAAA\n" + "N:;;Meep;Moop;;\n" + "FN:The Meep Moop\n" + "END:VCARD"; + + FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 403; + FakeConnection.TestSessionCode = 22; + FakeConnection.TestResultMessage = "You do not have permission to add this resource."; + + COServerResponse EditContactResult = FakeConnection.EditContact("testfile.vcf", ContactFile); + + EXPECT_EQ(COREQUEST_ERROR_SERVER, EditContactResult.RequestResult); + EXPECT_EQ("", EditContactResult.EntityTag); + EXPECT_EQ(403, EditContactResult.ResultCode); + EXPECT_EQ(22, EditContactResult.SessionCode); + EXPECT_EQ("You do not have permission to add this resource.", EditContactResult.ResultMessage); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Edit_A_Server_Contact_Due_To_Invalid_Location){ + + 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(); + + std::string ContactFile = + "BEGIN:VCARD\n" + "VERSION:4.0\n" + "UID:84q2ioj13jofiujqwrAAA\n" + "N:;;Meep;Moop;;\n" + "FN:The Meep Moop\n" + "END:VCARD"; + + FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 404; + FakeConnection.TestSessionCode = 22; + FakeConnection.TestResultMessage = "The resource could not be found."; + + COServerResponse EditContactResult = FakeConnection.EditContact("testfile.vcf", ContactFile); + + EXPECT_EQ(COREQUEST_ERROR_SERVER, EditContactResult.RequestResult); + EXPECT_EQ("", EditContactResult.EntityTag); + EXPECT_EQ(404, EditContactResult.ResultCode); + EXPECT_EQ(22, EditContactResult.SessionCode); + EXPECT_EQ("The resource could not be found.", EditContactResult.ResultMessage); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Edit_A_Server_Contact_Due_To_No_Connection){ + + 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(); + + std::string ContactFile = + "BEGIN:VCARD\n" + "VERSION:4.0\n" + "UID:84q2ioj13jofiujqwrAAA\n" + "N:;;Meep;Moop;;\n" + "FN:The Meep Moop\n" + "END:VCARD"; + + FakeConnection.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 0; + FakeConnection.TestSessionCode = 0; + FakeConnection.TestResultMessage = ""; + + COServerResponse EditContactResult = FakeConnection.EditContact("testfile.vcf", ContactFile); + + EXPECT_EQ(COREQUEST_ERROR_NOTCONNECTED, EditContactResult.RequestResult); + EXPECT_EQ("", EditContactResult.EntityTag); + EXPECT_EQ(0, EditContactResult.ResultCode); + EXPECT_EQ(0, EditContactResult.SessionCode); + EXPECT_EQ("", EditContactResult.ResultMessage); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Deletes_A_Server_Contact){ + + 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.TestRequestResult = COREQUEST_OK; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 200; + FakeConnection.TestSessionCode = 0; + FakeConnection.TestResultMessage = ""; + + COServerResponse DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf", "a23124sfadfdvxc1646541bsdfaf"); + + EXPECT_EQ(COREQUEST_OK, DeleteContactResult.RequestResult); + EXPECT_EQ("", DeleteContactResult.EntityTag); + EXPECT_EQ(200, DeleteContactResult.ResultCode); + EXPECT_EQ(0, DeleteContactResult.SessionCode); + EXPECT_EQ("", DeleteContactResult.ResultMessage); + + FakeConnection.TestRequestResult = COREQUEST_OK; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 204; + FakeConnection.TestSessionCode = 0; + FakeConnection.TestResultMessage = ""; + + DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf", "asf84sa484saf614as64asvada4s6fas"); + + EXPECT_EQ(COREQUEST_OK, DeleteContactResult.RequestResult); + EXPECT_EQ("", DeleteContactResult.EntityTag); + EXPECT_EQ(204, DeleteContactResult.ResultCode); + EXPECT_EQ(0, DeleteContactResult.SessionCode); + EXPECT_EQ("", DeleteContactResult.ResultMessage); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Delete_A_Server_Contact_Due_To_Invalid_Permissions){ + + 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.TestRequestResult = COREQUEST_ERROR_SERVER; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 403; + FakeConnection.TestSessionCode = 22; + FakeConnection.TestResultMessage = "You do not have permission to delete this resource."; + + COServerResponse DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf", "a23124sfadfdvxc1646541bsdfaf"); + + EXPECT_EQ(COREQUEST_ERROR_SERVER, DeleteContactResult.RequestResult); + EXPECT_EQ("", DeleteContactResult.EntityTag); + EXPECT_EQ(403, DeleteContactResult.ResultCode); + EXPECT_EQ(22, DeleteContactResult.SessionCode); + EXPECT_EQ("You do not have permission to delete this resource.", DeleteContactResult.ResultMessage); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Delete_A_Server_Contact_Due_To_Missing_Location){ + + 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.TestRequestResult = COREQUEST_ERROR_SERVER; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 404; + FakeConnection.TestSessionCode = 22; + FakeConnection.TestResultMessage = "The resource could not be found."; + + COServerResponse DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf", "a23124sfadfdvxc1646541bsdfaf"); + + EXPECT_EQ(COREQUEST_ERROR_SERVER, DeleteContactResult.RequestResult); + EXPECT_EQ("", DeleteContactResult.EntityTag); + EXPECT_EQ(404, DeleteContactResult.ResultCode); + EXPECT_EQ(22, DeleteContactResult.SessionCode); + EXPECT_EQ("The resource could not be found.", DeleteContactResult.ResultMessage); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Delete_A_Server_Contact_Due_To_No_Connection){ + + 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.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 0; + FakeConnection.TestSessionCode = 0; + FakeConnection.TestResultMessage = ""; + + COServerResponse DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf", "a23124sfadfdvxc1646541bsdfaf"); + + EXPECT_EQ(COREQUEST_ERROR_NOTCONNECTED, DeleteContactResult.RequestResult); + EXPECT_EQ("", DeleteContactResult.EntityTag); + EXPECT_EQ(0, DeleteContactResult.ResultCode); + EXPECT_EQ(0, DeleteContactResult.SessionCode); + EXPECT_EQ("", DeleteContactResult.ResultMessage); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_Server_Entity_Tag_Value){ + + 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.TestRequestResult = COREQUEST_OK; + FakeConnection.TestEntityTag = "a23124sfadfdvxc1646541bsdfaf"; + FakeConnection.TestResultCode = 200; + FakeConnection.TestSessionCode = 0; + FakeConnection.TestResultMessage = ""; + + COServerResponse EntityTagResult = FakeConnection.GetServerEntityTagValue("testfile.vcf"); + + EXPECT_EQ(COREQUEST_OK, EntityTagResult.RequestResult); + EXPECT_EQ("a23124sfadfdvxc1646541bsdfaf", EntityTagResult.EntityTag); + EXPECT_EQ(200, EntityTagResult.ResultCode); + EXPECT_EQ(0, EntityTagResult.SessionCode); + EXPECT_EQ("", EntityTagResult.ResultMessage); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_Server_Entity_Tag_Value_Due_To_Invalid_Permissions){ + + 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.TestRequestResult = COREQUEST_ERROR_SERVER; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 403; + FakeConnection.TestSessionCode = 22; + FakeConnection.TestResultMessage = "You do not have permission to access this resource."; + + COServerResponse EntityTagResult = FakeConnection.GetServerEntityTagValue("testfile.vcf"); + + EXPECT_EQ(COREQUEST_ERROR_SERVER, EntityTagResult.RequestResult); + EXPECT_EQ("", EntityTagResult.EntityTag); + EXPECT_EQ(403, EntityTagResult.ResultCode); + EXPECT_EQ(22, EntityTagResult.SessionCode); + EXPECT_EQ("You do not have permission to access this resource.", EntityTagResult.ResultMessage); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_Server_Entity_Tag_Value_Due_To_Missing_Resource){ + + 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.TestRequestResult = COREQUEST_ERROR_SERVER; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 404; + FakeConnection.TestSessionCode = 22; + FakeConnection.TestResultMessage = "The resource cannot be found."; + + COServerResponse EntityTagResult = FakeConnection.GetServerEntityTagValue("testfile.vcf"); + + EXPECT_EQ(COREQUEST_ERROR_SERVER, EntityTagResult.RequestResult); + EXPECT_EQ("", EntityTagResult.EntityTag); + EXPECT_EQ(404, EntityTagResult.ResultCode); + EXPECT_EQ(22, EntityTagResult.SessionCode); + EXPECT_EQ("The resource cannot be found.", EntityTagResult.ResultMessage); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_Server_Entity_Tag_Value_Due_To_No_Connection){ + + 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.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 0; + FakeConnection.TestSessionCode = 0; + FakeConnection.TestResultMessage = ""; + + COServerResponse EntityTagResult = FakeConnection.GetServerEntityTagValue("testfile.vcf"); + + EXPECT_EQ(COREQUEST_ERROR_NOTCONNECTED, EntityTagResult.RequestResult); + EXPECT_EQ("", EntityTagResult.EntityTag); + EXPECT_EQ(0, EntityTagResult.ResultCode); + EXPECT_EQ(0, EntityTagResult.SessionCode); + EXPECT_EQ("", EntityTagResult.ResultMessage); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_Server_Contact_Data){ + + 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(); + + std::string ContactFile = + "BEGIN:VCARD\n" + "VERSION:4.0\n" + "UID:84q2ioj13jofiujqwrAAA\n" + "N:;;Meep;Moop;;\n" + "FN:The Meep Moop\n" + "END:VCARD"; + + FakeConnection.TestRequestResult = COREQUEST_OK; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 200; + FakeConnection.TestSessionCode = 0; + FakeConnection.TestResultMessage = ContactFile; + + COServerResponse ServerDataResult = FakeConnection.GetContact("/location/testfile.vcf"); + + EXPECT_EQ(COREQUEST_OK, ServerDataResult.RequestResult); + EXPECT_EQ("", ServerDataResult.EntityTag); + EXPECT_EQ(200, ServerDataResult.ResultCode); + EXPECT_EQ(0, ServerDataResult.SessionCode); + EXPECT_EQ(ContactFile, ServerDataResult.ResultMessage); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Gets_Server_Contact_Data_Due_To_Invalid_Permissions){ + + 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.TestRequestResult = COREQUEST_OK; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 403; + FakeConnection.TestSessionCode = 22; + FakeConnection.TestResultMessage = "You do not have permission to access this resource."; + + COServerResponse ServerDataResult = FakeConnection.GetContact("/location/testfile.vcf"); + + EXPECT_EQ(COREQUEST_OK, ServerDataResult.RequestResult); + EXPECT_EQ("", ServerDataResult.EntityTag); + EXPECT_EQ(403, ServerDataResult.ResultCode); + EXPECT_EQ(22, ServerDataResult.SessionCode); + EXPECT_EQ("You do not have permission to access this resource.", ServerDataResult.ResultMessage); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Gets_Server_Contact_Data_Due_To_Missing_Resource){ + + 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.TestRequestResult = COREQUEST_OK; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 404; + FakeConnection.TestSessionCode = 22; + FakeConnection.TestResultMessage = "The resource could not be found."; + + COServerResponse ServerDataResult = FakeConnection.GetContact("/location/testfile.vcf"); + + EXPECT_EQ(COREQUEST_OK, ServerDataResult.RequestResult); + EXPECT_EQ("", ServerDataResult.EntityTag); + EXPECT_EQ(404, ServerDataResult.ResultCode); + EXPECT_EQ(22, ServerDataResult.SessionCode); + EXPECT_EQ("The resource could not be found.", ServerDataResult.ResultMessage); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_Server_Contact_Data_Due_To_No_Connection){ + + 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.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 0; + FakeConnection.TestSessionCode = 0; + FakeConnection.TestResultMessage = ""; + + COServerResponse ServerDataResult = FakeConnection.GetContact("/location/testfile.vcf"); + + EXPECT_EQ(COREQUEST_ERROR_NOTCONNECTED, ServerDataResult.RequestResult); + EXPECT_EQ("", ServerDataResult.EntityTag); + EXPECT_EQ(0, ServerDataResult.ResultCode); + EXPECT_EQ(0, ServerDataResult.SessionCode); + EXPECT_EQ("", ServerDataResult.ResultMessage); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_A_Full_Server_Contact_List){ + + 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(); + + std::string ContactFile1 = + "BEGIN:VCARD\n" + "VERSION:4.0\n" + "UID:84q2ioj13jofiujqwrAAA-1\n" + "N:;;Meep;Moop;;\n" + "FN:The Meep Moop\n" + "END:VCARD"; + + std::string ContactFile2 = + "BEGIN:VCARD\n" + "VERSION:4.0\n" + "UID:84q2ioj13jofiujqwrAAA-2\n" + "N:;;Meep;Moop;;\n" + "FN:The Meep Moop\n" + "END:VCARD"; + + std::string ContactFile3 = + "BEGIN:VCARD\n" + "VERSION:4.0\n" + "UID:84q2ioj13jofiujqwrAAA-3\n" + "N:;;Meep;Moop;;\n" + "FN:The Meep Moop\n" + "END:VCARD"; + + COContactList ContactListSetup; + COContactData ContactPerson; + + ContactPerson.Location = "/location1.vcf"; + ContactPerson.Data = ContactFile1; + ContactListSetup.ListData.push_back(ContactPerson); + + ContactPerson.Location = "/location2.vcf"; + ContactPerson.Data = ContactFile2; + ContactListSetup.ListData.push_back(ContactPerson); + + ContactPerson.Location = "/location3.vcf"; + ContactPerson.Data = ContactFile3; + ContactListSetup.ListData.push_back(ContactPerson); + ContactListSetup.SyncToken = "2312312-12312312"; + + FakeConnection.TestContactList = ContactListSetup; + FakeConnection.TestRequestResult = COREQUEST_OK; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 200; + FakeConnection.TestSessionCode = 0; + FakeConnection.TestResultMessage = ""; + + COContactList ServerDataResult = FakeConnection.GetContactList(""); + + EXPECT_EQ(COREQUEST_OK, ServerDataResult.ServerResponse.RequestResult); + EXPECT_EQ("", ServerDataResult.ServerResponse.EntityTag); + EXPECT_EQ(200, ServerDataResult.ServerResponse.ResultCode); + EXPECT_EQ(0, ServerDataResult.ServerResponse.SessionCode); + EXPECT_EQ("", ServerDataResult.ServerResponse.ResultMessage); + + EXPECT_EQ("2312312-12312312", ServerDataResult.SyncToken); + + EXPECT_EQ(3, ServerDataResult.ListData.size()); + + EXPECT_EQ("/location1.vcf", ServerDataResult.ListData[0].Location); + EXPECT_EQ(ContactFile1, ServerDataResult.ListData[0].Data); + + EXPECT_EQ("/location2.vcf", ServerDataResult.ListData[1].Location); + EXPECT_EQ(ContactFile2, ServerDataResult.ListData[1].Data); + + EXPECT_EQ("/location3.vcf", ServerDataResult.ListData[2].Location); + EXPECT_EQ(ContactFile3, ServerDataResult.ListData[2].Data); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Gets_A_Partial_Server_Contact_List){ + + 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(); + + std::string ContactFile3 = + "BEGIN:VCARD\n" + "VERSION:4.0\n" + "UID:84q2ioj13jofiujqwrAAA-3\n" + "N:;;Meep;Moop;;\n" + "FN:The Meep Moop\n" + "END:VCARD"; + + COContactList ContactListSetup; + COContactData ContactPerson; + + ContactPerson.Location = "/location3.vcf"; + ContactPerson.Data = ContactFile3; + ContactListSetup.ListData.push_back(ContactPerson); + ContactListSetup.SyncToken = "5964589-43543534"; + + FakeConnection.TestContactList = ContactListSetup; + FakeConnection.TestRequestResult = COREQUEST_OK; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 200; + FakeConnection.TestSessionCode = 0; + FakeConnection.TestResultMessage = ""; + + COContactList ServerDataResult = FakeConnection.GetContactList("2312312-12312312"); + + EXPECT_EQ(COREQUEST_OK, ServerDataResult.ServerResponse.RequestResult); + EXPECT_EQ("", ServerDataResult.ServerResponse.EntityTag); + EXPECT_EQ(200, ServerDataResult.ServerResponse.ResultCode); + EXPECT_EQ(0, ServerDataResult.ServerResponse.SessionCode); + EXPECT_EQ("", ServerDataResult.ServerResponse.ResultMessage); + + EXPECT_EQ("5964589-43543534", ServerDataResult.SyncToken); + + EXPECT_EQ(1, ServerDataResult.ListData.size()); + + EXPECT_EQ("/location3.vcf", ServerDataResult.ListData[0].Location); + EXPECT_EQ(ContactFile3, ServerDataResult.ListData[0].Data); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_A_Contact_List_Due_To_Invalid_Permissions){ + + 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(); + + COContactList ContactListSetup; + ContactListSetup.SyncToken = ""; + + FakeConnection.TestContactList = ContactListSetup; + FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 403; + FakeConnection.TestSessionCode = 22; + FakeConnection.TestResultMessage = "You do not have permission to access this resource."; + + COContactList ServerDataResult = FakeConnection.GetContactList(""); + + EXPECT_EQ(COREQUEST_ERROR_SERVER, ServerDataResult.ServerResponse.RequestResult); + EXPECT_EQ("", ServerDataResult.ServerResponse.EntityTag); + EXPECT_EQ(403, ServerDataResult.ServerResponse.ResultCode); + EXPECT_EQ(22, ServerDataResult.ServerResponse.SessionCode); + EXPECT_EQ("You do not have permission to access this resource.", ServerDataResult.ServerResponse.ResultMessage); + + EXPECT_EQ(0, ServerDataResult.ListData.size()); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_A_Contact_List_Due_To_Missing_Resource){ + + 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(); + + COContactList ContactListSetup; + ContactListSetup.SyncToken = ""; + + FakeConnection.TestContactList = ContactListSetup; + FakeConnection.TestRequestResult = COREQUEST_ERROR_SERVER; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 404; + FakeConnection.TestSessionCode = 22; + FakeConnection.TestResultMessage = "The resource could not be found."; + + COContactList ServerDataResult = FakeConnection.GetContactList(""); + + EXPECT_EQ(COREQUEST_ERROR_SERVER, ServerDataResult.ServerResponse.RequestResult); + EXPECT_EQ("", ServerDataResult.ServerResponse.EntityTag); + EXPECT_EQ(404, ServerDataResult.ServerResponse.ResultCode); + EXPECT_EQ(22, ServerDataResult.ServerResponse.SessionCode); + EXPECT_EQ("The resource could not be found.", ServerDataResult.ServerResponse.ResultMessage); + + EXPECT_EQ(0, ServerDataResult.ListData.size()); + +} + +TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_That_Fails_To_Get_A_Contact_List_Due_To_No_Connection){ + + 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(); + + COContactList ContactListSetup; + ContactListSetup.SyncToken = ""; + + FakeConnection.TestContactList = ContactListSetup; + FakeConnection.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED; + FakeConnection.TestEntityTag = ""; + FakeConnection.TestResultCode = 404; + FakeConnection.TestSessionCode = 22; + FakeConnection.TestResultMessage = "The resource could not be found."; + + COContactList ServerDataResult = FakeConnection.GetContactList(""); + + EXPECT_EQ(COREQUEST_ERROR_NOTCONNECTED, ServerDataResult.ServerResponse.RequestResult); + EXPECT_EQ("", ServerDataResult.ServerResponse.EntityTag); + EXPECT_EQ(404, ServerDataResult.ServerResponse.ResultCode); + EXPECT_EQ(22, ServerDataResult.ServerResponse.SessionCode); + EXPECT_EQ("The resource could not be found.", ServerDataResult.ServerResponse.ResultMessage); + + EXPECT_EQ(0, ServerDataResult.ListData.size()); + } \ No newline at end of file -- 2.39.5