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

Commit 4796d329 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "test: replace callocs with stack allocs" am: f8d97dea

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2023275

Change-Id: I96d40ea0d02ee6a18d8459475ce4845bb322391e
parents 87bc2571 f8d97dea
Loading
Loading
Loading
Loading
+12 −15
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <cstddef>
#include <future>
#include <map>

@@ -364,35 +365,33 @@ TEST_F(MainShimTest, connect_and_disconnect) {

TEST_F(MainShimTest, is_flushable) {
  {
    BT_HDR* bt_hdr =
        (BT_HDR*)calloc(1, sizeof(BT_HDR) + sizeof(HciDataPreamble));
    alignas(BT_HDR)
        std::byte hdr_data[sizeof(BT_HDR) + sizeof(HciDataPreamble)]{};
    BT_HDR* bt_hdr = reinterpret_cast<BT_HDR*>(hdr_data);

    ASSERT_TRUE(!IsPacketFlushable(bt_hdr));
    HciDataPreamble* hci = ToPacketData<HciDataPreamble>(bt_hdr);
    hci->SetFlushable();
    ASSERT_TRUE(IsPacketFlushable(bt_hdr));

    free(bt_hdr);
  }

  {
    size_t offset = 1024;
    BT_HDR* bt_hdr =
        (BT_HDR*)calloc(1, sizeof(BT_HDR) + sizeof(HciDataPreamble) + offset);
    bt_hdr->offset = offset;
    const size_t offset = 1024;
    alignas(BT_HDR)
        std::byte hdr_data[sizeof(BT_HDR) + sizeof(HciDataPreamble) + offset]{};
    BT_HDR* bt_hdr = reinterpret_cast<BT_HDR*>(hdr_data);

    ASSERT_TRUE(!IsPacketFlushable(bt_hdr));
    HciDataPreamble* hci = ToPacketData<HciDataPreamble>(bt_hdr);
    hci->SetFlushable();
    ASSERT_TRUE(IsPacketFlushable(bt_hdr));

    free(bt_hdr);
  }

  {
    size_t offset = 1024;
    BT_HDR* bt_hdr =
        (BT_HDR*)calloc(1, sizeof(BT_HDR) + sizeof(HciDataPreamble) + offset);
    const size_t offset = 1024;
    alignas(BT_HDR)
        std::byte hdr_data[sizeof(BT_HDR) + sizeof(HciDataPreamble) + offset]{};
    BT_HDR* bt_hdr = reinterpret_cast<BT_HDR*>(hdr_data);

    uint8_t* p = ToPacketData<uint8_t>(bt_hdr, L2CAP_SEND_CMD_OFFSET);
    UINT16_TO_STREAM(
@@ -402,7 +401,5 @@ TEST_F(MainShimTest, is_flushable) {
    p = ToPacketData<uint8_t>(bt_hdr, L2CAP_SEND_CMD_OFFSET);
    UINT16_TO_STREAM(p, 0x123 | (L2CAP_PKT_START << L2CAP_PKT_TYPE_SHIFT));
    ASSERT_TRUE(IsPacketFlushable(bt_hdr));

    free(bt_hdr);
  }
}