bus: Consistently leverage mock
We have some project generating matches that are using the mock.
Previously, we never checked the return value of this function and it
allowed our match creations to silently fail. With error checking added,
this was breaking unit tests.
This change makes sure that all users of slot generating functions have
their calls properly mocked.
Change-Id: I5dab3e3ae73e8516db21c928fc39bc00d4218c82
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/bus/match.cpp b/src/bus/match.cpp
index c5b9b19..033a47f 100644
--- a/src/bus/match.cpp
+++ b/src/bus/match.cpp
@@ -7,21 +7,22 @@
namespace sdbusplus::bus::match
{
-static sd_bus_slot* makeMatch(sd_bus* bus, const char* _match,
- sd_bus_message_handler_t handler, void* context)
+static slot_t makeMatch(SdBusInterface* intf, sd_bus* bus, const char* _match,
+ sd_bus_message_handler_t handler, void* context)
{
sd_bus_slot* slot;
- int r = sd_bus_add_match(bus, &slot, _match, handler, context);
+ int r = intf->sd_bus_add_match(bus, &slot, _match, handler, context);
if (r < 0)
{
throw exception::SdBusError(-r, "sd_bus_match");
}
- return slot;
+ return slot_t{slot, intf};
}
match::match(sdbusplus::bus_t& bus, const char* _match,
sd_bus_message_handler_t handler, void* context) :
- _slot(makeMatch(get_busp(bus), _match, handler, context))
+ _slot(
+ makeMatch(bus.getInterface(), get_busp(bus), _match, handler, context))
{}
// The callback is 'noexcept' because it is called from C code (sd-bus).
@@ -36,7 +37,8 @@
match::match(sdbusplus::bus_t& bus, const char* _match, callback_t callback) :
_callback(std::make_unique<callback_t>(std::move(callback))),
- _slot(makeMatch(get_busp(bus), _match, matchCallback, _callback.get()))
+ _slot(makeMatch(bus.getInterface(), get_busp(bus), _match, matchCallback,
+ _callback.get()))
{}
} // namespace sdbusplus::bus::match