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
16 #include "softbus_adapter_test.h"
17
18 using namespace testing::ext;
19
20 namespace OHOS {
21 namespace DistributedHardware {
SetUpTestCase(void)22 void SoftbusAdapterTest::SetUpTestCase(void) {}
23
TearDownTestCase(void)24 void SoftbusAdapterTest::TearDownTestCase(void) {}
25
SetUp(void)26 void SoftbusAdapterTest::SetUp(void) {}
27
TearDown(void)28 void SoftbusAdapterTest::TearDown(void) {}
29
30 /**
31 * @tc.name: RegisterSoftbusListener_001
32 * @tc.desc: Verify the RegisterSoftbusListener function.
33 * @tc.type: FUNC
34 * @tc.require: Issue Number
35 */
36 HWTEST_F(SoftbusAdapterTest, RegisterSoftbusListener_001, TestSize.Level1)
37 {
38 std::shared_ptr<ISoftbusListener> listener = nullptr;
39 std::string sessionName;
40 std::string peerDevId;
41
42 int32_t actual = softbusAdapter.RegisterSoftbusListener(listener, sessionName, peerDevId);
43
44 EXPECT_EQ(DH_SUCCESS, actual);
45 }
46
47 /**
48 * @tc.name: RegisterSoftbusListener_002
49 * @tc.desc: Verify the RegisterSoftbusListener function.
50 * @tc.type: FUNC
51 * @tc.require: Issue Number
52 */
53 HWTEST_F(SoftbusAdapterTest, RegisterSoftbusListener_002, TestSize.Level1)
54 {
55 std::shared_ptr<ISoftbusListener> listener = nullptr;
56 std::string sessionName = "hello";
57 std::string peerDevId = "world";
58
59 softbusAdapter.mapListeners_["hello_world"] = listener;
60 int32_t actual = softbusAdapter.RegisterSoftbusListener(listener, sessionName, peerDevId);
61
62 EXPECT_EQ(ERR_DH_SCREEN_ADAPTER_REGISTER_SOFTBUS_LISTENER_FAIL, actual);
63 }
64
65 /**
66 * @tc.name: UnRegisterSoftbusListener_001
67 * @tc.desc: Verify the UnRegisterSoftbusListener function.
68 * @tc.type: FUNC
69 * @tc.require: Issue Number
70 */
71 HWTEST_F(SoftbusAdapterTest, UnRegisterSoftbusListener_001, TestSize.Level1)
72 {
73 std::string sessionName = "hello";
74 std::string peerDevId = "world";
75
76 int32_t actual = softbusAdapter.UnRegisterSoftbusListener(sessionName, peerDevId);
77
78 EXPECT_EQ(DH_SUCCESS, actual);
79 }
80
81 /**
82 * @tc.name: CreateSoftbusSessionServer_001
83 * @tc.desc: Verify the CreateSoftbusSessionServer function.
84 * @tc.type: FUNC
85 * @tc.require: Issue Number
86 */
87 HWTEST_F(SoftbusAdapterTest, CreateSoftbusSessionServer_001, TestSize.Level1)
88 {
89 std::string pkgname = "hello";
90 std::string sessionName = "world";
91 std::string peerDevId = "world";
92
93 softbusAdapter.mapSessionSet_[sessionName].insert(peerDevId);
94 int32_t actual = softbusAdapter.CreateSoftbusSessionServer(pkgname, sessionName, peerDevId);
95
96 EXPECT_EQ(DH_SUCCESS, actual);
97 }
98
99 /**
100 * @tc.name: RemoveSoftbusSessionServer_001
101 * @tc.desc: Verify the RemoveSoftbusSessionServer function.
102 * @tc.type: FUNC
103 * @tc.require: Issue Number
104 */
105 HWTEST_F(SoftbusAdapterTest, RemoveSoftbusSessionServer_001, TestSize.Level1)
106 {
107 std::string pkgname = "hello";
108 std::string sessionName = "world";
109 std::string peerDevId = "world";
110
111 int32_t actual = softbusAdapter.RemoveSoftbusSessionServer(pkgname, sessionName, peerDevId);
112
113 EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_OPERATION, actual);
114 }
115
116 /**
117 * @tc.name: RemoveSoftbusSessionServer_002
118 * @tc.desc: Verify the RemoveSoftbusSessionServer function.
119 * @tc.type: FUNC
120 * @tc.require: Issue Number
121 */
122 HWTEST_F(SoftbusAdapterTest, RemoveSoftbusSessionServer_002, TestSize.Level1)
123 {
124 std::string pkgname = "hello";
125 std::string sessionName = "world";
126 std::string peerDevId = "world";
127
128 softbusAdapter.mapSessionSet_[sessionName].insert(peerDevId);
129 int32_t actual = softbusAdapter.RemoveSoftbusSessionServer(pkgname, sessionName, peerDevId);
130
131 EXPECT_EQ(DH_SUCCESS, actual);
132 }
133
134 /**
135 * @tc.name: OpenSoftbusSession_001
136 * @tc.desc: Verify the OpenSoftbusSession function.
137 * @tc.type: FUNC
138 * @tc.require: Issue Number
139 */
140 HWTEST_F(SoftbusAdapterTest, OpenSoftbusSession_001, TestSize.Level1)
141 {
142 std::string mySessionName = DATA_SESSION_NAME;
143 std::string peerSessionName = "world";
144 std::string peerDevId = "world";
145
146 int32_t actual = softbusAdapter.OpenSoftbusSession(mySessionName, peerSessionName, peerDevId);
147
148 EXPECT_EQ(ERR_DH_SCREEN_ADAPTER_OPEN_SESSION_FAIL, actual);
149 }
150
151 /**
152 * @tc.name: OpenSoftbusSession_002
153 * @tc.desc: Verify the OpenSoftbusSession function.
154 * @tc.type: FUNC
155 * @tc.require: Issue Number
156 */
157 HWTEST_F(SoftbusAdapterTest, OpenSoftbusSession_002, TestSize.Level1)
158 {
159 std::string mySessionName = "hello";
160 std::string peerSessionName = "world";
161 std::string peerDevId = "world";
162
163 int32_t actual = softbusAdapter.OpenSoftbusSession(mySessionName, peerSessionName, peerDevId);
164
165 EXPECT_EQ(ERR_DH_SCREEN_ADAPTER_OPEN_SESSION_FAIL, actual);
166 }
167
168 /**
169 * @tc.name: CloseSoftbusSession_001
170 * @tc.desc: Verify the CloseSoftbusSession function.
171 * @tc.type: FUNC
172 * @tc.require: Issue Number
173 */
174 HWTEST_F(SoftbusAdapterTest, CloseSoftbusSession_001, TestSize.Level1)
175 {
176 int32_t sessionId = 0;
177
178 int32_t actual = softbusAdapter.CloseSoftbusSession(sessionId);
179
180 EXPECT_EQ(DH_SUCCESS, actual);
181 }
182
183 /**
184 * @tc.name: SendSoftbusBytes_001
185 * @tc.desc: Verify the SendSoftbusBytes function.
186 * @tc.type: FUNC
187 * @tc.require: Issue Number
188 */
189 HWTEST_F(SoftbusAdapterTest, SendSoftbusBytes_001, TestSize.Level1)
190 {
191 int32_t sessionId = 0;
192 void *data = nullptr;
193 int32_t dataLen = 0;
194
195 int32_t actual = softbusAdapter.SendSoftbusBytes(sessionId, data, dataLen);
196
197 EXPECT_EQ(ERR_DH_SCREEN_TRANS_ERROR, actual);
198 }
199
200 /**
201 * @tc.name: SendSoftbusStream_001
202 * @tc.desc: Verify the SendSoftbusStream function.
203 * @tc.type: FUNC
204 * @tc.require: Issue Number
205 */
206 HWTEST_F(SoftbusAdapterTest, SendSoftbusStream_001, TestSize.Level1)
207 {
208 int32_t sessionId = 0;
209 StreamData *data = nullptr;
210 StreamData *ext = nullptr;
211 StreamFrameInfo *param = nullptr;
212
213 int32_t actual = softbusAdapter.SendSoftbusStream(sessionId, data, ext, param);
214
215 EXPECT_EQ(ERR_DH_SCREEN_TRANS_ERROR, actual);
216 }
217
218 /**
219 * @tc.name: GetSoftbusListener_001
220 * @tc.desc: Verify the GetSoftbusListener function.
221 * @tc.type: FUNC
222 * @tc.require: Issue Number
223 */
224 HWTEST_F(SoftbusAdapterTest, GetSoftbusListener_001, TestSize.Level1)
225 {
226 int32_t sessionId = 0;
227
228 std::shared_ptr<ISoftbusListener> actual = softbusAdapter.GetSoftbusListenerById(sessionId);
229
230 EXPECT_EQ(nullptr, actual);
231 }
232
233 /**
234 * @tc.name: GetSoftbusListener_002
235 * @tc.desc: Verify the GetSoftbusListener function.
236 * @tc.type: FUNC
237 * @tc.require: Issue Number
238 */
239 HWTEST_F(SoftbusAdapterTest, GetSoftbusListener_002, TestSize.Level1)
240 {
241 int32_t sessionId = 0;
242
243 SessionInfo sessionInfo;
244 sessionInfo.sessionName = "hello";
245 sessionInfo.peerDevId = "world";
246 softbusAdapter.mapSessionInfos_[sessionId] = sessionInfo;
247 std::shared_ptr<ISoftbusListener> listener = nullptr;
248 softbusAdapter.mapListeners_["hello_world"] = listener;
249 std::shared_ptr<ISoftbusListener> actual = softbusAdapter.GetSoftbusListenerById(sessionId);
250
251 EXPECT_EQ(nullptr, actual);
252 }
253
254 /**
255 * @tc.name: OnSoftbusSessionOpened_001
256 * @tc.desc: Verify the OnSoftbusSessionOpened function.
257 * @tc.type: FUNC
258 * @tc.require: Issue Number
259 */
260 HWTEST_F(SoftbusAdapterTest, OnSoftbusSessionOpened_001, TestSize.Level1)
261 {
262 int32_t sessionId = 0;
263 int32_t result = 0;
264
265 int32_t actual = softbusAdapter.OnSoftbusSessionOpened(sessionId, result);
266
267 EXPECT_EQ(ERR_DH_SCREEN_TRANS_ERROR, actual);
268 }
269
270 /**
271 * @tc.name: OnSoftbusSessionClosed_001
272 * @tc.desc: Verify the OnSoftbusSessionClosed function.
273 * @tc.type: FUNC
274 * @tc.require: Issue Number
275 */
276 HWTEST_F(SoftbusAdapterTest, OnSoftbusSessionClosed_001, TestSize.Level1)
277 {
278 int32_t sessionId = 0;
279
280 softbusAdapter.OnSoftbusSessionClosed(sessionId);
281 }
282
283 /**
284 * @tc.name: OnSoftbusSessionClosed_002
285 * @tc.desc: Verify the OnSoftbusSessionClosed function.
286 * @tc.type: FUNC
287 * @tc.require: Issue Number
288 */
289 HWTEST_F(SoftbusAdapterTest, OnSoftbusSessionClosed_002, TestSize.Level1)
290 {
291 int32_t sessionId = 0;
292
293 SessionInfo sessionInfo;
294 sessionInfo.sessionName = "hello";
295 sessionInfo.peerDevId = "world";
296 softbusAdapter.mapSessionInfos_[sessionId] = sessionInfo;
297 std::shared_ptr<ISoftbusListener> listener = nullptr;
298 softbusAdapter.mapListeners_["hello_world"] = listener;
299
300 softbusAdapter.OnSoftbusSessionClosed(sessionId);
301 }
302 } // DistributedHardware
303 } // OHOS