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

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

Issue 1919683002: Adapter changes for implementing local GATT attributes and tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dbus_classes
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 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<TestBluetoothLocalGattServiceDelegate*>(
145 service_bluez->GetDelegate())
146 ->set_expected_characteristic(characteristic);
147
148 base::RunLoop run_loop;
149 characteristic_provider->GetValue(
150 base::Bind(&GetValueCallback, run_loop.QuitClosure(), value_callback),
151 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback));
152 run_loop.Run();
103 } 153 }
154
155 void BluetoothTestBlueZ::SimulateLocalGattCharacteristicValueWriteRequest(
156 BluetoothLocalGattService* service,
157 BluetoothLocalGattCharacteristic* characteristic,
158 const std::vector<uint8_t>& value_to_write,
159 const base::Closure& success_callback,
160 const base::Closure& error_callback) {
161 bluez::BluetoothLocalGattCharacteristicBlueZ* characteristic_bluez =
162 static_cast<bluez::BluetoothLocalGattCharacteristicBlueZ*>(
163 characteristic);
164 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
165 static_cast<bluez::FakeBluetoothGattManagerClient*>(
166 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
167 bluez::FakeBluetoothGattCharacteristicServiceProvider*
168 characteristic_provider =
169 fake_bluetooth_gatt_manager_client->GetCharacteristicServiceProvider(
170 characteristic_bluez->object_path());
171
172 bluez::BluetoothLocalGattServiceBlueZ* service_bluez =
173 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>(service);
174 static_cast<TestBluetoothLocalGattServiceDelegate*>(
175 service_bluez->GetDelegate())
176 ->set_expected_characteristic(characteristic);
177
178 base::RunLoop run_loop;
179 characteristic_provider->SetValue(
180 value_to_write,
181 base::Bind(&ClosureCallback, run_loop.QuitClosure(), success_callback),
182 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback));
183 run_loop.Run();
184 }
185
186 void BluetoothTestBlueZ::SimulateLocalGattDescriptorValueReadRequest(
187 BluetoothLocalGattService* service,
188 BluetoothLocalGattDescriptor* descriptor,
189 const BluetoothLocalGattService::Delegate::ValueCallback& value_callback,
190 const base::Closure& error_callback) {
191 bluez::BluetoothLocalGattDescriptorBlueZ* descriptor_bluez =
192 static_cast<bluez::BluetoothLocalGattDescriptorBlueZ*>(descriptor);
193 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
194 static_cast<bluez::FakeBluetoothGattManagerClient*>(
195 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
196 bluez::FakeBluetoothGattDescriptorServiceProvider* descriptor_provider =
197 fake_bluetooth_gatt_manager_client->GetDescriptorServiceProvider(
198 descriptor_bluez->object_path());
199
200 bluez::BluetoothLocalGattServiceBlueZ* service_bluez =
201 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>(service);
202 static_cast<TestBluetoothLocalGattServiceDelegate*>(
203 service_bluez->GetDelegate())
204 ->set_expected_descriptor(descriptor);
205
206 base::RunLoop run_loop;
207 descriptor_provider->GetValue(
208 base::Bind(&GetValueCallback, run_loop.QuitClosure(), value_callback),
209 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback));
210 run_loop.Run();
211 }
212
213 void BluetoothTestBlueZ::SimulateLocalGattDescriptorValueWriteRequest(
214 BluetoothLocalGattService* service,
215 BluetoothLocalGattDescriptor* descriptor,
216 const std::vector<uint8_t>& value_to_write,
217 const base::Closure& success_callback,
218 const base::Closure& error_callback) {
219 bluez::BluetoothLocalGattDescriptorBlueZ* descriptor_bluez =
220 static_cast<bluez::BluetoothLocalGattDescriptorBlueZ*>(descriptor);
221 bluez::FakeBluetoothGattManagerClient* fake_bluetooth_gatt_manager_client =
222 static_cast<bluez::FakeBluetoothGattManagerClient*>(
223 bluez::BluezDBusManager::Get()->GetBluetoothGattManagerClient());
224 bluez::FakeBluetoothGattDescriptorServiceProvider* descriptor_provider =
225 fake_bluetooth_gatt_manager_client->GetDescriptorServiceProvider(
226 descriptor_bluez->object_path());
227
228 bluez::BluetoothLocalGattServiceBlueZ* service_bluez =
229 static_cast<bluez::BluetoothLocalGattServiceBlueZ*>(service);
230 static_cast<TestBluetoothLocalGattServiceDelegate*>(
231 service_bluez->GetDelegate())
232 ->set_expected_descriptor(descriptor);
233
234 base::RunLoop run_loop;
235 descriptor_provider->SetValue(
236 value_to_write,
237 base::Bind(&ClosureCallback, run_loop.QuitClosure(), success_callback),
238 base::Bind(&ClosureCallback, run_loop.QuitClosure(), error_callback));
239 run_loop.Run();
240 }
241
242 } // 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