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

Commit aea5476d authored by Henri Chataing's avatar Henri Chataing
Browse files

Replace use of CHECK in test by gtest helpers

Test: m com.android.btservices
Bug: 305066880
Flag: EXEMPT, test change
Change-Id: Ia6812ab22183165f90009e5af33efd3e4c6450c4
parent e86439cb
Loading
Loading
Loading
Loading
+23 −22
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@
#include "btif/include/btif_common.h"
#include "common/message_loop_thread.h"
#include "device/include/interop.h"
#include "include/check.h"
#include "include/hardware/bt_rc.h"
#include "test/common/mock_functions.h"
#include "test/mock/mock_osi_alarm.h"
@@ -66,7 +65,7 @@ void AvrcpService::ServiceInterfaceImpl::SetBipClientStatus(
bool AvrcpService::ServiceInterfaceImpl::Cleanup() { return true; };

AvrcpService* AvrcpService::Get() {
  CHECK(instance_ == nullptr);
  EXPECT_EQ(instance_, nullptr);
  instance_ = new AvrcpService();
  return instance_;
}
@@ -144,7 +143,7 @@ TEST_F(BtifRcTest, get_element_attr_rsp) {
  btrc_element_attr_val_t p_attrs[BTRC_MAX_ELEM_ATTR_SIZE];
  uint8_t num_attr = BTRC_MAX_ELEM_ATTR_SIZE + 1;

  CHECK(get_element_attr_rsp(kDeviceAddress, num_attr, p_attrs) ==
  ASSERT_EQ(get_element_attr_rsp(kDeviceAddress, num_attr, p_attrs),
            BT_STATUS_SUCCESS);
  ASSERT_EQ(1, get_func_call_count("AVRC_BldResponse"));
}
@@ -157,7 +156,7 @@ TEST_F(BtifRcTest, btif_rc_get_addr_by_handle) {
  btif_rc_cb.rc_multi_cb[0].rc_handle = 0;

  btif_rc_get_addr_by_handle(0, bd_addr);
  CHECK(kDeviceAddress == bd_addr);
  ASSERT_EQ(kDeviceAddress, bd_addr);
}

static btrc_ctrl_callbacks_t default_btrc_ctrl_callbacks = {
@@ -268,10 +267,11 @@ TEST_F(BtifRcWithCallbacksTest, handle_rc_ctrl_features) {
  handle_rc_ctrl_features(&p_dev);
  ASSERT_EQ(1, get_func_call_count("AVRC_BldCommand"));

  CHECK(std::future_status::ready == future.wait_for(std::chrono::seconds(2)));
  ASSERT_EQ(std::future_status::ready,
            future.wait_for(std::chrono::seconds(2)));
  auto res = future.get();
  log::info("FEATURES:{}", res.feature);
  CHECK(res.feature == (BTRC_FEAT_ABSOLUTE_VOLUME | BTRC_FEAT_METADATA |
  ASSERT_EQ(res.feature, (BTRC_FEAT_ABSOLUTE_VOLUME | BTRC_FEAT_METADATA |
                          BTRC_FEAT_BROWSE | BTRC_FEAT_COVER_ARTWORK));
}

@@ -318,9 +318,10 @@ TEST_F(BtifRcBrowseConnectionTest, handle_rc_browse_connect) {

  /* process unit test  handle_rc_browse_connect */
  handle_rc_browse_connect(&browse_data);
  CHECK(std::future_status::ready == future.wait_for(std::chrono::seconds(2)));
  ASSERT_EQ(std::future_status::ready,
            future.wait_for(std::chrono::seconds(2)));
  auto res = future.get();
  CHECK(res.bt_state == true);
  ASSERT_TRUE(res.bt_state);
}

class BtifRcConnectionTest : public BtifRcTest {
@@ -368,10 +369,10 @@ TEST_F(BtifRcConnectionTest, handle_rc_browse_connect) {

  /* process unit test  handle_rc_browse_connect */
  handle_rc_browse_connect(&browse_data);
  CHECK(std::future_status::ready ==
  ASSERT_EQ(std::future_status::ready,
            g_btrc_connection_state_future.wait_for(std::chrono::seconds(2)));
  auto res = g_btrc_connection_state_future.get();
  CHECK(res.bt_state == true);
  ASSERT_TRUE(res.bt_state);
}

TEST_F(BtifRcConnectionTest, btif_rc_check_pending_cmd) {
@@ -386,10 +387,10 @@ TEST_F(BtifRcConnectionTest, btif_rc_check_pending_cmd) {
  btif_rc_check_pending_cmd(kDeviceAddress);
  ASSERT_EQ(1, get_func_call_count("AVRC_BldCommand"));

  CHECK(std::future_status::ready ==
  ASSERT_EQ(std::future_status::ready,
            g_btrc_connection_state_future.wait_for(std::chrono::seconds(3)));
  auto res = g_btrc_connection_state_future.get();
  CHECK(res.rc_state == true);
  ASSERT_TRUE(res.rc_state);
}

TEST_F(BtifRcConnectionTest, bt_av_rc_open_evt) {
@@ -419,14 +420,14 @@ TEST_F(BtifRcConnectionTest, bt_av_rc_open_evt) {

  btif_rc_handler(BTA_AV_RC_OPEN_EVT, &data);

  CHECK(btif_rc_cb.rc_multi_cb[data.rc_open.rc_handle].rc_connected == true);
  CHECK(btif_rc_cb.rc_multi_cb[data.rc_open.rc_handle].rc_state ==
  ASSERT_TRUE(btif_rc_cb.rc_multi_cb[data.rc_open.rc_handle].rc_connected);
  ASSERT_EQ(btif_rc_cb.rc_multi_cb[data.rc_open.rc_handle].rc_state,
            BTRC_CONNECTION_STATE_CONNECTED);

  CHECK(std::future_status::ready ==
  ASSERT_EQ(std::future_status::ready,
            g_btrc_connection_state_future.wait_for(std::chrono::seconds(2)));
  auto res = g_btrc_connection_state_future.get();
  CHECK(res.rc_state == true);
  ASSERT_TRUE(res.rc_state);
}

class BtifTrackChangeCBTest : public BtifRcTest {
+10 −4
Original line number Diff line number Diff line
#include "osi/semaphore.h"

#include <base/logging.h>
#include <gtest/gtest.h>
#include <sys/select.h>
#include <unistd.h>

#include "common/message_loop_thread.h"
#include "include/check.h"
#include "osi/include/osi.h"
#include "osi/include/reactor.h"

@@ -21,8 +19,16 @@ namespace {
void sleep_then_increment_counter(void* context) {
  SemaphoreTestSequenceHelper* helper =
      reinterpret_cast<SemaphoreTestSequenceHelper*>(context);
  CHECK(helper);
  CHECK(helper->semaphore);
  EXPECT_NE(helper, nullptr);
  if (helper == nullptr) {
    return;
  }

  EXPECT_NE(helper->semaphore, nullptr);
  if (helper->semaphore == nullptr) {
    return;
  }

  sleep(1);
  ++helper->counter;
  semaphore_post(helper->semaphore);
+4 −5
Original line number Diff line number Diff line
#include "osi/include/list.h"

#include <base/logging.h>
#include <gtest/gtest.h>

#include "osi/include/osi.h"
@@ -143,8 +142,8 @@ TEST_F(ListTest, test_list_next) {
}

static bool list_callback_sum(void* data, void* context) {
  CHECK(data);
  CHECK(context);
  EXPECT_NE(data, nullptr);
  EXPECT_NE(context, nullptr);
  int* sum = (int*)context;
  int* value = (int*)data;
  *sum += *value;
@@ -152,8 +151,8 @@ static bool list_callback_sum(void* data, void* context) {
}

static bool list_callback_find_int(void* data, void* context) {
  CHECK(data);
  CHECK(context);
  EXPECT_NE(data, nullptr);
  EXPECT_NE(context, nullptr);
  return (*(int*)data != *(int*)context);
}

+7 −12
Original line number Diff line number Diff line
@@ -16,16 +16,14 @@
 *
 ******************************************************************************/

#include <gtest/gtest.h>
#include "osi/include/wakelock.h"

#include <base/logging.h>
#include <fcntl.h>
#include <gtest/gtest.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>

#include "osi/include/wakelock.h"

static bool is_wake_lock_acquired = false;

static int acquire_wake_lock_cb(const char* lock_name) {
@@ -53,10 +51,7 @@ class WakelockTest : public ::testing::Test {

    char* buffer = const_cast<char*>(tmp_dir_.c_str());
    char* dtemp = mkdtemp(buffer);
    if (!dtemp) {
      perror("Can't make wake lock test directory: ");
      CHECK(false);
    }
    ASSERT_NE(dtemp, nullptr) << "Can't make wake lock test directory";

    lock_path_ = tmp_dir_ + "/wake_lock";
    unlock_path_ = tmp_dir_ + "/wake_unlock";
@@ -89,16 +84,16 @@ class WakelockTest : public ::testing::Test {
    bool acquired = false;

    int lock_fd = open(lock_path_.c_str(), O_RDONLY);
    CHECK(lock_fd >= 0);
    EXPECT_GE(lock_fd, 0);

    int unlock_fd = open(unlock_path_.c_str(), O_RDONLY);
    CHECK(unlock_fd >= 0);
    EXPECT_GE(unlock_fd, 0);

    struct stat lock_stat, unlock_stat;
    fstat(lock_fd, &lock_stat);
    fstat(unlock_fd, &unlock_stat);

    CHECK(lock_stat.st_size >= unlock_stat.st_size);
    EXPECT_GE(lock_stat.st_size, unlock_stat.st_size);

    void* lock_file =
        mmap(nullptr, lock_stat.st_size, PROT_READ, MAP_PRIVATE, lock_fd, 0);
@@ -111,7 +106,7 @@ class WakelockTest : public ::testing::Test {
    } else {
      // these files should always either be with a lock that has more,
      // or equal.
      CHECK(false);
      ADD_FAILURE();
    }

    munmap(lock_file, lock_stat.st_size);
+1 −4
Original line number Diff line number Diff line
@@ -16,13 +16,10 @@

#include "stack/include/a2dp_vendor_ldac_decoder.h"

#include <base/logging.h>
#include <gtest/gtest.h>
#include <stdio.h>

#include <cstdint>

#include "include/check.h"
#include "osi/include/allocator.h"
#include "stack/include/bt_hdr.h"

@@ -55,6 +52,6 @@ class A2dpStackTest : public ::testing::Test {
TEST_F(A2dpStackTest, DecodePacket_ZeroLength) {
  const std::vector<uint8_t> data;
  BT_HDR* p_buf = AllocateL2capPacket(data);
  CHECK(!a2dp_vendor_ldac_decoder_decode_packet(p_buf));
  ASSERT_FALSE(a2dp_vendor_ldac_decoder_decode_packet(p_buf));
  osi_free(p_buf);
}
Loading