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 #include "test_helpers.h"
21
22 namespace rootcanal {
23
24 using namespace bluetooth::hci;
25
26 class LeCreateConnectionCancelTest : public ::testing::Test {
27 public:
28 LeCreateConnectionCancelTest() = default;
29 ~LeCreateConnectionCancelTest() override = default;
30
31 protected:
32 Address address_{0};
33 ControllerProperties properties_{};
34 LinkLayerController controller_{address_, properties_};
35 };
36
TEST_F(LeCreateConnectionCancelTest,CancelLegacyConnection)37 TEST_F(LeCreateConnectionCancelTest, CancelLegacyConnection) {
38 ASSERT_EQ(controller_.LeCreateConnection(
39 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS,
40 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
41 OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, 0x0c80, 0x0, 0x0),
42 ErrorCode::SUCCESS);
43 ASSERT_EQ(controller_.LeCreateConnectionCancel(), ErrorCode::SUCCESS);
44 }
45
TEST_F(LeCreateConnectionCancelTest,CancelExtendedConnection)46 TEST_F(LeCreateConnectionCancelTest, CancelExtendedConnection) {
47 ASSERT_EQ(controller_.LeExtendedCreateConnection(
48 InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS,
49 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
50 {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, 0x0c80, 0x0,
51 0x0)}),
52 ErrorCode::SUCCESS);
53 ASSERT_EQ(controller_.LeCreateConnectionCancel(), ErrorCode::SUCCESS);
54 }
55
TEST_F(LeCreateConnectionCancelTest,NoPendingConnection)56 TEST_F(LeCreateConnectionCancelTest, NoPendingConnection) {
57 ASSERT_EQ(controller_.LeCreateConnectionCancel(), ErrorCode::COMMAND_DISALLOWED);
58 }
59
60 } // namespace rootcanal
61