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 static std::vector<uint8_t> _rsp_sig_ids{};
29 
avdt_msg_send_rsp(AvdtpCcb * p_ccb,uint8_t sig_id,tAVDT_MSG * p_params)30 void avdt_msg_send_rsp(AvdtpCcb* p_ccb, uint8_t sig_id, tAVDT_MSG* p_params) {
31   inc_func_call_count(__func__);
32   _rsp_sig_ids.push_back(sig_id);
33 }
34 
mock_avdt_msg_send_rsp_get_count(void)35 size_t mock_avdt_msg_send_rsp_get_count(void) {
36   return _rsp_sig_ids.size();
37 }
38 
mock_avdt_msg_send_rsp_clear_history(void)39 void mock_avdt_msg_send_rsp_clear_history(void) {
40   _rsp_sig_ids.clear();
41 }
42 
mock_avdt_msg_send_rsp_get_sig_id_at(size_t nth)43 uint8_t mock_avdt_msg_send_rsp_get_sig_id_at(size_t nth) {
44   return _rsp_sig_ids[nth];
45 }
46 
avdt_msg_ind(AvdtpCcb * p_ccb,BT_HDR * p_buf)47 void avdt_msg_ind(AvdtpCcb* p_ccb, BT_HDR* p_buf) {
48   inc_func_call_count(__func__);
49 }
50 
avdt_msg_send_rej(AvdtpCcb * p_ccb,uint8_t sig_id,tAVDT_MSG * p_params)51 void avdt_msg_send_rej(AvdtpCcb* p_ccb, uint8_t sig_id, tAVDT_MSG* p_params) {
52   inc_func_call_count(__func__);
53 }
54 
55 static std::vector<uint8_t> _cmd_sig_ids{};
56 
avdt_msg_send_cmd(AvdtpCcb * p_ccb,void * p_scb,uint8_t sig_id,tAVDT_MSG * p_params)57 void avdt_msg_send_cmd(AvdtpCcb* p_ccb, void* p_scb, uint8_t sig_id,
58                        tAVDT_MSG* p_params) {
59   inc_func_call_count(__func__);
60   _cmd_sig_ids.push_back(sig_id);
61 }
62 
mock_avdt_msg_send_cmd_get_count(void)63 size_t mock_avdt_msg_send_cmd_get_count(void) {
64   return _cmd_sig_ids.size();
65 }
66 
mock_avdt_msg_send_cmd_clear_history(void)67 void mock_avdt_msg_send_cmd_clear_history(void) {
68   _cmd_sig_ids.clear();
69 }
70 
mock_avdt_msg_send_cmd_get_sig_id_at(size_t nth)71 uint8_t mock_avdt_msg_send_cmd_get_sig_id_at(size_t nth) {
72   return _cmd_sig_ids[nth];
73 }
74 
avdt_msg_send(AvdtpCcb * p_ccb,BT_HDR * p_msg)75 bool avdt_msg_send(AvdtpCcb* p_ccb, BT_HDR* p_msg) {
76   inc_func_call_count(__func__);
77   return true;
78 }
79 
80 const uint8_t avdt_msg_rej_2_evt[AVDT_CCB_NUM_ACTIONS] = {};
81