diff options
| author | Patrick Williams <patrick@stwcx.xyz> | 2017-04-29 15:50:13 -0500 |
|---|---|---|
| committer | Patrick Williams <patrick@stwcx.xyz> | 2017-05-01 21:59:51 -0500 |
| commit | faa89f27152b3d9727e16825eac0e90d0f588e3a (patch) | |
| tree | 676fb08e912f5cc945709668968339f0f5638d48 | |
| parent | b77868ad0f23d8cfae760f51ddc78e8280f52bd6 (diff) | |
| download | sdbusplus-faa89f27152b3d9727e16825eac0e90d0f588e3a.tar.gz sdbusplus-faa89f27152b3d9727e16825eac0e90d0f588e3a.zip | |
test: add test for bus::match
Change-Id: Ia45c659a6d88e8a688bcdc92a084a8edc7455ba8
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
| -rw-r--r-- | test/Makefile.am | 4 | ||||
| -rw-r--r-- | test/bus/match.cpp | 51 |
2 files changed, 55 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 0e66587..fb1895c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -10,6 +10,10 @@ check_PROGRAMS += bus_list_names bus_list_names_SOURCES = bus/list_names.cpp bus_list_names_LDFLAGS = $(gtest_ldflags) $(SYSTEMD_LIBS) +check_PROGRAMS += bus_match +bus_match_SOURCES = bus/match.cpp +bus_match_LDFLAGS = $(gtest_ldflags) $(SYSTEMD_LIBS) + check_PROGRAMS += message_append message_append_CXXFLAGS = $(SYSTEMD_CFLAGS) $(PTHREAD_CFLAGS) message_append_LDFLAGS = $(SYSTEMD_LIBS) $(PTHREAD_LIBS) diff --git a/test/bus/match.cpp b/test/bus/match.cpp new file mode 100644 index 0000000..8b58c9f --- /dev/null +++ b/test/bus/match.cpp @@ -0,0 +1,51 @@ +#include <gtest/gtest.h> +#include <sdbusplus/bus.hpp> +#include <sdbusplus/bus/match.hpp> + +class Match : public ::testing::Test +{ + protected: + decltype(sdbusplus::bus::new_default()) bus = + sdbusplus::bus::new_default(); + + static constexpr auto busName = + "xyz.openbmc_project.sdbusplus.test.Match"; + + static constexpr auto matchRule = + "type='signal'," + "interface=org.freedesktop.DBus," + "member='NameOwnerChanged'," + "arg0='xyz.openbmc_project.sdbusplus.test.Match'"; + + void waitForIt(bool& triggered) + { + for (size_t i = 0; (i < 16) && !triggered; ++i) + { + bus.wait(0); + bus.process_discard(); + } + } +}; + +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) + { + *static_cast<bool*>(context) = true; + return 0; + }; + + sdbusplus::bus::match_t m{bus, matchRule, trigger, &triggered}; + auto m2 = std::move(m); // ensure match is move-safe. + + waitForIt(triggered); + ASSERT_FALSE(triggered); + + bus.request_name(busName); + + waitForIt(triggered); + ASSERT_TRUE(triggered); +} |

