diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-22 18:28:42 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-22 18:28:42 +0000 |
commit | 090d8e51bb768c3c4ecd30a81b3285fc6ddff9e2 (patch) | |
tree | f393d869c901f3e5958dcd3077d715f096b8bbb9 /dbus | |
parent | 9b8aa5b5adf8aa3f005876fdbcc5120099073604 (diff) | |
download | chromium_src-090d8e51bb768c3c4ecd30a81b3285fc6ddff9e2.zip chromium_src-090d8e51bb768c3c4ecd30a81b3285fc6ddff9e2.tar.gz chromium_src-090d8e51bb768c3c4ecd30a81b3285fc6ddff9e2.tar.bz2 |
Add AppendArrayOfObjectPaths, which was missing.
It was an oversight not to have this function.
BUG=90036
TEST=dbus_unittests
Review URL: http://codereview.chromium.org/7686013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97689 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/message.cc | 11 | ||||
-rw-r--r-- | dbus/message.h | 5 | ||||
-rw-r--r-- | dbus/message_unittest.cc | 20 |
3 files changed, 36 insertions, 0 deletions
diff --git a/dbus/message.cc b/dbus/message.cc index 79c1b77..9216515 100644 --- a/dbus/message.cc +++ b/dbus/message.cc @@ -512,6 +512,17 @@ void MessageWriter::AppendArrayOfBytes(const uint8* values, size_t length) { CloseContainer(&array_writer); } +void MessageWriter::AppendArrayOfObjectPaths( + const std::vector<std::string>& object_paths) { + DCHECK(!container_is_open_); + MessageWriter array_writer(message_); + OpenArray("o", &array_writer); + for (size_t i = 0; i < object_paths.size(); ++i) { + array_writer.AppendObjectPath(object_paths[i]); + } + CloseContainer(&array_writer); +} + void MessageWriter::AppendVariantOfByte(uint8 value) { AppendVariantOfBasic(DBUS_TYPE_BYTE, &value); } diff --git a/dbus/message.h b/dbus/message.h index 31887a1..4f8dc07 100644 --- a/dbus/message.h +++ b/dbus/message.h @@ -238,6 +238,11 @@ class MessageWriter { // function. void AppendArrayOfBytes(const uint8* values, size_t length); + // Appends the array of object paths. Arrays of object paths are often + // used to exchanging object paths, hence it's worth having a + // specialized function. + void AppendArrayOfObjectPaths(const std::vector<std::string>& object_paths); + // Appends the byte wrapped in a variant data container. Variants are // widely used in D-Bus services so it's worth having a specialized // function. For instance, The third parameter of diff --git a/dbus/message_unittest.cc b/dbus/message_unittest.cc index e7d913d..518a7e0 100644 --- a/dbus/message_unittest.cc +++ b/dbus/message_unittest.cc @@ -175,6 +175,26 @@ TEST(MessageTest, ArrayOfBytes) { ASSERT_EQ(3, output_bytes[2]); } +TEST(MessageTest, ArrayOfObjectPaths) { + dbus::Message message; + message.reset_raw_message(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL)); + dbus::MessageWriter writer(&message); + std::vector<std::string> object_paths; + object_paths.push_back("/object/path/1"); + object_paths.push_back("/object/path/2"); + object_paths.push_back("/object/path/3"); + writer.AppendArrayOfObjectPaths(object_paths); + + dbus::MessageReader reader(&message); + std::vector<std::string> output_object_paths; + ASSERT_TRUE(reader.PopArrayOfObjectPaths(&output_object_paths)); + ASSERT_FALSE(reader.HasMoreData()); + ASSERT_EQ(3U, output_object_paths.size()); + ASSERT_EQ("/object/path/1", output_object_paths[0]); + ASSERT_EQ("/object/path/2", output_object_paths[1]); + ASSERT_EQ("/object/path/3", output_object_paths[2]); +} + // Test that an array can be properly written and read. We only have this // test for array, as repeating this for other container types is too // redundant. |