diff options
author | 2025-03-06 10:46:57 +0100 | |
---|---|---|
committer | 2025-03-12 12:27:39 +0100 | |
commit | eb06188da9843a034ee8915beffd092581cc7279 (patch) | |
tree | 0a14c0a1d67efecce49963240729d4337a0355c0 /system/btif | |
parent | 271e582f3a2d75849f7746c42f4cf5f39a7e0f72 (diff) |
Test: make mock_controller_ into unique_ptr
Getting rid of memory leaks, dangling pointers in tests.
Bug: None
Test: updated
Flag: exempt, test only change
Change-Id: I4d5ab702da62364a41bf1d822482396456dc8656
Diffstat (limited to 'system/btif')
-rw-r--r-- | system/btif/test/btif_core_test.cc | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/system/btif/test/btif_core_test.cc b/system/btif/test/btif_core_test.cc index 7342a17b99..21723e3674 100644 --- a/system/btif/test/btif_core_test.cc +++ b/system/btif/test/btif_core_test.cc @@ -207,7 +207,8 @@ class BtifCoreTest : public ::testing::Test { protected: void SetUp() override { callback_map_.clear(); - bluetooth::hci::testing::mock_controller_ = &controller_; + bluetooth::hci::testing::mock_controller_ = + std::make_unique<bluetooth::hci::testing::MockControllerInterface>(); bluetooth::testing::set_hal_cbacks(&callbacks); auto promise = std::promise<void>(); auto future = promise.get_future(); @@ -223,17 +224,17 @@ protected: callback_map_["callback_thread_event"] = [&promise]() { promise.set_value(); }; CleanCoreInterface(); ASSERT_EQ(std::future_status::ready, future.wait_for(timeout_time)); - bluetooth::hci::testing::mock_controller_ = nullptr; + bluetooth::hci::testing::mock_controller_.reset(); callback_map_.erase("callback_thread_event"); } - bluetooth::hci::testing::MockControllerInterface controller_; }; class BtifCoreWithControllerTest : public BtifCoreTest { protected: void SetUp() override { BtifCoreTest::SetUp(); - ON_CALL(controller_, SupportsSniffSubrating).WillByDefault(Return(true)); + ON_CALL(*bluetooth::hci::testing::mock_controller_, SupportsSniffSubrating) + .WillByDefault(Return(true)); } void TearDown() override { BtifCoreTest::TearDown(); } |