13b5db5bcSBenjamin Kietzman // Copyright (c) Benjamin Kietzman (github.com/bkietz)
23b5db5bcSBenjamin Kietzman //
33b5db5bcSBenjamin Kietzman // Distributed under the Boost Software License, Version 1.0. (See accompanying
43b5db5bcSBenjamin Kietzman // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
53b5db5bcSBenjamin Kietzman
6da3eeb6aSEd Tanous #include <dbus/connection.hpp>
7da3eeb6aSEd Tanous #include <dbus/endpoint.hpp>
882a51ce2SEd Tanous #include <dbus/error.hpp>
9da3eeb6aSEd Tanous #include <dbus/filter.hpp>
10da3eeb6aSEd Tanous #include <dbus/match.hpp>
11da3eeb6aSEd Tanous #include <dbus/message.hpp>
12da3eeb6aSEd Tanous #include <gtest/gtest.h>
133b5db5bcSBenjamin Kietzman
TEST(MessageTest,CallMessage)14da3eeb6aSEd Tanous TEST(MessageTest, CallMessage) {
15da3eeb6aSEd Tanous const dbus::message m =
16da3eeb6aSEd Tanous dbus::message::new_call(dbus::endpoint("org.freedesktop.Avahi", "/",
1716d80fe9SBenjamin Kietzman "org.freedesktop.Avahi.Server"),
183b5db5bcSBenjamin Kietzman "GetHostName");
193b5db5bcSBenjamin Kietzman
203b5db5bcSBenjamin Kietzman ASSERT_EQ("org.freedesktop.Avahi", m.get_destination());
213b5db5bcSBenjamin Kietzman ASSERT_EQ("/", m.get_path());
223b5db5bcSBenjamin Kietzman ASSERT_EQ("org.freedesktop.Avahi.Server", m.get_interface());
233b5db5bcSBenjamin Kietzman ASSERT_EQ("GetHostName", m.get_member());
243b5db5bcSBenjamin Kietzman
25da3eeb6aSEd Tanous dbus::message m2 =
26da3eeb6aSEd Tanous dbus::message::new_call(dbus::endpoint("org.freedesktop.Avahi", "/",
2744d24258SBenjamin Kietzman "org.freedesktop.Avahi.Server"),
2844d24258SBenjamin Kietzman "GetHostName");
2944d24258SBenjamin Kietzman
30*a04118e8SEd Tanous m2.pack(1);
3144d24258SBenjamin Kietzman int i;
32*a04118e8SEd Tanous m2.unpack(i);
3344d24258SBenjamin Kietzman ASSERT_EQ(i, 1);
3444d24258SBenjamin Kietzman
353b5db5bcSBenjamin Kietzman // m.get_sender();
363b5db5bcSBenjamin Kietzman }
374317e4d9SBenjamin Kietzman
TEST(MessageTest,Misc)3882a51ce2SEd Tanous TEST(MessageTest, Misc) {
3982a51ce2SEd Tanous auto signal_name = std::string("PropertiesChanged");
4082a51ce2SEd Tanous dbus::endpoint test_endpoint(
4182a51ce2SEd Tanous "org.freedesktop.Avahi",
4282a51ce2SEd Tanous "/xyz/openbmc_project/sensors/temperature/LR_Brd_Temp",
4382a51ce2SEd Tanous "org.freedesktop.DBus.Properties");
4482a51ce2SEd Tanous auto m = dbus::message::new_signal(test_endpoint, signal_name);
4582a51ce2SEd Tanous
4682a51ce2SEd Tanous dbus::dbus_variant v(std::string("hello world"));
4782a51ce2SEd Tanous m.pack(v);
4882a51ce2SEd Tanous
4982a51ce2SEd Tanous std::vector<dbus::dbus_variant> av{{std::string("hello world"), 1, 42}};
500d6f56d2SEd Tanous m.pack(v, av);
510d6f56d2SEd Tanous
52377e76abSEd Tanous double foo = 1.0;
53377e76abSEd Tanous m.pack(foo, foo, foo);
54377e76abSEd Tanous }
550d6f56d2SEd Tanous
TEST(MessageTest,VariadicCallback)560d6f56d2SEd Tanous TEST(MessageTest, VariadicCallback) {
570d6f56d2SEd Tanous auto signal_name = std::string("PropertiesChanged");
580d6f56d2SEd Tanous dbus::endpoint test_endpoint(
590d6f56d2SEd Tanous "org.freedesktop.Avahi",
600d6f56d2SEd Tanous "/xyz/openbmc_project/sensors/temperature/LR_Brd_Temp",
610d6f56d2SEd Tanous "org.freedesktop.DBus.Properties");
620d6f56d2SEd Tanous auto m = dbus::message::new_signal(test_endpoint, signal_name);
630d6f56d2SEd Tanous
640d6f56d2SEd Tanous dbus::dbus_variant v(std::string("hello world"));
650d6f56d2SEd Tanous std::vector<dbus::dbus_variant> av{{std::string("hello world"), 1, 42}};
660d6f56d2SEd Tanous m.pack(v, av);
6782a51ce2SEd Tanous }
6882a51ce2SEd Tanous
694317e4d9SBenjamin Kietzman // I actually don't know what to do with these yet.
704317e4d9SBenjamin Kietzman /*
71da3eeb6aSEd Tanous TEST(MessageTest, ErrorMessage)
724317e4d9SBenjamin Kietzman {
734317e4d9SBenjamin Kietzman
74da3eeb6aSEd Tanous dbus::message m = dbus::message::new_call(
75da3eeb6aSEd Tanous dbus::endpoint(
764317e4d9SBenjamin Kietzman "org.freedesktop.Avahi",
774317e4d9SBenjamin Kietzman "/",
784317e4d9SBenjamin Kietzman "org.freedesktop.Avahi.Server"),
794317e4d9SBenjamin Kietzman "GetHostName");
804317e4d9SBenjamin Kietzman
814317e4d9SBenjamin Kietzman m.set_reply_serial(42);
824317e4d9SBenjamin Kietzman m.set_serial(43);
834317e4d9SBenjamin Kietzman
84da3eeb6aSEd Tanous dbus::message em = dbus::message::new_error(
854317e4d9SBenjamin Kietzman m,
864317e4d9SBenjamin Kietzman "com.skizizo.NoHostname",
874317e4d9SBenjamin Kietzman "No hostname for you!");
884317e4d9SBenjamin Kietzman
894317e4d9SBenjamin Kietzman const error e(em);
904317e4d9SBenjamin Kietzman
914317e4d9SBenjamin Kietzman e.throw_if_set();
924317e4d9SBenjamin Kietzman }
934317e4d9SBenjamin Kietzman */
94