parent
609fbee24f
commit
1625869696
@ -1,30 +0,0 @@
|
||||
#ifndef WFD_AUTH_SETTINGS_H
|
||||
#define WFD_AUTH_SETTINGS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wfd_auth_settings;
|
||||
|
||||
|
||||
extern char const *
|
||||
wfd_auth_settings_get_provider(
|
||||
struct wfd_auth_settings * settings);
|
||||
|
||||
extern char const *
|
||||
wfd_auth_settings_get(
|
||||
struct wfd_auth_settings * settings,
|
||||
char const * key);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -1,51 +0,0 @@
|
||||
#include "webfused/auth/settings.h"
|
||||
#include "webfused/config/auth_settings.h"
|
||||
|
||||
#include <libconfig.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wfd_auth_settings
|
||||
{
|
||||
char * provider_name;
|
||||
struct config_setting_t * settings;
|
||||
};
|
||||
|
||||
struct wfd_auth_settings *
|
||||
wfd_auth_settings_create(
|
||||
char const * provider_name,
|
||||
struct config_setting_t * settings)
|
||||
{
|
||||
struct wfd_auth_settings * auth_settings = malloc(sizeof(struct wfd_auth_settings));
|
||||
auth_settings->provider_name = strdup(provider_name);
|
||||
auth_settings->settings = settings;
|
||||
|
||||
return auth_settings;
|
||||
}
|
||||
|
||||
void
|
||||
wfd_auth_settings_dispose(
|
||||
struct wfd_auth_settings * settings)
|
||||
{
|
||||
free(settings->provider_name);
|
||||
free(settings);
|
||||
}
|
||||
|
||||
char const *
|
||||
wfd_auth_settings_get_provider(
|
||||
struct wfd_auth_settings * settings)
|
||||
{
|
||||
return settings->provider_name;
|
||||
}
|
||||
|
||||
char const *
|
||||
wfd_auth_settings_get(
|
||||
struct wfd_auth_settings * settings,
|
||||
char const * key)
|
||||
{
|
||||
char const * result;
|
||||
int rc = config_setting_lookup_string(settings->settings, key, &result);
|
||||
|
||||
return (CONFIG_TRUE == rc) ? result : NULL;
|
||||
}
|
||||
|
@ -1,25 +0,0 @@
|
||||
#ifndef WFD_CONFIG_AUTH_SETTINGS_H
|
||||
#define WFD_CONFIG_AUTH_SETTINGS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wfd_auth_settings;
|
||||
struct config_setting_t;
|
||||
|
||||
extern struct wfd_auth_settings *
|
||||
wfd_auth_settings_create(
|
||||
char const * provider_name,
|
||||
struct config_setting_t * settings);
|
||||
|
||||
extern void
|
||||
wfd_auth_settings_dispose(
|
||||
struct wfd_auth_settings * settings);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,32 @@
|
||||
#include "webfused/config/settings.h"
|
||||
#include "webfused/config/settings_intern.h"
|
||||
|
||||
#include <libconfig.h>
|
||||
#include <stddef.h>
|
||||
|
||||
void
|
||||
wfd_settings_init(
|
||||
struct wfd_settings * settings,
|
||||
struct config_setting_t * setting)
|
||||
{
|
||||
settings->setting = setting;
|
||||
}
|
||||
|
||||
void
|
||||
wfd_settings_cleanup(
|
||||
struct wfd_settings * settings)
|
||||
{
|
||||
settings->setting = NULL;
|
||||
}
|
||||
|
||||
char const *
|
||||
wfd_settings_get(
|
||||
struct wfd_settings * settings,
|
||||
char const * key)
|
||||
{
|
||||
char const * result;
|
||||
int rc = config_setting_lookup_string(settings->setting, key, &result);
|
||||
|
||||
return (CONFIG_TRUE == rc) ? result : NULL;
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
#ifndef WFD_CONFIG_SETTINGS_H
|
||||
#define WFD_CONFIG_SETTINGS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wfd_settings;
|
||||
|
||||
|
||||
extern char const *
|
||||
wfd_settings_get(
|
||||
struct wfd_settings * settings,
|
||||
char const * key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,30 @@
|
||||
#ifndef WFD_CONFIG_SETTINGS_INTERN_H
|
||||
#define WFD_CONFIG_SETTINGS_INTERN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct config_setting_t;
|
||||
|
||||
struct wfd_settings
|
||||
{
|
||||
struct config_setting_t * setting;
|
||||
};
|
||||
|
||||
|
||||
extern void
|
||||
wfd_settings_init(
|
||||
struct wfd_settings * settings,
|
||||
struct config_setting_t * setting);
|
||||
|
||||
extern void
|
||||
wfd_settings_cleanup(
|
||||
struct wfd_settings * settings);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,63 +0,0 @@
|
||||
#include "mock_auth_settings.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
using webfused_test::IAuthSettings;
|
||||
|
||||
static IAuthSettings * wfd_mock_auth_settings = nullptr;
|
||||
|
||||
extern char const *
|
||||
__real_wfd_auth_settings_get_provider(
|
||||
struct wfd_auth_settings * settings);
|
||||
|
||||
extern char const *
|
||||
__real_wfd_auth_settings_get(
|
||||
struct wfd_auth_settings * settings,
|
||||
char const * key);
|
||||
|
||||
char const *
|
||||
__wrap_wfd_auth_settings_get_provider(
|
||||
struct wfd_auth_settings * settings)
|
||||
{
|
||||
if (nullptr == wfd_mock_auth_settings)
|
||||
{
|
||||
return __real_wfd_auth_settings_get_provider(settings);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_mock_auth_settings->getProvider();
|
||||
}
|
||||
}
|
||||
|
||||
char const *
|
||||
__wrap_wfd_auth_settings_get(
|
||||
struct wfd_auth_settings * settings,
|
||||
char const * key)
|
||||
{
|
||||
if (nullptr == wfd_mock_auth_settings)
|
||||
{
|
||||
return __real_wfd_auth_settings_get(settings, key);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_mock_auth_settings->get(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
MockAuthSettings::MockAuthSettings()
|
||||
{
|
||||
wfd_mock_auth_settings = this;
|
||||
}
|
||||
|
||||
MockAuthSettings::~MockAuthSettings()
|
||||
{
|
||||
wfd_mock_auth_settings = nullptr;
|
||||
}
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
#ifndef WFD_MOCK_AUTH_SETTINGS_HPP
|
||||
#define WFD_MOCK_AUTH_SETTINGS_HPP
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include "webfused/auth/settings.h"
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
class IAuthSettings
|
||||
{
|
||||
public:
|
||||
virtual ~IAuthSettings() = default;
|
||||
virtual char const * getProvider() = 0;
|
||||
virtual char const * get(char const * key) = 0;
|
||||
};
|
||||
|
||||
class MockAuthSettings: public IAuthSettings
|
||||
{
|
||||
public:
|
||||
MockAuthSettings();
|
||||
~MockAuthSettings() override;
|
||||
MOCK_METHOD0(getProvider, char const * ());
|
||||
MOCK_METHOD1(get, char const * (char const * key));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,45 @@
|
||||
#include "mock_settings.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
using webfused_test::ISettings;
|
||||
|
||||
static ISettings * wfd_mock_settings = nullptr;
|
||||
|
||||
extern char const *
|
||||
__real_wfd_settings_get(
|
||||
struct wfd_settings * settings,
|
||||
char const * key);
|
||||
|
||||
char const *
|
||||
__wrap_wfd_settings_get(
|
||||
struct wfd_settings * settings,
|
||||
char const * key)
|
||||
{
|
||||
if (nullptr == wfd_mock_settings)
|
||||
{
|
||||
return __real_wfd_settings_get(settings, key);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_mock_settings->get(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
MockSettings::MockSettings()
|
||||
{
|
||||
wfd_mock_settings = this;
|
||||
}
|
||||
|
||||
MockSettings::~MockSettings()
|
||||
{
|
||||
wfd_mock_settings = nullptr;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
#ifndef WFD_MOCK_AUTH_SETTINGS_HPP
|
||||
#define WFD_MOCK_AUTH_SETTINGS_HPP
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include "webfused/config/settings.h"
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
class ISettings
|
||||
{
|
||||
public:
|
||||
virtual ~ISettings() = default;
|
||||
virtual char const * get(char const * key) = 0;
|
||||
};
|
||||
|
||||
class MockSettings: public ISettings
|
||||
{
|
||||
public:
|
||||
MockSettings();
|
||||
~MockSettings() override;
|
||||
MOCK_METHOD1(get, char const * (char const * key));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,31 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfused/auth/settings.h"
|
||||
#include "webfused/config/auth_settings.h"
|
||||
#include <libconfig.h>
|
||||
|
||||
TEST(auth_settings, auth_settings)
|
||||
{
|
||||
char const settings_text[] =
|
||||
"settings:\n"
|
||||
"{\n"
|
||||
" string_value = \"some.string\"\n"
|
||||
" int_value = 42\n"
|
||||
"}\n"
|
||||
;
|
||||
config_t config;
|
||||
config_init(&config);
|
||||
int rc = config_read_string(&config, settings_text);
|
||||
ASSERT_TRUE(CONFIG_TRUE == rc);
|
||||
|
||||
config_setting_t * settings = config_lookup(&config, "settings");
|
||||
ASSERT_NE(nullptr, settings);
|
||||
|
||||
wfd_auth_settings * auth_settings = wfd_auth_settings_create("test_provider", settings);
|
||||
ASSERT_STREQ("test_provider", wfd_auth_settings_get_provider(auth_settings));
|
||||
ASSERT_STREQ("some.string", wfd_auth_settings_get(auth_settings, "string_value"));
|
||||
ASSERT_EQ(nullptr, wfd_auth_settings_get(auth_settings, "int_value"));
|
||||
ASSERT_EQ(nullptr, wfd_auth_settings_get(auth_settings, "invalid_value"));
|
||||
|
||||
wfd_auth_settings_dispose(auth_settings);
|
||||
config_destroy(&config);
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfused/config/settings_intern.h"
|
||||
#include "webfused/config/settings.h"
|
||||
#include <libconfig.h>
|
||||
|
||||
TEST(settings, settings)
|
||||
{
|
||||
char const settings_text[] =
|
||||
"settings:\n"
|
||||
"{\n"
|
||||
" string_value = \"some.string\"\n"
|
||||
" int_value = 42\n"
|
||||
"}\n"
|
||||
;
|
||||
config_t config;
|
||||
config_init(&config);
|
||||
int rc = config_read_string(&config, settings_text);
|
||||
ASSERT_TRUE(CONFIG_TRUE == rc);
|
||||
|
||||
config_setting_t * setting = config_lookup(&config, "settings");
|
||||
ASSERT_NE(nullptr, setting);
|
||||
|
||||
wfd_settings settings;
|
||||
wfd_settings_init(&settings, setting);
|
||||
ASSERT_STREQ("some.string", wfd_settings_get(&settings, "string_value"));
|
||||
ASSERT_EQ(nullptr, wfd_settings_get(&settings, "int_value"));
|
||||
ASSERT_EQ(nullptr, wfd_settings_get(&settings, "invalid_value"));
|
||||
|
||||
wfd_settings_cleanup(&settings);
|
||||
config_destroy(&config);
|
||||
}
|
Loading…
Reference in new issue