diff options
author | 2025-01-10 13:14:32 +0000 | |
---|---|---|
committer | 2025-03-17 14:02:16 +0000 | |
commit | 9a65dd1ced9f33ce1f009d303ea595132ac9c55a (patch) | |
tree | 89c6c3285746e1269b8cca72e1854749b205b81f /system/test | |
parent | 9001e81c9c3bb1598e46d82c4a41f3bba7c88323 (diff) |
ASHA: add basic test framework
Add test framework for ASHA in native.
Bug: 388446070
Test: m .
Flag: EXEMPT, test only
Change-Id: I8a51d50855613c71d5a254d2a83ea2fb7255f919
Diffstat (limited to 'system/test')
-rw-r--r-- | system/test/Android.bp | 15 | ||||
-rw-r--r-- | system/test/mock/mock_bta_hearing_aid_audio_source.cc | 43 | ||||
-rw-r--r-- | system/test/mock/mock_stack_gap_conn_interface.cc (renamed from system/test/mock/mock_stack_gap_conn.cc) | 53 | ||||
-rw-r--r-- | system/test/mock/mock_stack_gap_conn_interface.h | 63 |
4 files changed, 156 insertions, 18 deletions
diff --git a/system/test/Android.bp b/system/test/Android.bp index 106dedb7bd..9dab01352f 100644 --- a/system/test/Android.bp +++ b/system/test/Android.bp @@ -88,6 +88,13 @@ filegroup { } filegroup { + name: "TestMockBtaHearingAidAudioSource", + srcs: [ + "mock/mock_bta_hearing_aid_audio_source.cc", + ], +} + +filegroup { name: "TestMockBtaHf", srcs: [ "mock/mock_bta_hf*.cc", @@ -184,6 +191,7 @@ filegroup { ":TestMockBtaHas", ":TestMockBtaHd", ":TestMockBtaHearingAid", + ":TestMockBtaHearingAidAudioSource", ":TestMockBtaHf", ":TestMockBtaHh", ":TestMockBtaJv", @@ -457,6 +465,13 @@ filegroup { } filegroup { + name: "TestMockStackGapConnInterface", + srcs: [ + "mock/mock_stack_gap_conn_interface.cc", + ], +} + +filegroup { name: "TestMockStackConnMgr", srcs: [ "mock/mock_stack_connection_manager.cc", diff --git a/system/test/mock/mock_bta_hearing_aid_audio_source.cc b/system/test/mock/mock_bta_hearing_aid_audio_source.cc new file mode 100644 index 0000000000..c68fad3b8d --- /dev/null +++ b/system/test/mock/mock_bta_hearing_aid_audio_source.cc @@ -0,0 +1,43 @@ +/* + * Copyright 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Generated mock file from original source file + * Functions generated:8 + */ + +#include <base/functional/callback.h> + +#include <cstdint> + +#include "bta/include/bta_gatt_queue.h" +#include "bta/include/bta_hearing_aid_api.h" +#include "test/common/mock_functions.h" +#include "types/raw_address.h" + +void HearingAidAudioSource::Start(const CodecConfiguration& /*codecConfiguration*/, + HearingAidAudioReceiver* /*audioReceiver*/, + uint16_t /*remote_delay_ms*/) { + inc_func_call_count(__func__); +} + +void HearingAidAudioSource::Stop() { inc_func_call_count(__func__); } + +void HearingAidAudioSource::Initialize() { inc_func_call_count(__func__); } + +void HearingAidAudioSource::CleanUp() { inc_func_call_count(__func__); } + +void HearingAidAudioSource::DebugDump(int /*fd*/) { inc_func_call_count(__func__); } diff --git a/system/test/mock/mock_stack_gap_conn.cc b/system/test/mock/mock_stack_gap_conn_interface.cc index 07193c9130..2ef1a3ef8f 100644 --- a/system/test/mock/mock_stack_gap_conn.cc +++ b/system/test/mock/mock_stack_gap_conn_interface.cc @@ -1,5 +1,5 @@ /* - * Copyright 2021 The Android Open Source Project + * Copyright 2025 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,19 +14,39 @@ * limitations under the License. */ -/* - * Generated mock file from original source file - * Functions generated:13 - */ +#include "test/mock/mock_stack_gap_conn_interface.h" -#include "gap_api.h" -#include "stack/include/bt_hdr.h" +#include "stack/include/gap_api.h" #include "test/common/mock_functions.h" -#include "types/raw_address.h" -const RawAddress* GAP_ConnGetRemoteAddr(uint16_t /* gap_handle */) { +namespace { +bluetooth::testing::stack::gap_conn::Mock mock_gap_conn_interface; +bluetooth::testing::stack::gap_conn::Interface* interface_ = &mock_gap_conn_interface; +} // namespace + +void bluetooth::testing::stack::gap_conn::reset_interface() { + interface_ = &mock_gap_conn_interface; +} + +void bluetooth::testing::stack::gap_conn::set_interface( + bluetooth::testing::stack::gap_conn::Interface* interface) { + interface_ = interface; +} + +uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id, bool is_server, + const RawAddress* p_rem_bda, uint16_t psm, uint16_t le_mps, + tL2CAP_CFG_INFO* p_cfg, tL2CAP_ERTM_INFO* ertm_info, uint16_t security, + tGAP_CONN_CALLBACK* p_cb, tBT_TRANSPORT transport) { inc_func_call_count(__func__); - return nullptr; + + return interface_->GAP_ConnOpen(p_serv_name, service_id, is_server, p_rem_bda, psm, le_mps, p_cfg, + ertm_info, security, p_cb, transport); +} + +const RawAddress* GAP_ConnGetRemoteAddr(uint16_t gap_handle) { + inc_func_call_count(__func__); + + return interface_->GAP_ConnGetRemoteAddr(gap_handle); } int GAP_GetRxQueueCnt(uint16_t /* handle */, uint32_t* /* p_rx_queue_count */) { inc_func_call_count(__func__); @@ -44,14 +64,6 @@ uint16_t GAP_ConnGetRemMtuSize(uint16_t /* gap_handle */) { inc_func_call_count(__func__); return 0; } -uint16_t GAP_ConnOpen(const char* /* p_serv_name */, uint8_t /* service_id */, bool /* is_server */, - const RawAddress* /* p_rem_bda */, uint16_t /* psm */, uint16_t /* le_mps */, - tL2CAP_CFG_INFO* /* p_cfg */, tL2CAP_ERTM_INFO* /* ertm_info */, - uint16_t /* security */, tGAP_CONN_CALLBACK* /* p_cb */, - tBT_TRANSPORT /* transport */) { - inc_func_call_count(__func__); - return 0; -} uint16_t GAP_ConnReadData(uint16_t /* gap_handle */, uint8_t* /* p_data */, uint16_t /* max_len */, uint16_t* /* p_len */) { inc_func_call_count(__func__); @@ -74,3 +86,8 @@ bool GAP_IsTransportLe(uint16_t /* gap_handle */) { return false; } void GAP_Init(void) { inc_func_call_count(__func__); } + +bluetooth::testing::stack::gap_conn::Interface& +bluetooth::testing::stack::gap_conn::get_interface() { + return *interface_; +} diff --git a/system/test/mock/mock_stack_gap_conn_interface.h b/system/test/mock/mock_stack_gap_conn_interface.h new file mode 100644 index 0000000000..c1ed7caea3 --- /dev/null +++ b/system/test/mock/mock_stack_gap_conn_interface.h @@ -0,0 +1,63 @@ +/* + * Copyright 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include <gmock/gmock.h> + +#include <vector> + +#include "stack/include/gap_api.h" + +namespace bluetooth { +namespace testing { +namespace stack { +namespace gap_conn { + +class Interface { +public: + virtual ~Interface() = default; + + virtual uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id, bool is_server, + const RawAddress* p_rem_bda, uint16_t psm, uint16_t le_mps, + tL2CAP_CFG_INFO* p_cfg, tL2CAP_ERTM_INFO* ertm_info, + uint16_t security, tGAP_CONN_CALLBACK* p_cb, + tBT_TRANSPORT transport) = 0; + + virtual const RawAddress* GAP_ConnGetRemoteAddr(uint16_t gap_handle) = 0; +}; + +class Mock : public Interface { +public: + ~Mock() = default; + + MOCK_METHOD(uint16_t, GAP_ConnOpen, + (const char* p_serv_name, uint8_t service_id, bool is_server, + const RawAddress* p_rem_bda, uint16_t psm, uint16_t le_mps, tL2CAP_CFG_INFO* p_cfg, + tL2CAP_ERTM_INFO* ertm_info, uint16_t security, tGAP_CONN_CALLBACK* p_cb, + tBT_TRANSPORT transport)); + + MOCK_METHOD(const RawAddress*, GAP_ConnGetRemoteAddr, (uint16_t gap_handle)); +}; + +void reset_interface(); +void set_interface(Interface* interface_); +Interface& get_interface(); + +} // namespace gap_conn +} // namespace stack +} // namespace testing +} // namespace bluetooth |