@@ -24,19 +24,39 @@ using msg_defn = message<"msg", id_field, field1, field2, field3>;
2424
2525constexpr auto id_match = msg::equal_to<id_field, 0x80 >;
2626
27+ constexpr struct custom_match_t {
28+ using is_matcher = void ;
29+
30+ [[nodiscard]] constexpr auto operator ()(msg::owning<msg_defn>) const {
31+ return true ;
32+ }
33+
34+ [[nodiscard]] constexpr static auto describe () { return " custom" _sc; }
35+
36+ [[nodiscard]] constexpr static auto describe_match (msg::owning<msg_defn>) {
37+ return describe ();
38+ }
39+ } custom_match;
40+
2741std::string log_buffer{};
2842} // namespace
2943
3044template <>
3145inline auto logging::config<> =
3246 logging::fmt::config{std::back_inserter (log_buffer)};
3347
34- TEST_CASE (" callback matches message" , " [callback]" ) {
48+ TEST_CASE (" callback matches message by view " , " [callback]" ) {
3549 auto callback = msg::callback<" cb" , msg_defn>(id_match, [] {});
3650 auto const msg_match = std::array{0x8000ba11u , 0x0042d00du };
3751 CHECK (callback.is_match (msg_match));
3852}
3953
54+ TEST_CASE (" callback matches message by owning" , " [callback]" ) {
55+ auto callback = msg::callback<" cb" , msg_defn>(custom_match, [] {});
56+ auto const msg_match = std::array{0x8000ba11u , 0x0042d00du };
57+ CHECK (callback.is_match (msg_match));
58+ }
59+
4060TEST_CASE (" callback matches message (alternative range)" , " [callback]" ) {
4161 auto callback = msg::callback<" cb" , msg_defn>(id_match, [] {});
4262 auto const msg_match = std::array<std::uint8_t , 8 >{0x11 , 0xba , 0x00 , 0x80 ,
@@ -50,7 +70,7 @@ TEST_CASE("callback matches message (typed message)", "[callback]") {
5070 CHECK (callback.is_match (msg_match));
5171}
5272
53- TEST_CASE (" callback logs mismatch (raw)" , " [callback]" ) {
73+ TEST_CASE (" callback logs mismatch by view (raw)" , " [callback]" ) {
5474 auto callback = msg::callback<" cb" , msg_defn>(id_match, [] {});
5575 auto const msg_nomatch = std::array{0x8100ba11u , 0x0042d00du };
5676 CHECK (not callback.is_match (msg_nomatch));
@@ -61,6 +81,16 @@ TEST_CASE("callback logs mismatch (raw)", "[callback]") {
6181 CHECK (log_buffer.find (" cb - F:(id (0x81) == 0x80)" ) != std::string::npos);
6282}
6383
84+ TEST_CASE (" callback logs mismatch by owning (raw)" , " [callback]" ) {
85+ auto callback = msg::callback<" cb" , msg_defn>(custom_match, [] {});
86+ auto const msg_nomatch = std::array{0x8100ba11u , 0x0042d00du };
87+
88+ log_buffer.clear ();
89+ callback.log_mismatch (msg_nomatch);
90+ CAPTURE (log_buffer);
91+ CHECK (log_buffer.find (" cb - F:(custom)" ) != std::string::npos);
92+ }
93+
6494TEST_CASE (" callback logs mismatch (typed)" , " [callback]" ) {
6595 auto callback = msg::callback<" cb" , msg_defn>(id_match, [] {});
6696 auto const msg_nomatch = msg::owning<msg_defn>{" id" _field = 0x81 };
@@ -72,7 +102,7 @@ TEST_CASE("callback logs mismatch (typed)", "[callback]") {
72102 CHECK (log_buffer.find (" cb - F:(id (0x81) == 0x80)" ) != std::string::npos);
73103}
74104
75- TEST_CASE (" callback handles message (raw)" , " [callback]" ) {
105+ TEST_CASE (" callback handles message by view (raw)" , " [callback]" ) {
76106 auto callback = msg::callback<" cb" , msg_defn>(
77107 id_match, [](msg::const_view<msg_defn>) { dispatched = true ; });
78108 auto const msg_match = std::array{0x8000ba11u , 0x0042d00du };
@@ -82,6 +112,16 @@ TEST_CASE("callback handles message (raw)", "[callback]") {
82112 CHECK (dispatched);
83113}
84114
115+ TEST_CASE (" callback handles message by owning (raw)" , " [callback]" ) {
116+ auto callback = msg::callback<" cb" , msg_defn>(
117+ id_match, [](msg::owning<msg_defn>) { dispatched = true ; });
118+ auto const msg_match = std::array{0x8000ba11u , 0x0042d00du };
119+
120+ dispatched = false ;
121+ CHECK (callback.handle (msg_match));
122+ CHECK (dispatched);
123+ }
124+
85125namespace {
86126template <typename T>
87127using uint8_view =
0 commit comments