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

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

Issue 1749403002: Implement BluetoothRemoteGattCharacteristicWin::StartNotifySession and related unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add more unit tests 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 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 cd852aaf9951764250a065ac4485e86db5b10cdd..3052a339b37787b38e41cddebc4c5327cbc26a5c 100644
--- a/device/bluetooth/test/bluetooth_test_win.cc
+++ b/device/bluetooth/test/bluetooth_test_win.cc
@@ -13,6 +13,7 @@
#include "device/bluetooth/bluetooth_adapter_win.h"
#include "device/bluetooth/bluetooth_low_energy_win.h"
#include "device/bluetooth/bluetooth_remote_gatt_characteristic_win.h"
+#include "device/bluetooth/bluetooth_remote_gatt_descriptor_win.h"
#include "device/bluetooth/bluetooth_remote_gatt_service_win.h"
namespace {
@@ -113,7 +114,6 @@ void BluetoothTestWin::InitWithFakeAdapter() {
&BluetoothTestWin::AdapterInitCallback, base::Unretained(this)));
adapter_win_ = static_cast<BluetoothAdapterWin*>(adapter_.get());
adapter_win_->InitForTest(nullptr, bluetooth_task_runner_);
- adapter_win_->GetWinBluetoothTaskManager()->AddObserver(this);
FinishPendingTasks();
}
@@ -121,6 +121,10 @@ bool BluetoothTestWin::DenyPermission() {
return false;
}
+void BluetoothTestWin::RunUntilIdle() {
+ FinishPendingTasks();
+}
+
void BluetoothTestWin::StartLowEnergyDiscoverySession() {
__super ::StartLowEnergyDiscoverySession();
FinishPendingTasks();
@@ -318,7 +322,7 @@ void BluetoothTestWin::SimulateGattCharacteristicReadError(
win::GattCharacteristic* target_characteristic =
GetSimulatedCharacteristic(characteristic);
CHECK(target_characteristic);
- HRESULT hr = ERROR_SEM_TIMEOUT;
+ HRESULT hr = HRESULT_FROM_WIN32(ERROR_SEM_TIMEOUT);
if (error_code == BluetoothGattService::GATT_ERROR_INVALID_LENGTH)
hr = E_BLUETOOTH_ATT_INVALID_ATTRIBUTE_VALUE_LENGTH;
fake_bt_le_wrapper_->SimulateGattCharacteristicReadError(
@@ -338,7 +342,7 @@ void BluetoothTestWin::SimulateGattCharacteristicWriteError(
win::GattCharacteristic* target_characteristic =
GetSimulatedCharacteristic(characteristic);
CHECK(target_characteristic);
- HRESULT hr = ERROR_SEM_TIMEOUT;
+ HRESULT hr = HRESULT_FROM_WIN32(ERROR_SEM_TIMEOUT);
if (error_code == BluetoothGattService::GATT_ERROR_INVALID_LENGTH)
hr = E_BLUETOOTH_ATT_INVALID_ATTRIBUTE_VALUE_LENGTH;
fake_bt_le_wrapper_->SimulateGattCharacteristicWriteError(
@@ -347,6 +351,16 @@ void BluetoothTestWin::SimulateGattCharacteristicWriteError(
FinishPendingTasks();
}
+void BluetoothTestWin::
+ SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce(
+ BluetoothGattCharacteristic* characteristic) {
+ win::GattCharacteristic* target_characteristic =
+ GetSimulatedCharacteristic(characteristic);
+ CHECK(target_characteristic);
+ fake_bt_le_wrapper_->SimulateGattCharacteristicSetNotifyError(
+ target_characteristic, E_BLUETOOTH_ATT_UNKNOWN_ERROR);
+}
+
void BluetoothTestWin::DeleteDevice(BluetoothDevice* device) {
CHECK(device);
fake_bt_le_wrapper_->RemoveSimulatedBLEDevice(device->GetAddress());
@@ -364,21 +378,78 @@ void BluetoothTestWin::SimulateGattDescriptor(
ForceRefreshDevice();
}
-void BluetoothTestWin::OnAttemptReadGattCharacteristic() {
+void BluetoothTestWin::SimulateGattDescriptorWriteWillFailSynchronouslyOnce(
+ BluetoothGattDescriptor* descriptor) {
+ BluetoothRemoteGattDescriptorWin* win_descriptor =
+ (BluetoothRemoteGattDescriptorWin*)descriptor;
+ win::GattCharacteristic* target_characteristic =
+ GetSimulatedCharacteristic(win_descriptor->GetCharacteristic());
+ CHECK(target_characteristic);
+ win::GattDescriptor* target_descriptor =
+ fake_bt_le_wrapper_->GetSimulatedDescriptor(
+ target_characteristic,
+ std::to_string(win_descriptor->GetAttributeHandle()));
+ CHECK(target_descriptor);
+ fake_bt_le_wrapper_->SimulateGattDescriptorWriteError(
+ target_descriptor, E_BLUETOOTH_ATT_REQUEST_NOT_SUPPORTED);
+}
+
+void BluetoothTestWin::SimulateGattNotifySessionStarted(
+ BluetoothGattCharacteristic* characteristic) {
+ FinishPendingTasks();
+}
+
+void BluetoothTestWin::SimulateGattCharacteristicChanged(
+ BluetoothGattCharacteristic* characteristic,
+ const std::vector<uint8_t>& value) {
+ BluetoothGattCharacteristic* target_characteristic = characteristic;
+ if (target_characteristic == nullptr)
+ target_characteristic = remembered_characteristic_;
+ CHECK(target_characteristic);
+
+ win::GattCharacteristic* simulated_characteristic =
+ GetSimulatedCharacteristic(target_characteristic);
+ CHECK(simulated_characteristic);
+ fake_bt_le_wrapper_->SimulateGattCharacteristicValue(simulated_characteristic,
+ value);
+ std::string device_address =
+ characteristic->GetService()->GetDevice()->GetAddress();
+ win::BLEDevice* target_device =
+ fake_bt_le_wrapper_->GetSimulatedBLEDevice(device_address);
+ CHECK(target_device);
+ win::GattService* parent_service =
+ GetSimulatedService(target_device, characteristic->GetService());
+ CHECK(parent_service);
+ fake_bt_le_wrapper_->SimulateCharacteristicValueChangeNotification(
+ parent_service, simulated_characteristic);
+
+ FinishPendingTasks();
+}
+
+void BluetoothTestWin::OnReadGattCharacteristicValue() {
gatt_read_characteristic_attempts_++;
}
-void BluetoothTestWin::OnAttemptWriteGattCharacteristic() {
+void BluetoothTestWin::OnWriteGattCharacteristicValue(
+ const PBTH_LE_GATT_CHARACTERISTIC_VALUE value) {
gatt_write_characteristic_attempts_++;
+ last_write_value_.clear();
+ for (ULONG i = 0; i < value->DataSize; i++)
+ last_write_value_.push_back(value->Data[i]);
}
-void BluetoothTestWin::onWriteGattCharacteristicValue(
- const PBTH_LE_GATT_CHARACTERISTIC_VALUE value) {
+void BluetoothTestWin::OnWriteGattDescriptorValue(
+ const PBTH_LE_GATT_DESCRIPTOR_VALUE value) {
+ gatt_write_descriptor_attempts_++;
last_write_value_.clear();
for (ULONG i = 0; i < value->DataSize; i++)
last_write_value_.push_back(value->Data[i]);
}
+void BluetoothTestWin::OnStartCharacteristicNotification() {
+ gatt_notify_characteristic_attempts_++;
+}
+
win::GattService* BluetoothTestWin::GetSimulatedService(
win::BLEDevice* device,
BluetoothGattService* service) {

Powered by Google App Engine
This is Rietveld 408576698