xref: /openbmc/sdbusplus/test/message/types.cpp (revision f7509067)
1 #include <gtest/gtest.h>
2 #include <sdbusplus/message/types.hpp>
3 #include <sdbusplus/utility/tuple_to_array.hpp>
4 
5 template <typename... Args> auto dbus_string(Args&&... args)
6 {
7     return std::string(sdbusplus::utility::tuple_to_array(
8                            sdbusplus::message::types::type_id<Args...>())
9                            .data());
10 }
11 
12 TEST(MessageTypes, Integer)
13 {
14     ASSERT_EQ(dbus_string(1), "i");
15 }
16 
17 TEST(MessageTypes, Double)
18 {
19     ASSERT_EQ(dbus_string(1.0), "d");
20 }
21 
22 TEST(MessageTypes, MultipleParameter)
23 {
24     ASSERT_EQ(dbus_string(false, true), "bb");
25     ASSERT_EQ(dbus_string(1, 2, 3, true, 1.0), "iiibd");
26 }
27 
28 TEST(MessageTypes, StringReferences)
29 {
30     std::string a = "a";
31     std::string b = "b";
32     const char* c = "c";
33 
34     ASSERT_EQ(dbus_string(a, std::move(b), c), "sss");
35 }
36 
37 TEST(MessageTypes, ObjectPath)
38 {
39     ASSERT_EQ(dbus_string(sdbusplus::message::object_path("/asdf")), "o");
40 }
41 
42 TEST(MessageTypes, Signature)
43 {
44     ASSERT_EQ(dbus_string(sdbusplus::message::signature("sss")), "g");
45 }
46