Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Unified Diff: dbus/property_unittest.cc

Issue 2369423003: bluetooth: Expose service data from BlueZ (Closed)
Patch Set: Fix comment Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dbus/property.cc ('k') | device/bluetooth/bluetooth_device.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « dbus/property.cc ('k') | device/bluetooth/bluetooth_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698