| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/test_bluetooth_local_gatt_service_delegate.h> | 5 #include <device/bluetooth/test/test_bluetooth_local_gatt_service_delegate.h> |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "device/bluetooth/test/bluetooth_gatt_server_test.h" | 7 #include "device/bluetooth/test/bluetooth_gatt_server_test.h" |
| 8 | 8 |
| 9 namespace device { | 9 namespace device { |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 const BluetoothLocalGattCharacteristic* characteristic, | 24 const BluetoothLocalGattCharacteristic* characteristic, |
| 25 int offset, | 25 int offset, |
| 26 const ValueCallback& callback, | 26 const ValueCallback& callback, |
| 27 const ErrorCallback& error_callback) { | 27 const ErrorCallback& error_callback) { |
| 28 EXPECT_EQ(expected_characteristic_->GetIdentifier(), | 28 EXPECT_EQ(expected_characteristic_->GetIdentifier(), |
| 29 characteristic->GetIdentifier()); | 29 characteristic->GetIdentifier()); |
| 30 if (should_fail_) { | 30 if (should_fail_) { |
| 31 error_callback.Run(); | 31 error_callback.Run(); |
| 32 return; | 32 return; |
| 33 } | 33 } |
| 34 last_seen_device_ = device->GetIdentifier(); |
| 34 callback.Run(BluetoothGattServerTest::GetValue(value_to_write_)); | 35 callback.Run(BluetoothGattServerTest::GetValue(value_to_write_)); |
| 35 } | 36 } |
| 36 | 37 |
| 37 void TestBluetoothLocalGattServiceDelegate::OnCharacteristicWriteRequest( | 38 void TestBluetoothLocalGattServiceDelegate::OnCharacteristicWriteRequest( |
| 38 const BluetoothDevice* device, | 39 const BluetoothDevice* device, |
| 39 const BluetoothLocalGattCharacteristic* characteristic, | 40 const BluetoothLocalGattCharacteristic* characteristic, |
| 40 const std::vector<uint8_t>& value, | 41 const std::vector<uint8_t>& value, |
| 41 int offset, | 42 int offset, |
| 42 const base::Closure& callback, | 43 const base::Closure& callback, |
| 43 const ErrorCallback& error_callback) { | 44 const ErrorCallback& error_callback) { |
| 44 EXPECT_EQ(expected_characteristic_->GetIdentifier(), | 45 EXPECT_EQ(expected_characteristic_->GetIdentifier(), |
| 45 characteristic->GetIdentifier()); | 46 characteristic->GetIdentifier()); |
| 46 if (should_fail_) { | 47 if (should_fail_) { |
| 47 error_callback.Run(); | 48 error_callback.Run(); |
| 48 return; | 49 return; |
| 49 } | 50 } |
| 51 last_seen_device_ = device->GetIdentifier(); |
| 50 last_written_value_ = BluetoothGattServerTest::GetInteger(value); | 52 last_written_value_ = BluetoothGattServerTest::GetInteger(value); |
| 51 callback.Run(); | 53 callback.Run(); |
| 52 } | 54 } |
| 53 | 55 |
| 54 void TestBluetoothLocalGattServiceDelegate::OnDescriptorReadRequest( | 56 void TestBluetoothLocalGattServiceDelegate::OnDescriptorReadRequest( |
| 55 const BluetoothDevice* device, | 57 const BluetoothDevice* device, |
| 56 const BluetoothLocalGattDescriptor* descriptor, | 58 const BluetoothLocalGattDescriptor* descriptor, |
| 57 int offset, | 59 int offset, |
| 58 const ValueCallback& callback, | 60 const ValueCallback& callback, |
| 59 const ErrorCallback& error_callback) { | 61 const ErrorCallback& error_callback) { |
| 60 EXPECT_EQ(expected_descriptor_->GetIdentifier(), descriptor->GetIdentifier()); | 62 EXPECT_EQ(expected_descriptor_->GetIdentifier(), descriptor->GetIdentifier()); |
| 61 if (should_fail_) { | 63 if (should_fail_) { |
| 62 error_callback.Run(); | 64 error_callback.Run(); |
| 63 return; | 65 return; |
| 64 } | 66 } |
| 67 last_seen_device_ = device->GetIdentifier(); |
| 65 callback.Run(BluetoothGattServerTest::GetValue(value_to_write_)); | 68 callback.Run(BluetoothGattServerTest::GetValue(value_to_write_)); |
| 66 } | 69 } |
| 67 | 70 |
| 68 void TestBluetoothLocalGattServiceDelegate::OnDescriptorWriteRequest( | 71 void TestBluetoothLocalGattServiceDelegate::OnDescriptorWriteRequest( |
| 69 const BluetoothDevice* device, | 72 const BluetoothDevice* device, |
| 70 const BluetoothLocalGattDescriptor* descriptor, | 73 const BluetoothLocalGattDescriptor* descriptor, |
| 71 const std::vector<uint8_t>& value, | 74 const std::vector<uint8_t>& value, |
| 72 int offset, | 75 int offset, |
| 73 const base::Closure& callback, | 76 const base::Closure& callback, |
| 74 const ErrorCallback& error_callback) { | 77 const ErrorCallback& error_callback) { |
| 75 EXPECT_EQ(expected_descriptor_->GetIdentifier(), descriptor->GetIdentifier()); | 78 EXPECT_EQ(expected_descriptor_->GetIdentifier(), descriptor->GetIdentifier()); |
| 76 if (should_fail_) { | 79 if (should_fail_) { |
| 77 error_callback.Run(); | 80 error_callback.Run(); |
| 78 return; | 81 return; |
| 79 } | 82 } |
| 83 last_seen_device_ = device->GetIdentifier(); |
| 80 last_written_value_ = BluetoothGattServerTest::GetInteger(value); | 84 last_written_value_ = BluetoothGattServerTest::GetInteger(value); |
| 81 callback.Run(); | 85 callback.Run(); |
| 82 } | 86 } |
| 83 | 87 |
| 84 void TestBluetoothLocalGattServiceDelegate::OnNotificationsStart( | 88 void TestBluetoothLocalGattServiceDelegate::OnNotificationsStart( |
| 85 const BluetoothDevice* device, | 89 const BluetoothDevice* device, |
| 86 const BluetoothLocalGattCharacteristic* characteristic) { | 90 const BluetoothLocalGattCharacteristic* characteristic) { |
| 87 EXPECT_EQ(expected_characteristic_->GetIdentifier(), | 91 EXPECT_EQ(expected_characteristic_->GetIdentifier(), |
| 88 characteristic->GetIdentifier()); | 92 characteristic->GetIdentifier()); |
| 89 notifications_started_for_characteristic_[characteristic->GetIdentifier()] = | 93 notifications_started_for_characteristic_[characteristic->GetIdentifier()] = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 102 bool TestBluetoothLocalGattServiceDelegate::NotificationStatusForCharacteristic( | 106 bool TestBluetoothLocalGattServiceDelegate::NotificationStatusForCharacteristic( |
| 103 BluetoothLocalGattCharacteristic* characteristic) { | 107 BluetoothLocalGattCharacteristic* characteristic) { |
| 104 auto found = notifications_started_for_characteristic_.find( | 108 auto found = notifications_started_for_characteristic_.find( |
| 105 characteristic->GetIdentifier()); | 109 characteristic->GetIdentifier()); |
| 106 if (found == notifications_started_for_characteristic_.end()) | 110 if (found == notifications_started_for_characteristic_.end()) |
| 107 return false; | 111 return false; |
| 108 return found->second; | 112 return found->second; |
| 109 } | 113 } |
| 110 | 114 |
| 111 } // namespace device | 115 } // namespace device |
| OLD | NEW |