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_LEAVE_LNN_TEST_001
78 * @tc.desc: server ipc leave lnn test
79 * @tc.type: FUNC
80 * @tc.require:
81 */
82 HWTEST_F(BusCenterServerTest, SERVER_IPC_LEAVE_LNN_TEST_001, TestSize.Level1)
83 {
84 const char *pkgName = "000";
85 const char *networkId = "1234";
86
87 int32_t ret = ServerIpcLeaveLNN(pkgName, networkId);
88 EXPECT_TRUE(ret == SOFTBUS_OK);
89 }
90
91 /*
92 * @tc.name: SERVER_IPC_STOP_TIME_SYNC_TEST_001
93 * @tc.desc: server ipc stop time sync test
94 * @tc.type: FUNC
95 * @tc.require:
96 */
97 HWTEST_F(BusCenterServerTest, SERVER_IPC_STOP_TIME_SYNC_TEST_001, TestSize.Level1)
98 {
99 const char *pkgName = "000";
100 const char *targetNetworkId = "1234";
101
102 int32_t ret = ServerIpcStartTimeSync(pkgName, targetNetworkId, NORMAL_ACCURACY, BIT_NETWORK_TYPE_WIFI);
103 EXPECT_TRUE(ret != SOFTBUS_ERR);
104 ret = ServerIpcStopTimeSync(pkgName, targetNetworkId);
105 EXPECT_TRUE(ret != SOFTBUS_OK);
106 }
107
108 /*
109 * @tc.name: SERVER_IPC_ACTIVE_META_NODE_TEST_001
110 * @tc.desc: server ipc active meta node test
111 * @tc.type: FUNC
112 * @tc.require:
113 */
114 HWTEST_F(BusCenterServerTest, SERVER_IPC_ACTIVE_META_NODE_TEST_001, TestSize.Level1)
115 {
116 const char *pkgName = "000";
117 char udid[] = "123456789987654321001234567899876543210012345678998765432100123";
118 MetaNodeConfigInfo info;
119 char metaNodeId[NETWORK_ID_BUF_LEN] = {0};
120
121 (void)memset_s(&info, sizeof(MetaNodeConfigInfo), 0, sizeof(MetaNodeConfigInfo));
122 info.addrNum = 1;
123 EXPECT_TRUE(strncpy_s(info.udid, UDID_BUF_LEN, udid, UDID_BUF_LEN) == EOK);
124 int32_t ret = ServerIpcActiveMetaNode(pkgName, &info, metaNodeId);
125 EXPECT_TRUE(ret == SOFTBUS_OK);
126 }
127
128 /*
129 * @tc.name: SERVER_IPC_DEACTIVE_META_NODE_TEST_001
130 * @tc.desc: server ipc deactive meta node test
131 * @tc.type: FUNC
132 * @tc.require:
133 */
134 HWTEST_F(BusCenterServerTest, SERVER_IPC_DEACTIVE_META_NODE_TEST_001, TestSize.Level1)
135 {
136 const char *pkgName = "000";
137 char metaNodeId[NETWORK_ID_BUF_LEN] = {0};
138
139 int32_t ret = ServerIpcDeactiveMetaNode(pkgName, metaNodeId);
140 EXPECT_TRUE(ret == SOFTBUS_OK);
141 }
142
143 /*
144 * @tc.name: SERVER_IPC_GET_ALL_META_NODE_INFO_TEST_001
145 * @tc.desc: server ipc get all meta node info test
146 * @tc.type: FUNC
147 * @tc.require:
148 */
149 HWTEST_F(BusCenterServerTest, SERVER_IPC_GET_ALL_META_NODE_INFO_TEST_001, TestSize.Level1)
150 {
151 const char *pkgName = "000";
152 MetaNodeInfo infos;
153 int32_t infoNum = 1;
154
155 (void)memset_s(&infos, sizeof(MetaNodeInfo), 0, sizeof(MetaNodeInfo));
156 int32_t ret = ServerIpcGetAllMetaNodeInfo(pkgName, &infos, &infoNum);
157 EXPECT_TRUE(ret == SOFTBUS_OK);
158 }
159
160 /*
161 * @tc.name: SERVER_IPC_SHIFT_LNN_GEAR_TEST_001
162 * @tc.desc: server ipc shift lnn gear test
163 * @tc.type: FUNC
164 * @tc.require:
165 */
166 HWTEST_F(BusCenterServerTest, SERVER_IPC_SHIFT_LNN_GEAR_TEST_001, TestSize.Level1)
167 {
168 const char *pkgName = "000";
169 const char *callerId = "1234";
170 const char *targetNetworkId = nullptr;
171 GearMode mode = {
172 .cycle = MID_FREQ_CYCLE,
173 .duration = DEFAULT_DURATION,
174 .wakeupFlag = false,
175 };
176
177 int32_t ret = ServerIpcShiftLNNGear(pkgName, callerId, targetNetworkId, &mode);
178 EXPECT_TRUE(ret != SOFTBUS_INVALID_PARAM);
179 }
180 } // namespace OHOS
181