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

Side by Side Diff: device/bluetooth/bluez/bluetooth_service_attribute_value_bluez_unittest.cc

Issue 2084463002: BlueZ + DBus implementations of create/remove service record functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 6 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 2016 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.
4
5 #include "device/bluetooth/bluez/bluetooth_service_attribute_value_bluez.h"
6
7 #include <cstdint>
8
9 #include "base/memory/ptr_util.h"
10 #include "base/values.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace bluez {
14
15 namespace {
16
17 using Type = BluetoothServiceAttributeValueBlueZ::Type;
18 using Sequence = BluetoothServiceAttributeValueBlueZ::Sequence;
19
20 constexpr char kServiceUuid[] = "00001801-0000-1000-8000-00805f9b34fb";
21
22 void CheckUuidValue(const BluetoothServiceAttributeValueBlueZ& value,
23 const std::string& uuid) {
24 EXPECT_EQ(Type::UUID, value.type());
25 std::string str;
26 EXPECT_TRUE(value.value().GetAsString(&str));
27 EXPECT_EQ(uuid, str);
28 }
29
30 void CheckIntValue(const BluetoothServiceAttributeValueBlueZ& value,
31 uint32_t val) {
32 EXPECT_EQ(Type::INT, value.type());
33 int i_val;
34 EXPECT_TRUE(value.value().GetAsInteger(&i_val));
35 EXPECT_EQ(val, static_cast<uint32_t>(i_val));
36 }
37 }
38
39 TEST(BluetoothServiceAttributeBlueZTest, BasicValue) {
40 BluetoothServiceAttributeValueBlueZ value1(
41 Type::UUID, 16, base::WrapUnique(new base::StringValue(kServiceUuid)));
xiyuan 2016/06/22 21:28:44 nit: learned from my other review, we can do ba
rkc 2016/06/23 19:55:44 Done.
42 BluetoothServiceAttributeValueBlueZ value2 = value1;
43
44 CheckUuidValue(value2, kServiceUuid);
45 }
46
47 TEST(BluetoothServiceAttributeBlueZTest, Sequence) {
48 BluetoothServiceAttributeValueBlueZ value1(
49 Type::UUID, 16, base::WrapUnique(new base::StringValue(kServiceUuid)));
50 BluetoothServiceAttributeValueBlueZ value2(
51 Type::INT, 4, base::WrapUnique(new base::FundamentalValue(0x1337)));
52 BluetoothServiceAttributeValueBlueZ value3(
53 Type::INT, 4, base::WrapUnique(new base::FundamentalValue(0x7331)));
54
55 BluetoothServiceAttributeValueBlueZ* value4 =
56 new BluetoothServiceAttributeValueBlueZ(
57 base::WrapUnique(new Sequence({value1, value2, value3})));
58 BluetoothServiceAttributeValueBlueZ value = *value4;
59 delete value4;
60
61 EXPECT_EQ(3u, value.size());
62 const Sequence& s = value.sequence();
63 EXPECT_EQ(3u, s.size());
64
65 CheckUuidValue(s[0], kServiceUuid);
66 CheckIntValue(s[2], 0x7331); // Checking out of order by intention.
67 CheckIntValue(s[1], 0x1337);
68 }
69
70 TEST(BluetoothServiceAttributeBlueZTest, NestedValue) {
71 BluetoothServiceAttributeValueBlueZ value1(
72 Type::UUID, 16, base::WrapUnique(new base::StringValue(kServiceUuid)));
73 BluetoothServiceAttributeValueBlueZ value2(
74 Type::INT, 4, base::WrapUnique(new base::FundamentalValue(0x1337)));
75 BluetoothServiceAttributeValueBlueZ value3(
76 base::WrapUnique(new Sequence({value1, value2})));
77 BluetoothServiceAttributeValueBlueZ value4(
78 base::WrapUnique(new Sequence({value3})));
79
80 BluetoothServiceAttributeValueBlueZ* value5 =
81 new BluetoothServiceAttributeValueBlueZ(
82 base::WrapUnique(new Sequence({value1, value2, value3, value4})));
83 BluetoothServiceAttributeValueBlueZ value = *value5;
84 delete value5;
85
86 // Check outer layer first.
87 EXPECT_EQ(4u, value.size());
88 const Sequence& v5 = value.sequence();
89 EXPECT_EQ(4u, v5.size());
90 CheckUuidValue(v5[0], kServiceUuid);
91 CheckIntValue(v5[1], 0x1337);
92
93 // Check value3.
94 EXPECT_EQ(2u, v5[2].size());
95 EXPECT_EQ(Type::SEQUENCE, v5[2].type());
96 const Sequence& v3 = v5[2].sequence();
97 EXPECT_EQ(2u, v3.size());
98 CheckUuidValue(v3[0], kServiceUuid);
99 CheckIntValue(v3[1], 0x1337);
100
101 // Check value4 now.
102 EXPECT_EQ(1u, v5[3].size());
103 EXPECT_EQ(Type::SEQUENCE, v5[3].type());
104 const Sequence& v4 = v5[3].sequence();
105 EXPECT_EQ(1u, v4.size());
106
107 // Check value3 again.
108 EXPECT_EQ(2u, v4[0].size());
109 EXPECT_EQ(Type::SEQUENCE, v4[0].type());
110 const Sequence& v31 = v4[0].sequence();
111 EXPECT_EQ(2u, v31.size());
112 CheckUuidValue(v31[0], kServiceUuid);
113 CheckIntValue(v31[1], 0x1337);
114 }
115
116 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698