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

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

Issue 2640883002: Enable more unittests for BlueZ and ChromeOS. (Closed)
Patch Set: Added comment in TearDown. Created 3 years, 11 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') | no next file » | 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 <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 BluetoothTestBlueZ::BluetoothTestBlueZ() 60 BluetoothTestBlueZ::BluetoothTestBlueZ()
61 : fake_bluetooth_device_client_(nullptr) {} 61 : fake_bluetooth_device_client_(nullptr) {}
62 62
63 BluetoothTestBlueZ::~BluetoothTestBlueZ() {} 63 BluetoothTestBlueZ::~BluetoothTestBlueZ() {}
64 64
65 void BluetoothTestBlueZ::SetUp() { 65 void BluetoothTestBlueZ::SetUp() {
66 BluetoothTestBase::SetUp(); 66 BluetoothTestBase::SetUp();
67 std::unique_ptr<bluez::BluezDBusManagerSetter> dbus_setter = 67 std::unique_ptr<bluez::BluezDBusManagerSetter> dbus_setter =
68 bluez::BluezDBusManager::GetSetterForTesting(); 68 bluez::BluezDBusManager::GetSetterForTesting();
69
70 fake_bluetooth_adapter_client_ = new bluez::FakeBluetoothAdapterClient;
71 dbus_setter->SetBluetoothAdapterClient(
72 std::unique_ptr<bluez::BluetoothAdapterClient>(
73 fake_bluetooth_adapter_client_));
74
69 fake_bluetooth_device_client_ = new bluez::FakeBluetoothDeviceClient; 75 fake_bluetooth_device_client_ = new bluez::FakeBluetoothDeviceClient;
70 dbus_setter->SetBluetoothDeviceClient( 76 dbus_setter->SetBluetoothDeviceClient(
71 std::unique_ptr<bluez::BluetoothDeviceClient>( 77 std::unique_ptr<bluez::BluetoothDeviceClient>(
72 fake_bluetooth_device_client_)); 78 fake_bluetooth_device_client_));
79
80 // Make the fake adapter post tasks without delay in order to avoid timing
81 // issues.
82 fake_bluetooth_adapter_client_->SetSimulationIntervalMs(0);
73 } 83 }
74 84
75 void BluetoothTestBlueZ::TearDown() { 85 void BluetoothTestBlueZ::TearDown() {
86 // Connections and sessions will normally be closed by destructors,
87 // but for BlueZ we need to close them before shutting down the
88 // BluezDBusManager.
89 for (const auto& connection : gatt_connections_) {
90 if (connection->IsConnected())
91 connection->Disconnect();
92 }
93 gatt_connections_.clear();
94
95 for (const auto& session : discovery_sessions_) {
96 if (session->IsActive())
97 session->Stop(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing));
98 }
99 discovery_sessions_.clear();
100
76 adapter_ = nullptr; 101 adapter_ = nullptr;
77 bluez::BluezDBusManager::Shutdown(); 102 bluez::BluezDBusManager::Shutdown();
78 BluetoothTestBase::TearDown(); 103 BluetoothTestBase::TearDown();
79 } 104 }
80 105
81 bool BluetoothTestBlueZ::PlatformSupportsLowEnergy() { 106 bool BluetoothTestBlueZ::PlatformSupportsLowEnergy() {
82 return true; 107 return true;
83 } 108 }
84 109
85 void BluetoothTestBlueZ::InitWithFakeAdapter() { 110 void BluetoothTestBlueZ::InitWithFakeAdapter() {
86 base::RunLoop run_loop; 111 base::RunLoop run_loop;
87 adapter_ = new bluez::BluetoothAdapterBlueZ( 112 adapter_ = new bluez::BluetoothAdapterBlueZ(
88 base::Bind(&AdapterCallback, run_loop.QuitClosure())); 113 base::Bind(&AdapterCallback, run_loop.QuitClosure()));
89 run_loop.Run(); 114 run_loop.Run();
115 adapter_->SetPowered(true, base::Bind(&base::DoNothing),
116 base::Bind(&base::DoNothing));
90 } 117 }
91 118
92 BluetoothDevice* BluetoothTestBlueZ::SimulateLowEnergyDevice( 119 BluetoothDevice* BluetoothTestBlueZ::SimulateLowEnergyDevice(
93 int device_ordinal) { 120 int device_ordinal) {
94 if (device_ordinal > 6 || device_ordinal < 1) 121 if (device_ordinal > 6 || device_ordinal < 1)
95 return nullptr; 122 return nullptr;
96 123
97 base::Optional<std::string> device_name = kTestDeviceName; 124 base::Optional<std::string> device_name = kTestDeviceName;
98 std::string device_address = kTestDeviceAddress1; 125 std::string device_address = kTestDeviceAddress1;
99 std::vector<std::string> service_uuids; 126 std::vector<std::string> service_uuids;
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 std::vector<BluetoothLocalGattService*> services; 344 std::vector<BluetoothLocalGattService*> services;
318 bluez::BluetoothAdapterBlueZ* adapter_bluez = 345 bluez::BluetoothAdapterBlueZ* adapter_bluez =
319 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter_.get()); 346 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter_.get());
320 347
321 for (const auto& iter : adapter_bluez->registered_gatt_services_) 348 for (const auto& iter : adapter_bluez->registered_gatt_services_)
322 services.push_back(iter.second); 349 services.push_back(iter.second);
323 return services; 350 return services;
324 } 351 }
325 352
326 } // namespace device 353 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/test/bluetooth_test_bluez.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698