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