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

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

unittest: Enum-ify tBTA_DM_STATE and add bta_dm_state_text

Bug: 254884279
Test: gd/cert/run
Tag: #refactor
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: I65fdb8b34fd390fadf6589c4b55e6d0339e25ecf
parent 3380e1af
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -396,14 +396,25 @@ typedef struct {
} tBTA_DM_DI_CB;

/* DM search state */
enum {
typedef enum {

  BTA_DM_SEARCH_IDLE,
  BTA_DM_SEARCH_ACTIVE,
  BTA_DM_SEARCH_CANCELLING,
  BTA_DM_DISCOVER_ACTIVE

};
} tBTA_DM_STATE;

inline std::string bta_dm_state_text(const tBTA_DM_STATE& state) {
  switch (state) {
    CASE_RETURN_TEXT(BTA_DM_SEARCH_IDLE);
    CASE_RETURN_TEXT(BTA_DM_SEARCH_ACTIVE);
    CASE_RETURN_TEXT(BTA_DM_SEARCH_CANCELLING);
    CASE_RETURN_TEXT(BTA_DM_DISCOVER_ACTIVE);
    default:
      return base::StringPrintf("UNKNOWN[%d]", state);
  }
}

typedef struct {
  uint16_t page_timeout; /* timeout for page in slots */
+18 −0
Original line number Diff line number Diff line
@@ -346,3 +346,21 @@ TEST_F(BtaDmTest, bta_dm_event_text) {
                                     std::numeric_limits<uint16_t>::max()))
                   .c_str());
}

TEST_F(BtaDmTest, bta_dm_state_text) {
  std::vector<std::pair<tBTA_DM_STATE, std::string>> states = {
      std::make_pair(BTA_DM_SEARCH_IDLE, "BTA_DM_SEARCH_IDLE"),
      std::make_pair(BTA_DM_SEARCH_ACTIVE, "BTA_DM_SEARCH_ACTIVE"),
      std::make_pair(BTA_DM_SEARCH_CANCELLING, "BTA_DM_SEARCH_CANCELLING"),
      std::make_pair(BTA_DM_DISCOVER_ACTIVE, "BTA_DM_DISCOVER_ACTIVE"),
  };
  for (const auto& state : states) {
    ASSERT_STREQ(state.second.c_str(), bta_dm_state_text(state.first).c_str());
  }
  auto unknown =
      base::StringPrintf("UNKNOWN[%d]", std::numeric_limits<int>::max());
  ASSERT_STREQ(unknown.c_str(),
               bta_dm_state_text(
                   static_cast<tBTA_DM_STATE>(std::numeric_limits<int>::max()))
                   .c_str());
}