1 /*
2 * Copyright (c) 2022-2024 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 "UTTest_ipc_server_stub.h"
17
18 #include <algorithm>
19 #include <thread>
20 #include <unistd.h>
21
22 #include "device_manager_ipc_interface_code.h"
23 #include "device_manager_service.h"
24 #include "dm_device_info.h"
25 #include "ipc_remote_broker.h"
26 #include "ipc_server_stub.h"
27 #include "device_manager_impl.h"
28 #include "dm_constants.h"
29 #include "if_system_ability_manager.h"
30 #include "ipc_cmd_register.h"
31 #include "ipc_skeleton.h"
32 #include "ipc_types.h"
33 #include "iservice_registry.h"
34 #include "string_ex.h"
35 #include "system_ability_definition.h"
36
37 namespace OHOS {
38 namespace DistributedHardware {
SetUp()39 void IpcServerStubTest::SetUp()
40 {
41 }
42
TearDown()43 void IpcServerStubTest::TearDown()
44 {
45 }
46
SetUpTestCase()47 void IpcServerStubTest::SetUpTestCase()
48 {
49 }
50
TearDownTestCase()51 void IpcServerStubTest::TearDownTestCase()
52 {
53 }
54
55 namespace {
56 /**
57 * @tc.name: OnStop_001
58 * @tc.desc: 1. Call IpcServerStub OnStop
59 * 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING
60 * @tc.type: FUNC
61 * @tc.require: AR000GHSJK
62 */
63 HWTEST_F(IpcServerStubTest, OnStop_001, testing::ext::TestSize.Level0)
64 {
65 // 1. Call IpcServerStub OnStop
66 IpcServerStub::GetInstance().OnStop();
67 // 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING
68 ASSERT_EQ(ServiceRunningState::STATE_NOT_START, IpcServerStub::GetInstance().state_);
69 ASSERT_EQ(IpcServerStub::GetInstance().registerToService_, false);
70 }
71
72 /**
73 * @tc.name: OnStart_001
74 * @tc.desc: 1. set IpcServerStub state is ServiceRunningState::STATE_RUNNING
75 * 2. Call IpcServerStub OnStart
76 * 3. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING
77 * @tc.type: FUNC
78 * @tc.require: AR000GHSJK
79 */
80 HWTEST_F(IpcServerStubTest, OnStart_001, testing::ext::TestSize.Level0)
81 {
82 // 1. set IpcServerStub state is ServiceRunningState::STATE_RUNNING
83 IpcServerStub::GetInstance().state_ = ServiceRunningState::STATE_RUNNING;
84 // 2. Call IpcServerStub OnStart
85 IpcServerStub::GetInstance().OnStart();
86 // 3. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING
87 ASSERT_EQ(ServiceRunningState::STATE_RUNNING, IpcServerStub::GetInstance().state_);
88 }
89
90 /**
91 * @tc.name: Init_001
92 * @tc.desc: 1. Call IpcServerStub OnStart
93 * 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING
94 * @tc.type: FUNC
95 * @tc.require: AR000GHSJK
96 */
97 HWTEST_F(IpcServerStubTest, Init_001, testing::ext::TestSize.Level0)
98 {
99 IpcServerStub::GetInstance().registerToService_=true;
100 bool result = IpcServerStub::GetInstance().Init();
101 // 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING
102 ASSERT_EQ(result, true);
103 }
104
105 /**
106 * @tc.name: OnRemoteRequest_001
107 * @tc.desc: 1. Set Code = 999
108 * 2. Call IpcServerStub OnRemoteRequest with param
109 * 3. check ret not DM_OK
110 * @tc.type: FUNC
111 * @tc.require: AR000GHSJK
112 */
113 HWTEST_F(IpcServerStubTest, OnRemoteRequest_001, testing::ext::TestSize.Level0)
114 {
115 // 1. Set Code = 999
116 uint32_t code = 999;
117 MessageParcel data;
118 MessageParcel reply;
119 MessageOption option;
120 int ret = 0;
121 // 2. Call IpcServerStub OnRemoteRequest with param
122 ret = IpcServerStub::GetInstance().OnRemoteRequest(code, data, reply, option);
123 // 3. check ret not DM_OK
124 ASSERT_NE(ret, DM_OK);
125 }
126
127 /**
128 * @tc.name: OnRemoteRequest_002
129 * @tc.desc: 1. Set Code = 999
130 * 2. Call IpcServerStub OnRemoteRequest with param
131 * 3. check ret not DM_OK
132 * @tc.type: FUNC
133 * @tc.require: AR000GHSJK
134 */
135 HWTEST_F(IpcServerStubTest, OnRemoteRequest_002, testing::ext::TestSize.Level0)
136 {
137 // 1. Set Code is SERVER_DEVICE_STATE_NOTIFY
138 uint32_t code = SERVER_DEVICE_STATE_NOTIFY;
139 MessageParcel data;
140 MessageParcel reply;
141 MessageOption option;
142 int ret = 0;
143 // 2. Call IpcServerStub OnRemoteRequest with param
144 ret = IpcServerStub::GetInstance().OnRemoteRequest(code, data, reply, option);
145 // 3. check ret not ERR_DM_IPC_READ_FAILED
146 ASSERT_EQ(ret, ERR_DM_IPC_READ_FAILED);
147 }
148
149 /**
150 * @tc.name: SendCmd_001
151 * @tc.desc: 1. Call IpcServerStub SendCmd
152 * 2. check ret is DM_OK
153 * @tc.type: FUNC
154 * @tc.require: AR000GHSJK
155 */
156 HWTEST_F(IpcServerStubTest, SendCmd_001, testing::ext::TestSize.Level0)
157 {
158 int result = 305;
159 int32_t cmdCode = -1;
160 std::shared_ptr<IpcReq> req = std::make_shared<IpcReq>();
161 std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
162 // 1. Call IpcServerStub SendCmd
163 int32_t ret = IpcServerStub::GetInstance().SendCmd(cmdCode, req, rsp);
164 // 2. check ret is DM_OK
165 ASSERT_EQ(ret, result);
166 }
167
168 /**
169 * @tc.name: SendCmd_002
170 * @tc.desc: 1. Call IpcServerStub SendCmd
171 * 2. check ret is ERR_DM_INPUT_PARA_INVALID
172 * @tc.type: FUNC
173 * @tc.require: AR000GHSJK
174 */
175 HWTEST_F(IpcServerStubTest, SendCmd_002, testing::ext::TestSize.Level0)
176 {
177 int result = 305;
178 int32_t cmdCode = IPC_MSG_BUTT;
179 std::shared_ptr<IpcReq> req = std::make_shared<IpcReq>();
180 std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
181 // 1. Call IpcServerStub SendCmd
182 int32_t ret = IpcServerStub::GetInstance().SendCmd(cmdCode, req, rsp);
183 // 2. check ret is DM_OK
184 ASSERT_EQ(ret, result);
185 }
186
187 /**
188 * @tc.name: QueryServiceState_001
189 * @tc.desc: 1. Call IpcServerStub QueryServiceState
190 * 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING
191 * @tc.type: FUNC
192 * @tc.require: AR000GHSJK
193 */
194 HWTEST_F(IpcServerStubTest, QueryServiceState_001, testing::ext::TestSize.Level0)
195 {
196 IpcServerStub::GetInstance().state_ = ServiceRunningState::STATE_NOT_START;
197 // 1. Call IpcServerStub QueryServiceState
198 ServiceRunningState state = IpcServerStub::GetInstance().QueryServiceState();
199 // 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING
200 ASSERT_EQ(state, ServiceRunningState::STATE_NOT_START);
201 }
202
203 /**
204 * @tc.name: RegisterDeviceManagerListener_001
205 * @tc.desc: 1. Call IpcServerStub RegisterDeviceManagerListener
206 * 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING
207 * @tc.type: FUNC
208 * @tc.require: AR000GHSJK
209 */
210 HWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_001, testing::ext::TestSize.Level0)
211 {
212 std::string pkgName = "";
213 int ret = 0;
214 sptr<IpcRemoteBroker> listener = nullptr;
215 ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener);
216 ASSERT_EQ(ret, ERR_DM_POINT_NULL);
217 }
218
219 /**
220 * @tc.name: RegisterDeviceManagerListener_002
221 * @tc.desc: 1. Call IpcServerStub RegisterDeviceManagerListener
222 * 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING
223 * @tc.type: FUNC
224 * @tc.require: AR000GHSJK
225 */
226 HWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_002, testing::ext::TestSize.Level0)
227 {
228 std::string pkgName = "com.ohos.test";
229 int ret = 0;
230 sptr<IpcRemoteBroker> listener = sptr<IpcClientStub>(new IpcClientStub());
231 ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener);
232 ASSERT_EQ(ret, DM_OK);
233 }
234
235 /**
236 * @tc.name: RegisterDeviceManagerListener_003
237 * @tc.desc: 1. Call IpcServerStub RegisterDeviceManagerListener
238 * 2. check IpcServerStub.state is ServiceRunningState::STATE_RUNNING
239 * @tc.type: FUNC
240 * @tc.require: AR000GHSJK
241 */
242 HWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_003, testing::ext::TestSize.Level0)
243 {
244 std::string pkgName = "";
245 int ret = 0;
246 sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub());
247 ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener);
248 ASSERT_EQ(ret, ERR_DM_POINT_NULL);
249 }
250
251 /**
252 * @tc.name: RegisterDeviceManagerListener_004
253 * @tc.desc: 1. Set PkgName is com.ohos.test
254 * 2. Call IpcServerStub RegisterDeviceManagerListener with param
255 * 3. check ret is DM_OK
256 * @tc.type: FUNC
257 * @tc.require: AR000GHSJK
258 */
259 HWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_004, testing::ext::TestSize.Level0)
260 {
261 // 1. Set PkgName is com.ohos.test
262 std::string pkgName = "com.ohos.test";
263 int ret = 0;
264 sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub());
265 // 2. Call IpcServerStub RegisterDeviceManagerListener with param
266 ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener);
267 // 3. check ret is DM_OK
268 ASSERT_EQ(ret, DM_OK);
269 }
270
271 /**
272 * @tc.name: RegisterDeviceManagerListener_005
273 * @tc.desc: 1. Set PkgName is com.ohos.test
274 * 2. Call IpcServerStub RegisterDeviceManagerListener with param
275 * 3. check ret is DM_OK
276 * 4. Call IpcServerStub RegisterDeviceManagerListener with same pkgName another listener
277 * 5. check result is DM_OK
278 * @tc.type: FUNC
279 * @tc.require: AR000GHSJK
280 */
281 HWTEST_F(IpcServerStubTest, RegisterDeviceManagerListener_005, testing::ext::TestSize.Level0)
282 {
283 // 1. Set PkgName is com.ohos.test
284 std::string pkgName = "com.ohos.test";
285 int ret = 0;
286 int result = 0;
287 sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub());
288 // 2. Call IpcServerStub RegisterDeviceManagerListener with param
289 ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener);
290 // 3. check ret is DM_OK
291 ASSERT_EQ(ret, DM_OK);
292 sptr<IpcClientStub> listener2 = sptr<IpcClientStub>(new IpcClientStub());
293 // 4. Call IpcServerStub RegisterDeviceManagerListener with same pkgName another listener
294 result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener2);
295 // 5. check result is DM_OK
296 ASSERT_EQ(result, DM_OK);
297 }
298
299 /**
300 * @tc.name: UnRegisterDeviceManagerListener_001
301 * @tc.desc: 1. Call IpcServerStub UnRegisterDeviceManagerListener
302 * 2. check ret is ERR_DM_INPUT_PARA_INVALID
303 * @tc.type: FUNC
304 * @tc.require: AR000GHSJK
305 */
306 HWTEST_F(IpcServerStubTest, UnRegisterDeviceManagerListener_001, testing::ext::TestSize.Level0)
307 {
308 std::string pkgName;
309 int ret = 0;
310 ret = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName);
311 ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
312 }
313
314 /**
315 * @tc.name: UnRegisterDeviceManagerListener_002
316 * @tc.desc: 1. Set PkgName is com.ohos.test
317 * 2. Call IpcServerStub RegisterDeviceManagerListener with param
318 * 3. check ret is DM_OK
319 * 4. Call IpcServerStub UnRegisterDeviceManagerListener
320 * 5. check ret is DM_OK
321 * @tc.type: FUNC
322 * @tc.require: AR000GHSJK
323 */
324 HWTEST_F(IpcServerStubTest, UnRegisterDeviceManagerListener_002, testing::ext::TestSize.Level0)
325 {
326 // 1. Set PkgName is com.ohos.test
327 std::string pkgName = "com.ohos.test";
328 int ret = 0;
329 sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub());
330 // 2. Call IpcServerStub RegisterDeviceManagerListener with param
331 ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener);
332 // 3. check ret is DM_OK
333 ASSERT_EQ(ret, DM_OK);
334 int result = 0;
335 // 4. Call IpcServerStub UnRegisterDeviceManagerListener
336 result = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName);
337 // 5. check ret is DM_OK
338 ASSERT_EQ(result, DM_OK);
339 }
340
341 /**
342 * @tc.name: UnRegisterDeviceManagerListener_003
343 * @tc.desc: 1. Set pkgName is com.ohos.test
344 * 2. Call IpcServerStub UnRegisterDeviceManagerListener
345 * 3. check ret is DM_OK
346 * @tc.type: FUNC
347 * @tc.require: AR000GHSJK
348 */
349 HWTEST_F(IpcServerStubTest, UnRegisterDeviceManagerListener_003, testing::ext::TestSize.Level0)
350 {
351 // 1. Set pkgName is com.ohos.test
352 std::string pkgName = "com.ohos.test";
353 int ret = 0;
354 // 2. Call IpcServerStub UnRegisterDeviceManagerListener
355 ret = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName);
356 // 3. check ret is DM_OK
357 ASSERT_EQ(ret, DM_OK);
358 }
359
360 /**
361 * @tc.name: UnRegisterDeviceManagerListener_004
362 * @tc.desc: 1. Set PkgName is com.ohos.test
363 * 2. Call IpcServerStub RegisterDeviceManagerListener with param
364 * 3. check ret is DM_OK
365 * 4. Call IpcServerStub UnRegisterDeviceManagerListener
366 * 5. check ret is DM_OK
367 * @tc.type: FUNC
368 * @tc.require: AR000GHSJK
369 */
370 HWTEST_F(IpcServerStubTest, UnRegisterDeviceManagerListener_004, testing::ext::TestSize.Level0)
371 {
372 // 1. Set PkgName is com.ohos.test
373 std::string pkgName = "com.ohos.test1";
374 int ret = 0;
375 sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub());
376 // 2. Call IpcServerStub RegisterDeviceManagerListener with param
377 ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener);
378 // 3. check ret is DM_OK
379 ASSERT_EQ(ret, DM_OK);
380 int result = 0;
381 // 4. Call IpcServerStub UnRegisterDeviceManagerListener
382 result = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(pkgName);
383 // 5. check ret is DM_OK
384 ASSERT_EQ(result, DM_OK);
385 sptr<IpcRemoteBroker> dmListener = IpcServerStub::GetInstance().dmListener_[pkgName];
386 ASSERT_EQ(dmListener, nullptr);
387 }
388
389 /**
390 * @tc.name: UnRegisterDeviceManagerListener_005
391 * @tc.desc: 1. Set PkgName is com.ohos.test
392 * 2. Call IpcServerStub RegisterDeviceManagerListener with param
393 * 3. check ret is DM_OK
394 * 4. Call IpcServerStub UnRegisterDeviceManagerListener
395 * 5. check ret is DM_OK
396 * @tc.type: FUNC
397 * @tc.require: AR000GHSJK
398 */
399 HWTEST_F(IpcServerStubTest, UnRegisterDeviceManagerListener_005, testing::ext::TestSize.Level0)
400 {
401 // 1. Set PkgName is com.ohos.test
402 std::string pkgName = "com.ohos.test2";
403 int ret = 0;
404 sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub());
405 // 2. Call IpcServerStub RegisterDeviceManagerListener with param
406 ret = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener);
407 // 3. check ret is DM_OK
408 ASSERT_EQ(ret, DM_OK);
409 int result = 0;
410 // 4. Call IpcServerStub UnRegisterDeviceManagerListener
411 std::string testPkgName = "com.test";
412 result = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(testPkgName);
413 // 5. check ret is DM_OK
414 ASSERT_EQ(result, DM_OK);
415 sptr<IpcRemoteBroker> dmListener = IpcServerStub::GetInstance().dmListener_[pkgName];
416 ASSERT_NE(dmListener, nullptr);
417 }
418
419 /**
420 * @tc.name: GetDmListener_001
421 * @tc.desc: 1. Set pkgName is com.ohos.test
422 * 2. Call IpcServerStub GetDmListener
423 * 3. check ret is DM_OK
424 * @tc.type: FUNC
425 * @tc.require: AR000GHSJK
426 */
427 HWTEST_F(IpcServerStubTest, GetDmListener_001, testing::ext::TestSize.Level0)
428 {
429 // 1. Set pkgName is com.ohos.test
430 std::string pkgName = "com.ohos.test";
431 sptr<IpcRemoteBroker> ret = nullptr;
432 // 2. Call IpcServerStub UnRegisterDeviceManagerListener
433 ret = IpcServerStub::GetInstance().GetDmListener(pkgName);
434 // 3. check ret is DM_OK
435 ASSERT_EQ(ret, nullptr);
436 }
437
438 /**
439 * @tc.name: GetDmListener_002
440 * @tc.desc: 1. Set pkgName is com.ohos.test
441 * 2. Call IpcServerStub GetDmListener
442 * 3. check ret is DM_OK
443 * @tc.type: FUNC
444 * @tc.require: AR000GHSJK
445 */
446 HWTEST_F(IpcServerStubTest, GetDmListener_002, testing::ext::TestSize.Level0)
447 {
448 // 1. Set pkgName is com.ohos.test
449 std::string pkgName = "com.ohos.test";
450 int result = 0;
451 sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub());
452 // 2. Call IpcServerStub RegisterDeviceManagerListener with param
453 result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener);
454 // 3. check ret is DM_OK
455 ASSERT_EQ(result, DM_OK);
456 sptr<IpcRemoteBroker> ret = nullptr;
457 // 2. Call IpcServerStub UnRegisterDeviceManagerListener
458 ret = IpcServerStub::GetInstance().GetDmListener(pkgName);
459 // 3. check ret is DM_OK
460 ASSERT_NE(ret, nullptr);
461 }
462
463 /**
464 * @tc.name: GetDmListener_003
465 * @tc.desc: 1. Set pkgName is com.ohos.test
466 * 2. Call IpcServerStub GetDmListener
467 * 3. check ret is DM_OK
468 * @tc.type: FUNC
469 * @tc.require: AR000GHSJK
470 */
471 HWTEST_F(IpcServerStubTest, GetDmListener_003, testing::ext::TestSize.Level0)
472 {
473 // 1. Set pkgName is com.ohos.test
474 std::string pkgName = "com.ohos.test";
475 int result = 0;
476 sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub());
477 // 2. Call IpcServerStub RegisterDeviceManagerListener with param
478 result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener);
479 // 3. check ret is DM_OK
480 ASSERT_EQ(result, DM_OK);
481 sptr<IpcRemoteBroker> ret = nullptr;
482 // 2. Call IpcServerStub UnRegisterDeviceManagerListener
483 std::string testPkgName = "test";
484 ret = IpcServerStub::GetInstance().GetDmListener(testPkgName);
485 // 3. check ret is DM_OK
486 ASSERT_EQ(ret, nullptr);
487 }
488
489 /**
490 * @tc.name: GetDmListener_004
491 * @tc.desc: 1. Set pkgName is com.ohos.test
492 * 2. Call IpcServerStub GetDmListener
493 * 3. check ret is ERR_DM_POINT_NULL
494 * @tc.type: FUNC
495 * @tc.require: AR000GHSJK
496 */
497 HWTEST_F(IpcServerStubTest, GetDmListener_004, testing::ext::TestSize.Level0)
498 {
499 // 1. Set pkgName is null
500 std::string pkgName = "";
501 int result = 0;
502 sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub());
503 // 2. Call IpcServerStub RegisterDeviceManagerListener with param
504 result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener);
505 // 3. check ret is ERR_DM_POINT_NULL
506 ASSERT_EQ(result, ERR_DM_POINT_NULL);
507 sptr<IpcRemoteBroker> ret = nullptr;
508 // 2. Call IpcServerStub UnRegisterDeviceManagerListener
509 ret = IpcServerStub::GetInstance().GetDmListener(pkgName);
510 // 3. check ret is nullptr
511 ASSERT_EQ(ret, nullptr);
512 }
513
514 /**
515 * @tc.name: GetDmListener_005
516 * @tc.desc: 1. Set pkgName is com.ohos.test
517 * 2. Call IpcServerStub GetDmListener
518 * 3. check ret is ERR_DM_POINT_NULL
519 * @tc.type: FUNC
520 * @tc.require: AR000GHSJK
521 */
522 HWTEST_F(IpcServerStubTest, GetDmListener_005, testing::ext::TestSize.Level0)
523 {
524 // 1. Set pkgName is null
525 std::string pkgName = "com.test.ohos";
526 int result = 0;
527 sptr<IpcClientStub> listener = nullptr;
528 // 2. Call IpcServerStub RegisterDeviceManagerListener with param
529 result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(pkgName, listener);
530 // 3. check ret is ERR_DM_POINT_NULL
531 ASSERT_EQ(result, ERR_DM_POINT_NULL);
532 sptr<IpcRemoteBroker> ret = nullptr;
533 // 2. Call IpcServerStub UnRegisterDeviceManagerListener
534 ret = IpcServerStub::GetInstance().GetDmListener(pkgName);
535 // 3. check ret is nullptr
536 ASSERT_EQ(ret, nullptr);
537 }
538
539 /**
540 * @tc.name: OnRemoveSystemAbility_001
541 * @tc.type: FUNC
542 */
543 HWTEST_F(IpcServerStubTest, OnRemoveSystemAbility_001, testing::ext::TestSize.Level0)
544 {
545 int32_t systemAbilityId = SOFTBUS_SERVER_SA_ID;
546 std::string deviceId;
547 IpcServerStub::GetInstance().OnRemoveSystemAbility(systemAbilityId, deviceId);
548 ASSERT_EQ(DeviceManagerService::GetInstance().softbusListener_, nullptr);
549 }
550
551 /**
552 * @tc.name: OnRemoveSystemAbility_002
553 * @tc.type: FUNC
554 */
555 HWTEST_F(IpcServerStubTest, OnRemoveSystemAbility_002, testing::ext::TestSize.Level0)
556 {
557 int32_t systemAbilityId = 9999;
558 std::string deviceId;
559 IpcServerStub::GetInstance().OnRemoveSystemAbility(systemAbilityId, deviceId);
560 ASSERT_EQ(DeviceManagerService::GetInstance().softbusListener_, nullptr);
561 }
562
563 /**
564 * @tc.name: OnAddSystemAbility_001
565 * @tc.type: FUNC
566 */
567 HWTEST_F(IpcServerStubTest, OnAddSystemAbility_001, testing::ext::TestSize.Level0)
568 {
569 int32_t systemAbilityId = SOFTBUS_SERVER_SA_ID;
570 std::string deviceId;
571 IpcServerStub::GetInstance().OnAddSystemAbility(systemAbilityId, deviceId);
572 ASSERT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr);
573 }
574
575 /**
576 * @tc.name: OnAddSystemAbility_002
577 * @tc.type: FUNC
578 */
579 HWTEST_F(IpcServerStubTest, OnAddSystemAbility_002, testing::ext::TestSize.Level0)
580 {
581 int32_t systemAbilityId = 9999;
582 std::string deviceId;
583 IpcServerStub::GetInstance().OnAddSystemAbility(systemAbilityId, deviceId);
584 ASSERT_NE(DeviceManagerService::GetInstance().softbusListener_, nullptr);
585 }
586
587 /**
588 * @tc.name: GetAllPkgName_001
589 * @tc.type: FUNC
590 */
591 HWTEST_F(IpcServerStubTest, GetAllPkgName_001, testing::ext::TestSize.Level0)
592 {
593 std::vector<std::string> pkgName;
594 pkgName = IpcServerStub::GetInstance().GetAllPkgName();
595 ASSERT_EQ(pkgName.empty(), false);
596 }
597
598 /**
599 * @tc.name: Dump_001
600 * @tc.type: FUNC
601 */
602 HWTEST_F(IpcServerStubTest, Dump_001, testing::ext::TestSize.Level0)
603 {
604 int32_t fd = 0;
605 std::vector<std::u16string> args;
606 int32_t ret = IpcServerStub::GetInstance().Dump(fd, args);
607 ASSERT_NE(ret, DM_OK);
608 }
609 } // namespace
610 } // namespace DistributedHardware
611 } // namespace OHOS
612