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

Side by Side Diff: dbus/property_unittest.cc

Issue 2421713002: arc: bluetooth: Expose missing advertise data. (Closed)
Patch Set: Add BlueZ unittests / more comment Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « dbus/property.cc ('k') | device/bluetooth/bluetooth_adapter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "dbus/property.h" 5 #include "dbus/property.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 480
481 Property<std::unordered_map<std::string, std::vector<uint8_t>>> test_property; 481 Property<std::unordered_map<std::string, std::vector<uint8_t>>> test_property;
482 test_property.ReplaceSetValueForTesting(test_map); 482 test_property.ReplaceSetValueForTesting(test_map);
483 test_property.AppendSetValueToWriter(&writer); 483 test_property.AppendSetValueToWriter(&writer);
484 484
485 MessageReader reader(message.get()); 485 MessageReader reader(message.get());
486 EXPECT_TRUE(test_property.PopValueFromReader(&reader)); 486 EXPECT_TRUE(test_property.PopValueFromReader(&reader));
487 EXPECT_EQ(test_map, test_property.value()); 487 EXPECT_EQ(test_map, test_property.value());
488 } 488 }
489 489
490 TEST(PropertyTestStatic, ReadWriteUInt16ToByteVectorMap) {
491 std::unique_ptr<Response> message(Response::CreateEmpty());
492 MessageWriter writer(message.get());
493 MessageWriter variant_writer(nullptr);
494 MessageWriter dict_writer(nullptr);
495
496 writer.OpenVariant("a{qv}", &variant_writer);
497 variant_writer.OpenArray("{qv}", &dict_writer);
498
499 const uint16_t keys[] = {11, 12, 13, 14};
500 const std::vector<uint8_t> values[] = {{1}, {1, 2}, {1, 2, 3}, {1, 2, 3, 4}};
501 for (unsigned i = 0; i < arraysize(keys); ++i) {
502 MessageWriter entry_writer(nullptr);
503 dict_writer.OpenDictEntry(&entry_writer);
504
505 entry_writer.AppendUint16(keys[i]);
506
507 MessageWriter value_varient_writer(nullptr);
508 entry_writer.OpenVariant("ay", &value_varient_writer);
509 value_varient_writer.AppendArrayOfBytes(values[i].data(), values[i].size());
510 entry_writer.CloseContainer(&value_varient_writer);
511
512 dict_writer.CloseContainer(&entry_writer);
513 }
514
515 variant_writer.CloseContainer(&dict_writer);
516 writer.CloseContainer(&variant_writer);
517
518 MessageReader reader(message.get());
519 Property<std::unordered_map<uint16_t, std::vector<uint8_t>>> test_property;
520 EXPECT_TRUE(test_property.PopValueFromReader(&reader));
521
522 ASSERT_EQ(arraysize(keys), test_property.value().size());
523 for (unsigned i = 0; i < arraysize(keys); ++i)
524 EXPECT_EQ(values[i], test_property.value().at(keys[i]));
525 }
526
527 TEST(PropertyTestStatic, SerializeUInt16ToByteVectorMap) {
528 std::unordered_map<uint16_t, std::vector<uint8_t>> test_map;
529 test_map[11] = {1, 2, 3};
530 test_map[12] = {0xab, 0xcd};
531 test_map[13] = {0x0};
532
533 std::unique_ptr<Response> message(Response::CreateEmpty());
534 MessageWriter writer(message.get());
535
536 Property<std::unordered_map<uint16_t, std::vector<uint8_t>>> test_property;
537 test_property.ReplaceSetValueForTesting(test_map);
538 test_property.AppendSetValueToWriter(&writer);
539
540 MessageReader reader(message.get());
541 EXPECT_TRUE(test_property.PopValueFromReader(&reader));
542 EXPECT_EQ(test_map, test_property.value());
543 }
544
490 } // namespace dbus 545 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/property.cc ('k') | device/bluetooth/bluetooth_adapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698