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

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

Issue 1954643002: DBus support for attribute properties and permissions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@register_and_events
Patch Set: 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 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> 5 #include <string>
6 #include <vector>
7
8 #include "base/bind.h"
9 #include "base/memory/ptr_util.h"
10 #include "dbus/bus.h"
11 #include "dbus/message.h"
12 #include "dbus/object_path.h"
17 #include "device/bluetooth/dbus/bluetooth_gatt_application_service_provider.h" 13 #include "device/bluetooth/dbus/bluetooth_gatt_application_service_provider.h"
14 #include "device/bluetooth/dbus/bluetooth_gatt_application_service_provider_impl .h"
15 #include "device/bluetooth/dbus/bluetooth_gatt_characteristic_service_provider_i mpl.h"
16 #include "device/bluetooth/dbus/bluetooth_gatt_descriptor_service_provider_impl. h"
17 #include "device/bluetooth/dbus/bluetooth_gatt_service_service_provider_impl.h"
18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 namespace bluez { 20 namespace bluez {
20 21
21 namespace { 22 namespace {
22 23
23 const char kAppObjectPath[] = "/fake/hci0/gatt_application"; 24 const char kAppObjectPath[] = "/fake/hci0/gatt_application";
24 const char kFakeServiceUuid[] = "00000000-0000-0000-0000-010040008000"; 25 const char kFakeServiceUuid[] = "00000000-0000-0000-0000-010040008000";
25 const char kFakeCharacteristicUuid[] = "00000000-0000-0000-0000-010040908000"; 26 const char kFakeCharacteristicUuid[] = "00000000-0000-0000-0000-010040908000";
26 const char kFakeDescriptorUuid[] = "00000000-0000-0000-0000-018390008000"; 27 const char kFakeDescriptorUuid[] = "00000000-0000-0000-0000-018390008000";
27 28
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 " dict entry {\n" 92 " dict entry {\n"
92 " string \"UUID\"\n" 93 " string \"UUID\"\n"
93 " variant string " 94 " variant string "
94 "\"00000000-0000-0000-0000-010040908000\"\n" 95 "\"00000000-0000-0000-0000-010040908000\"\n"
95 " }\n" 96 " }\n"
96 " dict entry {\n" 97 " dict entry {\n"
97 " string \"Service\"\n" 98 " string \"Service\"\n"
98 " variant object_path " 99 " variant object_path "
99 "\"/fake/hci0/gatt_application/service0\"\n" 100 "\"/fake/hci0/gatt_application/service0\"\n"
100 " }\n" 101 " }\n"
102 " dict entry {\n"
103 " string \"Flags\"\n"
104 " variant array [\n"
105 " string \"read\"\n"
106 " string \"write\"\n"
107 " ]\n"
108 " }\n"
101 " ]\n" 109 " ]\n"
102 " }\n" 110 " }\n"
103 " ]\n" 111 " ]\n"
104 " }\n" 112 " }\n"
105 " dict entry {\n" 113 " dict entry {\n"
106 " object_path \"/fake/hci0/gatt_application/service0/characteristic1\"\n" 114 " object_path \"/fake/hci0/gatt_application/service0/characteristic1\"\n"
107 " array [\n" 115 " array [\n"
108 " dict entry {\n" 116 " dict entry {\n"
109 " string \"org.bluez.GattCharacteristic1\"\n" 117 " string \"org.bluez.GattCharacteristic1\"\n"
110 " array [\n" 118 " array [\n"
111 " dict entry {\n" 119 " dict entry {\n"
112 " string \"UUID\"\n" 120 " string \"UUID\"\n"
113 " variant string " 121 " variant string "
114 "\"00000000-0000-0000-0000-010040908000\"\n" 122 "\"00000000-0000-0000-0000-010040908000\"\n"
115 " }\n" 123 " }\n"
116 " dict entry {\n" 124 " dict entry {\n"
117 " string \"Service\"\n" 125 " string \"Service\"\n"
118 " variant object_path " 126 " variant object_path "
119 "\"/fake/hci0/gatt_application/service0\"\n" 127 "\"/fake/hci0/gatt_application/service0\"\n"
120 " }\n" 128 " }\n"
129 " dict entry {\n"
130 " string \"Flags\"\n"
131 " variant array [\n"
132 " string \"read\"\n"
133 " string \"write\"\n"
134 " ]\n"
135 " }\n"
121 " ]\n" 136 " ]\n"
122 " }\n" 137 " }\n"
123 " ]\n" 138 " ]\n"
124 " }\n" 139 " }\n"
125 " dict entry {\n" 140 " dict entry {\n"
126 " object_path \"/fake/hci0/gatt_application/service1/characteristic0\"\n" 141 " object_path \"/fake/hci0/gatt_application/service1/characteristic0\"\n"
127 " array [\n" 142 " array [\n"
128 " dict entry {\n" 143 " dict entry {\n"
129 " string \"org.bluez.GattCharacteristic1\"\n" 144 " string \"org.bluez.GattCharacteristic1\"\n"
130 " array [\n" 145 " array [\n"
131 " dict entry {\n" 146 " dict entry {\n"
132 " string \"UUID\"\n" 147 " string \"UUID\"\n"
133 " variant string " 148 " variant string "
134 "\"00000000-0000-0000-0000-010040908000\"\n" 149 "\"00000000-0000-0000-0000-010040908000\"\n"
135 " }\n" 150 " }\n"
136 " dict entry {\n" 151 " dict entry {\n"
137 " string \"Service\"\n" 152 " string \"Service\"\n"
138 " variant object_path " 153 " variant object_path "
139 "\"/fake/hci0/gatt_application/service1\"\n" 154 "\"/fake/hci0/gatt_application/service1\"\n"
140 " }\n" 155 " }\n"
156 " dict entry {\n"
157 " string \"Flags\"\n"
158 " variant array [\n"
159 " string \"read\"\n"
160 " string \"write\"\n"
161 " ]\n"
162 " }\n"
141 " ]\n" 163 " ]\n"
142 " }\n" 164 " }\n"
143 " ]\n" 165 " ]\n"
144 " }\n" 166 " }\n"
145 " dict entry {\n" 167 " dict entry {\n"
146 " object_path " 168 " object_path "
147 "\"/fake/hci0/gatt_application/service0/characteristic0/descriptor0\"\n" 169 "\"/fake/hci0/gatt_application/service0/characteristic0/descriptor0\"\n"
148 " array [\n" 170 " array [\n"
149 " dict entry {\n" 171 " dict entry {\n"
150 " string \"org.bluez.GattDescriptor1\"\n" 172 " string \"org.bluez.GattDescriptor1\"\n"
151 " array [\n" 173 " array [\n"
152 " dict entry {\n" 174 " dict entry {\n"
153 " string \"UUID\"\n" 175 " string \"UUID\"\n"
154 " variant string " 176 " variant string "
155 "\"00000000-0000-0000-0000-018390008000\"\n" 177 "\"00000000-0000-0000-0000-018390008000\"\n"
156 " }\n" 178 " }\n"
157 " dict entry {\n" 179 " dict entry {\n"
158 " string \"Characteristic\"\n" 180 " string \"Characteristic\"\n"
159 " variant object_path " 181 " variant object_path "
160 "\"/fake/hci0/gatt_application/service0/characteristic0\"\n" 182 "\"/fake/hci0/gatt_application/service0/characteristic0\"\n"
161 " }\n" 183 " }\n"
184 " dict entry {\n"
185 " string \"Flags\"\n"
186 " variant array [\n"
187 " string \"read\"\n"
188 " string \"write\"\n"
189 " ]\n"
190 " }\n"
162 " ]\n" 191 " ]\n"
163 " }\n" 192 " }\n"
164 " ]\n" 193 " ]\n"
165 " }\n" 194 " }\n"
166 " dict entry {\n" 195 " dict entry {\n"
167 " object_path " 196 " object_path "
168 "\"/fake/hci0/gatt_application/service0/characteristic1/descriptor1\"\n" 197 "\"/fake/hci0/gatt_application/service0/characteristic1/descriptor1\"\n"
169 " array [\n" 198 " array [\n"
170 " dict entry {\n" 199 " dict entry {\n"
171 " string \"org.bluez.GattDescriptor1\"\n" 200 " string \"org.bluez.GattDescriptor1\"\n"
172 " array [\n" 201 " array [\n"
173 " dict entry {\n" 202 " dict entry {\n"
174 " string \"UUID\"\n" 203 " string \"UUID\"\n"
175 " variant string " 204 " variant string "
176 "\"00000000-0000-0000-0000-018390008000\"\n" 205 "\"00000000-0000-0000-0000-018390008000\"\n"
177 " }\n" 206 " }\n"
178 " dict entry {\n" 207 " dict entry {\n"
179 " string \"Characteristic\"\n" 208 " string \"Characteristic\"\n"
180 " variant object_path " 209 " variant object_path "
181 "\"/fake/hci0/gatt_application/service0/characteristic1\"\n" 210 "\"/fake/hci0/gatt_application/service0/characteristic1\"\n"
182 " }\n" 211 " }\n"
212 " dict entry {\n"
213 " string \"Flags\"\n"
214 " variant array [\n"
215 " string \"read\"\n"
216 " string \"write\"\n"
217 " ]\n"
218 " }\n"
183 " ]\n" 219 " ]\n"
184 " }\n" 220 " }\n"
185 " ]\n" 221 " ]\n"
186 " }\n" 222 " }\n"
187 " dict entry {\n" 223 " dict entry {\n"
188 " object_path " 224 " object_path "
189 "\"/fake/hci0/gatt_application/service1/characteristic0/descriptor2\"\n" 225 "\"/fake/hci0/gatt_application/service1/characteristic0/descriptor2\"\n"
190 " array [\n" 226 " array [\n"
191 " dict entry {\n" 227 " dict entry {\n"
192 " string \"org.bluez.GattDescriptor1\"\n" 228 " string \"org.bluez.GattDescriptor1\"\n"
193 " array [\n" 229 " array [\n"
194 " dict entry {\n" 230 " dict entry {\n"
195 " string \"UUID\"\n" 231 " string \"UUID\"\n"
196 " variant string " 232 " variant string "
197 "\"00000000-0000-0000-0000-018390008000\"\n" 233 "\"00000000-0000-0000-0000-018390008000\"\n"
198 " }\n" 234 " }\n"
199 " dict entry {\n" 235 " dict entry {\n"
200 " string \"Characteristic\"\n" 236 " string \"Characteristic\"\n"
201 " variant object_path " 237 " variant object_path "
202 "\"/fake/hci0/gatt_application/service1/characteristic0\"\n" 238 "\"/fake/hci0/gatt_application/service1/characteristic0\"\n"
203 " }\n" 239 " }\n"
240 " dict entry {\n"
241 " string \"Flags\"\n"
242 " variant array [\n"
243 " string \"read\"\n"
244 " string \"write\"\n"
245 " ]\n"
246 " }\n"
204 " ]\n" 247 " ]\n"
205 " }\n" 248 " }\n"
206 " ]\n" 249 " ]\n"
207 " }\n" 250 " }\n"
208 " dict entry {\n" 251 " dict entry {\n"
209 " object_path " 252 " object_path "
210 "\"/fake/hci0/gatt_application/service0/characteristic0/descriptor3\"\n" 253 "\"/fake/hci0/gatt_application/service0/characteristic0/descriptor3\"\n"
211 " array [\n" 254 " array [\n"
212 " dict entry {\n" 255 " dict entry {\n"
213 " string \"org.bluez.GattDescriptor1\"\n" 256 " string \"org.bluez.GattDescriptor1\"\n"
214 " array [\n" 257 " array [\n"
215 " dict entry {\n" 258 " dict entry {\n"
216 " string \"UUID\"\n" 259 " string \"UUID\"\n"
217 " variant string " 260 " variant string "
218 "\"00000000-0000-0000-0000-018390008000\"\n" 261 "\"00000000-0000-0000-0000-018390008000\"\n"
219 " }\n" 262 " }\n"
220 " dict entry {\n" 263 " dict entry {\n"
221 " string \"Characteristic\"\n" 264 " string \"Characteristic\"\n"
222 " variant object_path " 265 " variant object_path "
223 "\"/fake/hci0/gatt_application/service0/characteristic0\"\n" 266 "\"/fake/hci0/gatt_application/service0/characteristic0\"\n"
224 " }\n" 267 " }\n"
268 " dict entry {\n"
269 " string \"Flags\"\n"
270 " variant array [\n"
271 " string \"read\"\n"
272 " string \"write\"\n"
273 " ]\n"
274 " }\n"
225 " ]\n" 275 " ]\n"
226 " }\n" 276 " }\n"
227 " ]\n" 277 " ]\n"
228 " }\n" 278 " }\n"
229 "]\n"; 279 "]\n";
230 280
231 void ResponseSenderCallback(const std::string& expected_message, 281 void ResponseSenderCallback(const std::string& expected_message,
232 std::unique_ptr<dbus::Response> response) { 282 std::unique_ptr<dbus::Response> response) {
233 EXPECT_EQ(expected_message, response->ToString()); 283 EXPECT_EQ(expected_message, response->ToString());
234 } 284 }
235 285
236 } // namespace 286 } // namespace
237 287
238 class BluetoothGattApplicationServiceProviderTest : public testing::Test { 288 class BluetoothGattApplicationServiceProviderTest : public testing::Test {
239 public: 289 public:
240 std::string CreateFakeService( 290 std::string CreateFakeService(
241 dbus::Bus* bus, 291 dbus::Bus* bus,
242 BluetoothGattApplicationServiceProviderImpl* app_provider, 292 BluetoothGattApplicationServiceProviderImpl* app_provider,
243 const std::string& service_path) { 293 const std::string& service_path) {
244 const std::string& full_service_path = 294 const std::string& full_service_path =
245 std::string(kAppObjectPath) + "/" + service_path; 295 std::string(kAppObjectPath) + "/" + service_path;
246 app_provider->service_providers_.push_back( 296 app_provider->service_providers_.push_back(
247 base::WrapUnique(new BluetoothGattServiceServiceProviderImpl( 297 base::WrapUnique(new BluetoothGattServiceServiceProviderImpl(
248 dbus::ObjectPath(full_service_path), kFakeServiceUuid, true))); 298 nullptr, dbus::ObjectPath(full_service_path), kFakeServiceUuid,
299 true, std::vector<dbus::ObjectPath>())));
249 return full_service_path; 300 return full_service_path;
250 } 301 }
251 302
252 std::string CreateFakeCharacteristic( 303 std::string CreateFakeCharacteristic(
253 dbus::Bus* bus, 304 dbus::Bus* bus,
254 BluetoothGattApplicationServiceProviderImpl* app_provider, 305 BluetoothGattApplicationServiceProviderImpl* app_provider,
255 const std::string& characteristic_path, 306 const std::string& characteristic_path,
256 const std::string& service_path) { 307 const std::string& service_path) {
257 const std::string& full_characteristic_path = 308 const std::string& full_characteristic_path =
258 service_path + "/" + characteristic_path; 309 service_path + "/" + characteristic_path;
259 app_provider->characteristic_providers_.push_back( 310 app_provider->characteristic_providers_.push_back(
260 base::WrapUnique(new BluetoothGattCharacteristicServiceProviderImpl( 311 base::WrapUnique(new BluetoothGattCharacteristicServiceProviderImpl(
261 dbus::ObjectPath(full_characteristic_path), kFakeCharacteristicUuid, 312 nullptr, dbus::ObjectPath(full_characteristic_path), nullptr,
313 kFakeCharacteristicUuid,
314 std::vector<std::string>({"read", "write"}),
262 dbus::ObjectPath(service_path)))); 315 dbus::ObjectPath(service_path))));
263 return full_characteristic_path; 316 return full_characteristic_path;
264 } 317 }
265 318
266 void CreateFakeDescriptor( 319 void CreateFakeDescriptor(
267 dbus::Bus* bus, 320 dbus::Bus* bus,
268 BluetoothGattApplicationServiceProviderImpl* app_provider, 321 BluetoothGattApplicationServiceProviderImpl* app_provider,
269 const std::string& descriptor_path, 322 const std::string& descriptor_path,
270 const std::string& characteristic_path) { 323 const std::string& characteristic_path) {
271 const std::string& full_descriptor_path = 324 const std::string& full_descriptor_path =
272 characteristic_path + "/" + descriptor_path; 325 characteristic_path + "/" + descriptor_path;
273 app_provider->descriptor_providers_.push_back( 326 app_provider->descriptor_providers_.push_back(
274 base::WrapUnique(new BluetoothGattDescriptorServiceProviderImpl( 327 base::WrapUnique(new BluetoothGattDescriptorServiceProviderImpl(
275 dbus::ObjectPath(full_descriptor_path), kFakeDescriptorUuid, 328 nullptr, dbus::ObjectPath(full_descriptor_path), nullptr,
329 kFakeDescriptorUuid, std::vector<std::string>({"read", "write"}),
276 dbus::ObjectPath(characteristic_path)))); 330 dbus::ObjectPath(characteristic_path))));
277 } 331 }
278 332
279 void CreateFakeAttributes( 333 void CreateFakeAttributes(
280 dbus::Bus* bus, 334 dbus::Bus* bus,
281 BluetoothGattApplicationServiceProviderImpl* app_provider) { 335 BluetoothGattApplicationServiceProviderImpl* app_provider) {
282 const std::string& kServicePath1 = 336 const std::string& kServicePath1 =
283 CreateFakeService(bus, app_provider, "service0"); 337 CreateFakeService(bus, app_provider, "service0");
284 const std::string& kServicePath2 = 338 const std::string& kServicePath2 =
285 CreateFakeService(bus, app_provider, "service1"); 339 CreateFakeService(bus, app_provider, "service1");
(...skipping 23 matching lines...) Expand all
309 CreateFakeAttributes(nullptr, app_provider.get()); 363 CreateFakeAttributes(nullptr, app_provider.get());
310 364
311 dbus::MethodCall method_call("com.example.Interface", "SomeMethod"); 365 dbus::MethodCall method_call("com.example.Interface", "SomeMethod");
312 // Not setting the serial causes a crash. 366 // Not setting the serial causes a crash.
313 method_call.SetSerial(123); 367 method_call.SetSerial(123);
314 app_provider->GetManagedObjects( 368 app_provider->GetManagedObjects(
315 &method_call, base::Bind(&ResponseSenderCallback, kExpectedMessage)); 369 &method_call, base::Bind(&ResponseSenderCallback, kExpectedMessage));
316 } 370 }
317 371
318 } // namespace bluez 372 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698