• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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 #include "mock_dbinder_remote_listener.h"
21 #undef private
22 #include "dbinder_remote_listener.h"
23 #include "gtest/gtest.h"
24 #include "rpc_feature_set.h"
25 #include "rpc_log.h"
26 #include "log_tags.h"
27 #include "string_ex.h"
28 
29 using namespace testing::ext;
30 using namespace OHOS;
31 using namespace OHOS::HiviewDFX;
32 
33 namespace {
34 constexpr binder_uintptr_t TEST_BINDER_OBJECT_PTR = 1564618;
35 constexpr int TEST_STUB_INDEX = 1234;
36 constexpr int32_t TEST_SYSTEM_ABILITY_ID = 0x2;
37 constexpr int TEST_OBJECT_HANDLE = 16;
38 constexpr uint32_t TEST_SEQ_NUMBER = 123456;
39 constexpr int TEST_PID = 10;
40 constexpr int TEST_UID = 10;
41 }
42 
43 class DBinderServiceUnitTest : public testing::Test {
44 public:
45     static void SetUpTestCase(void);
46     static void TearDownTestCase(void);
47     void SetUp();
48     void TearDown();
49     static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_ID_TEST, "DBinderServiceUnitTest" };
50 };
51 
SetUp()52 void DBinderServiceUnitTest::SetUp() {}
53 
TearDown()54 void DBinderServiceUnitTest::TearDown() {}
55 
SetUpTestCase()56 void DBinderServiceUnitTest::SetUpTestCase() {}
57 
TearDownTestCase()58 void DBinderServiceUnitTest::TearDownTestCase() {}
59 
60 class TestDeathRecipient : public IRemoteObject::DeathRecipient {
61 public:
TestDeathRecipient()62     TestDeathRecipient() {}
~TestDeathRecipient()63     virtual ~TestDeathRecipient() {}
OnRemoteDied(const wptr<IRemoteObject> & object)64     void OnRemoteDied(const wptr<IRemoteObject>& object) override {}
65 };
66 
67 class TestRpcSystemAbilityCallback : public RpcSystemAbilityCallback {
68 public:
GetSystemAbilityFromRemote(int32_t systemAbilityId)69     sptr<IRemoteObject> GetSystemAbilityFromRemote(int32_t systemAbilityId) override
70     {
71         return nullptr;
72     }
73 
LoadSystemAbilityFromRemote(const std::string & srcNetworkId,int32_t systemAbilityId)74     bool LoadSystemAbilityFromRemote(const std::string& srcNetworkId, int32_t systemAbilityId) override
75     {
76         return isLoad_;
77     }
IsDistributedSystemAbility(int32_t systemAbilityId)78     bool IsDistributedSystemAbility(int32_t systemAbilityId) override
79     {
80         return isSystemAbility_;
81     }
82     bool isSystemAbility_ = true;
83     bool isLoad_ = true;
84 };
85 
86 /*
87  * @tc.name: ProcessOnSessionClosed001
88  * @tc.desc: Verify the ProcessOnSessionClosed function
89  * @tc.type: FUNC
90  */
91 HWTEST_F(DBinderServiceUnitTest, ProcessOnSessionClosed001, TestSize.Level1)
92 {
93     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
94     EXPECT_TRUE(dBinderService != nullptr);
95     std::string networkId = "1234567890";
96     EXPECT_EQ(dBinderService->ProcessOnSessionClosed(networkId), true);
97 }
98 
99 /*
100  * @tc.name: ProcessOnSessionClosed002
101  * @tc.desc: Verify the ProcessOnSessionClosed function
102  * @tc.type: FUNC
103  */
104 HWTEST_F(DBinderServiceUnitTest, ProcessOnSessionClosed002, TestSize.Level1)
105 {
106     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
107     EXPECT_TRUE(dBinderService != nullptr);
108     std::string networkId = "";
109     EXPECT_EQ(dBinderService->ProcessOnSessionClosed(networkId), true);
110 }
111 
112 /*
113  * @tc.name: ProcessOnSessionClosed003
114  * @tc.desc: Verify the ProcessOnSessionClosed function
115  * @tc.type: FUNC
116  */
117 HWTEST_F(DBinderServiceUnitTest, ProcessOnSessionClosed003, TestSize.Level1)
118 {
119     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
120     EXPECT_NE(dBinderService, nullptr);
121 
122     auto info = std::make_shared<ThreadLockInfo>();
123     info->networkId = "1";
124     dBinderService->threadLockInfo_.insert({1, info});
125 
126     std::string networkId = "2";
127     bool ret = dBinderService->ProcessOnSessionClosed(networkId);
128     EXPECT_TRUE(ret);
129 }
130 
131 /**
132  * @tc.name: StartDBinderService001
133  * @tc.desc: Verify the StartDBinderService function
134  * @tc.type: FUNC
135  */
136 HWTEST_F(DBinderServiceUnitTest, StartDBinderService001, TestSize.Level1)
137 {
138     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
139     EXPECT_TRUE(dBinderService != nullptr);
140     std::shared_ptr<RpcSystemAbilityCallback> callbackImpl = nullptr;
141     bool res = dBinderService->StartDBinderService(callbackImpl);
142     EXPECT_EQ(res, false);
143 }
144 
145 /**
146  * @tc.name: StartDBinderService002
147  * @tc.desc: Verify the StartDBinderService function
148  * @tc.type: FUNC
149  */
150 HWTEST_F(DBinderServiceUnitTest, StartDBinderService002, TestSize.Level1)
151 {
152     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
153     EXPECT_TRUE(dBinderService != nullptr);
154     std::shared_ptr<RpcSystemAbilityCallback> callbackImpl = nullptr;
155     DBinderService::mainThreadCreated_ = true;
156     bool res = dBinderService->StartDBinderService(callbackImpl);
157     EXPECT_EQ(res, false);
158 }
159 
160 /**
161  * @tc.name: StartDBinderService003
162  * @tc.desc: Verify the StartDBinderService function
163  * @tc.type: FUNC
164  */
165 HWTEST_F(DBinderServiceUnitTest, StartDBinderService003, TestSize.Level1)
166 {
167     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
168     EXPECT_TRUE(dBinderService != nullptr);
169     std::shared_ptr<RpcSystemAbilityCallback> callbackImpl = nullptr;
170     DBinderService::mainThreadCreated_ = false;
171     dBinderService->remoteListener_ = nullptr;
172     bool res = dBinderService->StartDBinderService(callbackImpl);
173     EXPECT_EQ(res, false);
174 }
175 
176 /**
177  * @tc.name: StartDBinderService004
178  * @tc.desc: Verify the StartDBinderService function
179  * @tc.type: FUNC
180  */
181 HWTEST_F(DBinderServiceUnitTest, StartDBinderService004, TestSize.Level1)
182 {
183     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
184     EXPECT_TRUE(dBinderService != nullptr);
185     std::shared_ptr<RpcSystemAbilityCallback> callbackImpl = nullptr;
186     DBinderService::mainThreadCreated_ = false;
187     dBinderService->remoteListener_ = std::make_shared<DBinderRemoteListener>();
188     EXPECT_TRUE(dBinderService->remoteListener_ != nullptr);
189     bool res = dBinderService->StartDBinderService(callbackImpl);
190     EXPECT_EQ(res, true);
191 }
192 
193 /**
194  * @tc.name: ReStartRemoteListener001
195  * @tc.desc: Verify the ReStartRemoteListener function
196  * @tc.type: FUNC
197  */
198 HWTEST_F(DBinderServiceUnitTest, ReStartRemoteListener001, TestSize.Level1)
199 {
200     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
201     EXPECT_TRUE(dBinderService != nullptr);
202     dBinderService->remoteListener_ = nullptr;
203     bool res = dBinderService->ReStartRemoteListener();
204     EXPECT_EQ(res, false);
205 }
206 
207 /**
208  * @tc.name: ReStartRemoteListener002
209  * @tc.desc: Verify the ReStartRemoteListener function
210  * @tc.type: FUNC
211  */
212 HWTEST_F(DBinderServiceUnitTest, ReStartRemoteListener002, TestSize.Level1)
213 {
214     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
215     EXPECT_TRUE(dBinderService != nullptr);
216     dBinderService->remoteListener_ = std::make_shared<DBinderRemoteListener>();
217     EXPECT_TRUE(dBinderService->remoteListener_ != nullptr);
218     bool res = dBinderService->ReStartRemoteListener();
219     EXPECT_EQ(res, false);
220 }
221 
222 /**
223  * @tc.name: StartRemoteListener001
224  * @tc.desc: Verify the StartRemoteListener function
225  * @tc.type: FUNC
226  */
227 HWTEST_F(DBinderServiceUnitTest, StartRemoteListener001, TestSize.Level1)
228 {
229     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
230     EXPECT_TRUE(dBinderService != nullptr);
231     dBinderService->remoteListener_ = nullptr;
232     bool res = dBinderService->StartRemoteListener();
233     EXPECT_EQ(res, false);
234 }
235 
236 /**
237  * @tc.name: StartRemoteListener002
238  * @tc.desc: Verify the StartRemoteListener function
239  * @tc.type: FUNC
240  */
241 HWTEST_F(DBinderServiceUnitTest, StartRemoteListener002, TestSize.Level1)
242 {
243     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
244     EXPECT_TRUE(dBinderService != nullptr);
245     dBinderService->remoteListener_ = std::make_shared<DBinderRemoteListener>();
246     EXPECT_TRUE(dBinderService->remoteListener_ != nullptr);
247     bool res = dBinderService->StartRemoteListener();
248     EXPECT_EQ(res, true);
249 }
250 
251 /**
252  * @tc.name: RegisterRemoteProxy001
253  * @tc.desc: Verify the RegisterRemoteProxy function
254  * @tc.type: FUNC
255  */
256 HWTEST_F(DBinderServiceUnitTest, RegisterRemoteProxy001, TestSize.Level1)
257 {
258     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
259     EXPECT_TRUE(dBinderService != nullptr);
260     std::u16string serviceName = std::u16string();
261     sptr<IRemoteObject> binderObject = nullptr;
262     bool res = dBinderService->RegisterRemoteProxy(serviceName, binderObject);
263     EXPECT_EQ(res, false);
264 }
265 
266 /**
267  * @tc.name: RegisterRemoteProxy002
268  * @tc.desc: Verify the RegisterRemoteProxy function
269  * @tc.type: FUNC
270  */
271 HWTEST_F(DBinderServiceUnitTest, RegisterRemoteProxy002, TestSize.Level1)
272 {
273     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
274     EXPECT_TRUE(dBinderService != nullptr);
275     std::u16string serviceName = std::u16string();
276     int32_t systemAbilityId = 0;
277     EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, systemAbilityId), false);
278 }
279 
280 /**
281  * @tc.name: QuerySessionObject001
282  * @tc.desc: Verify the QuerySessionObject function
283  * @tc.type: FUNC
284  */
285 HWTEST_F(DBinderServiceUnitTest, QuerySessionObject001, TestSize.Level1)
286 {
287     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
288     EXPECT_TRUE(dBinderService != nullptr);
289     binder_uintptr_t stub = 0;
290     std::shared_ptr<struct SessionInfo> testSession = nullptr;
291     testSession = dBinderService->QuerySessionObject(stub);
292     EXPECT_EQ(testSession, nullptr);
293 }
294 
295 /**
296  * @tc.name: QuerySessionObject002
297  * @tc.desc: Verify the QuerySessionObject function
298  * @tc.type: FUNC
299  */
300 HWTEST_F(DBinderServiceUnitTest, QuerySessionObject002, TestSize.Level1)
301 {
302     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
303     EXPECT_TRUE(dBinderService != nullptr);
304     binder_uintptr_t stub = 0;
305     std::shared_ptr<struct SessionInfo> Session = nullptr;
306     EXPECT_EQ(dBinderService->AttachSessionObject(Session, stub), true);
307     std::shared_ptr<struct SessionInfo> testSession = dBinderService->QuerySessionObject(stub);
308     EXPECT_EQ(testSession, Session);
309 }
310 
311 /**
312  * @tc.name: AttachDeathRecipient001
313  * @tc.desc: Verify the AttachDeathRecipient function
314  * @tc.type: FUNC
315  */
316 HWTEST_F(DBinderServiceUnitTest, AttachDeathRecipient001, TestSize.Level1)
317 {
318     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
319     EXPECT_TRUE(dBinderService != nullptr);
320     sptr<IRemoteObject> object = nullptr;
321     sptr<IRemoteObject::DeathRecipient> deathRecipient = nullptr;
322     bool res = dBinderService->AttachDeathRecipient(object, deathRecipient);
323     EXPECT_TRUE(res);
324 }
325 
326 /**
327  * @tc.name: AttachCallbackProxy001
328  * @tc.desc: Verify the AttachCallbackProxy function
329  * @tc.type: FUNC
330  */
331 HWTEST_F(DBinderServiceUnitTest, AttachCallbackProxy001, TestSize.Level1)
332 {
333     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
334     EXPECT_TRUE(dBinderService != nullptr);
335     sptr<IRemoteObject> object = nullptr;
336     DBinderServiceStub *dbStub = nullptr;
337     bool res = dBinderService->AttachCallbackProxy(object, dbStub);
338     EXPECT_TRUE(res);
339 }
340 
341 /**
342  * @tc.name: DetachProxyObject001
343  * @tc.desc: Verify the DetachProxyObject function
344  * @tc.type: FUNC
345  */
346 HWTEST_F(DBinderServiceUnitTest, DetachProxyObject001, TestSize.Level1)
347 {
348     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
349     EXPECT_TRUE(dBinderService != nullptr);
350     binder_uintptr_t binderObject = 0;
351     bool res = dBinderService->DetachProxyObject(binderObject);
352     EXPECT_EQ(res, false);
353 }
354 
355 /**
356  * @tc.name: ConvertToSecureDeviceIDTest001
357  * @tc.desc: Verify the ConvertToSecureDeviceID function
358  * @tc.type: FUNC
359  */
360 HWTEST_F(DBinderServiceUnitTest, ConvertToSecureDeviceIDTest001, TestSize.Level1)
361 {
362     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
363     EXPECT_TRUE(dBinderService != nullptr);
364     std::string deviceID;
365     EXPECT_EQ(dBinderService->ConvertToSecureDeviceID(deviceID), "****");
366 }
367 
368 /**
369  * @tc.name: ConvertToSecureDeviceIDTest002
370  * @tc.desc: Verify the ConvertToSecureDeviceID function
371  * @tc.type: FUNC
372  */
373 HWTEST_F(DBinderServiceUnitTest, ConvertToSecureDeviceIDTest002, TestSize.Level1)
374 {
375     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
376     EXPECT_TRUE(dBinderService != nullptr);
377     std::string deviceID("123456");
378     EXPECT_EQ(dBinderService->ConvertToSecureDeviceID(deviceID),
379     deviceID.substr(0, ENCRYPT_LENGTH) + "****" + deviceID.substr(strlen(deviceID.c_str()) - ENCRYPT_LENGTH));
380 }
381 
382 /**
383  * @tc.name: GetRemoteTransTypeTest003
384  * @tc.desc: Verify the GetRemoteTransType function
385  * @tc.type: FUNC
386  */
387 HWTEST_F(DBinderServiceUnitTest, GetRemoteTransTypeTest003, TestSize.Level1)
388 {
389     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
390     EXPECT_TRUE(dBinderService != nullptr);
391     EXPECT_EQ(dBinderService->GetRemoteTransType(), IRemoteObject::DATABUS_TYPE);
392 }
393 
394 /**
395  * @tc.name: StopRemoteListener001
396  * @tc.desc: Verify the StopRemoteListener function
397  * @tc.type: FUNC
398  */
399 HWTEST_F(DBinderServiceUnitTest, StopRemoteListener001, TestSize.Level1)
400 {
401     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
402     EXPECT_TRUE(dBinderService != nullptr);
403     std::shared_ptr<DBinderRemoteListener> testListener = std::make_shared<DBinderRemoteListener>();
404     EXPECT_TRUE(testListener != nullptr);
405     EXPECT_EQ(dBinderService->StartRemoteListener(), true);
406     dBinderService->StopRemoteListener();
407 }
408 
409 /**
410  * @tc.name: GetRemoteTransType001
411  * @tc.desc: Verify the GetRemoteTransType function
412  * @tc.type: FUNC
413  */
414 HWTEST_F(DBinderServiceUnitTest, GetRemoteListener001, TestSize.Level1)
415 {
416     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
417     EXPECT_TRUE(dBinderService != nullptr);
418     std::shared_ptr<DBinderRemoteListener> testDbinder = nullptr;
419     testDbinder = dBinderService->GetRemoteListener();
420     EXPECT_EQ(testDbinder, nullptr);
421 }
422 
423 /**
424  * @tc.name: GetRemoteListener002
425  * @tc.desc: Verify the GetRemoteListener function
426  * @tc.type: FUNC
427  */
428 HWTEST_F(DBinderServiceUnitTest, GetRemoteListener002, TestSize.Level1)
429 {
430     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
431     EXPECT_TRUE(dBinderService != nullptr);
432     std::shared_ptr<DBinderRemoteListener> testListener = std::make_shared<DBinderRemoteListener>();
433     EXPECT_TRUE(testListener != nullptr);
434     EXPECT_EQ(dBinderService->StartRemoteListener(), false);
435     std::shared_ptr<DBinderRemoteListener> testDbinder = nullptr;
436     testDbinder = dBinderService->GetRemoteListener();
437 }
438 
439 /**
440  * @tc.name: GetSeqNumber001
441  * @tc.desc: Verify the GetSeqNumber function
442  * @tc.type: FUNC
443  */
444 HWTEST_F(DBinderServiceUnitTest, GetSeqNumber001, TestSize.Level1)
445 {
446     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
447     EXPECT_TRUE(dBinderService != nullptr);
448     dBinderService->seqNumber_ = 0;
449     uint32_t ret = dBinderService->GetSeqNumber();
450     EXPECT_EQ(ret, dBinderService->seqNumber_++);
451 }
452 
453 /**
454  * @tc.name: GetSeqNumber002
455  * @tc.desc: Verify the GetSeqNumber function
456  * @tc.type: FUNC
457  */
458 HWTEST_F(DBinderServiceUnitTest, GetSeqNumber002, TestSize.Level1)
459 {
460     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
461     EXPECT_TRUE(dBinderService != nullptr);
462     dBinderService->seqNumber_ = std::numeric_limits<uint32_t>::max();
463     uint32_t ret = dBinderService->GetSeqNumber();
464     EXPECT_EQ(ret, 1);
465 }
466 
467 /**
468  * @tc.name: IsDeviceIdIllegal001
469  * @tc.desc: Verify the IsDeviceIdIllegal function
470  * @tc.type: FUNC
471  */
472 HWTEST_F(DBinderServiceUnitTest, IsDeviceIdIllegal001, TestSize.Level1)
473 {
474     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
475     EXPECT_TRUE(dBinderService != nullptr);
476     std::string deviceID = "";
477     bool res = dBinderService->IsDeviceIdIllegal(deviceID);
478     EXPECT_EQ(res, true);
479 }
480 
481 /**
482  * @tc.name: IsDeviceIdIllegal002
483  * @tc.desc: Verify the IsDeviceIdIllegal function
484  * @tc.type: FUNC
485  */
486 HWTEST_F(DBinderServiceUnitTest, IsDeviceIdIllegal002, TestSize.Level1)
487 {
488     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
489     EXPECT_TRUE(dBinderService != nullptr);
490     std::string deviceID = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
491     bool res = dBinderService->IsDeviceIdIllegal(deviceID);
492     EXPECT_EQ(res, true);
493 }
494 
495 /**
496  * @tc.name: IsDeviceIdIllegal003
497  * @tc.desc: Verify the IsDeviceIdIllegal function
498  * @tc.type: FUNC
499  */
500 HWTEST_F(DBinderServiceUnitTest, IsDeviceIdIllegal003, TestSize.Level1)
501 {
502     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
503     EXPECT_TRUE(dBinderService != nullptr);
504     std::string deviceID = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
505     bool res = dBinderService->IsDeviceIdIllegal(deviceID);
506     EXPECT_EQ(res, false);
507 }
508 
509 /**
510  * @tc.name: AddStubByTag001
511  * @tc.desc: Verify the AddStubByTag function
512  * @tc.type: FUNC
513  */
514 HWTEST_F(DBinderServiceUnitTest, AddStubByTag001, TestSize.Level1)
515 {
516     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
517     EXPECT_TRUE(dBinderService != nullptr);
518 
519     const std::u16string serviceName = u"abc";
520     const std::string deviceID = "bcd";
521     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
522     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID, binderObject);
523     EXPECT_TRUE(stub != nullptr);
524     binder_uintptr_t binderObjectPtr = reinterpret_cast<binder_uintptr_t>(stub.GetRefPtr());
525 
526     binder_uintptr_t stubTag = dBinderService->stubTagNum_++;
527     auto result = dBinderService->mapDBinderStubRegisters_.insert({stubTag, binderObjectPtr});
528     EXPECT_TRUE(result.second);
529 
530     binder_uintptr_t stubTag2 = dBinderService->AddStubByTag(binderObjectPtr);
531     EXPECT_EQ(stubTag2, stubTag);
532 
533     dBinderService->stubTagNum_ = 1;
534     dBinderService->mapDBinderStubRegisters_.clear();
535 }
536 
537 /**
538  * @tc.name: AddStubByTag002
539  * @tc.desc: Verify the AddStubByTag function
540  * @tc.type: FUNC
541  */
542 HWTEST_F(DBinderServiceUnitTest, AddStubByTag002, TestSize.Level1)
543 {
544     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
545     EXPECT_TRUE(dBinderService != nullptr);
546 
547     const std::u16string serviceName = u"abc";
548     const std::string deviceID = "bcd";
549     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
550     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID, binderObject);
551     EXPECT_TRUE(stub != nullptr);
552     binder_uintptr_t binderObjectPtr = reinterpret_cast<binder_uintptr_t>(stub.GetRefPtr());
553 
554     binder_uintptr_t stubTag = dBinderService->AddStubByTag(binderObjectPtr);
555     EXPECT_GT(stubTag, 0);
556 
557     dBinderService->stubTagNum_ = 1;
558     dBinderService->mapDBinderStubRegisters_.clear();
559 }
560 
561 /**
562  * @tc.name: AddStubByTag003
563  * @tc.desc: Verify the AddStubByTag function
564  * @tc.type: FUNC
565  */
566 HWTEST_F(DBinderServiceUnitTest, AddStubByTag003, TestSize.Level1)
567 {
568     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
569     EXPECT_TRUE(dBinderService != nullptr);
570 
571     const std::u16string serviceName = u"abc";
572     const std::string deviceID = "bcd";
573     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
574     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID, binderObject);
575     EXPECT_NE(stub, nullptr);
576     binder_uintptr_t binderObjectPtr = reinterpret_cast<binder_uintptr_t>(stub.GetRefPtr());
577     binder_uintptr_t stubTag = dBinderService->AddStubByTag(binderObjectPtr);
578     EXPECT_GT(stubTag, 0);
579 
580     sptr<DBinderServiceStub> stub2 = new (std::nothrow) DBinderServiceStub(serviceName, deviceID, binderObject);
581     EXPECT_NE(stub2, nullptr);
582     binder_uintptr_t binderObject2Ptr = reinterpret_cast<binder_uintptr_t>(stub2.GetRefPtr());
583     auto result = dBinderService->mapDBinderStubRegisters_.insert_or_assign(stubTag, binderObject2Ptr);
584     EXPECT_FALSE(result.second);
585 
586     dBinderService->stubTagNum_--;
587     binder_uintptr_t stubTag2 = dBinderService->AddStubByTag(binderObjectPtr);
588     EXPECT_EQ(stubTag2, 0);
589 
590     dBinderService->stubTagNum_ = 1;
591     dBinderService->mapDBinderStubRegisters_.clear();
592 }
593 
594 /**
595  * @tc.name: QueryStubPtr001
596  * @tc.desc: Verify the QueryStubPtr function
597  * @tc.type: FUNC
598  */
599 HWTEST_F(DBinderServiceUnitTest, QueryStubPtr001, TestSize.Level1)
600 {
601     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
602     EXPECT_TRUE(dBinderService != nullptr);
603 
604     const std::u16string serviceName = u"abc";
605     const std::string deviceID = "bcd";
606     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
607     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID, binderObject);
608     EXPECT_NE(stub, nullptr);
609     binder_uintptr_t binderObjectPtr = reinterpret_cast<binder_uintptr_t>(stub.GetRefPtr());
610 
611     binder_uintptr_t stubTag = dBinderService->AddStubByTag(binderObjectPtr);
612     EXPECT_GT(stubTag, 0);
613 
614     binder_uintptr_t stubPtr = dBinderService->QueryStubPtr(stubTag);
615     EXPECT_EQ(stubPtr, binderObjectPtr);
616 
617     dBinderService->stubTagNum_ = 1;
618     dBinderService->mapDBinderStubRegisters_.clear();
619 }
620 
621 /**
622  * @tc.name: QueryStubPtr002
623  * @tc.desc: Verify the QueryStubPtr function
624  * @tc.type: FUNC
625  */
626 HWTEST_F(DBinderServiceUnitTest, QueryStubPtr002, TestSize.Level1)
627 {
628     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
629     EXPECT_TRUE(dBinderService != nullptr);
630 
631     binder_uintptr_t binderObject = 0;
632     binder_uintptr_t stubPtr = dBinderService->QueryStubPtr(binderObject);
633     EXPECT_EQ(stubPtr, 0);
634 }
635 
636 /**
637  * @tc.name: CheckBinderObject001
638  * @tc.desc: Verify the CheckBinderObject function
639  * @tc.type: FUNC
640  */
641 HWTEST_F(DBinderServiceUnitTest, CheckBinderObject001, TestSize.Level1)
642 {
643     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
644     EXPECT_TRUE(dBinderService != nullptr);
645     sptr<DBinderServiceStub> stub = nullptr;
646     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
647     bool res = dBinderService->CheckBinderObject(stub, binderObject);
648     EXPECT_EQ(res, false);
649 }
650 
651 /**
652  * @tc.name: CheckBinderObject002
653  * @tc.desc: Verify the CheckBinderObject function
654  * @tc.type: FUNC
655  */
656 HWTEST_F(DBinderServiceUnitTest, CheckBinderObject002, TestSize.Level1)
657 {
658     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
659     EXPECT_TRUE(dBinderService != nullptr);
660     const std::u16string serviceName = u"abc";
661     const std::string deviceID = "bcd";
662     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
663     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID, binderObject);
664     EXPECT_TRUE(stub != nullptr);
665     bool res = dBinderService->CheckBinderObject(stub, binderObject);
666     EXPECT_EQ(res, false);
667 }
668 
669 /**
670  * @tc.name: CheckBinderObject003
671  * @tc.desc: Verify the CheckBinderObject function
672  * @tc.type: FUNC
673  */
674 HWTEST_F(DBinderServiceUnitTest, CheckBinderObject003, TestSize.Level1)
675 {
676     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
677     EXPECT_TRUE(dBinderService != nullptr);
678     const std::u16string serviceName = u"abc";
679     const std::string deviceID = "bcd";
680     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
681     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID, binderObject);
682     EXPECT_TRUE(stub != nullptr);
683 
684     binder_uintptr_t binderObjectPtr = reinterpret_cast<binder_uintptr_t>(stub.GetRefPtr());
685     bool ret = dBinderService->CheckBinderObject(stub, binderObjectPtr);
686     EXPECT_TRUE(ret);
687 }
688 
689 /**
690  * @tc.name: HasDBinderStub001
691  * @tc.desc: Verify the HasDBinderStub function
692  * @tc.type: FUNC
693  */
694 HWTEST_F(DBinderServiceUnitTest, HasDBinderStub001, TestSize.Level1)
695 {
696     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
697     EXPECT_TRUE(dBinderService != nullptr);
698     dBinderService->DBinderStubRegisted_.clear();
699 
700     const std::u16string serviceName = u"abc";
701     const std::string deviceID = "bcd";
702     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
703     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID, binderObject);
704     EXPECT_TRUE(stub != nullptr);
705     dBinderService->DBinderStubRegisted_.push_back(stub);
706 
707     binder_uintptr_t binderObjectPtr = reinterpret_cast<binder_uintptr_t>(stub.GetRefPtr());
708     bool ret = dBinderService->HasDBinderStub(binderObjectPtr);
709     EXPECT_TRUE(ret);
710 
711     dBinderService->DBinderStubRegisted_.clear();
712 }
713 
714 /**
715  * @tc.name: HasDBinderStub002
716  * @tc.desc: Verify the HasDBinderStub function
717  * @tc.type: FUNC
718  */
719 HWTEST_F(DBinderServiceUnitTest, HasDBinderStub002, TestSize.Level1)
720 {
721     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
722     EXPECT_TRUE(dBinderService != nullptr);
723     dBinderService->DBinderStubRegisted_.clear();
724 
725     const std::u16string serviceName = u"abc";
726     const std::string deviceID = "bcd";
727     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
728     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID, binderObject);
729     EXPECT_TRUE(stub != nullptr);
730 
731     binderObject = reinterpret_cast<binder_uintptr_t>(stub.GetRefPtr());
732     stub->binderObject_ = binderObject;
733 
734     dBinderService->DBinderStubRegisted_.push_back(stub);
735     bool ret = dBinderService->HasDBinderStub(binderObject);
736     EXPECT_TRUE(ret);
737 
738     dBinderService->DBinderStubRegisted_.clear();
739 }
740 
741 /**
742  * @tc.name: DeleteDBinderStub001
743  * @tc.desc: Verify the DeleteDBinderStub function
744  * @tc.type: FUNC
745  */
746 HWTEST_F(DBinderServiceUnitTest, DeleteDBinderStub001, TestSize.Level1)
747 {
748     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
749     EXPECT_TRUE(dBinderService != nullptr);
750 
751     dBinderService->DBinderStubRegisted_.clear();
752     dBinderService->mapDBinderStubRegisters_.clear();
753 
754     const std::u16string serviceName = u"abc";
755     const std::string deviceID = "bcd";
756     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
757     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID, binderObject);
758     EXPECT_TRUE(stub != nullptr);
759     dBinderService->DBinderStubRegisted_.push_back(stub);
760 
761     const std::u16string serviceName2 = u"abcd";
762     const std::string deviceID2 = "bcde";
763     binder_uintptr_t binderObject2 = TEST_BINDER_OBJECT_PTR + 1;
764     sptr<DBinderServiceStub> stub2 = new (std::nothrow) DBinderServiceStub(serviceName2, deviceID2, binderObject2);
765     EXPECT_TRUE(stub2 != nullptr);
766 
767     binder_uintptr_t binderPtr = reinterpret_cast<binder_uintptr_t>(stub.GetRefPtr());
768     dBinderService->mapDBinderStubRegisters_.insert({binderPtr, binderPtr});
769 
770     binder_uintptr_t binderPtr2 = reinterpret_cast<binder_uintptr_t>(stub2.GetRefPtr());
771     dBinderService->mapDBinderStubRegisters_.insert({binderPtr2, binderPtr2});
772     bool ret = dBinderService->DeleteDBinderStub(serviceName, deviceID);
773     ASSERT_TRUE(ret);
774 }
775 
776 /**
777  * @tc.name: DeleteDBinderStub002
778  * @tc.desc: Verify the DeleteDBinderStub function
779  * @tc.type: FUNC
780  */
781 HWTEST_F(DBinderServiceUnitTest, DeleteDBinderStub002, TestSize.Level1)
782 {
783     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
784     EXPECT_TRUE(dBinderService != nullptr);
785 
786     dBinderService->DBinderStubRegisted_.clear();
787     dBinderService->mapDBinderStubRegisters_.clear();
788     const std::u16string serviceName = u"abc";
789     const std::string deviceID = "bcd";
790     bool ret = dBinderService->DeleteDBinderStub(serviceName, deviceID, 0, 0);
791     ASSERT_FALSE(ret);
792 
793     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
794     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID, binderObject);
795     EXPECT_TRUE(stub != nullptr);
796     dBinderService->DBinderStubRegisted_.push_back(stub);
797     ret = dBinderService->DeleteDBinderStub(serviceName, deviceID, 0, 0);
798     ASSERT_TRUE(ret);
799 }
800 
801 /**
802  * @tc.name: IsSameStubObject001
803  * @tc.desc: Verify the IsSameStubObject function
804  * @tc.type: FUNC
805  */
806 HWTEST_F(DBinderServiceUnitTest, IsSameStubObject001, TestSize.Level1)
807 {
808     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
809     EXPECT_TRUE(dBinderService != nullptr);
810     sptr<DBinderServiceStub> stub = nullptr;
811     std::u16string service = std::u16string();
812     const std::string device = "";
813     bool res = dBinderService->IsSameStubObject(stub, service, device);
814     EXPECT_EQ(res, false);
815 }
816 
817 /**
818  * @tc.name: MakeRemoteBinder001
819  * @tc.desc: Verify the MakeRemoteBinder function
820  * @tc.type: FUNC
821  */
822 HWTEST_F(DBinderServiceUnitTest, MakeRemoteBinder001, TestSize.Level1)
823 {
824     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
825     EXPECT_TRUE(dBinderService != nullptr);
826     std::u16string serviceName = std::u16string();
827     std::string deviceID = "";
828     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
829     uint32_t pid = 0;
830     uint32_t uid = 0;
831     EXPECT_EQ(dBinderService->MakeRemoteBinder(serviceName, deviceID, binderObject, pid, uid), nullptr);
832 }
833 
834 /**
835  * @tc.name: MakeRemoteBinder002
836  * @tc.desc: Verify the MakeRemoteBinder function
837  * @tc.type: FUNC
838  */
839 HWTEST_F(DBinderServiceUnitTest, MakeRemoteBinder002, TestSize.Level1)
840 {
841     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
842     EXPECT_TRUE(dBinderService != nullptr);
843     std::u16string serviceName;
844     std::string deviceID("001");
845     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
846     uint32_t pid = 0;
847     uint32_t uid = 0;
848     EXPECT_EQ(dBinderService->MakeRemoteBinder(serviceName, deviceID, binderObject, pid, uid), nullptr);
849 }
850 
851 /**
852  * @tc.name: MakeRemoteBinderTest003
853  * @tc.desc: Verify the MakeRemoteBinder function
854  * @tc.type: FUNC
855  */
856 HWTEST_F(DBinderServiceUnitTest, MakeRemoteBinderTest003, TestSize.Level1)
857 {
858     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
859     EXPECT_TRUE(dBinderService != nullptr);
860     std::u16string serviceName;
861     std::string deviceID("001");
862     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
863     uint32_t pid = TEST_PID;
864     uint32_t uid = TEST_UID;
865     EXPECT_EQ(dBinderService->MakeRemoteBinder(serviceName, deviceID, binderObject, pid, uid), nullptr);
866 }
867 
868 /**
869  * @tc.name: MakeRemoteBinderTest004
870  * @tc.desc: Verify the MakeRemoteBinder function
871  * @tc.type: FUNC
872  */
873 HWTEST_F(DBinderServiceUnitTest, MakeRemoteBinderTest004, TestSize.Level1)
874 {
875     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
876     EXPECT_TRUE(dBinderService != nullptr);
877     std::u16string serviceName = u"abcd";
878     std::string deviceID("001");
879     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
880     uint32_t pid = TEST_PID;
881     uint32_t uid = TEST_UID;
882     sptr<DBinderServiceStub> ret = dBinderService->MakeRemoteBinder(serviceName, deviceID, binderObject, pid, uid);
883     EXPECT_EQ(ret, nullptr);
884 }
885 
886 /**
887  * @tc.name: CheckDeviceIDsInvalid001
888  * @tc.desc: Verify the CheckDeviceIDsInvalid function
889  * @tc.type: FUNC
890  */
891 HWTEST_F(DBinderServiceUnitTest, CheckDeviceIDsInvalid001, TestSize.Level1)
892 {
893     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
894     EXPECT_TRUE(dBinderService != nullptr);
895 
896     std::string deviceID;
897     std::string localDevID;
898     bool ret = dBinderService->CheckDeviceIDsInvalid(deviceID, localDevID);
899     EXPECT_TRUE(ret);
900 }
901 
902 /**
903  * @tc.name: CheckDeviceIDsInvalid002
904  * @tc.desc: Verify the CheckDeviceIDsInvalid function
905  * @tc.type: FUNC
906  */
907 HWTEST_F(DBinderServiceUnitTest, CheckDeviceIDsInvalid002, TestSize.Level1)
908 {
909     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
910     EXPECT_TRUE(dBinderService != nullptr);
911 
912     std::string deviceID(DEVICEID_LENGTH - 1, 'a');
913     std::string localDevID(DEVICEID_LENGTH - 1, 'a');
914     bool ret = dBinderService->CheckDeviceIDsInvalid(deviceID, localDevID);
915     EXPECT_FALSE(ret);
916 }
917 
918 /**
919  * @tc.name: CopyDeviceIDsToMessage001
920  * @tc.desc: Verify the CopyDeviceIDsToMessage function
921  * @tc.type: FUNC
922  */
923 HWTEST_F(DBinderServiceUnitTest, CopyDeviceIDsToMessage001, TestSize.Level1)
924 {
925     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
926     EXPECT_TRUE(dBinderService != nullptr);
927 
928     auto message = std::make_shared<struct DHandleEntryTxRx>();
929 
930     std::string localDevID(DEVICEID_LENGTH + 1, 'a');
931     std::string deviceID(DEVICEID_LENGTH + 1, 'a');
932     bool ret = dBinderService->CopyDeviceIDsToMessage(message, localDevID, deviceID);
933     EXPECT_FALSE(ret);
934 }
935 
936 /**
937  * @tc.name: CopyDeviceIDsToMessage002
938  * @tc.desc: Verify the CopyDeviceIDsToMessage function
939  * @tc.type: FUNC
940  */
941 HWTEST_F(DBinderServiceUnitTest, CopyDeviceIDsToMessage002, TestSize.Level1)
942 {
943     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
944     EXPECT_TRUE(dBinderService != nullptr);
945 
946     auto message = std::make_shared<struct DHandleEntryTxRx>();
947 
948     std::string localDevID(DEVICEID_LENGTH - 1, 'a');
949     std::string deviceID(DEVICEID_LENGTH - 1, 'a');
950     bool ret = dBinderService->CopyDeviceIDsToMessage(message, localDevID, deviceID);
951     EXPECT_TRUE(ret);
952 }
953 
954 /**
955  * @tc.name: CreateMessage001
956  * @tc.desc: Verify the CreateMessage function
957  * @tc.type: FUNC
958  */
959 HWTEST_F(DBinderServiceUnitTest, CreateMessage001, TestSize.Level1)
960 {
961     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
962     EXPECT_TRUE(dBinderService != nullptr);
963 
964     std::u16string serviceName = u"testServiceName";
965     std::string deviceID = "testDeviceID";
966     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
967     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID, binderObject);
968     ASSERT_NE(stub, nullptr);
969     uint32_t seqNumber = 1;
970     uint32_t pid = 1;
971     uint32_t uid = 1;
972     auto message = dBinderService->CreateMessage(stub, seqNumber, pid, uid);
973     EXPECT_EQ(message, nullptr);
974 }
975 
976 /**
977  * @tc.name: CreateMessage002
978  * @tc.desc: Verify the CreateMessage function
979  * @tc.type: FUNC
980  */
981 HWTEST_F(DBinderServiceUnitTest, CreateMessage002, TestSize.Level1)
982 {
983     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
984     EXPECT_TRUE(dBinderService != nullptr);
985 
986     std::u16string serviceName = u"123";
987     std::string deviceID = "testDeviceID";
988     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
989     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID, binderObject);
990     ASSERT_NE(stub, nullptr);
991     uint32_t seqNumber = 1;
992     uint32_t pid = 1;
993     uint32_t uid = 1;
994     auto message = dBinderService->CreateMessage(stub, seqNumber, pid, uid);
995     EXPECT_NE(message, nullptr);
996 }
997 
998 /**
999  * @tc.name: SendEntryToRemote001
1000  * @tc.desc: Verify the SendEntryToRemote function
1001  * @tc.type: FUNC
1002  */
1003 HWTEST_F(DBinderServiceUnitTest, SendEntryToRemote001, TestSize.Level1)
1004 {
1005     std::u16string serviceName = u"testServiceName";
1006     std::string deviceID = "testDeviceID";
1007     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
1008     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1009     EXPECT_TRUE(dBinderService != nullptr);
1010     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID, binderObject);
1011     EXPECT_TRUE(stub != nullptr);
1012     uint32_t seqNumber = 0;
1013     uint32_t pid = 0;
1014     uint32_t uid = 0;
1015     bool res = dBinderService->SendEntryToRemote(stub, seqNumber, pid, uid);
1016     EXPECT_EQ(res, false);
1017 }
1018 
1019 /**
1020  * @tc.name: CheckSystemAbilityId001
1021  * @tc.desc: Verify the CheckSystemAbilityId function
1022  * @tc.type: FUNC
1023  */
1024 HWTEST_F(DBinderServiceUnitTest, CheckSystemAbilityId001, TestSize.Level1)
1025 {
1026     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1027     EXPECT_TRUE(dBinderService != nullptr);
1028     int32_t systemAbilityId = TEST_SYSTEM_ABILITY_ID;
1029     bool res = dBinderService->CheckSystemAbilityId(systemAbilityId);
1030     EXPECT_EQ(res, true);
1031 }
1032 
1033 /**
1034  * @tc.name: AllocFreeSocketPort001
1035  * @tc.desc: Verify the AllocFreeSocketPort function
1036  * @tc.type: FUNC
1037  */
1038 HWTEST_F(DBinderServiceUnitTest, AllocFreeSocketPort001, TestSize.Level1)
1039 {
1040     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1041     EXPECT_TRUE(dBinderService != nullptr);
1042     uint16_t ret = dBinderService->AllocFreeSocketPort();
1043     EXPECT_EQ(ret, 0);
1044 }
1045 
1046 /**
1047  * @tc.name: IsSameLoadSaItem001
1048  * @tc.desc: Verify the IsSameLoadSaItem function
1049  * @tc.type: FUNC
1050  */
1051 HWTEST_F(DBinderServiceUnitTest, IsSameLoadSaItem001, TestSize.Level1)
1052 {
1053     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1054     EXPECT_TRUE(dBinderService != nullptr);
1055     std::string srcNetworkId = "aaaaaaaaaaaaaa";
1056     int32_t systemAbilityId = TEST_SYSTEM_ABILITY_ID;
1057     std::shared_ptr<DHandleEntryTxRx> loadSaItem = std::make_shared<DHandleEntryTxRx>();
1058     EXPECT_TRUE(loadSaItem != nullptr);
1059     loadSaItem->binderObject = TEST_SYSTEM_ABILITY_ID;
1060     strcpy_s(loadSaItem->deviceIdInfo.fromDeviceId, DEVICEID_LENGTH, "aaaaaaaaaaaaaa");
1061     bool res = dBinderService->IsSameLoadSaItem(srcNetworkId, systemAbilityId, loadSaItem);
1062     EXPECT_EQ(res, true);
1063 }
1064 
1065 /**
1066  * @tc.name: IsSameLoadSaItem002
1067  * @tc.desc: Verify the IsSameLoadSaItem function
1068  * @tc.type: FUNC
1069  */
1070 HWTEST_F(DBinderServiceUnitTest, IsSameLoadSaItem002, TestSize.Level1)
1071 {
1072     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1073     EXPECT_TRUE(dBinderService != nullptr);
1074     std::string srcNetworkId = "bbbbbbb";
1075     int32_t systemAbilityId = TEST_SYSTEM_ABILITY_ID;
1076     std::shared_ptr<DHandleEntryTxRx> loadSaItem = std::make_shared<DHandleEntryTxRx>();
1077     EXPECT_TRUE(loadSaItem != nullptr);
1078     loadSaItem->stubIndex = TEST_STUB_INDEX;
1079     strcpy_s(loadSaItem->deviceIdInfo.fromDeviceId, DEVICEID_LENGTH, "aaaaaaaaaaaaaa");
1080     bool res = dBinderService->IsSameLoadSaItem(srcNetworkId, systemAbilityId, loadSaItem);
1081     EXPECT_EQ(res, false);
1082 }
1083 
1084 /**
1085  * @tc.name: IsSameLoadSaItem003
1086  * @tc.desc: Verify the IsSameLoadSaItem function
1087  * @tc.type: FUNC
1088  */
1089 HWTEST_F(DBinderServiceUnitTest, IsSameLoadSaItem003, TestSize.Level1)
1090 {
1091     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1092     EXPECT_TRUE(dBinderService != nullptr);
1093     std::string srcNetworkId = "aaaaaaaaaaaaaa";
1094     int32_t systemAbilityId = TEST_SYSTEM_ABILITY_ID;
1095     std::shared_ptr<DHandleEntryTxRx> loadSaItem = std::make_shared<DHandleEntryTxRx>();
1096     EXPECT_TRUE(loadSaItem != nullptr);
1097     loadSaItem->stubIndex = TEST_STUB_INDEX;
1098     strcpy_s(loadSaItem->deviceIdInfo.fromDeviceId, DEVICEID_LENGTH, "aaaaaaaaaaaaaa");
1099     bool res = dBinderService->IsSameLoadSaItem(srcNetworkId, systemAbilityId, loadSaItem);
1100     EXPECT_EQ(res, false);
1101 }
1102 
1103 /**
1104  * @tc.name: OnRemoteInvokerMessage001
1105  * @tc.desc: Verify the OnRemoteInvokerMessage function
1106  * @tc.type: FUNC
1107  */
1108 HWTEST_F(DBinderServiceUnitTest, OnRemoteInvokerMessage001, TestSize.Level1)
1109 {
1110     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1111     EXPECT_TRUE(dBinderService != nullptr);
1112     std::shared_ptr<MockDBinderRemoteListener> mockListener = std::make_shared<MockDBinderRemoteListener>();
1113     dBinderService->remoteListener_ = std::static_pointer_cast<DBinderRemoteListener>(mockListener);
1114     EXPECT_TRUE(dBinderService->remoteListener_ != nullptr);
1115 
1116     std::shared_ptr<struct DHandleEntryTxRx> message = std::make_shared<DHandleEntryTxRx>();
1117     EXPECT_TRUE(message != nullptr);
1118     (void)memset_s(message.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
1119     message->stubIndex = DBinderService::FIRST_SYS_ABILITY_ID - 1;
1120     message->binderObject = DBinderService::FIRST_SYS_ABILITY_ID - 1;
1121     message->deviceIdInfo.fromDeviceId[0] = 't';
1122 
1123     DBinderSoftbusClient::GetInstance().sendBytesFunc_ = MockDBinderRemoteListener::SendBytes;
1124     PeerSocketInfo info;
1125     info.networkId = message->deviceIdInfo.fromDeviceId;
1126     int32_t socket = 1001;
1127     DBinderRemoteListener::ServerOnBind(socket, info);
1128 
1129     bool ret = dBinderService->OnRemoteInvokerMessage(message);
1130     EXPECT_FALSE(ret);
1131     EXPECT_EQ(MockDBinderRemoteListener::GetInstance().GetResult(), SAID_INVALID_ERR);
1132     dBinderService->remoteListener_ = nullptr;
1133     DBinderSoftbusClient::GetInstance().sendBytesFunc_ = nullptr;
1134 }
1135 
1136 /**
1137  * @tc.name: OnRemoteInvokerMessage002
1138  * @tc.desc: Verify the OnRemoteInvokerMessage function
1139  * @tc.type: FUNC
1140  */
1141 HWTEST_F(DBinderServiceUnitTest, OnRemoteInvokerMessage002, TestSize.Level1)
1142 {
1143     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1144     EXPECT_TRUE(dBinderService != nullptr);
1145     std::shared_ptr<struct DHandleEntryTxRx> message = std::make_shared<DHandleEntryTxRx>();
1146     EXPECT_TRUE(message != nullptr);
1147     (void)memset_s(message.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
1148     message->stubIndex = TEST_STUB_INDEX;
1149     dBinderService->dbinderCallback_ = std::make_shared<TestRpcSystemAbilityCallback>();
1150     EXPECT_TRUE(dBinderService->dbinderCallback_ != nullptr);
1151     bool res = dBinderService->OnRemoteInvokerMessage(message);
1152     EXPECT_EQ(res, true);
1153 }
1154 
1155 /**
1156  * @tc.name: OnRemoteInvokerMessage003
1157  * @tc.desc: Verify the OnRemoteInvokerMessage function
1158  * @tc.type: FUNC
1159  */
1160 HWTEST_F(DBinderServiceUnitTest, OnRemoteInvokerMessage003, TestSize.Level1)
1161 {
1162     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1163     EXPECT_TRUE(dBinderService != nullptr);
1164     std::shared_ptr<MockDBinderRemoteListener> mockListener = std::make_shared<MockDBinderRemoteListener>();
1165     dBinderService->remoteListener_ = std::static_pointer_cast<DBinderRemoteListener>(mockListener);
1166     EXPECT_TRUE(dBinderService->remoteListener_ != nullptr);
1167 
1168     std::shared_ptr<struct DHandleEntryTxRx> message = std::make_shared<DHandleEntryTxRx>();
1169     EXPECT_TRUE(message != nullptr);
1170     (void)memset_s(message.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
1171     message->stubIndex = DBinderService::FIRST_SYS_ABILITY_ID;
1172     message->binderObject = DBinderService::FIRST_SYS_ABILITY_ID;
1173     message->deviceIdInfo.fromDeviceId[0] = 't';
1174 
1175     std::shared_ptr<TestRpcSystemAbilityCallback> cb = std::make_shared<TestRpcSystemAbilityCallback>();
1176     cb->isSystemAbility_ = false;
1177     dBinderService->dbinderCallback_ = cb;
1178 
1179     DBinderSoftbusClient::GetInstance().sendBytesFunc_ = MockDBinderRemoteListener::SendBytes;
1180     PeerSocketInfo info;
1181     info.networkId = message->deviceIdInfo.fromDeviceId;
1182     int32_t socket = 1001;
1183     DBinderRemoteListener::ServerOnBind(socket, info);
1184 
1185     bool ret = dBinderService->OnRemoteInvokerMessage(message);
1186     EXPECT_FALSE(ret);
1187     EXPECT_EQ(MockDBinderRemoteListener::GetInstance().GetResult(), SA_NOT_DISTRUBUTED_ERR);
1188     dBinderService->remoteListener_ = nullptr;
1189     cb->isSystemAbility_ = true;
1190     DBinderSoftbusClient::GetInstance().sendBytesFunc_ = nullptr;
1191 }
1192 
1193 /**
1194  * @tc.name: OnRemoteInvokerMessage004
1195  * @tc.desc: Verify the OnRemoteInvokerMessage function
1196  * @tc.type: FUNC
1197  */
1198 HWTEST_F(DBinderServiceUnitTest, OnRemoteInvokerMessage004, TestSize.Level1)
1199 {
1200     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1201     EXPECT_TRUE(dBinderService != nullptr);
1202     std::shared_ptr<MockDBinderRemoteListener> mockListener = std::make_shared<MockDBinderRemoteListener>();
1203     dBinderService->remoteListener_ = std::static_pointer_cast<DBinderRemoteListener>(mockListener);
1204     EXPECT_TRUE(dBinderService->remoteListener_ != nullptr);
1205 
1206     std::shared_ptr<struct DHandleEntryTxRx> message = std::make_shared<DHandleEntryTxRx>();
1207     EXPECT_TRUE(message != nullptr);
1208     (void)memset_s(message.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
1209     message->stubIndex = DBinderService::FIRST_SYS_ABILITY_ID;
1210     message->binderObject = DBinderService::FIRST_SYS_ABILITY_ID;
1211     message->deviceIdInfo.fromDeviceId[0] = 't';
1212 
1213     std::shared_ptr<TestRpcSystemAbilityCallback> cb = std::make_shared<TestRpcSystemAbilityCallback>();
1214     cb->isLoad_ = false;
1215     dBinderService->dbinderCallback_ = cb;
1216 
1217     DBinderSoftbusClient::GetInstance().sendBytesFunc_ = MockDBinderRemoteListener::SendBytes;
1218     PeerSocketInfo info;
1219     info.networkId = message->deviceIdInfo.fromDeviceId;
1220     int32_t socket = 1001;
1221     DBinderRemoteListener::ServerOnBind(socket, info);
1222 
1223     bool ret = dBinderService->OnRemoteInvokerMessage(message);
1224     EXPECT_FALSE(ret);
1225     EXPECT_EQ(MockDBinderRemoteListener::GetInstance().GetResult(), SA_NOT_AVAILABLE);
1226     dBinderService->remoteListener_ = nullptr;
1227     cb->isLoad_ = true;
1228     DBinderSoftbusClient::GetInstance().sendBytesFunc_ = nullptr;
1229 }
1230 
1231 
1232 /**
1233  * @tc.name: GetDatabusNameByProxyTest001
1234  * @tc.desc: Verify the GetDatabusNameByProxy function
1235  * @tc.type: FUNC
1236  */
1237 HWTEST_F(DBinderServiceUnitTest, GetDatabusNameByProxyTest001, TestSize.Level1)
1238 {
1239     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1240     EXPECT_TRUE(dBinderService != nullptr);
1241     IPCObjectProxy* proxy = nullptr;
1242     std::string res = dBinderService->GetDatabusNameByProxy(proxy);
1243     EXPECT_EQ(res, "");
1244     IPCObjectProxy object(TEST_OBJECT_HANDLE);
1245     res = dBinderService->GetDatabusNameByProxy(&object);
1246     EXPECT_EQ(res, "");
1247 }
1248 
1249 /**
1250  * @tc.name: InvokerRemoteDBinderTest001
1251  * @tc.desc: Verify the InvokerRemoteDBinder function
1252  * @tc.type: FUNC
1253  */
1254 HWTEST_F(DBinderServiceUnitTest, InvokerRemoteDBinderTest001, TestSize.Level1)
1255 {
1256     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1257     EXPECT_TRUE(dBinderService != nullptr);
1258     sptr<DBinderServiceStub> stub = nullptr;
1259     uint32_t seqNumber = TEST_SEQ_NUMBER;
1260     uint32_t pid = 0;
1261     uint32_t uid = 0;
1262     int32_t ret = dBinderService->InvokerRemoteDBinder(stub, seqNumber, pid, uid);
1263     EXPECT_EQ(ret, DBinderErrorCode::STUB_INVALID);
1264     std::u16string serviceName(u"testServer");
1265     std::string deviceID("123456");
1266     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
1267     stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID, binderObject);
1268     EXPECT_TRUE(stub != nullptr);
1269     ret = dBinderService->InvokerRemoteDBinder(stub, seqNumber, pid, uid);
1270     EXPECT_EQ(ret, DBinderErrorCode::SEND_MESSAGE_FAILED);
1271 }
1272 
1273 /**
1274  * @tc.name: CreateDatabusNameTest001
1275  * @tc.desc: Verify the CreateDatabusName function
1276  * @tc.type: FUNC
1277  */
1278 HWTEST_F(DBinderServiceUnitTest, CreateDatabusNameTest001, TestSize.Level1)
1279 {
1280     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1281     EXPECT_TRUE(dBinderService != nullptr);
1282     int pid = 0;
1283     int uid = 0;
1284     std::string res = dBinderService->CreateDatabusName(pid, uid);
1285     EXPECT_EQ(res, "");
1286     pid = TEST_PID;
1287     uid = TEST_UID;
1288     res = dBinderService->CreateDatabusName(pid, uid);
1289     EXPECT_EQ(res, "");
1290 }
1291 
1292 /**
1293  * @tc.name: FindServicesByDeviceIDTest001
1294  * @tc.desc: Verify the FindServicesByDeviceID function
1295  * @tc.type: FUNC
1296  */
1297 HWTEST_F(DBinderServiceUnitTest, FindServicesByDeviceIDTest001, TestSize.Level1)
1298 {
1299     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1300     EXPECT_TRUE(dBinderService != nullptr);
1301     std::u16string serviceName(u"testServer");
1302     std::string deviceID("123456");
1303     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
1304     sptr<DBinderServiceStub> dBinderServiceStub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID,
1305         binderObject);
1306     EXPECT_TRUE(dBinderServiceStub != nullptr);
1307     dBinderService->DBinderStubRegisted_.push_back(dBinderServiceStub);
1308     std::set<std::u16string> serviceNames;
1309     serviceNames.emplace(serviceName);
1310     EXPECT_EQ(dBinderService->FindServicesByDeviceID(deviceID), serviceNames);
1311 }
1312 
1313 /**
1314  * @tc.name: NoticeDeviceDieTest001
1315  * @tc.desc: Verify the NoticeDeviceDie function
1316  * @tc.type: FUNC
1317  */
1318 HWTEST_F(DBinderServiceUnitTest, NoticeDeviceDieTest001, TestSize.Level1)
1319 {
1320     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1321     EXPECT_TRUE(dBinderService != nullptr);
1322     std::string deviceID;
1323     EXPECT_EQ(dBinderService->NoticeDeviceDie(deviceID), DBINDER_SERVICE_INVALID_DATA_ERR);
1324 }
1325 
1326 /**
1327  * @tc.name: NoticeDeviceDieTest002
1328  * @tc.desc: Verify the NoticeDeviceDie function
1329  * @tc.type: FUNC
1330  */
1331 HWTEST_F(DBinderServiceUnitTest, NoticeDeviceDieTest002, TestSize.Level1)
1332 {
1333     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1334     EXPECT_TRUE(dBinderService != nullptr);
1335     std::string deviceID("123456");
1336     EXPECT_EQ(dBinderService->NoticeDeviceDie(deviceID), DBINDER_SERVICE_NOTICE_DIE_ERR);
1337 }
1338 
1339 /**
1340  * @tc.name: NoticeDeviceDieTest003
1341  * @tc.desc: Verify the NoticeDeviceDie function
1342  * @tc.type: FUNC
1343  */
1344 HWTEST_F(DBinderServiceUnitTest, NoticeDeviceDieTest003, TestSize.Level1)
1345 {
1346     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1347     EXPECT_TRUE(dBinderService != nullptr);
1348     std::string deviceID("123456");
1349     EXPECT_EQ(dBinderService->NoticeDeviceDie(deviceID), DBINDER_SERVICE_NOTICE_DIE_ERR);
1350 }
1351 
1352 /**
1353  * @tc.name: NoticeServiceDieTest001
1354  * @tc.desc: Verify the NoticeServiceDie function
1355  * @tc.type: FUNC
1356  */
1357 HWTEST_F(DBinderServiceUnitTest, NoticeServiceDieTest001, TestSize.Level1)
1358 {
1359     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1360     EXPECT_TRUE(dBinderService != nullptr);
1361     dBinderService->StartRemoteListener();
1362     std::u16string serviceName;
1363     std::string deviceID("123456");
1364     EXPECT_EQ(dBinderService->NoticeServiceDie(serviceName, deviceID), DBINDER_SERVICE_INVALID_DATA_ERR);
1365 }
1366 
1367 /**
1368  * @tc.name: NoticeServiceDieInnerTest001
1369  * @tc.desc: Verify the NoticeServiceDieInner function
1370  * @tc.type: FUNC
1371  */
1372 HWTEST_F(DBinderServiceUnitTest, NoticeServiceDieInnerTest001, TestSize.Level1)
1373 {
1374     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1375     EXPECT_TRUE(dBinderService != nullptr);
1376     dBinderService->StartRemoteListener();
1377     std::u16string serviceName;
1378     std::string deviceID("123456");
1379     EXPECT_EQ(dBinderService->NoticeServiceDieInner(serviceName, deviceID), DBINDER_SERVICE_INVALID_DATA_ERR);
1380 }
1381 
1382 /**
1383  * @tc.name: NoticeServiceDieInnerTest002
1384  * @tc.desc: Verify the NoticeServiceDieInner function
1385  * @tc.type: FUNC
1386  */
1387 HWTEST_F(DBinderServiceUnitTest, NoticeServiceDieInnerTest002, TestSize.Level1)
1388 {
1389     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1390     EXPECT_TRUE(dBinderService != nullptr);
1391     dBinderService->StartRemoteListener();
1392     std::u16string serviceName(u"test");
1393     std::string deviceID("123456");
1394     EXPECT_EQ(dBinderService->NoticeServiceDieInner(serviceName, deviceID), ERR_NONE);
1395 }
1396 
1397 /**
1398  * @tc.name: NoticeServiceDieInnerTest003
1399  * @tc.desc: Verify the NoticeServiceDieInner function
1400  * @tc.type: FUNC
1401  */
1402 HWTEST_F(DBinderServiceUnitTest, NoticeServiceDieInnerTest003, TestSize.Level1)
1403 {
1404     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1405     EXPECT_TRUE(dBinderService != nullptr);
1406     dBinderService->StartRemoteListener();
1407     std::u16string serviceName(u"testServer");
1408     std::string deviceID("123456");
1409     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
1410     sptr<DBinderServiceStub> dBinderServiceStub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID,
1411         binderObject);
1412     EXPECT_TRUE(dBinderServiceStub != nullptr);
1413     dBinderService->DBinderStubRegisted_.push_back(dBinderServiceStub);
1414     EXPECT_EQ(dBinderService->NoticeServiceDieInner(serviceName, deviceID), DBINDER_SERVICE_NOTICE_DIE_ERR);
1415     dBinderService->DBinderStubRegisted_.clear();
1416 }
1417 
1418 /**
1419  * @tc.name: ProcessCallbackProxyTest001
1420  * @tc.desc: Verify the ProcessCallbackProxy function
1421  * @tc.type: FUNC
1422  */
1423 HWTEST_F(DBinderServiceUnitTest, ProcessCallbackProxyTest001, TestSize.Level1)
1424 {
1425     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1426     EXPECT_TRUE(dBinderService != nullptr);
1427     sptr<IRemoteObject> object = new (std::nothrow) IPCObjectProxy(TEST_OBJECT_HANDLE);
1428     EXPECT_TRUE(object != nullptr);
1429     std::u16string serviceName(u"testServer");
1430     std::string deviceID("123456");
1431     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
1432     sptr<DBinderServiceStub> dBinderServiceStub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID,
1433         binderObject);
1434     EXPECT_TRUE(dBinderServiceStub != nullptr);
1435     bool res = dBinderService->AttachCallbackProxy(object, dBinderServiceStub.GetRefPtr());
1436     std::vector<sptr<DBinderServiceStub>> vec;
1437     vec.emplace_back(dBinderServiceStub);
1438     dBinderService->ProcessCallbackProxy(vec);
1439     EXPECT_TRUE(res);
1440 }
1441 
1442 /**
1443  * @tc.name: NoticeCallbackProxyTest001
1444  * @tc.desc: Verify the NoticeCallbackProxy function
1445  * @tc.type: FUNC
1446  */
1447 HWTEST_F(DBinderServiceUnitTest, NoticeCallbackProxyTest001, TestSize.Level1)
1448 {
1449     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1450     EXPECT_TRUE(dBinderService != nullptr);
1451     sptr<IRemoteObject> object = new (std::nothrow) IPCObjectProxy(TEST_OBJECT_HANDLE);
1452     EXPECT_TRUE(object != nullptr);
1453     std::u16string serviceName(u"testServer");
1454     std::string deviceID("123456");
1455     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
1456     sptr<DBinderServiceStub> dBinderServiceStub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID,
1457         binderObject);
1458     EXPECT_TRUE(dBinderServiceStub != nullptr);
1459     dBinderService->AttachCallbackProxy(object, dBinderServiceStub.GetRefPtr());
1460     EXPECT_EQ(dBinderService->NoticeCallbackProxy(serviceName, deviceID), true);
1461 }
1462 
1463 /**
1464  * @tc.name: DetachCallbackProxyTest001
1465  * @tc.desc: Verify the DetachCallbackProxy function
1466  * @tc.type: FUNC
1467  */
1468 HWTEST_F(DBinderServiceUnitTest, DetachCallbackProxyTest001, TestSize.Level1)
1469 {
1470     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1471     EXPECT_TRUE(dBinderService != nullptr);
1472     sptr<IRemoteObject> object = new (std::nothrow) IPCObjectProxy(TEST_OBJECT_HANDLE);
1473     EXPECT_TRUE(object != nullptr);
1474     std::u16string serviceName(u"test1");
1475     std::string deviceID("12345");
1476     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
1477     sptr<DBinderServiceStub> dBinderServiceStub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID,
1478         binderObject);
1479     EXPECT_TRUE(dBinderServiceStub != nullptr);
1480     dBinderService->AttachCallbackProxy(object, dBinderServiceStub.GetRefPtr());
1481     EXPECT_EQ(dBinderService->DetachCallbackProxy(object), true);
1482 }
1483 
1484 /**
1485  * @tc.name: DetachCallbackProxyTest002
1486  * @tc.desc: Verify the DetachCallbackProxy function
1487  * @tc.type: FUNC
1488  */
1489 HWTEST_F(DBinderServiceUnitTest, DetachCallbackProxyTest002, TestSize.Level1)
1490 {
1491     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1492     EXPECT_TRUE(dBinderService != nullptr);
1493     sptr<IRemoteObject> object = new (std::nothrow) IPCObjectProxy(TEST_OBJECT_HANDLE);
1494     EXPECT_TRUE(object != nullptr);
1495     EXPECT_EQ(dBinderService->DetachCallbackProxy(object), false);
1496 }
1497 
1498 /**
1499  * @tc.name: QueryDeathRecipientTest001
1500  * @tc.desc: Verify the QueryDeathRecipient function
1501  * @tc.type: FUNC
1502  */
1503 HWTEST_F(DBinderServiceUnitTest, QueryDeathRecipientTest001, TestSize.Level1)
1504 {
1505     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1506     EXPECT_TRUE(dBinderService != nullptr);
1507     sptr<IRemoteObject> object = new (std::nothrow) IPCObjectProxy(TEST_OBJECT_HANDLE);
1508     EXPECT_TRUE(object != nullptr);
1509     sptr<IRemoteObject::DeathRecipient> deathRecipient = new (std::nothrow) TestDeathRecipient();
1510     EXPECT_TRUE(deathRecipient != nullptr);
1511     dBinderService->AttachDeathRecipient(object, deathRecipient);
1512     EXPECT_EQ(dBinderService->QueryDeathRecipient(object), deathRecipient);
1513 }
1514 
1515 /**
1516  * @tc.name: QueryDeathRecipientTest002
1517  * @tc.desc: Verify the QueryDeathRecipient function
1518  * @tc.type: FUNC
1519  */
1520 HWTEST_F(DBinderServiceUnitTest, QueryDeathRecipientTest002, TestSize.Level1)
1521 {
1522     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1523     EXPECT_TRUE(dBinderService != nullptr);
1524     EXPECT_EQ(dBinderService->QueryDeathRecipient(nullptr), nullptr);
1525 }
1526 
1527 /**
1528  * @tc.name: AttachProxyObjectTest001
1529  * @tc.desc: Verify the AttachProxyObject function
1530  * @tc.type: FUNC
1531  */
1532 HWTEST_F(DBinderServiceUnitTest, AttachProxyObjectTest001, TestSize.Level1)
1533 {
1534     std::string name("Test");
1535     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
1536     binder_uintptr_t binderObject1 = TEST_BINDER_OBJECT_PTR + 1;
1537     sptr<IRemoteObject> object = new (std::nothrow) IPCObjectProxy(TEST_OBJECT_HANDLE);
1538     EXPECT_TRUE(object != nullptr);
1539     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1540     EXPECT_TRUE(dBinderService != nullptr);
1541     EXPECT_EQ(dBinderService->AttachProxyObject(object, binderObject), true);
1542     EXPECT_EQ(dBinderService->QueryProxyObject(binderObject), object);
1543     EXPECT_EQ(dBinderService->QueryProxyObject(binderObject1), nullptr);
1544 }
1545 
1546 /**
1547  * @tc.name: AttachProxyObjectTest002
1548  * @tc.desc: Verify the AttachProxyObject function
1549  * @tc.type: FUNC
1550  */
1551 HWTEST_F(DBinderServiceUnitTest, AttachProxyObjectTest002, TestSize.Level1)
1552 {
1553     uint32_t seqNumber = TEST_SEQ_NUMBER;
1554     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1555     EXPECT_TRUE(dBinderService != nullptr);
1556     std::shared_ptr<OHOS::ThreadLockInfo> threadLockInfo = std::make_shared<OHOS::ThreadLockInfo>();
1557     EXPECT_TRUE(threadLockInfo != nullptr);
1558     dBinderService->AttachThreadLockInfo(seqNumber, "networkId", threadLockInfo);
1559     dBinderService->WakeupThreadByStub(seqNumber);
1560     EXPECT_TRUE(dBinderService->QueryThreadLockInfo(seqNumber) != nullptr);
1561     EXPECT_EQ(dBinderService->QueryThreadLockInfo(seqNumber), threadLockInfo);
1562     dBinderService->DetachThreadLockInfo(seqNumber);
1563     dBinderService->WakeupThreadByStub(seqNumber);
1564     EXPECT_TRUE(dBinderService->QueryThreadLockInfo(seqNumber) == nullptr);
1565 }
1566 
1567 /**
1568  * @tc.name: MakeSessionByReplyMessageTest001
1569  * @tc.desc: Verify the MakeSessionByReplyMessage function
1570  * @tc.type: FUNC
1571  */
1572 HWTEST_F(DBinderServiceUnitTest, MakeSessionByReplyMessageTest001, TestSize.Level1)
1573 {
1574     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1575     EXPECT_TRUE(dBinderService != nullptr);
1576     std::shared_ptr<struct DHandleEntryTxRx> replyMessage = std::make_shared<DHandleEntryTxRx>();
1577     EXPECT_TRUE(replyMessage != nullptr);
1578     (void)memset_s(replyMessage.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
1579     dBinderService->MakeSessionByReplyMessage(replyMessage);
1580     EXPECT_EQ(dBinderService->HasDBinderStub(replyMessage->binderObject), false);
1581 
1582     std::u16string serviceName(u"testServer");
1583     std::string deviceID;
1584     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
1585     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID, binderObject);
1586     EXPECT_TRUE(stub != nullptr);
1587     replyMessage->stub = reinterpret_cast<binder_uintptr_t>(stub.GetRefPtr());
1588     dBinderService->MakeSessionByReplyMessage(replyMessage);
1589 }
1590 
1591 /**
1592  * @tc.name: RegisterRemoteProxyTest001
1593  * @tc.desc: Verify the RegisterRemoteProxy function
1594  * @tc.type: FUNC
1595  */
1596 HWTEST_F(DBinderServiceUnitTest, RegisterRemoteProxyTest001, TestSize.Level1)
1597 {
1598     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1599     EXPECT_TRUE(dBinderService != nullptr);
1600     std::u16string serviceName;
1601     int32_t systemAbilityId = 1;
1602     EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, systemAbilityId), false);
1603     serviceName = u"testServer";
1604     systemAbilityId = 0;
1605     EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, systemAbilityId), false);
1606     systemAbilityId = 1;
1607     EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, systemAbilityId), true);
1608 }
1609 
1610 /**
1611  * @tc.name: RegisterRemoteProxyTest002
1612  * @tc.desc: Verify the RegisterRemoteProxy function
1613  * @tc.type: FUNC
1614  */
1615 HWTEST_F(DBinderServiceUnitTest, RegisterRemoteProxyTest002, TestSize.Level1)
1616 {
1617     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1618     EXPECT_TRUE(dBinderService != nullptr);
1619     std::u16string serviceName;
1620     sptr<IRemoteObject> binderObject = nullptr;
1621     EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, binderObject), false);
1622     serviceName = u"testServer";
1623     EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, binderObject), false);
1624     sptr<IRemoteObject> object = new (std::nothrow) IPCObjectProxy(TEST_OBJECT_HANDLE);
1625     EXPECT_TRUE(object != nullptr);
1626     EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, object), true);
1627 }
1628 
1629 /**
1630  * @tc.name: GetRegisterServiceTest001
1631  * @tc.desc: Verify the GetRegisterService function
1632  * @tc.type: FUNC
1633  */
1634 HWTEST_F(DBinderServiceUnitTest, GetRegisterServiceTest001, TestSize.Level1)
1635 {
1636     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1637     EXPECT_TRUE(dBinderService != nullptr);
1638     binder_uintptr_t binderObject = 1;
1639     EXPECT_EQ(dBinderService->GetRegisterService(binderObject), std::u16string());
1640     std::u16string serviceName(u"testServer");
1641     dBinderService->RegisterRemoteProxyInner(serviceName, binderObject);
1642     EXPECT_EQ(dBinderService->GetRegisterService(binderObject), serviceName);
1643 }
1644 
1645 /**
1646  * @tc.name: OnRemoteMessageTaskTest001
1647  * @tc.desc: Verify the OnRemoteMessageTask function
1648  * @tc.type: FUNC
1649  */
1650 HWTEST_F(DBinderServiceUnitTest, OnRemoteMessageTaskTest001, TestSize.Level1)
1651 {
1652     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1653     EXPECT_TRUE(dBinderService != nullptr);
1654     std::shared_ptr<struct DHandleEntryTxRx> handleEntryTxRx = nullptr;
1655     EXPECT_EQ(dBinderService->OnRemoteMessageTask(handleEntryTxRx), false);
1656     std::shared_ptr<DHandleEntryTxRx> message = std::make_shared<DHandleEntryTxRx>();
1657     EXPECT_TRUE(message != nullptr);
1658     message->head.len = 10;
1659     message->head.version = 1;
1660     message->transType = 0;
1661     message->fromPort = 1;
1662     message->toPort = 2;
1663     message->stubIndex = 1;
1664     message->seqNumber = 1;
1665     message->binderObject = TEST_BINDER_OBJECT_PTR;
1666     message->deviceIdInfo.tokenId = 1;
1667     message->deviceIdInfo.fromDeviceId[0] = 't';
1668     message->deviceIdInfo.toDeviceId[0] = 't';
1669     message->stub = 10;
1670     message->serviceNameLength = 10;
1671     message->serviceName[0] = 't';
1672     message->pid = TEST_PID;
1673     message->uid = TEST_UID;
1674     dBinderService->dbinderCallback_ = std::make_shared<TestRpcSystemAbilityCallback>();
1675     EXPECT_TRUE(dBinderService->dbinderCallback_ != nullptr);
1676     message->dBinderCode = DBinderCode::MESSAGE_AS_INVOKER;
1677     EXPECT_EQ(dBinderService->OnRemoteMessageTask(message), true);
1678     message->dBinderCode = DBinderCode::MESSAGE_AS_REPLY;
1679     EXPECT_EQ(dBinderService->OnRemoteMessageTask(message), true);
1680     message->dBinderCode = DBinderCode::MESSAGE_AS_OBITUARY;
1681     EXPECT_EQ(dBinderService->OnRemoteMessageTask(message), false);
1682     message->dBinderCode = DBinderCode::MESSAGE_AS_REMOTE_ERROR;
1683     EXPECT_EQ(dBinderService->OnRemoteMessageTask(message), true);
1684 }
1685 
1686 /**
1687  * @tc.name: OnRemoteInvokerDataBusMessageTest001
1688  * @tc.desc: Verify the OnRemoteInvokerDataBusMessage function
1689  * @tc.type: FUNC
1690  */
1691 HWTEST_F(DBinderServiceUnitTest, OnRemoteInvokerDataBusMessageTest001, TestSize.Level1)
1692 {
1693     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1694     EXPECT_TRUE(dBinderService != nullptr);
1695     IPCObjectProxy* proxy = nullptr;
1696     std::string remoteDeviceId;
1697     int pid = 1;
1698     int uid = 1;
1699     uint32_t tokenId = 1;
1700     std::shared_ptr<struct DHandleEntryTxRx> replyMessage = std::make_shared<DHandleEntryTxRx>();
1701     EXPECT_TRUE(replyMessage != nullptr);
1702     (void)memset_s(replyMessage.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
1703     EXPECT_EQ(dBinderService->OnRemoteInvokerDataBusMessage(
1704         proxy, replyMessage, remoteDeviceId, pid, uid, tokenId), DBinderErrorCode::DEVICEID_INVALID);
1705 }
1706 
1707 /**
1708  * @tc.name: OnRemoteInvokerDataBusMessageTest002
1709  * @tc.desc: Verify the OnRemoteInvokerDataBusMessage function
1710  * @tc.type: FUNC
1711  */
1712 HWTEST_F(DBinderServiceUnitTest, OnRemoteInvokerDataBusMessageTest002, TestSize.Level1)
1713 {
1714     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1715     EXPECT_TRUE(dBinderService != nullptr);
1716     std::string remoteDeviceId("test");
1717     int pid = 1;
1718     int uid = 1;
1719     uint32_t tokenId = 1;
1720     IPCObjectProxy objectProxy(0);
1721     std::shared_ptr<struct DHandleEntryTxRx> replyMessage = std::make_shared<DHandleEntryTxRx>();
1722     EXPECT_TRUE(replyMessage != nullptr);
1723     (void)memset_s(replyMessage.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
1724     EXPECT_EQ(dBinderService->OnRemoteInvokerDataBusMessage(
1725         &objectProxy, replyMessage, remoteDeviceId, pid, uid, tokenId), DBinderErrorCode::SESSION_NAME_NOT_FOUND);
1726 }
1727 
1728 /*
1729  * @tc.name: ProcessOnSessionClosedTest002
1730  * @tc.desc: Verify the ProcessOnSessionClosed function
1731  * @tc.type: FUNC
1732  */
1733 HWTEST_F(DBinderServiceUnitTest, ProcessOnSessionClosedTest002, TestSize.Level1)
1734 {
1735     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1736     EXPECT_TRUE(dBinderService != nullptr);
1737     std::shared_ptr<OHOS::ThreadLockInfo> threadLockInfo = std::make_shared<OHOS::ThreadLockInfo>();
1738     EXPECT_TRUE(threadLockInfo != nullptr);
1739     uint32_t seqNumber = TEST_SEQ_NUMBER;
1740     std::string networkId = "networkId";
1741     dBinderService->AttachThreadLockInfo(seqNumber, networkId, threadLockInfo);
1742     EXPECT_EQ(dBinderService->ProcessOnSessionClosed(networkId), true);
1743 }
1744 
1745 /**
1746  * @tc.name: FindDBinderStub001
1747  * @tc.desc: Verify the FindDBinderStub function
1748  * @tc.type: FUNC
1749  */
1750 HWTEST_F(DBinderServiceUnitTest, FindDBinderStub001, TestSize.Level1)
1751 {
1752     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1753     EXPECT_TRUE(dBinderService != nullptr);
1754     std::u16string service(u"test");
1755     std::string device = "aaa";
1756     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
1757     bool isNew = false;
1758     sptr<DBinderServiceStub> testDdBinderStub1 = dBinderService->FindOrNewDBinderStub(service, device, binderObject,
1759         0, 0, isNew);
1760     EXPECT_TRUE(testDdBinderStub1 != nullptr);
1761     sptr<DBinderServiceStub> testDdBinderStub2 = dBinderService->FindOrNewDBinderStub(service, device, binderObject,
1762         0, 0, isNew);
1763     EXPECT_TRUE(testDdBinderStub2 != nullptr);
1764     EXPECT_EQ(testDdBinderStub1.GetRefPtr(), testDdBinderStub2.GetRefPtr());
1765 
1766     std::vector<sptr<DBinderServiceStub>> vec = dBinderService->FindDBinderStub(service, device);
1767     EXPECT_TRUE(vec.size() == 1);
1768     EXPECT_EQ(testDdBinderStub1.GetRefPtr(), vec[0].GetRefPtr());
1769 
1770     std::u16string service1(u"test1");
1771     std::string device1 = "bbb";
1772     vec = dBinderService->FindDBinderStub(service1, device1);
1773     EXPECT_EQ(vec.size(), 0);
1774 
1775     EXPECT_EQ(dBinderService->DeleteDBinderStub(service1, device1), false);
1776     EXPECT_EQ(dBinderService->DeleteDBinderStub(service, device), true);
1777 }
1778 
1779 /**
1780  * @tc.name: ReStartRemoteListenerTest001
1781  * @tc.desc: Verify the ReStartRemoteListener function
1782  * @tc.type: FUNC
1783  */
1784 HWTEST_F(DBinderServiceUnitTest, ReStartRemoteListenerTest001, TestSize.Level1)
1785 {
1786     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1787     EXPECT_TRUE(dBinderService != nullptr);
1788     dBinderService->remoteListener_ = nullptr;
1789     bool res = dBinderService->ReStartRemoteListener();
1790     EXPECT_EQ(res, false);
1791 }
1792 
1793 /**
1794  * @tc.name: ReStartRemoteListenerTest002
1795  * @tc.desc: Verify the ReStartRemoteListener function
1796  * @tc.type: FUNC
1797  */
1798 HWTEST_F(DBinderServiceUnitTest, ReStartRemoteListenerTest002, TestSize.Level1)
1799 {
1800     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1801     EXPECT_TRUE(dBinderService != nullptr);
1802     dBinderService->remoteListener_ = std::make_shared<DBinderRemoteListener>();
1803     EXPECT_TRUE(dBinderService->remoteListener_ != nullptr);
1804     bool res = dBinderService->ReStartRemoteListener();
1805     EXPECT_EQ(res, false);
1806 }
1807 
1808 /**
1809  * @tc.name: IsSameStubObjectTest002
1810  * @tc.desc: Verify the IsSameStubObject function
1811  * @tc.type: FUNC
1812  */
1813 HWTEST_F(DBinderServiceUnitTest, IsSameStubObjectTest002, TestSize.Level1)
1814 {
1815     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1816     EXPECT_TRUE(dBinderService != nullptr);
1817     std::u16string serviceName = u"test";
1818     std::string deviceID = "001";
1819     binder_uintptr_t binderObject = 1;
1820     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID, binderObject);
1821     EXPECT_TRUE(stub != nullptr);
1822     std::u16string service(u"test");
1823     bool res = dBinderService->IsSameStubObject(stub, service, deviceID);
1824     EXPECT_EQ(res, true);
1825 }
1826 
1827 /**
1828  * @tc.name: SendEntryToRemoteTest002
1829  * @tc.desc: Verify the SendEntryToRemote function
1830  * @tc.type: FUNC
1831  */
1832 HWTEST_F(DBinderServiceUnitTest, SendEntryToRemoteTest002, TestSize.Level1)
1833 {
1834     std::u16string serviceName(u"testServer");
1835     std::string deviceID;
1836     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
1837     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1838     EXPECT_TRUE(dBinderService != nullptr);
1839     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID, binderObject);
1840     EXPECT_TRUE(stub != nullptr);
1841     uint32_t seqNumber = 0;
1842     uint32_t pid = 0;
1843     uint32_t uid = 0;
1844     bool res = dBinderService->SendEntryToRemote(stub, seqNumber, pid, uid);
1845     EXPECT_EQ(res, false);
1846 }
1847 
1848 /**
1849  * @tc.name: PopLoadSaItemTest001
1850  * @tc.desc: Verify the PopLoadSaItem function
1851  * @tc.type: FUNC
1852  */
1853 HWTEST_F(DBinderServiceUnitTest, PopLoadSaItemTest001, TestSize.Level1)
1854 {
1855     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1856     EXPECT_TRUE(dBinderService != nullptr);
1857     std::string srcNetworkId;
1858     int32_t systemAbilityId = 1;
1859     EXPECT_EQ(dBinderService->PopLoadSaItem(srcNetworkId, systemAbilityId), nullptr);
1860 
1861     srcNetworkId = "t";
1862     std::shared_ptr<struct DHandleEntryTxRx> message = std::make_shared<DHandleEntryTxRx>();
1863     EXPECT_TRUE(message != nullptr);
1864     (void)memset_s(message.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
1865     message->stubIndex = systemAbilityId;
1866     message->deviceIdInfo.fromDeviceId[0] = 't';
1867     dBinderService->dbinderCallback_ = std::make_shared<TestRpcSystemAbilityCallback>();
1868     EXPECT_TRUE(dBinderService->dbinderCallback_ != nullptr);
1869     dBinderService->OnRemoteInvokerMessage(message);
1870     std::shared_ptr<DHandleEntryTxRx> dHandleEntryTxRx = dBinderService->PopLoadSaItem(srcNetworkId, systemAbilityId);
1871     EXPECT_TRUE(dHandleEntryTxRx != nullptr);
1872     sptr<IRemoteObject> remoteObject = nullptr;
1873     dBinderService->LoadSystemAbilityComplete("test", 2, remoteObject);
1874 
1875     /* verify running into the remoteObject is null branch */
1876     DBinderSoftbusClient::GetInstance().sendBytesFunc_ = MockDBinderRemoteListener::SendBytes;
1877     PeerSocketInfo info;
1878     info.networkId = message->deviceIdInfo.fromDeviceId;
1879     int32_t socket = 1001;
1880     DBinderRemoteListener::ServerOnBind(socket, info);
1881 
1882     std::shared_ptr<MockDBinderRemoteListener> mockListener = std::make_shared<MockDBinderRemoteListener>();
1883     dBinderService->remoteListener_ = std::static_pointer_cast<DBinderRemoteListener>(mockListener);
1884     EXPECT_TRUE(dBinderService->remoteListener_ != nullptr);
1885     dBinderService->LoadSystemAbilityComplete(srcNetworkId, systemAbilityId, remoteObject);
1886     EXPECT_EQ(MockDBinderRemoteListener::GetInstance().GetResult(), SA_NOT_FOUND);
1887 
1888     /* verify running into the add death recipient fail branch */
1889     dBinderService->loadSaReply_.push_back(message);
1890     sptr<MockIPCObjectProxy> remoteObject1 = sptr<MockIPCObjectProxy>::MakeSptr();
1891     EXPECT_TRUE(remoteObject1 != nullptr);
1892     EXPECT_CALL(*remoteObject1, AddDeathRecipient(testing::_)).WillRepeatedly(testing::Return(false));
1893     dBinderService->LoadSystemAbilityComplete(srcNetworkId, systemAbilityId, remoteObject1);
1894     EXPECT_EQ(MockDBinderRemoteListener::GetInstance().GetResult(), SA_NOT_FOUND);
1895     dBinderService->remoteListener_ = nullptr;
1896     DBinderSoftbusClient::GetInstance().sendBytesFunc_ = nullptr;
1897 }
1898 
1899 /**
1900  * @tc.name: PopLoadSaItemTest002
1901  * @tc.desc: Verify the PopLoadSaItem function
1902  * @tc.type: FUNC
1903  */
1904 HWTEST_F(DBinderServiceUnitTest, PopLoadSaItemTest002, TestSize.Level1)
1905 {
1906     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1907     EXPECT_TRUE(dBinderService != nullptr);
1908 
1909     std::string srcNetworkId = "t";
1910     int32_t systemAbilityId = 1;
1911     std::shared_ptr<struct DHandleEntryTxRx> message = std::make_shared<DHandleEntryTxRx>();
1912     EXPECT_TRUE(message != nullptr);
1913     (void)memset_s(message.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
1914     message->stubIndex = systemAbilityId;
1915     message->deviceIdInfo.fromDeviceId[0] = 't';
1916     message->binderObject = 0;
1917     dBinderService->loadSaReply_.push_back(message);
1918 
1919     sptr<IRemoteObject> remoteObject1 = new (std::nothrow) IPCObjectProxy(1);
1920     EXPECT_TRUE(remoteObject1 != nullptr);
1921     dBinderService->LoadSystemAbilityComplete(srcNetworkId, systemAbilityId, remoteObject1);
1922 }
1923 
1924 /**
1925  * @tc.name: PopLoadSaItemTest003
1926  * @tc.desc: Verify the PopLoadSaItem function
1927  * @tc.type: FUNC
1928  */
1929 HWTEST_F(DBinderServiceUnitTest, PopLoadSaItemTest003, TestSize.Level1)
1930 {
1931     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1932     EXPECT_TRUE(dBinderService != nullptr);
1933 
1934     std::string srcNetworkId = "t";
1935     int32_t systemAbilityId = 1;
1936     std::shared_ptr<struct DHandleEntryTxRx> message = std::make_shared<DHandleEntryTxRx>();
1937     EXPECT_TRUE(message != nullptr);
1938     (void)memset_s(message.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
1939     message->binderObject = systemAbilityId;
1940     message->deviceIdInfo.fromDeviceId[0] = 't';
1941     message->transType = IRemoteObject::DATABUS_TYPE + 1;
1942     dBinderService->loadSaReply_.push_back(message);
1943 
1944     sptr<IRemoteObject> remoteObject1 = new (std::nothrow) IPCObjectProxy(1);
1945     EXPECT_TRUE(remoteObject1 != nullptr);
1946     dBinderService->proxyObject_.clear();
1947     bool ret = dBinderService->AttachProxyObject(remoteObject1, message->binderObject);
1948     EXPECT_TRUE(ret);
1949 
1950     DBinderSoftbusClient::GetInstance().sendBytesFunc_ = MockDBinderRemoteListener::SendBytes;
1951     PeerSocketInfo info;
1952     info.networkId = message->deviceIdInfo.fromDeviceId;
1953     int32_t socket = 1001;
1954     DBinderRemoteListener::ServerOnBind(socket, info);
1955 
1956     /* verify running into the transType invalid branch */
1957     std::shared_ptr<MockDBinderRemoteListener> mockListener = std::make_shared<MockDBinderRemoteListener>();
1958     dBinderService->remoteListener_ = std::static_pointer_cast<DBinderRemoteListener>(mockListener);
1959     EXPECT_TRUE(dBinderService->remoteListener_ != nullptr);
1960     dBinderService->LoadSystemAbilityComplete(srcNetworkId, systemAbilityId, remoteObject1);
1961     EXPECT_EQ(MockDBinderRemoteListener::GetInstance().GetResult(), SA_INVOKE_FAILED);
1962     dBinderService->remoteListener_ = nullptr;
1963     DBinderSoftbusClient::GetInstance().sendBytesFunc_ = nullptr;
1964     dBinderService->DetachProxyObject(message->binderObject);
1965 }
1966 
1967 /**
1968  * @tc.name: PopLoadSaItemTest004
1969  * @tc.desc: Verify the PopLoadSaItem function
1970  * @tc.type: FUNC
1971  */
1972 HWTEST_F(DBinderServiceUnitTest, PopLoadSaItemTest004, TestSize.Level1)
1973 {
1974     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1975     EXPECT_TRUE(dBinderService != nullptr);
1976 
1977     std::string srcNetworkId = "t";
1978     int32_t systemAbilityId = 1;
1979     std::shared_ptr<struct DHandleEntryTxRx> message = std::make_shared<DHandleEntryTxRx>();
1980     EXPECT_TRUE(message != nullptr);
1981     (void)memset_s(message.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
1982     message->binderObject = systemAbilityId;
1983     message->deviceIdInfo.fromDeviceId[0] = 't';
1984     message->transType = IRemoteObject::DATABUS_TYPE;
1985     dBinderService->loadSaReply_.push_back(message);
1986 
1987     /* verify running into the OnRemoteInvokerDataBusMessage fail branch */
1988     sptr<MockIPCObjectProxy> remoteObject1 = sptr<MockIPCObjectProxy>::MakeSptr();
1989     EXPECT_TRUE(remoteObject1 != nullptr);
1990     bool ret = dBinderService->AttachProxyObject(remoteObject1, message->binderObject);
1991     EXPECT_TRUE(ret);
1992 
1993     DBinderSoftbusClient::GetInstance().sendBytesFunc_ = MockDBinderRemoteListener::SendBytes;
1994     PeerSocketInfo info;
1995     info.networkId = message->deviceIdInfo.fromDeviceId;;
1996     int32_t socket = 1001;
1997     DBinderRemoteListener::ServerOnBind(socket, info);
1998 
1999     std::shared_ptr<MockDBinderRemoteListener> mockListener = std::make_shared<MockDBinderRemoteListener>();
2000     dBinderService->remoteListener_ = std::static_pointer_cast<DBinderRemoteListener>(mockListener);
2001     EXPECT_TRUE(dBinderService->remoteListener_ != nullptr);
2002     EXPECT_CALL(*remoteObject1, IsObjectDead()).WillOnce(testing::Return(true)).WillRepeatedly(testing::Return(false));
2003     dBinderService->LoadSystemAbilityComplete(srcNetworkId, systemAbilityId, remoteObject1);
2004     EXPECT_EQ(MockDBinderRemoteListener::GetInstance().GetResult(), SESSION_NAME_NOT_FOUND);
2005     dBinderService->remoteListener_ = nullptr;
2006     DBinderSoftbusClient::GetInstance().sendBytesFunc_ = nullptr;
2007     ret = dBinderService->DetachProxyObject(message->binderObject);
2008     EXPECT_TRUE(ret);
2009 }
2010 
2011 /**
2012  * @tc.name: SendReplyMessageToRemote001
2013  * @tc.desc: Verify the SendReplyMessageToRemote function
2014  * @tc.type: FUNC
2015  */
2016 HWTEST_F(DBinderServiceUnitTest, SendReplyMessageToRemote001, TestSize.Level1)
2017 {
2018     uint32_t dBinderCode = 4;
2019     uint32_t reason = 0;
2020     std::shared_ptr<DHandleEntryTxRx> replyMessage = std::make_shared<DHandleEntryTxRx>();
2021     EXPECT_TRUE(replyMessage != nullptr);
2022     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
2023     EXPECT_TRUE(dBinderService != nullptr);
2024     dBinderService->remoteListener_ = std::make_shared<DBinderRemoteListener>();
2025     EXPECT_TRUE(dBinderService->remoteListener_ != nullptr);
2026     dBinderService->SendReplyMessageToRemote(dBinderCode, reason, replyMessage);
2027     dBinderCode = 1;
2028     dBinderService->SendReplyMessageToRemote(dBinderCode, reason, replyMessage);
2029     DBinderService *temp = DBinderService::GetInstance();
2030     EXPECT_TRUE(temp != nullptr);
2031     DBinderService::instance_ = temp;
2032     dBinderService = DBinderService::GetInstance();
2033     EXPECT_TRUE(dBinderService != nullptr);
2034     EXPECT_EQ(dBinderService, DBinderService::instance_);
2035 }
2036 
2037 /**
2038  * @tc.name: CheckAndAmendSaId001
2039  * @tc.desc: Verify the CheckAndAmendSaId function
2040  * @tc.type: FUNC
2041  */
2042 HWTEST_F(DBinderServiceUnitTest, CheckAndAmendSaId001, TestSize.Level1)
2043 {
2044     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
2045     EXPECT_NE(dBinderService, nullptr);
2046 
2047     std::shared_ptr<struct DHandleEntryTxRx> message = std::make_shared<DHandleEntryTxRx>();
2048     EXPECT_TRUE(message != nullptr);
2049     (void)memset_s(message.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
2050 
2051     message->stubIndex = DBinderService::FIRST_SYS_ABILITY_ID - 1;
2052     message->binderObject = DBinderService::FIRST_SYS_ABILITY_ID;
2053     bool ret = dBinderService->CheckAndAmendSaId(message);
2054     EXPECT_TRUE(ret);
2055 
2056     message->stubIndex = DBinderService::FIRST_SYS_ABILITY_ID - 1;
2057     message->binderObject = DBinderService::FIRST_SYS_ABILITY_ID - 1;
2058     ret = dBinderService->CheckAndAmendSaId(message);
2059     EXPECT_FALSE(ret);
2060 }
2061 
2062 /**
2063  * @tc.name: AddAsynMessageTask001
2064  * @tc.desc: Verify the AddAsynMessageTask function
2065  * @tc.type: FUNC
2066  */
2067 HWTEST_F(DBinderServiceUnitTest, AddAsynMessageTask001, TestSize.Level1)
2068 {
2069     std::shared_ptr<struct DHandleEntryTxRx> message = std::make_shared<struct DHandleEntryTxRx>();
2070     EXPECT_NE(message.get(), nullptr);
2071     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
2072     EXPECT_TRUE(dBinderService != nullptr);
2073     dBinderService->AddAsynMessageTask(message);
2074 }
2075 
2076 /**
2077  * @tc.name: IsSameSession002
2078  * @tc.desc: Verify the IsSameSession function
2079  * @tc.type: FUNC
2080  */
2081 HWTEST_F(DBinderServiceUnitTest, IsSameSession002, TestSize.Level1)
2082 {
2083     std::shared_ptr<struct SessionInfo> oldSession= std::make_shared<struct SessionInfo>();
2084     EXPECT_NE(oldSession.get(), nullptr);
2085     std::shared_ptr<struct SessionInfo> newSession= std::make_shared<struct SessionInfo>();
2086     EXPECT_NE(newSession.get(), nullptr);
2087     oldSession->stubIndex = 1;
2088     oldSession->toPort = 2;
2089     oldSession->fromPort = 3;
2090     oldSession->type = 4;
2091     oldSession->serviceName[0] = 't';
2092     newSession->stubIndex = 2;
2093     newSession->toPort = 2;
2094     newSession->fromPort = 3;
2095     newSession->type = 4;
2096     newSession->serviceName[0] = 't';
2097     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
2098     EXPECT_TRUE(dBinderService != nullptr);
2099     EXPECT_EQ(dBinderService->IsSameSession(oldSession, newSession), false);
2100     newSession->stubIndex = 1;
2101     newSession->toPort = 12;
2102     EXPECT_EQ(dBinderService->IsSameSession(oldSession, newSession), false);
2103     newSession->toPort = 2;
2104     newSession->fromPort = 13;
2105     EXPECT_EQ(dBinderService->IsSameSession(oldSession, newSession), false);
2106     newSession->fromPort = 3;
2107     newSession->type = 14;
2108     EXPECT_EQ(dBinderService->IsSameSession(oldSession, newSession), false);
2109     newSession->type = 4;
2110     EXPECT_EQ(dBinderService->IsSameSession(oldSession, newSession), true);
2111 }
2112 
2113 /**
2114  * @tc.name: IsSameSession003
2115  * @tc.desc: Verify the IsSameSession function
2116  * @tc.type: FUNC
2117  */
2118 HWTEST_F(DBinderServiceUnitTest, IsSameSession003, TestSize.Level1)
2119 {
2120     std::shared_ptr<struct SessionInfo> oldSession= std::make_shared<struct SessionInfo>();
2121     EXPECT_NE(oldSession.get(), nullptr);
2122     std::shared_ptr<struct SessionInfo> newSession= std::make_shared<struct SessionInfo>();
2123     EXPECT_NE(newSession.get(), nullptr);
2124 
2125     oldSession->stubIndex = 1;
2126     oldSession->toPort = 2;
2127     oldSession->fromPort = 3;
2128     oldSession->type = 4;
2129     oldSession->serviceName[0] = 't';
2130     oldSession->deviceIdInfo.fromDeviceId[0] = 'a';
2131 
2132     newSession->stubIndex = oldSession->stubIndex;
2133     newSession->toPort = oldSession->toPort;
2134     newSession->fromPort = oldSession->fromPort;
2135     newSession->type = oldSession->type;
2136     newSession->serviceName[0] = 't';
2137     newSession->deviceIdInfo.fromDeviceId[0] = 'b';
2138 
2139     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
2140     EXPECT_TRUE(dBinderService != nullptr);
2141 
2142     bool ret = dBinderService->IsSameSession(oldSession, newSession);
2143     EXPECT_FALSE(ret);
2144 }
2145 
2146 /**
2147  * @tc.name: AttachSessionObject001
2148  * @tc.desc: Verify the AttachSessionObject function
2149  * @tc.type: FUNC
2150  */
2151 HWTEST_F(DBinderServiceUnitTest, AttachSessionObject001, TestSize.Level1)
2152 {
2153     std::shared_ptr<struct SessionInfo> object = nullptr;
2154     binder_uintptr_t stub = 0;
2155     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
2156     EXPECT_TRUE(dBinderService != nullptr);
2157     dBinderService->sessionObject_.clear();
2158     EXPECT_EQ(dBinderService->AttachSessionObject(object, stub), true);
2159 }
2160 
2161 /**
2162  * @tc.name: CheckInvokeListenThreadIllegal001
2163  * @tc.desc: Verify the CheckInvokeListenThreadIllegal function
2164  * @tc.type: FUNC
2165  */
2166 HWTEST_F(DBinderServiceUnitTest, CheckInvokeListenThreadIllegal001, TestSize.Level1)
2167 {
2168     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
2169     EXPECT_NE(dBinderService, nullptr);
2170 
2171     IPCObjectProxy object(TEST_OBJECT_HANDLE);
2172     MessageParcel data;
2173     MessageParcel reply;
2174     bool ret = dBinderService->CheckInvokeListenThreadIllegal(&object, data, reply);
2175     EXPECT_TRUE(ret);
2176 }
2177 
2178 /**
2179  * @tc.name: CheckStubIndexAndSessionNameIllegal001
2180  * @tc.desc: Verify the CheckStubIndexAndSessionNameIllegal function
2181  * @tc.type: FUNC
2182  */
2183 HWTEST_F(DBinderServiceUnitTest, CheckStubIndexAndSessionNameIllegal001, TestSize.Level1)
2184 {
2185     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
2186     EXPECT_NE(dBinderService, nullptr);
2187 
2188     uint64_t stubIndex = 0;
2189     std::string serverSessionName;
2190     std::string deviceId;
2191     IPCObjectProxy proxy(TEST_OBJECT_HANDLE);
2192     bool ret = dBinderService->CheckStubIndexAndSessionNameIllegal(stubIndex, serverSessionName, deviceId, &proxy);
2193     EXPECT_TRUE(ret);
2194 
2195     stubIndex = 1;
2196     serverSessionName = "abc";
2197     ret = dBinderService->CheckStubIndexAndSessionNameIllegal(stubIndex, serverSessionName, deviceId, &proxy);
2198     EXPECT_FALSE(ret);
2199 }
2200 
2201 /**
2202  * @tc.name: SetReplyMessage001
2203  * @tc.desc: Verify the SetReplyMessage function
2204  * @tc.type: FUNC
2205  */
2206 HWTEST_F(DBinderServiceUnitTest, SetReplyMessage001, TestSize.Level1)
2207 {
2208     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
2209     EXPECT_NE(dBinderService, nullptr);
2210 
2211     auto replyMessage = std::make_shared<struct DHandleEntryTxRx>();
2212     (void)memset_s(replyMessage.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
2213     replyMessage->head.version = RPC_TOKENID_SUPPORT_VERSION + 1;
2214 
2215     uint64_t stubIndex = 0;
2216     std::string serverSessionName(SERVICENAME_LENGTH + 1, 'a');
2217     uint32_t selfTokenId = 0;
2218     IPCObjectProxy proxy(TEST_OBJECT_HANDLE);
2219     bool ret = dBinderService->SetReplyMessage(replyMessage, stubIndex, serverSessionName, selfTokenId, &proxy);
2220     EXPECT_FALSE(ret);
2221 
2222     serverSessionName = string(SERVICENAME_LENGTH - 1, 'a');
2223     ret = dBinderService->SetReplyMessage(replyMessage, stubIndex, serverSessionName, selfTokenId, &proxy);
2224     EXPECT_TRUE(ret);
2225 }
2226 
2227 /**
2228  * @tc.name: IsInvalidStub001
2229  * @tc.desc: Verify the IsInvalidStub function
2230  * @tc.type: FUNC
2231  */
2232 HWTEST_F(DBinderServiceUnitTest, IsInvalidStub001, TestSize.Level1)
2233 {
2234     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
2235     EXPECT_NE(dBinderService, nullptr);
2236 
2237     const std::u16string serviceName = u"abc";
2238     const std::string deviceID = "bcd";
2239     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
2240     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID, binderObject);
2241     EXPECT_NE(stub, nullptr);
2242 
2243     binder_uintptr_t binderObjectPtr = reinterpret_cast<binder_uintptr_t>(stub.GetRefPtr());
2244     binder_uintptr_t stubTag = dBinderService->stubTagNum_++;
2245     auto result = dBinderService->mapDBinderStubRegisters_.insert({stubTag, binderObjectPtr});
2246     EXPECT_TRUE(result.second);
2247 
2248     dBinderService->DBinderStubRegisted_.push_back(stub);
2249 
2250     auto replyMessage = std::make_shared<struct DHandleEntryTxRx>();
2251     (void)memset_s(replyMessage.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
2252     replyMessage->stub = stubTag;
2253 
2254     bool ret = dBinderService->IsInvalidStub(replyMessage);
2255     EXPECT_FALSE(ret);
2256 }
2257 
2258 /**
2259  * @tc.name: CopyDeviceIdInfo001
2260  * @tc.desc: Verify the CopyDeviceIdInfo function
2261  * @tc.type: FUNC
2262  */
2263 HWTEST_F(DBinderServiceUnitTest, CopyDeviceIdInfo001, TestSize.Level1)
2264 {
2265     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
2266     EXPECT_NE(dBinderService, nullptr);
2267 
2268     auto session = std::make_shared<SessionInfo>();
2269 
2270     auto replyMessage = std::make_shared<struct DHandleEntryTxRx>();
2271     (void)memset_s(replyMessage.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
2272 
2273     dBinderService->InitializeSession(session, replyMessage);
2274     bool ret = dBinderService->CopyDeviceIdInfo(session, replyMessage);
2275     EXPECT_TRUE(ret);
2276 }
2277 
2278 /**
2279  * @tc.name: MakeSessionByReplyMessage001
2280  * @tc.desc: Verify the MakeSessionByReplyMessage function
2281  * @tc.type: FUNC
2282  */
2283 HWTEST_F(DBinderServiceUnitTest, MakeSessionByReplyMessage001, TestSize.Level1)
2284 {
2285     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
2286     EXPECT_NE(dBinderService, nullptr);
2287 
2288     const std::u16string serviceName = u"abc";
2289     const std::string deviceID = "bcd";
2290     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
2291     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID, binderObject);
2292     EXPECT_NE(stub, nullptr);
2293     binder_uintptr_t binderObjectPtr = reinterpret_cast<binder_uintptr_t>(stub.GetRefPtr());
2294     binder_uintptr_t stubTag = dBinderService->AddStubByTag(binderObjectPtr);
2295     EXPECT_GT(stubTag, 0);
2296 
2297     dBinderService->DBinderStubRegisted_.push_back(stub);
2298 
2299     auto replyMessage = std::make_shared<struct DHandleEntryTxRx>();
2300     (void)memset_s(replyMessage.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
2301 
2302     replyMessage->dBinderCode = MESSAGE_AS_REPLY;
2303     replyMessage->stubIndex = 0;
2304     dBinderService->MakeSessionByReplyMessage(replyMessage);
2305 
2306     replyMessage->stubIndex = 1;
2307     dBinderService->MakeSessionByReplyMessage(replyMessage);
2308 
2309     replyMessage->stub = binderObjectPtr;
2310     dBinderService->MakeSessionByReplyMessage(replyMessage);
2311 }
2312 
2313 /**
2314  * @tc.name: NoticeServiceDie001
2315  * @tc.desc: Verify the NoticeServiceDie function
2316  * @tc.type: FUNC
2317  */
2318 HWTEST_F(DBinderServiceUnitTest, NoticeServiceDie001, TestSize.Level1)
2319 {
2320     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
2321     EXPECT_NE(dBinderService, nullptr);
2322 
2323     std::u16string serviceName;
2324     std::string deviceID;
2325 
2326     int32_t ret = dBinderService->NoticeServiceDie(serviceName, deviceID);
2327     EXPECT_EQ(ret, DBINDER_SERVICE_INVALID_DATA_ERR);
2328 }
2329 
2330 
2331 /**
2332  * @tc.name: IsValidSessionName001
2333  * @tc.desc: Verify the IsValidSessionName function
2334  * @tc.type: FUNC
2335  */
2336 HWTEST_F(DBinderServiceUnitTest, IsValidSessionName001, TestSize.Level1)
2337 {
2338     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
2339     EXPECT_NE(dBinderService, nullptr);
2340 
2341     auto replyMessage = std::make_shared<struct DHandleEntryTxRx>();
2342     (void)memset_s(replyMessage.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
2343 
2344     // empty sessionName
2345     replyMessage->serviceNameLength = 0;
2346     (void)memset_s(replyMessage->serviceName, SERVICENAME_LENGTH + 1, 0, SERVICENAME_LENGTH + 1);
2347     bool ret = dBinderService->IsValidSessionName(replyMessage);
2348     ASSERT_TRUE(ret);
2349 
2350     // serviceNameLength > SERVICENAME_LENGTH
2351     replyMessage->serviceNameLength = SERVICENAME_LENGTH + 1;
2352     ret = dBinderService->IsValidSessionName(replyMessage);
2353     ASSERT_FALSE(ret);
2354 
2355     // testName length < serviceNameLength < SERVICENAME_LENGTH
2356     std::string testName = "abc";
2357     replyMessage->serviceNameLength = testName.size() + 1;
2358     ASSERT_EQ(strcpy_s(replyMessage->serviceName, SERVICENAME_LENGTH + 1, testName.c_str()), EOK);
2359     ret = dBinderService->IsValidSessionName(replyMessage);
2360     ASSERT_FALSE(ret);
2361 
2362     // serviceNameLength == testName length
2363     replyMessage->serviceNameLength = testName.size();
2364     ret = dBinderService->IsValidSessionName(replyMessage);
2365     ASSERT_TRUE(ret);
2366 }
2367 
2368 /**
2369  * @tc.name: InvokerRemoteDBinderWhenRequest001
2370  * @tc.desc: Verify the InvokerRemoteDBinderWhenRequest function
2371  * @tc.type: FUNC
2372  */
2373 HWTEST_F(DBinderServiceUnitTest, InvokerRemoteDBinderWhenRequest001, TestSize.Level1)
2374 {
2375     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
2376     EXPECT_NE(dBinderService, nullptr);
2377 
2378     std::u16string serviceName(u"abcd");
2379     std::string deviceID("001");
2380     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
2381     uint32_t pid = TEST_PID;
2382     uint32_t uid = TEST_UID;
2383     uint32_t seqNumber = 0;
2384     std::shared_ptr<struct ThreadLockInfo> threadLockInfo;
2385 
2386     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID,
2387         binderObject, pid, uid);
2388     EXPECT_NE(stub, nullptr);
2389     dBinderService->threadLockInfo_[seqNumber] = threadLockInfo;
2390     int32_t ret = dBinderService->InvokerRemoteDBinderWhenRequest(stub, seqNumber, pid, uid, threadLockInfo);
2391     EXPECT_EQ(ret, MAKE_THREADLOCK_FAILED);
2392     dBinderService->threadLockInfo_.clear();
2393 
2394     ret = dBinderService->InvokerRemoteDBinderWhenRequest(stub, seqNumber, pid, uid, threadLockInfo);
2395     EXPECT_EQ(ret, SEND_MESSAGE_FAILED);
2396 }
2397 
2398 /**
2399  * @tc.name: InvokerRemoteDBinderWhenWaitRsp001
2400  * @tc.desc: Verify the InvokerRemoteDBinderWhenWaitRsp function
2401  * @tc.type: FUNC
2402  */
2403 HWTEST_F(DBinderServiceUnitTest, InvokerRemoteDBinderWhenWaitRsp001, TestSize.Level1)
2404 {
2405     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
2406     EXPECT_NE(dBinderService, nullptr);
2407 
2408     std::u16string serviceName(u"abcd");
2409     std::string deviceID("001");
2410     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
2411     uint32_t pid = TEST_PID;
2412     uint32_t uid = TEST_UID;
2413     uint32_t seqNumber = 0;
2414     std::shared_ptr<struct ThreadLockInfo> threadLockInfo;
2415 
2416     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID,
2417         binderObject, pid, uid);
2418     EXPECT_NE(stub, nullptr);
2419     int32_t ret = dBinderService->InvokerRemoteDBinderWhenWaitRsp(stub, seqNumber, pid, uid, threadLockInfo);
2420     EXPECT_EQ(ret, MAKE_THREADLOCK_FAILED);
2421     threadLockInfo = std::make_shared<struct ThreadLockInfo>();
2422     dBinderService->threadLockInfo_[seqNumber] = threadLockInfo;
2423     ret = dBinderService->InvokerRemoteDBinderWhenWaitRsp(stub, seqNumber, pid, uid, threadLockInfo);
2424     EXPECT_EQ(ret, DBINDER_OK);
2425     dBinderService->threadLockInfo_.clear();
2426 }
2427 
2428 /**
2429  * @tc.name: ProcessCallbackProxyInner001
2430  * @tc.desc: Verify the ProcessCallbackProxyInner function
2431  * @tc.type: FUNC
2432  */
2433 HWTEST_F(DBinderServiceUnitTest, ProcessCallbackProxyInner001, TestSize.Level1)
2434 {
2435     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
2436     EXPECT_NE(dBinderService, nullptr);
2437 
2438     dBinderService->ProcessCallbackProxyInner(nullptr, nullptr);
2439 
2440     std::u16string serviceName(u"abcd");
2441     std::string deviceID("001");
2442     binder_uintptr_t binderObject = TEST_BINDER_OBJECT_PTR;
2443     uint32_t pid = TEST_PID;
2444     uint32_t uid = TEST_UID;
2445     std::shared_ptr<struct ThreadLockInfo> threadLockInfo;
2446 
2447     sptr<DBinderServiceStub> stub = new (std::nothrow) DBinderServiceStub(serviceName, deviceID,
2448         binderObject, pid, uid);
2449     EXPECT_NE(stub, nullptr);
2450     sptr<IRemoteObject> proxy = new (std::nothrow) IPCObjectProxy(0);
2451     EXPECT_NE(proxy, nullptr);
2452     dBinderService->ProcessCallbackProxyInner(stub, proxy);
2453 }