1 /*
2  * Copyright 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <gmock/gmock.h>
19 
20 #include <cstdint>
21 
22 #include "common/contextual_callback.h"
23 #include "hci/address.h"
24 #include "hci/hci_interface.h"
25 #include "hci/hci_packets.h"
26 
27 // Unit test interfaces
28 namespace bluetooth {
29 namespace hci {
30 namespace testing {
31 
32 class MockHciLayer : public HciInterface {
33  public:
34   MOCK_METHOD(
35       void,
36       EnqueueCommand,
37       (std::unique_ptr<CommandBuilder>, common::ContextualOnceCallback<void(CommandCompleteView)>),
38       (override));
39   MOCK_METHOD(
40       void,
41       EnqueueCommand,
42       (std::unique_ptr<CommandBuilder>, common::ContextualOnceCallback<void(CommandStatusView)>),
43       (override));
44   MOCK_METHOD((common::BidiQueueEnd<AclBuilder, AclView>*), GetAclQueueEnd, (), (override));
45   MOCK_METHOD((common::BidiQueueEnd<ScoBuilder, ScoView>*), GetScoQueueEnd, (), (override));
46   MOCK_METHOD((common::BidiQueueEnd<IsoBuilder, IsoView>*), GetIsoQueueEnd, (), (override));
47   MOCK_METHOD(
48       (void),
49       RegisterEventHandler,
50       (EventCode, common::ContextualCallback<void(EventView)>),
51       (override));
52   MOCK_METHOD((void), UnregisterEventHandler, (EventCode), (override));
53   MOCK_METHOD(
54       (void),
55       RegisterLeEventHandler,
56       (SubeventCode, common::ContextualCallback<void(LeMetaEventView)>),
57       (override));
58   MOCK_METHOD((void), UnregisterLeEventHandler, (SubeventCode), (override));
59   MOCK_METHOD(
60       (void),
61       RegisterVendorSpecificEventHandler,
62       (VseSubeventCode, common::ContextualCallback<void(VendorSpecificEventView)>),
63       (override));
64   MOCK_METHOD((void), UnregisterVendorSpecificEventHandler, (VseSubeventCode), (override));
65   MOCK_METHOD(
66       (SecurityInterface*),
67       GetSecurityInterface,
68       (common::ContextualCallback<void(EventView)> event_handler),
69       (override));
70 
71   MOCK_METHOD(
72       (void),
73       RegisterForDisconnects,
74       (common::ContextualCallback<void(uint16_t, hci::ErrorCode)> on_disconnect));
75 
76   MOCK_METHOD(
77       (LeSecurityInterface*),
78       GetLeSecurityInterface,
79       (common::ContextualCallback<void(LeMetaEventView)> event_handler),
80       (override));
81 
82   MOCK_METHOD(
83       (AclConnectionInterface*),
84       GetAclConnectionInterface,
85       (common::ContextualCallback<void(EventView)> event_handler,
86        common::ContextualCallback<void(uint16_t, hci::ErrorCode)> on_disconnect,
87        common::ContextualCallback<void(Address, ClassOfDevice)> on_connection_request,
88        common::ContextualCallback<void(hci::ErrorCode, uint16_t, uint8_t, uint16_t, uint16_t)>
89            on_read_remote_version_complete),
90       (override));
91   MOCK_METHOD((void), PutAclConnectionInterface, (), (override));
92 
93   MOCK_METHOD(
94       (LeAclConnectionInterface*),
95       GetLeAclConnectionInterface,
96       (common::ContextualCallback<void(LeMetaEventView)> event_handler,
97        common::ContextualCallback<void(uint16_t, hci::ErrorCode)> on_disconnect,
98        common::ContextualCallback<void(hci::ErrorCode, uint16_t, uint8_t, uint16_t, uint16_t)>
99            on_read_remote_version_complete),
100       (override));
101   MOCK_METHOD((void), PutLeAclConnectionInterface, (), (override));
102 
103   MOCK_METHOD(
104       (LeAdvertisingInterface*),
105       GetLeAdvertisingInterface,
106       (common::ContextualCallback<void(LeMetaEventView)> event_handler),
107       (override));
108 
109   MOCK_METHOD(
110       (LeScanningInterface*),
111       GetLeScanningInterface,
112       (common::ContextualCallback<void(LeMetaEventView)> event_handler),
113       (override));
114 
115   MOCK_METHOD(
116       (LeIsoInterface*),
117       GetLeIsoInterface,
118       (common::ContextualCallback<void(LeMetaEventView)> event_handler),
119       (override));
120 
121   MOCK_METHOD(
122       (DistanceMeasurementInterface*),
123       GetDistanceMeasurementInterface,
124       (common::ContextualCallback<void(LeMetaEventView)> event_handler),
125       (override));
126 
127   MOCK_METHOD(
128       void,
129       RegisterForScoConnectionRequests,
130       (common::ContextualCallback<void(Address, ClassOfDevice, ConnectionRequestLinkType)>
131            on_sco_connection_request));
132 };
133 
134 }  // namespace testing
135 }  // namespace hci
136 }  // namespace bluetooth
137