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

Side by Side Diff: device/bluetooth/test/bluetooth_test_bluez.cc

Issue 1979163002: Add DBus plumbing and tests for sending devices with ATT read/writes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@devices
Patch Set: gyp 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "device/bluetooth/test/bluetooth_test_bluez.h" 5 #include "device/bluetooth/test/bluetooth_test_bluez.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/run_loop.h" 13 #include "base/run_loop.h"
13 #include "dbus/object_path.h" 14 #include "dbus/object_path.h"
14 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" 15 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h"
16 #include "device/bluetooth/bluez/bluetooth_device_bluez.h"
15 #include "device/bluetooth/bluez/bluetooth_gatt_characteristic_bluez.h" 17 #include "device/bluetooth/bluez/bluetooth_gatt_characteristic_bluez.h"
16 #include "device/bluetooth/bluez/bluetooth_gatt_descriptor_bluez.h" 18 #include "device/bluetooth/bluez/bluetooth_gatt_descriptor_bluez.h"
17 #include "device/bluetooth/bluez/bluetooth_local_gatt_characteristic_bluez.h" 19 #include "device/bluetooth/bluez/bluetooth_local_gatt_characteristic_bluez.h"
18 #include "device/bluetooth/bluez/bluetooth_local_gatt_descriptor_bluez.h" 20 #include "device/bluetooth/bluez/bluetooth_local_gatt_descriptor_bluez.h"
21 #include "device/bluetooth/bluez/bluetooth_local_gatt_service_bluez.h"
19 #include "device/bluetooth/dbus/bluez_dbus_manager.h" 22 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
20 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" 23 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h"
21 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" 24 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h"
22 #include "device/bluetooth/dbus/fake_bluetooth_gatt_characteristic_service_provi der.h" 25 #include "device/bluetooth/dbus/fake_bluetooth_gatt_characteristic_service_provi der.h"
23 #include "device/bluetooth/dbus/fake_bluetooth_gatt_descriptor_service_provider. h" 26 #include "device/bluetooth/dbus/fake_bluetooth_gatt_descriptor_service_provider. h"
24 #include "device/bluetooth/dbus/fake_bluetooth_gatt_manager_client.h" 27 #include "device/bluetooth/dbus/fake_bluetooth_gatt_manager_client.h"
25 #include "device/bluetooth/test/bluetooth_gatt_server_test.h" 28 #include "device/bluetooth/test/test_bluetooth_local_gatt_service_delegate.h"
26 29
27 namespace device { 30 namespace device {
28 31
29 namespace { 32 namespace {
30 33
31 void AdapterCallback(const base::Closure& quit_closure) { 34 void AdapterCallback(const base::Closure& quit_closure) {
32 quit_closure.Run(); 35 quit_closure.Run();
33 } 36 }
34 37
35 void GetValueCallback( 38 void GetValueCallback(
36 const base::Closure& quit_closure, 39 const base::Closure& quit_closure,
37 const BluetoothLocalGattService::Delegate::ValueCallback& value_callback, 40 const BluetoothLocalGattService::Delegate::ValueCallback& value_callback,
38 const std::vector<uint8_t>& value) { 41 const std::vector<uint8_t>& value) {
39 value_callback.Run(value); 42 value_callback.Run(value);
40 quit_closure.Run(); 43 quit_closure.Run();
41 } 44 }
42 45
43 void ClosureCallback(const base::Closure& quit_closure, 46 void ClosureCallback(const base::Closure& quit_closure,
44 const base::Closure& callback) { 47 const base::Closure& callback) {
45 callback.Run(); 48 callback.Run();
46 quit_closure.Run(); 49 quit_closure.Run();
47 } 50 }
48 51
52 dbus::ObjectPath GetDevicePath(BluetoothDevice* device) {
53 bluez::BluetoothDeviceBlueZ* device_bluez =
54 static_cast<bluez::BluetoothDeviceBlueZ*>(device);
55 return device_bluez->object_path();
56 }
57
49 } // namespace 58 } // namespace
50 59
51 BluetoothTestBlueZ::BluetoothTestBlueZ() 60 BluetoothTestBlueZ::BluetoothTestBlueZ()
52 : fake_bluetooth_device_client_(nullptr) {} 61 : fake_bluetooth_device_client_(nullptr) {}
53 62
54 BluetoothTestBlueZ::~BluetoothTestBlueZ() {} 63 BluetoothTestBlueZ::~BluetoothTestBlueZ() {}
55 64
56 void BluetoothTestBlueZ::SetUp() { 65 void BluetoothTestBlueZ::SetUp() {
57 BluetoothTestBase::SetUp(); 66 BluetoothTestBase::SetUp();
58 std::unique_ptr<bluez::BluezDBusManagerSetter> dbus_setter = 67 std::unique_ptr<bluez::BluezDBusManagerSetter> dbus_setter =
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 126 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
118 device_name /* name */, device_name /* alias */, device_address, 127 device_name /* name */, device_name /* alias */, device_address,
119 service_uuids); 128 service_uuids);
120 } 129 }
121 BluetoothDevice* device = adapter_->GetDevice(device_address); 130 BluetoothDevice* device = adapter_->GetDevice(device_address);
122 131
123 return device; 132 return device;
124 } 133 }
125 134
126 void BluetoothTestBlueZ::SimulateLocalGattCharacteristicValueReadRequest( 135 void BluetoothTestBlueZ::SimulateLocalGattCharacteristicValueReadRequest(
136 BluetoothDevice* from_device,
127 BluetoothLocalGattCharacteristic* characteristic, 137 BluetoothLocalGattCharacteristic* characteristic,
128 const BluetoothLocalGattService::Delegate::ValueCallback& value_callback, 138 const BluetoothLocalGattService::Delegate::ValueCallback& value_callback,
129 const base::Closure& error_callback) { 139 const base::Closure& error_callback) {
130 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez = 140 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez =
131 static_cast<bluez::BluetoothLocalGattCharacteristicBlueZ*>( 141 static_cast<bluez::BluetoothLocalGattCharacteristicBlueZ*>(
132 characteristic); 142 characteristic);
133 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = 143 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
134 static_cast<bluez::FakeBluetoothGattManagerClient*>( 144 static_cast<bluez::FakeBluetoothGattManagerClient*>(
135 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); 145 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
136 bluez::FakeBluetoothGattCharacteristicServiceProvider* 146 bluez::FakeBluetoothGattCharacteristicServiceProvider*
137 characteristic_provider = 147 characteristic_provider =
138 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider( 148 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider(
139 characteristic_bluez->object_path()); 149 characteristic_bluez->object_path());
140 150
141 bluez::BluetoothLocalGattServiceBlueZ* service_bluez = 151 bluez::BluetoothLocalGattServiceBlueZ* service_bluez =
142 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>( 152 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>(
143 characteristic->GetService()); 153 characteristic->GetService());
144 static_cast<TestBluetoothLocalGattServiceDelegate*>( 154 static_cast<TestBluetoothLocalGattServiceDelegate*>(
145 service_bluez->GetDelegate()) 155 service_bluez->GetDelegate())
146 ->set_expected_characteristic(characteristic); 156 ->set_expected_characteristic(characteristic);
147 157
148 base::RunLoop run_loop; 158 base::RunLoop run_loop;
149 characteristic_provider->GetValue( 159 characteristic_provider->GetValue(
160 GetDevicePath(from_device),
150 base::Bind(&GetValueCallback, run_loop.QuitClosure(), value_callback), 161 base::Bind(&GetValueCallback, run_loop.QuitClosure(), value_callback),
151 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback)); 162 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback));
152 run_loop.Run(); 163 run_loop.Run();
153 } 164 }
154 165
155 void BluetoothTestBlueZ::SimulateLocalGattCharacteristicValueWriteRequest( 166 void BluetoothTestBlueZ::SimulateLocalGattCharacteristicValueWriteRequest(
167 BluetoothDevice* from_device,
156 BluetoothLocalGattCharacteristic* characteristic, 168 BluetoothLocalGattCharacteristic* characteristic,
157 const std::vector<uint8_t>& value_to_write, 169 const std::vector<uint8_t>& value_to_write,
158 const base::Closure& success_callback, 170 const base::Closure& success_callback,
159 const base::Closure& error_callback) { 171 const base::Closure& error_callback) {
160 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez = 172 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez =
161 static_cast<bluez::BluetoothLocalGattCharacteristicBlueZ*>( 173 static_cast<bluez::BluetoothLocalGattCharacteristicBlueZ*>(
162 characteristic); 174 characteristic);
163 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = 175 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
164 static_cast<bluez::FakeBluetoothGattManagerClient*>( 176 static_cast<bluez::FakeBluetoothGattManagerClient*>(
165 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); 177 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
166 bluez::FakeBluetoothGattCharacteristicServiceProvider* 178 bluez::FakeBluetoothGattCharacteristicServiceProvider*
167 characteristic_provider = 179 characteristic_provider =
168 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider( 180 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider(
169 characteristic_bluez->object_path()); 181 characteristic_bluez->object_path());
170 182
171 bluez::BluetoothLocalGattServiceBlueZ* service_bluez = 183 bluez::BluetoothLocalGattServiceBlueZ* service_bluez =
172 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>( 184 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>(
173 characteristic->GetService()); 185 characteristic->GetService());
174 static_cast<TestBluetoothLocalGattServiceDelegate*>( 186 static_cast<TestBluetoothLocalGattServiceDelegate*>(
175 service_bluez->GetDelegate()) 187 service_bluez->GetDelegate())
176 ->set_expected_characteristic(characteristic); 188 ->set_expected_characteristic(characteristic);
177 189
178 base::RunLoop run_loop; 190 base::RunLoop run_loop;
179 characteristic_provider->SetValue( 191 characteristic_provider->SetValue(
180 value_to_write, 192 GetDevicePath(from_device), value_to_write,
181 base::Bind(&ClosureCallback, run_loop.QuitClosure(), success_callback), 193 base::Bind(&ClosureCallback, run_loop.QuitClosure(), success_callback),
182 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback)); 194 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback));
183 run_loop.Run(); 195 run_loop.Run();
184 } 196 }
185 197
186 void BluetoothTestBlueZ::SimulateLocalGattDescriptorValueReadRequest( 198 void BluetoothTestBlueZ::SimulateLocalGattDescriptorValueReadRequest(
199 BluetoothDevice* from_device,
187 BluetoothLocalGattDescriptor* descriptor, 200 BluetoothLocalGattDescriptor* descriptor,
188 const BluetoothLocalGattService::Delegate::ValueCallback& value_callback, 201 const BluetoothLocalGattService::Delegate::ValueCallback& value_callback,
189 const base::Closure& error_callback) { 202 const base::Closure& error_callback) {
190 bluez::BluetoothLocalGattDescriptorBlueZ* descriptor_bluez = 203 bluez::BluetoothLocalGattDescriptorBlueZ* descriptor_bluez =
191 static_cast<bluez::BluetoothLocalGattDescriptorBlueZ*>(descriptor); 204 static_cast<bluez::BluetoothLocalGattDescriptorBlueZ*>(descriptor);
192 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = 205 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
193 static_cast<bluez::FakeBluetoothGattManagerClient*>( 206 static_cast<bluez::FakeBluetoothGattManagerClient*>(
194 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); 207 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
195 bluez::FakeBluetoothGattDescriptorServiceProvider* descriptor_provider = 208 bluez::FakeBluetoothGattDescriptorServiceProvider* descriptor_provider =
196 fake_bluetooth_gatt_manager_client->GetDescriptorServiceProvider( 209 fake_bluetooth_gatt_manager_client->GetDescriptorServiceProvider(
197 descriptor_bluez->object_path()); 210 descriptor_bluez->object_path());
198 211
199 bluez::BluetoothLocalGattServiceBlueZ* service_bluez = 212 bluez::BluetoothLocalGattServiceBlueZ* service_bluez =
200 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>( 213 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>(
201 descriptor->GetCharacteristic()->GetService()); 214 descriptor->GetCharacteristic()->GetService());
202 static_cast<TestBluetoothLocalGattServiceDelegate*>( 215 static_cast<TestBluetoothLocalGattServiceDelegate*>(
203 service_bluez->GetDelegate()) 216 service_bluez->GetDelegate())
204 ->set_expected_descriptor(descriptor); 217 ->set_expected_descriptor(descriptor);
205 218
206 base::RunLoop run_loop; 219 base::RunLoop run_loop;
207 descriptor_provider->GetValue( 220 descriptor_provider->GetValue(
221 GetDevicePath(from_device),
208 base::Bind(&GetValueCallback, run_loop.QuitClosure(), value_callback), 222 base::Bind(&GetValueCallback, run_loop.QuitClosure(), value_callback),
209 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback)); 223 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback));
210 run_loop.Run(); 224 run_loop.Run();
211 } 225 }
212 226
213 void BluetoothTestBlueZ::SimulateLocalGattDescriptorValueWriteRequest( 227 void BluetoothTestBlueZ::SimulateLocalGattDescriptorValueWriteRequest(
228 BluetoothDevice* from_device,
214 BluetoothLocalGattDescriptor* descriptor, 229 BluetoothLocalGattDescriptor* descriptor,
215 const std::vector<uint8_t>& value_to_write, 230 const std::vector<uint8_t>& value_to_write,
216 const base::Closure& success_callback, 231 const base::Closure& success_callback,
217 const base::Closure& error_callback) { 232 const base::Closure& error_callback) {
218 bluez::BluetoothLocalGattDescriptorBlueZ* descriptor_bluez = 233 bluez::BluetoothLocalGattDescriptorBlueZ* descriptor_bluez =
219 static_cast<bluez::BluetoothLocalGattDescriptorBlueZ*>(descriptor); 234 static_cast<bluez::BluetoothLocalGattDescriptorBlueZ*>(descriptor);
220 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client = 235 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
221 static_cast<bluez::FakeBluetoothGattManagerClient*>( 236 static_cast<bluez::FakeBluetoothGattManagerClient*>(
222 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient()); 237 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
223 bluez::FakeBluetoothGattDescriptorServiceProvider* descriptor_provider = 238 bluez::FakeBluetoothGattDescriptorServiceProvider* descriptor_provider =
224 fake_bluetooth_gatt_manager_client->GetDescriptorServiceProvider( 239 fake_bluetooth_gatt_manager_client->GetDescriptorServiceProvider(
225 descriptor_bluez->object_path()); 240 descriptor_bluez->object_path());
226 241
227 bluez::BluetoothLocalGattServiceBlueZ* service_bluez = 242 bluez::BluetoothLocalGattServiceBlueZ* service_bluez =
228 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>( 243 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>(
229 descriptor->GetCharacteristic()->GetService()); 244 descriptor->GetCharacteristic()->GetService());
230 static_cast<TestBluetoothLocalGattServiceDelegate*>( 245 static_cast<TestBluetoothLocalGattServiceDelegate*>(
231 service_bluez->GetDelegate()) 246 service_bluez->GetDelegate())
232 ->set_expected_descriptor(descriptor); 247 ->set_expected_descriptor(descriptor);
233 248
234 base::RunLoop run_loop; 249 base::RunLoop run_loop;
235 descriptor_provider->SetValue( 250 descriptor_provider->SetValue(
236 value_to_write, 251 GetDevicePath(from_device), value_to_write,
237 base::Bind(&ClosureCallback, run_loop.QuitClosure(), success_callback), 252 base::Bind(&ClosureCallback, run_loop.QuitClosure(), success_callback),
238 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback)); 253 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback));
239 run_loop.Run(); 254 run_loop.Run();
240 } 255 }
241 256
242 bool BluetoothTestBlueZ::SimulateLocalGattCharacteristicNotificationsRequest( 257 bool BluetoothTestBlueZ::SimulateLocalGattCharacteristicNotificationsRequest(
243 BluetoothLocalGattCharacteristic* characteristic, 258 BluetoothLocalGattCharacteristic* characteristic,
244 bool start) { 259 bool start) {
245 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez = 260 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez =
246 static_cast<bluez::BluetoothLocalGattCharacteristicBlueZ*>( 261 static_cast<bluez::BluetoothLocalGattCharacteristicBlueZ*>(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 std::vector<BluetoothLocalGattService*> services; 300 std::vector<BluetoothLocalGattService*> services;
286 bluez::BluetoothAdapterBlueZ* adapter_bluez = 301 bluez::BluetoothAdapterBlueZ* adapter_bluez =
287 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter_.get()); 302 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter_.get());
288 303
289 for (const auto& iter : adapter_bluez->registered_gatt_services_) 304 for (const auto& iter : adapter_bluez->registered_gatt_services_)
290 services.push_back(iter.second); 305 services.push_back(iter.second);
291 return services; 306 return services;
292 } 307 }
293 308
294 } // namespace device 309 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/test/bluetooth_test_bluez.h ('k') | device/bluetooth/test/test_bluetooth_local_gatt_service_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698