Index: dbus/property_unittest.cc |
diff --git a/dbus/property_unittest.cc b/dbus/property_unittest.cc |
index 5922554f23d425074d0df17302b019ba63f2a23e..8208581c4e0c7897a1bd8a5401417c2d05b067a4 100644 |
--- a/dbus/property_unittest.cc |
+++ b/dbus/property_unittest.cc |
@@ -7,6 +7,7 @@ |
#include <stddef.h> |
#include <stdint.h> |
+#include <memory> |
#include <string> |
#include <vector> |
@@ -431,4 +432,59 @@ TEST(PropertyTestStatic, SerializeNetAddressArray) { |
EXPECT_EQ(test_list, ip_list.value()); |
} |
+TEST(PropertyTestStatic, ReadWriteStringToByteVectorMap) { |
+ std::unique_ptr<Response> message(Response::CreateEmpty()); |
+ MessageWriter writer(message.get()); |
+ MessageWriter variant_writer(nullptr); |
+ MessageWriter dict_writer(nullptr); |
+ |
+ writer.OpenVariant("a{sv}", &variant_writer); |
+ variant_writer.OpenArray("{sv}", &dict_writer); |
+ |
+ const char* keys[] = {"One", "Two", "Three", "Four"}; |
+ const std::vector<uint8_t> values[] = {{1}, {1, 2}, {1, 2, 3}, {1, 2, 3, 4}}; |
+ for (unsigned i = 0; i < arraysize(keys); ++i) { |
+ MessageWriter entry_writer(nullptr); |
+ dict_writer.OpenDictEntry(&entry_writer); |
+ |
+ entry_writer.AppendString(keys[i]); |
+ |
+ MessageWriter value_varient_writer(nullptr); |
+ entry_writer.OpenVariant("ay", &value_varient_writer); |
+ value_varient_writer.AppendArrayOfBytes(values[i].data(), values[i].size()); |
+ entry_writer.CloseContainer(&value_varient_writer); |
+ |
+ dict_writer.CloseContainer(&entry_writer); |
+ } |
+ |
+ variant_writer.CloseContainer(&dict_writer); |
+ writer.CloseContainer(&variant_writer); |
+ |
+ MessageReader reader(message.get()); |
+ Property<std::unordered_map<std::string, std::vector<uint8_t>>> test_property; |
+ EXPECT_TRUE(test_property.PopValueFromReader(&reader)); |
+ |
+ ASSERT_EQ(arraysize(keys), test_property.value().size()); |
+ for (unsigned i = 0; i < arraysize(keys); ++i) |
+ EXPECT_EQ(values[i], test_property.value().at(keys[i])); |
+} |
+ |
+TEST(PropertyTestStatic, SerializeStringToByteVectorMap) { |
+ std::unordered_map<std::string, std::vector<uint8_t>> test_map; |
+ test_map["Hi"] = {1, 2, 3}; |
+ test_map["Map"] = {0xab, 0xcd}; |
+ test_map["Random"] = {0x0}; |
+ |
+ std::unique_ptr<Response> message(Response::CreateEmpty()); |
+ MessageWriter writer(message.get()); |
+ |
+ Property<std::unordered_map<std::string, std::vector<uint8_t>>> test_property; |
+ test_property.ReplaceSetValueForTesting(test_map); |
+ test_property.AppendSetValueToWriter(&writer); |
+ |
+ MessageReader reader(message.get()); |
+ EXPECT_TRUE(test_property.PopValueFromReader(&reader)); |
+ EXPECT_EQ(test_map, test_property.value()); |
+} |
+ |
} // namespace dbus |