summaryrefslogtreecommitdiff
path: root/system/btif
diff options
context:
space:
mode:
author Jakub Pawlowski <jpawlowski@google.com> 2025-03-07 04:35:26 +0100
committer Jakub Pawlowski <jpawlowski@google.com> 2025-03-12 12:27:39 +0100
commit36706f4baf3f36477884be8bedf17ca023250e41 (patch)
tree7700df63f06e4d007f834e96c94b1c76f462a053 /system/btif
parenteb06188da9843a034ee8915beffd092581cc7279 (diff)
Test: make mock_hci_layer_ into unique_ptr
Getting rid of memory leaks, dangling pointers in tests. Bug: None Test: updated Flag: exempt, test only change Change-Id: I66f13abdb21b5d6322d6e9a3ab0b15386b0cffc0
Diffstat (limited to 'system/btif')
-rw-r--r--system/btif/test/btif_core_test.cc18
1 files changed, 10 insertions, 8 deletions
diff --git a/system/btif/test/btif_core_test.cc b/system/btif/test/btif_core_test.cc
index 21723e3674..3073bd194c 100644
--- a/system/btif/test/btif_core_test.cc
+++ b/system/btif/test/btif_core_test.cc
@@ -762,12 +762,13 @@ class BtifCoreWithVendorSupportTest : public BtifCoreWithControllerTest {
protected:
void SetUp() override {
BtifCoreWithControllerTest::SetUp();
- bluetooth::hci::testing::mock_hci_layer_ = &hci_;
+ bluetooth::hci::testing::mock_hci_layer_ =
+ std::make_unique<bluetooth::hci::testing::MockHciLayer>();
test::mock::osi_properties::osi_property_get.body = get_properties;
std::promise<void> configuration_promise;
auto configuration_done = configuration_promise.get_future();
- EXPECT_CALL(hci_,
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_,
EnqueueCommand(_, Matcher<ContextualOnceCallback<void(CommandCompleteView)>>(_)))
.WillOnce(
// Replace with real PDL for 0xfc17
@@ -785,7 +786,7 @@ protected:
configuration_promise.set_value();
})
.RetiresOnSaturation();
- EXPECT_CALL(hci_,
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_,
EnqueueCommand(_, Matcher<ContextualOnceCallback<void(CommandCompleteView)>>(_)))
.WillOnce([](std::unique_ptr<CommandBuilder> cmd,
ContextualOnceCallback<void(CommandCompleteView)> callback) {
@@ -799,7 +800,8 @@ protected:
callback(response);
})
.RetiresOnSaturation();
- EXPECT_CALL(hci_, RegisterVendorSpecificEventHandler(VseSubeventCode::BQR_EVENT, _))
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_,
+ RegisterVendorSpecificEventHandler(VseSubeventCode::BQR_EVENT, _))
.WillOnce(SaveArg<1>(&this->vse_callback_));
do_in_main_thread(BindOnce([]() { bluetooth::bqr::EnableBtQualityReport(get_main()); }));
ASSERT_EQ(std::future_status::ready, configuration_done.wait_for(std::chrono::seconds(1)));
@@ -809,18 +811,18 @@ protected:
std::promise<void> disable_promise;
auto disable_future = disable_promise.get_future();
auto set_promise = [&disable_promise]() { disable_promise.set_value(); };
- EXPECT_CALL(hci_, UnregisterVendorSpecificEventHandler(VseSubeventCode::BQR_EVENT));
- EXPECT_CALL(hci_,
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_,
+ UnregisterVendorSpecificEventHandler(VseSubeventCode::BQR_EVENT));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_,
EnqueueCommand(_, Matcher<ContextualOnceCallback<void(CommandCompleteView)>>(_)))
.WillOnce(Invoke(set_promise))
.RetiresOnSaturation();
do_in_main_thread(BindOnce([]() { bluetooth::bqr::DisableBtQualityReport(); }));
ASSERT_EQ(std::future_status::ready, disable_future.wait_for(std::chrono::seconds(1)));
- bluetooth::hci::testing::mock_hci_layer_ = nullptr;
+ bluetooth::hci::testing::mock_hci_layer_.reset();
BtifCoreWithControllerTest::TearDown();
}
- bluetooth::hci::testing::MockHciLayer hci_;
ContextualCallback<void(VendorSpecificEventView)> vse_callback_;
};