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
17 #include <gmock/gmock.h>
18 #include <gtest/gtest.h>
19 #include <cstring>
20 #include <map>
21
22 #include "common/message_loop_thread.h"
23 #include "osi/include/log.h"
24 #include "stack/hid/hidh_int.h"
25 #include "stack/include/hci_error_code.h"
26 #include "test/mock/mock_stack_l2cap_api.h"
27 #include "types/bt_transport.h"
28 #include "types/raw_address.h"
29
30 std::map<std::string, int> mock_function_count_map;
31
get_main_thread()32 bluetooth::common::MessageLoopThread* get_main_thread() { return nullptr; }
btm_get_acl_disc_reason_code(void)33 tHCI_REASON btm_get_acl_disc_reason_code(void) { return HCI_SUCCESS; }
34
BTM_IsAclConnectionUp(const RawAddress & remote_bda,tBT_TRANSPORT transport)35 bool BTM_IsAclConnectionUp(const RawAddress& remote_bda,
36 tBT_TRANSPORT transport) {
37 return true;
38 }
39 namespace {
40
41 using testing::_;
42 using testing::DoAll;
43 using testing::NotNull;
44 using testing::Pointee;
45 using testing::Return;
46 using testing::SaveArg;
47 using testing::SaveArgPointee;
48 using testing::StrEq;
49 using testing::StrictMock;
50 using testing::Test;
51
52 class StackHidTest : public Test {
53 public:
54 protected:
SetUp()55 void SetUp() override { mock_function_count_map.clear(); }
TearDown()56 void TearDown() override {}
57 };
58
TEST_F(StackHidTest,disconnect_bad_cid)59 TEST_F(StackHidTest, disconnect_bad_cid) {
60 tL2CAP_APPL_INFO l2cap_callbacks;
61
62 test::mock::stack_l2cap_api::L2CA_Register2.body =
63 [&l2cap_callbacks](uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
64 bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info,
65 uint16_t my_mtu, uint16_t required_remote_mtu,
66 uint16_t sec_level) {
67 l2cap_callbacks = p_cb_info;
68 return psm;
69 };
70
71 tHID_STATUS status = hidh_conn_reg();
72 ASSERT_EQ(HID_SUCCESS, status);
73
74 l2cap_callbacks.pL2CA_Error_Cb(123, 456);
75 }
76
77 } // namespace
78