2020-03-08 18:45:49 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
|
|
|
|
#include "webfused/log/logger.h"
|
|
|
|
#include "webfused/log/log.h"
|
2020-03-08 19:29:08 +00:00
|
|
|
#include "mock_logger.hpp"
|
2020-03-08 18:45:49 +00:00
|
|
|
|
|
|
|
using ::testing::_;
|
|
|
|
using ::testing::StrEq;
|
2020-03-08 19:29:08 +00:00
|
|
|
using ::webfused_test::MockLogger;
|
2020-03-08 18:45:49 +00:00
|
|
|
|
|
|
|
TEST(log, fatal)
|
|
|
|
{
|
2020-03-08 19:29:08 +00:00
|
|
|
MockLogger logger(true);
|
2020-03-08 18:45:49 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(logger, log(WFD_LOGLEVEL_FATAL, StrEq("too bad"), _)).Times(1);
|
|
|
|
EXPECT_CALL(logger, onclose()).Times(1);
|
|
|
|
|
2020-03-08 19:29:08 +00:00
|
|
|
wfd_logger_init(WFD_LOGLEVEL_ALL, &wfd_MockLogger_log, &wfd_MockLogger_onclose, logger.getUserData());
|
2020-03-08 18:45:49 +00:00
|
|
|
WFD_FATAL("too bad");
|
|
|
|
wfd_logger_close();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(log, error)
|
|
|
|
{
|
2020-03-08 19:29:08 +00:00
|
|
|
MockLogger logger(true);
|
2020-03-08 18:45:49 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, StrEq("too bad"), _)).Times(1);
|
|
|
|
EXPECT_CALL(logger, onclose()).Times(1);
|
|
|
|
|
2020-03-08 19:29:08 +00:00
|
|
|
wfd_logger_init(WFD_LOGLEVEL_ALL, &wfd_MockLogger_log, &wfd_MockLogger_onclose, logger.getUserData());
|
2020-03-08 18:45:49 +00:00
|
|
|
WFD_ERROR("too bad");
|
|
|
|
wfd_logger_close();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(log, warn)
|
|
|
|
{
|
2020-03-08 19:29:08 +00:00
|
|
|
MockLogger logger(true);
|
2020-03-08 18:45:49 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(logger, log(WFD_LOGLEVEL_WARN, StrEq("too bad"), _)).Times(1);
|
|
|
|
EXPECT_CALL(logger, onclose()).Times(1);
|
|
|
|
|
2020-03-08 19:29:08 +00:00
|
|
|
wfd_logger_init(WFD_LOGLEVEL_ALL, &wfd_MockLogger_log, &wfd_MockLogger_onclose, logger.getUserData());
|
2020-03-08 18:45:49 +00:00
|
|
|
WFD_WARN("too bad");
|
|
|
|
wfd_logger_close();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(log, info)
|
|
|
|
{
|
2020-03-08 19:29:08 +00:00
|
|
|
MockLogger logger(true);
|
2020-03-08 18:45:49 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(logger, log(WFD_LOGLEVEL_INFO, StrEq("too bad"), _)).Times(1);
|
|
|
|
EXPECT_CALL(logger, onclose()).Times(1);
|
|
|
|
|
2020-03-08 19:29:08 +00:00
|
|
|
wfd_logger_init(WFD_LOGLEVEL_ALL, &wfd_MockLogger_log, &wfd_MockLogger_onclose, logger.getUserData());
|
2020-03-08 18:45:49 +00:00
|
|
|
WFD_INFO("too bad");
|
|
|
|
wfd_logger_close();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(log, debug)
|
|
|
|
{
|
2020-03-08 19:29:08 +00:00
|
|
|
MockLogger logger(true);
|
2020-03-08 18:45:49 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(logger, log(WFD_LOGLEVEL_DEBUG, StrEq("too bad"), _)).Times(1);
|
|
|
|
EXPECT_CALL(logger, onclose()).Times(1);
|
|
|
|
|
2020-03-08 19:29:08 +00:00
|
|
|
wfd_logger_init(WFD_LOGLEVEL_ALL, &wfd_MockLogger_log, &wfd_MockLogger_onclose, logger.getUserData());
|
2020-03-08 18:45:49 +00:00
|
|
|
WFD_DEBUG("too bad");
|
|
|
|
wfd_logger_close();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(log, respect_loglevel)
|
|
|
|
{
|
2020-03-08 19:29:08 +00:00
|
|
|
MockLogger logger(true);
|
2020-03-08 18:45:49 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
|
|
|
EXPECT_CALL(logger, onclose()).Times(1);
|
|
|
|
|
2020-03-08 19:29:08 +00:00
|
|
|
wfd_logger_init(WFD_LOGLEVEL_WARN, &wfd_MockLogger_log, &wfd_MockLogger_onclose, logger.getUserData());
|
2020-03-08 18:45:49 +00:00
|
|
|
WFD_DEBUG("too bad");
|
|
|
|
wfd_logger_close();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(log, log_same_loglevel)
|
|
|
|
{
|
2020-03-08 19:29:08 +00:00
|
|
|
MockLogger logger(true);
|
2020-03-08 18:45:49 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(logger, log(WFD_LOGLEVEL_WARN, StrEq("too bad"), _)).Times(1);
|
|
|
|
EXPECT_CALL(logger, onclose()).Times(1);
|
|
|
|
|
2020-03-08 19:29:08 +00:00
|
|
|
wfd_logger_init(WFD_LOGLEVEL_WARN, &wfd_MockLogger_log, &wfd_MockLogger_onclose, logger.getUserData());
|
2020-03-08 18:45:49 +00:00
|
|
|
WFD_WARN("too bad");
|
|
|
|
wfd_logger_close();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(log, omit_onclose_if_nullptr)
|
|
|
|
{
|
2020-03-08 19:29:08 +00:00
|
|
|
MockLogger logger(true);
|
2020-03-08 18:45:49 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(logger, log(WFD_LOGLEVEL_WARN, StrEq("too bad"), _)).Times(1);
|
|
|
|
EXPECT_CALL(logger, onclose()).Times(0);
|
|
|
|
|
2020-03-08 19:29:08 +00:00
|
|
|
wfd_logger_init(WFD_LOGLEVEL_WARN, &wfd_MockLogger_log, nullptr, logger.getUserData());
|
2020-03-08 18:45:49 +00:00
|
|
|
WFD_WARN("too bad");
|
|
|
|
wfd_logger_close();
|
|
|
|
}
|
2020-03-17 12:30:13 +00:00
|
|
|
|
|
|
|
TEST(log, default_log)
|
|
|
|
{
|
|
|
|
WFD_ERROR("trigger log");
|
|
|
|
}
|