Skip to content

Commit

Permalink
pw_bluetooth_proxy: Tweak CreateNonInteractingToHostBuffer to take array
Browse files Browse the repository at this point in the history
Simple refactor ahead of larger refactor in later CL.

Bug: 326499611
Test: CQ (tests updated)
Change-Id: I782fadf8ab97013b884fb9e13467f7451367c307
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/213663
Pigweed-Auto-Submit: David Rees <[email protected]>
Lint: Lint 🤖 <[email protected]>
Reviewed-by: Ben Lawson <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
  • Loading branch information
studgeek authored and CQ Bot Account committed Jun 4, 2024
1 parent 6618a7d commit ee2ddb5
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions pw_bluetooth_proxy/proxy_host_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ EmbossT CreateAndPopulateToControllerView(std::array<uint8_t, arr_size>& h4_arr,

// Return a populated H4 command buffer of a type that proxy host doesn't
// interact with.
std::array<uint8_t, emboss::InquiryCommandView::SizeInBytes() + 1>
PopulateNoninteractingToControllerBuffer(
void PopulateNoninteractingToControllerBuffer(
std::array<uint8_t, emboss::InquiryCommandView::SizeInBytes() + 1>& arr) {
CreateAndPopulateToControllerView<emboss::InquiryCommandWriter>(
arr, emboss::OpCode::LINK_KEY_REQUEST_REPLY);
return arr;
}

// Populate passed H4 event buffer and return Emboss view on it.
Expand All @@ -68,13 +66,12 @@ EmbossT CreateAndPopulateToHostEventView(std::array<uint8_t, arr_size>& arr,

// Return a populated H4 event buffer of a type that proxy host doesn't interact
// with.
std::array<uint8_t, emboss::InquiryCompleteEventView::SizeInBytes() + 1>
CreateNonInteractingToHostBuffer() {
std::array<uint8_t, emboss::InquiryCompleteEventWriter::SizeInBytes() + 1>
arr;

void CreateNonInteractingToHostBuffer(
std::array<uint8_t, emboss::InquiryCompleteEventView::SizeInBytes() + 1>&
arr) {
CreateAndPopulateToHostEventView<emboss::InquiryCompleteEventWriter>(
arr, emboss::EventCode::INQUIRY_COMPLETE);
return arr;
}

// ########## Examples
Expand All @@ -89,7 +86,8 @@ TEST(Example, ExampleUsage) {

// Populate H4 buffer to send towards host.
std::array<uint8_t, emboss::InquiryCompleteEventView::SizeInBytes() + 1>
h4_array_from_controller = CreateNonInteractingToHostBuffer();
h4_array_from_controller;
CreateNonInteractingToHostBuffer(h4_array_from_controller);
auto h4_span_from_controller = pw::span(h4_array_from_controller);

H4HciPacketSendFn containerSendToHostFn([](H4HciPacket packet) {});
Expand Down Expand Up @@ -159,7 +157,8 @@ TEST(PassthroughTest, ToControllerPassesEqualBuffer) {
// Verify buffer is properly passed (contents unaltered and zero-copy).
TEST(PassthroughTest, ToHostPassesEqualBuffer) {
std::array<uint8_t, emboss::InquiryCompleteEventView::SizeInBytes() + 1>
send_packet = CreateNonInteractingToHostBuffer();
send_packet;
CreateNonInteractingToHostBuffer(send_packet);

// Struct for capturing because `pw::Function` can't fit multiple captures.
struct {
Expand Down Expand Up @@ -287,7 +286,8 @@ TEST(BadPacketTest, EmptyBufferToHostIsPassedOn) {

TEST(BadPacketTest, TooShortEventToHostIsPassOn) {
std::array<uint8_t, emboss::InquiryCompleteEventView::SizeInBytes() + 1>
valid_packet = CreateNonInteractingToHostBuffer();
valid_packet;
CreateNonInteractingToHostBuffer(valid_packet);

// Create span for sending whose size is one less than a valid command
// complete event.
Expand Down

0 comments on commit ee2ddb5

Please sign in to comment.