1 /*
2 * Copyright 2022 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 <base/functional/bind.h>
18 #include <base/location.h>
19 #include <gtest/gtest.h>
20
21 #include <chrono>
22
23 #include "bta/av/bta_av_int.h"
24 #include "bta/dm/bta_dm_int.h"
25 #include "bta/hf_client/bta_hf_client_int.h"
26 #include "bta/include/bta_api.h"
27 #include "bta/include/bta_dm_api.h"
28 #include "bta/include/bta_hf_client_api.h"
29 #include "btif/include/stack_manager.h"
30 #include "common/message_loop_thread.h"
31 #include "osi/include/log.h"
32 #include "stack/include/btm_status.h"
33 #include "test/common/mock_functions.h"
34 #include "test/mock/mock_osi_alarm.h"
35 #include "test/mock/mock_stack_acl.h"
36 #include "test/mock/mock_stack_btm_sec.h"
37
38 using namespace std::chrono_literals;
39
40 namespace {
41 const RawAddress kRawAddress({0x11, 0x22, 0x33, 0x44, 0x55, 0x66});
42 } // namespace
43
44 // TODO move into mock
BTM_block_role_switch_and_sniff_mode_for(const RawAddress & peer_addr)45 void BTM_block_role_switch_and_sniff_mode_for(const RawAddress& peer_addr) {}
46
47 struct alarm_t {
alarm_talarm_t48 alarm_t(const char* name){};
49 int any_value;
50 };
51
52 extern uint8_t appl_trace_level;
53
54 class BtaAvTest : public testing::Test {
55 protected:
SetUp()56 void SetUp() override {
57 reset_mock_function_count_map();
58 bluetooth::common::InitFlags::SetAllForTesting();
59 appl_trace_level = BT_TRACE_LEVEL_VERBOSE;
60 }
TearDown()61 void TearDown() override {
62 LOG_INFO("appl_trace_level:%hhu", appl_trace_level);
63 }
64 };
65
TEST_F(BtaAvTest,nop)66 TEST_F(BtaAvTest, nop) {
67 bool status = true;
68 ASSERT_EQ(true, status);
69 }
70
TEST_F(BtaAvTest,bta_av_rc_opened)71 TEST_F(BtaAvTest, bta_av_rc_opened) {
72 tBTA_AV_CB cb = {
73 .p_cback =
74 [](tBTA_AV_EVT event, tBTA_AV* p_data) {
75 const tBTA_AV_RC_OPEN* rc_open = &p_data->rc_open;
76 ASSERT_EQ(BTA_AV_RC_OPEN_EVT, event);
77 ASSERT_EQ(kRawAddress, rc_open->peer_addr);
78 },
79 };
80 tBTA_AV_DATA data = {
81 .rc_conn_chg =
82 {
83 .hdr = {},
84 .peer_addr = kRawAddress,
85 .handle = 0,
86 },
87 };
88 bta_av_rc_opened(&cb, &data);
89 }
90