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 LeSetScanParametersTest : public ::testing::Test {
26 public:
27 LeSetScanParametersTest() = default;
28 ~LeSetScanParametersTest() override = default;
29
30 protected:
31 Address address_{0};
32 ControllerProperties properties_{};
33 LinkLayerController controller_{address_, properties_};
34 };
35
TEST_F(LeSetScanParametersTest,Success)36 TEST_F(LeSetScanParametersTest, Success) {
37 ASSERT_EQ(
38 controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200,
39 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
40 LeScanningFilterPolicy::ACCEPT_ALL),
41 ErrorCode::SUCCESS);
42 }
43
TEST_F(LeSetScanParametersTest,ScanningActive)44 TEST_F(LeSetScanParametersTest, ScanningActive) {
45 ASSERT_EQ(controller_.LeSetScanEnable(true, false), ErrorCode::SUCCESS);
46
47 ASSERT_EQ(
48 controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200,
49 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
50 LeScanningFilterPolicy::ACCEPT_ALL),
51 ErrorCode::COMMAND_DISALLOWED);
52 }
53
TEST_F(LeSetScanParametersTest,InvalidScanInterval)54 TEST_F(LeSetScanParametersTest, InvalidScanInterval) {
55 ASSERT_EQ(
56 controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x0, 0x200,
57 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
58 LeScanningFilterPolicy::ACCEPT_ALL),
59 ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
60
61 ASSERT_EQ(
62 controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x4001, 0x200,
63 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
64 LeScanningFilterPolicy::ACCEPT_ALL),
65 ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
66 }
67
TEST_F(LeSetScanParametersTest,InvalidScanWindow)68 TEST_F(LeSetScanParametersTest, InvalidScanWindow) {
69 ASSERT_EQ(
70 controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x0,
71 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
72 LeScanningFilterPolicy::ACCEPT_ALL),
73 ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
74
75 ASSERT_EQ(
76 controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x4001,
77 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
78 LeScanningFilterPolicy::ACCEPT_ALL),
79 ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
80
81 ASSERT_EQ(
82 controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x2001,
83 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
84 LeScanningFilterPolicy::ACCEPT_ALL),
85 ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
86 }
87
88 } // namespace rootcanal
89