1 // Copyright 2018 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 CHROMECAST_DEVICE_BLUETOOTH_LE_MOCK_REMOTE_CHARACTERISTIC_H_ 6 #define CHROMECAST_DEVICE_BLUETOOTH_LE_MOCK_REMOTE_CHARACTERISTIC_H_ 7 8 #include <utility> 9 #include <vector> 10 11 #include "chromecast/device/bluetooth/le/remote_characteristic.h" 12 #include "chromecast/device/bluetooth/le/remote_descriptor.h" 13 #include "testing/gmock/include/gmock/gmock.h" 14 15 namespace chromecast { 16 namespace bluetooth { 17 18 class MockRemoteCharacteristic : public RemoteCharacteristic { 19 public: 20 explicit MockRemoteCharacteristic(const bluetooth_v2_shlib::Uuid& uuid); 21 22 MOCK_METHOD0(GetDescriptors, std::vector<scoped_refptr<RemoteDescriptor>>()); 23 MOCK_METHOD1( 24 GetDescriptorByUuid, 25 scoped_refptr<RemoteDescriptor>(const bluetooth_v2_shlib::Uuid& uuid)); 26 27 MOCK_METHOD1(SetRegisterNotification, bool(bool)); SetRegisterNotification(bool enable,StatusCallback cb)28 void SetRegisterNotification(bool enable, StatusCallback cb) override { 29 std::move(cb).Run(SetRegisterNotification(enable)); 30 } 31 32 MOCK_METHOD1(SetRegisterNotificationOrIndication, bool(bool)); SetRegisterNotificationOrIndication(bool enable,StatusCallback cb)33 void SetRegisterNotificationOrIndication(bool enable, 34 StatusCallback cb) override { 35 std::move(cb).Run(SetRegisterNotificationOrIndication(enable)); 36 } 37 SetNotification(bool enable,StatusCallback cb)38 void SetNotification(bool enable, StatusCallback cb) override {} ReadAuth(bluetooth_v2_shlib::Gatt::Client::AuthReq auth_req,ReadCallback callback)39 void ReadAuth(bluetooth_v2_shlib::Gatt::Client::AuthReq auth_req, 40 ReadCallback callback) override {} 41 42 MOCK_METHOD0(Read, std::pair<bool, std::vector<uint8_t>>()); Read(ReadCallback callback)43 void Read(ReadCallback callback) override { 44 auto res = Read(); 45 std::move(callback).Run(res.first, std::move(res.second)); 46 } 47 48 MOCK_METHOD3(WriteAuth, 49 bool(bluetooth_v2_shlib::Gatt::Client::AuthReq auth_req, 50 bluetooth_v2_shlib::Gatt::WriteType write_type, 51 const std::vector<uint8_t>& value)); WriteAuth(bluetooth_v2_shlib::Gatt::Client::AuthReq auth_req,bluetooth_v2_shlib::Gatt::WriteType write_type,const std::vector<uint8_t> & value,StatusCallback callback)52 void WriteAuth(bluetooth_v2_shlib::Gatt::Client::AuthReq auth_req, 53 bluetooth_v2_shlib::Gatt::WriteType write_type, 54 const std::vector<uint8_t>& value, 55 StatusCallback callback) override { 56 std::move(callback).Run(WriteAuth(auth_req, write_type, value)); 57 } 58 59 MOCK_METHOD1(Write, bool(const std::vector<uint8_t>& value)); Write(const std::vector<uint8_t> & value,StatusCallback callback)60 void Write(const std::vector<uint8_t>& value, 61 StatusCallback callback) override { 62 std::move(callback).Run(Write(value)); 63 } 64 65 MOCK_METHOD0(NotificationEnabled, bool()); uuid()66 const bluetooth_v2_shlib::Uuid& uuid() const override { return uuid_; } 67 MOCK_CONST_METHOD0(handle, HandleId()); 68 MOCK_CONST_METHOD0(permissions, bluetooth_v2_shlib::Gatt::Permissions()); 69 MOCK_CONST_METHOD0(properties, bluetooth_v2_shlib::Gatt::Properties()); 70 71 const bluetooth_v2_shlib::Uuid uuid_; 72 73 private: 74 friend testing::StrictMock<MockRemoteCharacteristic>; 75 76 ~MockRemoteCharacteristic(); 77 }; 78 79 } // namespace bluetooth 80 } // namespace chromecast 81 82 #endif // CHROMECAST_DEVICE_BLUETOOTH_LE_MOCK_REMOTE_CHARACTERISTIC_H_ 83