1 #include <sdbusplus/message/types.hpp> 2 #include <sdbusplus/utility/tuple_to_array.hpp> 3 4 #include <gtest/gtest.h> 5 6 template <typename... Args> 7 auto dbus_string(Args&&... /*args*/) 8 { 9 return std::string(sdbusplus::utility::tuple_to_array( 10 sdbusplus::message::types::type_id<Args...>()) 11 .data()); 12 } 13 14 TEST(MessageTypes, Integer) 15 { 16 ASSERT_EQ(dbus_string(1), "i"); 17 } 18 19 TEST(MessageTypes, Double) 20 { 21 ASSERT_EQ(dbus_string(1.0), "d"); 22 } 23 24 TEST(MessageTypes, MultipleParameter) 25 { 26 ASSERT_EQ(dbus_string(false, true), "bb"); 27 ASSERT_EQ(dbus_string(1, 2, 3, true, 1.0), "iiibd"); 28 } 29 30 TEST(MessageTypes, StringReferences) 31 { 32 std::string a = "a"; 33 std::string b = "b"; 34 const char* c = "c"; 35 36 ASSERT_EQ(dbus_string(a, std::move(b), c), "sss"); 37 } 38 39 TEST(MessageTypes, ObjectPath) 40 { 41 ASSERT_EQ(dbus_string(sdbusplus::message::object_path("/asdf")), "o"); 42 } 43 44 TEST(MessageTypes, ObjectPathLeaf) 45 { 46 ASSERT_EQ(sdbusplus::message::object_path("/abc/def").filename(), "def"); 47 ASSERT_EQ(sdbusplus::message::object_path("/abc/").filename(), ""); 48 ASSERT_EQ(sdbusplus::message::object_path("/abc").filename(), "abc"); 49 ASSERT_EQ(sdbusplus::message::object_path("/").filename(), ""); 50 ASSERT_EQ(sdbusplus::message::object_path("").filename(), ""); 51 ASSERT_EQ(sdbusplus::message::object_path("abc").filename(), ""); 52 } 53 54 TEST(MessageTypes, ObjectPathParent) 55 { 56 ASSERT_EQ(sdbusplus::message::object_path("/abc/def").parent_path(), 57 sdbusplus::message::object_path("/abc")); 58 ASSERT_EQ(sdbusplus::message::object_path("/abc/").parent_path(), 59 sdbusplus::message::object_path("/abc")); 60 ASSERT_EQ(sdbusplus::message::object_path("/abc").parent_path(), 61 sdbusplus::message::object_path("/")); 62 ASSERT_EQ(sdbusplus::message::object_path("/").parent_path(), 63 sdbusplus::message::object_path("/")); 64 } 65 66 TEST(MessageTypes, Signature) 67 { 68 ASSERT_EQ(dbus_string(sdbusplus::message::signature("sss")), "g"); 69 } 70 71 TEST(MessageTypes, VectorOfString) 72 { 73 std::vector<std::string> s = {"a", "b"}; 74 75 ASSERT_EQ(dbus_string(s), "as"); 76 } 77 78 TEST(MessageTypes, SetOfString) 79 { 80 std::set<std::string> s = {"a", "b"}; 81 82 ASSERT_EQ(dbus_string(s), "as"); 83 } 84