incremental
diff --git a/boost-dbus/test/avahi.cpp b/boost-dbus/test/avahi.cpp
index debbff3..8cbb82f 100644
--- a/boost-dbus/test/avahi.cpp
+++ b/boost-dbus/test/avahi.cpp
@@ -150,27 +150,114 @@
}
}
-TEST(BOOST_DBUS, ListObjects) {
+TEST(BOOST_DBUS, SingleSensorChanged) {
boost::asio::io_service io;
dbus::connection system_bus(io, dbus::bus::system);
- dbus::endpoint test_daemon("org.freedesktop.DBus", "/",
- "org.freedesktop.DBus");
+ dbus::match ma(system_bus,
+ "type='signal',path_namespace='/xyz/openbmc_project/sensors'");
+ dbus::filter f(system_bus, [](dbus::message& m) {
+ auto member = m.get_member();
+ return member == "PropertiesChanged";
+ });
- // create new service browser
- dbus::message m = dbus::message::new_call(test_daemon, "ListNames");
- auto r = system_bus.send(m);
+ // std::function<void(boost::system::error_code, dbus::message)> event_handler
+ // =
- std::vector<std::string> services;
- r.unpack(services);
- // todo(ed) find out why this needs to be static
- static std::atomic<int> dbus_count(0);
- std::cout << dbus_count << " Callers\n";
- auto names = std::make_shared<std::vector<std::string>>();
- for (auto& service : services) {
- std::string name = "/";
- query_interfaces(system_bus, service, name);
- }
+ f.async_dispatch([&](boost::system::error_code ec, dbus::message s) {
+ std::string object_name;
+ EXPECT_EQ(s.get_path(),
+ "/xyz/openbmc_project/sensors/temperature/LR_Brd_Temp");
+
+ std::vector<std::pair<std::string, dbus::dbus_variant>> values;
+ s.unpack(object_name).unpack(values);
+
+ EXPECT_EQ(object_name, "xyz.openbmc_project.Sensor.Value");
+
+ EXPECT_EQ(values.size(), 1);
+ auto expected = std::pair<std::string, dbus::dbus_variant>("Value", 42);
+ EXPECT_EQ(values[0], expected);
+
+ io.stop();
+ });
+
+ dbus::endpoint test_endpoint(
+ "org.freedesktop.Avahi",
+ "/xyz/openbmc_project/sensors/temperature/LR_Brd_Temp",
+ "org.freedesktop.DBus.Properties");
+
+ auto signal_name = std::string("PropertiesChanged");
+ auto m = dbus::message::new_signal(test_endpoint, signal_name);
+
+ m.pack("xyz.openbmc_project.Sensor.Value");
+
+ std::vector<std::pair<std::string, dbus::dbus_variant>> map2;
+
+ map2.emplace_back("Value", 42);
+
+ m.pack(map2);
+
+ auto removed = std::vector<uint32_t>();
+ m.pack(removed);
+ system_bus.async_send(m,
+ [&](boost::system::error_code ec, dbus::message s) {});
io.run();
}
+
+TEST(BOOST_DBUS, MultipleSensorChanged) {
+ boost::asio::io_service io;
+ dbus::connection system_bus(io, dbus::bus::system);
+
+ dbus::match ma(system_bus,
+ "type='signal',path_namespace='/xyz/openbmc_project/sensors'");
+ dbus::filter f(system_bus, [](dbus::message& m) {
+ auto member = m.get_member();
+ return member == "PropertiesChanged";
+ });
+
+ int count = 0;
+ f.async_dispatch([&](boost::system::error_code ec, dbus::message s) {
+ std::string object_name;
+ EXPECT_EQ(s.get_path(),
+ "/xyz/openbmc_project/sensors/temperature/LR_Brd_Temp");
+
+ std::vector<std::pair<std::string, dbus::dbus_variant>> values;
+ s.unpack(object_name).unpack(values);
+
+ EXPECT_EQ(object_name, "xyz.openbmc_project.Sensor.Value");
+
+ EXPECT_EQ(values.size(), 1);
+ auto expected = std::pair<std::string, dbus::dbus_variant>("Value", 42);
+ EXPECT_EQ(values[0], expected);
+ count++;
+ if (count == 2) {
+ io.stop();
+ }
+
+ });
+
+ dbus::endpoint test_endpoint(
+ "org.freedesktop.Avahi",
+ "/xyz/openbmc_project/sensors/temperature/LR_Brd_Temp",
+ "org.freedesktop.DBus.Properties");
+
+ auto signal_name = std::string("PropertiesChanged");
+ auto m = dbus::message::new_signal(test_endpoint, signal_name);
+
+ m.pack("xyz.openbmc_project.Sensor.Value");
+
+ std::vector<std::pair<std::string, dbus::dbus_variant>> map2;
+
+ map2.emplace_back("Value", 42);
+
+ m.pack(map2);
+
+ auto removed = std::vector<uint32_t>();
+ m.pack(removed);
+ system_bus.async_send(m,
+ [&](boost::system::error_code ec, dbus::message s) {});
+ system_bus.async_send(m,
+ [&](boost::system::error_code ec, dbus::message s) {});
+ io.run();
+}
\ No newline at end of file
diff --git a/boost-dbus/test/message.cpp b/boost-dbus/test/message.cpp
index d591f61..8c8169f 100644
--- a/boost-dbus/test/message.cpp
+++ b/boost-dbus/test/message.cpp
@@ -3,9 +3,9 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-#include <dbus/error.hpp>
#include <dbus/connection.hpp>
#include <dbus/endpoint.hpp>
+#include <dbus/error.hpp>
#include <dbus/filter.hpp>
#include <dbus/match.hpp>
#include <dbus/message.hpp>
@@ -35,6 +35,21 @@
// m.get_sender();
}
+TEST(MessageTest, Misc) {
+ auto signal_name = std::string("PropertiesChanged");
+ dbus::endpoint test_endpoint(
+ "org.freedesktop.Avahi",
+ "/xyz/openbmc_project/sensors/temperature/LR_Brd_Temp",
+ "org.freedesktop.DBus.Properties");
+ auto m = dbus::message::new_signal(test_endpoint, signal_name);
+
+ dbus::dbus_variant v(std::string("hello world"));
+ m.pack(v);
+
+ std::vector<dbus::dbus_variant> av{{std::string("hello world"), 1, 42}};
+ m.pack(av);
+}
+
// I actually don't know what to do with these yet.
/*
TEST(MessageTest, ErrorMessage)