// xestiaab_carddav.h - Xestia Address Book CardDAV Object Unit Tests.
//
// (c) 2012-2015 Xestia Software Development.
//
// This file is part of Xestia Address Book.
//
// Xestia Address Book is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by the
// Free Software Foundation, version 3 of the license.
//
// Xestia Address Book is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with Xestia Address Book. If not, see
#include
#include "classes/FakeConnectionObject.h"
#include
#include
// 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);
FakeConnection1.ResultTestMode = true;
FakeConnection2.ResultTestMode = true;
FakeConnection3.ResultTestMode = true;
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");
FakeConnection1.ResultTestMode = false;
FakeConnection2.ResultTestMode = false;
FakeConnection3.ResultTestMode = 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(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";
FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
FakeConnection.ResultStatus = COCONNECT_OK;
EXPECT_EQ(COCONNECT_OK, FakeConnection.Connect(false));
}
TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_Returning_InvalidAddress){
std::string ServerAddress1 = "gibberish.invalid";
std::string ServerUser1 = "user";
std::string ServerPass1 = "pass";
FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
FakeConnection.ResultStatus = COCONNECT_INVALID;
EXPECT_EQ(COCONNECT_INVALID, FakeConnection.Connect(false));
}
TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_Returning_Timeout){
std::string ServerAddress1 = "gibberish.invalid";
std::string ServerUser1 = "user";
std::string ServerPass1 = "pass";
FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
FakeConnection.ResultStatus = COCONNECT_TIMEOUT;
EXPECT_EQ(COCONNECT_TIMEOUT, FakeConnection.Connect(false));
}
TEST(CardDAV, Use_Fake_To_Simulate_A_Connection_Returning_Authentication_Failure){
std::string ServerAddress1 = "gibberish.invalid";
std::string ServerUser1 = "user";
std::string ServerPass1 = "pass";
FakeConnectionObject FakeConnection(ServerAddress1, 8080, ServerUser1, ServerPass1, true);
FakeConnection.ResultStatus = COCONNECT_AUTHFAIL;
EXPECT_EQ(COCONNECT_AUTHFAIL, FakeConnection.Connect(false));
}
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(false);
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(false);
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(false);
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(false);
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(false);
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 = COSSL_VERIFIED;
FakeConnection.Connect(false);
EXPECT_EQ(COSSL_VERIFIED, 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 = COSSL_UNABLETOVERIFY;
FakeConnection.ResultStatus = COCONNECT_SSLFAIL;
EXPECT_EQ(COCONNECT_SSLFAIL, FakeConnection.Connect(false));
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(false);
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(false);
EXPECT_EQ(COSSL_NOTAPPLICABLE, 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(false);
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(false);
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(false);
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(false);
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(false);
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(false);
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, "/prefix", "Account1");
FakeConnection.ResultServerPrefix = "/prefix/test/b";
FakeConnection.Connect(false);
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 = 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(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(false);
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(false);
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(false);
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(false);
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(false);
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(false);
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(false);
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(false);
FakeConnection.TestRequestResult = COREQUEST_OK;
FakeConnection.TestEntityTag = "";
FakeConnection.TestResultCode = 200;
FakeConnection.TestSessionCode = 0;
FakeConnection.TestResultMessage = "";
COServerResponse DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf");
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");
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(false);
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");
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(false);
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");
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(false);
FakeConnection.TestRequestResult = COREQUEST_ERROR_NOTCONNECTED;
FakeConnection.TestEntityTag = "";
FakeConnection.TestResultCode = 0;
FakeConnection.TestSessionCode = 0;
FakeConnection.TestResultMessage = "";
COServerResponse DeleteContactResult = FakeConnection.DeleteContact("testfile.vcf");
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(false);
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(false);
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(false);
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(false);
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(false);
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(false);
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(false);
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(false);
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(false);
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(false);
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(false);
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(false);
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(false);
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());
}
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(false);
FakeConnection.ResultTaskCompleted = false;
while (!FakeConnection.IsTaskCompleted()){
std::this_thread::sleep_for(std::chrono::milliseconds(250));
FakeConnection.ResultTaskCompleted = true;
}
EXPECT_TRUE(FakeConnection.ResultTaskCompleted);
}