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

Side by Side Diff: device/bluetooth/dbus/bluetooth_gatt_application_service_provider_unittest.cc

Issue 1914893002: DBus changes for implementing local GATT attributes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth_classes
Patch Set: test leak fix Created 4 years, 7 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 <base/bind.h>
6 #include <base/memory/ptr_util.h>
7 #include <dbus/bus.h>
8 #include <dbus/message.h>
9 #include <dbus/object_path.h>
10 #include <device/bluetooth/dbus/bluetooth_gatt_application_service_provider_impl .h>
11 #include <device/bluetooth/dbus/bluetooth_gatt_characteristic_service_provider_i mpl.h>
12 #include <device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider_impl. h>
13 #include <device/bluetooth/dbus/bluetooth_gatt_service_service_provider_impl.h>
14 #include <gtest/gtest.h>
15 #include <gtest/internal/gtest-internal.h>
16 #include <string>
17 #include "device/bluetooth/dbus/bluetooth_gatt_application_service_provider.h"
18
19 namespace bluez {
20
21 namespace {
22
23 const char kAppObjectPath[] = "/fake/hci0/gatt_application";
24 const char kFakeServiceUuid[] = "00000000-0000-0000-0000-010040008000";
25 const char kFakeCharacteristicUuid[] = "00000000-0000-0000-0000-010040908000";
26 const char kFakeDescriptorUuid[] = "00000000-0000-0000-0000-018390008000";
27
28 // This is really ugly, but it really is the best way to verify our message
29 // was constructed correctly. This string was generated from the test data
30 // and then manually verified to match the expected signature.
31 const char kExpectedMessage[] =
32 "message_type: MESSAGE_METHOD_RETURN\n"
33 "signature: a(oa(sa{sv}))\n"
34 "reply_serial: 123\n"
35 "\n"
36 "array [\n"
37 " struct {\n"
38 " object_path \"/fake/hci0/gatt_application/service0\"\n"
39 " array [\n"
40 " struct {\n"
41 " string \"org.bluez.GattService1\"\n"
42 " array [\n"
43 " dict entry {\n"
44 " string \"UUID\"\n"
45 " variant string "
46 "\"00000000-0000-0000-0000-010040008000\"\n"
47 " }\n"
48 " dict entry {\n"
49 " string \"Includes\"\n"
50 " variant array [\n"
51 " ]\n"
52 " }\n"
53 " ]\n"
54 " }\n"
55 " ]\n"
56 " }\n"
57 " struct {\n"
58 " object_path \"/fake/hci0/gatt_application/service1\"\n"
59 " array [\n"
60 " struct {\n"
61 " string \"org.bluez.GattService1\"\n"
62 " array [\n"
63 " dict entry {\n"
64 " string \"UUID\"\n"
65 " variant string "
66 "\"00000000-0000-0000-0000-010040008000\"\n"
67 " }\n"
68 " dict entry {\n"
69 " string \"Includes\"\n"
70 " variant array [\n"
71 " ]\n"
72 " }\n"
73 " ]\n"
74 " }\n"
75 " ]\n"
76 " }\n"
77 " struct {\n"
78 " object_path \"/fake/hci0/gatt_application/service0/characteristic0\"\n"
79 " array [\n"
80 " struct {\n"
81 " string \"org.bluez.GattCharacteristic1\"\n"
82 " array [\n"
83 " dict entry {\n"
84 " string \"UUID\"\n"
85 " variant string "
86 "\"00000000-0000-0000-0000-010040908000\"\n"
87 " }\n"
88 " dict entry {\n"
89 " string \"Service\"\n"
90 " variant object_path "
91 "\"/fake/hci0/gatt_application/service0\"\n"
92 " }\n"
93 " ]\n"
94 " }\n"
95 " ]\n"
96 " }\n"
97 " struct {\n"
98 " object_path \"/fake/hci0/gatt_application/service0/characteristic1\"\n"
99 " array [\n"
100 " struct {\n"
101 " string \"org.bluez.GattCharacteristic1\"\n"
102 " array [\n"
103 " dict entry {\n"
104 " string \"UUID\"\n"
105 " variant string "
106 "\"00000000-0000-0000-0000-010040908000\"\n"
107 " }\n"
108 " dict entry {\n"
109 " string \"Service\"\n"
110 " variant object_path "
111 "\"/fake/hci0/gatt_application/service0\"\n"
112 " }\n"
113 " ]\n"
114 " }\n"
115 " ]\n"
116 " }\n"
117 " struct {\n"
118 " object_path \"/fake/hci0/gatt_application/service1/characteristic0\"\n"
119 " array [\n"
120 " struct {\n"
121 " string \"org.bluez.GattCharacteristic1\"\n"
122 " array [\n"
123 " dict entry {\n"
124 " string \"UUID\"\n"
125 " variant string "
126 "\"00000000-0000-0000-0000-010040908000\"\n"
127 " }\n"
128 " dict entry {\n"
129 " string \"Service\"\n"
130 " variant object_path "
131 "\"/fake/hci0/gatt_application/service1\"\n"
132 " }\n"
133 " ]\n"
134 " }\n"
135 " ]\n"
136 " }\n"
137 " struct {\n"
138 " object_path "
139 "\"/fake/hci0/gatt_application/service0/characteristic0/descriptor0\"\n"
140 " array [\n"
141 " struct {\n"
142 " string \"org.bluez.GattDescriptor1\"\n"
143 " array [\n"
144 " dict entry {\n"
145 " string \"UUID\"\n"
146 " variant string "
147 "\"00000000-0000-0000-0000-018390008000\"\n"
148 " }\n"
149 " dict entry {\n"
150 " string \"Characteristic\"\n"
151 " variant object_path "
152 "\"/fake/hci0/gatt_application/service0/characteristic0\"\n"
153 " }\n"
154 " ]\n"
155 " }\n"
156 " ]\n"
157 " }\n"
158 " struct {\n"
159 " object_path "
160 "\"/fake/hci0/gatt_application/service0/characteristic1/descriptor1\"\n"
161 " array [\n"
162 " struct {\n"
163 " string \"org.bluez.GattDescriptor1\"\n"
164 " array [\n"
165 " dict entry {\n"
166 " string \"UUID\"\n"
167 " variant string "
168 "\"00000000-0000-0000-0000-018390008000\"\n"
169 " }\n"
170 " dict entry {\n"
171 " string \"Characteristic\"\n"
172 " variant object_path "
173 "\"/fake/hci0/gatt_application/service0/characteristic1\"\n"
174 " }\n"
175 " ]\n"
176 " }\n"
177 " ]\n"
178 " }\n"
179 " struct {\n"
180 " object_path "
181 "\"/fake/hci0/gatt_application/service1/characteristic0/descriptor2\"\n"
182 " array [\n"
183 " struct {\n"
184 " string \"org.bluez.GattDescriptor1\"\n"
185 " array [\n"
186 " dict entry {\n"
187 " string \"UUID\"\n"
188 " variant string "
189 "\"00000000-0000-0000-0000-018390008000\"\n"
190 " }\n"
191 " dict entry {\n"
192 " string \"Characteristic\"\n"
193 " variant object_path "
194 "\"/fake/hci0/gatt_application/service1/characteristic0\"\n"
195 " }\n"
196 " ]\n"
197 " }\n"
198 " ]\n"
199 " }\n"
200 " struct {\n"
201 " object_path "
202 "\"/fake/hci0/gatt_application/service0/characteristic0/descriptor3\"\n"
203 " array [\n"
204 " struct {\n"
205 " string \"org.bluez.GattDescriptor1\"\n"
206 " array [\n"
207 " dict entry {\n"
208 " string \"UUID\"\n"
209 " variant string "
210 "\"00000000-0000-0000-0000-018390008000\"\n"
211 " }\n"
212 " dict entry {\n"
213 " string \"Characteristic\"\n"
214 " variant object_path "
215 "\"/fake/hci0/gatt_application/service0/characteristic0\"\n"
216 " }\n"
217 " ]\n"
218 " }\n"
219 " ]\n"
220 " }\n"
221 "]\n";
222
223 void ResponseSenderCallback(const std::string& expected_message,
224 std::unique_ptr<dbus::Response> response) {
225 EXPECT_EQ(expected_message, response->ToString());
226 }
227
228 } // namespace
229
230 class BluetoothGattApplicationServiceProviderTest : public testing::Test {
231 public:
232 std::string CreateFakeService(
233 dbus::Bus* bus,
234 BluetoothGattApplicationServiceProviderImpl* app_provider,
235 const std::string& service_path) {
236 const std::string& full_service_path =
237 std::string(kAppObjectPath) + "/" + service_path;
238 app_provider->service_providers_.push_back(
239 base::WrapUnique(new BluetoothGattServiceServiceProviderImpl(
240 dbus::ObjectPath(full_service_path), kFakeServiceUuid)));
241 return full_service_path;
242 }
243
244 std::string CreateFakeCharacteristic(
245 dbus::Bus* bus,
246 BluetoothGattApplicationServiceProviderImpl* app_provider,
247 const std::string& characteristic_path,
248 const std::string& service_path) {
249 const std::string& full_characteristic_path =
250 service_path + "/" + characteristic_path;
251 app_provider->characteristic_providers_.push_back(
252 base::WrapUnique(new BluetoothGattCharacteristicServiceProviderImpl(
253 dbus::ObjectPath(full_characteristic_path), kFakeCharacteristicUuid,
254 dbus::ObjectPath(service_path))));
255 return full_characteristic_path;
256 }
257
258 void CreateFakeDescriptor(
259 dbus::Bus* bus,
260 BluetoothGattApplicationServiceProviderImpl* app_provider,
261 const std::string& descriptor_path,
262 const std::string& characteristic_path) {
263 const std::string& full_descriptor_path =
264 characteristic_path + "/" + descriptor_path;
265 app_provider->descriptor_providers_.push_back(
266 base::WrapUnique(new BluetoothGattDescriptorServiceProviderImpl(
267 dbus::ObjectPath(full_descriptor_path), kFakeDescriptorUuid,
268 dbus::ObjectPath(characteristic_path))));
269 }
270
271 void CreateFakeAttributes(
272 dbus::Bus* bus,
273 BluetoothGattApplicationServiceProviderImpl* app_provider) {
274 const std::string& kServicePath1 =
275 CreateFakeService(bus, app_provider, "service0");
276 const std::string& kServicePath2 =
277 CreateFakeService(bus, app_provider, "service1");
278
279 const std::string& kCharacteristicPath1 = CreateFakeCharacteristic(
280 bus, app_provider, "characteristic0", kServicePath1);
281 const std::string& kCharacteristicPath2 = CreateFakeCharacteristic(
282 bus, app_provider, "characteristic1", kServicePath1);
283 const std::string& kCharacteristicPath3 = CreateFakeCharacteristic(
284 bus, app_provider, "characteristic0", kServicePath2);
285
286 CreateFakeDescriptor(bus, app_provider, "descriptor0",
287 kCharacteristicPath1);
288 CreateFakeDescriptor(bus, app_provider, "descriptor1",
289 kCharacteristicPath2);
290 CreateFakeDescriptor(bus, app_provider, "descriptor2",
291 kCharacteristicPath3);
292 CreateFakeDescriptor(bus, app_provider, "descriptor3",
293 kCharacteristicPath1);
294 }
295 };
296
297 TEST_F(BluetoothGattApplicationServiceProviderTest, GetManagedObjects) {
298 std::unique_ptr<BluetoothGattApplicationServiceProviderImpl> app_provider =
299 base::WrapUnique(new BluetoothGattApplicationServiceProviderImpl(
300 dbus::ObjectPath(kAppObjectPath)));
301 CreateFakeAttributes(nullptr, app_provider.get());
302
303 dbus::MethodCall method_call("com.example.Interface", "SomeMethod");
304 // Not setting the serial causes a crash.
305 method_call.SetSerial(123);
306 app_provider->GetManagedObjects(
307 &method_call, base::Bind(&ResponseSenderCallback, kExpectedMessage));
308 }
309
310 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698