1 #include "includes.h"
2 
3 static const char *tested_logger_name = "null_logger";
4 static const char *tested_logger_name2 = "null_logger2";
5 
6 TEST_CASE("register_drop", "[registry]")
7 {
8     spdlog::drop_all();
9     spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name);
10     REQUIRE(spdlog::get(tested_logger_name)!=nullptr);
11     //Throw if registring existing name
12     REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name), spdlog::spdlog_ex);
13 }
14 
15 
16 TEST_CASE("explicit register" "[registry]")
17 {
18     spdlog::drop_all();
19     auto logger = std::make_shared<spdlog::logger>(tested_logger_name, std::make_shared<spdlog::sinks::null_sink_st>());
20     spdlog::register_logger(logger);
21     REQUIRE(spdlog::get(tested_logger_name) != nullptr);
22     //Throw if registring existing name
23     REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name), spdlog::spdlog_ex);
24 }
25 
26 TEST_CASE("apply_all" "[registry]")
27 {
28     spdlog::drop_all();
29     auto logger = std::make_shared<spdlog::logger>(tested_logger_name, std::make_shared<spdlog::sinks::null_sink_st>());
30     spdlog::register_logger(logger);
31     auto logger2 = std::make_shared<spdlog::logger>(tested_logger_name2, std::make_shared<spdlog::sinks::null_sink_st>());
32     spdlog::register_logger(logger2);
33 
34     int counter = 0;
35     spdlog::apply_all([&counter](std::shared_ptr<spdlog::logger> l)
36     {
37         counter++;
38     });
39     REQUIRE(counter == 2);
40 
41     counter = 0;
42     spdlog::drop(tested_logger_name2);
43     spdlog::apply_all([&counter](std::shared_ptr<spdlog::logger> l)
44     {
45         REQUIRE(l->name() == tested_logger_name);
46         counter++;
47     }
48                      );
49     REQUIRE(counter == 1);
50 }
51 
52 
53 
54 TEST_CASE("drop" "[registry]")
55 {
56     spdlog::drop_all();
57     spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name);
58     spdlog::drop(tested_logger_name);
59     REQUIRE_FALSE(spdlog::get(tested_logger_name));
60 }
61 
62 TEST_CASE("drop_all" "[registry]")
63 {
64     spdlog::drop_all();
65     spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name);
66     spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name2);
67     spdlog::drop_all();
68     REQUIRE_FALSE(spdlog::get(tested_logger_name));
69     REQUIRE_FALSE(spdlog::get(tested_logger_name));
70 }
71 
72 
73 TEST_CASE("drop non existing" "[registry]")
74 {
75     spdlog::drop_all();
76     spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name);
77     spdlog::drop("some_name");
78     REQUIRE_FALSE(spdlog::get("some_name"));
79     REQUIRE(spdlog::get(tested_logger_name));
80     spdlog::drop_all();
81 }
82 
83 
84 
85