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