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/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 static_cast<BluetoothLowEnergyDeviceMac*>(device); | 195 static_cast<BluetoothLowEnergyDeviceMac*>(device); |
196 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); | 196 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); |
197 MockCBPeripheral* mockPeripheral = static_cast<MockCBPeripheral*>(peripheral); | 197 MockCBPeripheral* mockPeripheral = static_cast<MockCBPeripheral*>(peripheral); |
198 [mockPeripheral setState:CBPeripheralStateConnected]; | 198 [mockPeripheral setState:CBPeripheralStateConnected]; |
199 CBCentralManager* centralManager = | 199 CBCentralManager* centralManager = |
200 static_cast<CBCentralManager*>(mock_central_manager_); | 200 static_cast<CBCentralManager*>(mock_central_manager_); |
201 [centralManager.delegate centralManager:centralManager | 201 [centralManager.delegate centralManager:centralManager |
202 didConnectPeripheral:peripheral]; | 202 didConnectPeripheral:peripheral]; |
203 } | 203 } |
204 | 204 |
205 void BluetoothTestMac::SimulateGattDisconnection(BluetoothDevice* device) { | 205 void BluetoothTestMac::SimulateGattConnectionError( |
206 BluetoothDevice* device, | |
207 BluetoothDevice::ConnectErrorCode errorCode) { | |
206 BluetoothLowEnergyDeviceMac* lowEnergyDeviceMac = | 208 BluetoothLowEnergyDeviceMac* lowEnergyDeviceMac = |
207 static_cast<BluetoothLowEnergyDeviceMac*>(device); | 209 static_cast<BluetoothLowEnergyDeviceMac*>(device); |
208 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); | 210 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); |
209 MockCBPeripheral* mockPeripheral = static_cast<MockCBPeripheral*>(peripheral); | 211 MockCBPeripheral* mockPeripheral = static_cast<MockCBPeripheral*>(peripheral); |
msarda
2016/02/22 14:06:22
Use ObjcCast instead of static_cast for Objective-
| |
210 [mockPeripheral setState:CBPeripheralStateDisconnected]; | 212 [mockPeripheral setState:CBPeripheralStateDisconnected]; |
211 CBCentralManager* centralManager = | 213 CBCentralManager* centralManager = |
212 static_cast<CBCentralManager*>(mock_central_manager_); | 214 static_cast<CBCentralManager*>(mock_central_manager_); |
215 NSError* error = | |
216 BluetoothAdapterMac::GetNSErrorFromConnectErrorCode(errorCode); | |
213 [centralManager.delegate centralManager:centralManager | 217 [centralManager.delegate centralManager:centralManager |
214 didDisconnectPeripheral:peripheral | 218 didFailToConnectPeripheral:peripheral |
215 error:nil]; | 219 error:error]; |
216 } | 220 } |
217 | 221 |
218 void BluetoothTestMac::SimulateGattConnectionError( | 222 void BluetoothTestMac::SimulateGattDisconnection(BluetoothDevice* device) { |
219 BluetoothDevice* device, | |
220 BluetoothDevice::ConnectErrorCode errorCode) { | |
221 BluetoothLowEnergyDeviceMac* lowEnergyDeviceMac = | 223 BluetoothLowEnergyDeviceMac* lowEnergyDeviceMac = |
222 static_cast<BluetoothLowEnergyDeviceMac*>(device); | 224 static_cast<BluetoothLowEnergyDeviceMac*>(device); |
223 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); | 225 CBPeripheral* peripheral = lowEnergyDeviceMac->GetPeripheral(); |
224 MockCBPeripheral* mockPeripheral = static_cast<MockCBPeripheral*>(peripheral); | 226 MockCBPeripheral* mockPeripheral = static_cast<MockCBPeripheral*>(peripheral); |
225 [mockPeripheral setState:CBPeripheralStateDisconnected]; | 227 [mockPeripheral setState:CBPeripheralStateDisconnected]; |
226 CBCentralManager* centralManager = | 228 CBCentralManager* centralManager = |
227 static_cast<CBCentralManager*>(mock_central_manager_); | 229 static_cast<CBCentralManager*>(mock_central_manager_); |
228 // TODO(http://crbug.com/585894): Need to convert the connect error code into | |
229 // NSError | |
230 NSError* error = [NSError errorWithDomain:@"BluetoothDevice::ConnectErrorCode" | |
231 code:-1 | |
232 userInfo:nil]; | |
233 [centralManager.delegate centralManager:centralManager | 230 [centralManager.delegate centralManager:centralManager |
234 didFailToConnectPeripheral:peripheral | 231 didDisconnectPeripheral:peripheral |
235 error:error]; | 232 error:nil]; |
236 } | 233 } |
237 | 234 |
238 void BluetoothTestMac::OnFakeBluetoothDeviceConnectGattCalled() { | 235 void BluetoothTestMac::OnFakeBluetoothDeviceConnectGattCalled() { |
239 gatt_connection_attempts_++; | 236 gatt_connection_attempts_++; |
240 } | 237 } |
241 | 238 |
242 void BluetoothTestMac::OnFakeBluetoothGattDisconnect() { | 239 void BluetoothTestMac::OnFakeBluetoothGattDisconnect() { |
243 gatt_disconnection_attempts_++; | 240 gatt_disconnection_attempts_++; |
244 } | 241 } |
245 | 242 |
(...skipping 26 matching lines...) Expand all Loading... | |
272 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); | 269 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); |
273 // if (base::HexEncode(raw, sizeof(raw)) == target) { | 270 // if (base::HexEncode(raw, sizeof(raw)) == target) { |
274 // return input_str; | 271 // return input_str; |
275 // } | 272 // } |
276 // ++input[0]; | 273 // ++input[0]; |
277 // } | 274 // } |
278 // return ""; | 275 // return ""; |
279 // } | 276 // } |
280 | 277 |
281 } // namespace device | 278 } // namespace device |
OLD | NEW |