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

Side by Side Diff: device/bluetooth/bluetooth_low_energy_win_fake.cc

Issue 1804093003: Add BluetoothGattCharacteristicTest::StartNotifySession_Reentrant unit test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/bluetooth_low_energy_win_fake.h" 5 #include "device/bluetooth/bluetooth_low_energy_win_fake.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "device/bluetooth/bluetooth_low_energy_defs_win.h" 8 #include "device/bluetooth/bluetooth_low_energy_defs_win.h"
9 9
10 namespace { 10 namespace {
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 PVOID context, 249 PVOID context,
250 BLUETOOTH_GATT_EVENT_HANDLE* out_handle) { 250 BLUETOOTH_GATT_EVENT_HANDLE* out_handle) {
251 // Right now, only CharacteristicValueChangedEvent is supported. 251 // Right now, only CharacteristicValueChangedEvent is supported.
252 CHECK(CharacteristicValueChangedEvent == type); 252 CHECK(CharacteristicValueChangedEvent == type);
253 253
254 scoped_ptr<GattCharacteristicObserver> observer( 254 scoped_ptr<GattCharacteristicObserver> observer(
255 new GattCharacteristicObserver()); 255 new GattCharacteristicObserver());
256 observer->callback = callback; 256 observer->callback = callback;
257 observer->context = context; 257 observer->context = context;
258 *out_handle = (BLUETOOTH_GATT_EVENT_HANDLE)observer.get(); 258 *out_handle = (BLUETOOTH_GATT_EVENT_HANDLE)observer.get();
259 gatt_characteristic_observers_[*out_handle] = std::move(observer);
260 259
261 PBLUETOOTH_GATT_VALUE_CHANGED_EVENT_REGISTRATION parameter = 260 PBLUETOOTH_GATT_VALUE_CHANGED_EVENT_REGISTRATION parameter =
262 (PBLUETOOTH_GATT_VALUE_CHANGED_EVENT_REGISTRATION)event_parameter; 261 (PBLUETOOTH_GATT_VALUE_CHANGED_EVENT_REGISTRATION)event_parameter;
263 for (USHORT i = 0; i < parameter->NumCharacteristics; i++) { 262 for (USHORT i = 0; i < parameter->NumCharacteristics; i++) {
264 GattCharacteristic* target_characteristic = GetSimulatedGattCharacteristic( 263 GattCharacteristic* target_characteristic = GetSimulatedGattCharacteristic(
265 service_path, &parameter->Characteristics[i]); 264 service_path, &parameter->Characteristics[i]);
266 CHECK(target_characteristic); 265 CHECK(target_characteristic);
266
267 // Return error simulated by SimulateGattCharacteristicSetNotifyError.
268 if (target_characteristic->notify_errors.size()) {
269 HRESULT error = target_characteristic->notify_errors[0];
270 target_characteristic->notify_errors.erase(
271 target_characteristic->notify_errors.begin());
272 return error;
273 }
274
267 target_characteristic->observers.push_back(*out_handle); 275 target_characteristic->observers.push_back(*out_handle);
268 } 276 }
277 gatt_characteristic_observers_[*out_handle] = std::move(observer);
269 278
270 if (observer_) 279 if (observer_)
271 observer_->OnStartCharacteristicNotification(); 280 observer_->OnStartCharacteristicNotification();
272 281
273 return S_OK; 282 return S_OK;
274 } 283 }
275 284
276 HRESULT BluetoothLowEnergyWrapperFake::UnregisterGattEvent( 285 HRESULT BluetoothLowEnergyWrapperFake::UnregisterGattEvent(
277 BLUETOOTH_GATT_EVENT_HANDLE event_handle) { 286 BLUETOOTH_GATT_EVENT_HANDLE event_handle) {
278 gatt_characteristic_observers_.erase(event_handle); 287 gatt_characteristic_observers_.erase(event_handle);
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 characteristic->characteristic_info->AttributeHandle; 442 characteristic->characteristic_info->AttributeHandle;
434 event.CharacteristicValueDataSize = 443 event.CharacteristicValueDataSize =
435 characteristic->value->DataSize + sizeof(ULONG); 444 characteristic->value->DataSize + sizeof(ULONG);
436 event.CharacteristicValue = characteristic->value.get(); 445 event.CharacteristicValue = characteristic->value.get();
437 it->second->callback(CharacteristicValueChangedEvent, &event, 446 it->second->callback(CharacteristicValueChangedEvent, &event,
438 it->second->context); 447 it->second->context);
439 } 448 }
440 } 449 }
441 } 450 }
442 451
452 void BluetoothLowEnergyWrapperFake::SimulateGattCharacteristicSetNotifyError(
453 GattCharacteristic* characteristic,
454 HRESULT error) {
455 characteristic->notify_errors.push_back(error);
456 }
457
443 void BluetoothLowEnergyWrapperFake::SimulateGattCharacteristicReadError( 458 void BluetoothLowEnergyWrapperFake::SimulateGattCharacteristicReadError(
444 GattCharacteristic* characteristic, 459 GattCharacteristic* characteristic,
445 HRESULT error) { 460 HRESULT error) {
446 CHECK(characteristic); 461 CHECK(characteristic);
447 characteristic->read_errors.push_back(error); 462 characteristic->read_errors.push_back(error);
448 } 463 }
449 464
450 void BluetoothLowEnergyWrapperFake::SimulateGattCharacteristicWriteError( 465 void BluetoothLowEnergyWrapperFake::SimulateGattCharacteristicWriteError(
451 GattCharacteristic* characteristic, 466 GattCharacteristic* characteristic,
452 HRESULT error) { 467 HRESULT error) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 std::string BluetoothLowEnergyWrapperFake::BluetoothAddressToCanonicalString( 586 std::string BluetoothLowEnergyWrapperFake::BluetoothAddressToCanonicalString(
572 const BLUETOOTH_ADDRESS& btha) { 587 const BLUETOOTH_ADDRESS& btha) {
573 std::string result = base::StringPrintf( 588 std::string result = base::StringPrintf(
574 "%02X:%02X:%02X:%02X:%02X:%02X", btha.rgBytes[5], btha.rgBytes[4], 589 "%02X:%02X:%02X:%02X:%02X:%02X", btha.rgBytes[5], btha.rgBytes[4],
575 btha.rgBytes[3], btha.rgBytes[2], btha.rgBytes[1], btha.rgBytes[0]); 590 btha.rgBytes[3], btha.rgBytes[2], btha.rgBytes[1], btha.rgBytes[0]);
576 return result; 591 return result;
577 } 592 }
578 593
579 } // namespace win 594 } // namespace win
580 } // namespace device 595 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698