• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 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/logging.h>
18 #include <gtest/gtest.h>
19 #include <stdio.h>
20 
21 #include <cstdint>
22 
23 #include "bta/include/bta_av_api.h"
24 #include "btif/include/btif_common.h"
25 #include "common/message_loop_thread.h"
26 #include "device/include/interop.h"
27 #include "include/hardware/bt_rc.h"
28 #include "osi/test/AllocationTestHarness.h"
29 #include "stack/include/bt_hdr.h"
30 #include "stack/include/btm_api_types.h"
31 #include "types/raw_address.h"
32 #undef LOG_TAG
33 #include "btif/src/btif_rc.cc"
34 
35 void allocation_tracker_uninit(void);
36 
37 namespace {
38 int AVRC_BldResponse_ = 0;
39 }  // namespace
40 
41 uint8_t appl_trace_level = BT_TRACE_LEVEL_WARNING;
42 uint8_t btif_trace_level = BT_TRACE_LEVEL_WARNING;
43 
avrcp_absolute_volume_is_enabled()44 bool avrcp_absolute_volume_is_enabled() { return true; }
AVRC_BldCommand(tAVRC_COMMAND * p_cmd,BT_HDR ** pp_pkt)45 tAVRC_STS AVRC_BldCommand(tAVRC_COMMAND* p_cmd, BT_HDR** pp_pkt) { return 0; }
AVRC_BldResponse(uint8_t handle,tAVRC_RESPONSE * p_rsp,BT_HDR ** pp_pkt)46 tAVRC_STS AVRC_BldResponse(uint8_t handle, tAVRC_RESPONSE* p_rsp,
47                            BT_HDR** pp_pkt) {
48   AVRC_BldResponse_++;
49   return 0;
50 }
AVRC_Ctrl_ParsCommand(tAVRC_MSG * p_msg,tAVRC_COMMAND * p_result)51 tAVRC_STS AVRC_Ctrl_ParsCommand(tAVRC_MSG* p_msg, tAVRC_COMMAND* p_result) {
52   return 0;
53 }
AVRC_Ctrl_ParsResponse(tAVRC_MSG * p_msg,tAVRC_RESPONSE * p_result,uint8_t * p_buf,uint16_t * buf_len)54 tAVRC_STS AVRC_Ctrl_ParsResponse(tAVRC_MSG* p_msg, tAVRC_RESPONSE* p_result,
55                                  uint8_t* p_buf, uint16_t* buf_len) {
56   return 0;
57 }
AVRC_ParsCommand(tAVRC_MSG * p_msg,tAVRC_COMMAND * p_result,uint8_t * p_buf,uint16_t buf_len)58 tAVRC_STS AVRC_ParsCommand(tAVRC_MSG* p_msg, tAVRC_COMMAND* p_result,
59                            uint8_t* p_buf, uint16_t buf_len) {
60   return 0;
61 }
AVRC_ParsResponse(tAVRC_MSG * p_msg,tAVRC_RESPONSE * p_result,UNUSED_ATTR uint8_t * p_buf,UNUSED_ATTR uint16_t buf_len)62 tAVRC_STS AVRC_ParsResponse(tAVRC_MSG* p_msg, tAVRC_RESPONSE* p_result,
63                             UNUSED_ATTR uint8_t* p_buf,
64                             UNUSED_ATTR uint16_t buf_len) {
65   return 0;
66 }
BTA_AvCloseRc(uint8_t rc_handle)67 void BTA_AvCloseRc(uint8_t rc_handle) {}
BTA_AvMetaCmd(uint8_t rc_handle,uint8_t label,tBTA_AV_CMD cmd_code,BT_HDR * p_pkt)68 void BTA_AvMetaCmd(uint8_t rc_handle, uint8_t label, tBTA_AV_CMD cmd_code,
69                    BT_HDR* p_pkt) {}
BTA_AvMetaRsp(uint8_t rc_handle,uint8_t label,tBTA_AV_CODE rsp_code,BT_HDR * p_pkt)70 void BTA_AvMetaRsp(uint8_t rc_handle, uint8_t label, tBTA_AV_CODE rsp_code,
71                    BT_HDR* p_pkt) {}
BTA_AvRemoteCmd(uint8_t rc_handle,uint8_t label,tBTA_AV_RC rc_id,tBTA_AV_STATE key_state)72 void BTA_AvRemoteCmd(uint8_t rc_handle, uint8_t label, tBTA_AV_RC rc_id,
73                      tBTA_AV_STATE key_state) {}
BTA_AvRemoteVendorUniqueCmd(uint8_t rc_handle,uint8_t label,tBTA_AV_STATE key_state,uint8_t * p_msg,uint8_t buf_len)74 void BTA_AvRemoteVendorUniqueCmd(uint8_t rc_handle, uint8_t label,
75                                  tBTA_AV_STATE key_state, uint8_t* p_msg,
76                                  uint8_t buf_len) {}
BTA_AvVendorCmd(uint8_t rc_handle,uint8_t label,tBTA_AV_CODE cmd_code,uint8_t * p_data,uint16_t len)77 void BTA_AvVendorCmd(uint8_t rc_handle, uint8_t label, tBTA_AV_CODE cmd_code,
78                      uint8_t* p_data, uint16_t len) {}
BTA_AvVendorRsp(uint8_t rc_handle,uint8_t label,tBTA_AV_CODE rsp_code,uint8_t * p_data,uint16_t len,uint32_t company_id)79 void BTA_AvVendorRsp(uint8_t rc_handle, uint8_t label, tBTA_AV_CODE rsp_code,
80                      uint8_t* p_data, uint16_t len, uint32_t company_id) {}
btif_av_clear_remote_suspend_flag(void)81 void btif_av_clear_remote_suspend_flag(void) {}
btif_av_is_connected(void)82 bool btif_av_is_connected(void) { return false; }
btif_av_is_sink_enabled(void)83 bool btif_av_is_sink_enabled(void) { return false; }
btif_av_sink_active_peer(void)84 RawAddress btif_av_sink_active_peer(void) { return RawAddress(); }
btif_av_source_active_peer(void)85 RawAddress btif_av_source_active_peer(void) { return RawAddress(); }
btif_av_stream_started_ready(void)86 bool btif_av_stream_started_ready(void) { return false; }
btif_transfer_context(tBTIF_CBACK * p_cback,uint16_t event,char * p_params,int param_len,tBTIF_COPY_CBACK * p_copy_cback)87 bt_status_t btif_transfer_context(tBTIF_CBACK* p_cback, uint16_t event,
88                                   char* p_params, int param_len,
89                                   tBTIF_COPY_CBACK* p_copy_cback) {
90   return BT_STATUS_SUCCESS;
91 }
dump_rc_event(uint8_t event)92 const char* dump_rc_event(uint8_t event) { return nullptr; }
dump_rc_notification_event_id(uint8_t event_id)93 const char* dump_rc_notification_event_id(uint8_t event_id) { return nullptr; }
dump_rc_pdu(uint8_t pdu)94 const char* dump_rc_pdu(uint8_t pdu) { return nullptr; }
dump_rc_opcode(uint8_t pdu)95 const char* dump_rc_opcode(uint8_t pdu) { return nullptr; }
do_in_jni_thread(const base::Location & from_here,base::OnceClosure task)96 bt_status_t do_in_jni_thread(const base::Location& from_here,
97                              base::OnceClosure task) {
98   return BT_STATUS_SUCCESS;
99 }
get_main_thread()100 bluetooth::common::MessageLoopThread* get_main_thread() { return nullptr; }
interop_match_addr(const interop_feature_t feature,const RawAddress * addr)101 bool interop_match_addr(const interop_feature_t feature,
102                         const RawAddress* addr) {
103   return false;
104 }
105 
106 /**
107  * Test class to test selected functionality in hci/src/hci_layer.cc
108  */
109 class BtifRcTest : public AllocationTestHarness {
110  protected:
SetUp()111   void SetUp() override {
112     AllocationTestHarness::SetUp();
113     // Disable our allocation tracker to allow ASAN full range
114     allocation_tracker_uninit();
115   }
116 
TearDown()117   void TearDown() override { AllocationTestHarness::TearDown(); }
118 };
119 
TEST_F(BtifRcTest,get_element_attr_rsp)120 TEST_F(BtifRcTest, get_element_attr_rsp) {
121   RawAddress bd_addr;
122 
123   btif_rc_cb.rc_multi_cb[0].rc_addr = bd_addr;
124   btif_rc_cb.rc_multi_cb[0].rc_connected = true;
125   btif_rc_cb.rc_multi_cb[0]
126       .rc_pdu_info[IDX_GET_ELEMENT_ATTR_RSP]
127       .is_rsp_pending = true;
128   btif_rc_cb.rc_multi_cb[0].rc_state = BTRC_CONNECTION_STATE_CONNECTED;
129 
130   btrc_element_attr_val_t p_attrs[BTRC_MAX_ELEM_ATTR_SIZE];
131   uint8_t num_attr = BTRC_MAX_ELEM_ATTR_SIZE + 1;
132 
133   CHECK(get_element_attr_rsp(bd_addr, num_attr, p_attrs) == BT_STATUS_SUCCESS);
134   CHECK(AVRC_BldResponse_ == 1);
135 }
136