2020-03-20 14:10:58 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2020-11-13 18:29:03 +00:00
|
|
|
#include "webfused/config/config.h"
|
2020-03-20 14:10:58 +00:00
|
|
|
#include "webfused/config/factory.h"
|
|
|
|
#include "webfused/log/logger.h"
|
|
|
|
#include "webfused/log/log.h"
|
|
|
|
#include "mock/logger.hpp"
|
|
|
|
#include "mock/config_builder.hpp"
|
|
|
|
#include "mock/libconfig.hpp"
|
|
|
|
|
|
|
|
using ::testing::_;
|
|
|
|
using ::testing::Return;
|
|
|
|
using ::testing::StrictMock;
|
|
|
|
using ::testing::StrEq;
|
|
|
|
using ::webfused_test::MockLogger;
|
|
|
|
using ::webfused_test::MockConfigBuilder;
|
|
|
|
using ::webfused_test::MockLibConfig;
|
|
|
|
|
|
|
|
TEST(configfile_log, set_logger)
|
|
|
|
{
|
|
|
|
MockLogger logger;
|
|
|
|
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
|
|
|
EXPECT_CALL(logger, onclose()).Times(1);
|
|
|
|
|
|
|
|
StrictMock<MockConfigBuilder> builder;
|
|
|
|
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
2020-11-13 18:29:03 +00:00
|
|
|
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(1).WillOnce(Return(true));
|
2020-03-20 14:10:58 +00:00
|
|
|
|
2020-11-13 18:29:03 +00:00
|
|
|
char const config_text[] =
|
|
|
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
2020-03-20 14:10:58 +00:00
|
|
|
"log:\n"
|
|
|
|
"{\n"
|
|
|
|
" provider = \"stderr\"\n"
|
|
|
|
" level = \"all\"\n"
|
|
|
|
"}\n"
|
|
|
|
;
|
|
|
|
struct wfd_config * config = wfd_config_load_string(config_text);
|
|
|
|
ASSERT_NE(nullptr, config);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(configfile_log, log_fail_set_logger)
|
|
|
|
{
|
|
|
|
MockLogger logger;
|
|
|
|
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
|
|
|
EXPECT_CALL(logger, onclose()).Times(1);
|
|
|
|
|
|
|
|
StrictMock<MockConfigBuilder> builder;
|
|
|
|
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
|
|
|
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
2020-11-13 18:29:03 +00:00
|
|
|
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(1).WillOnce(Return(false));
|
2020-03-20 14:10:58 +00:00
|
|
|
|
2020-11-13 18:29:03 +00:00
|
|
|
char const config_text[] =
|
|
|
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
2020-03-20 14:10:58 +00:00
|
|
|
"log:\n"
|
|
|
|
"{\n"
|
|
|
|
" provider = \"stderr\"\n"
|
|
|
|
" level = \"all\"\n"
|
|
|
|
"}\n"
|
|
|
|
;
|
|
|
|
struct wfd_config * config = wfd_config_load_string(config_text);
|
|
|
|
ASSERT_EQ(nullptr, config);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(configfile_log, log_fail_missing_provider)
|
|
|
|
{
|
|
|
|
MockLogger logger;
|
|
|
|
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
|
|
|
EXPECT_CALL(logger, onclose()).Times(1);
|
|
|
|
|
|
|
|
StrictMock<MockConfigBuilder> builder;
|
|
|
|
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
|
|
|
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
|
|
|
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(0);
|
|
|
|
|
2020-11-13 18:29:03 +00:00
|
|
|
char const config_text[] =
|
|
|
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
2020-03-20 14:10:58 +00:00
|
|
|
"log:\n"
|
|
|
|
"{\n"
|
|
|
|
" level = \"all\"\n"
|
|
|
|
"}\n"
|
|
|
|
;
|
|
|
|
struct wfd_config * config = wfd_config_load_string(config_text);
|
|
|
|
ASSERT_EQ(nullptr, config);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(configfile_log, log_fail_missing_level)
|
|
|
|
{
|
|
|
|
MockLogger logger;
|
|
|
|
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
|
|
|
EXPECT_CALL(logger, onclose()).Times(1);
|
|
|
|
|
|
|
|
StrictMock<MockConfigBuilder> builder;
|
|
|
|
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
|
|
|
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
|
|
|
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(0);
|
|
|
|
|
2020-11-13 18:29:03 +00:00
|
|
|
char const config_text[] =
|
|
|
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
2020-03-20 14:10:58 +00:00
|
|
|
"log:\n"
|
|
|
|
"{\n"
|
|
|
|
" provider = \"stderr\"\n"
|
|
|
|
" level = \"fancy\"\n"
|
|
|
|
"}\n"
|
|
|
|
;
|
|
|
|
struct wfd_config * config = wfd_config_load_string(config_text);
|
|
|
|
ASSERT_EQ(nullptr, config);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(configfile_log, log_fail_invalid_level)
|
|
|
|
{
|
|
|
|
MockLogger logger;
|
|
|
|
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
|
|
|
EXPECT_CALL(logger, onclose()).Times(1);
|
|
|
|
|
|
|
|
StrictMock<MockConfigBuilder> builder;
|
|
|
|
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
|
|
|
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
|
|
|
EXPECT_CALL(builder, wfd_config_set_logger(_, _, _, _)).Times(0);
|
|
|
|
|
2020-11-13 18:29:03 +00:00
|
|
|
char const config_text[] =
|
|
|
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
2020-03-20 14:10:58 +00:00
|
|
|
"log:\n"
|
|
|
|
"{\n"
|
|
|
|
" provider = \"stderr\"\n"
|
|
|
|
"}\n"
|
|
|
|
;
|
|
|
|
struct wfd_config * config = wfd_config_load_string(config_text);
|
|
|
|
ASSERT_EQ(nullptr, config);
|
|
|
|
}
|