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(controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200,
38 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
39 LeScanningFilterPolicy::ACCEPT_ALL),
40 ErrorCode::SUCCESS);
41 ASSERT_EQ(controller_.LeSetScanEnable(true, false), ErrorCode::SUCCESS);
42 }
43
TEST_F(LeSetScanEnableTest,EnableUsingRandomAddress)44 TEST_F(LeSetScanEnableTest, EnableUsingRandomAddress) {
45 ASSERT_EQ(controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200,
46 OwnAddressType::RANDOM_DEVICE_ADDRESS,
47 LeScanningFilterPolicy::ACCEPT_ALL),
48 ErrorCode::SUCCESS);
49 ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS);
50 ASSERT_EQ(controller_.LeSetScanEnable(true, false), ErrorCode::SUCCESS);
51 }
52
TEST_F(LeSetScanEnableTest,EnableUsingResolvableAddress)53 TEST_F(LeSetScanEnableTest, EnableUsingResolvableAddress) {
54 ASSERT_EQ(controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200,
55 OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS,
56 LeScanningFilterPolicy::ACCEPT_ALL),
57 ErrorCode::SUCCESS);
58 ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS);
59 ASSERT_EQ(controller_.LeSetScanEnable(true, false), ErrorCode::SUCCESS);
60 }
61
TEST_F(LeSetScanEnableTest,Disable)62 TEST_F(LeSetScanEnableTest, Disable) {
63 ASSERT_EQ(controller_.LeSetScanEnable(false, false), ErrorCode::SUCCESS);
64 }
65
TEST_F(LeSetScanEnableTest,NoRandomAddress)66 TEST_F(LeSetScanEnableTest, NoRandomAddress) {
67 ASSERT_EQ(controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200,
68 OwnAddressType::RANDOM_DEVICE_ADDRESS,
69 LeScanningFilterPolicy::ACCEPT_ALL),
70 ErrorCode::SUCCESS);
71 ASSERT_EQ(controller_.LeSetScanEnable(true, false), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
72
73 ASSERT_EQ(controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200,
74 OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS,
75 LeScanningFilterPolicy::ACCEPT_ALL),
76 ErrorCode::SUCCESS);
77 ASSERT_EQ(controller_.LeSetScanEnable(true, false), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
78 }
79
80 } // namespace rootcanal
81