OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <device/bluetooth/test/test_bluetooth_local_gatt_service_delegate.h> |
| 6 #include "base/callback.h" |
| 7 #include "device/bluetooth/test/bluetooth_gatt_server_test.h" |
| 8 |
| 9 namespace device { |
| 10 |
| 11 TestBluetoothLocalGattServiceDelegate::TestBluetoothLocalGattServiceDelegate() |
| 12 : should_fail_(false), |
| 13 last_written_value_(0), |
| 14 value_to_write_(0), |
| 15 expected_service_(nullptr), |
| 16 expected_characteristic_(nullptr), |
| 17 expected_descriptor_(nullptr) {} |
| 18 |
| 19 void TestBluetoothLocalGattServiceDelegate::OnCharacteristicReadRequest( |
| 20 const BluetoothLocalGattService* service, |
| 21 const BluetoothLocalGattCharacteristic* characteristic, |
| 22 int offset, |
| 23 const ValueCallback& callback, |
| 24 const ErrorCallback& error_callback) { |
| 25 EXPECT_EQ(expected_service_, service); |
| 26 EXPECT_EQ(expected_characteristic_, characteristic); |
| 27 if (should_fail_) { |
| 28 error_callback.Run(); |
| 29 return; |
| 30 } |
| 31 callback.Run(BluetoothGattServerTest::GetValue(value_to_write_)); |
| 32 } |
| 33 |
| 34 void TestBluetoothLocalGattServiceDelegate::OnCharacteristicWriteRequest( |
| 35 const BluetoothLocalGattService* service, |
| 36 const BluetoothLocalGattCharacteristic* characteristic, |
| 37 const std::vector<uint8_t>& value, |
| 38 int offset, |
| 39 const base::Closure& callback, |
| 40 const ErrorCallback& error_callback) { |
| 41 EXPECT_EQ(expected_service_, service); |
| 42 EXPECT_EQ(expected_characteristic_, characteristic); |
| 43 if (should_fail_) { |
| 44 error_callback.Run(); |
| 45 return; |
| 46 } |
| 47 last_written_value_ = BluetoothGattServerTest::GetInteger(value); |
| 48 callback.Run(); |
| 49 } |
| 50 |
| 51 void TestBluetoothLocalGattServiceDelegate::OnDescriptorReadRequest( |
| 52 const BluetoothLocalGattService* service, |
| 53 const BluetoothLocalGattDescriptor* descriptor, |
| 54 int offset, |
| 55 const ValueCallback& callback, |
| 56 const ErrorCallback& error_callback) { |
| 57 EXPECT_EQ(expected_service_, service); |
| 58 EXPECT_EQ(expected_descriptor_, descriptor); |
| 59 if (should_fail_) { |
| 60 error_callback.Run(); |
| 61 return; |
| 62 } |
| 63 callback.Run(BluetoothGattServerTest::GetValue(value_to_write_)); |
| 64 } |
| 65 |
| 66 void TestBluetoothLocalGattServiceDelegate::OnDescriptorWriteRequest( |
| 67 const BluetoothLocalGattService* service, |
| 68 const BluetoothLocalGattDescriptor* descriptor, |
| 69 const std::vector<uint8_t>& value, |
| 70 int offset, |
| 71 const base::Closure& callback, |
| 72 const ErrorCallback& error_callback) { |
| 73 EXPECT_EQ(expected_service_, service); |
| 74 EXPECT_EQ(expected_descriptor_, descriptor); |
| 75 if (should_fail_) { |
| 76 error_callback.Run(); |
| 77 return; |
| 78 } |
| 79 last_written_value_ = BluetoothGattServerTest::GetInteger(value); |
| 80 callback.Run(); |
| 81 } |
| 82 |
| 83 } // namespace device |
OLD | NEW |