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_interface.h"
25
26 // TODO(b/369381361) Enfore -Wmissing-prototypes
27 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
28
get_main_thread()29 bluetooth::common::MessageLoopThread* get_main_thread() { return nullptr; }
btm_get_acl_disc_reason_code(void)30 tHCI_REASON btm_get_acl_disc_reason_code(void) { return HCI_SUCCESS; }
31
32 using ::testing::_;
33 using ::testing::DoAll;
34 using ::testing::NotNull;
35 using ::testing::Pointee;
36 using ::testing::Return;
37 using ::testing::ReturnArg;
38 using ::testing::SaveArg;
39 using ::testing::SaveArgPointee;
40 using ::testing::StrEq;
41 using ::testing::StrictMock;
42 using ::testing::Test;
43
44 namespace {
45
46 class StackHidTest : public Test {
47 public:
48 protected:
SetUp()49 void SetUp() override {
50 reset_mock_function_count_map();
51 bluetooth::testing::stack::l2cap::set_interface(&l2cap_interface_);
52 }
TearDown()53 void TearDown() override { bluetooth::testing::stack::l2cap::reset_interface(); }
54
55 bluetooth::testing::stack::l2cap::Mock l2cap_interface_;
56 const tL2CAP_APPL_INFO* p_cb_info_;
57 };
58
TEST_F(StackHidTest,disconnect_bad_cid)59 TEST_F(StackHidTest, disconnect_bad_cid) {
60 tL2CAP_APPL_INFO l2cap_callbacks{};
61 EXPECT_CALL(l2cap_interface_, L2CA_RegisterWithSecurity(_, _, _, _, _, _, _))
62 .WillRepeatedly(DoAll(SaveArg<1>(&l2cap_callbacks), ::testing::ReturnArg<0>()));
63
64 tHID_STATUS status = hidh_conn_reg();
65 ASSERT_EQ(HID_SUCCESS, status);
66
67 l2cap_callbacks.pL2CA_Error_Cb(123, static_cast<uint16_t>(tL2CAP_CONN::L2CAP_CONN_NO_RESOURCES));
68 }
69
70 } // namespace
71