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