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 <gtest/gtest.h>
18 
19 #include "model/controller/link_layer_controller.h"
20 #include "test_helpers.h"
21 
22 namespace rootcanal {
23 
24 using namespace bluetooth::hci;
25 
26 class LeSetAddressResolutionEnableTest : public ::testing::Test {
27 public:
28   LeSetAddressResolutionEnableTest() = default;
29   ~LeSetAddressResolutionEnableTest() override = default;
30 
31 protected:
32   Address address_{0};
33   ControllerProperties properties_{};
34   LinkLayerController controller_{address_, properties_};
35 };
36 
TEST_F(LeSetAddressResolutionEnableTest,Success)37 TEST_F(LeSetAddressResolutionEnableTest, Success) {
38   ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::SUCCESS);
39   ASSERT_EQ(controller_.LeSetAddressResolutionEnable(false), ErrorCode::SUCCESS);
40 }
41 
TEST_F(LeSetAddressResolutionEnableTest,ScanningActive)42 TEST_F(LeSetAddressResolutionEnableTest, ScanningActive) {
43   controller_.LeSetScanEnable(true, false);
44   ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::COMMAND_DISALLOWED);
45   ASSERT_EQ(controller_.LeSetAddressResolutionEnable(false), ErrorCode::COMMAND_DISALLOWED);
46 }
47 
TEST_F(LeSetAddressResolutionEnableTest,LegacyAdvertisingActive)48 TEST_F(LeSetAddressResolutionEnableTest, LegacyAdvertisingActive) {
49   ASSERT_EQ(controller_.LeSetAdvertisingEnable(true), ErrorCode::SUCCESS);
50   ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::COMMAND_DISALLOWED);
51   ASSERT_EQ(controller_.LeSetAddressResolutionEnable(false), ErrorCode::COMMAND_DISALLOWED);
52 }
53 
TEST_F(LeSetAddressResolutionEnableTest,ExtendedAdvertisingActive)54 TEST_F(LeSetAddressResolutionEnableTest, ExtendedAdvertisingActive) {
55   ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters(
56                     0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7,
57                     OwnAddressType::PUBLIC_DEVICE_ADDRESS,
58                     PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty,
59                     AdvertisingFilterPolicy::LISTED_SCAN, 0x70, PrimaryPhyType::LE_1M, 0,
60                     SecondaryPhyType::LE_2M, 0x0, false),
61             ErrorCode::SUCCESS);
62   ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}),
63             ErrorCode::SUCCESS);
64 
65   ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::COMMAND_DISALLOWED);
66   ASSERT_EQ(controller_.LeSetAddressResolutionEnable(false), ErrorCode::COMMAND_DISALLOWED);
67 }
68 
69 }  // namespace rootcanal
70