1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "bta/include/bta_api.h"
18 
19 #include <base/functional/bind.h>
20 #include <base/location.h>
21 #include <gtest/gtest.h>
22 
23 #include <cstdint>
24 #include <utility>
25 #include <vector>
26 
27 #include "common/init_flags.h"
28 #include "test/common/mock_functions.h"
29 
30 using namespace std::chrono_literals;
31 
32 class BtaApiTest : public testing::Test {
33  protected:
SetUp()34   void SetUp() override { reset_mock_function_count_map(); }
TearDown()35   void TearDown() override {}
36 };
37 
TEST_F(BtaApiTest,bta_status_text)38 TEST_F(BtaApiTest, bta_status_text) {
39   std::vector<std::pair<tBTA_STATUS, std::string>> statuses = {
40       std::make_pair(BTA_SUCCESS, "BTA_SUCCESS"),
41       std::make_pair(BTA_FAILURE, "BTA_FAILURE"),
42       std::make_pair(BTA_PENDING, "BTA_PENDING"),
43       std::make_pair(BTA_BUSY, "BTA_BUSY"),
44       std::make_pair(BTA_NO_RESOURCES, "BTA_NO_RESOURCES"),
45       std::make_pair(BTA_WRONG_MODE, "BTA_WRONG_MODE"),
46   };
47   for (const auto& status : statuses) {
48     ASSERT_STREQ(status.second.c_str(), bta_status_text(status.first).c_str());
49   }
50   auto unknown =
51       base::StringPrintf("UNKNOWN[%d]", std::numeric_limits<uint8_t>::max());
52   ASSERT_STREQ(unknown.c_str(),
53                bta_status_text(static_cast<tBTA_STATUS>(
54                                    std::numeric_limits<uint8_t>::max()))
55                    .c_str());
56 }
57