Loading system/bta/Android.bp +18 −3 Original line number Diff line number Diff line Loading @@ -202,6 +202,7 @@ cc_test { ":LegacyStackSdp", ":TestCommonLogMsg", ":TestCommonMockFunctions", ":TestFakeOsi", ":TestMockBtif", ":TestMockMainShim", ":TestMockStackBtm", Loading Loading @@ -237,7 +238,6 @@ cc_test { "libchrome", "libcom.android.sysprop.bluetooth", "libgmock", "libosi", ], data: [ ":audio_set_configurations_bfbs", Loading Loading @@ -302,16 +302,31 @@ cc_test { "BluetoothGeneratedPackets_h", ], srcs: [ ":LegacyStackSdp", ":OsiCompatSources", ":TestCommonLogMsg", ":TestCommonMainHandler", ":TestCommonMockFunctions", ":TestFakeOsi", ":TestMockBtaSdp", ":TestMockBtif", ":TestMockDevice", ":TestMockMainShim", ":TestMockOsi", ":TestMockStack", ":TestMockSrvcDis", ":TestMockStackA2dp", ":TestMockStackAcl", ":TestMockStackAvct", ":TestMockStackAvdt", ":TestMockStackAvrc", ":TestMockStackBtm", ":TestMockStackCryptotoolbox", ":TestMockStackGap", ":TestMockStackGatt", ":TestMockStackHid", ":TestMockStackL2cap", ":TestMockStackMetrics", ":TestMockStackPan", ":TestMockStackRfcomm", "ar/bta_ar.cc", "av/bta_av_aact.cc", "av/bta_av_act.cc", Loading system/bta/test/bta_dm_cust_uuid_test.cc +8 −1 Original line number Diff line number Diff line Loading @@ -18,15 +18,22 @@ #include <gtest/gtest.h> #include <memory> #include "bta/dm/bta_dm_int.h" #include "stack/include/bt_hdr.h" #include "test/fake/fake_osi.h" #include "types/bluetooth/uuid.h" using bluetooth::Uuid; class BtaCustUuid : public testing::Test { protected: void SetUp() override { bta_dm_cb = {}; } void SetUp() override { fake_osi_ = std::make_unique<test::fake::FakeOsi>(); bta_dm_cb = {}; } std::unique_ptr<test::fake::FakeOsi> fake_osi_; }; namespace { Loading system/bta/test/bta_dm_test.cc +5 −29 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include <gtest/gtest.h> #include <chrono> #include <memory> #include "bta/dm/bta_dm_int.h" #include "bta/hf_client/bta_hf_client_int.h" Loading @@ -31,6 +32,7 @@ #include "stack/include/btm_status.h" #include "test/common/main_handler.h" #include "test/common/mock_functions.h" #include "test/fake/fake_osi.h" #include "test/mock/mock_osi_alarm.h" #include "test/mock/mock_osi_allocator.h" #include "test/mock/mock_stack_acl.h" Loading Loading @@ -63,33 +65,12 @@ const tBTA_SYS_REG bta_dm_search_reg = {bta_dm_search_sm_execute, } // namespace struct alarm_t { alarm_t(const char* name){}; int any_value; }; class BtaDmTest : public testing::Test { protected: void SetUp() override { reset_mock_function_count_map(); bluetooth::common::InitFlags::Load(test_flags); test::mock::osi_alarm::alarm_new.body = [](const char* name) -> alarm_t* { return new alarm_t(name); }; test::mock::osi_alarm::alarm_free.body = [](alarm_t* alarm) { delete alarm; }; test::mock::osi_allocator::osi_malloc.body = [](size_t size) { return malloc(size); }; test::mock::osi_allocator::osi_calloc.body = [](size_t size) { return calloc(1UL, size); }; test::mock::osi_allocator::osi_free.body = [](void* ptr) { free(ptr); }; test::mock::osi_allocator::osi_free_and_reset.body = [](void** ptr) { free(*ptr); *ptr = nullptr; }; fake_osi_ = std::make_unique<test::fake::FakeOsi>(); main_thread_start_up(); post_on_bt_main([]() { LOG_INFO("Main thread started up"); }); Loading @@ -108,14 +89,9 @@ class BtaDmTest : public testing::Test { bta_dm_deinit_cb(); post_on_bt_main([]() { LOG_INFO("Main thread shutting down"); }); main_thread_shut_down(); test::mock::osi_alarm::alarm_new = {}; test::mock::osi_alarm::alarm_free = {}; test::mock::osi_allocator::osi_malloc = {}; test::mock::osi_allocator::osi_calloc = {}; test::mock::osi_allocator::osi_free = {}; test::mock::osi_allocator::osi_free_and_reset = {}; } std::unique_ptr<test::fake::FakeOsi> fake_osi_; }; TEST_F(BtaDmTest, nop) { Loading system/bta/test/bta_hf_client_add_record_test.cc +5 −6 Original line number Diff line number Diff line Loading @@ -19,19 +19,18 @@ #include <base/logging.h> #include <gtest/gtest.h> #include <memory> #include "bta/hf_client/bta_hf_client_int.h" #include "bta/include/bta_hf_client_api.h" #include "types/bluetooth/uuid.h" static uint16_t gVersion; #include "test/fake/fake_osi.h" class BtaHfClientAddRecordTest : public ::testing::Test { protected: void SetUp() override { gVersion = 0; } void SetUp() override { fake_osi_ = std::make_unique<test::fake::FakeOsi>(); } void TearDown() override {} std::unique_ptr<test::fake::FakeOsi> fake_osi_; }; TEST_F(BtaHfClientAddRecordTest, test_hf_client_add_record) { Loading system/bta/test/bta_hf_client_test.cc +5 −0 Original line number Diff line number Diff line Loading @@ -18,9 +18,12 @@ #include <gtest/gtest.h> #include <memory> #include "bta/hf_client/bta_hf_client_int.h" #include "bta/include/bta_hf_client_api.h" #include "common/message_loop_thread.h" #include "test/fake/fake_osi.h" #include "types/raw_address.h" namespace base { Loading @@ -37,10 +40,12 @@ const RawAddress bdaddr2({0x66, 0x55, 0x44, 0x33, 0x22, 0x11}); class BtaHfClientTest : public testing::Test { protected: void SetUp() override { fake_osi_ = std::make_unique<test::fake::FakeOsi>(); // Reset the memory block, this is the state on which the allocate handle // would start operating bta_hf_client_cb_arr_init(); } std::unique_ptr<test::fake::FakeOsi> fake_osi_; }; // Test that when we can allocate a device on the block and then check Loading Loading
system/bta/Android.bp +18 −3 Original line number Diff line number Diff line Loading @@ -202,6 +202,7 @@ cc_test { ":LegacyStackSdp", ":TestCommonLogMsg", ":TestCommonMockFunctions", ":TestFakeOsi", ":TestMockBtif", ":TestMockMainShim", ":TestMockStackBtm", Loading Loading @@ -237,7 +238,6 @@ cc_test { "libchrome", "libcom.android.sysprop.bluetooth", "libgmock", "libosi", ], data: [ ":audio_set_configurations_bfbs", Loading Loading @@ -302,16 +302,31 @@ cc_test { "BluetoothGeneratedPackets_h", ], srcs: [ ":LegacyStackSdp", ":OsiCompatSources", ":TestCommonLogMsg", ":TestCommonMainHandler", ":TestCommonMockFunctions", ":TestFakeOsi", ":TestMockBtaSdp", ":TestMockBtif", ":TestMockDevice", ":TestMockMainShim", ":TestMockOsi", ":TestMockStack", ":TestMockSrvcDis", ":TestMockStackA2dp", ":TestMockStackAcl", ":TestMockStackAvct", ":TestMockStackAvdt", ":TestMockStackAvrc", ":TestMockStackBtm", ":TestMockStackCryptotoolbox", ":TestMockStackGap", ":TestMockStackGatt", ":TestMockStackHid", ":TestMockStackL2cap", ":TestMockStackMetrics", ":TestMockStackPan", ":TestMockStackRfcomm", "ar/bta_ar.cc", "av/bta_av_aact.cc", "av/bta_av_act.cc", Loading
system/bta/test/bta_dm_cust_uuid_test.cc +8 −1 Original line number Diff line number Diff line Loading @@ -18,15 +18,22 @@ #include <gtest/gtest.h> #include <memory> #include "bta/dm/bta_dm_int.h" #include "stack/include/bt_hdr.h" #include "test/fake/fake_osi.h" #include "types/bluetooth/uuid.h" using bluetooth::Uuid; class BtaCustUuid : public testing::Test { protected: void SetUp() override { bta_dm_cb = {}; } void SetUp() override { fake_osi_ = std::make_unique<test::fake::FakeOsi>(); bta_dm_cb = {}; } std::unique_ptr<test::fake::FakeOsi> fake_osi_; }; namespace { Loading
system/bta/test/bta_dm_test.cc +5 −29 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include <gtest/gtest.h> #include <chrono> #include <memory> #include "bta/dm/bta_dm_int.h" #include "bta/hf_client/bta_hf_client_int.h" Loading @@ -31,6 +32,7 @@ #include "stack/include/btm_status.h" #include "test/common/main_handler.h" #include "test/common/mock_functions.h" #include "test/fake/fake_osi.h" #include "test/mock/mock_osi_alarm.h" #include "test/mock/mock_osi_allocator.h" #include "test/mock/mock_stack_acl.h" Loading Loading @@ -63,33 +65,12 @@ const tBTA_SYS_REG bta_dm_search_reg = {bta_dm_search_sm_execute, } // namespace struct alarm_t { alarm_t(const char* name){}; int any_value; }; class BtaDmTest : public testing::Test { protected: void SetUp() override { reset_mock_function_count_map(); bluetooth::common::InitFlags::Load(test_flags); test::mock::osi_alarm::alarm_new.body = [](const char* name) -> alarm_t* { return new alarm_t(name); }; test::mock::osi_alarm::alarm_free.body = [](alarm_t* alarm) { delete alarm; }; test::mock::osi_allocator::osi_malloc.body = [](size_t size) { return malloc(size); }; test::mock::osi_allocator::osi_calloc.body = [](size_t size) { return calloc(1UL, size); }; test::mock::osi_allocator::osi_free.body = [](void* ptr) { free(ptr); }; test::mock::osi_allocator::osi_free_and_reset.body = [](void** ptr) { free(*ptr); *ptr = nullptr; }; fake_osi_ = std::make_unique<test::fake::FakeOsi>(); main_thread_start_up(); post_on_bt_main([]() { LOG_INFO("Main thread started up"); }); Loading @@ -108,14 +89,9 @@ class BtaDmTest : public testing::Test { bta_dm_deinit_cb(); post_on_bt_main([]() { LOG_INFO("Main thread shutting down"); }); main_thread_shut_down(); test::mock::osi_alarm::alarm_new = {}; test::mock::osi_alarm::alarm_free = {}; test::mock::osi_allocator::osi_malloc = {}; test::mock::osi_allocator::osi_calloc = {}; test::mock::osi_allocator::osi_free = {}; test::mock::osi_allocator::osi_free_and_reset = {}; } std::unique_ptr<test::fake::FakeOsi> fake_osi_; }; TEST_F(BtaDmTest, nop) { Loading
system/bta/test/bta_hf_client_add_record_test.cc +5 −6 Original line number Diff line number Diff line Loading @@ -19,19 +19,18 @@ #include <base/logging.h> #include <gtest/gtest.h> #include <memory> #include "bta/hf_client/bta_hf_client_int.h" #include "bta/include/bta_hf_client_api.h" #include "types/bluetooth/uuid.h" static uint16_t gVersion; #include "test/fake/fake_osi.h" class BtaHfClientAddRecordTest : public ::testing::Test { protected: void SetUp() override { gVersion = 0; } void SetUp() override { fake_osi_ = std::make_unique<test::fake::FakeOsi>(); } void TearDown() override {} std::unique_ptr<test::fake::FakeOsi> fake_osi_; }; TEST_F(BtaHfClientAddRecordTest, test_hf_client_add_record) { Loading
system/bta/test/bta_hf_client_test.cc +5 −0 Original line number Diff line number Diff line Loading @@ -18,9 +18,12 @@ #include <gtest/gtest.h> #include <memory> #include "bta/hf_client/bta_hf_client_int.h" #include "bta/include/bta_hf_client_api.h" #include "common/message_loop_thread.h" #include "test/fake/fake_osi.h" #include "types/raw_address.h" namespace base { Loading @@ -37,10 +40,12 @@ const RawAddress bdaddr2({0x66, 0x55, 0x44, 0x33, 0x22, 0x11}); class BtaHfClientTest : public testing::Test { protected: void SetUp() override { fake_osi_ = std::make_unique<test::fake::FakeOsi>(); // Reset the memory block, this is the state on which the allocate handle // would start operating bta_hf_client_cb_arr_init(); } std::unique_ptr<test::fake::FakeOsi> fake_osi_; }; // Test that when we can allocate a device on the block and then check Loading