| 
									
										
										
										
											2015-05-15 20:30:37 +03:00
										 |  |  | #include "includes.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-15 18:41:59 +03:00
										 |  |  | static const char *tested_logger_name = "null_logger"; | 
					
						
							| 
									
										
										
										
											2016-08-20 13:51:07 +03:00
										 |  |  | static const char *tested_logger_name2 = "null_logger2"; | 
					
						
							| 
									
										
										
										
											2015-05-15 20:30:37 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | TEST_CASE("register_drop", "[registry]") | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     spdlog::drop_all(); | 
					
						
							| 
									
										
										
										
											2016-07-15 18:41:59 +03:00
										 |  |  |     spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name); | 
					
						
							| 
									
										
										
										
											2018-03-09 15:26:33 +02:00
										 |  |  |     REQUIRE(spdlog::get(tested_logger_name) != nullptr); | 
					
						
							|  |  |  |     // Throw if registring existing name
 | 
					
						
							| 
									
										
										
										
											2018-08-17 00:32:13 +03:00
										 |  |  |     REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name), const spdlog::spdlog_ex &); | 
					
						
							| 
									
										
										
										
											2015-05-15 20:30:37 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-12 03:04:55 +03:00
										 |  |  | TEST_CASE("explicit register", "[registry]") | 
					
						
							| 
									
										
										
										
											2015-05-15 20:30:37 +03:00
										 |  |  | { | 
					
						
							|  |  |  |     spdlog::drop_all(); | 
					
						
							| 
									
										
										
										
											2016-07-15 18:41:59 +03:00
										 |  |  |     auto logger = std::make_shared<spdlog::logger>(tested_logger_name, std::make_shared<spdlog::sinks::null_sink_st>()); | 
					
						
							| 
									
										
										
										
											2015-05-15 20:30:37 +03:00
										 |  |  |     spdlog::register_logger(logger); | 
					
						
							| 
									
										
										
										
											2016-07-15 18:41:59 +03:00
										 |  |  |     REQUIRE(spdlog::get(tested_logger_name) != nullptr); | 
					
						
							| 
									
										
										
										
											2018-03-09 15:26:33 +02:00
										 |  |  |     // Throw if registring existing name
 | 
					
						
							| 
									
										
										
										
											2018-08-17 00:32:13 +03:00
										 |  |  |     REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name), const spdlog::spdlog_ex &); | 
					
						
							| 
									
										
										
										
											2015-05-15 20:30:37 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-12 03:04:55 +03:00
										 |  |  | TEST_CASE("apply_all", "[registry]") | 
					
						
							| 
									
										
										
										
											2016-08-20 13:51:07 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-08-20 13:55:50 +03:00
										 |  |  |     spdlog::drop_all(); | 
					
						
							|  |  |  |     auto logger = std::make_shared<spdlog::logger>(tested_logger_name, std::make_shared<spdlog::sinks::null_sink_st>()); | 
					
						
							|  |  |  |     spdlog::register_logger(logger); | 
					
						
							|  |  |  |     auto logger2 = std::make_shared<spdlog::logger>(tested_logger_name2, std::make_shared<spdlog::sinks::null_sink_st>()); | 
					
						
							|  |  |  |     spdlog::register_logger(logger2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     int counter = 0; | 
					
						
							| 
									
										
										
										
											2018-08-13 12:27:25 +03:00
										 |  |  |     spdlog::apply_all([&counter](std::shared_ptr<spdlog::logger>) { counter++; }); | 
					
						
							| 
									
										
										
										
											2016-08-20 13:55:50 +03:00
										 |  |  |     REQUIRE(counter == 2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     counter = 0; | 
					
						
							|  |  |  |     spdlog::drop(tested_logger_name2); | 
					
						
							| 
									
										
										
										
											2018-03-09 15:26:33 +02:00
										 |  |  |     spdlog::apply_all([&counter](std::shared_ptr<spdlog::logger> l) { | 
					
						
							| 
									
										
										
										
											2016-08-20 13:55:50 +03:00
										 |  |  |         REQUIRE(l->name() == tested_logger_name); | 
					
						
							|  |  |  |         counter++; | 
					
						
							| 
									
										
										
										
											2018-03-09 15:26:33 +02:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2016-08-20 13:55:50 +03:00
										 |  |  |     REQUIRE(counter == 1); | 
					
						
							| 
									
										
										
										
											2016-08-20 13:51:07 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-12 03:04:55 +03:00
										 |  |  | TEST_CASE("drop", "[registry]") | 
					
						
							| 
									
										
										
										
											2015-05-15 20:30:37 +03:00
										 |  |  | { | 
					
						
							|  |  |  |     spdlog::drop_all(); | 
					
						
							| 
									
										
										
										
											2016-07-15 18:41:59 +03: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 20:30:37 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-13 19:23:11 +03:00
										 |  |  | TEST_CASE("drop-default", "[registry]") | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     spdlog::set_default_logger(spdlog::null_logger_st(tested_logger_name)); | 
					
						
							|  |  |  |     spdlog::drop(tested_logger_name); | 
					
						
							|  |  |  |     REQUIRE_FALSE(spdlog::default_logger()); | 
					
						
							|  |  |  |     REQUIRE_FALSE(spdlog::get(tested_logger_name)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-12 03:04:55 +03:00
										 |  |  | TEST_CASE("drop_all", "[registry]") | 
					
						
							| 
									
										
										
										
											2015-05-15 20:30:37 +03:00
										 |  |  | { | 
					
						
							|  |  |  |     spdlog::drop_all(); | 
					
						
							| 
									
										
										
										
											2016-07-15 18:41:59 +03:00
										 |  |  |     spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name); | 
					
						
							| 
									
										
										
										
											2016-08-20 13:51:07 +03:00
										 |  |  |     spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name2); | 
					
						
							| 
									
										
										
										
											2015-05-15 20:30:37 +03:00
										 |  |  |     spdlog::drop_all(); | 
					
						
							| 
									
										
										
										
											2016-07-15 18:41:59 +03:00
										 |  |  |     REQUIRE_FALSE(spdlog::get(tested_logger_name)); | 
					
						
							| 
									
										
										
										
											2018-08-16 17:53:55 +02:00
										 |  |  |     REQUIRE_FALSE(spdlog::get(tested_logger_name2)); | 
					
						
							| 
									
										
										
										
											2018-10-13 19:23:11 +03:00
										 |  |  |     REQUIRE_FALSE(spdlog::default_logger()); | 
					
						
							| 
									
										
										
										
											2015-05-15 20:30:37 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-12 03:04:55 +03:00
										 |  |  | TEST_CASE("drop non existing", "[registry]") | 
					
						
							| 
									
										
										
										
											2015-05-15 20:30:37 +03:00
										 |  |  | { | 
					
						
							|  |  |  |     spdlog::drop_all(); | 
					
						
							| 
									
										
										
										
											2016-07-15 18:41:59 +03:00
										 |  |  |     spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name); | 
					
						
							| 
									
										
										
										
											2015-05-15 20:30:37 +03:00
										 |  |  |     spdlog::drop("some_name"); | 
					
						
							|  |  |  |     REQUIRE_FALSE(spdlog::get("some_name")); | 
					
						
							| 
									
										
										
										
											2016-07-15 18:41:59 +03:00
										 |  |  |     REQUIRE(spdlog::get(tested_logger_name)); | 
					
						
							| 
									
										
										
										
											2015-05-15 20:30:37 +03:00
										 |  |  |     spdlog::drop_all(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-10-12 03:04:55 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | TEST_CASE("default logger", "[registry]") | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     spdlog::drop_all(); | 
					
						
							| 
									
										
										
										
											2019-01-08 17:33:31 +02:00
										 |  |  |     spdlog::set_default_logger(spdlog::null_logger_st(tested_logger_name)); | 
					
						
							| 
									
										
										
										
											2018-10-13 19:23:11 +03:00
										 |  |  |     REQUIRE(spdlog::get(tested_logger_name) == spdlog::default_logger()); | 
					
						
							| 
									
										
										
										
											2018-10-12 03:04:55 +03:00
										 |  |  |     spdlog::drop_all(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-10-13 19:23:11 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | TEST_CASE("set_default_logger(nullptr)", "[registry]") | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     spdlog::set_default_logger(nullptr); | 
					
						
							|  |  |  |     REQUIRE_FALSE(spdlog::default_logger()); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-11-10 14:34:04 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | TEST_CASE("disable automatic registration", "[registry]") | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // set some global parameters
 | 
					
						
							|  |  |  |     spdlog::level::level_enum log_level = spdlog::level::level_enum::warn; | 
					
						
							|  |  |  |     spdlog::set_level(log_level); | 
					
						
							|  |  |  |     // but disable automatic registration
 | 
					
						
							|  |  |  |     spdlog::set_automatic_registration(false); | 
					
						
							|  |  |  |     auto logger1 = spdlog::create<spdlog::sinks::daily_file_sink_st>(tested_logger_name, "filename", 11, 59); | 
					
						
							|  |  |  |     auto logger2 = spdlog::create_async<spdlog::sinks::stdout_color_sink_mt>(tested_logger_name2); | 
					
						
							|  |  |  |     // loggers should not be part of the registry
 | 
					
						
							|  |  |  |     REQUIRE_FALSE(spdlog::get(tested_logger_name)); | 
					
						
							|  |  |  |     REQUIRE_FALSE(spdlog::get(tested_logger_name2)); | 
					
						
							|  |  |  |     // but make sure they are still initialized according to global defaults
 | 
					
						
							|  |  |  |     REQUIRE(logger1->level() == log_level); | 
					
						
							|  |  |  |     REQUIRE(logger2->level() == log_level); | 
					
						
							| 
									
										
										
										
											2018-11-11 01:25:17 +02:00
										 |  |  |     spdlog::set_level(spdlog::level::info); | 
					
						
							| 
									
										
										
										
											2018-12-02 19:04:44 +02:00
										 |  |  |     spdlog::set_automatic_registration(true); | 
					
						
							| 
									
										
										
										
											2018-11-10 14:34:04 +01:00
										 |  |  | } |