1 // Copyright (c) Benjamin Kietzman (github.com/bkietz)
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #include <dbus/connection.hpp>
7 #include <dbus/endpoint.hpp>
8 #include <dbus/error.hpp>
9 #include <dbus/filter.hpp>
10 #include <dbus/match.hpp>
11 #include <dbus/message.hpp>
12 #include <gtest/gtest.h>
13
TEST(MessageTest,CallMessage)14 TEST(MessageTest, CallMessage) {
15 const dbus::message m =
16 dbus::message::new_call(dbus::endpoint("org.freedesktop.Avahi", "/",
17 "org.freedesktop.Avahi.Server"),
18 "GetHostName");
19
20 ASSERT_EQ("org.freedesktop.Avahi", m.get_destination());
21 ASSERT_EQ("/", m.get_path());
22 ASSERT_EQ("org.freedesktop.Avahi.Server", m.get_interface());
23 ASSERT_EQ("GetHostName", m.get_member());
24
25 dbus::message m2 =
26 dbus::message::new_call(dbus::endpoint("org.freedesktop.Avahi", "/",
27 "org.freedesktop.Avahi.Server"),
28 "GetHostName");
29
30 m2.pack(1);
31 int i;
32 m2.unpack(i);
33 ASSERT_EQ(i, 1);
34
35 // m.get_sender();
36 }
37
TEST(MessageTest,Misc)38 TEST(MessageTest, Misc) {
39 auto signal_name = std::string("PropertiesChanged");
40 dbus::endpoint test_endpoint(
41 "org.freedesktop.Avahi",
42 "/xyz/openbmc_project/sensors/temperature/LR_Brd_Temp",
43 "org.freedesktop.DBus.Properties");
44 auto m = dbus::message::new_signal(test_endpoint, signal_name);
45
46 dbus::dbus_variant v(std::string("hello world"));
47 m.pack(v);
48
49 std::vector<dbus::dbus_variant> av{{std::string("hello world"), 1, 42}};
50 m.pack(v, av);
51
52 double foo = 1.0;
53 m.pack(foo, foo, foo);
54 }
55
TEST(MessageTest,VariadicCallback)56 TEST(MessageTest, VariadicCallback) {
57 auto signal_name = std::string("PropertiesChanged");
58 dbus::endpoint test_endpoint(
59 "org.freedesktop.Avahi",
60 "/xyz/openbmc_project/sensors/temperature/LR_Brd_Temp",
61 "org.freedesktop.DBus.Properties");
62 auto m = dbus::message::new_signal(test_endpoint, signal_name);
63
64 dbus::dbus_variant v(std::string("hello world"));
65 std::vector<dbus::dbus_variant> av{{std::string("hello world"), 1, 42}};
66 m.pack(v, av);
67 }
68
69 // I actually don't know what to do with these yet.
70 /*
71 TEST(MessageTest, ErrorMessage)
72 {
73
74 dbus::message m = dbus::message::new_call(
75 dbus::endpoint(
76 "org.freedesktop.Avahi",
77 "/",
78 "org.freedesktop.Avahi.Server"),
79 "GetHostName");
80
81 m.set_reply_serial(42);
82 m.set_serial(43);
83
84 dbus::message em = dbus::message::new_error(
85 m,
86 "com.skizizo.NoHostname",
87 "No hostname for you!");
88
89 const error e(em);
90
91 e.throw_if_set();
92 }
93 */
94