mirror of
https://github.com/LizardByte/Sunshine.git
synced 2024-11-16 23:10:13 +00:00
45 lines
1.1 KiB
C++
45 lines
1.1 KiB
C++
/**
|
|
* @file tests/unit/test_logging.cpp
|
|
* @brief Test src/logging.*.
|
|
*/
|
|
#include <src/logging.h>
|
|
|
|
#include "../tests_common.h"
|
|
#include "../tests_log_checker.h"
|
|
|
|
#include <random>
|
|
|
|
namespace {
|
|
std::array log_levels = {
|
|
std::tuple("verbose", &verbose),
|
|
std::tuple("debug", &debug),
|
|
std::tuple("info", &info),
|
|
std::tuple("warning", &warning),
|
|
std::tuple("error", &error),
|
|
std::tuple("fatal", &fatal),
|
|
};
|
|
|
|
constexpr auto log_file = "test_sunshine.log";
|
|
} // namespace
|
|
|
|
struct LogLevelsTest: testing::TestWithParam<decltype(log_levels)::value_type> {};
|
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
|
Logging,
|
|
LogLevelsTest,
|
|
testing::ValuesIn(log_levels),
|
|
[](const auto &info) { return std::string(std::get<0>(info.param)); });
|
|
|
|
TEST_P(LogLevelsTest, PutMessage) {
|
|
auto [label, plogger] = GetParam();
|
|
ASSERT_TRUE(plogger);
|
|
auto &logger = *plogger;
|
|
|
|
std::random_device rand_dev;
|
|
std::mt19937_64 rand_gen(rand_dev());
|
|
auto test_message = std::to_string(rand_gen()) + std::to_string(rand_gen());
|
|
BOOST_LOG(logger) << test_message;
|
|
|
|
ASSERT_TRUE(log_checker::line_contains(log_file, test_message));
|
|
}
|