1 /*
2 * Copyright 2022 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 <gmock/gmock.h>
18 #include <gtest/gtest.h>
19
20 #include "bta/dm/bta_dm_disc_int.h"
21 #include "bta/test/bta_test_fixtures.h"
22 #include "hci/controller_interface_mock.h"
23 #include "test/mock/mock_main_shim_entry.h"
24
25 void BTA_dm_on_hw_on();
26 void BTA_dm_on_hw_off();
27
28 namespace {
29 const char kName[] = "Hello";
30 }
31
32 namespace bluetooth {
33 namespace legacy {
34 namespace testing {
35
36 tBTA_DM_SERVICE_DISCOVERY_CB& bta_dm_discovery_cb();
37 void bta_dm_sdp_result(tSDP_STATUS sdp_status, tBTA_DM_SDP_STATE* state);
38
39 } // namespace testing
40 } // namespace legacy
41 } // namespace bluetooth
42
43 class BtaSdpTest : public BtaWithHwOnTest {
44 protected:
SetUp()45 void SetUp() override {
46 BtaWithHwOnTest::SetUp();
47 ON_CALL(controller_, LeRand).WillByDefault([](bluetooth::hci::LeRandCallback cb) {
48 cb(0x1234);
49 });
50 bluetooth::hci::testing::mock_controller_ = &controller_;
51 }
52
TearDown()53 void TearDown() override {
54 BtaWithHwOnTest::TearDown();
55 bluetooth::hci::testing::mock_controller_ = nullptr;
56 }
57 bluetooth::hci::testing::MockControllerInterface controller_;
58 };
59
60 class BtaSdpRegisteredTest : public BtaSdpTest {
61 protected:
SetUp()62 void SetUp() override { BtaSdpTest::SetUp(); }
63
TearDown()64 void TearDown() override { BtaSdpTest::TearDown(); }
65 };
66
TEST_F(BtaSdpTest,nop)67 TEST_F(BtaSdpTest, nop) {}
68
TEST_F(BtaSdpRegisteredTest,bta_dm_sdp_result_SDP_SUCCESS)69 TEST_F(BtaSdpRegisteredTest, bta_dm_sdp_result_SDP_SUCCESS) {
70 std::unique_ptr<tBTA_DM_SDP_STATE> state = std::make_unique<tBTA_DM_SDP_STATE>(
71 tBTA_DM_SDP_STATE{.service_index = BTA_MAX_SERVICE_ID});
72 bluetooth::legacy::testing::bta_dm_sdp_result(tSDP_STATUS::SDP_SUCCESS, state.get());
73 }
74