• 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 #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,
42                 0x0c80, 0x0, 0x0),
43             ErrorCode::SUCCESS);
44   ASSERT_EQ(controller_.LeCreateConnectionCancel(), ErrorCode::SUCCESS);
45 }
46 
TEST_F(LeCreateConnectionCancelTest,CancelExtendedConnection)47 TEST_F(LeCreateConnectionCancelTest, CancelExtendedConnection) {
48   ASSERT_EQ(
49       controller_.LeExtendedCreateConnection(
50           InitiatorFilterPolicy::USE_PEER_ADDRESS,
51           OwnAddressType::PUBLIC_DEVICE_ADDRESS,
52           AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
53           {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010,
54                                        0x0c80, 0x0, 0x0)}),
55       ErrorCode::SUCCESS);
56   ASSERT_EQ(controller_.LeCreateConnectionCancel(), ErrorCode::SUCCESS);
57 }
58 
TEST_F(LeCreateConnectionCancelTest,NoPendingConnection)59 TEST_F(LeCreateConnectionCancelTest, NoPendingConnection) {
60   ASSERT_EQ(controller_.LeCreateConnectionCancel(),
61             ErrorCode::COMMAND_DISALLOWED);
62 }
63 
64 }  // namespace rootcanal
65