Chromium Code Reviews| 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 f4046ef5ce54ab91e54597465d890990ac2e51d9..8b00f3185a6c19dbed0f5037c8c9b47fc19c2d64 100644 |
| --- a/device/bluetooth/test/bluetooth_test_mac.mm |
| +++ b/device/bluetooth/test/bluetooth_test_mac.mm |
| @@ -118,6 +118,7 @@ BluetoothDevice* BluetoothTestMac::DiscoverLowEnergyDevice(int device_ordinal) { |
| scoped_nsobject<MockCBPeripheral> mock_peripheral( |
| [[MockCBPeripheral alloc] |
| initWithUTF8StringIdentifier:kTestPeripheralUUID1.c_str()]); |
| + mock_peripheral.get().bluetoothTestMac = this; |
|
ortuno
2016/05/06 16:03:34
Why do you need to do this?
jlebel
2016/05/07 00:16:12
I need to do this so the mock peripheral can call:
ortuno
2016/05/09 19:54:00
Ah ok.
|
| NSArray* uuids = @[ |
| [CBUUID UUIDWithString:@(kTestUUIDGenericAccess.c_str())], |
| [CBUUID UUIDWithString:@(kTestUUIDGenericAttribute.c_str())] |
| @@ -134,6 +135,7 @@ BluetoothDevice* BluetoothTestMac::DiscoverLowEnergyDevice(int device_ordinal) { |
| scoped_nsobject<MockCBPeripheral> mock_peripheral( |
| [[MockCBPeripheral alloc] |
| initWithUTF8StringIdentifier:kTestPeripheralUUID1.c_str()]); |
| + mock_peripheral.get().bluetoothTestMac = this; |
| NSArray* uuids = @[ |
| [CBUUID UUIDWithString:@(kTestUUIDImmediateAlert.c_str())], |
| [CBUUID UUIDWithString:@(kTestUUIDLinkLoss.c_str())] |
| @@ -150,6 +152,7 @@ BluetoothDevice* BluetoothTestMac::DiscoverLowEnergyDevice(int device_ordinal) { |
| scoped_nsobject<MockCBPeripheral> mock_peripheral( |
| [[MockCBPeripheral alloc] |
| initWithUTF8StringIdentifier:kTestPeripheralUUID1.c_str()]); |
| + mock_peripheral.get().bluetoothTestMac = this; |
| scoped_nsobject<NSDictionary> advertisement_data( |
| CreateAdvertisementData(@(kTestDeviceNameEmpty.c_str()), nil)); |
| [central_manager_delegate centralManager:central_manager |
| @@ -162,6 +165,7 @@ BluetoothDevice* BluetoothTestMac::DiscoverLowEnergyDevice(int device_ordinal) { |
| scoped_nsobject<MockCBPeripheral> mock_peripheral( |
| [[MockCBPeripheral alloc] |
| initWithUTF8StringIdentifier:kTestPeripheralUUID2.c_str()]); |
| + mock_peripheral.get().bluetoothTestMac = this; |
| NSArray* uuids = nil; |
| scoped_nsobject<NSDictionary> advertisement_data = |
| CreateAdvertisementData(@(kTestDeviceNameEmpty.c_str()), uuids); |
| @@ -217,6 +221,38 @@ void BluetoothTestMac::SimulateGattDisconnection(BluetoothDevice* device) { |
| error:nil]; |
| } |
| +void BluetoothTestMac::SimulateGattServicesDiscovered( |
| + BluetoothDevice* device, |
| + const std::vector<std::string>& uuids) { |
| + BluetoothLowEnergyDeviceMac* device_mac = |
| + static_cast<BluetoothLowEnergyDeviceMac*>(device); |
| + CBPeripheral* peripheral = device_mac->GetPeripheral(); |
| + MockCBPeripheral* peripheral_mock = ObjCCast<MockCBPeripheral>(peripheral); |
| + scoped_nsobject<NSMutableArray> services = [[NSMutableArray alloc] init]; |
| + for (auto uuid : uuids) { |
| + CBUUID* cb_service_uuid = [CBUUID UUIDWithString:@(uuid.c_str())]; |
| + [services addObject:cb_service_uuid]; |
|
ortuno
2016/05/06 16:03:34
Does the ownership of cb_service_uuid get transfer
jlebel
2016/05/07 00:16:12
There is no real ownership in objective-c. The |se
ortuno
2016/05/09 19:54:00
Got it. Thanks for the explanation!
|
| + } |
| + [peripheral_mock removeAllServices]; |
| + [peripheral_mock addServices:services]; |
| + [peripheral_mock didDiscoverWithError:nil]; |
| +} |
| + |
| +void BluetoothTestMac::SimulateGattServiceRemoved( |
| + BluetoothRemoteGattService* service) { |
| + BluetoothUUID bluetooth_service_uuid = service->GetUUID(); |
| + std::string service_uuid_string = bluetooth_service_uuid.canonical_value(); |
| + CBUUID* cb_service_uuid = |
| + [CBUUID UUIDWithString:@(service_uuid_string.c_str())]; |
| + BluetoothDevice* device = service->GetDevice(); |
| + BluetoothLowEnergyDeviceMac* device_mac = |
| + static_cast<BluetoothLowEnergyDeviceMac*>(device); |
| + CBPeripheral* peripheral = device_mac->GetPeripheral(); |
| + MockCBPeripheral* peripheral_mock = ObjCCast<MockCBPeripheral>(peripheral); |
| + [peripheral_mock removeServiceWithCBUUID:cb_service_uuid]; |
|
ortuno
2016/05/06 16:03:34
I don't think we should use the UUID to remove ser
jlebel
2016/05/07 00:16:12
Done.
|
| + [peripheral_mock didDiscoverWithError:nil]; |
| +} |
| + |
| void BluetoothTestMac::OnFakeBluetoothDeviceConnectGattCalled() { |
| gatt_connection_attempts_++; |
| } |
| @@ -225,6 +261,10 @@ void BluetoothTestMac::OnFakeBluetoothGattDisconnect() { |
| gatt_disconnection_attempts_++; |
| } |
| +void BluetoothTestMac::OnFakeBluetoothServiceDiscovery() { |
| + gatt_discovery_attempts_++; |
| +} |
| + |
| // Utility function for generating new (CBUUID, address) pairs where CBUUID |
| // hashes to address. For use when adding a new device address to the testing |
| // suite because CoreBluetooth peripherals have CBUUIDs in place of addresses, |