098-message-stringifier.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // Copyright (c) 2024 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
  3. //
  4. // Distributed under the MIT Software License
  5. //
  6. #include "rotor.hpp"
  7. #include "rotor/extended_error.h"
  8. #include "supervisor_test.h"
  9. #include <catch2/matchers/catch_matchers_string.hpp>
  10. #include <catch2/catch_test_macros.hpp>
  11. using namespace Catch::Matchers;
  12. namespace r = rotor;
  13. namespace rt = rotor::test;
  14. namespace payload {
  15. struct ping_t {};
  16. } // namespace payload
  17. namespace message {
  18. using ping_t = r::message_t<payload::ping_t>;
  19. }
  20. TEST_CASE("default message stringifier", "[misc]") {
  21. r::system_context_ptr_t system_context = new r::system_context_t();
  22. auto sup = system_context->create_supervisor<rt::supervisor_test_t>().timeout(rt::default_timeout).finish();
  23. auto &stringifer = system_context->get_stringifier();
  24. SECTION("rotor message") {
  25. auto start_message = r::make_message<r::payload::start_actor_t>(sup->get_address());
  26. auto message = stringifer.stringify(*start_message);
  27. CHECK_THAT(message, StartsWith("r::start_trigger @"));
  28. }
  29. SECTION("unknown / non-rotor message") {
  30. auto ping = r::make_message<payload::ping_t>(sup->get_address());
  31. auto message = stringifer.stringify(*ping);
  32. CHECK_THAT(message, ContainsSubstring("[?]"));
  33. CHECK_THAT(message, ContainsSubstring("rotor::message_t"));
  34. CHECK_THAT(message, ContainsSubstring("payload::ping_t"));
  35. CHECK_THAT(message, ContainsSubstring(" =>"));
  36. }
  37. SECTION("extended error") {
  38. auto ping = r::make_message<r::payload::start_actor_t>(sup->get_address());
  39. auto context = std::string("some-actor");
  40. auto ee = r::make_error(context, {}, {}, ping);
  41. auto string = ee->message(&stringifer);
  42. CHECK_THAT(string, ContainsSubstring("[r::start_trigger @"));
  43. CHECK_THAT(string, ContainsSubstring("some-actor"));
  44. }
  45. sup->do_process();
  46. sup->do_shutdown();
  47. sup->do_process();
  48. }