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

Unified Diff: device/bluetooth/test/bluetooth_test_win.cc

Issue 1672843002: Implement fake Bluetooth adapter for BluetoothTest.ConstructFakeAdapter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move ScopedHandle from task manager to low level code Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/test/bluetooth_test_win.cc
diff --git a/device/bluetooth/test/bluetooth_test_win.cc b/device/bluetooth/test/bluetooth_test_win.cc
index 13464937115aaaf1c84de0cb190dc1e77d1ab364..4e6536f616b6539855ba77ee2ea7112f493a5afe 100644
--- a/device/bluetooth/test/bluetooth_test_win.cc
+++ b/device/bluetooth/test/bluetooth_test_win.cc
@@ -5,9 +5,28 @@
#include "device/bluetooth/test/bluetooth_test_win.h"
#include "base/bind.h"
+#include "base/strings/sys_string_conversions.h"
#include "device/bluetooth/bluetooth_adapter_win.h"
#include "device/bluetooth/bluetooth_low_energy_win.h"
+namespace {
+
+BLUETOOTH_ADDRESS CanonicalStringToBLUETOOTH_ADDRESS(
+ std::string device_address) {
+ BLUETOOTH_ADDRESS win_addr;
+ unsigned int data[6];
+ int result =
+ sscanf_s(device_address.c_str(), "%02X:%02X:%02X:%02X:%02X:%02X",
+ &data[5], &data[4], &data[3], &data[2], &data[1], &data[0]);
+ CHECK(result == 6);
+ for (int i = 0; i < 6; i++) {
+ win_addr.rgBytes[i] = data[i];
+ }
+ return win_addr;
+}
+
+} // namespace
+
namespace device {
BluetoothTestWin::BluetoothTestWin()
: ui_task_runner_(new base::TestSimpleTaskRunner()),
@@ -35,16 +54,20 @@ void BluetoothTestWin::InitWithoutDefaultAdapter() {
}
void BluetoothTestWin::InitWithFakeAdapter() {
+ fake_bt_classic_wrapper_ = new win::BluetoothClassicWrapperFake();
+ fake_bt_le_wrapper_ = new win::BluetoothLowEnergyWrapperFake();
+ win::BluetoothClassicWrapper::SetInstanceForTest(fake_bt_classic_wrapper_);
+ win::BluetoothLowEnergyWrapper::SetInstanceForTest(fake_bt_le_wrapper_);
+ fake_bt_classic_wrapper_->SimulateARadio(
+ base::SysUTF8ToWide(kTestAdapterName),
+ CanonicalStringToBLUETOOTH_ADDRESS(kTestAdapterAddress));
+
adapter_ = new BluetoothAdapterWin(base::Bind(
&BluetoothTestWin::AdapterInitCallback, base::Unretained(this)));
adapter_win_ = static_cast<BluetoothAdapterWin*>(adapter_.get());
adapter_win_->InitForTest(ui_task_runner_, bluetooth_task_runner_);
- BluetoothTaskManagerWin::AdapterState* adapter_state =
- new BluetoothTaskManagerWin::AdapterState();
- adapter_state->name = kTestAdapterName;
- adapter_state->address = kTestAdapterAddress;
- adapter_state->powered = true;
- adapter_win_->AdapterStateChanged(*adapter_state);
+ bluetooth_task_runner_->RunPendingTasks();
+ ui_task_runner_->RunPendingTasks();
}
bool BluetoothTestWin::DenyPermission() {
« device/bluetooth/bluetooth_classic_win_fake.cc ('K') | « device/bluetooth/test/bluetooth_test_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698