1 /*
2 * Copyright (c) 2025 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 <gtest/gtest.h>
16
17 #include "general_connection_server_proxy_standard.h"
18 #include "softbus_error_code.h"
19
20 using namespace testing::ext;
21 namespace OHOS {
22 namespace {
23 class ConnectionServerProxyStandardTest : public testing::Test {
24 public:
25 static void SetUpTestCase();
26 static void TearDownTestCase();
27 void SetUp();
28 void TearDown();
29 };
30
SetUpTestCase()31 void ConnectionServerProxyStandardTest::SetUpTestCase() { }
32
TearDownTestCase()33 void ConnectionServerProxyStandardTest::TearDownTestCase() { }
34
SetUp()35 void ConnectionServerProxyStandardTest::SetUp() { }
36
TearDown()37 void ConnectionServerProxyStandardTest::TearDown() { }
38
39 /*
40 * @tc.name: ConnectionServerProxyVirtualTest001
41 * @tc.desc: test ConnectionServerProxy virtual function
42 * @tc.type: FUNC
43 * @tc.require:
44 */
45 HWTEST_F(ConnectionServerProxyStandardTest, ConnectionServerProxyVirtualTest001, TestSize.Level0)
46 {
47 const sptr<IRemoteObject> impl = nullptr;
48 ConnectionServerProxy testProxy(impl);
49 int32_t ret = testProxy.SoftbusRegisterService(nullptr, nullptr);
50 ASSERT_EQ(ret, SOFTBUS_OK);
51 ret = testProxy.CreateSessionServer(nullptr, nullptr, 1);
52 ASSERT_EQ(ret, SOFTBUS_OK);
53 ret = testProxy.RemoveSessionServer(nullptr, nullptr, 1);
54 ASSERT_EQ(ret, SOFTBUS_OK);
55 ret = testProxy.OpenSession(nullptr, nullptr);
56 ASSERT_EQ(ret, SOFTBUS_OK);
57 ret = testProxy.OpenAuthSession(nullptr, nullptr);
58 ASSERT_EQ(ret, SOFTBUS_OK);
59 ret = testProxy.NotifyAuthSuccess(0, 0);
60 ASSERT_EQ(ret, SOFTBUS_OK);
61 ret = testProxy.ReleaseResources(0);
62 ASSERT_EQ(ret, SOFTBUS_OK);
63 ret = testProxy.CloseChannel(nullptr, 0, 0);
64 ASSERT_EQ(ret, SOFTBUS_OK);
65 ret = testProxy.CloseChannelWithStatistics(0, 0, 0, nullptr, 0);
66 ASSERT_EQ(ret, SOFTBUS_OK);
67 ret = testProxy.SendMessage(0, 0, nullptr, 0, 0);
68 ASSERT_EQ(ret, SOFTBUS_OK);
69 ret = testProxy.QosReport(0, 0, 0, 0);
70 ASSERT_EQ(ret, SOFTBUS_OK);
71 ret = testProxy.StreamStats(0, 0, nullptr);
72 ASSERT_EQ(ret, SOFTBUS_OK);
73 ret = testProxy.RippleStats(0, 0, nullptr);
74 ASSERT_EQ(ret, SOFTBUS_OK);
75 ret = testProxy.JoinLNN(nullptr, nullptr, 0, false);
76 ASSERT_EQ(ret, SOFTBUS_OK);
77 ret = testProxy.LeaveLNN(nullptr, nullptr);
78 ASSERT_EQ(ret, SOFTBUS_OK);
79 }
80
81 /*
82 * @tc.name: ConnectionServerProxyVirtualTest002
83 * @tc.desc: test ConnectionServerProxy virtual function
84 * @tc.type: FUNC
85 * @tc.require:
86 */
87 HWTEST_F(ConnectionServerProxyStandardTest, ConnectionServerProxyVirtualTest002, TestSize.Level0)
88 {
89 const sptr<IRemoteObject> impl = nullptr;
90 ConnectionServerProxy testProxy(impl);
91 int32_t ret = testProxy.GetAllOnlineNodeInfo(nullptr, nullptr, 0, nullptr);
92 ASSERT_EQ(ret, SOFTBUS_OK);
93 ret = testProxy.GetLocalDeviceInfo(nullptr, nullptr, 0);
94 ASSERT_EQ(ret, SOFTBUS_OK);
95 ret = testProxy.GetNodeKeyInfo(nullptr, nullptr, 0, nullptr, 0);
96 ASSERT_EQ(ret, SOFTBUS_OK);
97 ret = testProxy.SetNodeDataChangeFlag(nullptr, nullptr, 0);
98 ASSERT_EQ(ret, SOFTBUS_OK);
99 ret = testProxy.RegDataLevelChangeCb(nullptr);
100 ASSERT_EQ(ret, SOFTBUS_OK);
101 ret = testProxy.UnregDataLevelChangeCb(nullptr);
102 ASSERT_EQ(ret, SOFTBUS_OK);
103 ret = testProxy.SetDataLevel(nullptr);
104 ASSERT_EQ(ret, SOFTBUS_OK);
105 ret = testProxy.StartTimeSync(nullptr, nullptr, 0, 0);
106 ASSERT_EQ(ret, SOFTBUS_OK);
107 ret = testProxy.StopTimeSync(nullptr, nullptr);
108 ASSERT_EQ(ret, SOFTBUS_OK);
109 ret = testProxy.EvaluateQos(nullptr, DATA_TYPE_MESSAGE, nullptr, 0);
110 ASSERT_EQ(ret, SOFTBUS_OK);
111 ret = testProxy.ProcessInnerEvent(0, nullptr, 0);
112 ASSERT_EQ(ret, SOFTBUS_OK);
113 ret = testProxy.PrivilegeCloseChannel(0, 0, nullptr);
114 ASSERT_EQ(ret, SOFTBUS_OK);
115 }
116
117 /*
118 * @tc.name: ConnectionServerProxyCreateServerTest
119 * @tc.desc: test ConnectionServerProxy CreateServer function
120 * @tc.type: FUNC
121 * @tc.require:
122 */
123 HWTEST_F(ConnectionServerProxyStandardTest, ConnectionServerProxyCreateServerTest, TestSize.Level0)
124 {
125 const sptr<IRemoteObject> impl = nullptr;
126 ConnectionServerProxy testProxy(impl);
127 int32_t ret = testProxy.CreateServer(nullptr, nullptr);
128 ASSERT_EQ(ret, SOFTBUS_INVALID_PARAM);
129 ret = testProxy.CreateServer("test", "test");
130 ASSERT_NE(ret, SOFTBUS_OK);
131 }
132
133 /*
134 * @tc.name: ConnectionServerProxyRemoveServerTest
135 * @tc.desc: test ConnectionServerProxy RemoveServer function
136 * @tc.type: FUNC
137 * @tc.require:
138 */
139 HWTEST_F(ConnectionServerProxyStandardTest, ConnectionServerProxyRemoveServerTest, TestSize.Level0)
140 {
141 const sptr<IRemoteObject> impl = nullptr;
142 ConnectionServerProxy testProxy(impl);
143 int32_t ret = testProxy.RemoveServer(nullptr, nullptr);
144 ASSERT_EQ(ret, SOFTBUS_INVALID_PARAM);
145 ret = testProxy.RemoveServer("test", "test");
146 ASSERT_NE(ret, SOFTBUS_OK);
147 }
148
149 /*
150 * @tc.name: ConnectionServerProxyConnectTest
151 * @tc.desc: test ConnectionServerProxy Connect function
152 * @tc.type: FUNC
153 * @tc.require:
154 */
155 HWTEST_F(ConnectionServerProxyStandardTest, ConnectionServerProxyConnectTest, TestSize.Level0)
156 {
157 const sptr<IRemoteObject> impl = nullptr;
158 ConnectionServerProxy testProxy(impl);
159 int32_t ret = testProxy.Connect(nullptr, nullptr, nullptr);
160 ASSERT_EQ(ret, SOFTBUS_INVALID_PARAM);
161 ret = testProxy.Connect("test", nullptr, nullptr);
162 ASSERT_EQ(ret, SOFTBUS_INVALID_PARAM);
163 ret = testProxy.Connect("test", "test", nullptr);
164 ASSERT_EQ(ret, SOFTBUS_INVALID_PARAM);
165 Address address;
166 ret = testProxy.Connect("test", "test", &address);
167 ASSERT_NE(ret, SOFTBUS_OK);
168 }
169
170 /*
171 * @tc.name: ConnectionServerProxyDisconnectTest
172 * @tc.desc: test ConnectionServerProxy Disconnect function
173 * @tc.type: FUNC
174 * @tc.require:
175 */
176 HWTEST_F(ConnectionServerProxyStandardTest, ConnectionServerProxyDisconnectTest, TestSize.Level0)
177 {
178 const sptr<IRemoteObject> impl = nullptr;
179 ConnectionServerProxy testProxy(impl);
180 int32_t ret = testProxy.Disconnect(0);
181 ASSERT_NE(ret, SOFTBUS_OK);
182 }
183
184 /*
185 * @tc.name: ConnectionServerProxySendTest
186 * @tc.desc: test ConnectionServerProxy Send function
187 * @tc.type: FUNC
188 * @tc.require:
189 */
190 HWTEST_F(ConnectionServerProxyStandardTest, ConnectionServerProxySendTest, TestSize.Level0)
191 {
192 const sptr<IRemoteObject> impl = nullptr;
193 ConnectionServerProxy testProxy(impl);
194 int32_t ret = testProxy.Send(0, nullptr, 0);
195 ASSERT_EQ(ret, SOFTBUS_INVALID_PARAM);
196 const uint8_t *data = reinterpret_cast<const uint8_t *>("test");
197 uint32_t len = strlen("test");
198 ret = testProxy.Send(0, data, len);
199 ASSERT_NE(ret, SOFTBUS_OK);
200 }
201
202 /*
203 * @tc.name: ConnectionServerProxyConnGetPeerDeviceIdTest
204 * @tc.desc: test ConnectionServerProxy ConnGetPeerDeviceId function
205 * @tc.type: FUNC
206 * @tc.require:
207 */
208 HWTEST_F(ConnectionServerProxyStandardTest, ConnectionServerProxyConnGetPeerDeviceIdTest, TestSize.Level0)
209 {
210 const sptr<IRemoteObject> impl = nullptr;
211 ConnectionServerProxy testProxy(impl);
212 int32_t ret = testProxy.ConnGetPeerDeviceId(0, nullptr, 0);
213 ASSERT_EQ(ret, SOFTBUS_INVALID_PARAM);
214 const uint8_t *deviceId = reinterpret_cast<const uint8_t *>("test");
215 uint32_t len = strlen("test");
216 ret = testProxy.Send(0, deviceId, len);
217 ASSERT_NE(ret, SOFTBUS_OK);
218 }
219 }
220 } // namespace OHOS
221