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

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: fixes + moar tests 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/values.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace bluez {
13
14 namespace {
15
16 using Type = BluetoothServiceAttributeValueBlueZ::Type;
17 using ValueType = BluetoothServiceAttributeValueBlueZ::ValueType;
18 using Sequence = BluetoothServiceAttributeValueBlueZ::Sequence;
19
20 // constexpr uint16_t kServiceUuidAttributeId = 0x0003;
21 constexpr char kServiceUuid[] = "00001801-0000-1000-8000-00805f9b34fb";
22
23 void CheckUuidValue(const BluetoothServiceAttributeValueBlueZ& value,
24 const std::string& uuid) {
25 EXPECT_EQ(Type::UUID, value.get_type());
26 std::string str;
27 EXPECT_TRUE(value.get_value().value->GetAsString(&str));
28 EXPECT_EQ(uuid, str);
29 }
30
31 void CheckIntValue(const BluetoothServiceAttributeValueBlueZ& value,
32 uint32_t val) {
33 EXPECT_EQ(Type::INT, value.get_type());
34 int i_val;
35 EXPECT_TRUE(value.get_value().value->GetAsInteger(&i_val));
36 EXPECT_EQ(val, static_cast<uint32_t>(i_val));
37 }
38 }
39
40 TEST(BluetoothServiceAttributeBlueZTest, BasicValue) {
41 BluetoothServiceAttributeValueBlueZ value1(
42 Type::UUID, 16, new base::StringValue(kServiceUuid));
43 BluetoothServiceAttributeValueBlueZ value2 = value1;
44
45 CheckUuidValue(value2, kServiceUuid);
46 }
47
48 TEST(BluetoothServiceAttributeBlueZTest, Sequence) {
49 BluetoothServiceAttributeValueBlueZ value1(
50 Type::UUID, 16, new base::StringValue(kServiceUuid));
51 BluetoothServiceAttributeValueBlueZ value2(
52 Type::INT, 4, new base::FundamentalValue(0x1337));
53 BluetoothServiceAttributeValueBlueZ value3(
54 Type::INT, 4, new base::FundamentalValue(0x7331));
55
56 BluetoothServiceAttributeValueBlueZ* value4 =
57 new BluetoothServiceAttributeValueBlueZ(
58 Type::SEQUENCE, 3, new Sequence({value1, value2, value3}));
59 BluetoothServiceAttributeValueBlueZ value = *value4;
60 delete value4;
61
62 EXPECT_EQ(3u, value.get_size());
63 Sequence* s = value.get_value().sequence;
64 EXPECT_EQ(3u, s->size());
65
66 CheckUuidValue((*s)[0], kServiceUuid);
67 CheckIntValue((*s)[2], 0x7331); // Checking out of order by intention.
68 CheckIntValue((*s)[1], 0x1337);
69 }
70
71 TEST(BluetoothServiceAttributeBlueZTest, NestedValue) {
72 BluetoothServiceAttributeValueBlueZ value1(
73 Type::UUID, 16, new base::StringValue(kServiceUuid));
74 BluetoothServiceAttributeValueBlueZ value2(
75 Type::INT, 4, new base::FundamentalValue(0x1337));
76 BluetoothServiceAttributeValueBlueZ value3(Type::SEQUENCE, 2,
77 new Sequence({value1, value2}));
78 BluetoothServiceAttributeValueBlueZ value4(Type::SEQUENCE, 1,
79 new Sequence({value3}));
80
81 BluetoothServiceAttributeValueBlueZ* value5 =
82 new BluetoothServiceAttributeValueBlueZ(
83 Type::SEQUENCE, 4, new Sequence({value1, value2, value3, value4}));
84 BluetoothServiceAttributeValueBlueZ value = *value5;
85 delete value5;
86
87 // Check outer layer first.
88 EXPECT_EQ(4u, value.get_size());
89 Sequence* v5 = value.get_value().sequence;
90 EXPECT_EQ(4u, v5->size());
91 CheckUuidValue((*v5)[0], kServiceUuid);
92 CheckIntValue((*v5)[1], 0x1337);
93
94 // Check value3 again.
95 EXPECT_EQ(2u, (*v5)[2].get_size());
96 EXPECT_EQ(Type::SEQUENCE, (*v5)[2].get_type());
97 Sequence* v3 = (*v5)[2].get_value().sequence;
98 EXPECT_EQ(2u, v3->size());
99 CheckUuidValue((*v3)[0], kServiceUuid);
100 CheckIntValue((*v3)[1], 0x1337);
101
102 // Check value4 now.
103 EXPECT_EQ(1u, (*v5)[3].get_size());
104 EXPECT_EQ(Type::SEQUENCE, (*v5)[3].get_type());
105 Sequence* v4 = (*v5)[3].get_value().sequence;
106 EXPECT_EQ(1u, v4->size());
107
108 // Check value3 again.
109 EXPECT_EQ(2u, (*v4)[0].get_size());
110 EXPECT_EQ(Type::SEQUENCE, (*v4)[0].get_type());
111 v3 = (*v4)[0].get_value().sequence;
112 EXPECT_EQ(2u, v3->size());
113 CheckUuidValue((*v3)[0], kServiceUuid);
114 CheckIntValue((*v3)[1], 0x1337);
115 }
116
117 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698