• 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 LeSetExtendedScanEnableTest : public ::testing::Test {
26  public:
27   LeSetExtendedScanEnableTest() = default;
28   ~LeSetExtendedScanEnableTest() override = default;
29 
30  protected:
31   Address address_{0};
32   ControllerProperties properties_{};
33   LinkLayerController controller_{address_, properties_};
34 };
35 
MakeScanningPhyParameters(LeScanType scan_type,uint16_t scan_interval,uint16_t scan_window)36 static ScanningPhyParameters MakeScanningPhyParameters(LeScanType scan_type,
37                                                        uint16_t scan_interval,
38                                                        uint16_t scan_window) {
39   ScanningPhyParameters parameters;
40   parameters.le_scan_type_ = scan_type;
41   parameters.le_scan_interval_ = scan_interval;
42   parameters.le_scan_window_ = scan_window;
43   return parameters;
44 }
45 
TEST_F(LeSetExtendedScanEnableTest,EnableUsingPublicAddress)46 TEST_F(LeSetExtendedScanEnableTest, EnableUsingPublicAddress) {
47   ASSERT_EQ(
48       controller_.LeSetExtendedScanParameters(
49           OwnAddressType::PUBLIC_DEVICE_ADDRESS,
50           LeScanningFilterPolicy::ACCEPT_ALL, 0x1,
51           {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}),
52       ErrorCode::SUCCESS);
53   ASSERT_EQ(controller_.LeSetExtendedScanEnable(
54                 true, FilterDuplicates::DISABLED, 0, 0),
55             ErrorCode::SUCCESS);
56 }
57 
TEST_F(LeSetExtendedScanEnableTest,EnableUsingRandomAddress)58 TEST_F(LeSetExtendedScanEnableTest, EnableUsingRandomAddress) {
59   ASSERT_EQ(
60       controller_.LeSetExtendedScanParameters(
61           OwnAddressType::RANDOM_DEVICE_ADDRESS,
62           LeScanningFilterPolicy::ACCEPT_ALL, 0x1,
63           {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}),
64       ErrorCode::SUCCESS);
65   ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS);
66   ASSERT_EQ(controller_.LeSetExtendedScanEnable(
67                 true, FilterDuplicates::DISABLED, 0, 0),
68             ErrorCode::SUCCESS);
69 }
70 
TEST_F(LeSetExtendedScanEnableTest,EnableUsingResolvableAddress)71 TEST_F(LeSetExtendedScanEnableTest, EnableUsingResolvableAddress) {
72   ASSERT_EQ(
73       controller_.LeSetExtendedScanParameters(
74           OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS,
75           LeScanningFilterPolicy::ACCEPT_ALL, 0x1,
76           {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}),
77       ErrorCode::SUCCESS);
78   ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS);
79   ASSERT_EQ(controller_.LeSetExtendedScanEnable(
80                 true, FilterDuplicates::DISABLED, 0, 0),
81             ErrorCode::SUCCESS);
82 }
83 
TEST_F(LeSetExtendedScanEnableTest,ResetEachPeriod)84 TEST_F(LeSetExtendedScanEnableTest, ResetEachPeriod) {
85   ASSERT_EQ(
86       controller_.LeSetExtendedScanParameters(
87           OwnAddressType::PUBLIC_DEVICE_ADDRESS,
88           LeScanningFilterPolicy::ACCEPT_ALL, 0x1,
89           {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}),
90       ErrorCode::SUCCESS);
91   ASSERT_EQ(controller_.LeSetExtendedScanEnable(
92                 true, FilterDuplicates::RESET_EACH_PERIOD, 100, 1000),
93             ErrorCode::SUCCESS);
94 }
95 
TEST_F(LeSetExtendedScanEnableTest,Disable)96 TEST_F(LeSetExtendedScanEnableTest, Disable) {
97   ASSERT_EQ(controller_.LeSetExtendedScanEnable(
98                 false, FilterDuplicates::DISABLED, 0, 0),
99             ErrorCode::SUCCESS);
100 }
101 
TEST_F(LeSetExtendedScanEnableTest,ValidDuration)102 TEST_F(LeSetExtendedScanEnableTest, ValidDuration) {
103   ASSERT_EQ(
104       controller_.LeSetExtendedScanParameters(
105           OwnAddressType::PUBLIC_DEVICE_ADDRESS,
106           LeScanningFilterPolicy::ACCEPT_ALL, 0x1,
107           {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}),
108       ErrorCode::SUCCESS);
109 
110   ASSERT_EQ(controller_.LeSetExtendedScanEnable(
111                 true, FilterDuplicates::DISABLED, 127, 1),
112             ErrorCode::SUCCESS);
113 }
114 
TEST_F(LeSetExtendedScanEnableTest,InvalidDuration)115 TEST_F(LeSetExtendedScanEnableTest, InvalidDuration) {
116   ASSERT_EQ(
117       controller_.LeSetExtendedScanParameters(
118           OwnAddressType::PUBLIC_DEVICE_ADDRESS,
119           LeScanningFilterPolicy::ACCEPT_ALL, 0x1,
120           {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}),
121       ErrorCode::SUCCESS);
122 
123   ASSERT_EQ(controller_.LeSetExtendedScanEnable(
124                 true, FilterDuplicates::RESET_EACH_PERIOD, 0, 0),
125             ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
126   ASSERT_EQ(controller_.LeSetExtendedScanEnable(
127                 true, FilterDuplicates::DISABLED, 128, 1),
128             ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
129 }
130 
TEST_F(LeSetExtendedScanEnableTest,NoRandomAddress)131 TEST_F(LeSetExtendedScanEnableTest, NoRandomAddress) {
132   ASSERT_EQ(
133       controller_.LeSetExtendedScanParameters(
134           OwnAddressType::RANDOM_DEVICE_ADDRESS,
135           LeScanningFilterPolicy::ACCEPT_ALL, 0x1,
136           {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}),
137       ErrorCode::SUCCESS);
138   ASSERT_EQ(controller_.LeSetExtendedScanEnable(
139                 true, FilterDuplicates::DISABLED, 0, 0),
140             ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
141 
142   ASSERT_EQ(
143       controller_.LeSetExtendedScanParameters(
144           OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS,
145           LeScanningFilterPolicy::ACCEPT_ALL, 0x1,
146           {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}),
147       ErrorCode::SUCCESS);
148   ASSERT_EQ(controller_.LeSetExtendedScanEnable(
149                 true, FilterDuplicates::DISABLED, 0, 0),
150             ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
151 }
152 
153 }  // namespace rootcanal
154