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