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 "hci/controller.h"
18 
19 #include <gtest/gtest.h>
20 
21 namespace bluetooth {
22 namespace hci {
23 
24 class ControllerUnitTest : public ::testing::Test {
25  protected:
SetUp()26   void SetUp() override {}
27 
TearDown()28   void TearDown() override {}
29 };
30 
TEST_F(ControllerUnitTest,testLeEventMask)31 TEST_F(ControllerUnitTest, testLeEventMask) {
32   LocalVersionInformation version;
33   version.hci_version_ = HciVersion::V_5_3;
34 
35   // Update the function and this test when adding new bits.
36   ASSERT_TRUE(Controller::kLeEventMask53 > Controller::kDefaultLeEventMask);
37 
38   ASSERT_EQ(
39       Controller::MaskLeEventMask(version.hci_version_, Controller::kDefaultLeEventMask),
40       Controller::kDefaultLeEventMask);
41   ASSERT_LE(
42       Controller::MaskLeEventMask(version.hci_version_, Controller::kDefaultLeEventMask),
43       Controller::kLeEventMask53);
44   version.hci_version_ = HciVersion::V_5_2;
45   ASSERT_LE(
46       Controller::MaskLeEventMask(version.hci_version_, Controller::kDefaultLeEventMask), Controller::kLeEventMask52);
47   version.hci_version_ = HciVersion::V_5_1;
48   ASSERT_LE(
49       Controller::MaskLeEventMask(version.hci_version_, Controller::kDefaultLeEventMask), Controller::kLeEventMask51);
50   version.hci_version_ = HciVersion::V_4_2;
51   ASSERT_LE(
52       Controller::MaskLeEventMask(version.hci_version_, Controller::kDefaultLeEventMask), Controller::kLeEventMask42);
53   version.hci_version_ = HciVersion::V_4_1;
54   ASSERT_LE(
55       Controller::MaskLeEventMask(version.hci_version_, Controller::kDefaultLeEventMask), Controller::kLeEventMask41);
56 }
57 
58 }  // namespace hci
59 }  // namespace bluetooth
60