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

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

Issue 2071323002: bluetooth: mac: Initial BluetoothRemoteGattCharacteristicMac implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Skip reconnect-during-disconnected-event test Created 4 years, 6 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 cc4b8d85f108e4324b61616c904472b36a309f8d..41ca2742d935fd866294e3fd58225a1871437bdc 100644
--- a/device/bluetooth/test/bluetooth_test_mac.mm
+++ b/device/bluetooth/test/bluetooth_test_mac.mm
@@ -10,8 +10,11 @@
#include "base/strings/string_number_conversions.h"
#include "build/build_config.h"
#include "device/bluetooth/bluetooth_adapter_mac.h"
+#include "device/bluetooth/bluetooth_remote_gatt_characteristic_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_cbperipheral_mac.h"
+#include "device/bluetooth/test/mock_bluetooth_cbservice_mac.h"
#include "device/bluetooth/test/mock_bluetooth_central_manager_mac.h"
#include "device/bluetooth/test/test_bluetooth_adapter_observer.h"
#include "third_party/ocmock/OCMock/OCMock.h"
@@ -21,6 +24,18 @@
using base::mac::ObjCCast;
using base::scoped_nsobject;
+namespace {
+
+void DidDiscoverServices(MockCBPeripheral* peripheral_mock) {
+ [peripheral_mock didDiscoverServicesWithError:nil];
+ // BluetoothLowEnergyDeviceMac is expected to call
+ // -[CBPeripheral discoverCharacteristics:forService:] for each services,
+ // so -[<CBPeripheralDelegate peripheral:didDiscoverCharacteristicsForService:
+ // error:] needs to be called
+ [peripheral_mock didDiscoverCharactericsForAllServices];
+}
+} // namespace
+
namespace device {
// This class hides Objective-C from bluetooth_test_mac.h.
@@ -237,7 +252,7 @@ void BluetoothTestMac::SimulateGattServicesDiscovered(
[services addObject:cb_service_uuid];
}
[peripheral_mock addServices:services];
- [peripheral_mock didDiscoverServicesWithError:nil];
+ DidDiscoverServices(peripheral_mock);
}
void BluetoothTestMac::SimulateGattServiceRemoved(
@@ -252,7 +267,44 @@ void BluetoothTestMac::SimulateGattServiceRemoved(
CBPeripheral* peripheral = device_mac->GetPeripheral();
MockCBPeripheral* peripheral_mock = ObjCCast<MockCBPeripheral>(peripheral);
[peripheral_mock removeService:mac_gatt_service->GetService()];
- [peripheral_mock didDiscoverServicesWithError:nil];
+ // After -[MockCBPeripheral removeService:], BluetoothLowEnergyDeviceMac is
+ // expected to call -[CBPeripheral discoverServices:]
+ DidDiscoverServices(peripheral_mock);
+}
+
+void BluetoothTestMac::SimulateGattCharacteristic(
+ BluetoothRemoteGattService* service,
+ const std::string& uuid,
+ int properties) {
+ BluetoothRemoteGattServiceMac* mac_gatt_service =
+ static_cast<BluetoothRemoteGattServiceMac*>(service);
+ CBService* cb_service = mac_gatt_service->GetService();
+ MockCBService* service_mock = ObjCCast<MockCBService>(cb_service);
+ CBUUID* cb_uuid = [CBUUID UUIDWithString:@(uuid.c_str())];
+ [service_mock addCharacteristicWithUUID:cb_uuid properties:properties];
+ MockCBPeripheral* peripheral_mock = GetMockCBPeripheral(service);
+ [peripheral_mock didModifyServices:@[]];
+ // After -[MockCBPeripheral didModifyServices:], BluetoothLowEnergyDeviceMac
+ // is expected to call -[CBPeripheral discoverServices:]
+ DidDiscoverServices(peripheral_mock);
+}
+
+void BluetoothTestMac::SimulateGattCharacteristicRemoved(
+ BluetoothRemoteGattService* service,
+ BluetoothRemoteGattCharacteristic* characteristic) {
+ MockCBPeripheral* peripheral_mock = GetMockCBPeripheral(service);
+ BluetoothRemoteGattServiceMac* mac_gatt_service =
+ static_cast<BluetoothRemoteGattServiceMac*>(service);
+ CBService* cb_service = mac_gatt_service->GetService();
+ MockCBService* service_mock = ObjCCast<MockCBService>(cb_service);
+ BluetoothRemoteGattCharacteristicMac* characteristic_mac =
+ static_cast<BluetoothRemoteGattCharacteristicMac*>(characteristic);
+ CBCharacteristic* cb_characteristic =
+ characteristic_mac->GetCBCharacteristic();
+ MockCBCharacteristic* characteristic_mock =
+ ObjCCast<MockCBCharacteristic>(cb_characteristic);
+ [service_mock removeCharacteristicMock:characteristic_mock];
+ DidDiscoverServices(peripheral_mock);
}
void BluetoothTestMac::OnFakeBluetoothDeviceConnectGattCalled() {
@@ -267,6 +319,15 @@ void BluetoothTestMac::OnFakeBluetoothServiceDiscovery() {
gatt_discovery_attempts_++;
}
+MockCBPeripheral* BluetoothTestMac::GetMockCBPeripheral(
+ BluetoothRemoteGattService* service) const {
+ BluetoothDevice* device = service->GetDevice();
+ BluetoothLowEnergyDeviceMac* device_mac =
+ static_cast<BluetoothLowEnergyDeviceMac*>(device);
+ CBPeripheral* cb_peripheral = device_mac->GetPeripheral();
+ return ObjCCast<MockCBPeripheral>(cb_peripheral);
+}
+
// 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,
« no previous file with comments | « device/bluetooth/test/bluetooth_test_mac.h ('k') | device/bluetooth/test/mock_bluetooth_cbcharacteristic_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698