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

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

Issue 1920693002: Complete //device/bt implementation for hosting local GATT attributes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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
« no previous file with comments | « device/bluetooth/test/bluetooth_test_bluez.h ('k') | device/device_tests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <iterator> 7 #include <string>
8 #include <sstream>
9 8
10 #include "base/logging.h" 9 #include "base/bind.h"
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
11 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "dbus/object_path.h"
12 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h" 14 #include "device/bluetooth/bluez/bluetooth_adapter_bluez.h"
13 #include "device/bluetooth/bluez/bluetooth_device_bluez.h" 15 #include "device/bluetooth/bluez/bluetooth_gatt_characteristic_bluez.h"
14 #include "device/bluetooth/bluez/bluetooth_gatt_descriptor_bluez.h" 16 #include "device/bluetooth/bluez/bluetooth_gatt_descriptor_bluez.h"
15 #include "device/bluetooth/bluez/bluetooth_remote_gatt_characteristic_bluez.h" 17 #include "device/bluetooth/bluez/bluetooth_local_gatt_characteristic_bluez.h"
16 #include "device/bluetooth/bluez/bluetooth_remote_gatt_service_bluez.h" 18 #include "device/bluetooth/bluez/bluetooth_local_gatt_descriptor_bluez.h"
17 #include "device/bluetooth/dbus/bluez_dbus_manager.h" 19 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
18 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" 20 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h"
19 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" 21 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h"
20 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" 22 #include "device/bluetooth/dbus/fake_bluetooth_gatt_characteristic_service_provi der.h"
23 #include "device/bluetooth/dbus/fake_bluetooth_gatt_descriptor_service_provider. h"
24 #include "device/bluetooth/dbus/fake_bluetooth_gatt_manager_client.h"
25 #include "device/bluetooth/test/bluetooth_gatt_server_test.h"
21 26
22 namespace device { 27 namespace device {
23 28
24 namespace { 29 namespace {
25 30
26 void AdapterCallback(base::Closure quit_closure) { 31 void AdapterCallback(const base::Closure& quit_closure) {
27 quit_closure.Run(); 32 quit_closure.Run();
28 } 33 }
34
35 void GetValueCallback(
36 const base::Closure& quit_closure,
37 const BluetoothLocalGattService::Delegate::ValueCallback& value_callback,
38 const std::vector<uint8_t>& value) {
39 value_callback.Run(value);
40 quit_closure.Run();
29 } 41 }
30 42
43 void ClosureCallback(const base::Closure& quit_closure,
44 const base::Closure& callback) {
45 callback.Run();
46 quit_closure.Run();
47 }
48
49 } // namespace
50
31 BluetoothTestBlueZ::BluetoothTestBlueZ() 51 BluetoothTestBlueZ::BluetoothTestBlueZ()
32 : fake_bluetooth_device_client_(nullptr) {} 52 : fake_bluetooth_device_client_(nullptr) {}
33 53
34 BluetoothTestBlueZ::~BluetoothTestBlueZ() {} 54 BluetoothTestBlueZ::~BluetoothTestBlueZ() {}
35 55
36 void BluetoothTestBlueZ::SetUp() { 56 void BluetoothTestBlueZ::SetUp() {
57 BluetoothTestBase::SetUp();
37 std::unique_ptr<bluez::BluezDBusManagerSetter> dbus_setter = 58 std::unique_ptr<bluez::BluezDBusManagerSetter> dbus_setter =
38 bluez::BluezDBusManager::GetSetterForTesting(); 59 bluez::BluezDBusManager::GetSetterForTesting();
39 fake_bluetooth_device_client_ = new bluez::FakeBluetoothDeviceClient; 60 fake_bluetooth_device_client_ = new bluez::FakeBluetoothDeviceClient;
40 // TODO(rkc): This is a big hacky. Creating a device client creates three 61 // TODO(rkc): This is a big hacky. Creating a device client creates three
41 // devices by default. For now, the easiest path is to just clear them, but 62 // devices by default. For now, the easiest path is to just clear them, but
42 // a better way will be to only create them as needed. This will require 63 // a better way will be to only create them as needed. This will require
43 // looking at a lot of tests but should be done eventually. 64 // looking at a lot of tests but should be done eventually.
44 fake_bluetooth_device_client_->RemoveAllDevices(); 65 fake_bluetooth_device_client_->RemoveAllDevices();
45 dbus_setter->SetBluetoothDeviceClient( 66 dbus_setter->SetBluetoothDeviceClient(
46 std::unique_ptr<bluez::BluetoothDeviceClient>( 67 std::unique_ptr<bluez::BluetoothDeviceClient>(
47 fake_bluetooth_device_client_)); 68 fake_bluetooth_device_client_));
48 } 69 }
49 70
50 void BluetoothTestBlueZ::TearDown() { 71 void BluetoothTestBlueZ::TearDown() {
51 adapter_ = nullptr; 72 adapter_ = nullptr;
52 bluez::BluezDBusManager::Shutdown(); 73 bluez::BluezDBusManager::Shutdown();
74 BluetoothTestBase::TearDown();
53 } 75 }
54 76
55 bool BluetoothTestBlueZ::PlatformSupportsLowEnergy() { 77 bool BluetoothTestBlueZ::PlatformSupportsLowEnergy() {
56 return true; 78 return true;
57 } 79 }
58 80
59 void BluetoothTestBlueZ::InitWithFakeAdapter() { 81 void BluetoothTestBlueZ::InitWithFakeAdapter() {
60 base::RunLoop run_loop; 82 base::RunLoop run_loop;
61 adapter_ = new bluez::BluetoothAdapterBlueZ( 83 adapter_ = new bluez::BluetoothAdapterBlueZ(
62 base::Bind(&AdapterCallback, run_loop.QuitClosure())); 84 base::Bind(&AdapterCallback, run_loop.QuitClosure()));
(...skipping 30 matching lines...) Expand all
93 if (!adapter_->GetDevice(device_address)) { 115 if (!adapter_->GetDevice(device_address)) {
94 fake_bluetooth_device_client_->CreateTestDevice( 116 fake_bluetooth_device_client_->CreateTestDevice(
95 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), 117 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath),
96 device_name /* name */, device_name /* alias */, device_address, 118 device_name /* name */, device_name /* alias */, device_address,
97 service_uuids); 119 service_uuids);
98 } 120 }
99 BluetoothDevice* device = adapter_->GetDevice(device_address); 121 BluetoothDevice* device = adapter_->GetDevice(device_address);
100 122
101 return device; 123 return device;
102 } 124 }
125
126 void BluetoothTestBlueZ::SimulateLocalGattCharacteristicValueReadRequest(
127 BluetoothLocalGattService* service,
128 BluetoothLocalGattCharacteristic* characteristic,
129 const BluetoothLocalGattService::Delegate::ValueCallback& value_callback,
130 const base::Closure& error_callback) {
131 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez =
132 static_cast<bluez::BluetoothLocalGattCharacteristicBlueZ*>(
133 characteristic);
134 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
135 static_cast<bluez::FakeBluetoothGattManagerClient*>(
136 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
137 bluez::FakeBluetoothGattCharacteristicServiceProvider*
138 characteristic_provider =
139 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider(
140 characteristic_bluez->object_path());
141
142 bluez::BluetoothLocalGattServiceBlueZ* service_bluez =
143 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>(service);
144 static_cast<TestLocalGattServiceDelegate*>(service_bluez->GetDelegate())
145 ->set_expected_characteristic(characteristic);
146
147 base::RunLoop run_loop;
148 characteristic_provider->GetValue(
149 base::Bind(&GetValueCallback, run_loop.QuitClosure(), value_callback),
150 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback));
151 run_loop.Run();
103 } 152 }
153
154 void BluetoothTestBlueZ::SimulateLocalGattCharacteristicValueWriteRequest(
155 BluetoothLocalGattService* service,
156 BluetoothLocalGattCharacteristic* characteristic,
157 const std::vector<uint8_t>& value_to_write,
158 const base::Closure& success_callback,
159 const base::Closure& error_callback) {
160 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez =
161 static_cast<bluez::BluetoothLocalGattCharacteristicBlueZ*>(
162 characteristic);
163 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
164 static_cast<bluez::FakeBluetoothGattManagerClient*>(
165 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
166 bluez::FakeBluetoothGattCharacteristicServiceProvider*
167 characteristic_provider =
168 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider(
169 characteristic_bluez->object_path());
170
171 bluez::BluetoothLocalGattServiceBlueZ* service_bluez =
172 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>(service);
173 static_cast<TestLocalGattServiceDelegate*>(service_bluez->GetDelegate())
174 ->set_expected_characteristic(characteristic);
175
176 base::RunLoop run_loop;
177 characteristic_provider->SetValue(
178 value_to_write,
179 base::Bind(&ClosureCallback, run_loop.QuitClosure(), success_callback),
180 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback));
181 run_loop.Run();
182 }
183
184 void BluetoothTestBlueZ::SimulateLocalGattDescriptorValueReadRequest(
185 BluetoothLocalGattService* service,
186 BluetoothLocalGattDescriptor* descriptor,
187 const BluetoothLocalGattService::Delegate::ValueCallback& value_callback,
188 const base::Closure& error_callback) {
189 bluez::BluetoothLocalGattDescriptorBlueZ* descriptor_bluez =
190 static_cast<bluez::BluetoothLocalGattDescriptorBlueZ*>(descriptor);
191 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
192 static_cast<bluez::FakeBluetoothGattManagerClient*>(
193 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
194 bluez::FakeBluetoothGattDescriptorServiceProvider* descriptor_provider =
195 fake_bluetooth_gatt_manager_client->GetDescriptorServiceProvider(
196 descriptor_bluez->object_path());
197
198 bluez::BluetoothLocalGattServiceBlueZ* service_bluez =
199 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>(service);
200 static_cast<TestLocalGattServiceDelegate*>(service_bluez->GetDelegate())
201 ->set_expected_descriptor(descriptor);
202
203 base::RunLoop run_loop;
204 descriptor_provider->GetValue(
205 base::Bind(&GetValueCallback, run_loop.QuitClosure(), value_callback),
206 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback));
207 run_loop.Run();
208 }
209
210 void BluetoothTestBlueZ::SimulateLocalGattDescriptorValueWriteRequest(
211 BluetoothLocalGattService* service,
212 BluetoothLocalGattDescriptor* descriptor,
213 const std::vector<uint8_t>& value_to_write,
214 const base::Closure& success_callback,
215 const base::Closure& error_callback) {
216 bluez::BluetoothLocalGattDescriptorBlueZ* descriptor_bluez =
217 static_cast<bluez::BluetoothLocalGattDescriptorBlueZ*>(descriptor);
218 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
219 static_cast<bluez::FakeBluetoothGattManagerClient*>(
220 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
221 bluez::FakeBluetoothGattDescriptorServiceProvider* descriptor_provider =
222 fake_bluetooth_gatt_manager_client->GetDescriptorServiceProvider(
223 descriptor_bluez->object_path());
224
225 bluez::BluetoothLocalGattServiceBlueZ* service_bluez =
226 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>(service);
227 static_cast<TestLocalGattServiceDelegate*>(service_bluez->GetDelegate())
228 ->set_expected_descriptor(descriptor);
229
230 base::RunLoop run_loop;
231 descriptor_provider->SetValue(
232 value_to_write,
233 base::Bind(&ClosureCallback, run_loop.QuitClosure(), success_callback),
234 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback));
235 run_loop.Run();
236 }
237
238 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/test/bluetooth_test_bluez.h ('k') | device/device_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698