OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/test/bluetooth_test_mac.h" | 5 #include "device/bluetooth/test/bluetooth_test_mac.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 BluetoothDeviceMac::GetNSErrorFromConnectErrorCode(errorCode); | 206 BluetoothDeviceMac::GetNSErrorFromConnectErrorCode(errorCode); |
207 [centralManager.delegate centralManager:centralManager | 207 [centralManager.delegate centralManager:centralManager |
208 didFailToConnectPeripheral:peripheral | 208 didFailToConnectPeripheral:peripheral |
209 error:error]; | 209 error:error]; |
210 } | 210 } |
211 | 211 |
212 void BluetoothTestMac::SimulateGattDisconnection(BluetoothDevice* device) { | 212 void BluetoothTestMac::SimulateGattDisconnection(BluetoothDevice* device) { |
213 BluetoothLowEnergyDeviceMac* lowEnergyDeviceMac = | 213 BluetoothLowEnergyDeviceMac* lowEnergyDeviceMac = |
214 static_cast<BluetoothLowEnergyDeviceMac*>(device); | 214 static_cast<BluetoothLowEnergyDeviceMac*>(device); |
215 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); | 215 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); |
216 MockCBPeripheral* mockPeripheral = (MockCBPeripheral*)peripheral; | 216 MockCBPeripheral* peripheral_mock = (MockCBPeripheral*)peripheral; |
217 [mockPeripheral setState:CBPeripheralStateDisconnected]; | 217 [peripheral_mock setState:CBPeripheralStateDisconnected]; |
218 CBCentralManager* centralManager = | 218 CBCentralManager* central_manager = |
219 ObjCCast<CBCentralManager>(mock_central_manager_->get()); | 219 ObjCCast<CBCentralManager>(mock_central_manager_->get()); |
220 [centralManager.delegate centralManager:centralManager | 220 [central_manager.delegate centralManager:central_manager |
221 didDisconnectPeripheral:peripheral | 221 didDisconnectPeripheral:peripheral |
222 error:nil]; | 222 error:nil]; |
223 } | 223 } |
224 | 224 |
225 void BluetoothTestMac::SimulateGattServicesDiscovered( | 225 void BluetoothTestMac::SimulateGattServicesDiscovered( |
226 BluetoothDevice* device, | 226 BluetoothDevice* device, |
227 const std::vector<std::string>& uuids) { | 227 const std::vector<std::string>& uuids) { |
228 BluetoothLowEnergyDeviceMac* device_mac = | 228 BluetoothLowEnergyDeviceMac* device_mac = |
229 static_cast<BluetoothLowEnergyDeviceMac*>(device); | 229 static_cast<BluetoothLowEnergyDeviceMac*>(device); |
230 CBPeripheral* peripheral = device_mac->GetPeripheral(); | 230 CBPeripheral* peripheral = device_mac->GetPeripheral(); |
231 MockCBPeripheral* peripheral_mock = ObjCCast<MockCBPeripheral>(peripheral); | 231 MockCBPeripheral* peripheral_mock = ObjCCast<MockCBPeripheral>(peripheral); |
232 scoped_nsobject<NSMutableArray> services = [[NSMutableArray alloc] init]; | 232 scoped_nsobject<NSMutableArray> services = [[NSMutableArray alloc] init]; |
233 for (auto uuid : uuids) { | 233 for (auto uuid : uuids) { |
234 CBUUID* cb_service_uuid = [CBUUID UUIDWithString:@(uuid.c_str())]; | 234 CBUUID* cb_service_uuid = [CBUUID UUIDWithString:@(uuid.c_str())]; |
235 [services addObject:cb_service_uuid]; | 235 [services addObject:cb_service_uuid]; |
236 } | 236 } |
237 [peripheral_mock removeAllServices]; | |
238 [peripheral_mock addServices:services]; | 237 [peripheral_mock addServices:services]; |
239 [peripheral_mock didDiscoverWithError:nil]; | 238 [peripheral_mock didDiscoverServicesWithError:nil]; |
240 } | 239 } |
241 | 240 |
242 void BluetoothTestMac::SimulateGattServiceRemoved( | 241 void BluetoothTestMac::SimulateGattServiceRemoved( |
243 BluetoothRemoteGattService* service) { | 242 BluetoothRemoteGattService* service) { |
244 BluetoothUUID bluetooth_service_uuid = service->GetUUID(); | 243 BluetoothUUID bluetooth_service_uuid = service->GetUUID(); |
245 std::string service_uuid_string = bluetooth_service_uuid.canonical_value(); | 244 std::string service_uuid_string = bluetooth_service_uuid.canonical_value(); |
246 BluetoothRemoteGattServiceMac* mac_gatt_service = | 245 BluetoothRemoteGattServiceMac* mac_gatt_service = |
247 static_cast<BluetoothRemoteGattServiceMac*>(service); | 246 static_cast<BluetoothRemoteGattServiceMac*>(service); |
248 BluetoothDevice* device = service->GetDevice(); | 247 BluetoothDevice* device = service->GetDevice(); |
249 BluetoothLowEnergyDeviceMac* device_mac = | 248 BluetoothLowEnergyDeviceMac* device_mac = |
250 static_cast<BluetoothLowEnergyDeviceMac*>(device); | 249 static_cast<BluetoothLowEnergyDeviceMac*>(device); |
251 CBPeripheral* peripheral = device_mac->GetPeripheral(); | 250 CBPeripheral* peripheral = device_mac->GetPeripheral(); |
252 MockCBPeripheral* peripheral_mock = ObjCCast<MockCBPeripheral>(peripheral); | 251 MockCBPeripheral* peripheral_mock = ObjCCast<MockCBPeripheral>(peripheral); |
253 [peripheral_mock removeService:mac_gatt_service->GetService()]; | 252 [peripheral_mock removeService:mac_gatt_service->GetService()]; |
254 [peripheral_mock didDiscoverWithError:nil]; | 253 [peripheral_mock didDiscoverServicesWithError:nil]; |
ortuno
2016/06/03 00:05:10
This ends up calling didDiscoverServices which mea
jlebel
2016/06/03 00:23:19
After calling -[<CBPeripheralDelegate> peripheral:
ortuno
2016/06/03 01:07:56
Ah I see. Hmm the test seems bit fragile but no ne
| |
255 } | 254 } |
256 | 255 |
257 void BluetoothTestMac::OnFakeBluetoothDeviceConnectGattCalled() { | 256 void BluetoothTestMac::OnFakeBluetoothDeviceConnectGattCalled() { |
258 gatt_connection_attempts_++; | 257 gatt_connection_attempts_++; |
259 } | 258 } |
260 | 259 |
261 void BluetoothTestMac::OnFakeBluetoothGattDisconnect() { | 260 void BluetoothTestMac::OnFakeBluetoothGattDisconnect() { |
262 gatt_disconnection_attempts_++; | 261 gatt_disconnection_attempts_++; |
263 } | 262 } |
264 | 263 |
(...skipping 30 matching lines...) Expand all Loading... | |
295 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); | 294 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); |
296 // if (base::HexEncode(raw, sizeof(raw)) == target) { | 295 // if (base::HexEncode(raw, sizeof(raw)) == target) { |
297 // return input_str; | 296 // return input_str; |
298 // } | 297 // } |
299 // ++input[0]; | 298 // ++input[0]; |
300 // } | 299 // } |
301 // return ""; | 300 // return ""; |
302 // } | 301 // } |
303 | 302 |
304 } // namespace device | 303 } // namespace device |
OLD | NEW |