| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "device/bluetooth/test/bluetooth_test_bluez.h" |
| 6 |
| 7 #include <iterator> |
| 8 #include <sstream> |
| 9 |
| 10 #include "base/logging.h" |
| 11 #include "base/run_loop.h" |
| 12 #include "device/bluetooth/bluetooth_adapter_bluez.h" |
| 13 #include "device/bluetooth/bluetooth_device_bluez.h" |
| 14 #include "device/bluetooth/bluetooth_gatt_descriptor_bluez.h" |
| 15 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_bluez.h" |
| 16 #include "device/bluetooth/bluetooth_remote_gatt_service_bluez.h" |
| 17 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 18 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" |
| 19 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" |
| 20 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" |
| 21 |
| 22 namespace device { |
| 23 |
| 24 namespace { |
| 25 |
| 26 void AdapterCallback(base::Closure quit_closure) { |
| 27 quit_closure.Run(); |
| 28 } |
| 29 } |
| 30 |
| 31 BluetoothTestBlueZ::BluetoothTestBlueZ() |
| 32 : fake_bluetooth_device_client_(nullptr) {} |
| 33 |
| 34 BluetoothTestBlueZ::~BluetoothTestBlueZ() {} |
| 35 |
| 36 void BluetoothTestBlueZ::SetUp() { |
| 37 std::unique_ptr<bluez::BluezDBusManagerSetter> dbus_setter = |
| 38 bluez::BluezDBusManager::GetSetterForTesting(); |
| 39 fake_bluetooth_device_client_ = new bluez::FakeBluetoothDeviceClient; |
| 40 // 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 |
| 42 // 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. |
| 44 fake_bluetooth_device_client_->RemoveAllDevices(); |
| 45 dbus_setter->SetBluetoothDeviceClient( |
| 46 std::unique_ptr<bluez::BluetoothDeviceClient>( |
| 47 fake_bluetooth_device_client_)); |
| 48 } |
| 49 |
| 50 void BluetoothTestBlueZ::TearDown() { |
| 51 adapter_ = nullptr; |
| 52 bluez::BluezDBusManager::Shutdown(); |
| 53 } |
| 54 |
| 55 bool BluetoothTestBlueZ::PlatformSupportsLowEnergy() { |
| 56 return true; |
| 57 } |
| 58 |
| 59 void BluetoothTestBlueZ::InitWithFakeAdapter() { |
| 60 base::RunLoop run_loop; |
| 61 adapter_ = new bluez::BluetoothAdapterBlueZ( |
| 62 base::Bind(&AdapterCallback, run_loop.QuitClosure())); |
| 63 run_loop.Run(); |
| 64 } |
| 65 |
| 66 BluetoothDevice* BluetoothTestBlueZ::DiscoverLowEnergyDevice( |
| 67 int device_ordinal) { |
| 68 if (device_ordinal > 4 || device_ordinal < 1) |
| 69 return nullptr; |
| 70 |
| 71 std::string device_name = kTestDeviceName; |
| 72 std::string device_address = kTestDeviceAddress1; |
| 73 std::vector<std::string> service_uuids; |
| 74 |
| 75 switch (device_ordinal) { |
| 76 case 1: |
| 77 service_uuids.push_back(kTestUUIDGenericAccess); |
| 78 service_uuids.push_back(kTestUUIDGenericAttribute); |
| 79 break; |
| 80 case 2: |
| 81 service_uuids.push_back(kTestUUIDImmediateAlert); |
| 82 service_uuids.push_back(kTestUUIDLinkLoss); |
| 83 break; |
| 84 case 3: |
| 85 device_name = kTestDeviceNameEmpty; |
| 86 break; |
| 87 case 4: |
| 88 device_name = kTestDeviceNameEmpty; |
| 89 device_address = kTestDeviceAddress2; |
| 90 break; |
| 91 } |
| 92 |
| 93 if (!adapter_->GetDevice(device_address)) { |
| 94 fake_bluetooth_device_client_->CreateTestDevice( |
| 95 dbus::ObjectPath(bluez::FakeBluetoothAdapterClient::kAdapterPath), |
| 96 device_name /* name */, device_name /* alias */, device_address, |
| 97 service_uuids); |
| 98 } |
| 99 BluetoothDevice* device = adapter_->GetDevice(device_address); |
| 100 |
| 101 return device; |
| 102 } |
| 103 } |
| OLD | NEW |