spdlog/tests/registry.cpp

54 lines
1.6 KiB
C++
Raw Normal View History

2015-05-15 13:30:37 -04:00
#include "includes.h"
2016-07-15 11:41:59 -04:00
static const char *tested_logger_name = "null_logger";
2015-05-15 13:30:37 -04:00
TEST_CASE("register_drop", "[registry]")
{
spdlog::drop_all();
2016-07-15 11:41:59 -04:00
spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name);
REQUIRE(spdlog::get(tested_logger_name)!=nullptr);
2015-05-15 13:30:37 -04:00
//Throw if registring existing name
2016-07-15 11:41:59 -04:00
REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name), spdlog::spdlog_ex);
2015-05-15 13:30:37 -04:00
}
TEST_CASE("explicit register" "[registry]")
{
spdlog::drop_all();
2016-07-15 11:41:59 -04:00
auto logger = std::make_shared<spdlog::logger>(tested_logger_name, std::make_shared<spdlog::sinks::null_sink_st>());
2015-05-15 13:30:37 -04:00
spdlog::register_logger(logger);
2016-07-15 11:41:59 -04:00
REQUIRE(spdlog::get(tested_logger_name) != nullptr);
2015-05-15 13:30:37 -04:00
//Throw if registring existing name
2016-07-15 11:41:59 -04:00
REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name), spdlog::spdlog_ex);
2015-05-15 13:30:37 -04:00
}
TEST_CASE("drop" "[registry]")
{
spdlog::drop_all();
2016-07-15 11:41:59 -04:00
spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name);
spdlog::drop(tested_logger_name);
REQUIRE_FALSE(spdlog::get(tested_logger_name));
2015-05-15 13:30:37 -04:00
}
TEST_CASE("drop_all" "[registry]")
{
spdlog::drop_all();
2016-07-15 11:41:59 -04:00
spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name);
2015-05-15 13:30:37 -04:00
spdlog::create<spdlog::sinks::null_sink_mt>("name2");
spdlog::drop_all();
2016-07-15 11:41:59 -04:00
REQUIRE_FALSE(spdlog::get(tested_logger_name));
2015-05-15 13:30:37 -04:00
REQUIRE_FALSE(spdlog::get("name2"));
}
TEST_CASE("drop non existing" "[registry]")
{
spdlog::drop_all();
2016-07-15 11:41:59 -04:00
spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name);
2015-05-15 13:30:37 -04:00
spdlog::drop("some_name");
REQUIRE_FALSE(spdlog::get("some_name"));
2016-07-15 11:41:59 -04:00
REQUIRE(spdlog::get(tested_logger_name));
2015-05-15 13:30:37 -04:00
spdlog::drop_all();
}