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 <cstring>
17 #include "securec.h"
18 #define private public
19 #include "dbinder_service.h"
20 #undef private
21 #include "dbinder_remote_listener.h"
22 #include "gtest/gtest.h"
23 #include "rpc_feature_set.h"
24 #include "rpc_log.h"
25 #include "log_tags.h"
26 #include "string_ex.h"
27 #include "session_impl.h"
28
29 using namespace testing::ext;
30 using namespace OHOS;
31 using namespace OHOS::HiviewDFX;
32 using Communication::SoftBus::Session;
33 using Communication::SoftBus::SessionImpl;
34
35 class DBinderServiceUnitTest : public testing::Test {
36 public:
37 static void SetUpTestCase(void);
38 static void TearDownTestCase(void);
39 void SetUp();
40 void TearDown();
41 static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_ID_RPC, "DBinderServiceUnitTest" };
42 };
43
SetUp()44 void DBinderServiceUnitTest::SetUp() {}
45
TearDown()46 void DBinderServiceUnitTest::TearDown() {}
47
SetUpTestCase()48 void DBinderServiceUnitTest::SetUpTestCase() {}
49
TearDownTestCase()50 void DBinderServiceUnitTest::TearDownTestCase() {}
51
52 class TestDeathRecipient : public IRemoteObject::DeathRecipient {
53 public:
TestDeathRecipient()54 TestDeathRecipient() {}
~TestDeathRecipient()55 virtual ~TestDeathRecipient() {}
OnRemoteDied(const wptr<IRemoteObject> & object)56 void OnRemoteDied(const wptr<IRemoteObject>& object) override {}
57 };
58
59 class TestRpcSystemAbilityCallback : public RpcSystemAbilityCallback {
60 public:
GetSystemAbilityFromRemote(int32_t systemAbilityId)61 sptr<IRemoteObject> GetSystemAbilityFromRemote(int32_t systemAbilityId) override
62 {
63 return nullptr;
64 }
65
LoadSystemAbilityFromRemote(const std::string & srcNetworkId,int32_t systemAbilityId)66 bool LoadSystemAbilityFromRemote(const std::string& srcNetworkId, int32_t systemAbilityId) override
67 {
68 return true;
69 }
70 };
71
72 /*
73 * @tc.name: ProcessOnSessionClosed001
74 * @tc.desc: Verify the ProcessOnSessionClosed function
75 * @tc.type: FUNC
76 */
77 HWTEST_F(DBinderServiceUnitTest, ProcessOnSessionClosed001, TestSize.Level1)
78 {
79 sptr<DBinderService> dBinderService;
80 std::shared_ptr<Session> session = nullptr;
81 EXPECT_EQ(dBinderService->ProcessOnSessionClosed(session), false);
82 }
83
84 /**
85 * @tc.name: StartDBinderService001
86 * @tc.desc: Verify the StartDBinderService function
87 * @tc.type: FUNC
88 */
89 HWTEST_F(DBinderServiceUnitTest, StartDBinderService001, TestSize.Level1)
90 {
91 sptr<DBinderService> dBinderService ;
92 std::shared_ptr<RpcSystemAbilityCallback> callbackImpl = nullptr;
93 bool res = dBinderService->StartDBinderService(callbackImpl);
94 EXPECT_EQ(res, false);
95 }
96
97 /**
98 * @tc.name: StartDBinderService002
99 * @tc.desc: Verify the StartDBinderService function
100 * @tc.type: FUNC
101 */
102 HWTEST_F(DBinderServiceUnitTest, StartDBinderService002, TestSize.Level1)
103 {
104 sptr<DBinderService> dBinderService ;
105 std::shared_ptr<RpcSystemAbilityCallback> callbackImpl = nullptr;
106 DBinderService::mainThreadCreated_ = true;
107 bool res = dBinderService->StartDBinderService(callbackImpl);
108 EXPECT_EQ(res, false);
109 }
110
111 /**
112 * @tc.name: ReStartRemoteListener001
113 * @tc.desc: Verify the ReStartRemoteListener function
114 * @tc.type: FUNC
115 */
116 HWTEST_F(DBinderServiceUnitTest, ReStartRemoteListener001, TestSize.Level1)
117 {
118 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
119 dBinderService->remoteListener_ = nullptr;
120 bool res = dBinderService->ReStartRemoteListener();
121 EXPECT_EQ(res, false);
122 }
123
124 /**
125 * @tc.name: StartRemoteListener001
126 * @tc.desc: Verify the StartRemoteListener function
127 * @tc.type: FUNC
128 */
129 HWTEST_F(DBinderServiceUnitTest, StartRemoteListener001, TestSize.Level1)
130 {
131 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
132 dBinderService->remoteListener_ = nullptr;
133 bool res = dBinderService->StartRemoteListener();
134 EXPECT_EQ(res, false);
135 }
136
137 /**
138 * @tc.name: RegisterRemoteProxy001
139 * @tc.desc: Verify the RegisterRemoteProxy function
140 * @tc.type: FUNC
141 */
142 HWTEST_F(DBinderServiceUnitTest, RegisterRemoteProxy001, TestSize.Level1)
143 {
144 sptr<DBinderService> dBinderService ;
145 std::u16string serviceName = std::u16string();
146 sptr<IRemoteObject> binderObject = nullptr;
147 bool res = dBinderService->RegisterRemoteProxy(serviceName, binderObject);
148 EXPECT_EQ(res, false);
149 }
150
151 /**
152 * @tc.name: RegisterRemoteProxy002
153 * @tc.desc: Verify the RegisterRemoteProxy function
154 * @tc.type: FUNC
155 */
156 HWTEST_F(DBinderServiceUnitTest, RegisterRemoteProxy002, TestSize.Level1)
157 {
158 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
159 std::u16string serviceName = std::u16string();
160 int32_t systemAbilityId = 0;
161 EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, systemAbilityId), false);
162 }
163
164 /**
165 * @tc.name: QuerySessionObject001
166 * @tc.desc: Verify the QuerySessionObject function
167 * @tc.type: FUNC
168 */
169 HWTEST_F(DBinderServiceUnitTest, QuerySessionObject001, TestSize.Level1)
170 {
171 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
172 binder_uintptr_t stub = 0;
173 std::shared_ptr<struct SessionInfo> testSession = nullptr;
174 testSession = dBinderService->QuerySessionObject(stub);
175 EXPECT_EQ(testSession, nullptr);
176 }
177
178 /**
179 * @tc.name: AttachDeathRecipient001
180 * @tc.desc: Verify the AttachDeathRecipient function
181 * @tc.type: FUNC
182 */
183 HWTEST_F(DBinderServiceUnitTest, AttachDeathRecipient001, TestSize.Level1)
184 {
185 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
186 sptr<IRemoteObject> object = nullptr;
187 sptr<IRemoteObject::DeathRecipient> deathRecipient = nullptr;
188 bool res = dBinderService->AttachDeathRecipient(object, deathRecipient);
189 EXPECT_TRUE(res);
190 }
191
192 /**
193 * @tc.name: AttachCallbackProxy001
194 * @tc.desc: Verify the AttachCallbackProxy function
195 * @tc.type: FUNC
196 */
197 HWTEST_F(DBinderServiceUnitTest, AttachCallbackProxy001, TestSize.Level1)
198 {
199 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
200 sptr<IRemoteObject> object = nullptr;
201 DBinderServiceStub *dbStub = nullptr;
202 bool res = dBinderService->AttachCallbackProxy(object, dbStub);
203 EXPECT_TRUE(res);
204 }
205
206 /**
207 * @tc.name: DetachProxyObject001
208 * @tc.desc: Verify the DetachProxyObject function
209 * @tc.type: FUNC
210 */
211 HWTEST_F(DBinderServiceUnitTest, DetachProxyObject001, TestSize.Level1)
212 {
213 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
214 binder_uintptr_t binderObject = 0;
215 bool res = dBinderService->DetachProxyObject(binderObject);
216 EXPECT_EQ(res, false);
217 }
218
219 /**
220 * @tc.name: ReGrantPermissionTest001
221 * @tc.desc: Verify the ReGrantPermission function
222 * @tc.type: FUNC
223 */
224 HWTEST_F(DBinderServiceUnitTest, ReGrantPermissionTest001, TestSize.Level1)
225 {
226 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
227 std::string sessionName;
228 EXPECT_EQ(dBinderService->ReGrantPermission(sessionName), false);
229 }
230
231 /**
232 * @tc.name: ReGrantPermissionTest002
233 * @tc.desc: Verify the ReGrantPermission function
234 * @tc.type: FUNC
235 */
236 HWTEST_F(DBinderServiceUnitTest, ReGrantPermissionTest002, TestSize.Level1)
237 {
238 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
239 std::string sessionName("testSession");
240 EXPECT_EQ(dBinderService->ReGrantPermission(sessionName), false);
241 }
242
243 /**
244 * @tc.name: ReGrantPermissionTest003
245 * @tc.desc: Verify the ReGrantPermission function
246 * @tc.type: FUNC
247 */
248 HWTEST_F(DBinderServiceUnitTest, ReGrantPermissionTest003, TestSize.Level1)
249 {
250 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
251 std::string sessionName("000000123_456000000");
252 EXPECT_EQ(dBinderService->ReGrantPermission(sessionName), false);
253 }
254
255 /**
256 * @tc.name: ConvertToSecureDeviceIDTest001
257 * @tc.desc: Verify the ConvertToSecureDeviceID function
258 * @tc.type: FUNC
259 */
260 HWTEST_F(DBinderServiceUnitTest, ConvertToSecureDeviceIDTest001, TestSize.Level1)
261 {
262 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
263 std::string deviceID;
264 EXPECT_EQ(dBinderService->ConvertToSecureDeviceID(deviceID), "****");
265 }
266
267 /**
268 * @tc.name: ConvertToSecureDeviceIDTest002
269 * @tc.desc: Verify the ConvertToSecureDeviceID function
270 * @tc.type: FUNC
271 */
272 HWTEST_F(DBinderServiceUnitTest, ConvertToSecureDeviceIDTest002, TestSize.Level1)
273 {
274 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
275 std::string deviceID("123456");
276 EXPECT_EQ(dBinderService->ConvertToSecureDeviceID(deviceID),
277 deviceID.substr(0, ENCRYPT_LENGTH) + "****" + deviceID.substr(strlen(deviceID.c_str()) - ENCRYPT_LENGTH));
278 }
279
280 /**
281 * @tc.name: GetRemoteTransTypeTest003
282 * @tc.desc: Verify the GetRemoteTransType function
283 * @tc.type: FUNC
284 */
285 HWTEST_F(DBinderServiceUnitTest, GetRemoteTransTypeTest003, TestSize.Level1)
286 {
287 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
288 EXPECT_EQ(dBinderService->GetRemoteTransType(), IRemoteObject::DATABUS_TYPE);
289 }
290
291 /**
292 * @tc.name: StopRemoteListener001
293 * @tc.desc: Verify the StopRemoteListener function
294 * @tc.type: FUNC
295 */
296 HWTEST_F(DBinderServiceUnitTest, StopRemoteListener001, TestSize.Level1)
297 {
298 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
299 std::shared_ptr<DBinderRemoteListener> testListener = std::make_shared<DBinderRemoteListener>(dBinderService);
300 EXPECT_EQ(dBinderService->StartRemoteListener(), false);
301 dBinderService->StopRemoteListener();
302 }
303
304 /**
305 * @tc.name: GetRemoteTransType001
306 * @tc.desc: Verify the GetRemoteTransType function
307 * @tc.type: FUNC
308 */
309 HWTEST_F(DBinderServiceUnitTest, GetRemoteListener001, TestSize.Level1)
310 {
311 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
312 std::shared_ptr<DBinderRemoteListener> testDbinder = nullptr;
313 testDbinder = dBinderService->GetRemoteListener();
314 EXPECT_EQ(testDbinder, nullptr);
315 }
316
317 /**
318 * @tc.name: GetRemoteListener002
319 * @tc.desc: Verify the GetRemoteListener function
320 * @tc.type: FUNC
321 */
322 HWTEST_F(DBinderServiceUnitTest, GetRemoteListener002, TestSize.Level1)
323 {
324 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
325 std::shared_ptr<DBinderRemoteListener> testListener = std::make_shared<DBinderRemoteListener>(dBinderService);
326 EXPECT_EQ(dBinderService->StartRemoteListener(), false);
327 std::shared_ptr<DBinderRemoteListener> testDbinder = nullptr;
328 testDbinder = dBinderService->GetRemoteListener();
329 }
330
331 /**
332 * @tc.name: GetSeqNumber001
333 * @tc.desc: Verify the GetSeqNumber function
334 * @tc.type: FUNC
335 */
336 HWTEST_F(DBinderServiceUnitTest, GetSeqNumber001, TestSize.Level1)
337 {
338 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
339 dBinderService->seqNumber_ = 0;
340 uint32_t ret = dBinderService->GetSeqNumber();
341 EXPECT_EQ(ret, dBinderService->seqNumber_++);
342 }
343
344 /**
345 * @tc.name: IsDeviceIdIllegal001
346 * @tc.desc: Verify the IsDeviceIdIllegal function
347 * @tc.type: FUNC
348 */
349 HWTEST_F(DBinderServiceUnitTest, IsDeviceIdIllegal001, TestSize.Level1)
350 {
351 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
352 std::string deviceID = "";
353 bool res = dBinderService->IsDeviceIdIllegal(deviceID);
354 EXPECT_EQ(res, true);
355 }
356
357 /**
358 * @tc.name: IsDeviceIdIllegal002
359 * @tc.desc: Verify the IsDeviceIdIllegal function
360 * @tc.type: FUNC
361 */
362 HWTEST_F(DBinderServiceUnitTest, IsDeviceIdIllegal002, TestSize.Level1)
363 {
364 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
365 std::string deviceID = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
366 bool res = dBinderService->IsDeviceIdIllegal(deviceID);
367 EXPECT_EQ(res, true);
368 }
369
370 /**
371 * @tc.name: IsDeviceIdIllegal003
372 * @tc.desc: Verify the IsDeviceIdIllegal function
373 * @tc.type: FUNC
374 */
375 HWTEST_F(DBinderServiceUnitTest, IsDeviceIdIllegal003, TestSize.Level1)
376 {
377 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
378 std::string deviceID = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
379 bool res = dBinderService->IsDeviceIdIllegal(deviceID);
380 EXPECT_EQ(res, false);
381 }
382
383 /**
384 * @tc.name: CheckBinderObject001
385 * @tc.desc: Verify the CheckBinderObject function
386 * @tc.type: FUNC
387 */
388 HWTEST_F(DBinderServiceUnitTest, CheckBinderObject001, TestSize.Level1)
389 {
390 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
391 sptr<DBinderServiceStub> stub = nullptr;
392 binder_uintptr_t binderObject = 1564618;
393 bool res = dBinderService->CheckBinderObject(stub, binderObject);
394 EXPECT_EQ(res, false);
395 }
396
397 /**
398 * @tc.name: CheckBinderObject002
399 * @tc.desc: Verify the CheckBinderObject function
400 * @tc.type: FUNC
401 */
402 HWTEST_F(DBinderServiceUnitTest, CheckBinderObject002, TestSize.Level1)
403 {
404 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
405 const std::string serviceName = "abc";
406 const std::string deviceID = "bcd";
407 binder_uintptr_t binderObject = 1564618;
408 sptr<DBinderServiceStub> stub = new DBinderServiceStub(serviceName, deviceID, binderObject);
409
410 bool res = dBinderService->CheckBinderObject(stub, binderObject);
411 EXPECT_EQ(res, true);
412 }
413
414 /**
415 * @tc.name: IsSameStubObject001
416 * @tc.desc: Verify the IsSameStubObject function
417 * @tc.type: FUNC
418 */
419 HWTEST_F(DBinderServiceUnitTest, IsSameStubObject001, TestSize.Level1)
420 {
421 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
422 sptr<DBinderServiceStub> stub = nullptr;
423 std::u16string service = std::u16string();
424 const std::string device = "";
425 bool res = dBinderService->IsSameStubObject(stub, service, device);
426 EXPECT_EQ(res, false);
427 }
428
429 /**
430 * @tc.name: MakeRemoteBinder001
431 * @tc.desc: Verify the MakeRemoteBinder function
432 * @tc.type: FUNC
433 */
434 HWTEST_F(DBinderServiceUnitTest, MakeRemoteBinder001, TestSize.Level1)
435 {
436 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
437 std::u16string serviceName = std::u16string();
438 std::string deviceID = "";
439 binder_uintptr_t binderObject = 12345;
440 uint32_t pid = 0;
441 uint32_t uid = 0;
442 bool res = dBinderService->MakeRemoteBinder(serviceName, deviceID, binderObject, pid, uid);
443 EXPECT_EQ(res, false);
444 }
445
446 /**
447 * @tc.name: SendEntryToRemote001
448 * @tc.desc: Verify the SendEntryToRemote function
449 * @tc.type: FUNC
450 */
451 HWTEST_F(DBinderServiceUnitTest, SendEntryToRemote001, TestSize.Level1)
452 {
453 const std::string serviceName = "testServiceName";
454 const std::string deviceID = "testDeviceID";
455 binder_uintptr_t binderObject = 161561;
456 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
457 sptr<DBinderServiceStub> stub = new DBinderServiceStub(serviceName, deviceID, binderObject);
458 uint32_t seqNumber = 0;
459 uint32_t pid = 0;
460 uint32_t uid = 0;
461 bool res = dBinderService->SendEntryToRemote(stub, seqNumber, pid, uid);
462 EXPECT_EQ(res, false);
463 }
464
465 /**
466 * @tc.name: InvokerRemoteDBinder001
467 * @tc.desc: Verify the InvokerRemoteDBinder function
468 * @tc.type: FUNC
469 */
470 HWTEST_F(DBinderServiceUnitTest, InvokerRemoteDBinder001, TestSize.Level1)
471 {
472 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
473 sptr<DBinderServiceStub> stub = nullptr;
474 uint32_t seqNumber = 0;
475 uint32_t pid = 0;
476 uint32_t uid = 0;
477 bool res = dBinderService->InvokerRemoteDBinder(stub, seqNumber, pid, uid);
478 EXPECT_EQ(res, false);
479 }
480
481 /**
482 * @tc.name: CheckSystemAbilityId001
483 * @tc.desc: Verify the CheckSystemAbilityId function
484 * @tc.type: FUNC
485 */
486 HWTEST_F(DBinderServiceUnitTest, CheckSystemAbilityId001, TestSize.Level1)
487 {
488 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
489 int32_t systemAbilityId = 0x00000002;
490 bool res = dBinderService->CheckSystemAbilityId(systemAbilityId);
491 EXPECT_EQ(res, true);
492 }
493
494 /**
495 * @tc.name: AllocFreeSocketPort001
496 * @tc.desc: Verify the AllocFreeSocketPort function
497 * @tc.type: FUNC
498 */
499 HWTEST_F(DBinderServiceUnitTest, AllocFreeSocketPort001, TestSize.Level1)
500 {
501 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
502 uint16_t ret = dBinderService->AllocFreeSocketPort();
503 EXPECT_EQ(ret, 0);
504 }
505
506 /**
507 * @tc.name: IsSameLoadSaItem001
508 * @tc.desc: Verify the IsSameLoadSaItem function
509 * @tc.type: FUNC
510 */
511 HWTEST_F(DBinderServiceUnitTest, IsSameLoadSaItem001, TestSize.Level1)
512 {
513 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
514 std::string srcNetworkId = "aaaaaaaaaaaaaa";
515 int32_t systemAbilityId = 123;
516 std::shared_ptr<DHandleEntryTxRx> loadSaItem = std::make_shared<DHandleEntryTxRx>();
517 loadSaItem->stubIndex = 123;
518 strcpy_s(loadSaItem->deviceIdInfo.fromDeviceId, DEVICEID_LENGTH, "aaaaaaaaaaaaaa");
519 bool res = dBinderService->IsSameLoadSaItem(srcNetworkId, systemAbilityId, loadSaItem);
520 EXPECT_EQ(res, true);
521 }
522
523 /**
524 * @tc.name: IsSameLoadSaItem002
525 * @tc.desc: Verify the IsSameLoadSaItem function
526 * @tc.type: FUNC
527 */
528 HWTEST_F(DBinderServiceUnitTest, IsSameLoadSaItem002, TestSize.Level1)
529 {
530 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
531 std::string srcNetworkId = "bbbbbbb";
532 int32_t systemAbilityId = 123;
533 std::shared_ptr<DHandleEntryTxRx> loadSaItem = std::make_shared<DHandleEntryTxRx>();
534 loadSaItem->stubIndex = 123;
535 strcpy_s(loadSaItem->deviceIdInfo.fromDeviceId, DEVICEID_LENGTH, "aaaaaaaaaaaaaa");
536 bool res = dBinderService->IsSameLoadSaItem(srcNetworkId, systemAbilityId, loadSaItem);
537 EXPECT_EQ(res, false);
538 }
539
540 /**
541 * @tc.name: IsSameLoadSaItem003
542 * @tc.desc: Verify the IsSameLoadSaItem function
543 * @tc.type: FUNC
544 */
545 HWTEST_F(DBinderServiceUnitTest, IsSameLoadSaItem003, TestSize.Level1)
546 {
547 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
548 std::string srcNetworkId = "aaaaaaaaaaaaaa";
549 int32_t systemAbilityId = 321;
550 std::shared_ptr<DHandleEntryTxRx> loadSaItem = std::make_shared<DHandleEntryTxRx>();
551 loadSaItem->stubIndex = 123;
552 strcpy_s(loadSaItem->deviceIdInfo.fromDeviceId, DEVICEID_LENGTH, "aaaaaaaaaaaaaa");
553 bool res = dBinderService->IsSameLoadSaItem(srcNetworkId, systemAbilityId, loadSaItem);
554 EXPECT_EQ(res, false);
555 }
556
557 /**
558 * @tc.name: OnRemoteInvokerMessage001
559 * @tc.desc: Verify the OnRemoteInvokerMessage function
560 * @tc.type: FUNC
561 */
562 HWTEST_F(DBinderServiceUnitTest, OnRemoteInvokerMessage001, TestSize.Level1)
563 {
564 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
565 struct DHandleEntryTxRx *message = nullptr;
566 bool res = dBinderService->OnRemoteInvokerMessage(message);
567 EXPECT_EQ(res, false);
568 }
569
570 /**
571 * @tc.name: OnRemoteInvokerMessage002
572 * @tc.desc: Verify the OnRemoteInvokerMessage function
573 * @tc.type: FUNC
574 */
575 HWTEST_F(DBinderServiceUnitTest, OnRemoteInvokerMessage002, TestSize.Level1)
576 {
577 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
578 struct DHandleEntryTxRx message;
579 dBinderService->dbinderCallback_ = std::make_shared<TestRpcSystemAbilityCallback>();
580 bool res = dBinderService->OnRemoteInvokerMessage(&message);
581 EXPECT_EQ(res, true);
582 }
583
584 /*
585 **
586 * @tc.name: GetDatabusNameByProxyTest001
587 * @tc.desc: Verify the GetDatabusNameByProxy function
588 * @tc.type: FUNC
589 */
590 HWTEST_F(DBinderServiceUnitTest, GetDatabusNameByProxyTest001, TestSize.Level1)
591 {
592 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
593 IPCObjectProxy* proxy = nullptr;
594 int32_t systemAbilityId = 3010;
595 std::string res = dBinderService->GetDatabusNameByProxy(proxy, systemAbilityId);
596 EXPECT_EQ(res, "");
597 IPCObjectProxy object(16);
598 std::string name("test");
599 EXPECT_EQ(dBinderService->AttachBusNameObject(&object, name), true);
600 res = dBinderService->GetDatabusNameByProxy(&object, systemAbilityId);
601 EXPECT_EQ(res, name);
602 IPCObjectProxy objectProxy(1);
603 res = dBinderService->GetDatabusNameByProxy(&objectProxy, systemAbilityId);
604 EXPECT_EQ(res, objectProxy.GetPidAndUidInfo(systemAbilityId));
605 }
606
607 /**
608 * @tc.name: InvokerRemoteDBinderTest001
609 * @tc.desc: Verify the InvokerRemoteDBinder function
610 * @tc.type: FUNC
611 */
612 HWTEST_F(DBinderServiceUnitTest, InvokerRemoteDBinderTest001, TestSize.Level1)
613 {
614 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
615 sptr<DBinderServiceStub> stub = nullptr;
616 uint32_t seqNumber = 123456;
617 uint32_t pid = 0;
618 uint32_t uid = 0;
619 bool res = dBinderService->InvokerRemoteDBinder(stub, seqNumber, pid, uid);
620 EXPECT_EQ(res, false);
621 std::string serviceName("testServer");
622 std::string deviceID("123456");
623 binder_uintptr_t binderObject = 100;
624 stub = new DBinderServiceStub(serviceName, deviceID, binderObject);
625 res = dBinderService->InvokerRemoteDBinder(stub, seqNumber, pid, uid);
626 EXPECT_EQ(res, false);
627 }
628
629 /**
630 * @tc.name: CreateDatabusNameTest001
631 * @tc.desc: Verify the CreateDatabusName function
632 * @tc.type: FUNC
633 */
634 HWTEST_F(DBinderServiceUnitTest, CreateDatabusNameTest001, TestSize.Level1)
635 {
636 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
637 int pid = 0;
638 int uid = 0;
639 std::string res = dBinderService->CreateDatabusName(pid, uid);
640 EXPECT_EQ(res, "");
641 pid = 10;
642 uid = 10;
643 res = dBinderService->CreateDatabusName(pid, uid);
644 EXPECT_EQ(res, "");
645 }
646
647 /**
648 * @tc.name: FindServicesByDeviceIDTest001
649 * @tc.desc: Verify the FindServicesByDeviceID function
650 * @tc.type: FUNC
651 */
652 HWTEST_F(DBinderServiceUnitTest, FindServicesByDeviceIDTest001, TestSize.Level1)
653 {
654 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
655 std::string serviceName("testServer");
656 std::string deviceID("123456");
657 binder_uintptr_t binderObject = 100;
658 sptr<DBinderServiceStub> dBinderServiceStub = new DBinderServiceStub(serviceName, deviceID, binderObject);
659 dBinderService->DBinderStubRegisted_.push_back(dBinderServiceStub);
660 std::list<std::u16string> serviceNames;
661 serviceNames.push_back(Str8ToStr16(serviceName));
662 EXPECT_EQ(dBinderService->FindServicesByDeviceID(deviceID), serviceNames);
663 }
664
665 /**
666 * @tc.name: NoticeDeviceDieTest001
667 * @tc.desc: Verify the NoticeDeviceDie function
668 * @tc.type: FUNC
669 */
670 HWTEST_F(DBinderServiceUnitTest, NoticeDeviceDieTest001, TestSize.Level1)
671 {
672 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
673 std::string deviceID;
674 EXPECT_EQ(dBinderService->NoticeDeviceDie(deviceID), DBINDER_SERVICE_INVALID_DATA_ERR);
675 }
676
677 /**
678 * @tc.name: NoticeDeviceDieTest002
679 * @tc.desc: Verify the NoticeDeviceDie function
680 * @tc.type: FUNC
681 */
682 HWTEST_F(DBinderServiceUnitTest, NoticeDeviceDieTest002, TestSize.Level1)
683 {
684 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
685 std::string deviceID("123456");
686 EXPECT_EQ(dBinderService->NoticeDeviceDie(deviceID), DBINDER_SERVICE_NOTICE_DIE_ERR);
687 }
688
689 /**
690 * @tc.name: NoticeServiceDieTest001
691 * @tc.desc: Verify the NoticeServiceDie function
692 * @tc.type: FUNC
693 */
694 HWTEST_F(DBinderServiceUnitTest, NoticeServiceDieTest001, TestSize.Level1)
695 {
696 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
697 dBinderService->StartRemoteListener();
698 std::u16string serviceName;
699 std::string deviceID("123456");
700 EXPECT_EQ(dBinderService->NoticeServiceDie(serviceName, deviceID), DBINDER_SERVICE_INVALID_DATA_ERR);
701 }
702
703 /**
704 * @tc.name: NoticeServiceDieInnerTest001
705 * @tc.desc: Verify the NoticeServiceDieInner function
706 * @tc.type: FUNC
707 */
708 HWTEST_F(DBinderServiceUnitTest, NoticeServiceDieInnerTest001, TestSize.Level1)
709 {
710 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
711 dBinderService->StartRemoteListener();
712 std::u16string serviceName;
713 std::string deviceID("123456");
714 EXPECT_EQ(dBinderService->NoticeServiceDieInner(serviceName, deviceID), DBINDER_SERVICE_INVALID_DATA_ERR);
715 }
716
717 /**
718 * @tc.name: NoticeServiceDieInnerTest002
719 * @tc.desc: Verify the NoticeServiceDieInner function
720 * @tc.type: FUNC
721 */
722 HWTEST_F(DBinderServiceUnitTest, NoticeServiceDieInnerTest002, TestSize.Level1)
723 {
724 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
725 dBinderService->StartRemoteListener();
726 std::u16string serviceName(u"test");
727 std::string deviceID("123456");
728 EXPECT_EQ(dBinderService->NoticeServiceDieInner(serviceName, deviceID), ERR_NONE);
729 }
730
731 /**
732 * @tc.name: NoticeServiceDieInnerTest003
733 * @tc.desc: Verify the NoticeServiceDieInner function
734 * @tc.type: FUNC
735 */
736 HWTEST_F(DBinderServiceUnitTest, NoticeServiceDieInnerTest003, TestSize.Level1)
737 {
738 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
739 dBinderService->StartRemoteListener();
740 std::u16string serviceName(u"testServer");
741 std::string deviceID("123456");
742 EXPECT_EQ(dBinderService->NoticeServiceDieInner(serviceName, deviceID), DBINDER_SERVICE_NOTICE_DIE_ERR);
743 }
744
745 /**
746 * @tc.name: ProcessCallbackProxyTest001
747 * @tc.desc: Verify the ProcessCallbackProxy function
748 * @tc.type: FUNC
749 */
750 HWTEST_F(DBinderServiceUnitTest, ProcessCallbackProxyTest001, TestSize.Level1)
751 {
752 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
753 sptr<IRemoteObject> object = new IPCObjectProxy(16);
754 std::string serviceName("testServer");
755 std::string deviceID("123456");
756 binder_uintptr_t binderObject = 100;
757 sptr<DBinderServiceStub> dBinderServiceStub = new DBinderServiceStub(serviceName, deviceID, binderObject);
758 dBinderService->AttachCallbackProxy(object, dBinderServiceStub.GetRefPtr());
759 dBinderService->ProcessCallbackProxy(dBinderServiceStub);
760 EXPECT_EQ(0, 0);
761 }
762
763 /**
764 * @tc.name: NoticeCallbackProxyTest001
765 * @tc.desc: Verify the NoticeCallbackProxy function
766 * @tc.type: FUNC
767 */
768 HWTEST_F(DBinderServiceUnitTest, NoticeCallbackProxyTest001, TestSize.Level1)
769 {
770 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
771 sptr<IRemoteObject> object = new IPCObjectProxy(16);
772 std::string serviceName("testServer");
773 std::string deviceID("123456");
774 binder_uintptr_t binderObject = 100;
775 sptr<DBinderServiceStub> dBinderServiceStub = new DBinderServiceStub(serviceName, deviceID, binderObject);
776 dBinderService->AttachCallbackProxy(object, dBinderServiceStub.GetRefPtr());
777 EXPECT_EQ(dBinderService->NoticeCallbackProxy(dBinderServiceStub), false);
778 }
779
780 /**
781 * @tc.name: DetachCallbackProxyTest001
782 * @tc.desc: Verify the DetachCallbackProxy function
783 * @tc.type: FUNC
784 */
785 HWTEST_F(DBinderServiceUnitTest, DetachCallbackProxyTest001, TestSize.Level1)
786 {
787 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
788 sptr<IRemoteObject> object = new IPCObjectProxy(16);
789 std::string serviceName("test1");
790 std::string deviceID("12345");
791 binder_uintptr_t binderObject = 100;
792 sptr<DBinderServiceStub> dBinderServiceStub = new DBinderServiceStub(serviceName, deviceID, binderObject);
793 dBinderService->AttachCallbackProxy(object, dBinderServiceStub.GetRefPtr());
794 EXPECT_EQ(dBinderService->DetachCallbackProxy(object), true);
795 }
796
797 /**
798 * @tc.name: DetachCallbackProxyTest002
799 * @tc.desc: Verify the DetachCallbackProxy function
800 * @tc.type: FUNC
801 */
802 HWTEST_F(DBinderServiceUnitTest, DetachCallbackProxyTest002, TestSize.Level1)
803 {
804 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
805 sptr<IRemoteObject> object = new IPCObjectProxy(100);
806 EXPECT_EQ(dBinderService->DetachCallbackProxy(object), false);
807 }
808
809 /**
810 * @tc.name: QueryDeathRecipientTest001
811 * @tc.desc: Verify the QueryDeathRecipient function
812 * @tc.type: FUNC
813 */
814 HWTEST_F(DBinderServiceUnitTest, QueryDeathRecipientTest001, TestSize.Level1)
815 {
816 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
817 sptr<IRemoteObject> object = new IPCObjectProxy(20);
818 sptr<IRemoteObject::DeathRecipient> deathRecipient = new TestDeathRecipient();
819 dBinderService->AttachDeathRecipient(object, deathRecipient);
820 EXPECT_EQ(dBinderService->QueryDeathRecipient(object), deathRecipient);
821 }
822
823 /**
824 * @tc.name: QueryDeathRecipientTest002
825 * @tc.desc: Verify the QueryDeathRecipient function
826 * @tc.type: FUNC
827 */
828 HWTEST_F(DBinderServiceUnitTest, QueryDeathRecipientTest002, TestSize.Level1)
829 {
830 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
831 EXPECT_EQ(dBinderService->QueryDeathRecipient(nullptr), nullptr);
832 }
833
834 /**
835 * @tc.name: AttachBusNameObjectTest001
836 * @tc.desc: Verify the AttachBusNameObject function
837 * @tc.type: FUNC
838 */
839 HWTEST_F(DBinderServiceUnitTest, AttachBusNameObjectTest001, TestSize.Level1)
840 {
841 sptr<IPCObjectProxy> object = new IPCObjectProxy(16);
842 std::string name("test");
843 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
844 EXPECT_EQ(dBinderService->AttachBusNameObject(object.GetRefPtr(), name), true);
845 EXPECT_EQ(dBinderService->QueryBusNameObject(object), name);
846 }
847
848 /**
849 * @tc.name: DetachBusNameObjectTest002
850 * @tc.desc: Verify the DetachBusNameObject function
851 * @tc.type: FUNC
852 */
853 HWTEST_F(DBinderServiceUnitTest, DetachBusNameObjectTest002, TestSize.Level1)
854 {
855 std::string name("Test");
856 sptr<IPCObjectProxy> object = new IPCObjectProxy(16);
857 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
858 dBinderService->AttachBusNameObject(object.GetRefPtr(), name);
859 EXPECT_EQ(dBinderService->DetachBusNameObject(object), true);
860 }
861
862 /**
863 * @tc.name: AttachProxyObjectTest001
864 * @tc.desc: Verify the AttachProxyObject function
865 * @tc.type: FUNC
866 */
867 HWTEST_F(DBinderServiceUnitTest, AttachProxyObjectTest001, TestSize.Level1)
868 {
869 std::string name("Test");
870 binder_uintptr_t binderObject = 10;
871 binder_uintptr_t binderObject1 = 11;
872 sptr<IRemoteObject> object = new IPCObjectProxy(16);
873 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
874 EXPECT_EQ(dBinderService->AttachProxyObject(object, binderObject), true);
875 EXPECT_EQ(dBinderService->QueryProxyObject(binderObject), object);
876 EXPECT_EQ(dBinderService->QueryProxyObject(binderObject1), nullptr);
877 }
878
879 /**
880 * @tc.name: AttachProxyObjectTest002
881 * @tc.desc: Verify the AttachProxyObject function
882 * @tc.type: FUNC
883 */
884 HWTEST_F(DBinderServiceUnitTest, AttachProxyObjectTest002, TestSize.Level1)
885 {
886 uint32_t seqNumber = 10;
887 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
888 std::shared_ptr<OHOS::ThreadLockInfo> threadLockInfo = std::make_shared<OHOS::ThreadLockInfo>();
889 dBinderService->AttachThreadLockInfo(seqNumber, "networkId", threadLockInfo);
890 dBinderService->WakeupThreadByStub(seqNumber);
891 EXPECT_TRUE(dBinderService->QueryThreadLockInfo(seqNumber) != nullptr);
892 EXPECT_EQ(dBinderService->QueryThreadLockInfo(seqNumber), threadLockInfo);
893 dBinderService->DetachThreadLockInfo(seqNumber);
894 dBinderService->WakeupThreadByStub(seqNumber);
895 EXPECT_TRUE(dBinderService->QueryThreadLockInfo(seqNumber) == nullptr);
896 }
897
898 /**
899 * @tc.name: MakeSessionByReplyMessageTest001
900 * @tc.desc: Verify the MakeSessionByReplyMessage function
901 * @tc.type: FUNC
902 */
903 HWTEST_F(DBinderServiceUnitTest, MakeSessionByReplyMessageTest001, TestSize.Level1)
904 {
905 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
906 struct DHandleEntryTxRx replyMessage;
907 dBinderService->MakeSessionByReplyMessage(&replyMessage);
908 EXPECT_EQ(dBinderService->HasDBinderStub(replyMessage.binderObject), false);
909 }
910
911 /**
912 * @tc.name: RegisterRemoteProxyTest001
913 * @tc.desc: Verify the RegisterRemoteProxy function
914 * @tc.type: FUNC
915 */
916 HWTEST_F(DBinderServiceUnitTest, RegisterRemoteProxyTest001, TestSize.Level1)
917 {
918 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
919 std::u16string serviceName;
920 int32_t systemAbilityId = 1;
921 EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, systemAbilityId), false);
922 serviceName = u"testServer";
923 systemAbilityId = 0;
924 EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, systemAbilityId), false);
925 systemAbilityId = 1;
926 EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, systemAbilityId), true);
927 }
928
929 /**
930 * @tc.name: RegisterRemoteProxyTest002
931 * @tc.desc: Verify the RegisterRemoteProxy function
932 * @tc.type: FUNC
933 */
934 HWTEST_F(DBinderServiceUnitTest, RegisterRemoteProxyTest002, TestSize.Level1)
935 {
936 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
937 std::u16string serviceName;
938 sptr<IRemoteObject> binderObject = nullptr;
939 EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, binderObject), false);
940 serviceName = u"testServer";
941 EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, binderObject), false);
942 sptr<IRemoteObject> object = new IPCObjectProxy(16);
943 EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, object), true);
944 }
945
946 /**
947 * @tc.name: GetRegisterServiceTest001
948 * @tc.desc: Verify the GetRegisterService function
949 * @tc.type: FUNC
950 */
951 HWTEST_F(DBinderServiceUnitTest, GetRegisterServiceTest001, TestSize.Level1)
952 {
953 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
954 binder_uintptr_t binderObject = 1;
955 EXPECT_EQ(dBinderService->GetRegisterService(binderObject), std::u16string());
956 std::u16string serviceName(u"testServer");
957 dBinderService->RegisterRemoteProxyInner(serviceName, binderObject);
958 EXPECT_EQ(dBinderService->GetRegisterService(binderObject), serviceName);
959 }
960
961 /**
962 * @tc.name: HandleInvokeListenThreadTest001
963 * @tc.desc: Verify the HandleInvokeListenThread function
964 * @tc.type: FUNC
965 */
966 HWTEST_F(DBinderServiceUnitTest, HandleInvokeListenThreadTest001, TestSize.Level1)
967 {
968 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
969 IPCObjectProxy* proxy = nullptr;
970 uint64_t stubIndex = 0;
971 std::string serverSessionName;
972 DHandleEntryTxRx* replyMessage = nullptr;
973 EXPECT_EQ(dBinderService->HandleInvokeListenThread(proxy, stubIndex, serverSessionName, replyMessage), false);
974 stubIndex = 1;
975 EXPECT_EQ(dBinderService->HandleInvokeListenThread(proxy, stubIndex, serverSessionName, replyMessage), false);
976 serverSessionName = "test";
977 DHandleEntryTxRx replyData;
978 EXPECT_EQ(dBinderService->HandleInvokeListenThread(proxy, stubIndex, serverSessionName, &replyData), true);
979 }
980
981 /**
982 * @tc.name: OnRemoteMessageTaskTest001
983 * @tc.desc: Verify the OnRemoteMessageTask function
984 * @tc.type: FUNC
985 */
986 HWTEST_F(DBinderServiceUnitTest, OnRemoteMessageTaskTest001, TestSize.Level1)
987 {
988 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
989 DHandleEntryTxRx* handleEntryTxRx = nullptr;
990 EXPECT_EQ(dBinderService->OnRemoteMessageTask(handleEntryTxRx), false);
991 DHandleEntryTxRx message;
992 message.head.len = 10;
993 message.head.version = 1;
994 message.transType = 0;
995 message.rpcFeatureSet = 1;
996 message.stubIndex = 1;
997 message.seqNumber = 1;
998 message.binderObject = 10;
999 message.deviceIdInfo.afType = 1;
1000 message.deviceIdInfo.reserved = 1;
1001 message.deviceIdInfo.fromDeviceId[0] = 't';
1002 message.deviceIdInfo.toDeviceId[0] = 't';
1003 message.stub = 10;
1004 message.serviceNameLength = 10;
1005 message.serviceName[0] = 't';
1006 message.pid = 100;
1007 message.uid = 100;
1008 dBinderService->dbinderCallback_ = std::make_shared<TestRpcSystemAbilityCallback>();
1009 message.dBinderCode = DBinderCode::MESSAGE_AS_INVOKER;
1010 EXPECT_EQ(dBinderService->OnRemoteMessageTask(&message), true);
1011 message.dBinderCode = DBinderCode::MESSAGE_AS_REPLY;
1012 EXPECT_EQ(dBinderService->OnRemoteMessageTask(&message), true);
1013 message.dBinderCode = DBinderCode::MESSAGE_AS_OBITUARY;
1014 EXPECT_EQ(dBinderService->OnRemoteMessageTask(&message), false);
1015 message.dBinderCode = DBinderCode::MESSAGE_AS_REMOTE_ERROR;
1016 EXPECT_EQ(dBinderService->OnRemoteMessageTask(&message), true);
1017 }
1018
1019 /**
1020 * @tc.name: OnRemoteInvokerDataBusMessageTest001
1021 * @tc.desc: Verify the OnRemoteInvokerDataBusMessage function
1022 * @tc.type: FUNC
1023 */
1024 HWTEST_F(DBinderServiceUnitTest, OnRemoteInvokerDataBusMessageTest001, TestSize.Level1)
1025 {
1026 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1027 IPCObjectProxy* proxy = nullptr;
1028 DHandleEntryTxRx replyMessage;
1029 std::string remoteDeviceId;
1030 int pid = 1;
1031 int uid = 1;
1032 EXPECT_EQ(dBinderService->OnRemoteInvokerDataBusMessage(proxy, &replyMessage, remoteDeviceId, pid, uid), false);
1033 }
1034
1035 /**
1036 * @tc.name: OnRemoteInvokerDataBusMessageTest002
1037 * @tc.desc: Verify the OnRemoteInvokerDataBusMessage function
1038 * @tc.type: FUNC
1039 */
1040 HWTEST_F(DBinderServiceUnitTest, OnRemoteInvokerDataBusMessageTest002, TestSize.Level1)
1041 {
1042 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1043 DHandleEntryTxRx replyMessage;
1044 std::string remoteDeviceId("test");
1045 int pid = 1;
1046 int uid = 1;
1047 IPCObjectProxy objectProxy(1);
1048 EXPECT_EQ(dBinderService->OnRemoteInvokerDataBusMessage(
1049 &objectProxy, &replyMessage, remoteDeviceId, pid, uid), false);
1050 }
1051
1052 /**
1053 * @tc.name: FindDBinderStub001
1054 * @tc.desc: Verify the FindDBinderStub function
1055 * @tc.type: FUNC
1056 */
1057 HWTEST_F(DBinderServiceUnitTest, FindDBinderStub001, TestSize.Level1)
1058 {
1059 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1060 std::u16string service(u"test");
1061 std::string device = "aaa";
1062 binder_uintptr_t binderObject = 100;
1063 sptr<DBinderServiceStub> testDdBinderStub1 = dBinderService->FindOrNewDBinderStub(service, device, binderObject);
1064 sptr<DBinderServiceStub> testDdBinderStub2 = dBinderService->FindOrNewDBinderStub(service, device, binderObject);
1065 EXPECT_EQ(testDdBinderStub1.GetRefPtr(), testDdBinderStub2.GetRefPtr());
1066
1067 sptr<DBinderServiceStub> testDdBinderStub3 = dBinderService->FindDBinderStub(service, device);
1068 EXPECT_EQ(testDdBinderStub1.GetRefPtr(), testDdBinderStub3.GetRefPtr());
1069
1070 std::u16string service1(u"test1");
1071 std::string device1 = "bbb";
1072 EXPECT_EQ(dBinderService->FindDBinderStub(service1, device1), nullptr);
1073
1074 EXPECT_EQ(dBinderService->DeleteDBinderStub(service1, device1), false);
1075 EXPECT_EQ(dBinderService->DeleteDBinderStub(service, device), true);
1076 }
1077
1078 /*
1079 * @tc.name: ProcessOnSessionClosedTest002
1080 * @tc.desc: Verify the ProcessOnSessionClosed function
1081 * @tc.type: FUNC
1082 */
1083 HWTEST_F(DBinderServiceUnitTest, ProcessOnSessionClosedTest002, TestSize.Level1)
1084 {
1085 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1086 std::shared_ptr<Session> session = std::make_shared<SessionImpl>();
1087 session->SetPeerDeviceId("networkId");
1088 std::shared_ptr<OHOS::ThreadLockInfo> threadLockInfo = std::make_shared<OHOS::ThreadLockInfo>();
1089 uint32_t seqNumber = 10;
1090 dBinderService->AttachThreadLockInfo(seqNumber, "networkId", threadLockInfo);
1091 EXPECT_EQ(dBinderService->ProcessOnSessionClosed(session), true);
1092 }
1093
1094 /**
1095 * @tc.name: ReStartRemoteListenerTest002
1096 * @tc.desc: Verify the ReStartRemoteListener function
1097 * @tc.type: FUNC
1098 */
1099 HWTEST_F(DBinderServiceUnitTest, ReStartRemoteListenerTest002, TestSize.Level1)
1100 {
1101 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1102 dBinderService->remoteListener_ = std::make_shared<DBinderRemoteListener>(dBinderService);
1103 bool res = dBinderService->ReStartRemoteListener();
1104 EXPECT_EQ(res, false);
1105 }
1106
1107
1108 /**
1109 * @tc.name: IsSameStubObjectTest002
1110 * @tc.desc: Verify the IsSameStubObject function
1111 * @tc.type: FUNC
1112 */
1113 HWTEST_F(DBinderServiceUnitTest, IsSameStubObjectTest002, TestSize.Level1)
1114 {
1115 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1116 std::string serviceName = "test";
1117 std::string deviceID = "001";
1118 binder_uintptr_t binderObject = 1;
1119 sptr<DBinderServiceStub> stub = new DBinderServiceStub(serviceName, deviceID, binderObject);
1120 std::u16string service(u"test");
1121 bool res = dBinderService->IsSameStubObject(stub, service, deviceID);
1122 EXPECT_EQ(res, true);
1123 }
1124
1125 /**
1126 * @tc.name: MakeRemoteBinder002
1127 * @tc.desc: Verify the MakeRemoteBinder function
1128 * @tc.type: FUNC
1129 */
1130 HWTEST_F(DBinderServiceUnitTest, MakeRemoteBinder002, TestSize.Level1)
1131 {
1132 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1133 std::u16string serviceName;
1134 std::string deviceID("001");
1135 binder_uintptr_t binderObject = 12345;
1136 uint32_t pid = 0;
1137 uint32_t uid = 0;
1138 EXPECT_EQ(dBinderService->MakeRemoteBinder(serviceName, deviceID, binderObject, pid, uid), nullptr);
1139 }
1140
1141 /**
1142 * @tc.name: MakeRemoteBinderTest003
1143 * @tc.desc: Verify the MakeRemoteBinder function
1144 * @tc.type: FUNC
1145 */
1146 HWTEST_F(DBinderServiceUnitTest, MakeRemoteBinderTest003, TestSize.Level1)
1147 {
1148 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1149 std::u16string serviceName;
1150 std::string deviceID("001");
1151 binder_uintptr_t binderObject = 12345;
1152 uint32_t pid = 10;
1153 uint32_t uid = 10;
1154 EXPECT_EQ(dBinderService->MakeRemoteBinder(serviceName, deviceID, binderObject, pid, uid), nullptr);
1155 }
1156
1157 /**
1158 * @tc.name: SendEntryToRemoteTest002
1159 * @tc.desc: Verify the SendEntryToRemote function
1160 * @tc.type: FUNC
1161 */
1162 HWTEST_F(DBinderServiceUnitTest, SendEntryToRemoteTest002, TestSize.Level1)
1163 {
1164 std::string serviceName("testServer");
1165 std::string deviceID;
1166 binder_uintptr_t binderObject = 161561;
1167 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1168 sptr<DBinderServiceStub> stub = new DBinderServiceStub(serviceName, deviceID, binderObject);
1169 uint32_t seqNumber = 0;
1170 uint32_t pid = 0;
1171 uint32_t uid = 0;
1172 bool res = dBinderService->SendEntryToRemote(stub, seqNumber, pid, uid);
1173 EXPECT_EQ(res, false);
1174 }
1175
1176 /**
1177 * @tc.name: PopLoadSaItemTest001
1178 * @tc.desc: Verify the PopLoadSaItem function
1179 * @tc.type: FUNC
1180 */
1181 HWTEST_F(DBinderServiceUnitTest, PopLoadSaItemTest001, TestSize.Level1)
1182 {
1183 sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1184 std::string srcNetworkId;
1185 int32_t systemAbilityId = 1;
1186 EXPECT_EQ(dBinderService->PopLoadSaItem(srcNetworkId, systemAbilityId), nullptr);
1187
1188 srcNetworkId = "t";
1189 DHandleEntryTxRx message;
1190 message.stubIndex = systemAbilityId;
1191 message.deviceIdInfo.fromDeviceId[0] = 't';
1192 dBinderService->dbinderCallback_ = std::make_shared<TestRpcSystemAbilityCallback>();
1193 dBinderService->OnRemoteInvokerMessage(&message);
1194 std::shared_ptr<DHandleEntryTxRx> dHandleEntryTxRx = dBinderService->PopLoadSaItem(srcNetworkId, systemAbilityId);
1195 EXPECT_TRUE(dHandleEntryTxRx != nullptr);
1196 sptr<IRemoteObject> remoteObject = nullptr;
1197 dBinderService->LoadSystemAbilityComplete("test", 2, remoteObject);
1198 dBinderService->LoadSystemAbilityComplete(srcNetworkId, systemAbilityId, remoteObject);
1199 remoteObject = new IPCObjectProxy(1);
1200 dBinderService->LoadSystemAbilityComplete(srcNetworkId, systemAbilityId, remoteObject);
1201 }