Roll src/third_party/WebKit f0fc3a1:b92951d (svn 201688:201689)
[chromium-blink-merge.git] / chromeos / dbus / privet_daemon_manager_client_unittest.cc
blob84f31d4f9bf089552bcf565bedf049adba28f050
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromeos/dbus/privet_daemon_manager_client.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "dbus/message.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace chromeos {
14 TEST(PrivetDaemonManagerClientTest, ReadPairingInfo) {
15 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty());
16 dbus::MessageWriter writer(message.get());
17 dbus::MessageWriter variant_writer(nullptr);
18 dbus::MessageWriter variant_array_writer(nullptr);
19 dbus::MessageWriter struct_entry_writer(nullptr);
21 writer.OpenVariant("a{sv}", &variant_writer);
22 variant_writer.OpenArray("{sv}", &variant_array_writer);
24 const uint8_t code_value[] = {0x67, 0x12, 0x23, 0x45, 0x64};
25 variant_array_writer.OpenDictEntry(&struct_entry_writer);
26 struct_entry_writer.AppendString("code");
27 dbus::MessageWriter struct_field_writer(nullptr);
28 struct_entry_writer.OpenVariant("ay", &struct_field_writer);
29 struct_field_writer.AppendArrayOfBytes(code_value, arraysize(code_value));
30 struct_entry_writer.CloseContainer(&struct_field_writer);
31 variant_array_writer.CloseContainer(&struct_entry_writer);
33 const char* string_items[] = {"mode", "sessionId"};
34 for (size_t i = 0; i < arraysize(string_items); ++i) {
35 variant_array_writer.OpenDictEntry(&struct_entry_writer);
36 struct_entry_writer.AppendString(string_items[i]);
37 struct_entry_writer.AppendVariantOfString(base::UintToString(i + 1));
38 variant_array_writer.CloseContainer(&struct_entry_writer);
40 writer.CloseContainer(&variant_writer);
41 variant_writer.CloseContainer(&variant_array_writer);
43 dbus::MessageReader reader(message.get());
44 PrivetDaemonManagerClient::PairingInfoProperty pairing_info;
45 EXPECT_TRUE(pairing_info.PopValueFromReader(&reader));
47 EXPECT_EQ(
48 std::vector<uint8_t>(code_value, code_value + arraysize(code_value)),
49 pairing_info.value().code());
50 EXPECT_EQ("1", pairing_info.value().mode());
51 EXPECT_EQ("2", pairing_info.value().session_id());
54 } // namespace chromeos