Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

registry.cpp 2.5 KB

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