1 // Copyright 2014 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_MOCK_BLUETOOTH_GATT_CHARACTERISTIC_H_ 6 #define DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_GATT_CHARACTERISTIC_H_ 7 8 #include <stdint.h> 9 10 #include <memory> 11 #include <string> 12 #include <vector> 13 14 #include "base/callback.h" 15 #include "base/containers/span.h" 16 #include "base/macros.h" 17 #include "build/chromeos_buildflags.h" 18 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" 19 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h" 20 #include "device/bluetooth/public/cpp/bluetooth_uuid.h" 21 #include "testing/gmock/include/gmock/gmock.h" 22 23 namespace device { 24 25 class BluetoothRemoteGattDescriptor; 26 class BluetoothRemoteGattService; 27 class MockBluetoothGattDescriptor; 28 class MockBluetoothGattService; 29 30 class MockBluetoothGattCharacteristic 31 : public BluetoothRemoteGattCharacteristic { 32 public: 33 MockBluetoothGattCharacteristic(MockBluetoothGattService* service, 34 const std::string& identifier, 35 const BluetoothUUID& uuid, 36 Properties properties, 37 Permissions permissions); 38 ~MockBluetoothGattCharacteristic() override; 39 40 MOCK_CONST_METHOD0(GetIdentifier, std::string()); 41 MOCK_CONST_METHOD0(GetUUID, BluetoothUUID()); 42 MOCK_CONST_METHOD0(GetValue, const std::vector<uint8_t>&()); 43 MOCK_CONST_METHOD0(GetService, BluetoothRemoteGattService*()); 44 MOCK_CONST_METHOD0(GetProperties, Properties()); 45 MOCK_CONST_METHOD0(GetPermissions, Permissions()); 46 MOCK_CONST_METHOD0(IsNotifying, bool()); 47 MOCK_CONST_METHOD0(GetDescriptors, 48 std::vector<BluetoothRemoteGattDescriptor*>()); 49 MOCK_CONST_METHOD1(GetDescriptor, 50 BluetoothRemoteGattDescriptor*(const std::string&)); 51 #if BUILDFLAG(IS_ASH) StartNotifySession(NotificationType t,NotifySessionCallback c,ErrorCallback ec)52 void StartNotifySession(NotificationType t, 53 NotifySessionCallback c, 54 ErrorCallback ec) override { 55 StartNotifySession_(t, c, ec); 56 } 57 MOCK_METHOD3(StartNotifySession_, 58 void(NotificationType, NotifySessionCallback&, ErrorCallback&)); 59 #endif StartNotifySession(NotifySessionCallback c,ErrorCallback ec)60 void StartNotifySession(NotifySessionCallback c, ErrorCallback ec) override { 61 StartNotifySession_(c, ec); 62 } 63 MOCK_METHOD2(StartNotifySession_, 64 void(NotifySessionCallback&, ErrorCallback&)); StopNotifySession(BluetoothGattNotifySession * s,base::OnceClosure c)65 void StopNotifySession(BluetoothGattNotifySession* s, 66 base::OnceClosure c) override { 67 StopNotifySession_(s, c); 68 } 69 MOCK_METHOD2(StopNotifySession_, 70 void(BluetoothGattNotifySession*, base::OnceClosure&)); ReadRemoteCharacteristic(ValueCallback c,ErrorCallback ec)71 void ReadRemoteCharacteristic(ValueCallback c, ErrorCallback ec) override { 72 ReadRemoteCharacteristic_(c, ec); 73 } 74 MOCK_METHOD2(ReadRemoteCharacteristic_, void(ValueCallback&, ErrorCallback&)); WriteRemoteCharacteristic(const std::vector<uint8_t> & v,WriteType t,base::OnceClosure c,ErrorCallback ec)75 void WriteRemoteCharacteristic(const std::vector<uint8_t>& v, 76 WriteType t, 77 base::OnceClosure c, 78 ErrorCallback ec) override { 79 WriteRemoteCharacteristic_(v, t, c, ec); 80 } 81 MOCK_METHOD4(WriteRemoteCharacteristic_, 82 void(const std::vector<uint8_t>&, 83 WriteType, 84 base::OnceClosure&, 85 ErrorCallback&)); DeprecatedWriteRemoteCharacteristic(const std::vector<uint8_t> & v,base::OnceClosure c,ErrorCallback ec)86 void DeprecatedWriteRemoteCharacteristic(const std::vector<uint8_t>& v, 87 base::OnceClosure c, 88 ErrorCallback ec) override { 89 DeprecatedWriteRemoteCharacteristic_(v, c, ec); 90 } 91 MOCK_METHOD3(DeprecatedWriteRemoteCharacteristic_, 92 void(const std::vector<uint8_t>&, 93 base::OnceClosure&, 94 ErrorCallback&)); 95 #if BUILDFLAG(IS_ASH) PrepareWriteRemoteCharacteristic(const std::vector<uint8_t> & v,base::OnceClosure c,ErrorCallback ec)96 void PrepareWriteRemoteCharacteristic(const std::vector<uint8_t>& v, 97 base::OnceClosure c, 98 ErrorCallback ec) override { 99 PrepareWriteRemoteCharacteristic_(v, c, ec); 100 } 101 MOCK_METHOD3(PrepareWriteRemoteCharacteristic_, 102 void(const std::vector<uint8_t>&, 103 base::OnceClosure&, 104 ErrorCallback&)); 105 #endif 106 107 void AddMockDescriptor( 108 std::unique_ptr<MockBluetoothGattDescriptor> mock_descriptor); 109 110 protected: 111 #if BUILDFLAG(IS_ASH) SubscribeToNotifications(BluetoothRemoteGattDescriptor * d,NotificationType t,base::OnceClosure c,ErrorCallback ec)112 void SubscribeToNotifications(BluetoothRemoteGattDescriptor* d, 113 NotificationType t, 114 base::OnceClosure c, 115 ErrorCallback ec) override { 116 SubscribeToNotifications_(d, t, c, ec); 117 } 118 MOCK_METHOD4(SubscribeToNotifications_, 119 void(BluetoothRemoteGattDescriptor*, 120 NotificationType, 121 base::OnceClosure&, 122 ErrorCallback&)); 123 #else 124 void SubscribeToNotifications(BluetoothRemoteGattDescriptor* d, 125 base::OnceClosure c, 126 ErrorCallback ec) override { 127 SubscribeToNotifications_(d, c, ec); 128 } 129 MOCK_METHOD3(SubscribeToNotifications_, 130 void(BluetoothRemoteGattDescriptor*, 131 base::OnceClosure&, 132 ErrorCallback&)); 133 #endif UnsubscribeFromNotifications(BluetoothRemoteGattDescriptor * d,base::OnceClosure c,ErrorCallback ec)134 void UnsubscribeFromNotifications(BluetoothRemoteGattDescriptor* d, 135 base::OnceClosure c, 136 ErrorCallback ec) override { 137 UnsubscribeFromNotifications_(d, c, ec); 138 } 139 MOCK_METHOD3(UnsubscribeFromNotifications_, 140 void(BluetoothRemoteGattDescriptor*, 141 base::OnceClosure&, 142 ErrorCallback&)); 143 144 private: 145 DISALLOW_COPY_AND_ASSIGN(MockBluetoothGattCharacteristic); 146 }; 147 148 } // namespace device 149 150 #endif // DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_GATT_CHARACTERISTIC_H_ 151