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

Commit d61e8dc2 authored by Chris Manton's avatar Chris Manton
Browse files

net_test_stack_btm: Add btm_sec_rmt_name_request_complete

Bug: 330612451
Test: m .
Flag: EXEMPT, Test Infrastructure
Change-Id: I1a44fd4b8adda3f250b632a702bb60e2e1bf78de
parent 8794d542
Loading
Loading
Loading
Loading
+42 −2
Original line number Diff line number Diff line
@@ -21,10 +21,12 @@
#include <vector>

#include "common/init_flags.h"
#include "common/strings.h"
#include "hci/hci_layer_mock.h"
#include "internal_include/bt_target.h"
#include "stack/btm/btm_ble_sec.h"
#include "stack/btm/btm_dev.h"
#include "stack/btm/btm_int_types.h"
#include "stack/btm/btm_sec.h"
#include "stack/btm/btm_sec_cb.h"
#include "stack/btm/security_device_record.h"
@@ -32,9 +34,19 @@
#include "test/mock/mock_main_shim_entry.h"
#include "types/raw_address.h"

extern tBTM_CB btm_cb;

using namespace bluetooth;

using testing::Return;
using testing::Test;

namespace {
const RawAddress kRawAddress = RawAddress({0x11, 0x22, 0x33, 0x44, 0x55, 0x66});
const uint8_t kBdName[] = "kBdName";
constexpr char kTimeFormat[] = "%Y-%m-%d %H:%M:%S";
}  // namespace

namespace bluetooth {
namespace testing {
namespace legacy {
@@ -95,10 +107,10 @@ class StackBtmSecWithInitFreeTest : public StackBtmSecWithQueuesTest {
 protected:
  void SetUp() override {
    StackBtmSecWithQueuesTest::SetUp();
    ::btm_sec_cb.Init(BTM_SEC_MODE_SC);
    BTM_Sec_Init();
  }
  void TearDown() override {
    ::btm_sec_cb.Free();
    BTM_Sec_Free();
    StackBtmSecWithQueuesTest::TearDown();
  }
};
@@ -269,3 +281,31 @@ TEST_F(StackBtmSecWithInitFreeTest, wipe_secrets_and_remove) {

  wipe_secrets_and_remove(device_record);
}

TEST_F(StackBtmSecWithInitFreeTest, btm_sec_rmt_name_request_complete) {
  btm_cb.history_ = std::make_shared<TimestampedStringCircularBuffer>(
      kBtmLogHistoryBufferSize);

  btm_sec_rmt_name_request_complete(&kRawAddress, kBdName, HCI_SUCCESS);
  btm_sec_rmt_name_request_complete(nullptr, nullptr, HCI_SUCCESS);
  btm_sec_rmt_name_request_complete(nullptr, kBdName, HCI_SUCCESS);
  btm_sec_rmt_name_request_complete(&kRawAddress, nullptr, HCI_SUCCESS);

  btm_sec_rmt_name_request_complete(&kRawAddress, kBdName, HCI_ERR_HW_FAILURE);
  btm_sec_rmt_name_request_complete(nullptr, nullptr, HCI_ERR_HW_FAILURE);
  btm_sec_rmt_name_request_complete(nullptr, kBdName, HCI_ERR_HW_FAILURE);
  btm_sec_rmt_name_request_complete(&kRawAddress, nullptr, HCI_ERR_HW_FAILURE);

  std::vector<common::TimestampedEntry<std::string>> history =
      btm_cb.history_->Pull();
  for (auto& record : history) {
    time_t then = record.timestamp / 1000;
    struct tm tm;
    localtime_r(&then, &tm);
    auto s2 = common::StringFormatTime(kTimeFormat, tm);
    log::debug(" {}.{} {}", s2,
               static_cast<unsigned int>(record.timestamp % 1000),
               record.entry);
  }
  ASSERT_EQ(8U, history.size());
}