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

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

Issue 2767813002: Bluetooth: macOS: Implementing read/write for descriptors (Closed)
Patch Set: NSString/NSNumber type for descriptor value Created 3 years, 8 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..54bfa5cbac08b93e38a3daf95d7d2655c31601c5 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,31 @@ void BluetoothTestMac::SimulateGattCharacteristicRemoved(
[peripheral_mock mockDidDiscoverEvents];
}
+void BluetoothTestMac::SimulateGattDescriptorRead(
+ BluetoothRemoteGattDescriptor* descriptor,
+ const std::vector<uint8_t>& value) {
+ SimulateGattDescriptorReadNSData(descriptor, value);
+}
+
+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_);
}
@@ -470,6 +497,28 @@ void BluetoothTestMac::SimulateDidDiscoverServices(
[GetMockCBPeripheral(device) mockDidDiscoverServices];
}
+void BluetoothTestMac::SimulateGattDescriptorReadNSData(
+ 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::SimulateGattDescriptorReadNSString(
+ BluetoothRemoteGattDescriptor* descriptor,
+ const std::string& value) {
+ NSString* string = base::SysUTF8ToNSString(value);
+ [GetCBMockDescriptor(descriptor) simulateReadWithValue:string error:nil];
+}
+
+void BluetoothTestMac::SimulateGattDescriptorReadNSNumber(
+ BluetoothRemoteGattDescriptor* descriptor,
+ short value) {
+ NSNumber* number = [NSNumber numberWithShort:value];
+ [GetCBMockDescriptor(descriptor) simulateReadWithValue:number error:nil];
+}
+
void BluetoothTestMac::OnFakeBluetoothDeviceConnectGattCalled() {
gatt_connection_attempts_++;
}
@@ -502,6 +551,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 +599,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 +614,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