1 #include <sdbusplus/message.hpp> 2 3 #include <map> 4 #include <string> 5 #include <unordered_map> 6 #include <vector> 7 8 #include <gtest/gtest.h> 9 10 using namespace std::string_literals; 11 12 /* Suite tests that object_path and signature can be cleanly converted to 13 * and from strings and used as container parameters. 14 */ 15 16 TEST(MessageNativeTypeConversions, ObjectPath) 17 { 18 std::string s1 = sdbusplus::message::object_path("/asdf/"); 19 sdbusplus::message::object_path p = std::move(s1); 20 21 ASSERT_EQ("/asdf/", p); 22 ASSERT_EQ(p, "/asdf/"); 23 } 24 25 TEST(MessageNativeTypeConversions, Signature) 26 { 27 std::string s2 = sdbusplus::message::signature("iii"); 28 sdbusplus::message::signature sig = s2; 29 30 ASSERT_EQ(sig, s2); 31 ASSERT_EQ(s2, sig); 32 } 33 34 TEST(MessageNativeTypeConversions, SignatureInVector) 35 { 36 std::vector<sdbusplus::message::signature> v = { 37 sdbusplus::message::signature("iii")}; 38 39 ASSERT_EQ(v.front(), "iii"); 40 } 41 42 TEST(MessageNativeTypeConversions, SignatureInMap) 43 { 44 std::map<sdbusplus::message::signature, int> m = { 45 {sdbusplus::message::signature("iii"), 1}}; 46 47 ASSERT_EQ(m[sdbusplus::message::signature("iii")], 1); 48 } 49 50 TEST(MessageNativeTypeConversions, SignatureInUnorderedMap) 51 { 52 std::unordered_map<sdbusplus::message::signature, int> u = { 53 {sdbusplus::message::signature("iii"), 2}}; 54 55 ASSERT_EQ(u[sdbusplus::message::signature("iii")], 2); 56 } 57 58 TEST(MessageNativeTypeConversions, WrapperReference) 59 { 60 auto orig = "str"s; 61 sdbusplus::message::object_path obj = orig; 62 auto out = static_cast<std::string>(obj); 63 EXPECT_EQ(orig, out); 64 } 65 66 TEST(MessageNativeTypeConversions, WrapperMove) 67 { 68 auto orig = "str"s; 69 sdbusplus::message::object_path obj = orig; 70 auto out = static_cast<std::string>(std::move(obj)); 71 EXPECT_EQ(orig, out); 72 } 73