• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
21 namespace rootcanal {
22 
23 using namespace bluetooth::hci;
24 
25 class LeSetScanEnableTest : public ::testing::Test {
26  public:
27   LeSetScanEnableTest() = default;
28   ~LeSetScanEnableTest() override = default;
29 
30  protected:
31   Address address_{0};
32   ControllerProperties properties_{};
33   LinkLayerController controller_{address_, properties_};
34 };
35 
TEST_F(LeSetScanEnableTest,EnableUsingPublicAddress)36 TEST_F(LeSetScanEnableTest, EnableUsingPublicAddress) {
37   ASSERT_EQ(
38       controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200,
39                                       OwnAddressType::PUBLIC_DEVICE_ADDRESS,
40                                       LeScanningFilterPolicy::ACCEPT_ALL),
41       ErrorCode::SUCCESS);
42   ASSERT_EQ(controller_.LeSetScanEnable(true, false), ErrorCode::SUCCESS);
43 }
44 
TEST_F(LeSetScanEnableTest,EnableUsingRandomAddress)45 TEST_F(LeSetScanEnableTest, EnableUsingRandomAddress) {
46   ASSERT_EQ(
47       controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200,
48                                       OwnAddressType::RANDOM_DEVICE_ADDRESS,
49                                       LeScanningFilterPolicy::ACCEPT_ALL),
50       ErrorCode::SUCCESS);
51   ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS);
52   ASSERT_EQ(controller_.LeSetScanEnable(true, false), ErrorCode::SUCCESS);
53 }
54 
TEST_F(LeSetScanEnableTest,EnableUsingResolvableAddress)55 TEST_F(LeSetScanEnableTest, EnableUsingResolvableAddress) {
56   ASSERT_EQ(controller_.LeSetScanParameters(
57                 LeScanType::PASSIVE, 0x2000, 0x200,
58                 OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS,
59                 LeScanningFilterPolicy::ACCEPT_ALL),
60             ErrorCode::SUCCESS);
61   ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS);
62   ASSERT_EQ(controller_.LeSetScanEnable(true, false), ErrorCode::SUCCESS);
63 }
64 
TEST_F(LeSetScanEnableTest,Disable)65 TEST_F(LeSetScanEnableTest, Disable) {
66   ASSERT_EQ(controller_.LeSetScanEnable(false, false), ErrorCode::SUCCESS);
67 }
68 
TEST_F(LeSetScanEnableTest,NoRandomAddress)69 TEST_F(LeSetScanEnableTest, NoRandomAddress) {
70   ASSERT_EQ(
71       controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200,
72                                       OwnAddressType::RANDOM_DEVICE_ADDRESS,
73                                       LeScanningFilterPolicy::ACCEPT_ALL),
74       ErrorCode::SUCCESS);
75   ASSERT_EQ(controller_.LeSetScanEnable(true, false),
76             ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
77 
78   ASSERT_EQ(controller_.LeSetScanParameters(
79                 LeScanType::PASSIVE, 0x2000, 0x200,
80                 OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS,
81                 LeScanningFilterPolicy::ACCEPT_ALL),
82             ErrorCode::SUCCESS);
83   ASSERT_EQ(controller_.LeSetScanEnable(true, false),
84             ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
85 }
86 
87 }  // namespace rootcanal
88