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 <vector>
18 
19 #include "stack/avdt/avdt_int.h"
20 #include "stack/include/bt_hdr.h"
21 #include "test/common/mock_functions.h"
22 
23 /*
24  * TODO: This way of mocking is primitive.
25  * Need to consider more sophisticated existing methods.
26  */
27 
28 // TODO(b/369381361) Enfore -Wmissing-prototypes
29 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
30 
31 static std::vector<uint8_t> _rsp_sig_ids{};
32 
avdt_msg_send_rsp(AvdtpCcb *,uint8_t sig_id,tAVDT_MSG *)33 void avdt_msg_send_rsp(AvdtpCcb* /*p_ccb*/, uint8_t sig_id, tAVDT_MSG* /*p_params*/) {
34   inc_func_call_count(__func__);
35   _rsp_sig_ids.push_back(sig_id);
36 }
37 
mock_avdt_msg_send_rsp_get_count(void)38 size_t mock_avdt_msg_send_rsp_get_count(void) { return _rsp_sig_ids.size(); }
39 
mock_avdt_msg_send_rsp_clear_history(void)40 void mock_avdt_msg_send_rsp_clear_history(void) { _rsp_sig_ids.clear(); }
41 
mock_avdt_msg_send_rsp_get_sig_id_at(size_t nth)42 uint8_t mock_avdt_msg_send_rsp_get_sig_id_at(size_t nth) { return _rsp_sig_ids[nth]; }
43 
avdt_msg_ind(AvdtpCcb *,BT_HDR *)44 void avdt_msg_ind(AvdtpCcb* /*p_ccb*/, BT_HDR* /*p_buf*/) { inc_func_call_count(__func__); }
45 
avdt_msg_send_rej(AvdtpCcb *,uint8_t,tAVDT_MSG *)46 void avdt_msg_send_rej(AvdtpCcb* /*p_ccb*/, uint8_t /*sig_id*/, tAVDT_MSG* /*p_params*/) {
47   inc_func_call_count(__func__);
48 }
49 
50 static std::vector<uint8_t> _cmd_sig_ids{};
51 
avdt_msg_send_cmd(AvdtpCcb *,void *,uint8_t sig_id,tAVDT_MSG *)52 void avdt_msg_send_cmd(AvdtpCcb* /*p_ccb*/, void* /*p_scb*/, uint8_t sig_id,
53                        tAVDT_MSG* /*p_params*/) {
54   inc_func_call_count(__func__);
55   _cmd_sig_ids.push_back(sig_id);
56 }
57 
mock_avdt_msg_send_cmd_get_count(void)58 size_t mock_avdt_msg_send_cmd_get_count(void) { return _cmd_sig_ids.size(); }
59 
mock_avdt_msg_send_cmd_clear_history(void)60 void mock_avdt_msg_send_cmd_clear_history(void) { _cmd_sig_ids.clear(); }
61 
mock_avdt_msg_send_cmd_get_sig_id_at(size_t nth)62 uint8_t mock_avdt_msg_send_cmd_get_sig_id_at(size_t nth) { return _cmd_sig_ids[nth]; }
63 
avdt_msg_send(AvdtpCcb *,BT_HDR *)64 bool avdt_msg_send(AvdtpCcb* /*p_ccb*/, BT_HDR* /*p_msg*/) {
65   inc_func_call_count(__func__);
66   return true;
67 }
68 
69 const uint8_t avdt_msg_rej_2_evt[AVDT_CCB_NUM_ACTIONS] = {};
70