diff options
author | armansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-15 07:40:49 +0000 |
---|---|---|
committer | armansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-15 07:40:49 +0000 |
commit | ebbfffa2f19d6d4727586710dd49be63fcd8e1e2 (patch) | |
tree | ca18177ab6074fd42aa589b53581ad7ca8d67983 /dbus | |
parent | df42c35236e9570d64477009bf89fb42baee7b60 (diff) | |
download | chromium_src-ebbfffa2f19d6d4727586710dd49be63fcd8e1e2.zip chromium_src-ebbfffa2f19d6d4727586710dd49be63fcd8e1e2.tar.gz chromium_src-ebbfffa2f19d6d4727586710dd49be63fcd8e1e2.tar.bz2 |
dbus: Add template specialization for Property<vector<uint8> >.
BUG=351229
TEST=dbus_unittests
Review URL: https://codereview.chromium.org/199573003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257315 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/property.cc | 28 | ||||
-rw-r--r-- | dbus/property.h | 5 | ||||
-rw-r--r-- | dbus/property_unittest.cc | 26 | ||||
-rw-r--r-- | dbus/test_service.cc | 23 |
4 files changed, 81 insertions, 1 deletions
diff --git a/dbus/property.cc b/dbus/property.cc index 9289c86..774719f 100644 --- a/dbus/property.cc +++ b/dbus/property.cc @@ -449,4 +449,32 @@ void Property<std::vector<ObjectPath> >::AppendSetValueToWriter( writer->CloseContainer(&variant_writer); } +// +// Property<std::vector<uint8> > specialization. +// + +template <> +bool Property<std::vector<uint8> >::PopValueFromReader(MessageReader* reader) { + MessageReader variant_reader(NULL); + if (!reader->PopVariant(&variant_reader)) + return false; + + value_.clear(); + const uint8* bytes = NULL; + size_t length = 0; + if (!variant_reader.PopArrayOfBytes(&bytes, &length)) + return false; + value_.assign(bytes, bytes + length); + return true; +} + +template <> +void Property<std::vector<uint8> >::AppendSetValueToWriter( + MessageWriter* writer) { + MessageWriter variant_writer(NULL); + writer->OpenVariant("ay", &variant_writer); + variant_writer.AppendArrayOfBytes(set_value_.data(), set_value_.size()); + writer->CloseContainer(&variant_writer); +} + } // namespace dbus diff --git a/dbus/property.h b/dbus/property.h index 9f5af48..f6baffc 100644 --- a/dbus/property.h +++ b/dbus/property.h @@ -466,6 +466,11 @@ template <> bool Property<std::vector<ObjectPath> >::PopValueFromReader( template <> void Property<std::vector<ObjectPath> >::AppendSetValueToWriter( MessageWriter* writer); +template <> bool Property<std::vector<uint8> >::PopValueFromReader( + MessageReader* reader); +template <> void Property<std::vector<uint8> >::AppendSetValueToWriter( + MessageWriter* writer); + } // namespace dbus #endif // DBUS_PROPERTY_H_ diff --git a/dbus/property_unittest.cc b/dbus/property_unittest.cc index cbff1dc..e078c00 100644 --- a/dbus/property_unittest.cc +++ b/dbus/property_unittest.cc @@ -33,6 +33,7 @@ class PropertyTest : public testing::Test { Property<int16> version; Property<std::vector<std::string> > methods; Property<std::vector<ObjectPath> > objects; + Property<std::vector<uint8> > bytes; Properties(ObjectProxy* object_proxy, PropertyChangedCallback property_changed_callback) @@ -43,6 +44,7 @@ class PropertyTest : public testing::Test { RegisterProperty("Version", &version); RegisterProperty("Methods", &methods); RegisterProperty("Objects", &objects); + RegisterProperty("Bytes", &bytes); } }; @@ -122,7 +124,7 @@ class PropertyTest : public testing::Test { } // Name, Version, Methods, Objects - static const int kExpectedSignalUpdates = 4; + static const int kExpectedSignalUpdates = 5; // Waits for initial values to be set. void WaitForGetAll() { @@ -166,6 +168,13 @@ TEST_F(PropertyTest, InitialValues) { std::vector<ObjectPath> objects = properties_->objects.value(); ASSERT_EQ(1U, objects.size()); EXPECT_EQ(ObjectPath("/TestObjectPath"), objects[0]); + + std::vector<uint8> bytes = properties_->bytes.value(); + ASSERT_EQ(4U, bytes.size()); + EXPECT_EQ('T', bytes[0]); + EXPECT_EQ('e', bytes[1]); + EXPECT_EQ('s', bytes[2]); + EXPECT_EQ('t', bytes[3]); } TEST_F(PropertyTest, UpdatedValues) { @@ -215,6 +224,21 @@ TEST_F(PropertyTest, UpdatedValues) { std::vector<ObjectPath> objects = properties_->objects.value(); ASSERT_EQ(1U, objects.size()); EXPECT_EQ(ObjectPath("/TestObjectPath"), objects[0]); + + // Update the value of the "Bytes" property, this value should not change + // and should not grow to contain duplicate entries. + properties_->bytes.Get(base::Bind(&PropertyTest::PropertyCallback, + base::Unretained(this), + "Bytes")); + WaitForCallback("Bytes"); + WaitForUpdates(1); + + std::vector<uint8> bytes = properties_->bytes.value(); + ASSERT_EQ(4U, bytes.size()); + EXPECT_EQ('T', bytes[0]); + EXPECT_EQ('e', bytes[1]); + EXPECT_EQ('s', bytes[2]); + EXPECT_EQ('t', bytes[3]); } TEST_F(PropertyTest, Get) { diff --git a/dbus/test_service.cc b/dbus/test_service.cc index 064b91e..96fa8bc 100644 --- a/dbus/test_service.cc +++ b/dbus/test_service.cc @@ -408,6 +408,20 @@ void TestService::GetProperty(MethodCall* method_call, writer.CloseContainer(&variant_writer); response_sender.Run(response.Pass()); + } else if (name == "Bytes") { + // Return the previous value for the "Bytes" property: + // Variant<[0x54, 0x65, 0x73, 0x74]> + scoped_ptr<Response> response = Response::FromMethodCall(method_call); + MessageWriter writer(response.get()); + MessageWriter variant_writer(NULL); + MessageWriter variant_array_writer(NULL); + + writer.OpenVariant("ay", &variant_writer); + const uint8 bytes[] = { 0x54, 0x65, 0x73, 0x74 }; + variant_writer.AppendArrayOfBytes(bytes, sizeof(bytes)); + writer.CloseContainer(&variant_writer); + + response_sender.Run(response.Pass()); } else { // Return error. response_sender.Run(scoped_ptr<Response>()); @@ -554,6 +568,7 @@ void TestService::AddPropertiesToWriter(MessageWriter* writer) { // "Version": Variant<10>, // "Methods": Variant<["Echo", "SlowEcho", "AsyncEcho", "BrokenMethod"]>, // "Objects": Variant<[objectpath:"/TestObjectPath"]> + // "Bytes": Variant<[0x54, 0x65, 0x73, 0x74]> // } MessageWriter array_writer(NULL); @@ -594,6 +609,14 @@ void TestService::AddPropertiesToWriter(MessageWriter* writer) { dict_entry_writer.CloseContainer(&variant_writer); array_writer.CloseContainer(&dict_entry_writer); + array_writer.OpenDictEntry(&dict_entry_writer); + dict_entry_writer.AppendString("Bytes"); + dict_entry_writer.OpenVariant("ay", &variant_writer); + const uint8 bytes[] = { 0x54, 0x65, 0x73, 0x74 }; + variant_writer.AppendArrayOfBytes(bytes, sizeof(bytes)); + dict_entry_writer.CloseContainer(&variant_writer); + array_writer.CloseContainer(&dict_entry_writer); + writer->CloseContainer(&array_writer); } |