2020-01-21 18:21:11 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <util/logging/loglevel.hpp>
|
2020-01-21 19:33:04 +00:00
|
|
|
#include <util/logging/logger.hpp>
|
|
|
|
#include <config/config.hpp>
|
2020-01-21 18:21:11 +00:00
|
|
|
|
2020-01-21 18:35:52 +00:00
|
|
|
using TestString = std::string;
|
|
|
|
|
|
|
|
struct TestParseLog
|
|
|
|
{
|
|
|
|
TestString input;
|
2020-05-01 19:51:15 +00:00
|
|
|
std::optional< llarp::LogLevel > level;
|
2020-01-21 18:35:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct LogLevelTest : public ::testing::TestWithParam< TestParseLog >
|
2020-01-21 18:21:11 +00:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2020-01-21 18:35:52 +00:00
|
|
|
TEST_P(LogLevelTest, parseLevel)
|
2020-01-21 18:21:11 +00:00
|
|
|
{
|
2020-01-21 18:35:52 +00:00
|
|
|
const auto data = GetParam();
|
|
|
|
const auto maybe = llarp::LogLevelFromString(data.input);
|
|
|
|
EXPECT_EQ(maybe, data.level);
|
2020-01-21 18:21:11 +00:00
|
|
|
}
|
2020-01-21 18:35:52 +00:00
|
|
|
|
|
|
|
static const TestParseLog testParseLog[] = {
|
|
|
|
// bad cases
|
|
|
|
{"bogus", {}},
|
|
|
|
{"BOGUS", {}},
|
|
|
|
{"", {}},
|
|
|
|
{" ", {}},
|
|
|
|
// good cases
|
|
|
|
{"info", llarp::eLogInfo},
|
|
|
|
{"infO", llarp::eLogInfo},
|
|
|
|
{"iNfO", llarp::eLogInfo},
|
|
|
|
{"InfO", llarp::eLogInfo},
|
|
|
|
{"INFO", llarp::eLogInfo},
|
|
|
|
{"debug", llarp::eLogDebug},
|
|
|
|
{"warn", llarp::eLogWarn},
|
|
|
|
{"error", llarp::eLogError},
|
|
|
|
{"none", llarp::eLogNone}};
|
|
|
|
|
2020-02-13 19:10:42 +00:00
|
|
|
INSTANTIATE_TEST_SUITE_P(TestLogConfig, LogLevelTest,
|
|
|
|
::testing::ValuesIn(testParseLog));
|
2020-01-21 19:15:04 +00:00
|
|
|
|
|
|
|
TEST_F(LogLevelTest, TestLogLevelToName)
|
|
|
|
{
|
|
|
|
EXPECT_EQ("Trace", LogLevelToName(llarp::eLogTrace));
|
|
|
|
EXPECT_EQ("Debug", LogLevelToName(llarp::eLogDebug));
|
|
|
|
EXPECT_EQ("Info", LogLevelToName(llarp::eLogInfo));
|
|
|
|
EXPECT_EQ("Warn", LogLevelToName(llarp::eLogWarn));
|
|
|
|
EXPECT_EQ("Error", LogLevelToName(llarp::eLogError));
|
|
|
|
EXPECT_EQ("None", LogLevelToName(llarp::eLogNone));
|
|
|
|
EXPECT_EQ("???", LogLevelToName( (llarp::LogLevel)99999 ));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(LogLevelTest, TestLogLevelToString)
|
|
|
|
{
|
|
|
|
EXPECT_EQ("TRC", LogLevelToString(llarp::eLogTrace));
|
|
|
|
EXPECT_EQ("DBG", LogLevelToString(llarp::eLogDebug));
|
|
|
|
EXPECT_EQ("NFO", LogLevelToString(llarp::eLogInfo));
|
|
|
|
EXPECT_EQ("WRN", LogLevelToString(llarp::eLogWarn));
|
|
|
|
EXPECT_EQ("ERR", LogLevelToString(llarp::eLogError));
|
|
|
|
EXPECT_EQ("???", LogLevelToString(llarp::eLogNone));
|
|
|
|
}
|
|
|
|
|