• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, tL2CAP_APPL_INFO* p_cb_info,
30                             bool enable_snoop) = 0;
31   virtual uint16_t ConnectRequest(uint16_t psm, const RawAddress& bd_addr) = 0;
32   virtual bool ConnectResponse(const RawAddress& bd_addr, uint8_t id,
33                                uint16_t lcid, uint16_t result,
34                                uint16_t status) = 0;
35   virtual bool DisconnectRequest(uint16_t cid) = 0;
36   virtual bool DisconnectResponse(uint16_t cid) = 0;
37   virtual bool ConfigRequest(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) = 0;
38   virtual bool ConfigResponse(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) = 0;
39   virtual uint8_t DataWrite(uint16_t cid, BT_HDR* p_data) = 0;
40   virtual ~L2capInterface() = default;
41 };
42 
43 class MockL2capInterface : public L2capInterface {
44  public:
45   MOCK_METHOD3(Register, uint16_t(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info,
46                                   bool enable_snoop));
47   MOCK_METHOD2(ConnectRequest,
48                uint16_t(uint16_t psm, const RawAddress& bd_addr));
49   MOCK_METHOD5(ConnectResponse,
50                bool(const RawAddress& bd_addr, uint8_t id, uint16_t lcid,
51                     uint16_t result, uint16_t status));
52   MOCK_METHOD1(DisconnectRequest, bool(uint16_t cid));
53   MOCK_METHOD1(DisconnectResponse, bool(uint16_t cid));
54   MOCK_METHOD2(ConfigRequest, bool(uint16_t cid, tL2CAP_CFG_INFO* p_cfg));
55   MOCK_METHOD2(ConfigResponse, bool(uint16_t cid, tL2CAP_CFG_INFO* p_cfg));
56   MOCK_METHOD2(DataWrite, uint8_t(uint16_t cid, BT_HDR* p_data));
57 };
58 
59 /**
60  * Set the {@link MockL2capInterface} for testing
61  *
62  * @param mock_l2cap_interface pointer to mock l2cap interface, could be null
63  */
64 void SetMockInterface(MockL2capInterface* mock_l2cap_interface);
65 
66 }  // namespace l2cap
67 }  // namespace bluetooth
68