diff --git a/system/btif/Android.bp b/system/btif/Android.bp index 65f4890eb87e576952a2b74bfbad3768afc52e58..aab31c5a3e170b401a5db84077f101e0a9bd648a 100644 --- a/system/btif/Android.bp +++ b/system/btif/Android.bp @@ -280,6 +280,9 @@ cc_test { host_supported: true, include_dirs: btifCommonIncludes, srcs: [ + ":OsiCompatSources", + ":TestCommonMockFunctions", + ":TestFakeOsi", "test/btif_dm_test.cc", "test/btif_storage_test.cc", ], @@ -332,7 +335,6 @@ cc_test { "libgmock", "liblc3", "libopus", - "libosi", "libprotobuf-cpp-lite", "libstatslog_bt", "libudrv-uipc", diff --git a/system/btif/test/btif_dm_test.cc b/system/btif/test/btif_dm_test.cc index d1d6b0758afa3731ae9f18ae782f2c8c1c477b6d..4df1a38fc347e289e457e3881cabb9983180b463 100644 --- a/system/btif/test/btif_dm_test.cc +++ b/system/btif/test/btif_dm_test.cc @@ -23,13 +23,18 @@ #include <memory> #include "bta/include/bta_api_data_types.h" +#include "btif/include/btif_dm.h" #include "btif/include/mock_core_callbacks.h" #include "main/shim/stack.h" #include "module.h" +#include "stack/include/bt_dev_class.h" #include "stack/include/btm_ble_api_types.h" #include "storage/storage_module.h" +#include "test/fake/fake_osi.h" +#include "test/mock/mock_osi_properties.h" using bluetooth::core::testing::MockCoreInterface; +using ::testing::ElementsAre; namespace { const RawAddress kRawAddress = {{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}}; @@ -66,6 +71,7 @@ constexpr tBTM_BLE_ENERGY_USED energy_used = 0x13579bdf; class BtifDmTest : public ::testing::Test { protected: void SetUp() override { + fake_osi_ = std::make_unique<test::fake::FakeOsi>(); mock_core_interface_ = std::make_unique<MockCoreInterface>(); bluetooth::legacy::testing::set_interface_to_profiles( mock_core_interface_.get()); @@ -73,6 +79,7 @@ class BtifDmTest : public ::testing::Test { void TearDown() override {} + std::unique_ptr<test::fake::FakeOsi> fake_osi_; std::unique_ptr<MockCoreInterface> mock_core_interface_; }; @@ -197,3 +204,27 @@ TEST_F_WITH_FLAGS(BtifDmWithStackTest, kBdName, (const char*)invoke_remote_device_properties_cb.properties[0].val); } + +TEST_F(BtifDmWithStackTest, btif_dm_get_local_class_of_device__default) { + DEV_CLASS dev_class = btif_dm_get_local_class_of_device(); + ASSERT_EQ(dev_class, kDevClassUnclassified); +} + +std::string kClassOfDeviceText = "1,2,3"; +DEV_CLASS kClassOfDevice = {1, 2, 3}; +TEST_F(BtifDmWithStackTest, btif_dm_get_local_class_of_device__with_property) { + test::mock::osi_properties::osi_property_get.body = + [](const char* /* key */, char* value, const char* /* default_value */) { + std::copy(kClassOfDeviceText.begin(), kClassOfDeviceText.end(), value); + return kClassOfDeviceText.size(); + }; + + DEV_CLASS dev_class = btif_dm_get_local_class_of_device(); + if (dev_class != kClassOfDevice) { + // If BAP is enabled, an extra bit gets set. + DEV_CLASS dev_class_with_bap = kClassOfDevice; + dev_class_with_bap[1] |= 0x01 << 6; + ASSERT_EQ(dev_class, dev_class_with_bap); + } + test::mock::osi_properties::osi_property_get = {}; +} diff --git a/system/test/mock/mock_osi_socket.cc b/system/test/mock/mock_osi_socket.cc index 353faf06bf121e31f64d0501c4bc04d46ef06ad7..be411f2f9a350f14901cad8a6ff81f8fde0a0409 100644 --- a/system/test/mock/mock_osi_socket.cc +++ b/system/test/mock/mock_osi_socket.cc @@ -99,3 +99,8 @@ ssize_t socket_write_and_transfer_fd(const socket_t* socket, const void* buf, } // Mocked functions complete // END mockcify generation +int osi_socket_local_server_bind(int /* s */, const char* /* name */, + int /* namespaceId */) { + inc_func_call_count(__func__); + return 0; +}