1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "ipc_types.h"
16 #include "iremote_object.h"
17 #include "log_tags.h"
18 #include "message_parcel.h"
19 #include "rpc_log.h"
20 #include "gtest/gtest.h"
21 #include <iostream>
22 
23 #define private public
24 #define protected public
25 #include "dbinder_service.h"
26 #include "dbinder_service_stub.h"
27 #undef protected
28 #undef private
29 
30 using namespace testing::ext;
31 using namespace OHOS;
32 using namespace OHOS::HiviewDFX;
33 
34 namespace {
35     constexpr binder_uintptr_t BINDER_OBJECT = 11;
36     constexpr uint32_t PROCESS_PROTO_CODE = 11;
37     constexpr uint32_t SESSION_TYPE_UNKNOWN = 99;
38     constexpr int32_t UNKNOWN_TRANSACTION_CODE = 999;
39 }
40 
41 typedef unsigned long long binder_uintptr_t;
42 class DBinderServiceStubUnitTest : public testing::Test {
43 public:
44     static void SetUpTestCase(void);
45     static void TearDownTestCase(void);
46     void SetUp();
47     void TearDown();
48 };
49 
SetUp()50 void DBinderServiceStubUnitTest::SetUp()
51 {}
52 
TearDown()53 void DBinderServiceStubUnitTest::TearDown()
54 {}
55 
SetUpTestCase()56 void DBinderServiceStubUnitTest::SetUpTestCase()
57 {}
58 
TearDownTestCase()59 void DBinderServiceStubUnitTest::TearDownTestCase()
60 {}
61 
62 /**
63  * @tc.name: DBinderServiceStub001
64  * @tc.desc: Verify the DBinderServiceStub function
65  * @tc.type: FUNC
66  */
67 HWTEST_F(DBinderServiceStubUnitTest, DBinderServiceStub001, TestSize.Level1)
68 {
69     const std::string service = "serviceTest";
70     const std::string device = "deviceTest";
71     binder_uintptr_t object = BINDER_OBJECT;
72     DBinderServiceStub dBinderServiceStub(service, device, object);
73     int32_t num = dBinderServiceStub.GetObjectRefCount();
74     EXPECT_NE(num, 0);
75 }
76 
77 /**
78  * @tc.name: DBinderServiceStub002
79  * @tc.desc: Verify the DBinderServiceStub function
80  * @tc.type: FUNC
81  */
82 HWTEST_F(DBinderServiceStubUnitTest, DBinderServiceStub002, TestSize.Level1)
83 {
84     const std::string service = "";
85     const std::string device = "deviceTest";
86     binder_uintptr_t object = BINDER_OBJECT;
87     DBinderServiceStub dBinderServiceStub(service, device, object);
88     int32_t num = dBinderServiceStub.GetObjectRefCount();
89     EXPECT_NE(num, 0);
90 }
91 
92 /**
93  * @tc.name: DBinderServiceStub003
94  * @tc.desc: Verify the DBinderServiceStub function
95  * @tc.type: FUNC
96  */
97 HWTEST_F(DBinderServiceStubUnitTest, DBinderServiceStub003, TestSize.Level1)
98 {
99     const std::string service = "serviceTest";
100     const std::string device = "";
101     binder_uintptr_t object = BINDER_OBJECT;
102     DBinderServiceStub dBinderServiceStub(service, device, object);
103     int32_t num = dBinderServiceStub.GetObjectRefCount();
104     EXPECT_NE(num, 0);
105 }
106 
107 /**
108  * @tc.name: DBinderServiceStub004
109  * @tc.desc: Verify the DBinderServiceStub function
110  * @tc.type: FUNC
111  */
112 HWTEST_F(DBinderServiceStubUnitTest, DBinderServiceStub004, TestSize.Level1)
113 {
114     const std::string service = "serviceTest";
115     const std::string device = "deviceTest";
116     binder_uintptr_t object = UINT_MAX;
117     DBinderServiceStub dBinderServiceStub(service, device, object);
118     int32_t num = dBinderServiceStub.GetObjectRefCount();
119     EXPECT_NE(num, 0);
120 }
121 
122 
123 /**
124  * @tc.name: GetServiceName001
125  * @tc.desc: Verify the GetServiceName function
126  * @tc.type: FUNC
127  */
128 HWTEST_F(DBinderServiceStubUnitTest, GetServiceName001, TestSize.Level1)
129 {
130     const std::string service = "serviceTest";
131     const std::string device = "deviceTest";
132     binder_uintptr_t object = BINDER_OBJECT;
133     DBinderServiceStub dBinderServiceStub(service, device, object);
134     std::string ret = dBinderServiceStub.GetServiceName();
135     EXPECT_EQ(ret, "serviceTest");
136 }
137 
138 /**
139  * @tc.name: GetServiceName002
140  * @tc.desc: Verify the GetServiceName function
141  * @tc.type: FUNC
142  */
143 HWTEST_F(DBinderServiceStubUnitTest, GetServiceName002, TestSize.Level1)
144 {
145     const std::string service;
146     const std::string device = "deviceTest";
147     binder_uintptr_t object = BINDER_OBJECT;
148     DBinderServiceStub dBinderServiceStub(service, device, object);
149     std::string ret = dBinderServiceStub.GetServiceName();
150     EXPECT_EQ(ret, "");
151 }
152 
153 /**
154  * @tc.name: GetDeviceID001
155  * @tc.desc: Verify the GetDeviceID function
156  * @tc.type: FUNC
157  */
158 HWTEST_F(DBinderServiceStubUnitTest, GetDeviceID001, TestSize.Level1)
159 {
160     const std::string service = "serviceTest";
161     const std::string device = "deviceTest";
162     binder_uintptr_t object = BINDER_OBJECT;
163     DBinderServiceStub dBinderServiceStub(service, device, object);
164     std::string ret = dBinderServiceStub.GetDeviceID();
165     EXPECT_EQ(ret, "deviceTest");
166 }
167 
168 /**
169  * @tc.name: GetDeviceID002
170  * @tc.desc: Verify the GetDeviceID function
171  * @tc.type: FUNC
172  */
173 HWTEST_F(DBinderServiceStubUnitTest, GetDeviceID002, TestSize.Level1)
174 {
175     const std::string service = "serviceTest";
176     const std::string device;
177     binder_uintptr_t object = BINDER_OBJECT;
178     DBinderServiceStub dBinderServiceStub(service, device, object);
179     std::string ret = dBinderServiceStub.GetDeviceID();
180     EXPECT_EQ(ret, "");
181 }
182 
183 /**
184  * @tc.name: GetBinderObject001
185  * @tc.desc: Verify the GetBinderObject function
186  * @tc.type: FUNC
187  */
188 HWTEST_F(DBinderServiceStubUnitTest, GetBinderObject001, TestSize.Level1)
189 {
190     const std::string service = "serviceTest";
191     const std::string device = "deviceTest";
192     binder_uintptr_t object = BINDER_OBJECT;
193     DBinderServiceStub dBinderServiceStub(service, device, object);
194     binder_uintptr_t ret = dBinderServiceStub.GetBinderObject();
195     EXPECT_EQ(ret, BINDER_OBJECT);
196 }
197 
198 /**
199  * @tc.name: GetBinderObject002
200  * @tc.desc: Verify the GetBinderObject function
201  * @tc.type: FUNC
202  */
203 HWTEST_F(DBinderServiceStubUnitTest, GetBinderObject002, TestSize.Level1)
204 {
205     const std::string service = "serviceTest";
206     const std::string device = "deviceTest";
207     binder_uintptr_t object = UINT_MAX;
208     DBinderServiceStub dBinderServiceStub(service, device, object);
209     binder_uintptr_t ret = dBinderServiceStub.GetBinderObject();
210     EXPECT_EQ(ret, UINT_MAX);
211 }
212 
213 /**
214  * @tc.name: ProcessProto001
215  * @tc.desc: Verify the ProcessProto function
216  * @tc.type: FUNC
217  */
218 HWTEST_F(DBinderServiceStubUnitTest, ProcessProto001, TestSize.Level1)
219 {
220     const std::string service = "serviceTest";
221     const std::string device = "deviceTest";
222     binder_uintptr_t object = BINDER_OBJECT;
223     DBinderServiceStub dBinderServiceStub(service, device, object);
224     uint32_t code = PROCESS_PROTO_CODE;
225     MessageParcel data;
226     MessageParcel reply;
227     MessageOption option;
228     int32_t ret = dBinderServiceStub.ProcessProto(code, data, reply, option);
229     EXPECT_EQ(ret, DBINDER_SERVICE_PROCESS_PROTO_ERR);
230 }
231 
232 /**
233  * @tc.name: ProcessProto002
234  * @tc.desc: Verify the ProcessProto function
235  * @tc.type: FUNC
236  */
237 HWTEST_F(DBinderServiceStubUnitTest, ProcessProto002, TestSize.Level1)
238 {
239     const std::string service = "serviceTest";
240     const std::string device = "deviceTest";
241     binder_uintptr_t object = BINDER_OBJECT;
242     DBinderServiceStub dBinderServiceStub(service, device, object);
243     binder_uintptr_t key = reinterpret_cast<binder_uintptr_t>(&dBinderServiceStub);
244     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
245     EXPECT_TRUE(dBinderService != nullptr);
246     std::shared_ptr<struct SessionInfo> sessionInfo = std::make_shared<struct SessionInfo>();
247     EXPECT_TRUE(sessionInfo != nullptr);
248     dBinderService->sessionObject_[key] = sessionInfo;
249     uint32_t code = PROCESS_PROTO_CODE;
250     MessageParcel data;
251     MessageParcel reply;
252     MessageOption option;
253     int32_t ret = dBinderServiceStub.ProcessProto(code, data, reply, option);
254     EXPECT_EQ(ret, DBINDER_SERVICE_PROCESS_PROTO_ERR);
255 }
256 
257 /**
258  * @tc.name: ProcessProto003
259  * @tc.desc: Verify the ProcessProto function
260  * @tc.type: FUNC
261  */
262 HWTEST_F(DBinderServiceStubUnitTest, ProcessProto003, TestSize.Level1)
263 {
264     const std::string service = "serviceTest";
265     const std::string device = "deviceTest";
266     binder_uintptr_t object = BINDER_OBJECT;
267     DBinderServiceStub dBinderServiceStub(service, device, object);
268     uint32_t code = PROCESS_PROTO_CODE;
269     MessageParcel data;
270     MessageParcel reply;
271     MessageOption option;
272     int32_t ret = dBinderServiceStub.ProcessProto(code, data, reply, option);
273     EXPECT_EQ(ret, DBINDER_SERVICE_PROCESS_PROTO_ERR);
274 }
275 
276 /**
277  * @tc.name: ProcessProto004
278  * @tc.desc: Verify the ProcessProto function with unknown session type
279  * @tc.type: FUNC
280  */
281 HWTEST_F(DBinderServiceStubUnitTest, ProcessProto004, TestSize.Level1)
282 {
283     const std::string service = "serviceTest";
284     const std::string device = "deviceTest";
285     binder_uintptr_t object = BINDER_OBJECT;
286     DBinderServiceStub dBinderServiceStub(service, device, object);
287 
288     uint32_t code = PROCESS_PROTO_CODE;
289     MessageParcel data;
290     MessageParcel reply;
291     MessageOption option;
292 
293     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
294     EXPECT_TRUE(dBinderService != nullptr);
295     binder_uintptr_t key = reinterpret_cast<binder_uintptr_t>(&dBinderServiceStub);
296     std::shared_ptr<struct SessionInfo> sessionInfo = std::make_shared<struct SessionInfo>();
297     EXPECT_TRUE(sessionInfo != nullptr);
298     sessionInfo->type = SESSION_TYPE_UNKNOWN;
299     dBinderService->sessionObject_[key] = sessionInfo;
300 
301     int32_t ret = dBinderServiceStub.ProcessProto(code, data, reply, option);
302     EXPECT_EQ(ret, DBINDER_SERVICE_PROCESS_PROTO_ERR);
303 }
304 
305 /**
306  * @tc.name: ProcessProto005
307  * @tc.desc: Verify the ProcessProto function
308  * @tc.type: FUNC
309  */
310 HWTEST_F(DBinderServiceStubUnitTest, ProcessProto005, TestSize.Level1)
311 {
312     const std::string service = "serviceTest";
313     const std::string device = "deviceTest";
314     binder_uintptr_t object = BINDER_OBJECT;
315     DBinderServiceStub dBinderServiceStub(service, device, object);
316     uint32_t code = UINT_MAX;
317     MessageParcel data;
318     MessageParcel reply;
319     MessageOption option;
320     int32_t ret = dBinderServiceStub.ProcessProto(code, data, reply, option);
321     EXPECT_EQ(ret, DBINDER_SERVICE_PROCESS_PROTO_ERR);
322 }
323 
324 /**
325  * @tc.name: OnRemoteRequest001
326  * @tc.desc: Verify the OnRemoteRequest function
327  * @tc.type: FUNC
328  */
329 HWTEST_F(DBinderServiceStubUnitTest, OnRemoteRequest001, TestSize.Level1)
330 {
331     const std::string service = "serviceTest";
332     const std::string device = "deviceTest";
333     binder_uintptr_t object = BINDER_OBJECT;
334     DBinderServiceStub dBinderServiceStub(service, device, object);
335 
336     uint32_t code = GET_PROTO_INFO;
337     MessageParcel data;
338     MessageParcel reply;
339     MessageOption option;
340     int32_t ret = dBinderServiceStub.OnRemoteRequest(code, data, reply, option);
341     EXPECT_EQ(ret, DBINDER_SERVICE_PROCESS_PROTO_ERR);
342 }
343 
344 /**
345  * @tc.name: OnRemoteRequest002
346  * @tc.desc: Verify the OnRemoteRequest function
347  * @tc.type: FUNC
348  */
349 HWTEST_F(DBinderServiceStubUnitTest, OnRemoteRequest002, TestSize.Level1)
350 {
351     const std::string service = "serviceTest";
352     const std::string device = "deviceTest";
353     binder_uintptr_t object = BINDER_OBJECT;
354     DBinderServiceStub dBinderServiceStub(service, device, object);
355 
356     uint32_t code = DBINDER_OBITUARY_TRANSACTION;
357     MessageParcel data;
358     MessageParcel reply;
359     MessageOption option;
360     int32_t ret = dBinderServiceStub.OnRemoteRequest(code, data, reply, option);
361     EXPECT_EQ(ret, DBINDER_SERVICE_INVALID_DATA_ERR);
362 }
363 
364 /**
365  * @tc.name: OnRemoteRequest003
366  * @tc.desc: Verify the OnRemoteRequest function
367  * @tc.type: FUNC
368  */
369 HWTEST_F(DBinderServiceStubUnitTest, OnRemoteRequest003, TestSize.Level1)
370 {
371     const std::string service = "serviceTest";
372     const std::string device = "deviceTest";
373     binder_uintptr_t object = BINDER_OBJECT;
374     DBinderServiceStub dBinderServiceStub(service, device, object);
375 
376     uint32_t code = PROCESS_PROTO_CODE;
377     MessageParcel data;
378     MessageParcel reply;
379     MessageOption option;
380     int32_t ret = dBinderServiceStub.OnRemoteRequest(code, data, reply, option);
381     EXPECT_EQ(ret, DBINDER_SERVICE_UNKNOW_TRANS_ERR);
382 }
383 
384 /**
385  * @tc.name: ProcessDeathRecipient001
386  * @tc.desc: Verify the ProcessDeathRecipient function
387  * @tc.type: FUNC
388  */
389 HWTEST_F(DBinderServiceStubUnitTest, ProcessDeathRecipient001, TestSize.Level1)
390 {
391     const std::string service = "serviceTest";
392     const std::string device = "deviceTest";
393     binder_uintptr_t object = BINDER_OBJECT;
394     DBinderServiceStub dBinderServiceStub(service, device, object);
395 
396     MessageParcel data;
397     data.WriteInt32(IRemoteObject::DeathRecipient::ADD_DEATH_RECIPIENT);
398     int32_t ret = dBinderServiceStub.ProcessDeathRecipient(data);
399     EXPECT_EQ(ret, DBINDER_SERVICE_INVALID_DATA_ERR);
400 }
401 
402 /**
403  * @tc.name: ProcessDeathRecipient002
404  * @tc.desc: Verify the ProcessDeathRecipient function
405  * @tc.type: FUNC
406  */
407 HWTEST_F(DBinderServiceStubUnitTest, ProcessDeathRecipient002, TestSize.Level1)
408 {
409     const std::string service = "serviceTest";
410     const std::string device = "deviceTest";
411     binder_uintptr_t object = BINDER_OBJECT;
412     DBinderServiceStub dBinderServiceStub(service, device, object);
413 
414     MessageParcel data;
415     data.WriteInt32(IRemoteObject::DeathRecipient::REMOVE_DEATH_RECIPIENT);
416     int32_t ret = dBinderServiceStub.ProcessDeathRecipient(data);
417     EXPECT_EQ(ret, DBINDER_SERVICE_REMOVE_DEATH_ERR);
418 }
419 
420 /**
421  * @tc.name: ProcessDeathRecipient003
422  * @tc.desc: Verify the ProcessDeathRecipient function with unknown type
423  * @tc.type: FUNC
424  */
425 HWTEST_F(DBinderServiceStubUnitTest, ProcessDeathRecipient003, TestSize.Level1)
426 {
427     const std::string service = "serviceTest";
428     const std::string device = "deviceTest";
429     binder_uintptr_t object = BINDER_OBJECT;
430     DBinderServiceStub dBinderServiceStub(service, device, object);
431 
432     MessageParcel data;
433     data.WriteInt32(UNKNOWN_TRANSACTION_CODE);
434 
435     int32_t ret = dBinderServiceStub.ProcessDeathRecipient(data);
436     EXPECT_EQ(ret, DBINDER_SERVICE_UNKNOW_TRANS_ERR);
437 }
438 
439 /**
440  * @tc.name: ProcessDeathRecipient004
441  * @tc.desc: Verify the ProcessDeathRecipient function with unknown type
442  * @tc.type: FUNC
443  */
444 HWTEST_F(DBinderServiceStubUnitTest, ProcessDeathRecipient004, TestSize.Level1)
445 {
446     const std::string service = "serviceTest";
447     const std::string device = "deviceTest";
448     binder_uintptr_t object = BINDER_OBJECT;
449     DBinderServiceStub dBinderServiceStub(service, device, object);
450 
451     MessageParcel data;
452     data.WriteString("");
453 
454     int32_t ret = dBinderServiceStub.ProcessDeathRecipient(data);
455     EXPECT_EQ(ret, DBINDER_SERVICE_INVALID_DATA_ERR);
456 }
457 
458 /**
459  * @tc.name: AddDbinderDeathRecipient001
460  * @tc.desc: Verify the AddDbinderDeathRecipient function
461  * @tc.type: FUNC
462  */
463 HWTEST_F(DBinderServiceStubUnitTest, AddDbinderDeathRecipient001, TestSize.Level1)
464 {
465     const std::string service = "serviceTest";
466     const std::string device = "deviceTest";
467     binder_uintptr_t object = BINDER_OBJECT;
468     DBinderServiceStub dBinderServiceStub(service, device, object);
469     MessageParcel data;
470     int32_t ret = dBinderServiceStub.AddDbinderDeathRecipient(data);
471     EXPECT_EQ(ret, DBINDER_SERVICE_INVALID_DATA_ERR);
472 }
473 
474 /**
475  * @tc.name: AddDbinderDeathRecipient002
476  * @tc.desc: Verify the AddDbinderDeathRecipient function
477  * @tc.type: FUNC
478  */
479 HWTEST_F(DBinderServiceStubUnitTest, AddDbinderDeathRecipient002, TestSize.Level1)
480 {
481     const std::string service = "serviceTest";
482     const std::string device = "deviceTest";
483     binder_uintptr_t object = BINDER_OBJECT;
484     DBinderServiceStub dBinderServiceStub(service, device, object);
485 
486     sptr<IPCObjectStub> callbackStub = new (std::nothrow) IPCObjectStub(u"testStub");
487     EXPECT_TRUE(callbackStub != nullptr);
488     MessageParcel data;
489     data.WriteRemoteObject(callbackStub);
490     data.WriteString("");
491     int32_t ret = dBinderServiceStub.AddDbinderDeathRecipient(data);
492     EXPECT_EQ(ret, DBINDER_SERVICE_ADD_DEATH_ERR);
493 }
494 
495 /**
496  * @tc.name: AddDbinderDeathRecipient003
497  * @tc.desc: Verify the AddDbinderDeathRecipient function
498  * @tc.type: FUNC
499  */
500 HWTEST_F(DBinderServiceStubUnitTest, AddDbinderDeathRecipient003, TestSize.Level1)
501 {
502     const std::string service = "serviceTest";
503     const std::string device = "deviceTest";
504     binder_uintptr_t object = BINDER_OBJECT;
505     DBinderServiceStub dBinderServiceStub(service, device, object);
506 
507     sptr<IPCObjectStub> callbackStub = new (std::nothrow) IPCObjectStub(u"testStub");
508     EXPECT_TRUE(callbackStub != nullptr);
509     MessageParcel data;
510     data.WriteRemoteObject(callbackStub);
511     data.WriteString("test");
512     int32_t ret = dBinderServiceStub.AddDbinderDeathRecipient(data);
513     EXPECT_EQ(ret, DBINDER_SERVICE_ADD_DEATH_ERR);
514 }
515 
516 /**
517  * @tc.name: AddDbinderDeathRecipient004
518  * @tc.desc: Verify the AddDbinderDeathRecipient function
519  * @tc.type: FUNC
520  */
521 HWTEST_F(DBinderServiceStubUnitTest, AddDbinderDeathRecipient004, TestSize.Level1)
522 {
523     const std::string service = "serviceTest";
524     const std::string device = "deviceTest";
525     binder_uintptr_t object = BINDER_OBJECT;
526     DBinderServiceStub dBinderServiceStub(service, device, object);
527 
528     sptr<IPCObjectProxy> callbackProxy = new (std::nothrow) IPCObjectProxy(0);
529     EXPECT_TRUE(callbackProxy != nullptr);
530     MessageParcel data;
531     data.WriteRemoteObject(callbackProxy);
532     data.WriteString("test");
533     int32_t ret = dBinderServiceStub.AddDbinderDeathRecipient(data);
534     EXPECT_EQ(ret, ERR_NONE);
535 }
536 
537 /**
538  * @tc.name: AddDbinderDeathRecipient005
539  * @tc.desc: Verify the AddDbinderDeathRecipient function
540  * @tc.type: FUNC
541  */
542 HWTEST_F(DBinderServiceStubUnitTest, AddDbinderDeathRecipient005, TestSize.Level1)
543 {
544     const std::string service = "serviceTest";
545     const std::string device = "deviceTest";
546     binder_uintptr_t object = BINDER_OBJECT;
547     DBinderServiceStub dBinderServiceStub(service, device, object);
548 
549     sptr<IPCObjectProxy> callbackProxy = new (std::nothrow) IPCObjectProxy(0);
550     EXPECT_TRUE(callbackProxy != nullptr);
551     MessageParcel data;
552     data.WriteRemoteObject(callbackProxy);
553     data.WriteString("");
554     int32_t ret = dBinderServiceStub.AddDbinderDeathRecipient(data);
555     EXPECT_EQ(ret, DBINDER_SERVICE_ADD_DEATH_ERR);
556 }
557 
558 /**
559  * @tc.name: RemoveDbinderDeathRecipient001
560  * @tc.desc: Verify the RemoveDbinderDeathRecipient function
561  * @tc.type: FUNC
562  */
563 HWTEST_F(DBinderServiceStubUnitTest, RemoveDbinderDeathRecipient001, TestSize.Level1)
564 {
565     const std::string service = "serviceTest";
566     const std::string device = "deviceTest";
567     binder_uintptr_t object = BINDER_OBJECT;
568     DBinderServiceStub dBinderServiceStub(service, device, object);
569 
570     MessageParcel data;
571     int32_t ret = dBinderServiceStub.RemoveDbinderDeathRecipient(data);
572     EXPECT_EQ(ret, DBINDER_SERVICE_REMOVE_DEATH_ERR);
573 }
574 
575 /**
576  * @tc.name: RemoveDbinderDeathRecipient002
577  * @tc.desc: Verify the RemoveDbinderDeathRecipient function
578  * @tc.type: FUNC
579  */
580 HWTEST_F(DBinderServiceStubUnitTest, RemoveDbinderDeathRecipient002, TestSize.Level1)
581 {
582     const std::string service = "serviceTest";
583     const std::string device = "deviceTest";
584     binder_uintptr_t object = BINDER_OBJECT;
585     DBinderServiceStub dBinderServiceStub(service, device, object);
586 
587     sptr<IPCObjectProxy> callbackProxy = new (std::nothrow) IPCObjectProxy(0);
588     EXPECT_TRUE(callbackProxy != nullptr);
589     MessageParcel data;
590     data.WriteRemoteObject(callbackProxy);
591     data.WriteString("test");
592     int32_t ret = dBinderServiceStub.RemoveDbinderDeathRecipient(data);
593     EXPECT_EQ(ret, ERR_NONE);
594 }
595 
596 /**
597  * @tc.name: RemoveDbinderDeathRecipient003
598  * @tc.desc: Verify the RemoveDbinderDeathRecipient function
599  * @tc.type: FUNC
600  */
601 HWTEST_F(DBinderServiceStubUnitTest, RemoveDbinderDeathRecipient003, TestSize.Level1)
602 {
603     const std::string service = "serviceTest";
604     const std::string device = "deviceTest";
605     binder_uintptr_t object = BINDER_OBJECT;
606     DBinderServiceStub dBinderServiceStub(service, device, object);
607 
608     sptr<IPCObjectProxy> callbackProxy = new (std::nothrow) IPCObjectProxy(0);
609     EXPECT_TRUE(callbackProxy != nullptr);
610     MessageParcel data;
611     data.WriteRemoteObject(callbackProxy);
612     data.WriteString("");
613     int32_t ret = dBinderServiceStub.RemoveDbinderDeathRecipient(data);
614     EXPECT_EQ(ret, DBINDER_SERVICE_REMOVE_DEATH_ERR);
615 }
616 
617 /**
618  * @tc.name: RemoveDbinderDeathRecipient004
619  * @tc.desc: Verify the RemoveDbinderDeathRecipient function
620  * @tc.type: FUNC
621  */
622 HWTEST_F(DBinderServiceStubUnitTest, RemoveDbinderDeathRecipient004, TestSize.Level1)
623 {
624     const std::string service = "serviceTest";
625     const std::string device = "deviceTest";
626     binder_uintptr_t object = BINDER_OBJECT;
627     DBinderServiceStub dBinderServiceStub(service, device, object);
628 
629     sptr<IPCObjectStub> callbackStub = new (std::nothrow) IPCObjectStub(u"testStub");
630     EXPECT_TRUE(callbackStub != nullptr);
631     MessageParcel data;
632     data.WriteRemoteObject(callbackStub);
633     data.WriteString("test");
634     int32_t ret = dBinderServiceStub.RemoveDbinderDeathRecipient(data);
635     EXPECT_EQ(ret, DBINDER_SERVICE_REMOVE_DEATH_ERR);
636 }
637 
638 /**
639  * @tc.name: RemoveDbinderDeathRecipient005
640  * @tc.desc: Verify the RemoveDbinderDeathRecipient function
641  * @tc.type: FUNC
642  */
643 HWTEST_F(DBinderServiceStubUnitTest, RemoveDbinderDeathRecipient005, TestSize.Level1)
644 {
645     const std::string service = "serviceTest";
646     const std::string device = "deviceTest";
647     binder_uintptr_t object = BINDER_OBJECT;
648     DBinderServiceStub dBinderServiceStub(service, device, object);
649 
650     sptr<IPCObjectStub> callbackStub = new (std::nothrow) IPCObjectStub(u"testStub");
651     EXPECT_TRUE(callbackStub != nullptr);
652     MessageParcel data;
653     data.WriteRemoteObject(callbackStub);
654     data.WriteString("");
655     int32_t ret = dBinderServiceStub.RemoveDbinderDeathRecipient(data);
656     EXPECT_EQ(ret, DBINDER_SERVICE_REMOVE_DEATH_ERR);
657 }
658