Skip to content

Commit b2266ad

Browse files
committed
✅ Add tests for msg handlers calling multiple callbacks
Problem: - When multiple callbacks match a message, they should all be called. There was no test binding this behaviour for either the "normal" handler or the indexed handler. Solution: - Add tests that bind the behaviour.
1 parent 68fe0a2 commit b2266ad

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

test/msg/handler_builder.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,27 @@ TEST_CASE("handle extra arguments", "[handler_builder]") {
143143
CHECK(callback_success);
144144
CHECK(callback_extra_arg == 42);
145145
}
146+
147+
namespace {
148+
bool callback2_success;
149+
150+
constexpr auto test_callback2 = msg::callback<"cb2", msg_defn>(
151+
id_match, [](msg_view_t) { callback2_success = true; });
152+
153+
struct test_project_multi_cb {
154+
constexpr static auto config =
155+
cib::config(cib::exports<test_service>,
156+
cib::extend<test_service>(test_callback, test_callback2));
157+
};
158+
} // namespace
159+
160+
TEST_CASE("call multiple callbacks", "[handler_builder]") {
161+
cib::nexus<test_project_multi_cb> test_nexus{};
162+
test_nexus.init();
163+
164+
callback_success = false;
165+
callback2_success = false;
166+
cib::service<test_service>->handle(test_msg_t{"id"_field = 0x80});
167+
CHECK(callback_success);
168+
CHECK(callback2_success);
169+
}

test/msg/indexed_builder.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,3 +490,28 @@ TEST_CASE("handle raw message by mixture of callbacks", "[indexed_builder]") {
490490
std::array{0x8000ba11u, 0x0042d00du}));
491491
CHECK(callback_count == 2);
492492
}
493+
494+
namespace {
495+
bool callback2_success;
496+
497+
constexpr auto test_callback2 = msg::callback<"TestCallback2", msg_defn>(
498+
msg::in<test_id_field, 0x80>, [](auto) { callback2_success = true; });
499+
500+
struct test_project_multi_cb {
501+
constexpr static auto config =
502+
cib::config(cib::exports<test_service>,
503+
cib::extend<test_service>(test_callback, test_callback2));
504+
};
505+
} // namespace
506+
507+
TEST_CASE("call multiple callbacks", "[handler_builder]") {
508+
cib::nexus<test_project_multi_cb> test_nexus{};
509+
test_nexus.init();
510+
511+
callback_success = false;
512+
callback2_success = false;
513+
cib::service<test_service>->handle(
514+
test_msg_t{"test_id_field"_field = 0x80});
515+
CHECK(callback_success);
516+
CHECK(callback2_success);
517+
}

0 commit comments

Comments
 (0)