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

Commit 5d5dda91 authored by Chris Manton's avatar Chris Manton Committed by Gerrit Code Review
Browse files

Merge "Add discovery_state_text"

parents 283c3e7b 06977764
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@
#ifndef SDP_INT_H
#define SDP_INT_H

#include <base/strings/stringprintf.h>

#include <cstdint>

#include "bt_target.h"
@@ -173,6 +175,28 @@ struct tCONN_CB {
  tCONN_CB(const tCONN_CB&) = delete;
};

#ifndef CASE_RETURN_TEXT
#define CASE_RETURN_TEXT(code) \
  case code:                   \
    return #code
#endif

using tSDP_DISC_WAIT = int;

inline std::string discovery_state_text(const tSDP_DISC_WAIT& state) {
  switch (state) {
    CASE_RETURN_TEXT(SDP_DISC_WAIT_CONN);
    CASE_RETURN_TEXT(SDP_DISC_WAIT_HANDLES);
    CASE_RETURN_TEXT(SDP_DISC_WAIT_ATTR);
    CASE_RETURN_TEXT(SDP_DISC_WAIT_SEARCH_ATTR);
    CASE_RETURN_TEXT(SDP_DISC_WAIT_CANCEL);
    default:
      return base::StringPrintf("UNKNOWN[%d]", state);
  }
}

#undef CASE_RETURN_TEXT

/*  The main SDP control block */
typedef struct {
  tL2CAP_CFG_INFO l2cap_my_cfg; /* My L2CAP config     */
+20 −0
Original line number Diff line number Diff line
@@ -172,3 +172,23 @@ TEST_F(StackSdpMainTest, sdp_service_search_request_queuing_race_condition) {

  sdp_disconnect(p_ccb2, SDP_SUCCESS);
}

TEST_F(StackSdpMainTest, discovery_state_text) {
  std::vector<std::pair<tSDP_DISC_WAIT, std::string>> states = {
      std::make_pair(SDP_DISC_WAIT_CONN, "SDP_DISC_WAIT_CONN"),
      std::make_pair(SDP_DISC_WAIT_HANDLES, "SDP_DISC_WAIT_HANDLES"),
      std::make_pair(SDP_DISC_WAIT_ATTR, "SDP_DISC_WAIT_ATTR"),
      std::make_pair(SDP_DISC_WAIT_SEARCH_ATTR, "SDP_DISC_WAIT_SEARCH_ATTR"),
      std::make_pair(SDP_DISC_WAIT_CANCEL, "SDP_DISC_WAIT_CANCEL"),
  };
  for (const auto& state : states) {
    ASSERT_STREQ(state.second.c_str(),
                 discovery_state_text(state.first).c_str());
  }
  auto unknown =
      base::StringPrintf("UNKNOWN[%d]", std::numeric_limits<int>::max());
  ASSERT_STREQ(unknown.c_str(),
               discovery_state_text(
                   static_cast<tSDP_DISC_WAIT>(std::numeric_limits<int>::max()))
                   .c_str());
}