OLD | NEW |
1 // Copyright 2014 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 #ifndef DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_GATT_DESCRIPTOR_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_DESCRIPTOR_H_ |
6 #define DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_GATT_DESCRIPTOR_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_DESCRIPTOR_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | |
10 #include <string> | |
11 #include <vector> | 9 #include <vector> |
12 | 10 |
13 #include "base/callback.h" | |
14 #include "base/macros.h" | 11 #include "base/macros.h" |
15 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | 12 #include "device/bluetooth/bluetooth_export.h" |
16 #include "device/bluetooth/bluetooth_gatt_descriptor.h" | 13 #include "device/bluetooth/bluetooth_gatt_descriptor.h" |
| 14 #include "device/bluetooth/bluetooth_local_gatt_characteristic.h" |
17 #include "device/bluetooth/bluetooth_uuid.h" | 15 #include "device/bluetooth/bluetooth_uuid.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | |
19 | 16 |
20 namespace device { | 17 namespace device { |
21 | 18 |
22 class MockBluetoothGattCharacteristic; | 19 // BluetoothLocalGattDescriptor represents a local GATT characteristic |
| 20 // descriptor. A GATT characteristic descriptor provides further information |
| 21 // about a characteristic's value. They can be used to describe the |
| 22 // characteristic's features or to control certain behaviors. |
| 23 // |
| 24 // Note: We use virtual inheritance on the GATT descriptor since it will be |
| 25 // inherited by platform specific versions of the GATT descriptor classes also. |
| 26 // The platform specific local GATT descriptor classes will inherit both this |
| 27 // class and their GATT descriptor class, hence causing an inheritance diamond. |
| 28 class DEVICE_BLUETOOTH_EXPORT BluetoothLocalGattDescriptor |
| 29 : public virtual BluetoothGattDescriptor { |
| 30 public: |
| 31 // Constructs a BluetoothLocalGattDescriptor that can be associated with a |
| 32 // local GATT characteristic when the adapter is in the peripheral role. To |
| 33 // associate the returned descriptor with a characteristic, provide a pointer |
| 34 // to that characteristic instance to the create function. |
| 35 // |
| 36 // This method constructs a characteristic descriptor with UUID |uuid| and the |
| 37 // initial cached value |value|. |value| will be cached and returned for read |
| 38 // requests and automatically modified for write requests by default, unless |
| 39 // an instance of BluetoothLocalGattService::Delegate has been provided to |
| 40 // the |
| 41 // associated BluetoothLocalGattService instance, in which case the delegate |
| 42 // will |
| 43 // handle the read and write requests. |
| 44 // |
| 45 // Currently, only custom UUIDs, |kCharacteristicDescriptionUuid|, and |
| 46 // |kCharacteristicPresentationFormat| are supported for locally hosted |
| 47 // descriptors. This method will return NULL if |uuid| is any one of the |
| 48 // unsupported predefined descriptor UUIDs. |
| 49 static BluetoothLocalGattDescriptor* Create( |
| 50 const BluetoothUUID& uuid, |
| 51 const std::vector<uint8_t>& value, |
| 52 BluetoothGattCharacteristic::Permissions permissions, |
| 53 BluetoothLocalGattCharacteristic* characteristic); |
23 | 54 |
24 class MockBluetoothGattDescriptor : public BluetoothGattDescriptor { | 55 protected: |
25 public: | 56 BluetoothLocalGattDescriptor(); |
26 MockBluetoothGattDescriptor( | 57 ~BluetoothLocalGattDescriptor() override; |
27 MockBluetoothGattCharacteristic* characteristic, | |
28 const std::string& identifier, | |
29 const BluetoothUUID& uuid, | |
30 bool is_local, | |
31 BluetoothGattCharacteristic::Permissions permissions); | |
32 virtual ~MockBluetoothGattDescriptor(); | |
33 | |
34 MOCK_CONST_METHOD0(GetIdentifier, std::string()); | |
35 MOCK_CONST_METHOD0(GetUUID, BluetoothUUID()); | |
36 MOCK_CONST_METHOD0(IsLocal, bool()); | |
37 MOCK_CONST_METHOD0(GetValue, const std::vector<uint8_t>&()); | |
38 MOCK_CONST_METHOD0(GetCharacteristic, BluetoothGattCharacteristic*()); | |
39 MOCK_CONST_METHOD0(GetPermissions, | |
40 BluetoothGattCharacteristic::Permissions()); | |
41 MOCK_METHOD2(ReadRemoteDescriptor, | |
42 void(const ValueCallback&, const ErrorCallback&)); | |
43 MOCK_METHOD3(WriteRemoteDescriptor, | |
44 void(const std::vector<uint8_t>&, | |
45 const base::Closure&, | |
46 const ErrorCallback&)); | |
47 | 58 |
48 private: | 59 private: |
49 DISALLOW_COPY_AND_ASSIGN(MockBluetoothGattDescriptor); | 60 DISALLOW_COPY_AND_ASSIGN(BluetoothLocalGattDescriptor); |
50 }; | 61 }; |
51 | 62 |
52 } // namespace device | 63 } // namespace device |
53 | 64 |
54 #endif // DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_GATT_DESCRIPTOR_H_ | 65 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOCAL_GATT_DESCRIPTOR_H_ |
OLD | NEW |