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

Unified Diff: device/bluetooth/test/bluetooth_test_mac.mm

Issue 2767813002: Bluetooth: macOS: Implementing read/write for descriptors (Closed)
Patch Set: Adding NSError logs (and merge) Created 3 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_mac.mm
diff --git a/device/bluetooth/test/bluetooth_test_mac.mm b/device/bluetooth/test/bluetooth_test_mac.mm
index 777e91339cf66d8d512b200378f7e9f0ebc7f116..4084676632ef6dc05f835695150e5a34f21e13e1 100644
--- a/device/bluetooth/test/bluetooth_test_mac.mm
+++ b/device/bluetooth/test/bluetooth_test_mac.mm
@@ -13,8 +13,10 @@
#include "device/bluetooth/bluetooth_adapter_mac.h"
#include "device/bluetooth/bluetooth_device_mac.h"
#include "device/bluetooth/bluetooth_remote_gatt_characteristic_mac.h"
+#include "device/bluetooth/bluetooth_remote_gatt_descriptor_mac.h"
#include "device/bluetooth/bluetooth_remote_gatt_service_mac.h"
#include "device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h"
+#include "device/bluetooth/test/mock_bluetooth_cbdescriptor_mac.h"
#include "device/bluetooth/test/mock_bluetooth_cbperipheral_mac.h"
#include "device/bluetooth/test/mock_bluetooth_cbservice_mac.h"
#include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h"
@@ -446,6 +448,33 @@ void BluetoothTestMac::SimulateGattCharacteristicRemoved(
[peripheral_mock mockDidDiscoverEvents];
}
+void BluetoothTestMac::SimulateGattDescriptorRead(
+ BluetoothRemoteGattDescriptor* descriptor,
+ const std::vector<uint8_t>& value) {
+ scoped_nsobject<NSData> data(
+ [[NSData alloc] initWithBytes:value.data() length:value.size()]);
+ [GetCBMockDescriptor(descriptor) simulateReadWithValue:data error:nil];
+}
+
+void BluetoothTestMac::SimulateGattDescriptorReadError(
+ BluetoothRemoteGattDescriptor* descriptor,
+ BluetoothRemoteGattService::GattErrorCode error_code) {
+ NSError* error = BluetoothDeviceMac::GetNSErrorFromGattErrorCode(error_code);
+ [GetCBMockDescriptor(descriptor) simulateReadWithValue:nil error:error];
+}
+
+void BluetoothTestMac::SimulateGattDescriptorWrite(
+ BluetoothRemoteGattDescriptor* descriptor) {
+ [GetCBMockDescriptor(descriptor) simulateWriteWithError:nil];
+}
+
+void BluetoothTestMac::SimulateGattDescriptorWriteError(
+ BluetoothRemoteGattDescriptor* descriptor,
+ BluetoothRemoteGattService::GattErrorCode error_code) {
+ NSError* error = BluetoothDeviceMac::GetNSErrorFromGattErrorCode(error_code);
+ [GetCBMockDescriptor(descriptor) simulateWriteWithError:error];
+}
+
void BluetoothTestMac::ExpectedChangeNotifyValueAttempts(int attempts) {
EXPECT_EQ(attempts, gatt_notify_characteristic_attempts_);
}
@@ -502,6 +531,16 @@ void BluetoothTest::OnFakeBluetoothGattSetCharacteristicNotification(
gatt_notify_characteristic_attempts_++;
}
+void BluetoothTest::OnFakeBluetoothDescriptorReadValue() {
+ gatt_read_descriptor_attempts_++;
+}
+
+void BluetoothTest::OnFakeBluetoothDescriptorWriteValue(
+ std::vector<uint8_t> value) {
+ last_write_value_ = value;
+ gatt_write_descriptor_attempts_++;
+}
+
BluetoothDevice::UUIDSet
BluetoothTestMac::RetrieveConnectedPeripheralServiceUUIDs() {
BluetoothDevice::UUIDSet service_uuids;
@@ -540,6 +579,11 @@ MockCBPeripheral* BluetoothTestMac::GetMockCBPeripheral(
return GetMockCBPeripheral(characteristic->GetService());
}
+MockCBPeripheral* BluetoothTestMac::GetMockCBPeripheral(
+ BluetoothRemoteGattDescriptor* descriptor) const {
+ return GetMockCBPeripheral(descriptor->GetCharacteristic());
+}
+
MockCBCharacteristic* BluetoothTest::GetCBMockCharacteristic(
BluetoothRemoteGattCharacteristic* characteristic) const {
device::BluetoothRemoteGattCharacteristicMac* mac_gatt_characteristic =
@@ -550,6 +594,14 @@ MockCBCharacteristic* BluetoothTest::GetCBMockCharacteristic(
return ObjCCast<MockCBCharacteristic>(cb_characteristic);
}
+MockCBDescriptor* BluetoothTest::GetCBMockDescriptor(
+ BluetoothRemoteGattDescriptor* descriptor) const {
+ device::BluetoothRemoteGattDescriptorMac* mac_gatt_descriptor =
+ static_cast<device::BluetoothRemoteGattDescriptorMac*>(descriptor);
+ CBDescriptor* cb_descriptor = mac_gatt_descriptor->GetCBDescriptor();
+ return ObjCCast<MockCBDescriptor>(cb_descriptor);
+}
+
void BluetoothTest::AddServicesToDevice(BluetoothDevice* device,
const std::vector<std::string>& uuids) {
scoped_nsobject<NSMutableArray> services([[NSMutableArray alloc] init]);

Powered by Google App Engine
This is Rietveld 408576698