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

Side by Side Diff: chromeos/dbus/privet_daemon_manager_client_unittest.cc

Issue 996013003: privetd: Expose dbus API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove Variant typed class and replace with a concrete class Created 5 years, 9 months 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
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
hashimoto 2015/03/20 06:41:48 nit: 2015.
dtapuska 2015/03/20 13:47:56 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chromeos/dbus/privet_daemon_manager_client.h"
6
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"
11 #include "third_party/cros_system_api/dbus/service_constants.h"
hashimoto 2015/03/20 06:41:48 nit: Looks unused.
dtapuska 2015/03/20 13:47:56 Done.
12
13 namespace chromeos {
14
15 TEST(PrivetDaemonManagerClientTest, ReadWritePairingInfo) {
16 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty());
17 dbus::MessageWriter writer(message.get());
18 dbus::MessageWriter variant_writer(NULL);
19 dbus::MessageWriter variant_array_writer(NULL);
20 dbus::MessageWriter struct_entry_writer(NULL);
21
22 writer.OpenVariant("a{sv}", &variant_writer);
23 variant_writer.OpenArray("{sv}", &variant_array_writer);
24
25 const uint8_t code_value[] = {0x67, 0x12, 0x23, 0x45, 0x64};
26 variant_array_writer.OpenDictEntry(&struct_entry_writer);
27 struct_entry_writer.AppendString("code");
28 dbus::MessageWriter struct_field_writer(NULL);
29 struct_entry_writer.OpenVariant("ay", &struct_field_writer);
30 struct_field_writer.AppendArrayOfBytes(code_value, arraysize(code_value));
31 struct_entry_writer.CloseContainer(&struct_field_writer);
32 variant_array_writer.CloseContainer(&struct_entry_writer);
33
34 const char* string_items[] = {"mode", "sessionId"};
35 for (size_t i = 0; i < arraysize(string_items); ++i) {
36 variant_array_writer.OpenDictEntry(&struct_entry_writer);
37 struct_entry_writer.AppendString(string_items[i]);
38 struct_entry_writer.AppendVariantOfString(base::UintToString(i + 1));
39 variant_array_writer.CloseContainer(&struct_entry_writer);
40 }
41 writer.CloseContainer(&variant_writer);
42 variant_writer.CloseContainer(&variant_array_writer);
43
44 dbus::MessageReader reader(message.get());
45 PrivetDaemonManagerClient::PairingInfoProperty pairing_info;
46 EXPECT_TRUE(pairing_info.PopValueFromReader(&reader));
47
48 EXPECT_EQ(arraysize(code_value), pairing_info.value().code().size());
49 EXPECT_EQ(0, memcmp(code_value, pairing_info.value().code().data(),
50 arraysize(code_value)));
51 EXPECT_EQ("1", pairing_info.value().mode());
52 EXPECT_EQ("2", pairing_info.value().session_id());
53 }
54
55 TEST(PrivetDaemonManagerClientTest, SerializePairingInfo) {
56 const uint8_t code_value[] = {0x67, 0x12, 0x23, 0x45, 0x64};
57 PrivetDaemonManagerClient::PairingInfo set_pairing_info;
58 set_pairing_info.set_code(code_value, arraysize(code_value));
59 set_pairing_info.set_mode("embeddedCode");
60 set_pairing_info.set_session_id("23");
61
62 scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty());
63 dbus::MessageWriter writer(message.get());
64
65 PrivetDaemonManagerClient::PairingInfoProperty pairing_info;
66 pairing_info.ReplaceSetValueForTesting(set_pairing_info);
67 pairing_info.AppendSetValueToWriter(&writer);
68
69 dbus::MessageReader reader(message.get());
70 EXPECT_TRUE(pairing_info.PopValueFromReader(&reader));
71 EXPECT_EQ(set_pairing_info.code(), pairing_info.value().code());
72 EXPECT_EQ(set_pairing_info.mode(), pairing_info.value().mode());
73 EXPECT_EQ(set_pairing_info.session_id(), pairing_info.value().session_id());
74 }
75
76 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698