Skip to content
Snippets Groups Projects
Commit 336f01c9 authored by Chris Manton's avatar Chris Manton
Browse files

Add bta::bta_status_text

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

Change-Id: I8f634f3597139ec759f4da89c12015dfb843916f
parent feba28e9
No related branches found
No related tags found
No related merge requests found
......@@ -257,6 +257,7 @@ cc_test {
"sys/bta_sys_main.cc",
"sys/utl.cc",
"test/bta_av_test.cc",
"test/bta_api_test.cc",
"test/bta_dm_test.cc",
"test/bta_gatt_test.cc",
"test/bta_pan_test.cc",
......
......@@ -58,6 +58,29 @@ typedef enum : uint8_t {
BTA_WRONG_MODE = 5,
} tBTA_STATUS;
#ifndef CASE_RETURN_TEXT
#define CASE_RETURN_TEXT(code) \
case code: \
return #code
#endif
inline std::string bta_status_text(const tBTA_STATUS& status) {
switch (status) {
CASE_RETURN_TEXT(BTA_SUCCESS);
CASE_RETURN_TEXT(BTA_FAILURE);
CASE_RETURN_TEXT(BTA_PENDING);
CASE_RETURN_TEXT(BTA_BUSY);
CASE_RETURN_TEXT(BTA_NO_RESOURCES);
CASE_RETURN_TEXT(BTA_WRONG_MODE);
default:
return base::StringPrintf("UNKNOWN[%d]", status);
}
}
#undef CASE_RETURN_TEXT
using tSDP_DISC_WAIT = int;
/*
* Service ID
*/
......
/*
* Copyright 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "bta/include/bta_api.h"
#include <base/bind.h>
#include <base/location.h>
#include <gtest/gtest.h>
#include <chrono>
#include <cstdint>
#include <utility>
#include <vector>
#include "bta/sys/bta_sys.h"
#include "test/common/mock_functions.h"
using namespace std::chrono_literals;
namespace {
const char* test_flags[] = {
"INIT_logging_debug_enabled_for_all=true",
nullptr,
};
} // namespace
class BtaApiTest : public testing::Test {
protected:
void SetUp() override {
mock_function_count_map.clear();
bluetooth::common::InitFlags::Load(test_flags);
}
void TearDown() override {}
};
TEST_F(BtaApiTest, bta_status_text) {
std::vector<std::pair<tBTA_STATUS, std::string>> statuses = {
std::make_pair(BTA_SUCCESS, "BTA_SUCCESS"),
std::make_pair(BTA_FAILURE, "BTA_FAILURE"),
std::make_pair(BTA_PENDING, "BTA_PENDING"),
std::make_pair(BTA_BUSY, "BTA_BUSY"),
std::make_pair(BTA_NO_RESOURCES, "BTA_NO_RESOURCES"),
std::make_pair(BTA_WRONG_MODE, "BTA_WRONG_MODE"),
};
for (const auto& status : statuses) {
ASSERT_STREQ(status.second.c_str(), bta_status_text(status.first).c_str());
}
auto unknown =
base::StringPrintf("UNKNOWN[%d]", std::numeric_limits<uint8_t>::max());
ASSERT_STREQ(unknown.c_str(),
bta_status_text(static_cast<tBTA_STATUS>(
std::numeric_limits<uint8_t>::max()))
.c_str());
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment