summaryrefslogtreecommitdiffstats
path: root/test/bus
diff options
context:
space:
mode:
authorPatrick Williams <patrick@stwcx.xyz>2017-05-01 16:27:57 -0500
committerPatrick Williams <patrick@stwcx.xyz>2017-05-01 21:59:51 -0500
commit2f7c8875d6b20d7229abc9c00da0c28fb4c8950c (patch)
treea61efed265faa9663c0f295d078a9d8c2d62dc83 /test/bus
parent43b283a0b05bca2b14ff2bcd865752a95868491c (diff)
downloadsdbusplus-2f7c8875d6b20d7229abc9c00da0c28fb4c8950c.tar.gz
sdbusplus-2f7c8875d6b20d7229abc9c00da0c28fb4c8950c.zip
match: allow message callbacks
The original match constructor only allowed sd_bus_message_handler_t functions, which does not allow for sdbusplus::message::message's to be passed in. Add a constructor that allows functions of the following type: void(*)(sdbusplus::message::message&) Change-Id: Idc006250777c5cc1a5fe48fc411da24339ca165e Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Diffstat (limited to 'test/bus')
-rw-r--r--test/bus/match.cpp51
1 files changed, 49 insertions, 2 deletions
diff --git a/test/bus/match.cpp b/test/bus/match.cpp
index 8b58c9f..764392a 100644
--- a/test/bus/match.cpp
+++ b/test/bus/match.cpp
@@ -29,8 +29,6 @@ class Match : public ::testing::Test
TEST_F(Match, FunctorIs_sd_bus_message_handler_t)
{
- using namespace std::literals;
-
bool triggered = false;
auto trigger = [](sd_bus_message *m, void* context, sd_bus_error* e)
{
@@ -49,3 +47,52 @@ TEST_F(Match, FunctorIs_sd_bus_message_handler_t)
waitForIt(triggered);
ASSERT_TRUE(triggered);
}
+
+TEST_F(Match, FunctorIs_LambdaTakingMessage)
+{
+ bool triggered = false;
+ auto trigger = [&triggered](sdbusplus::message::message& m)
+ {
+ triggered = true;
+ };
+
+ sdbusplus::bus::match_t m{bus, matchRule, trigger};
+ auto m2 = std::move(m); // ensure match is move-safe.
+
+ waitForIt(triggered);
+ ASSERT_FALSE(triggered);
+
+ bus.request_name(busName);
+
+ waitForIt(triggered);
+ ASSERT_TRUE(triggered);
+}
+
+TEST_F(Match, FunctorIs_MemberFunctionTakingMessage)
+{
+
+ class BoolHolder
+ {
+ public:
+ bool triggered = false;
+
+ void callback(sdbusplus::message::message& m)
+ {
+ triggered = true;
+ }
+ };
+ BoolHolder b;
+
+ sdbusplus::bus::match_t m{bus, matchRule,
+ std::bind(std::mem_fn(&BoolHolder::callback),
+ &b, std::placeholders::_1)};
+ auto m2 = std::move(m); // ensure match is move-safe.
+
+ waitForIt(b.triggered);
+ ASSERT_FALSE(b.triggered);
+
+ bus.request_name(busName);
+
+ waitForIt(b.triggered);
+ ASSERT_TRUE(b.triggered);
+}
OpenPOWER on IntegriCloud