1 /******************************************************************************
2  *
3  *  Copyright 2018 The Android Open Source Project
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 #pragma once
19 
20 #include <gmock/gmock.h>
21 
22 #include "l2c_api.h"
23 
24 namespace bluetooth {
25 namespace l2cap {
26 
27 class L2capInterface {
28  public:
29   virtual uint16_t Register(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
30                             bool enable_snoop,
31                             tL2CAP_ERTM_INFO* p_ertm_info) = 0;
32   virtual uint16_t ConnectRequest(uint16_t psm, const RawAddress& bd_addr) = 0;
33   virtual bool ConnectResponse(const RawAddress& bd_addr, uint8_t id,
34                                uint16_t lcid, uint16_t result,
35                                uint16_t status) = 0;
36   virtual bool DisconnectRequest(uint16_t cid) = 0;
37   virtual bool DisconnectResponse(uint16_t cid) = 0;
38   virtual bool ConfigRequest(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) = 0;
39   virtual bool ConfigResponse(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) = 0;
40   virtual uint8_t DataWrite(uint16_t cid, BT_HDR* p_data) = 0;
41   virtual uint16_t RegisterLECoc(uint16_t psm, const tL2CAP_APPL_INFO &cb_info, uint16_t sec_level) = 0;
42   virtual void DeregisterLECoc(uint16_t psm) = 0;
43   virtual bool ConnectCreditBasedRsp(const RawAddress& bd_addr, uint8_t id,
44                                        std::vector<uint16_t> &lcids,
45                                        uint16_t result,
46                                        tL2CAP_LE_CFG_INFO* p_cfg) = 0;
47   virtual std::vector<uint16_t>  ConnectCreditBasedReq(uint16_t psm,
48                                 const RawAddress& bd_addr,
49                                 tL2CAP_LE_CFG_INFO* p_cfg) = 0;
50   virtual bool ReconfigCreditBasedConnsReq(const RawAddress& bd_addr, std::vector<uint16_t> &lcids,
51                                 tL2CAP_LE_CFG_INFO* peer_cfg) = 0;
52   virtual ~L2capInterface() = default;
53 };
54 
55 class MockL2capInterface : public L2capInterface {
56  public:
57   MOCK_METHOD4(Register,
58                uint16_t(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
59                         bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info));
60   MOCK_METHOD2(ConnectRequest,
61                uint16_t(uint16_t psm, const RawAddress& bd_addr));
62   MOCK_METHOD5(ConnectResponse,
63                bool(const RawAddress& bd_addr, uint8_t id, uint16_t lcid,
64                     uint16_t result, uint16_t status));
65   MOCK_METHOD1(DisconnectRequest, bool(uint16_t cid));
66   MOCK_METHOD1(DisconnectResponse, bool(uint16_t cid));
67   MOCK_METHOD2(ConfigRequest, bool(uint16_t cid, tL2CAP_CFG_INFO* p_cfg));
68   MOCK_METHOD2(ConfigResponse, bool(uint16_t cid, tL2CAP_CFG_INFO* p_cfg));
69   MOCK_METHOD2(DataWrite, uint8_t(uint16_t cid, BT_HDR* p_data));
70   MOCK_METHOD3(RegisterLECoc,
71                uint16_t(uint16_t psm, const tL2CAP_APPL_INFO &cb_info, uint16_t sec_level));
72   MOCK_METHOD1(DeregisterLECoc, void(uint16_t psm));
73   MOCK_METHOD1(GetBleConnRole, uint8_t(const RawAddress& bd_addr));
74   MOCK_METHOD5(ConnectCreditBasedRsp,
75                bool(const RawAddress& p_bd_addr, uint8_t id,
76                     std::vector<uint16_t> &lcids,
77                     uint16_t result,
78                     tL2CAP_LE_CFG_INFO* p_cfg));
79   MOCK_METHOD3(ConnectCreditBasedReq,
80                std::vector<uint16_t> (uint16_t psm,
81                     const RawAddress& bd_addr,
82                     tL2CAP_LE_CFG_INFO* p_cfg));
83   MOCK_METHOD3(ReconfigCreditBasedConnsReq,
84                bool(const RawAddress& p_bd_addr, std::vector<uint16_t> &lcids, tL2CAP_LE_CFG_INFO* peer_cfg));
85 };
86 
87 /**
88  * Set the {@link MockL2capInterface} for testing
89  *
90  * @param mock_l2cap_interface pointer to mock l2cap interface, could be null
91  */
92 void SetMockInterface(MockL2capInterface* mock_l2cap_interface);
93 
94 }  // namespace l2cap
95 }  // namespace bluetooth
96