lokinet/test/util/test_llarp_util_log_level.cpp

57 lines
2.1 KiB
C++
Raw Normal View History

2021-03-01 21:07:32 +00:00
#include <catch2/catch.hpp>
2020-01-21 18:21:11 +00:00
#include <util/logging/loglevel.hpp>
#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;
2021-03-01 21:07:32 +00:00
std::optional<llarp::LogLevel> level;
2020-01-21 18:35:52 +00:00
};
2021-03-01 21:07:32 +00:00
std::vector<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}};
TEST_CASE("parseLevel")
2020-01-21 18:21:11 +00:00
{
2021-03-01 21:07:32 +00:00
const auto data = GENERATE(from_range(testParseLog));
2020-01-21 18:35:52 +00:00
const auto maybe = llarp::LogLevelFromString(data.input);
2021-03-01 21:07:32 +00:00
CHECK(maybe == data.level);
2020-01-21 18:21:11 +00:00
}
2020-01-21 18:35:52 +00:00
2021-03-01 21:07:32 +00:00
TEST_CASE("TestLogLevelToName")
{
2021-03-01 21:07:32 +00:00
CHECK("Trace" == LogLevelToName(llarp::eLogTrace));
CHECK("Debug" == LogLevelToName(llarp::eLogDebug));
CHECK("Info" == LogLevelToName(llarp::eLogInfo));
CHECK("Warn" == LogLevelToName(llarp::eLogWarn));
CHECK("Error" == LogLevelToName(llarp::eLogError));
CHECK("None" == LogLevelToName(llarp::eLogNone));
CHECK("???" == LogLevelToName((llarp::LogLevel)99999));
}
2021-03-01 21:07:32 +00:00
TEST_CASE("TestLogLevelToString")
{
2021-03-01 21:07:32 +00:00
CHECK("TRC" == LogLevelToString(llarp::eLogTrace));
CHECK("DBG" == LogLevelToString(llarp::eLogDebug));
CHECK("NFO" == LogLevelToString(llarp::eLogInfo));
CHECK("WRN" == LogLevelToString(llarp::eLogWarn));
CHECK("ERR" == LogLevelToString(llarp::eLogError));
CHECK("???" == LogLevelToString(llarp::eLogNone));
}