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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 | 318 |
319 void BluetoothTestMac::SimulateGattCharacteristicWriteError( | 319 void BluetoothTestMac::SimulateGattCharacteristicWriteError( |
320 BluetoothRemoteGattCharacteristic* characteristic, | 320 BluetoothRemoteGattCharacteristic* characteristic, |
321 BluetoothRemoteGattService::GattErrorCode error_code) { | 321 BluetoothRemoteGattService::GattErrorCode error_code) { |
322 MockCBCharacteristic* characteristic_mock = | 322 MockCBCharacteristic* characteristic_mock = |
323 GetCBMockCharacteristic(characteristic); | 323 GetCBMockCharacteristic(characteristic); |
324 NSError* error = BluetoothDeviceMac::GetNSErrorFromGattErrorCode(error_code); | 324 NSError* error = BluetoothDeviceMac::GetNSErrorFromGattErrorCode(error_code); |
325 [characteristic_mock simulateWriteWithError:error]; | 325 [characteristic_mock simulateWriteWithError:error]; |
326 } | 326 } |
327 | 327 |
| 328 void BluetoothTestMac::SimulateGattNotifySessionStarted( |
| 329 BluetoothRemoteGattCharacteristic* characteristic) { |
| 330 MockCBCharacteristic* characteristic_mock = |
| 331 GetCBMockCharacteristic(characteristic); |
| 332 [characteristic_mock simulateGattNotifySessionStarted]; |
| 333 } |
| 334 |
| 335 void BluetoothTestMac::SimulateGattNotifySessionStartError( |
| 336 BluetoothRemoteGattCharacteristic* characteristic, |
| 337 BluetoothRemoteGattService::GattErrorCode error_code) { |
| 338 MockCBCharacteristic* characteristic_mock = |
| 339 GetCBMockCharacteristic(characteristic); |
| 340 NSError* error = BluetoothDeviceMac::GetNSErrorFromGattErrorCode(error_code); |
| 341 [characteristic_mock simulateGattNotifySessionFailedWithError:error]; |
| 342 } |
| 343 |
| 344 void BluetoothTestMac::SimulateGattCharacteristicChanged( |
| 345 BluetoothRemoteGattCharacteristic* characteristic, |
| 346 const std::vector<uint8_t>& value) { |
| 347 MockCBCharacteristic* characteristic_mock = |
| 348 GetCBMockCharacteristic(characteristic); |
| 349 scoped_nsobject<NSData> data( |
| 350 [[NSData alloc] initWithBytes:value.data() length:value.size()]); |
| 351 [characteristic_mock simulateGattCharacteristicChangedWithValue:data]; |
| 352 } |
| 353 |
328 void BluetoothTestMac::SimulateGattCharacteristicRemoved( | 354 void BluetoothTestMac::SimulateGattCharacteristicRemoved( |
329 BluetoothRemoteGattService* service, | 355 BluetoothRemoteGattService* service, |
330 BluetoothRemoteGattCharacteristic* characteristic) { | 356 BluetoothRemoteGattCharacteristic* characteristic) { |
331 MockCBPeripheral* peripheral_mock = GetMockCBPeripheral(service); | 357 MockCBPeripheral* peripheral_mock = GetMockCBPeripheral(service); |
332 BluetoothRemoteGattServiceMac* mac_gatt_service = | 358 BluetoothRemoteGattServiceMac* mac_gatt_service = |
333 static_cast<BluetoothRemoteGattServiceMac*>(service); | 359 static_cast<BluetoothRemoteGattServiceMac*>(service); |
334 CBService* cb_service = mac_gatt_service->GetService(); | 360 CBService* cb_service = mac_gatt_service->GetService(); |
335 MockCBService* service_mock = ObjCCast<MockCBService>(cb_service); | 361 MockCBService* service_mock = ObjCCast<MockCBService>(cb_service); |
336 BluetoothRemoteGattCharacteristicMac* characteristic_mac = | 362 BluetoothRemoteGattCharacteristicMac* characteristic_mac = |
337 static_cast<BluetoothRemoteGattCharacteristicMac*>(characteristic); | 363 static_cast<BluetoothRemoteGattCharacteristicMac*>(characteristic); |
(...skipping 20 matching lines...) Expand all Loading... |
358 void BluetoothTest::OnFakeBluetoothCharacteristicReadValue() { | 384 void BluetoothTest::OnFakeBluetoothCharacteristicReadValue() { |
359 gatt_read_characteristic_attempts_++; | 385 gatt_read_characteristic_attempts_++; |
360 } | 386 } |
361 | 387 |
362 void BluetoothTest::OnFakeBluetoothCharacteristicWriteValue( | 388 void BluetoothTest::OnFakeBluetoothCharacteristicWriteValue( |
363 std::vector<uint8_t> value) { | 389 std::vector<uint8_t> value) { |
364 last_write_value_ = value; | 390 last_write_value_ = value; |
365 gatt_write_characteristic_attempts_++; | 391 gatt_write_characteristic_attempts_++; |
366 } | 392 } |
367 | 393 |
| 394 void BluetoothTest::OnFakeBluetoothGattSetCharacteristicNotification() { |
| 395 gatt_notify_characteristic_attempts_++; |
| 396 } |
| 397 |
368 MockCBPeripheral* BluetoothTestMac::GetMockCBPeripheral( | 398 MockCBPeripheral* BluetoothTestMac::GetMockCBPeripheral( |
369 BluetoothRemoteGattService* service) const { | 399 BluetoothRemoteGattService* service) const { |
370 BluetoothDevice* device = service->GetDevice(); | 400 BluetoothDevice* device = service->GetDevice(); |
371 BluetoothLowEnergyDeviceMac* device_mac = | 401 BluetoothLowEnergyDeviceMac* device_mac = |
372 static_cast<BluetoothLowEnergyDeviceMac*>(device); | 402 static_cast<BluetoothLowEnergyDeviceMac*>(device); |
373 CBPeripheral* cb_peripheral = device_mac->GetPeripheral(); | 403 CBPeripheral* cb_peripheral = device_mac->GetPeripheral(); |
374 return ObjCCast<MockCBPeripheral>(cb_peripheral); | 404 return ObjCCast<MockCBPeripheral>(cb_peripheral); |
375 } | 405 } |
376 | 406 |
377 MockCBCharacteristic* BluetoothTest::GetCBMockCharacteristic( | 407 MockCBCharacteristic* BluetoothTest::GetCBMockCharacteristic( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); | 443 // crypto::SHA256HashString(input_str, raw, sizeof(raw)); |
414 // if (base::HexEncode(raw, sizeof(raw)) == target) { | 444 // if (base::HexEncode(raw, sizeof(raw)) == target) { |
415 // return input_str; | 445 // return input_str; |
416 // } | 446 // } |
417 // ++input[0]; | 447 // ++input[0]; |
418 // } | 448 // } |
419 // return ""; | 449 // return ""; |
420 // } | 450 // } |
421 | 451 |
422 } // namespace device | 452 } // namespace device |
OLD | NEW |