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_error_code.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 SetAccessTokenPermission("busCenterTest");
41 int32_t ret = BusCenterServerProxyInit();
42 EXPECT_TRUE(ret == SOFTBUS_OK);
43 }
44
TearDownTestCase()45 void BusCenterServerTest::TearDownTestCase() { }
46
SetUp()47 void BusCenterServerTest::SetUp() { }
48
TearDown()49 void BusCenterServerTest::TearDown() { }
50
51 /*
52 * @tc.name: SERVER_IPC_JOIN_LNN_TEST_001
53 * @tc.desc: server ipc join lnn test
54 * @tc.type: FUNC
55 * @tc.require:
56 */
57 HWTEST_F(BusCenterServerTest, SERVER_IPC_JOIN_LNN_TEST_001, TestSize.Level1)
58 {
59 const char *pkgName = "000";
60 ConnectionAddr addr = {
61 .type = CONNECTION_ADDR_BR,
62 .peerUid = "001",
63 };
64
65 EXPECT_TRUE(strncpy_s(addr.info.br.brMac, BT_MAC_LEN, BR_MAC, BT_MAC_LEN) == EOK);
66 int32_t ret = ServerIpcJoinLNN(pkgName, static_cast<void *>(&addr), sizeof(ConnectionAddr), false);
67 EXPECT_NE(ret, SOFTBUS_INVALID_PARAM);
68 }
69
70 /*
71 * @tc.name: SERVER_IPC_LEAVE_LNN_TEST_001
72 * @tc.desc: server ipc leave lnn test
73 * @tc.type: FUNC
74 * @tc.require:
75 */
76 HWTEST_F(BusCenterServerTest, SERVER_IPC_LEAVE_LNN_TEST_001, TestSize.Level1)
77 {
78 const char *pkgName = "000";
79 const char *networkId = "1234";
80
81 int32_t ret = ServerIpcLeaveLNN(pkgName, networkId);
82 EXPECT_TRUE(ret == SOFTBUS_OK);
83 }
84
85 /*
86 * @tc.name: SERVER_IPC_STOP_TIME_SYNC_TEST_001
87 * @tc.desc: server ipc stop time sync test
88 * @tc.type: FUNC
89 * @tc.require:
90 */
91 HWTEST_F(BusCenterServerTest, SERVER_IPC_STOP_TIME_SYNC_TEST_001, TestSize.Level1)
92 {
93 const char *pkgName = "000";
94 const char *targetNetworkId = "1234";
95
96 int32_t ret = ServerIpcStartTimeSync(pkgName, targetNetworkId, NORMAL_ACCURACY, BIT_NETWORK_TYPE_WIFI);
97 EXPECT_NE(ret, SOFTBUS_OK);
98 ret = ServerIpcStopTimeSync(pkgName, targetNetworkId);
99 EXPECT_EQ(ret, SOFTBUS_OK);
100 }
101
102 /*
103 * @tc.name: SERVER_IPC_ACTIVE_META_NODE_TEST_001
104 * @tc.desc: server ipc active meta node test
105 * @tc.type: FUNC
106 * @tc.require:
107 */
108 HWTEST_F(BusCenterServerTest, SERVER_IPC_ACTIVE_META_NODE_TEST_001, TestSize.Level1)
109 {
110 const char *pkgName = "000";
111 char udid[] = "123456789987654321001234567899876543210012345678998765432100123";
112 MetaNodeConfigInfo info;
113 char metaNodeId[NETWORK_ID_BUF_LEN] = { 0 };
114
115 (void)memset_s(&info, sizeof(MetaNodeConfigInfo), 0, sizeof(MetaNodeConfigInfo));
116 info.addrNum = 1;
117 EXPECT_TRUE(strncpy_s(info.udid, UDID_BUF_LEN, udid, UDID_BUF_LEN) == EOK);
118 int32_t ret = ServerIpcActiveMetaNode(pkgName, &info, metaNodeId);
119 EXPECT_TRUE(ret == SOFTBUS_OK);
120 }
121
122 /*
123 * @tc.name: SERVER_IPC_DEACTIVE_META_NODE_TEST_001
124 * @tc.desc: server ipc deactive meta node test
125 * @tc.type: FUNC
126 * @tc.require:
127 */
128 HWTEST_F(BusCenterServerTest, SERVER_IPC_DEACTIVE_META_NODE_TEST_001, TestSize.Level1)
129 {
130 const char *pkgName = "000";
131 char metaNodeId[NETWORK_ID_BUF_LEN] = { 0 };
132
133 int32_t ret = ServerIpcDeactiveMetaNode(pkgName, metaNodeId);
134 EXPECT_TRUE(ret == SOFTBUS_OK);
135 }
136
137 /*
138 * @tc.name: SERVER_IPC_GET_ALL_META_NODE_INFO_TEST_001
139 * @tc.desc: server ipc get all meta node info test
140 * @tc.type: FUNC
141 * @tc.require:
142 */
143 HWTEST_F(BusCenterServerTest, SERVER_IPC_GET_ALL_META_NODE_INFO_TEST_001, TestSize.Level1)
144 {
145 const char *pkgName = "000";
146 MetaNodeInfo infos;
147 int32_t infoNum = 1;
148
149 (void)memset_s(&infos, sizeof(MetaNodeInfo), 0, sizeof(MetaNodeInfo));
150 int32_t ret = ServerIpcGetAllMetaNodeInfo(pkgName, &infos, &infoNum);
151 EXPECT_TRUE(ret == SOFTBUS_OK);
152 }
153
154 /*
155 * @tc.name: SERVER_IPC_SHIFT_LNN_GEAR_TEST_001
156 * @tc.desc: server ipc shift lnn gear test
157 * @tc.type: FUNC
158 * @tc.require:
159 */
160 HWTEST_F(BusCenterServerTest, SERVER_IPC_SHIFT_LNN_GEAR_TEST_001, TestSize.Level1)
161 {
162 const char *pkgName = "000";
163 const char *callerId = "1234";
164 const char *targetNetworkId = nullptr;
165 GearMode mode = {
166 .cycle = MID_FREQ_CYCLE,
167 .duration = DEFAULT_DURATION,
168 .wakeupFlag = false,
169 };
170
171 int32_t ret = ServerIpcShiftLNNGear(pkgName, callerId, targetNetworkId, &mode);
172 EXPECT_EQ(ret, SOFTBUS_OK);
173 }
174 } // namespace OHOS
175