• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 <securec.h>
18 
19 #include "bus_center_server_proxy.h"
20 #include "softbus_access_token_test.h"
21 #include "softbus_bus_center.h"
22 #include "softbus_common.h"
23 #include "softbus_errcode.h"
24 #include "softbus_utils.h"
25 
26 namespace OHOS {
27 using namespace testing::ext;
28 constexpr char BR_MAC[BT_MAC_LEN] = "01:02:03:04:05:06";
29 
30 class BusCenterServerTest : public testing::Test {
31 public:
32     static void SetUpTestCase();
33     static void TearDownTestCase();
34     void SetUp();
35     void TearDown();
36 };
37 
SetUpTestCase()38 void BusCenterServerTest::SetUpTestCase()
39 {
40     SetAceessTokenPermission("busCenterTest");
41     int32_t ret = BusCenterServerProxyInit();
42     EXPECT_TRUE(ret == SOFTBUS_OK);
43 }
44 
TearDownTestCase()45 void BusCenterServerTest::TearDownTestCase()
46 {
47 }
48 
SetUp()49 void BusCenterServerTest::SetUp()
50 {
51 }
52 
TearDown()53 void BusCenterServerTest::TearDown()
54 {
55 }
56 
57 /*
58 * @tc.name: SERVER_IPC_JOIN_LNN_TEST_001
59 * @tc.desc: server ipc join lnn test
60 * @tc.type: FUNC
61 * @tc.require:
62 */
63 HWTEST_F(BusCenterServerTest, SERVER_IPC_JOIN_LNN_TEST_001, TestSize.Level1)
64 {
65     const char *pkgName = "000";
66     ConnectionAddr addr  = {
67         .type = CONNECTION_ADDR_BR,
68         .peerUid = "001"
69     };
70 
71     EXPECT_TRUE(strncpy_s(addr.info.br.brMac, BT_MAC_LEN, BR_MAC, BT_MAC_LEN) == EOK);
72     int32_t ret = ServerIpcJoinLNN(pkgName, static_cast<void *>(&addr), sizeof(ConnectionAddr));
73     EXPECT_TRUE(ret != SOFTBUS_ERR);
74 }
75 
76 /*
77 * @tc.name: SERVER_IPC_JOIN_META_NODE_TEST_001
78 * @tc.desc: server ipc join meta node test
79 * @tc.type: FUNC
80 * @tc.require:
81 */
82 HWTEST_F(BusCenterServerTest, SERVER_IPC_JOIN_META_NODE_TEST_001, TestSize.Level1)
83 {
84     const char *pkgName = "000";
85     CustomData customData;
86     ConnectionAddr addr  = {
87         .type = CONNECTION_ADDR_BR,
88         .peerUid = "001"
89     };
90 
91     EXPECT_TRUE(strncpy_s(addr.info.br.brMac, BT_MAC_LEN, BR_MAC, BT_MAC_LEN) == EOK);
92     (void)memset_s(&customData, sizeof(CustomData), 0, sizeof(CustomData));
93     int32_t ret = ServerIpcJoinMetaNode(pkgName, static_cast<void *>(&addr), &customData, sizeof(ConnectionAddr));
94     EXPECT_TRUE(ret != SOFTBUS_ERR);
95 }
96 
97 /*
98 * @tc.name: SERVER_IPC_LEAVE_LNN_TEST_001
99 * @tc.desc: server ipc leave lnn test
100 * @tc.type: FUNC
101 * @tc.require:
102 */
103 HWTEST_F(BusCenterServerTest, SERVER_IPC_LEAVE_LNN_TEST_001, TestSize.Level1)
104 {
105     const char *pkgName = "000";
106     const char *networkId = "1234";
107 
108     int32_t ret = ServerIpcLeaveLNN(pkgName, networkId);
109     EXPECT_TRUE(ret == SOFTBUS_OK);
110 }
111 
112 /*
113 * @tc.name: SERVER_IPC_LEAVE_META_NODE_TEST_001
114 * @tc.desc: server ipc leave meta node test
115 * @tc.type: FUNC
116 * @tc.require:
117 */
118 HWTEST_F(BusCenterServerTest, SERVER_IPC_LEAVE_META_NODE_TEST_001, TestSize.Level1)
119 {
120     const char *pkgName = "000";
121     const char *networkId = "1234";
122 
123     int32_t ret = ServerIpcLeaveMetaNode(pkgName, networkId);
124     EXPECT_TRUE(ret == SOFTBUS_OK);
125 }
126 
127 /*
128 * @tc.name: SERVER_IPC_STOP_TIME_SYNC_TEST_001
129 * @tc.desc: server ipc stop time sync test
130 * @tc.type: FUNC
131 * @tc.require:
132 */
133 HWTEST_F(BusCenterServerTest, SERVER_IPC_STOP_TIME_SYNC_TEST_001, TestSize.Level1)
134 {
135     const char *pkgName = "000";
136     const char *targetNetworkId = "1234";
137 
138     int32_t ret = ServerIpcStartTimeSync(pkgName, targetNetworkId, NORMAL_ACCURACY, BIT_NETWORK_TYPE_WIFI);
139     EXPECT_TRUE(ret != SOFTBUS_ERR);
140     ret = ServerIpcStopTimeSync(pkgName, targetNetworkId);
141     EXPECT_TRUE(ret == SOFTBUS_OK);
142 }
143 
144 /*
145 * @tc.name: SERVER_IPC_ACTIVE_META_NODE_TEST_001
146 * @tc.desc: server ipc active meta node test
147 * @tc.type: FUNC
148 * @tc.require:
149 */
150 HWTEST_F(BusCenterServerTest, SERVER_IPC_ACTIVE_META_NODE_TEST_001, TestSize.Level1)
151 {
152     const char *pkgName = "000";
153     char udid[] = "123456789987654321001234567899876543210012345678998765432100123";
154     MetaNodeConfigInfo info;
155     char metaNodeId[NETWORK_ID_BUF_LEN] = {0};
156 
157     (void)memset_s(&info, sizeof(MetaNodeConfigInfo), 0, sizeof(MetaNodeConfigInfo));
158     info.addrNum = 1;
159     EXPECT_TRUE(strncpy_s(info.udid, UDID_BUF_LEN, udid, UDID_BUF_LEN) == EOK);
160     int32_t ret = ServerIpcActiveMetaNode(pkgName, &info, metaNodeId);
161     EXPECT_TRUE(ret == SOFTBUS_OK);
162 }
163 
164 /*
165 * @tc.name: SERVER_IPC_DEACTIVE_META_NODE_TEST_001
166 * @tc.desc: server ipc deactive meta node test
167 * @tc.type: FUNC
168 * @tc.require:
169 */
170 HWTEST_F(BusCenterServerTest, SERVER_IPC_DEACTIVE_META_NODE_TEST_001, TestSize.Level1)
171 {
172     const char *pkgName = "000";
173     char metaNodeId[NETWORK_ID_BUF_LEN] = {0};
174 
175     int32_t ret = ServerIpcDeactiveMetaNode(pkgName, metaNodeId);
176     EXPECT_TRUE(ret == SOFTBUS_OK);
177 }
178 
179 /*
180 * @tc.name: SERVER_IPC_GET_ALL_META_NODE_INFO_TEST_001
181 * @tc.desc: server ipc get all meta node info test
182 * @tc.type: FUNC
183 * @tc.require:
184 */
185 HWTEST_F(BusCenterServerTest, SERVER_IPC_GET_ALL_META_NODE_INFO_TEST_001, TestSize.Level1)
186 {
187     const char *pkgName = "000";
188     MetaNodeInfo infos;
189     int32_t infoNum = 1;
190 
191     (void)memset_s(&infos, sizeof(MetaNodeInfo), 0, sizeof(MetaNodeInfo));
192     int32_t ret = ServerIpcGetAllMetaNodeInfo(pkgName, &infos, &infoNum);
193     EXPECT_TRUE(ret == SOFTBUS_OK);
194 }
195 
196 /*
197 * @tc.name: SERVER_IPC_SHIFT_LNN_GEAR_TEST_001
198 * @tc.desc: server ipc shift lnn gear test
199 * @tc.type: FUNC
200 * @tc.require:
201 */
202 HWTEST_F(BusCenterServerTest, SERVER_IPC_SHIFT_LNN_GEAR_TEST_001, TestSize.Level1)
203 {
204     const char *pkgName = "000";
205     const char *callerId = "1234";
206     const char *targetNetworkId = nullptr;
207     GearMode mode = {
208         .cycle = MID_FREQ_CYCLE,
209         .duration = DEFAULT_DURATION,
210         .wakeupFlag = false,
211     };
212 
213     int32_t ret = ServerIpcShiftLNNGear(pkgName, callerId, targetNetworkId, &mode);
214     EXPECT_TRUE(ret == SOFTBUS_OK);
215 }
216 } // namespace OHOS
217