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

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

Issue 1739383002: Implement read & write remote GATT characteristic value for Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix conversion from 'size_t' to 'ULONG' error on trybot Created 4 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_win.h" 5 #include "device/bluetooth/test/bluetooth_test_win.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "device/bluetooth/bluetooth_adapter_win.h" 10 #include "device/bluetooth/bluetooth_adapter_win.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 void BluetoothTestWin::InitWithoutDefaultAdapter() { 92 void BluetoothTestWin::InitWithoutDefaultAdapter() {
93 adapter_ = new BluetoothAdapterWin(base::Bind( 93 adapter_ = new BluetoothAdapterWin(base::Bind(
94 &BluetoothTestWin::AdapterInitCallback, base::Unretained(this))); 94 &BluetoothTestWin::AdapterInitCallback, base::Unretained(this)));
95 adapter_win_ = static_cast<BluetoothAdapterWin*>(adapter_.get()); 95 adapter_win_ = static_cast<BluetoothAdapterWin*>(adapter_.get());
96 adapter_win_->InitForTest(ui_task_runner_, bluetooth_task_runner_); 96 adapter_win_->InitForTest(ui_task_runner_, bluetooth_task_runner_);
97 } 97 }
98 98
99 void BluetoothTestWin::InitWithFakeAdapter() { 99 void BluetoothTestWin::InitWithFakeAdapter() {
100 fake_bt_classic_wrapper_ = new win::BluetoothClassicWrapperFake(); 100 fake_bt_classic_wrapper_ = new win::BluetoothClassicWrapperFake();
101 fake_bt_le_wrapper_ = new win::BluetoothLowEnergyWrapperFake(); 101 fake_bt_le_wrapper_ = new win::BluetoothLowEnergyWrapperFake();
102 fake_bt_le_wrapper_->AddObserver(this);
102 win::BluetoothClassicWrapper::SetInstanceForTest(fake_bt_classic_wrapper_); 103 win::BluetoothClassicWrapper::SetInstanceForTest(fake_bt_classic_wrapper_);
103 win::BluetoothLowEnergyWrapper::SetInstanceForTest(fake_bt_le_wrapper_); 104 win::BluetoothLowEnergyWrapper::SetInstanceForTest(fake_bt_le_wrapper_);
104 fake_bt_classic_wrapper_->SimulateARadio( 105 fake_bt_classic_wrapper_->SimulateARadio(
105 base::SysUTF8ToWide(kTestAdapterName), 106 base::SysUTF8ToWide(kTestAdapterName),
106 CanonicalStringToBLUETOOTH_ADDRESS(kTestAdapterAddress)); 107 CanonicalStringToBLUETOOTH_ADDRESS(kTestAdapterAddress));
107 108
108 adapter_ = new BluetoothAdapterWin(base::Bind( 109 adapter_ = new BluetoothAdapterWin(base::Bind(
109 &BluetoothTestWin::AdapterInitCallback, base::Unretained(this))); 110 &BluetoothTestWin::AdapterInitCallback, base::Unretained(this)));
110 adapter_win_ = static_cast<BluetoothAdapterWin*>(adapter_.get()); 111 adapter_win_ = static_cast<BluetoothAdapterWin*>(adapter_.get());
111 adapter_win_->InitForTest(nullptr, bluetooth_task_runner_); 112 adapter_win_->InitForTest(nullptr, bluetooth_task_runner_);
113 adapter_win_->GetWinBluetoothTaskManager()->AddObserver(this);
112 FinishPendingTasks(); 114 FinishPendingTasks();
113 } 115 }
114 116
115 bool BluetoothTestWin::DenyPermission() { 117 bool BluetoothTestWin::DenyPermission() {
116 return false; 118 return false;
117 } 119 }
118 120
119 void BluetoothTestWin::StartLowEnergyDiscoverySession() { 121 void BluetoothTestWin::StartLowEnergyDiscoverySession() {
120 __super ::StartLowEnergyDiscoverySession(); 122 __super ::StartLowEnergyDiscoverySession();
121 FinishPendingTasks(); 123 FinishPendingTasks();
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 277
276 std::string characteristic_att_handle = std::to_string( 278 std::string characteristic_att_handle = std::to_string(
277 static_cast<BluetoothRemoteGattCharacteristicWin*>(characteristic) 279 static_cast<BluetoothRemoteGattCharacteristicWin*>(characteristic)
278 ->GetAttributeHandle()); 280 ->GetAttributeHandle());
279 fake_bt_le_wrapper_->SimulateGattCharacteriscRemove( 281 fake_bt_le_wrapper_->SimulateGattCharacteriscRemove(
280 target_service, characteristic_att_handle); 282 target_service, characteristic_att_handle);
281 283
282 ForceRefreshDevice(); 284 ForceRefreshDevice();
283 } 285 }
284 286
287 void BluetoothTestWin::RememberCharacteristicForSubsequentAction(
288 BluetoothGattCharacteristic* characteristic) {
289 remembered_characteristic_ =
290 static_cast<BluetoothRemoteGattCharacteristicWin*>(characteristic);
291 }
292
293 void BluetoothTestWin::SimulateGattCharacteristicRead(
294 BluetoothGattCharacteristic* characteristic,
295 const std::vector<uint8_t>& value) {
296 BluetoothGattCharacteristic* target_characteristic = characteristic;
297 if (target_characteristic == nullptr)
298 target_characteristic = remembered_characteristic_;
299 CHECK(target_characteristic);
300
301 win::GattCharacteristic* target_simulated_characteristic =
302 GetSimulatedCharacteristic(target_characteristic);
303 if (target_simulated_characteristic != nullptr) {
304 fake_bt_le_wrapper_->SimulateGattCharacteristicValue(
305 target_simulated_characteristic, value);
306 }
307
308 FinishPendingTasks();
309 }
310
311 void BluetoothTestWin::SimulateGattCharacteristicReadError(
312 BluetoothGattCharacteristic* characteristic,
313 BluetoothGattService::GattErrorCode error_code) {
314 win::GattCharacteristic* target_characteristic =
315 GetSimulatedCharacteristic(characteristic);
316 CHECK(target_characteristic);
317 HRESULT hr = ERROR_SEM_TIMEOUT;
318 if (error_code == BluetoothGattService::GATT_ERROR_INVALID_LENGTH)
319 hr = E_BLUETOOTH_ATT_INVALID_ATTRIBUTE_VALUE_LENGTH;
320 fake_bt_le_wrapper_->SimulateGattCharacteristicReadError(
321 target_characteristic, hr);
322
323 FinishPendingTasks();
324 }
325
326 void BluetoothTestWin::SimulateGattCharacteristicWrite(
327 BluetoothGattCharacteristic* characteristic) {
328 FinishPendingTasks();
329 }
330
331 void BluetoothTestWin::SimulateGattCharacteristicWriteError(
332 BluetoothGattCharacteristic* characteristic,
333 BluetoothGattService::GattErrorCode error_code) {
334 win::GattCharacteristic* target_characteristic =
335 GetSimulatedCharacteristic(characteristic);
336 CHECK(target_characteristic);
337 HRESULT hr = ERROR_SEM_TIMEOUT;
338 if (error_code == BluetoothGattService::GATT_ERROR_INVALID_LENGTH)
339 hr = E_BLUETOOTH_ATT_INVALID_ATTRIBUTE_VALUE_LENGTH;
340 fake_bt_le_wrapper_->SimulateGattCharacteristicWriteError(
341 target_characteristic, hr);
342
343 FinishPendingTasks();
344 }
345
346 void BluetoothTestWin::DeleteDevice(BluetoothDevice* device) {
347 CHECK(device);
348 fake_bt_le_wrapper_->RemoveSimulatedBLEDevice(device->GetAddress());
349 }
350
285 void BluetoothTestWin::SimulateGattDescriptor( 351 void BluetoothTestWin::SimulateGattDescriptor(
286 BluetoothGattCharacteristic* characteristic, 352 BluetoothGattCharacteristic* characteristic,
287 const std::string& uuid) { 353 const std::string& uuid) {
288 win::GattCharacteristic* target_characteristic = 354 win::GattCharacteristic* target_characteristic =
289 GetSimulatedCharacteristic(characteristic); 355 GetSimulatedCharacteristic(characteristic);
290 CHECK(target_characteristic); 356 CHECK(target_characteristic);
291 fake_bt_le_wrapper_->SimulateGattDescriptor( 357 fake_bt_le_wrapper_->SimulateGattDescriptor(
292 characteristic->GetService()->GetDevice()->GetAddress(), 358 characteristic->GetService()->GetDevice()->GetAddress(),
293 target_characteristic, CanonicalStringToBTH_LE_UUID(uuid)); 359 target_characteristic, CanonicalStringToBTH_LE_UUID(uuid));
294 ForceRefreshDevice(); 360 ForceRefreshDevice();
295 } 361 }
296 362
363 void BluetoothTestWin::OnAttemptReadGattCharacteristic() {
364 gatt_read_characteristic_attempts_++;
365 }
366
367 void BluetoothTestWin::OnAttemptWriteGattCharacteristic() {
368 gatt_write_characteristic_attempts_++;
369 }
370
371 void BluetoothTestWin::onWriteGattCharacteristicValue(
372 const PBTH_LE_GATT_CHARACTERISTIC_VALUE value) {
373 last_write_value_.clear();
374 for (ULONG i = 0; i < value->DataSize; i++)
375 last_write_value_.push_back(value->Data[i]);
376 }
377
297 win::GattService* BluetoothTestWin::GetSimulatedService( 378 win::GattService* BluetoothTestWin::GetSimulatedService(
298 win::BLEDevice* device, 379 win::BLEDevice* device,
299 BluetoothGattService* service) { 380 BluetoothGattService* service) {
300 CHECK(device); 381 CHECK(device);
301 CHECK(service); 382 CHECK(service);
302 383
303 std::vector<std::string> chain_of_att_handles; 384 std::vector<std::string> chain_of_att_handles;
304 BluetoothRemoteGattServiceWin* win_service = 385 BluetoothRemoteGattServiceWin* win_service =
305 static_cast<BluetoothRemoteGattServiceWin*>(service); 386 static_cast<BluetoothRemoteGattServiceWin*>(service);
306 chain_of_att_handles.insert( 387 chain_of_att_handles.insert(
(...skipping 29 matching lines...) Expand all
336 void BluetoothTestWin::ForceRefreshDevice() { 417 void BluetoothTestWin::ForceRefreshDevice() {
337 adapter_win_->force_update_device_for_test_ = true; 418 adapter_win_->force_update_device_for_test_ = true;
338 FinishPendingTasks(); 419 FinishPendingTasks();
339 } 420 }
340 421
341 void BluetoothTestWin::FinishPendingTasks() { 422 void BluetoothTestWin::FinishPendingTasks() {
342 bluetooth_task_runner_->RunPendingTasks(); 423 bluetooth_task_runner_->RunPendingTasks();
343 base::RunLoop().RunUntilIdle(); 424 base::RunLoop().RunUntilIdle();
344 } 425 }
345 } 426 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698