• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #include "softbus_conn_interface.h"
18 #include "softbus_conn_manager.h"
19 #include "softbus_def.h"
20 #include "softbus_errcode.h"
21 #include "softbus_feature_config.h"
22 #include "softbus_log.h"
23 #include "br_connection_manager.c"
24 
25 using namespace testing::ext;
26 namespace OHOS {
27 class ConnectionBrManagerTest : public testing::Test {
28 public:
SetUpTestCase()29     static void SetUpTestCase() {}
TearDownTestCase()30     static void TearDownTestCase() {}
SetUp()31     void SetUp() override {}
TearDown()32     void TearDown() override {}
33 };
34 
35 /*
36 * @tc.name: HasDiffMacDeviceExit
37 * @tc.desc:  br mac match
38 * @tc.type: FUNC
39 * @tc.require:
40 */
41 HWTEST_F(ConnectionBrManagerTest, HasDiffMacDeviceExit, TestSize.Level1)
42 {
43     BrConnectionInfo *info = CreateBrconnectionNode(true);
44     char mac[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
45     memcpy_s(info->mac, sizeof(info->mac), mac, sizeof(mac));
46     ListAdd(&g_connection_list, &info->node);
47 
48     ConnectOption option;
49     int32_t ret = HasDiffMacDeviceExit(&option);
50     EXPECT_EQ(ret, true);
51 
52     ListDelete(&info->node);
53     SoftBusFree(info);
54 }
55 
56 /*
57 * @tc.name: GetBrConnStateByConnectionId
58 * @tc.desc:  find by connection Id
59 * @tc.type: FUNC
60 * @tc.require:
61 */
62 HWTEST_F(ConnectionBrManagerTest, GetBrConnStateByConnectionId, TestSize.Level1)
63 {
64     BrConnectionInfo *info = CreateBrconnectionNode(true);
65     info->state = BR_CONNECTION_STATE_CLOSED;
66     ListAdd(&g_connection_list, &info->node);
67 
68     int32_t ret = GetBrConnStateByConnectionId(info->connectionId);
69     EXPECT_EQ(ret, BR_CONNECTION_STATE_CLOSED);
70 
71     ListDelete(&info->node);
72     SoftBusFree(info);
73 }
74 
75 /*
76 * @tc.name: BrClosingByConnOption
77 * @tc.desc:  br mac match
78 * @tc.type: FUNC
79 * @tc.require:
80 */
81 HWTEST_F(ConnectionBrManagerTest, BrClosingByConnOption, TestSize.Level1)
82 {
83     char mac[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
84     BrConnectionInfo *info = CreateBrconnectionNode(true);
85     memcpy_s(info->mac, sizeof(info->mac), mac, sizeof(mac));
86     info->state = BR_CONNECTION_STATE_CLOSED;
87     ListAdd(&g_connection_list, &info->node);
88 
89     ConnectOption option;
90     memcpy_s(option.brOption.brMac, sizeof(option.brOption.brMac), mac, sizeof(mac));
91 
92     int32_t socketFd;
93     int32_t sideType;
94     int32_t ret = BrClosingByConnOption(&option, &socketFd, &sideType);
95     EXPECT_EQ(ret, SOFTBUS_OK);
96 
97     ListDelete(&info->node);
98     SoftBusFree(info);
99 }
100 
101 /*
102 * @tc.name: BrCheckActiveConnection
103 * @tc.desc:  br mac match and state
104 * @tc.type: FUNC
105 * @tc.require:
106 */
107 HWTEST_F(ConnectionBrManagerTest, BrCheckActiveConnection, TestSize.Level1)
108 {
109     char mac[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
110     BrConnectionInfo *info = CreateBrconnectionNode(true);
111     memcpy_s(info->mac, sizeof(info->mac), mac, sizeof(mac));
112     info->state = BR_CONNECTION_STATE_CONNECTED;
113     ListAdd(&g_connection_list, &info->node);
114 
115     ConnectOption option;
116     memcpy_s(option.brOption.brMac, sizeof(option.brOption.brMac), mac, sizeof(mac));
117 
118     int32_t ret = BrCheckActiveConnection(&option);
119     EXPECT_EQ(ret, SOFTBUS_OK);
120 
121     ListDelete(&info->node);
122     SoftBusFree(info);
123 }
124 }