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 #ifndef DEVICE_BLUETOOTH_TEST_BLUETOOTH_GATT_SERVER_TEST_H_ |
| 6 #define DEVICE_BLUETOOTH_TEST_BLUETOOTH_GATT_SERVER_TEST_H_ |
| 7 |
| 8 #include <cstdint> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/callback_forward.h" |
| 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "device/bluetooth/bluetooth_local_gatt_characteristic.h" |
| 15 #include "device/bluetooth/bluetooth_local_gatt_descriptor.h" |
| 16 #include "device/bluetooth/bluetooth_local_gatt_service.h" |
| 17 |
| 18 #if defined(OS_ANDROID) |
| 19 #include "device/bluetooth/test/bluetooth_test_android.h" |
| 20 #elif defined(OS_MACOSX) |
| 21 #include "device/bluetooth/test/bluetooth_test_mac.h" |
| 22 #elif defined(OS_WIN) |
| 23 #include "device/bluetooth/test/bluetooth_test_win.h" |
| 24 #elif defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 25 #include "device/bluetooth/test/bluetooth_test_bluez.h" |
| 26 #endif |
| 27 |
| 28 namespace device { |
| 29 |
| 30 class TestLocalGattServiceDelegate |
| 31 : public BluetoothLocalGattService::Delegate { |
| 32 public: |
| 33 TestLocalGattServiceDelegate(); |
| 34 |
| 35 void OnCharacteristicReadRequest( |
| 36 const BluetoothLocalGattService* service, |
| 37 const BluetoothLocalGattCharacteristic* characteristic, |
| 38 int offset, |
| 39 const ValueCallback& callback, |
| 40 const ErrorCallback& error_callback) override; |
| 41 void OnCharacteristicWriteRequest( |
| 42 const BluetoothLocalGattService* service, |
| 43 const BluetoothLocalGattCharacteristic* characteristic, |
| 44 const std::vector<uint8_t>& value, |
| 45 int offset, |
| 46 const base::Closure& callback, |
| 47 const ErrorCallback& error_callback) override; |
| 48 void OnDescriptorReadRequest(const BluetoothLocalGattService* service, |
| 49 const BluetoothLocalGattDescriptor* descriptor, |
| 50 int offset, |
| 51 const ValueCallback& callback, |
| 52 const ErrorCallback& error_callback) override; |
| 53 |
| 54 void OnDescriptorWriteRequest(const BluetoothLocalGattService* service, |
| 55 const BluetoothLocalGattDescriptor* descriptor, |
| 56 const std::vector<uint8_t>& value, |
| 57 int offset, |
| 58 const base::Closure& callback, |
| 59 const ErrorCallback& error_callback) override; |
| 60 |
| 61 void set_expected_service(BluetoothLocalGattService* service) { |
| 62 expected_service_ = service; |
| 63 } |
| 64 |
| 65 void set_expected_characteristic( |
| 66 BluetoothLocalGattCharacteristic* characteristic) { |
| 67 expected_characteristic_ = characteristic; |
| 68 } |
| 69 |
| 70 void set_expected_descriptor(BluetoothLocalGattDescriptor* descriptor) { |
| 71 expected_descriptor_ = descriptor; |
| 72 } |
| 73 |
| 74 static bool should_fail_; |
| 75 static uint64_t last_written_value_; |
| 76 static uint64_t value_to_write_; |
| 77 |
| 78 private: |
| 79 BluetoothLocalGattService* expected_service_; |
| 80 BluetoothLocalGattCharacteristic* expected_characteristic_; |
| 81 BluetoothLocalGattDescriptor* expected_descriptor_; |
| 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(TestLocalGattServiceDelegate); |
| 84 }; |
| 85 |
| 86 // Base class for BlueZ GATT server unit tests. |
| 87 class BluetoothGattServerTest : public BluetoothTest { |
| 88 public: |
| 89 BluetoothGattServerTest(); |
| 90 ~BluetoothGattServerTest() override; |
| 91 |
| 92 // Start and complete boilerplate setup steps. |
| 93 void StartGattSetup(); |
| 94 void CompleteGattSetup(); |
| 95 |
| 96 // BluetoothTest overrides: |
| 97 void SetUp() override; |
| 98 void TearDown() override; |
| 99 |
| 100 // Utility methods to deal with values. |
| 101 static uint64_t GetInteger(const std::vector<uint8_t>& value); |
| 102 static std::vector<uint8_t> GetValue(uint64_t int_value); |
| 103 |
| 104 protected: |
| 105 base::WeakPtr<BluetoothLocalGattService> service_; |
| 106 |
| 107 std::unique_ptr<TestLocalGattServiceDelegate> delegate_; |
| 108 }; |
| 109 |
| 110 } // namespace device |
| 111 |
| 112 #endif // DEVICE_BLUETOOTH_TEST_BLUETOOTH_GATT_SERVER_TEST_H_ |
OLD | NEW |