1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "dbus/property.h"
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <string>
#include <vector>
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/message_loop/message_pump_type.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/task_environment.h"
#include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
#include "dbus/bus.h"
#include "dbus/object_path.h"
#include "dbus/object_proxy.h"
#include "dbus/test_service.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace dbus {
// The property test exerises the asynchronous APIs in PropertySet and
// Property<>.
class PropertyTest : public testing::Test {
public:
PropertyTest() = default;
struct Properties : public PropertySet {
Property<std::string> name;
Property<int16_t> version;
Property<std::vector<std::string>> methods;
Property<std::vector<ObjectPath>> objects;
Property<std::vector<uint8_t>> bytes;
Properties(ObjectProxy* object_proxy,
PropertyChangedCallback property_changed_callback)
: PropertySet(object_proxy,
"org.chromium.TestInterface",
property_changed_callback) {
RegisterProperty("Name", &name);
RegisterProperty("Version", &version);
RegisterProperty("Methods", &methods);
RegisterProperty("Objects", &objects);
RegisterProperty("Bytes", &bytes);
}
};
void SetUp() override {
// Make the main thread not to allow IO.
disallow_blocking_.emplace();
// Start the D-Bus thread.
dbus_thread_ = std::make_unique<base::Thread>("D-Bus Thread");
base::Thread::Options thread_options;
thread_options.message_pump_type = base::MessagePumpType::IO;
ASSERT_TRUE(dbus_thread_->StartWithOptions(std::move(thread_options)));
// Start the test service, using the D-Bus thread.
TestService::Options options;
options.dbus_task_runner = dbus_thread_->task_runner();
test_service_ = std::make_unique<TestService>(options);
ASSERT_TRUE(test_service_->StartService());
test_service_->WaitUntilServiceIsStarted();
ASSERT_TRUE(test_service_->HasDBusThread());
// Create the client, using the D-Bus thread.
Bus::Options bus_options;
bus_options.bus_type = Bus::SESSION;
bus_options.connection_type = Bus::PRIVATE;
bus_options.dbus_task_runner = dbus_thread_->task_runner();
bus_ = new Bus(bus_options);
object_proxy_ = bus_->GetObjectProxy(
test_service_->service_name(),
ObjectPath("/org/chromium/TestObject"));
ASSERT_TRUE(bus_->HasDBusThread());
// Create the properties structure
properties_ = std::make_unique<Properties>(
object_proxy_, base::BindRepeating(&PropertyTest::OnPropertyChanged,
base::Unretained(this)));
properties_->ConnectSignals();
properties_->GetAll();
}
void TearDown() override {
bus_->ShutdownOnDBusThreadAndBlock();
// Shut down the service.
test_service_->ShutdownAndBlock();
// Stopping a thread is considered an IO operation, so do this after
// allowing IO.
disallow_blocking_.reset();
test_service_->Stop();
}
// Generic callback, bind with a string |id| for passing to
// WaitForCallback() to ensure the callback for the right method is
// waited for.
void PropertyCallback(const std::string& id, bool success) {
last_callback_ = id;
run_loop_->Quit();
}
// Generic method callback, that might be used together with
// WaitForMethodCallback to test wether method was succesfully called.
void MethodCallback(Response* response) { run_loop_->Quit(); }
protected:
// Called when a property value is updated.
void OnPropertyChanged(const std::string& name) {
updated_properties_.push_back(name);
run_loop_->Quit();
}
// Waits for the given number of updates.
void WaitForUpdates(size_t num_updates) {
while (updated_properties_.size() < num_updates) {
run_loop_ = std::make_unique<base::RunLoop>();
run_loop_->Run();
}
for (size_t i = 0; i < num_updates; ++i)
updated_properties_.erase(updated_properties_.begin());
}
// Name, Version, Methods, Objects
static const int kExpectedSignalUpdates = 5;
// Waits for initial values to be set.
void WaitForGetAll() {
WaitForUpdates(kExpectedSignalUpdates);
}
// Waits until MethodCallback is called.
void WaitForMethodCallback() {
run_loop_ = std::make_unique<base::RunLoop>();
run_loop_->Run();
}
// Waits for the callback. |id| is the string bound to the callback when
// the method call is made that identifies it and distinguishes from any
// other; you can set this to whatever you wish.
void WaitForCallback(const std::string& id) {
while (last_callback_ != id) {
run_loop_ = std::make_unique<base::RunLoop>();
run_loop_->Run();
}
}
base::test::SingleThreadTaskEnvironment task_environment_;
absl::optional<base::ScopedDisallowBlocking> disallow_blocking_;
std::unique_ptr<base::RunLoop> run_loop_;
std::unique_ptr<base::Thread> dbus_thread_;
scoped_refptr<Bus> bus_;
raw_ptr<ObjectProxy, AcrossTasksDanglingUntriaged> object_proxy_;
std::unique_ptr<Properties> properties_;
std::unique_ptr<TestService> test_service_;
// Properties updated.
std::vector<std::string> updated_properties_;
// Last callback received.
std::string last_callback_;
};
TEST_F(PropertyTest, InitialValues) {
EXPECT_FALSE(properties_->name.is_valid());
EXPECT_FALSE(properties_->version.is_valid());
WaitForGetAll();
EXPECT_TRUE(properties_->name.is_valid());
EXPECT_EQ("TestService", properties_->name.value());
EXPECT_TRUE(properties_->version.is_valid());
EXPECT_EQ(10, properties_->version.value());
std::vector<std::string> methods = properties_->methods.value();
ASSERT_EQ(4U, methods.size());
EXPECT_EQ("Echo", methods[0]);
EXPECT_EQ("SlowEcho", methods[1]);
EXPECT_EQ("AsyncEcho", methods[2]);
EXPECT_EQ("BrokenMethod", methods[3]);
std::vector<ObjectPath> objects = properties_->objects.value();
ASSERT_EQ(1U, objects.size());
EXPECT_EQ(ObjectPath("/TestObjectPath"), objects[0]);
std::vector<uint8_t> 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) {
WaitForGetAll();
// Update the value of the "Name" property, this value should not change.
properties_->name.Get(base::BindOnce(&PropertyTest::PropertyCallback,
base::Unretained(this), "Name"));
WaitForCallback("Name");
WaitForUpdates(1);
EXPECT_EQ("TestService", properties_->name.value());
// Update the value of the "Version" property, this value should be changed.
properties_->version.Get(base::BindOnce(&PropertyTest::PropertyCallback,
base::Unretained(this), "Version"));
WaitForCallback("Version");
WaitForUpdates(1);
EXPECT_EQ(20, properties_->version.value());
// Update the value of the "Methods" property, this value should not change
// and should not grow to contain duplicate entries.
properties_->methods.Get(base::BindOnce(&PropertyTest::PropertyCallback,
base::Unretained(this), "Methods"));
WaitForCallback("Methods");
WaitForUpdates(1);
std::vector<std::string> methods = properties_->methods.value();
ASSERT_EQ(4U, methods.size());
EXPECT_EQ("Echo", methods[0]);
EXPECT_EQ("SlowEcho", methods[1]);
EXPECT_EQ("AsyncEcho", methods[2]);
EXPECT_EQ("BrokenMethod", methods[3]);
// Update the value of the "Objects" property, this value should not change
// and should not grow to contain duplicate entries.
properties_->objects.Get(base::BindOnce(&PropertyTest::PropertyCallback,
base::Unretained(this), "Objects"));
WaitForCallback("Objects");
WaitForUpdates(1);
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::BindOnce(&PropertyTest::PropertyCallback,
base::Unretained(this), "Bytes"));
WaitForCallback("Bytes");
WaitForUpdates(1);
std::vector<uint8_t> 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) {
WaitForGetAll();
// Ask for the new Version property.
properties_->version.Get(base::BindOnce(&PropertyTest::PropertyCallback,
base::Unretained(this), "Get"));
WaitForCallback("Get");
// Make sure we got a property update too.
WaitForUpdates(1);
EXPECT_EQ(20, properties_->version.value());
}
TEST_F(PropertyTest, Set) {
WaitForGetAll();
// Set a new name.
properties_->name.Set("NewService",
base::BindOnce(&PropertyTest::PropertyCallback,
base::Unretained(this), "Set"));
WaitForCallback("Set");
// TestService sends a property update.
WaitForUpdates(1);
EXPECT_EQ("NewService", properties_->name.value());
}
TEST_F(PropertyTest, Invalidate) {
WaitForGetAll();
EXPECT_TRUE(properties_->name.is_valid());
// Invalidate name.
MethodCall method_call("org.chromium.TestInterface", "PerformAction");
MessageWriter writer(&method_call);
writer.AppendString("InvalidateProperty");
writer.AppendObjectPath(ObjectPath("/org/chromium/TestService"));
object_proxy_->CallMethod(
&method_call, ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&PropertyTest::MethodCallback, base::Unretained(this)));
WaitForMethodCallback();
// TestService sends a property update.
WaitForUpdates(1);
EXPECT_FALSE(properties_->name.is_valid());
// Set name to something valid.
properties_->name.Set("NewService",
base::BindOnce(&PropertyTest::PropertyCallback,
base::Unretained(this), "Set"));
WaitForCallback("Set");
// TestService sends a property update.
WaitForUpdates(1);
EXPECT_TRUE(properties_->name.is_valid());
}
TEST(PropertyTestStatic, ReadWriteStringMap) {
std::unique_ptr<Response> message(Response::CreateEmpty());
MessageWriter writer(message.get());
MessageWriter variant_writer(nullptr);
MessageWriter variant_array_writer(nullptr);
MessageWriter struct_entry_writer(nullptr);
writer.OpenVariant("a{ss}", &variant_writer);
variant_writer.OpenArray("{ss}", &variant_array_writer);
const char* items[] = {"One", "Two", "Three", "Four"};
for (unsigned i = 0; i < std::size(items); ++i) {
variant_array_writer.OpenDictEntry(&struct_entry_writer);
struct_entry_writer.AppendString(items[i]);
struct_entry_writer.AppendString(base::NumberToString(i + 1));
variant_array_writer.CloseContainer(&struct_entry_writer);
}
variant_writer.CloseContainer(&variant_array_writer);
writer.CloseContainer(&variant_writer);
MessageReader reader(message.get());
Property<std::map<std::string, std::string>> string_map;
EXPECT_TRUE(string_map.PopValueFromReader(&reader));
ASSERT_EQ(4U, string_map.value().size());
EXPECT_EQ("1", string_map.value().at("One"));
EXPECT_EQ("2", string_map.value().at("Two"));
EXPECT_EQ("3", string_map.value().at("Three"));
EXPECT_EQ("4", string_map.value().at("Four"));
}
TEST(PropertyTestStatic, SerializeStringMap) {
std::map<std::string, std::string> test_map;
test_map["Hi"] = "There";
test_map["Map"] = "Test";
test_map["Random"] = "Text";
std::unique_ptr<Response> message(Response::CreateEmpty());
MessageWriter writer(message.get());
Property<std::map<std::string, std::string>> string_map;
string_map.ReplaceSetValueForTesting(test_map);
string_map.AppendSetValueToWriter(&writer);
MessageReader reader(message.get());
EXPECT_TRUE(string_map.PopValueFromReader(&reader));
EXPECT_EQ(test_map, string_map.value());
}
TEST(PropertyTestStatic, ReadWriteNetAddressArray) {
std::unique_ptr<Response> message(Response::CreateEmpty());
MessageWriter writer(message.get());
MessageWriter variant_writer(nullptr);
MessageWriter variant_array_writer(nullptr);
MessageWriter struct_entry_writer(nullptr);
writer.OpenVariant("a(ayq)", &variant_writer);
variant_writer.OpenArray("(ayq)", &variant_array_writer);
uint8_t ip_bytes[] = {0x54, 0x65, 0x73, 0x74, 0x30};
for (uint16_t i = 0; i < 5; ++i) {
variant_array_writer.OpenStruct(&struct_entry_writer);
ip_bytes[4] = 0x30 + i;
struct_entry_writer.AppendArrayOfBytes(ip_bytes, std::size(ip_bytes));
struct_entry_writer.AppendUint16(i);
variant_array_writer.CloseContainer(&struct_entry_writer);
}
variant_writer.CloseContainer(&variant_array_writer);
writer.CloseContainer(&variant_writer);
MessageReader reader(message.get());
Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>> ip_list;
EXPECT_TRUE(ip_list.PopValueFromReader(&reader));
ASSERT_EQ(5U, ip_list.value().size());
size_t item_index = 0;
for (auto& item : ip_list.value()) {
ASSERT_EQ(5U, item.first.size());
ip_bytes[4] = 0x30 + item_index;
EXPECT_EQ(0, memcmp(ip_bytes, item.first.data(), 5U));
EXPECT_EQ(item_index, item.second);
++item_index;
}
}
TEST(PropertyTestStatic, SerializeNetAddressArray) {
std::vector<std::pair<std::vector<uint8_t>, uint16_t>> test_list;
uint8_t ip_bytes[] = {0x54, 0x65, 0x73, 0x74, 0x30};
for (uint16_t i = 0; i < 5; ++i) {
ip_bytes[4] = 0x30 + i;
std::vector<uint8_t> bytes(ip_bytes, ip_bytes + std::size(ip_bytes));
test_list.push_back(make_pair(bytes, 16));
}
std::unique_ptr<Response> message(Response::CreateEmpty());
MessageWriter writer(message.get());
Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>> ip_list;
ip_list.ReplaceSetValueForTesting(test_list);
ip_list.AppendSetValueToWriter(&writer);
MessageReader reader(message.get());
EXPECT_TRUE(ip_list.PopValueFromReader(&reader));
EXPECT_EQ(test_list, ip_list.value());
}
TEST(PropertyTestStatic, ReadWriteStringToByteVectorMapVariantWrapped) {
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 < std::size(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::map<std::string, std::vector<uint8_t>>> test_property;
EXPECT_TRUE(test_property.PopValueFromReader(&reader));
ASSERT_EQ(std::size(keys), test_property.value().size());
for (unsigned i = 0; i < std::size(keys); ++i)
EXPECT_EQ(values[i], test_property.value().at(keys[i]));
}
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{say}", &variant_writer);
variant_writer.OpenArray("{say}", &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 < std::size(keys); ++i) {
MessageWriter entry_writer(nullptr);
dict_writer.OpenDictEntry(&entry_writer);
entry_writer.AppendString(keys[i]);
entry_writer.AppendArrayOfBytes(values[i].data(), values[i].size());
dict_writer.CloseContainer(&entry_writer);
}
variant_writer.CloseContainer(&dict_writer);
writer.CloseContainer(&variant_writer);
MessageReader reader(message.get());
Property<std::map<std::string, std::vector<uint8_t>>> test_property;
EXPECT_TRUE(test_property.PopValueFromReader(&reader));
ASSERT_EQ(std::size(keys), test_property.value().size());
for (unsigned i = 0; i < std::size(keys); ++i)
EXPECT_EQ(values[i], test_property.value().at(keys[i]));
}
TEST(PropertyTestStatic, SerializeStringToByteVectorMap) {
std::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::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());
}
TEST(PropertyTestStatic, ReadWriteUInt16ToByteVectorMapVariantWrapped) {
std::unique_ptr<Response> message(Response::CreateEmpty());
MessageWriter writer(message.get());
MessageWriter variant_writer(nullptr);
MessageWriter dict_writer(nullptr);
writer.OpenVariant("a{qv}", &variant_writer);
variant_writer.OpenArray("{qv}", &dict_writer);
const uint16_t keys[] = {11, 12, 13, 14};
const std::vector<uint8_t> values[] = {{1}, {1, 2}, {1, 2, 3}, {1, 2, 3, 4}};
for (unsigned i = 0; i < std::size(keys); ++i) {
MessageWriter entry_writer(nullptr);
dict_writer.OpenDictEntry(&entry_writer);
entry_writer.AppendUint16(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::map<uint16_t, std::vector<uint8_t>>> test_property;
EXPECT_TRUE(test_property.PopValueFromReader(&reader));
ASSERT_EQ(std::size(keys), test_property.value().size());
for (unsigned i = 0; i < std::size(keys); ++i)
EXPECT_EQ(values[i], test_property.value().at(keys[i]));
}
TEST(PropertyTestStatic, ReadWriteUInt16ToByteVectorMap) {
std::unique_ptr<Response> message(Response::CreateEmpty());
MessageWriter writer(message.get());
MessageWriter variant_writer(nullptr);
MessageWriter dict_writer(nullptr);
writer.OpenVariant("a{qay}", &variant_writer);
variant_writer.OpenArray("{qay}", &dict_writer);
const uint16_t keys[] = {11, 12, 13, 14};
const std::vector<uint8_t> values[] = {{1}, {1, 2}, {1, 2, 3}, {1, 2, 3, 4}};
for (unsigned i = 0; i < std::size(keys); ++i) {
MessageWriter entry_writer(nullptr);
dict_writer.OpenDictEntry(&entry_writer);
entry_writer.AppendUint16(keys[i]);
entry_writer.AppendArrayOfBytes(values[i].data(), values[i].size());
dict_writer.CloseContainer(&entry_writer);
}
variant_writer.CloseContainer(&dict_writer);
writer.CloseContainer(&variant_writer);
MessageReader reader(message.get());
Property<std::map<uint16_t, std::vector<uint8_t>>> test_property;
EXPECT_TRUE(test_property.PopValueFromReader(&reader));
ASSERT_EQ(std::size(keys), test_property.value().size());
for (unsigned i = 0; i < std::size(keys); ++i)
EXPECT_EQ(values[i], test_property.value().at(keys[i]));
}
TEST(PropertyTestStatic, SerializeUInt16ToByteVectorMap) {
std::map<uint16_t, std::vector<uint8_t>> test_map;
test_map[11] = {1, 2, 3};
test_map[12] = {0xab, 0xcd};
test_map[13] = {0x0};
std::unique_ptr<Response> message(Response::CreateEmpty());
MessageWriter writer(message.get());
Property<std::map<uint16_t, 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
|