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