• 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 #include <cstring>
16 #include <gtest/gtest.h>
17 #include <securec.h>
18 
19 #include "softbus_common.h"
20 #include "client_bus_center_manager.c"
21 
22 namespace OHOS {
23 using namespace testing::ext;
24 
25 
26 class ClientBusMangerTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     void SetUp();
31     void TearDown();
32 };
33 
SetUpTestCase()34 void ClientBusMangerTest::SetUpTestCase()
35 {
36 }
37 
TearDownTestCase()38 void ClientBusMangerTest::TearDownTestCase()
39 {
40 }
41 
SetUp()42 void ClientBusMangerTest::SetUp()
43 {
44     BusCenterClientInit();
45 }
46 
TearDown()47 void ClientBusMangerTest::TearDown()
48 {
49 }
50 
51 /*
52 * @tc.name: IS_SAME_CONNECTION_ADDR
53 * @tc.desc: PreLink lane test
54 * @tc.type: FUNC
55 * @tc.require: AR000FN5VC
56 */
57 HWTEST_F(ClientBusMangerTest, IS_SAME_CONNECTION_ADDR_Test_001, TestSize.Level1)
58 {
59     const ConnectionAddr addr1 = {
60         .type = CONNECTION_ADDR_MAX,
61         .info.session.sessionId = 1,
62     };
63     const ConnectionAddr addr2 = {
64         .type = CONNECTION_ADDR_SESSION,
65         .info.session.sessionId = 2,
66     };
67     int32_t ret = IsSameConnectionAddr(&addr1, &addr2);
68     EXPECT_TRUE(ret == false);
69     const ConnectionAddr addr3 = {
70         .type = CONNECTION_ADDR_SESSION,
71         .info.session.sessionId = 1,
72     };
73     ret = IsSameConnectionAddr(&addr3, &addr2);
74     EXPECT_TRUE(ret == false);
75 }
76 
77 /*
78 
79 * @tc.name: JoinMetaNodeInner
80 * @tc.desc: JoinMetaNode test
81 * @tc.type: FUNC
82 * @tc.require: AR000FN5VC
83 */
84 HWTEST_F(ClientBusMangerTest, JOIN_METANODE_Test_001, TestSize.Level1)
85 {
86     g_busCenterClient.isInit = false;
87     char pkgName[] = "test";
88     ConnectionAddr connAddr;
89     (void)memset_s(&connAddr, sizeof(ConnectionAddr), 0, sizeof(ConnectionAddr));
90     CustomData customData;
91     (void)memset_s(&customData, sizeof(CustomData), 0, sizeof(CustomData));
92     OnJoinLNNResult cb = nullptr;
93     int32_t ret = JoinMetaNodeInner(pkgName, &connAddr, &customData, cb);
94     EXPECT_TRUE(ret == SOFTBUS_NO_INIT);
95     g_busCenterClient.isInit = true;
96     ret = JoinMetaNodeInner(pkgName, &connAddr, &customData, cb);
97     EXPECT_TRUE(ret == SOFTBUS_IPC_ERR);
98 }
99 
100 /*
101 * @tc.name: LEAVE_META_NODE_INNER
102 * @tc.desc: LEAVE_META_NODE_INNER test
103 * @tc.type: FUNC
104 * @tc.require: AR000FN5VC
105 */
106 HWTEST_F(ClientBusMangerTest, LEAVE_META_NODE_INNER_Test_001, TestSize.Level1)
107 {
108     char pkgName[] = "test";
109     char networkId[] = "222";
110     OnLeaveMetaNodeResult cb = nullptr;
111     g_busCenterClient.isInit = false;
112     int32_t ret = LeaveMetaNodeInner(pkgName, networkId, cb);
113     EXPECT_TRUE(ret == SOFTBUS_NO_INIT);
114     g_busCenterClient.isInit = true;
115     ret = LeaveMetaNodeInner(pkgName, networkId, cb);
116     EXPECT_TRUE(ret == SOFTBUS_IPC_ERR);
117 }
118 
119 /*
120 * @tc.name: LEAVE_META_NODE_INNER
121 * @tc.desc: LEAVE_META_NODE_INNER test
122 * @tc.type: FUNC
123 * @tc.require: AR000FN5VC
124 */
125 HWTEST_F(ClientBusMangerTest, META_NODE_ON_JOIN_Test_001, TestSize.Level1)
126 {
127     g_busCenterClient.isInit = false;
128     void *addr = nullptr;
129     char networkId[] = "3333";
130     int32_t retCod = 111;
131     int32_t ret = MetaNodeOnJoinResult(addr, networkId, retCod);
132     EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
133     g_busCenterClient.isInit = true;
134     ConnectionAddr connAddr;
135     (void)memset_s(&connAddr, sizeof(ConnectionAddr), 0, sizeof(ConnectionAddr));
136     addr = (void*)&connAddr;
137     ret = MetaNodeOnJoinResult(addr, networkId, retCod);
138     EXPECT_TRUE(ret == SOFTBUS_OK);
139 }
140 
141 /*
142 * @tc.name: META_NODE_ON_LEAVE
143 * @tc.desc: LEAVE_META_NODE_INNER test
144 * @tc.type: FUNC
145 * @tc.require: AR000FN5VC
146 */
147 HWTEST_F(ClientBusMangerTest, META_NODE_ON_LEAVE_Test_001, TestSize.Level1)
148 {
149     g_busCenterClient.isInit = false;
150     char networkId[] = "3333";
151     int32_t retCod = 111;
152     int32_t ret = MetaNodeOnLeaveResult(networkId, retCod);
153     EXPECT_TRUE(ret == SOFTBUS_ERR);
154     g_busCenterClient.isInit = true;
155     ret = MetaNodeOnLeaveResult(networkId, retCod);
156     EXPECT_TRUE(ret == SOFTBUS_OK);
157 }
158 }