1 /*
2 * Copyright 2023 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 <gtest/gtest.h>
18
19 #include "stack/include/bt_dev_class.h"
20
21 class StackIncludeTest : public ::testing::Test {
22 protected:
SetUp()23 void SetUp() override {}
24
TearDown()25 void TearDown() override {}
26 };
27
TEST_F(StackIncludeTest,dev_class_simple_zeros)28 TEST_F(StackIncludeTest, dev_class_simple_zeros) {
29 int mn = 0;
30 int mj = 0;
31 int sv = 0;
32 DEV_CLASS dev_class{0xff};
33 FIELDS_TO_COD(dev_class, mn, mj, sv);
34 BTM_COD_MINOR_CLASS(mn, dev_class);
35 BTM_COD_MAJOR_CLASS(mj, dev_class);
36 BTM_COD_SERVICE_CLASS(sv, dev_class);
37 ASSERT_EQ(0, mn);
38 ASSERT_EQ(0, mj);
39 ASSERT_EQ(0, sv);
40 }
41
TEST_F(StackIncludeTest,dev_class_simple_ones)42 TEST_F(StackIncludeTest, dev_class_simple_ones) {
43 int mn = 0xff;
44 int mj = 0xff;
45 int sv = 0xffff;
46 DEV_CLASS dev_class{0x00};
47 FIELDS_TO_COD(dev_class, mn, mj, sv);
48 BTM_COD_MINOR_CLASS(mn, dev_class);
49 BTM_COD_MAJOR_CLASS(mj, dev_class);
50 BTM_COD_SERVICE_CLASS(sv, dev_class);
51 ASSERT_EQ(252, mn & BTM_COD_MINOR_CLASS_MASK);
52 ASSERT_EQ(31, mj & BTM_COD_MAJOR_CLASS_MASK);
53 ASSERT_EQ(65472, sv);
54 }
55
TEST_F(StackIncludeTest,dev_class_text)56 TEST_F(StackIncludeTest, dev_class_text) {
57 int mn = 0xff;
58 int mj = 0xff;
59 int sv = 0xffff;
60 DEV_CLASS dev_class;
61 FIELDS_TO_COD(dev_class, mn, mj, sv);
62 ASSERT_STREQ("ffc0-1f-fc", dev_class_text(dev_class).c_str());
63 }
64