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

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

stack::btm:: Consolidate test fixtures btm_test_fixtures.h

Bug: 332759631
Test: atest net_test_stack_btm
Flag: EXEMPT, Test Infrastructure
Change-Id: Ibd364cf890d48acc41b85c3304511027527b3ed5
parent 3f7adffa
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1561,6 +1561,7 @@ cc_test {
        ":TestCommonMockFunctions",
        ":TestCommonStackConfig",
        ":TestFakeLooper",
        ":TestFakeOsi",
        ":TestFakeThread",
        ":TestMockBta",
        ":TestMockBtif",
+41 −0
Original line number Diff line number Diff line
/*
 * Copyright 2024 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.
 */

#pragma once

#include <gtest/gtest.h>

#include "test/common/mock_functions.h"
#include "test/fake/fake_osi.h"

class BtmWithFakesTest : public testing::Test {
 protected:
  void SetUp() override { fake_osi_ = std::make_unique<test::fake::FakeOsi>(); }

  void TearDown() override { fake_osi_.reset(); }
  std::unique_ptr<test::fake::FakeOsi> fake_osi_;
};

// Setup any default or optional mocks
class BtmWithMocksTest : public BtmWithFakesTest {
 protected:
  void SetUp() override {
    BtmWithFakesTest::SetUp();
    reset_mock_function_count_map();
  }

  void TearDown() override { BtmWithFakesTest::TearDown(); }
};
+4 −3
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include "stack/include/hfp_lc3_encoder.h"
#include "stack/include/hfp_msbc_decoder.h"
#include "stack/include/hfp_msbc_encoder.h"
#include "stack/test/btm/btm_test_fixtures.h"
#include "test/common/mock_functions.h"
#include "udrv/include/uipc.h"

@@ -102,11 +103,11 @@ struct Lc3CodecInterface : bluetooth::core::CodecInterface {
  }
};

class ScoHciTest : public Test {
class ScoHciTest : public BtmWithMocksTest {
 public:
 protected:
  void SetUp() override {
    reset_mock_function_count_map();
    BtmWithMocksTest::SetUp();
    mock_uipc_init_ret = nullptr;
    mock_uipc_read_ret = 0;
    mock_uipc_send_ret = true;
@@ -116,7 +117,7 @@ class ScoHciTest : public Test {
    GetInterfaceToProfiles()->msbcCodec = &msbc_codec;
    GetInterfaceToProfiles()->lc3Codec = &lc3_codec;
  }
  void TearDown() override {}
  void TearDown() override { BtmWithMocksTest::TearDown(); }
};

class ScoHciWithOpenCleanTest : public ScoHciTest {
+4 −11
Original line number Diff line number Diff line
@@ -20,20 +20,13 @@

#include "stack/btm/btm_dev.h"
#include "stack/btm/btm_sec_cb.h"
#include "test/common/mock_functions.h"
#include "stack/test/btm/btm_test_fixtures.h"
#include "test/mock/mock_main_shim_entry.h"

class StackBtmTest : public testing::Test {
 public:
class StackBtmDevTest : public BtmWithMocksTest {
 protected:
  void SetUp() override { reset_mock_function_count_map(); }
  void TearDown() override {}
};

class StackBtmDevTest : public StackBtmTest {
 protected:
  void SetUp() override { StackBtmTest::SetUp(); }
  void TearDown() override { StackBtmTest::TearDown(); }
  void SetUp() override { BtmWithMocksTest::SetUp(); }
  void TearDown() override { BtmWithMocksTest::TearDown(); }
};

TEST_F(StackBtmDevTest, btm_sec_allocate_dev_rec__no_list) {
+4 −4
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@
#include "stack/btm/btm_sec.h"
#include "stack/btm/btm_sec_cb.h"
#include "stack/btm/security_device_record.h"
#include "test/common/mock_functions.h"
#include "stack/test/btm/btm_test_fixtures.h"
#include "test/mock/mock_main_shim_entry.h"
#include "types/raw_address.h"

@@ -62,11 +62,11 @@ using bluetooth::testing::legacy::wipe_secrets_and_remove;
constexpr size_t kBtmSecMaxDeviceRecords =
    static_cast<size_t>(BTM_SEC_MAX_DEVICE_RECORDS + 1);

class StackBtmSecTest : public Test {
class StackBtmSecTest : public BtmWithMocksTest {
 public:
 protected:
  void SetUp() override { reset_mock_function_count_map(); }
  void TearDown() override {}
  void SetUp() override { BtmWithMocksTest::SetUp(); }
  void TearDown() override { BtmWithMocksTest::TearDown(); }
};

class StackBtmSecWithQueuesTest : public StackBtmSecTest {
Loading