Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 445082d4 authored by Chris Manton's avatar Chris Manton
Browse files

Introduce bta/test mocks and fakes

Towards testable code

Bug: 176960731
Tag: #refactor
Test: gd/cert/run

Change-Id: I0527f4daf7d03d12a05975fa9fd01a06bd2105e5
parent 2bf0000f
Loading
Loading
Loading
Loading
+74 −0
Original line number Diff line number Diff line
@@ -153,6 +153,80 @@ cc_test {
    ],
}

cc_test {
    name: "bt_host_test_bta",
    defaults: ["fluoride_bta_defaults"],
    test_suites: ["device-tests"],
    host_supported: true,
    include_dirs: [
        "packages/modules/Bluetooth/system",
    ],
    srcs: [
        "dm/bta_dm_act.cc",
        "dm/bta_dm_cfg.cc",
        "dm/bta_dm_ci.cc",
        "dm/bta_dm_main.cc",
        "dm/bta_dm_pm.cc",
        "gatt/bta_gattc_act.cc",
        "gatt/bta_gattc_api.cc",
        "gatt/bta_gattc_cache.cc",
        "gatt/bta_gattc_main.cc",
        "gatt/bta_gattc_queue.cc",
        "gatt/bta_gattc_utils.cc",
        "gatt/database.cc",
        "gatt/database_builder.cc",
        "hh/bta_hh_act.cc",
        "hh/bta_hh_cfg.cc",
        "hh/bta_hh_le.cc",
        "hh/bta_hh_main.cc",
        "hh/bta_hh_utils.cc",
        "sys/bta_sys_conn.cc",
        "sys/bta_sys_main.cc",
        "test/bta_dm_test.cc",
        "test/common/fake_osi.cc",
        "test/common/mock_btif_co_bta_dm_co.cc",
        "test/common/mock_btif_co_bta_hh_co.cc",
        "test/common/mock_btif_debug_conn.cc",
        "test/common/mock_btif_dm.cc",
        "test/common/mock_btif_stack_manager.cc",
        "test/common/mock_btif_storage.cc",
        "test/common/mock_device_controller.cc",
        "test/common/mock_device_interop.cc",
        "test/common/mock_main_shim_acl.cc",
        "test/common/mock_main_shim_btm_api.cc",
        "test/common/mock_shim.cc",
        "test/common/mock_stack_acl.cc",
        "test/common/mock_stack_btm.cc",
        "test/common/mock_stack_btm_ble.cc",
        "test/common/mock_stack_btm_dev.cc",
        "test/common/mock_stack_btm_pm.cc",
        "test/common/mock_stack_btm_sco.cc",
        "test/common/mock_stack_btm_sec.cc",
        "test/common/mock_stack_crypto_toolbox_aes_cmac.cc",
        "test/common/mock_stack_gap_ble.cc",
        "test/common/mock_stack_gatt.cc",
        "test/common/mock_stack_gatt_attr.cc",
        "test/common/mock_stack_gatt_connection_manager.cc",
        "test/common/mock_stack_hidh.cc",
        "test/common/mock_stack_l2cap.cc",
        "test/common/mock_stack_l2cap_ble.cc",
        "test/common/mock_stack_sdp.cc",
        "test/common/mock_stack_srvc_dis.cc",
    ],
    shared_libs: [
        "libcrypto",
        "liblog",
        "libprotobuf-cpp-lite",
    ],
    static_libs: [
        "libbluetooth-types",
        "libbt-common",
        "libbt-protos-lite",
        "libbtcore",
        "libgmock",
    ],
}

// bta hf client add record tests for target
// ========================================================
cc_test {
+69 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <base/bind.h>
#include <base/location.h>
#include <gtest/gtest.h>

#include "bta/dm/bta_dm_int.h"
#include "bta/hf_client/bta_hf_client_int.h"
#include "bta/include/bta_hf_client_api.h"
#include "common/message_loop_thread.h"

std::map<std::string, int> mock_function_count_map;

bt_status_t do_in_main_thread_delayed(const base::Location& from_here,
                                      base::OnceClosure task,
                                      const base::TimeDelta& delay) {
  return BT_STATUS_SUCCESS;
}

bt_status_t do_in_main_thread(const base::Location& from_here,
                              base::OnceClosure task) {
  return BT_STATUS_SUCCESS;
}

void LogMsg(uint32_t trace_set_mask, const char* fmt_str, ...) {}

namespace base {
class MessageLoop;
}  // namespace base
bluetooth::common::MessageLoopThread* get_main_thread() { return nullptr; }

namespace {
constexpr uint8_t kUnusedTimer = BTA_ID_MAX;
}  // namespace

class BtaDmTest : public testing::Test {
 protected:
  void SetUp() override {
    mock_function_count_map.clear();

    bta_dm_init_cb();

    for (int i = 0; i < BTA_DM_NUM_PM_TIMER; i++) {
      for (int j = 0; j < BTA_DM_PM_MODE_TIMER_MAX; j++) {
        bta_dm_cb.pm_timer[i].srvc_id[j] = kUnusedTimer;
      }
    }
  }
  void TearDown() override { bta_dm_deinit_cb(); }
};

TEST_F(BtaDmTest, nop) {
  bool status = true;
  ASSERT_EQ(true, status);
}
Loading