| /* |
| * Copyright 2022 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. |
| */ |
| |
| #include <gmock/gmock.h> |
| #include <gtest/gtest.h> |
| #include <stdarg.h> |
| |
| #include <memory> |
| #include <string> |
| |
| #include "bta/dm/bta_dm_int.h" |
| #include "test/common/main_handler.h" |
| #include "test/fake/fake_osi.h" |
| #include "test/mock/mock_stack_gatt_api.h" |
| |
| void BTA_dm_on_hw_on(); |
| void BTA_dm_on_hw_off(); |
| |
| class BtaSdpTest : public testing::Test { |
| protected: |
| void SetUp() override { |
| fake_osi_ = std::make_unique<test::fake::FakeOsi>(); |
| test::mock::stack_gatt_api::GATT_Register.body = |
| [](const bluetooth::Uuid& p_app_uuid128, const std::string name, |
| tGATT_CBACK* p_cb_info, bool eatt_support) { return 5; }; |
| main_thread_start_up(); |
| sync_main_handler(); |
| |
| BTA_dm_on_hw_on(); |
| } |
| |
| void TearDown() override { |
| BTA_dm_on_hw_off(); |
| |
| sync_main_handler(); |
| main_thread_shut_down(); |
| |
| test::mock::stack_gatt_api::GATT_Register = {}; |
| } |
| std::unique_ptr<test::fake::FakeOsi> fake_osi_; |
| }; |
| |
| class BtaSdpRegisteredTest : public BtaSdpTest { |
| protected: |
| void SetUp() override { |
| BtaSdpTest::SetUp(); |
| bta_sys_register(BTA_ID_DM_SEARCH, &bta_sys_reg); |
| } |
| |
| void TearDown() override { |
| bta_sys_deregister(BTA_ID_DM_SEARCH); |
| BtaSdpTest::TearDown(); |
| } |
| |
| tBTA_SYS_REG bta_sys_reg = { |
| .evt_hdlr = [](BT_HDR_RIGID* p_msg) -> bool { |
| osi_free(p_msg); |
| return false; |
| }, |
| .disable = []() {}, |
| }; |
| }; |
| |
| TEST_F(BtaSdpTest, nop) {} |
| |
| TEST_F(BtaSdpRegisteredTest, bta_dm_sdp_result_SDP_SUCCESS) { |
| bta_dm_search_cb.service_index = BTA_MAX_SERVICE_ID; |
| |
| tBTA_DM_MSG msg = { |
| .sdp_event = |
| { |
| .sdp_result = SDP_SUCCESS, |
| }, |
| }; |
| bta_dm_sdp_result(&msg); |
| } |