mirror of
https://github.com/falk-werner/webfused
synced 2024-10-27 20:44:08 +00:00
use wrap utility
This commit is contained in:
parent
d7fd1fdf83
commit
90fc495d95
@ -13,11 +13,12 @@ using ::webfused_test::MockSettings;
|
||||
using ::webfused_test::MockCredentials;
|
||||
using ::testing::Return;
|
||||
using ::testing::StrEq;
|
||||
using ::testing::_;
|
||||
|
||||
TEST(file_authenticator, create)
|
||||
{
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_file_authenticator_create(nullptr, &authenticator);
|
||||
@ -29,7 +30,7 @@ TEST(file_authenticator, create)
|
||||
TEST(file_authenticator, create_fail_missing_file)
|
||||
{
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return(nullptr));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_file_authenticator_create(nullptr, &authenticator);
|
||||
@ -39,7 +40,7 @@ TEST(file_authenticator, create_fail_missing_file)
|
||||
TEST(file_authenticator, create_via_factory)
|
||||
{
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_authenticator_create("file", nullptr, &authenticator);
|
||||
@ -51,7 +52,7 @@ TEST(file_authenticator, create_via_factory)
|
||||
TEST(file_authenticator, authenticate)
|
||||
{
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_file_authenticator_create(nullptr, &authenticator);
|
||||
@ -70,7 +71,7 @@ TEST(file_authenticator, authenticate)
|
||||
TEST(file_authenticator, authenticate_fail_wrong_passwd)
|
||||
{
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_file_authenticator_create(nullptr, &authenticator);
|
||||
@ -89,7 +90,7 @@ TEST(file_authenticator, authenticate_fail_wrong_passwd)
|
||||
TEST(file_authenticator, authenticate_fail_no_passwd_file)
|
||||
{
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("unknown_passwd.json"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return("unknown_passwd.json"));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_file_authenticator_create(nullptr, &authenticator);
|
||||
@ -108,7 +109,7 @@ TEST(file_authenticator, authenticate_fail_no_passwd_file)
|
||||
TEST(file_authenticator, authenticate_fail_missing_username)
|
||||
{
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_file_authenticator_create(nullptr, &authenticator);
|
||||
@ -127,7 +128,7 @@ TEST(file_authenticator, authenticate_fail_missing_username)
|
||||
TEST(file_authenticator, authenticate_fail_missing_password)
|
||||
{
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_file_authenticator_create(nullptr, &authenticator);
|
||||
@ -146,7 +147,7 @@ TEST(file_authenticator, authenticate_fail_missing_password)
|
||||
TEST(file_authenticator, get_type)
|
||||
{
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("/any/path"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return("/any/path"));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_file_authenticator_create(nullptr, &authenticator);
|
||||
|
@ -79,7 +79,7 @@ TEST(pam_authenticator, authenticate_with_custom_service_name)
|
||||
EXPECT_CALL(pam, pam_end(_, _)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getStringOrDefault(StrEq("service_name"), StrEq("webfused")))
|
||||
EXPECT_CALL(settings, wfd_settings_get_string_or_default(_,StrEq("service_name"), StrEq("webfused")))
|
||||
.Times(1).WillOnce(Return("brummni"));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
|
@ -36,7 +36,7 @@ TEST(config, auth_config)
|
||||
ASSERT_NE(nullptr, config);
|
||||
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("/any/path"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return("/any/path"));
|
||||
|
||||
bool success = wfd_config_add_auth_provider(config, "file", nullptr);
|
||||
ASSERT_TRUE(success);
|
||||
@ -50,7 +50,7 @@ TEST(config, auth_config_failed_to_add_second_provider)
|
||||
ASSERT_NE(nullptr, config);
|
||||
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("/any/path"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return("/any/path"));
|
||||
|
||||
bool success = wfd_config_add_auth_provider(config, "file", nullptr);
|
||||
ASSERT_TRUE(success);
|
||||
|
@ -22,9 +22,9 @@ TEST(syslog_logger, init)
|
||||
TEST(syslog_logger, init_fail_invalid_facility)
|
||||
{
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getStringOrDefault(StrEq("ident"), _)).Times(1).WillOnce(Return("webfused_test"));
|
||||
EXPECT_CALL(settings, getStringOrDefault(StrEq("facility"), _)).Times(1).WillOnce(Return("invalid"));
|
||||
EXPECT_CALL(settings, getBool(StrEq("log_pid"))).Times(1).WillOnce(Return(false));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string_or_default(_,StrEq("ident"), _)).Times(1).WillOnce(Return("webfused_test"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string_or_default(_,StrEq("facility"), _)).Times(1).WillOnce(Return("invalid"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_bool(_,StrEq("log_pid"))).Times(1).WillOnce(Return(false));
|
||||
|
||||
wfd_settings * fake_settings = reinterpret_cast<wfd_settings*>(0xDEADBEEF);
|
||||
ASSERT_FALSE(wfd_syslog_logger_init(WFD_LOGLEVEL_ALL, fake_settings));
|
||||
|
@ -1,74 +1,14 @@
|
||||
#include "mock/settings.hpp"
|
||||
#include "util/wrap.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
using webfused_test::ISettings;
|
||||
|
||||
static ISettings * wfd_mock_settings = nullptr;
|
||||
|
||||
extern char const *
|
||||
__real_wfd_settings_get_string(
|
||||
struct wfd_settings * settings,
|
||||
char const * key);
|
||||
|
||||
extern char const *
|
||||
__real_wfd_settings_get_string_or_default(
|
||||
struct wfd_settings * settings,
|
||||
char const * key,
|
||||
char const * default_value);
|
||||
|
||||
extern bool
|
||||
__real_wfd_settings_get_bool(
|
||||
struct wfd_settings * settings,
|
||||
char const * key);
|
||||
|
||||
char const *
|
||||
__wrap_wfd_settings_get_string(
|
||||
struct wfd_settings * settings,
|
||||
char const * key)
|
||||
{
|
||||
if (nullptr == wfd_mock_settings)
|
||||
{
|
||||
return __real_wfd_settings_get_string(settings, key);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_mock_settings->getString(key);
|
||||
}
|
||||
}
|
||||
|
||||
char const *
|
||||
__wrap_wfd_settings_get_string_or_default(
|
||||
struct wfd_settings * settings,
|
||||
char const * key,
|
||||
char const * default_value)
|
||||
{
|
||||
if (nullptr == wfd_mock_settings)
|
||||
{
|
||||
return __real_wfd_settings_get_string_or_default(
|
||||
settings, key, default_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_mock_settings->getStringOrDefault(key, default_value);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
__wrap_wfd_settings_get_bool(
|
||||
struct wfd_settings * settings,
|
||||
char const * key)
|
||||
{
|
||||
if (nullptr == wfd_mock_settings)
|
||||
{
|
||||
return __real_wfd_settings_get_bool(settings, key);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_mock_settings->getBool(key);
|
||||
}
|
||||
}
|
||||
static webfused_test::ISettings * wfd_MockSettings = nullptr;
|
||||
|
||||
WFD_WRAP_FUNC2(wfd_MockSettings, char const *, wfd_settings_get_string, struct wfd_settings *, char const *);
|
||||
WFD_WRAP_FUNC3(wfd_MockSettings, char const *, wfd_settings_get_string_or_default,
|
||||
struct wfd_settings *, char const *, char const *);
|
||||
WFD_WRAP_FUNC2(wfd_MockSettings, bool, wfd_settings_get_bool, struct wfd_settings *, char const *);
|
||||
}
|
||||
|
||||
namespace webfused_test
|
||||
@ -76,12 +16,12 @@ namespace webfused_test
|
||||
|
||||
MockSettings::MockSettings()
|
||||
{
|
||||
wfd_mock_settings = this;
|
||||
wfd_MockSettings = this;
|
||||
}
|
||||
|
||||
MockSettings::~MockSettings()
|
||||
{
|
||||
wfd_mock_settings = nullptr;
|
||||
wfd_MockSettings = nullptr;
|
||||
}
|
||||
|
||||
}
|
@ -11,9 +11,9 @@ class ISettings
|
||||
{
|
||||
public:
|
||||
virtual ~ISettings() = default;
|
||||
virtual char const * getString(char const * key) = 0;
|
||||
virtual char const * getStringOrDefault(char const * key, char const * default_value) = 0;
|
||||
virtual bool getBool(char const * key) = 0;
|
||||
virtual char const * wfd_settings_get_string(wfd_settings * settings, char const * key) = 0;
|
||||
virtual char const * wfd_settings_get_string_or_default(wfd_settings * settings, char const * key, char const * default_value) = 0;
|
||||
virtual bool wfd_settings_get_bool(wfd_settings * settings, char const * key) = 0;
|
||||
};
|
||||
|
||||
class MockSettings: public ISettings
|
||||
@ -21,9 +21,9 @@ class MockSettings: public ISettings
|
||||
public:
|
||||
MockSettings();
|
||||
~MockSettings() override;
|
||||
MOCK_METHOD1(getString, char const * (char const * key));
|
||||
MOCK_METHOD2(getStringOrDefault, char const * (char const * key, char const * default_value));
|
||||
MOCK_METHOD1(getBool, bool (char const * key));
|
||||
MOCK_METHOD2(wfd_settings_get_string, char const * (wfd_settings * settings, char const * key));
|
||||
MOCK_METHOD3(wfd_settings_get_string_or_default, char const * (wfd_settings * settings, char const * key, char const * default_value));
|
||||
MOCK_METHOD2(wfd_settings_get_bool, bool (wfd_settings * settings, char const * key));
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user