• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #include <gmock/gmock.h>
18 
19 #define private public
20 #include "ipc_object_proxy.h"
21 #include "ipc_process_skeleton.h"
22 #include "ipc_thread_skeleton.h"
23 #include "ipc_types.h"
24 #include "iremote_object.h"
25 #include "mock_iremote_object.h"
26 #include "mock_session_impl.h"
27 #undef private
28 
29 using namespace testing::ext;
30 using namespace OHOS;
31 
32 class IPCObjectProxyTest : public testing::Test {
33 public:
34     static void SetUpTestCase(void);
35     static void TearDownTestCase(void);
36     void SetUp();
37     void TearDown();
38 };
39 
SetUpTestCase()40 void IPCObjectProxyTest::SetUpTestCase()
41 {
42 }
43 
TearDownTestCase()44 void IPCObjectProxyTest::TearDownTestCase()
45 {
46 }
47 
SetUp()48 void IPCObjectProxyTest::SetUp()
49 {
50 }
51 
TearDown()52 void IPCObjectProxyTest::TearDown()
53 {
54 }
55 
56 /**
57  * @tc.name: GetPidAndUidInfoTest001
58  * @tc.desc: Verify the IPCObjectProxy::GetPidAndUidInfo function
59  * @tc.type: FUNC
60  */
61 HWTEST_F(IPCObjectProxyTest, GetPidAndUidInfoTest001, TestSize.Level1)
62 {
63     IPCObjectProxy object(1);
64 
65     std::string ret = object.GetPidAndUidInfo(1);
66     ASSERT_TRUE(ret.size() != 0);
67 }
68 
69 /**
70  * @tc.name: GetDataBusNameTest001
71  * @tc.desc: Verify the IPCObjectProxy::GetDataBusName function
72  * @tc.type: FUNC
73  */
74 HWTEST_F(IPCObjectProxyTest, GetDataBusNameTest001, TestSize.Level1)
75 {
76     IPCObjectProxy object(1);
77 
78     std::string ret = object.GetDataBusName(1);
79     ASSERT_TRUE(ret.size() == 0);
80 }
81 
82 /**
83  * @tc.name: TransDataBusNameTest001
84  * @tc.desc: Verify the IPCObjectProxy::TransDataBusName function
85  * @tc.type: FUNC
86  */
87 HWTEST_F(IPCObjectProxyTest, TransDataBusNameTest001, TestSize.Level1)
88 {
89     IPCObjectProxy object(1);
90 
91     std::string ret = object.TransDataBusName(1, 1);
92     ASSERT_TRUE(ret.size() == 0);
93 }
94 
95 /**
96  * @tc.name: GetInterfaceDescriptorTest001
97  * @tc.desc: Verify the IPCObjectProxy::GetInterfaceDescriptor function
98  * @tc.type: FUNC
99  */
100 HWTEST_F(IPCObjectProxyTest, GetInterfaceDescriptorTest001, TestSize.Level1)
101 {
102     IPCObjectProxy object(1);
103 
104     std::u16string ret = object.GetInterfaceDescriptor();
105     ASSERT_TRUE(ret.size() != 0);
106 }
107 
108 /**
109  * @tc.name: GetObjectRefCountTest001
110  * @tc.desc: Verify the IPCObjectProxy::GetObjectRefCount function
111  * @tc.type: FUNC
112  */
113 HWTEST_F(IPCObjectProxyTest, GetObjectRefCountTest001, TestSize.Level1)
114 {
115     IPCObjectProxy object(1);
116 
117     auto ret = object.GetObjectRefCount();
118     ASSERT_TRUE(ret != 0);
119 }
120 
121 /**
122  * @tc.name: GetInterfaceDescriptorTest002
123  * @tc.desc: Verify the IPCObjectProxy::GetInterfaceDescriptor function
124  * @tc.type: FUNC
125  */
126 HWTEST_F(IPCObjectProxyTest, GetInterfaceDescriptorTest002, TestSize.Level1)
127 {
128     IPCObjectProxy object(0);
129     object.remoteDescriptor_ = u"";
130     auto ret = object.GetInterfaceDescriptor();
131     ASSERT_TRUE(ret.size() == 0);
132 }
133 
134 /**
135  * @tc.name: GetInterfaceDescriptorTest003
136  * @tc.desc: Verify the IPCObjectProxy::GetInterfaceDescriptor function
137  * @tc.type: FUNC
138  */
139 HWTEST_F(IPCObjectProxyTest, GetInterfaceDescriptorTest003, TestSize.Level1)
140 {
141     IPCObjectProxy object(1);
142     object.remoteDescriptor_ = u"test";
143     auto ret = object.GetInterfaceDescriptor();
144     ASSERT_TRUE(ret.size() != 0);
145 }
146 
147 /**
148  * @tc.name: GetInterfaceDescriptorTest004
149  * @tc.desc: Verify the IPCObjectProxy::GetInterfaceDescriptor function
150  * @tc.type: FUNC
151  */
152 HWTEST_F(IPCObjectProxyTest, GetInterfaceDescriptorTest004, TestSize.Level1)
153 {
154     IPCObjectProxy object(1);
155     object.remoteDescriptor_ = u"test";
156     auto ret = object.GetInterfaceDescriptor();
157     ASSERT_TRUE(ret.size() != 0);
158 }
159 
160 /**
161  * @tc.name: GetPidAndUidInfoTest002
162  * @tc.desc: Verify the IPCObjectProxy::GetPidAndUidInfo function
163  * @tc.type: FUNC
164  */
165 HWTEST_F(IPCObjectProxyTest, GetPidAndUidInfoTest002, TestSize.Level1)
166 {
167     IPCObjectProxy object(1);
168 
169     object.isRemoteDead_ = true;
170     auto ret = object.GetPidAndUidInfo(1);
171     ASSERT_TRUE(ret.size() == 0);
172 }
173 
174 /**
175  * @tc.name: GetDataBusNameTest002
176  * @tc.desc: Verify the IPCObjectProxy::GetDataBusName function
177  * @tc.type: FUNC
178  */
179 HWTEST_F(IPCObjectProxyTest, GetDataBusNameTest002, TestSize.Level1)
180 {
181     IPCObjectProxy object(1);
182 
183     object.isRemoteDead_ = false;
184     auto ret = object.GetDataBusName(1);
185     ASSERT_TRUE(ret.size() == 0);
186 }
187 
188 /**
189  * @tc.name: GetDataBusNameTest003
190  * @tc.desc: Verify the IPCObjectProxy::GetDataBusName function
191  * @tc.type: FUNC
192  */
193 HWTEST_F(IPCObjectProxyTest, GetDataBusNameTest003, TestSize.Level1)
194 {
195     IPCObjectProxy object(1);
196 
197     object.isRemoteDead_ = true;
198     auto ret = object.GetDataBusName(1);
199     ASSERT_TRUE(ret.size() == 0);
200 }
201 
202 /**
203  * @tc.name: TransDataBusNameTest002
204  * @tc.desc: Verify the IPCObjectProxy::TransDataBusName function
205  * @tc.type: FUNC
206  */
207 HWTEST_F(IPCObjectProxyTest, TransDataBusNameTest002, TestSize.Level1)
208 {
209     IPCObjectProxy object(1);
210 
211     object.isRemoteDead_ = false;
212     auto ret = object.TransDataBusName(1, 1);
213     ASSERT_TRUE(ret.size() == 0);
214 }
215 
216 /**
217  * @tc.name: TransDataBusNameTest003
218  * @tc.desc: Verify the IPCObjectProxy::TransDataBusName function
219  * @tc.type: FUNC
220  */
221 HWTEST_F(IPCObjectProxyTest, TransDataBusNameTest003, TestSize.Level1)
222 {
223     IPCObjectProxy object(1);
224 
225     object.isRemoteDead_ = true;
226     auto ret = object.TransDataBusName(1, 1);
227     ASSERT_TRUE(ret.size() == 0);
228 }
229 
230 /**
231  * @tc.name: WaitForInitTest001
232  * @tc.desc: Verify the IPCObjectProxy::WaitForInit function
233  * @tc.type: FUNC
234  */
235 HWTEST_F(IPCObjectProxyTest, WaitForInitTest001, TestSize.Level1)
236 {
237     IPCObjectProxy object(1);
238 
239     object.isRemoteDead_ = true;
240     object.WaitForInit();
241     EXPECT_EQ(object.isRemoteDead_, false);
242     EXPECT_EQ(object.isFinishInit_, true);
243 }
244 
245 #ifndef CONFIG_IPC_SINGLE
246 /**
247  * @tc.name: WaitForInitTest002
248  * @tc.desc: Verify the IPCObjectProxy::WaitForInit function
249  * @tc.type: FUNC
250  */
251 HWTEST_F(IPCObjectProxyTest, WaitForInitTest002, TestSize.Level1)
252 {
253     IPCObjectProxy object(1);
254 
255     object.isRemoteDead_ = false;
256     object.isRemoteDead_ = true;
257     object.proto_ = IRemoteObject::IF_PROT_DATABUS;
258 
259     IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
260     current->proxyToSession_.clear();
261     object.WaitForInit();
262     EXPECT_EQ(object.isRemoteDead_, false);
263 }
264 
265 /**
266  * @tc.name: WaitForInitTest003
267  * @tc.desc: Verify the IPCObjectProxy::WaitForInit function
268  * @tc.type: FUNC
269  */
270 HWTEST_F(IPCObjectProxyTest, WaitForInitTest003, TestSize.Level1)
271 {
272     IPCObjectProxy object(1);
273 
274     object.isRemoteDead_ = false;
275     object.isRemoteDead_ = true;
276     object.proto_ = IRemoteObject::IF_PROT_ERROR;
277 
278     IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
279     current->proxyToSession_.clear();
280     object.WaitForInit();
281     EXPECT_NE(object.isRemoteDead_, true);
282 }
283 
284 /**
285  * @tc.name: WaitForInitTest004
286  * @tc.desc: Verify the IPCObjectProxy::WaitForInit function
287  * @tc.type: FUNC
288  */
289 HWTEST_F(IPCObjectProxyTest, WaitForInitTest004, TestSize.Level1)
290 {
291     IPCObjectProxy object(1);
292 
293     object.isRemoteDead_ = false;
294     object.isRemoteDead_ = true;
295     object.proto_ = IRemoteObject::IF_PROT_ERROR;
296 
297     IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
298     current->proxyToSession_.clear();
299     object.WaitForInit();
300     EXPECT_NE(object.isRemoteDead_, true);
301 }
302 #endif
303 
304 /**
305  * @tc.name: RemoveDeathRecipientTest001
306  * @tc.desc: Verify the IPCObjectProxy::RemoveDeathRecipient function
307  * @tc.type: FUNC
308  */
309 HWTEST_F(IPCObjectProxyTest, RemoveDeathRecipientTest001, TestSize.Level1)
310 {
311     sptr<IPCObjectProxy> object = new IPCObjectProxy(
312         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
313     sptr<IRemoteObject::DeathRecipient> death(new MockDeathRecipient());
314     object->isRemoteDead_ = false;
315     object->proto_ = IRemoteObject::IF_PROT_ERROR;
316     object->recipients_.clear();
317 
318     object->RemoveDeathRecipient(death);
319     EXPECT_EQ(object->recipients_.empty(), true);
320 }
321 
322 /**
323  * @tc.name: RemoveDeathRecipientTest002
324  * @tc.desc: Verify the IPCObjectProxy::RemoveDeathRecipient function
325  * @tc.type: FUNC
326  */
327 HWTEST_F(IPCObjectProxyTest, RemoveDeathRecipientTest002, TestSize.Level1)
328 {
329     sptr<IPCObjectProxy> object = new IPCObjectProxy(
330         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
331     sptr<IRemoteObject::DeathRecipient> death(new MockDeathRecipient());
332     object->isRemoteDead_ = false;
333     object->proto_ = IRemoteObject::IF_PROT_ERROR;
334     object->recipients_.clear();
335 
336     object->RemoveDeathRecipient(death);
337     EXPECT_EQ(object->isRemoteDead_, false);
338 }
339 
340 /**
341  * @tc.name: RemoveDeathRecipientTest003
342  * @tc.desc: Verify the IPCObjectProxy::RemoveDeathRecipient function
343  * @tc.type: FUNC
344  */
345 HWTEST_F(IPCObjectProxyTest, RemoveDeathRecipientTest003, TestSize.Level1)
346 {
347     sptr<IPCObjectProxy> object = new IPCObjectProxy(
348         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
349     sptr<IRemoteObject::DeathRecipient> death(new MockDeathRecipient());
350     sptr<IRemoteObject::DeathRecipient> death2(new MockDeathRecipient());
351     object->recipients_.push_back(death);
352     object->recipients_.push_back(death2);
353     object->isRemoteDead_ = false;
354     object->proto_ = IRemoteObject::IF_PROT_ERROR;
355 
356     object->RemoveDeathRecipient(death);
357     EXPECT_EQ(object->recipients_.empty(), false);
358 }
359 
360 /**
361  * @tc.name: RemoveDeathRecipientTest004
362  * @tc.desc: Verify the IPCObjectProxy::RemoveDeathRecipient function
363  * @tc.type: FUNC
364  */
365 HWTEST_F(IPCObjectProxyTest, RemoveDeathRecipientTest004, TestSize.Level1)
366 {
367     sptr<IPCObjectProxy> object = new IPCObjectProxy(
368         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
369     sptr<IRemoteObject::DeathRecipient> death(new MockDeathRecipient());
370     object->recipients_.push_back(death);
371     object->isRemoteDead_ = false;
372     object->proto_ = IRemoteObject::IF_PROT_ERROR;
373 
374     auto ret = object->RemoveDeathRecipient(death);
375     EXPECT_EQ(ret, true);
376 }
377 
378 /**
379  * @tc.name: SendObituaryTest001
380  * @tc.desc: Verify the IPCObjectProxy::SendObituary function
381  * @tc.type: FUNC
382  */
383 HWTEST_F(IPCObjectProxyTest, SendObituaryTest001, TestSize.Level1)
384 {
385     sptr<IPCObjectProxy> object = new IPCObjectProxy(
386         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
387     sptr<IRemoteObject::DeathRecipient> death = new MockDeathRecipient();
388     object->recipients_.push_back(death);
389     object->isRemoteDead_ = false;
390     object->proto_ = IRemoteObject::IF_PROT_DATABUS;
391 
392     object->SendObituary();
393     ASSERT_TRUE(object->recipients_.size() == 0);
394     object->recipients_.clear();
395 }
396 
397 /**
398  * @tc.name: SendObituaryTest002
399  * @tc.desc: Verify the IPCObjectProxy::SendObituary function
400  * @tc.type: FUNC
401  */
402 HWTEST_F(IPCObjectProxyTest, SendObituaryTest002, TestSize.Level1)
403 {
404     sptr<IPCObjectProxy> object = new IPCObjectProxy(
405         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
406     object->recipients_.clear();
407     object->isRemoteDead_ = false;
408     object->proto_ = IRemoteObject::IF_PROT_DATABUS;
409 
410     object->SendObituary();
411     ASSERT_TRUE(object->recipients_.size() == 0);
412 }
413 
414 /**
415  * @tc.name: SendObituaryTest003
416  * @tc.desc: Verify the IPCObjectProxy::SendObituary function
417  * @tc.type: FUNC
418  */
419 HWTEST_F(IPCObjectProxyTest, SendObituaryTest003, TestSize.Level1)
420 {
421     sptr<IPCObjectProxy> object = new IPCObjectProxy(
422         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
423     sptr<IRemoteObject::DeathRecipient> death = nullptr;
424     object->recipients_.push_back(death);
425     object->isRemoteDead_ = false;
426     object->proto_ = IRemoteObject::IF_PROT_DATABUS;
427 
428     object->SendObituary();
429     ASSERT_TRUE(object->recipients_.size() == 0);
430 }
431 
432 #ifndef CONFIG_IPC_SINGLE
433 /**
434  * @tc.name: SendObituaryTest004
435  * @tc.desc: Verify the IPCObjectProxy::SendObituary function
436  * @tc.type: FUNC
437  */
438 HWTEST_F(IPCObjectProxyTest, SendObituaryTest004, TestSize.Level1)
439 {
440     sptr<IPCObjectProxy> object = new IPCObjectProxy(
441         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
442     sptr<IRemoteObject::DeathRecipient> death = nullptr;
443     object->recipients_.push_back(death);
444     object->isRemoteDead_ = false;
445     object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
446 
447     object->SendObituary();
448     ASSERT_TRUE(object->recipients_.size() == 0);
449 }
450 #endif
451 
452 /**
453  * @tc.name: NoticeServiceDieTest001
454  * @tc.desc: Verify the IPCObjectProxy::NoticeServiceDie function
455  * @tc.type: FUNC
456  */
457 HWTEST_F(IPCObjectProxyTest, NoticeServiceDieTest001, TestSize.Level1)
458 {
459     sptr<IPCObjectProxy> object = new IPCObjectProxy(
460         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
461 
462     object->isRemoteDead_ = false;
463     object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
464 
465     auto ret = object->NoticeServiceDie();
466     EXPECT_EQ(ret, IPC_PROXY_TRANSACTION_ERR);
467 }
468 
469 /**
470  * @tc.name: NoticeServiceDieTest002
471  * @tc.desc: Verify the IPCObjectProxy::NoticeServiceDie function
472  * @tc.type: FUNC
473  */
474 HWTEST_F(IPCObjectProxyTest, NoticeServiceDieTest002, TestSize.Level1)
475 {
476     sptr<IPCObjectProxy> object = new IPCObjectProxy(
477         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
478     object->isRemoteDead_ = true;
479     object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
480 
481     auto ret = object->NoticeServiceDie();
482     EXPECT_EQ(ret, IPC_PROXY_TRANSACTION_ERR);
483 }
484 
485 /**
486  * @tc.name: IncRefToRemoteTest001
487  * @tc.desc: Verify the IPCObjectProxy::IncRefToRemote function
488  * @tc.type: FUNC
489  */
490 HWTEST_F(IPCObjectProxyTest, IncRefToRemoteTest001, TestSize.Level1)
491 {
492     sptr<IPCObjectProxy> object = new IPCObjectProxy(
493         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
494     object->isRemoteDead_ = false;
495     object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
496 
497     auto ret = object->IncRefToRemote();
498     EXPECT_EQ(ret, IPC_STUB_INVALID_DATA_ERR);
499 }
500 
501 /**
502  * @tc.name: IncRefToRemoteTest002
503  * @tc.desc: Verify the IPCObjectProxy::IncRefToRemote function
504  * @tc.type: FUNC
505  */
506 HWTEST_F(IPCObjectProxyTest, IncRefToRemoteTest002, TestSize.Level1)
507 {
508     sptr<IPCObjectProxy> object = new IPCObjectProxy(
509         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
510     object->isRemoteDead_ = true;
511     object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
512 
513     auto ret = object->IncRefToRemote();
514     EXPECT_EQ(ret, ERR_DEAD_OBJECT);
515 }
516 
517 /**
518  * @tc.name: GetSessionFromDBinderServiceTest001
519  * @tc.desc: Verify the IPCObjectProxy::GetSessionFromDBinderService function
520  * @tc.type: FUNC
521  */
522 HWTEST_F(IPCObjectProxyTest, GetSessionFromDBinderServiceTest001, TestSize.Level1)
523 {
524     sptr<IPCObjectProxy> object = new IPCObjectProxy(
525         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
526     object->isRemoteDead_ = true;
527     object->proto_ = IRemoteObject::IF_PROT_DATABUS;
528 
529     auto ret = object->GetSessionFromDBinderService();
530     EXPECT_EQ(ret, IRemoteObject::IF_PROT_ERROR);
531 }
532 
533 /**
534  * @tc.name: GetSessionFromDBinderServiceTest002
535  * @tc.desc: Verify the IPCObjectProxy::GetSessionFromDBinderService function
536  * @tc.type: FUNC
537  */
538 HWTEST_F(IPCObjectProxyTest, GetSessionFromDBinderServiceTest002, TestSize.Level1)
539 {
540     sptr<IPCObjectProxy> object = new IPCObjectProxy(
541         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
542     object->isRemoteDead_ = true;
543     object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
544 
545     auto ret = object->GetSessionFromDBinderService();
546     EXPECT_EQ(ret, IRemoteObject::IF_PROT_ERROR);
547 }
548 
549 /**
550  * @tc.name: AddDbinderDeathRecipientTest001
551  * @tc.desc: Verify the IPCObjectProxy::AddDbinderDeathRecipient function
552  * @tc.type: FUNC
553  */
554 HWTEST_F(IPCObjectProxyTest, AddDbinderDeathRecipientTest001, TestSize.Level1)
555 {
556     sptr<IPCObjectProxy> object = new IPCObjectProxy(
557         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
558     object->isRemoteDead_ = false;
559     object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
560 
561     sptr<IPCObjectStub> objectStub = new IPCObjectStub(u"test");
562     IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
563     current->noticeStub_[object.GetRefPtr()] = objectStub;
564     auto ret = object->AddDbinderDeathRecipient();
565 
566     ASSERT_TRUE(ret == true);
567     current->noticeStub_.erase(object.GetRefPtr());
568 }
569 
570 /**
571  * @tc.name: AddDbinderDeathRecipientTest002
572  * @tc.desc: Verify the IPCObjectProxy::AddDbinderDeathRecipient function
573  * @tc.type: FUNC
574  */
575 HWTEST_F(IPCObjectProxyTest, AddDbinderDeathRecipientTest002, TestSize.Level1)
576 {
577     sptr<IPCObjectProxy> object = new IPCObjectProxy(
578         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
579     object->isRemoteDead_ = true;
580     object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
581 
582     IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
583     current->noticeStub_.clear();
584     auto ret = object->AddDbinderDeathRecipient();
585 
586     ASSERT_TRUE(ret == false);
587 }
588 
589 /**
590  * @tc.name: AddDbinderDeathRecipientTest003
591  * @tc.desc: Verify the IPCObjectProxy::AddDbinderDeathRecipient function
592  * @tc.type: FUNC
593  */
594 HWTEST_F(IPCObjectProxyTest, AddDbinderDeathRecipientTest003, TestSize.Level1)
595 {
596     sptr<IPCObjectProxy> object = new IPCObjectProxy(
597         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
598     object->isRemoteDead_ = true;
599     object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
600 
601     sptr<IPCObjectStub> objectStub = new IPCObjectStub(u"test");
602     IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
603     current->noticeStub_[object.GetRefPtr()] = objectStub;
604     auto ret = object->AddDbinderDeathRecipient();
605 
606     ASSERT_TRUE(ret == true);
607     current->noticeStub_.erase(object.GetRefPtr());
608 }
609 
610 /**
611  * @tc.name: RemoveDbinderDeathRecipientTest001
612  * @tc.desc: Verify the IPCObjectProxy::RemoveDbinderDeathRecipient function
613  * @tc.type: FUNC
614  */
615 HWTEST_F(IPCObjectProxyTest, RemoveDbinderDeathRecipientTest001, TestSize.Level1)
616 {
617     sptr<IPCObjectProxy> object = new IPCObjectProxy(
618         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
619     object->isRemoteDead_ = false;
620     object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
621 
622     sptr<IPCObjectStub> objectStub = new IPCObjectStub(u"test");
623     IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
624     current->noticeStub_[object.GetRefPtr()] = objectStub;
625     auto ret = object->RemoveDbinderDeathRecipient();
626 
627     ASSERT_TRUE(ret == true);
628     current->noticeStub_.erase(object.GetRefPtr());
629 }
630 
631 /**
632  * @tc.name: CheckHaveSessionTest001
633  * @tc.desc: Verify the IPCObjectProxy::CheckHaveSession function
634  * @tc.type: FUNC
635  */
636 HWTEST_F(IPCObjectProxyTest, CheckHaveSessionTest001, TestSize.Level1)
637 {
638     sptr<IPCObjectProxy> object = new IPCObjectProxy(
639         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
640     object->isRemoteDead_ = false;
641     object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
642 
643     std::shared_ptr<MockSessionImpl> sessionMock = std::make_shared<MockSessionImpl>();
644     std::string serviceName = "testserviceName";
645     std::string serverDeviceId = "testserverDeviceId";
646     auto dbinderSessionObject = std::make_shared<DBinderSessionObject>(sessionMock, serviceName, serverDeviceId);
647 
648     IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
649     auto session = current->proxyToSession_[1] = dbinderSessionObject;
650     ASSERT_TRUE(current->ProxyQueryDBinderSession(1) != nullptr);
651     auto ret = object->CheckHaveSession();
652 
653     ASSERT_TRUE(ret == true);
654 }
655 
656 /**
657  * @tc.name: UpdateDatabusClientSessionTest001
658  * @tc.desc: Verify the IPCObjectProxy::UpdateDatabusClientSession function
659  * @tc.type: FUNC
660  */
661 HWTEST_F(IPCObjectProxyTest, UpdateDatabusClientSessionTest001, TestSize.Level1)
662 {
663     sptr<IPCObjectProxy> object = new IPCObjectProxy(
664         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
665     object->isRemoteDead_ = false;
666     object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
667 
668     IRemoteInvoker *invoker = nullptr;
669     IPCThreadSkeleton *current = IPCThreadSkeleton::GetCurrent();
670     current->invokers_[IRemoteObject::IF_PROT_DATABUS] = invoker;
671     MessageParcel reply;
672     auto ret = object->UpdateDatabusClientSession(1, reply);
673 
674     ASSERT_TRUE(ret == false);
675     current->invokers_.clear();
676 }
677 
678 /**
679  * @tc.name: UpdateDatabusClientSessionTest002
680  * @tc.desc: Verify the IPCObjectProxy::UpdateDatabusClientSession function
681  * @tc.type: FUNC
682  */
683 HWTEST_F(IPCObjectProxyTest, UpdateDatabusClientSessionTest002, TestSize.Level1)
684 {
685     sptr<IPCObjectProxy> object = new IPCObjectProxy(
686         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
687     object->isRemoteDead_ = false;
688     object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
689 
690     IPCThreadSkeleton *current = IPCThreadSkeleton::GetCurrent();
691     current->invokers_.clear();
692 
693     MessageParcel reply;
694     uint64_t stubIndex = 1;
695     reply.ReadUint64(stubIndex);
696     std::string serviceName =  "testserviceName";
697     reply.WriteString(serviceName);
698     std::string peerID =  "testpeerID";
699     reply.WriteString(peerID);
700     std::string localID =  "testlocalID";
701     reply.WriteString(localID);
702     std::string localBusName =  "testlocalBusName";
703     reply.WriteString(localBusName);
704     uint32_t rpcFeatureSet = 1;
705     reply.WriteUint32(rpcFeatureSet);
706 
707     auto ret = object->UpdateDatabusClientSession(1, reply);
708 
709     ASSERT_TRUE(ret == false);
710 }
711 
712 /**
713  * @tc.name: UpdateDatabusClientSessionTest003
714  * @tc.desc: Verify the IPCObjectProxy::UpdateDatabusClientSession function
715  * @tc.type: FUNC
716  */
717 HWTEST_F(IPCObjectProxyTest, UpdateDatabusClientSessionTest003, TestSize.Level1)
718 {
719     sptr<IPCObjectProxy> object = new IPCObjectProxy(
720         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
721     object->isRemoteDead_ = false;
722     object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
723 
724     IPCThreadSkeleton *current = IPCThreadSkeleton::GetCurrent();
725     current->invokers_.clear();
726 
727     MessageParcel reply;
728     uint64_t stubIndex = 1;
729     reply.ReadUint64(stubIndex);
730     std::string serviceName =  "testserviceName";
731     reply.WriteString(serviceName);
732     std::string peerID =  "testpeerID";
733     reply.WriteString(peerID);
734     std::string localID =  "testlocalID";
735     reply.WriteString(localID);
736     std::string localBusName =  "testlocalBusName";
737     reply.WriteString(localBusName);
738     uint32_t rpcFeatureSet = 0;
739     reply.WriteUint32(rpcFeatureSet);
740 
741     auto ret = object->UpdateDatabusClientSession(1, reply);
742 
743     ASSERT_TRUE(ret == false);
744 }
745 
746 /**
747  * @tc.name: UpdateDatabusClientSessionTest004
748  * @tc.desc: Verify the IPCObjectProxy::UpdateDatabusClientSession function
749  * @tc.type: FUNC
750  */
751 HWTEST_F(IPCObjectProxyTest, UpdateDatabusClientSessionTest004, TestSize.Level1)
752 {
753     sptr<IPCObjectProxy> object = new IPCObjectProxy(
754         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
755     object->isRemoteDead_ = false;
756     object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
757 
758     IPCThreadSkeleton *current = IPCThreadSkeleton::GetCurrent();
759     current->invokers_.clear();
760 
761     MessageParcel reply;
762     uint64_t stubIndex = 0;
763     reply.ReadUint64(stubIndex);
764     std::string serviceName =  "testserviceName";
765     reply.WriteString(serviceName);
766     std::string peerID =  "testpeerID";
767     reply.WriteString(peerID);
768     std::string localID =  "testlocalID";
769     reply.WriteString(localID);
770     std::string localBusName =  "testlocalBusName";
771     reply.WriteString(localBusName);
772     uint32_t rpcFeatureSet = 0;
773     reply.WriteUint32(rpcFeatureSet);
774 
775     auto ret = object->UpdateDatabusClientSession(1, reply);
776     ASSERT_TRUE(ret == false);
777 }
778 
779 /**
780  * @tc.name: UpdateDatabusClientSessionTest005
781  * @tc.desc: Verify the IPCObjectProxy::UpdateDatabusClientSession5 function
782  * @tc.type: FUNC
783  */
784 HWTEST_F(IPCObjectProxyTest, UpdateDatabusClientSessionTest005, TestSize.Level1)
785 {
786     sptr<IPCObjectProxy> object = new IPCObjectProxy(
787         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
788     object->isRemoteDead_ = false;
789     object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
790 
791     IPCThreadSkeleton *current = IPCThreadSkeleton::GetCurrent();
792     current->invokers_.clear();
793 
794     MessageParcel reply;
795     uint64_t stubIndex = 1;
796     reply.ReadUint64(stubIndex);
797     std::string serviceName =  "testserviceName";
798     reply.WriteString(serviceName);
799     std::string peerID =  "testpeerID";
800     reply.WriteString(peerID);
801     std::string localID =  "testlocalID";
802     reply.WriteString(localID);
803     std::string localBusName =  "testlocalBusName";
804     reply.WriteString(localBusName);
805     uint32_t rpcFeatureSet = 1;
806     reply.WriteUint32(rpcFeatureSet);
807 
808     IPCProcessSkeleton *processCurrent = IPCProcessSkeleton::GetCurrent();
809     std::shared_ptr<MockSessionImpl> sessionMock = std::make_shared<MockSessionImpl>();
810     auto dbinderSessionObject = std::make_shared<DBinderSessionObject>(sessionMock, serviceName, peerID);
811     processCurrent->proxyToSession_[0] = dbinderSessionObject;
812 
813     auto ret = object->UpdateDatabusClientSession(1, reply);
814 
815     ASSERT_TRUE(ret == false);
816     processCurrent->proxyToSession_.clear();
817 }
818 
819 /**
820  * @tc.name: UpdateDatabusClientSessionTest006
821  * @tc.desc: Verify the IPCObjectProxy::UpdateDatabusClientSession5 function
822  * @tc.type: FUNC
823  */
824 HWTEST_F(IPCObjectProxyTest, UpdateDatabusClientSessionTest006, TestSize.Level1)
825 {
826     sptr<IPCObjectProxy> object = new IPCObjectProxy(
827         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
828     object->isRemoteDead_ = false;
829     object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
830 
831     IPCThreadSkeleton *current = IPCThreadSkeleton::GetCurrent();
832     current->invokers_.clear();
833 
834     MessageParcel reply;
835     uint64_t stubIndex = 1;
836     reply.ReadUint64(stubIndex);
837     std::string serviceName =  "testserviceName";
838     reply.WriteString(serviceName);
839     std::string peerID =  "testpeerID";
840     reply.WriteString(peerID);
841     std::string localID =  "testlocalID";
842     reply.WriteString(localID);
843     std::string localBusName =  "testlocalBusName";
844     reply.WriteString(localBusName);
845     uint32_t rpcFeatureSet = 1;
846     reply.WriteUint32(rpcFeatureSet);
847 
848     IPCProcessSkeleton *processCurrent = IPCProcessSkeleton::GetCurrent();
849     std::shared_ptr<MockSessionImpl> sessionMock = std::make_shared<MockSessionImpl>();
850 
851     auto dbinderSessionObject = std::make_shared<DBinderSessionObject>(sessionMock, serviceName, peerID);
852     processCurrent->proxyToSession_[0] = dbinderSessionObject;
853     processCurrent->handleToStubIndex_[1] = 0;
854 
855     auto ret = object->UpdateDatabusClientSession(1, reply);
856 
857     ASSERT_TRUE(ret == false);
858     processCurrent->proxyToSession_.clear();
859     processCurrent->handleToStubIndex_.clear();
860 }
861 
862 /**
863  * @tc.name: UpdateDatabusClientSessionTest007
864  * @tc.desc: Verify the IPCObjectProxy::UpdateDatabusClientSession5 function
865  * @tc.type: FUNC
866  */
867 HWTEST_F(IPCObjectProxyTest, UpdateDatabusClientSessionTest007, TestSize.Level1)
868 {
869     sptr<IPCObjectProxy> object = new IPCObjectProxy(
870         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
871     object->isRemoteDead_ = false;
872     object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
873 
874     IPCThreadSkeleton *current = IPCThreadSkeleton::GetCurrent();
875     current->invokers_.clear();
876 
877     MessageParcel reply;
878     uint64_t stubIndex = 1;
879     reply.ReadUint64(stubIndex);
880     std::string serviceName =  "testserviceName";
881     reply.WriteString(serviceName);
882     std::string peerID =  "testpeerID";
883     reply.WriteString(peerID);
884     std::string localID =  "testlocalID";
885     reply.WriteString(localID);
886     std::string localBusName =  "";
887     reply.WriteString(localBusName);
888     uint32_t rpcFeatureSet = 1;
889     reply.WriteUint32(rpcFeatureSet);
890 
891     IPCProcessSkeleton *processCurrent = IPCProcessSkeleton::GetCurrent();
892     std::shared_ptr<MockSessionImpl> sessionMock = std::make_shared<MockSessionImpl>();
893     auto dbinderSessionObject = std::make_shared<DBinderSessionObject>(sessionMock, serviceName, peerID);
894     processCurrent->proxyToSession_[0] = dbinderSessionObject;
895     processCurrent->handleToStubIndex_.clear();
896 
897     auto ret = object->UpdateDatabusClientSession(1, reply);
898 
899     ASSERT_TRUE(ret == false);
900     processCurrent->proxyToSession_.clear();
901 }
902 
903 /**
904  * @tc.name: UpdateDatabusClientSessionTest008
905  * @tc.desc: Verify the IPCObjectProxy::UpdateDatabusClientSession5 function
906  * @tc.type: FUNC
907  */
908 HWTEST_F(IPCObjectProxyTest, UpdateDatabusClientSessionTest008, TestSize.Level1)
909 {
910     sptr<IPCObjectProxy> object = new IPCObjectProxy(
911         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
912     object->isRemoteDead_ = false;
913     object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
914 
915     IPCThreadSkeleton *current = IPCThreadSkeleton::GetCurrent();
916     current->invokers_.clear();
917 
918     MessageParcel reply;
919     uint64_t stubIndex = 0;
920     reply.ReadUint64(stubIndex);
921     std::string serviceName =  "testserviceName";
922     reply.WriteString(serviceName);
923     std::string peerID =  "testpeerID";
924     reply.WriteString(peerID);
925     std::string localID =  "testlocalID";
926     reply.WriteString(localID);
927     std::string localBusName =  "";
928     reply.WriteString(localBusName);
929     uint32_t rpcFeatureSet = 0;
930     reply.WriteUint32(rpcFeatureSet);
931 
932     IPCProcessSkeleton *processCurrent = IPCProcessSkeleton::GetCurrent();
933     processCurrent->proxyToSession_.clear();
934     processCurrent->handleToStubIndex_.clear();
935 
936     auto ret = object->UpdateDatabusClientSession(1, reply);
937 
938     ASSERT_TRUE(ret == false);
939 }
940 
941 /**
942  * @tc.name: ReleaseDatabusProtoTest001
943  * @tc.desc: Verify the IPCObjectProxy::ReleaseDatabusProto function
944  * @tc.type: FUNC
945  */
946 HWTEST_F(IPCObjectProxyTest, ReleaseDatabusProtoTest001, TestSize.Level1)
947 {
948     sptr<IPCObjectProxy> object = new IPCObjectProxy(
949         0, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
950 
951     object->ReleaseDatabusProto();
952     ASSERT_TRUE(object->isRemoteDead_ == false);
953 }
954 
955 /**
956  * @tc.name: ReleaseDatabusProtoTest002
957  * @tc.desc: Verify the IPCObjectProxy::ReleaseDatabusProto function
958  * @tc.type: FUNC
959  */
960 HWTEST_F(IPCObjectProxyTest, ReleaseDatabusProtoTest002, TestSize.Level1)
961 {
962     sptr<IPCObjectProxy> object = new IPCObjectProxy(
963         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
964 
965     object->proto_ = IRemoteObject::IF_PROT_DATABUS;
966     object->ReleaseDatabusProto();
967     object->isRemoteDead_ = true;
968     ASSERT_TRUE(object->handle_ != 0);
969 }
970 
971 /**
972  * @tc.name: ReleaseDatabusProtoTest003
973  * @tc.desc: Verify the IPCObjectProxy::ReleaseDatabusProto function
974  * @tc.type: FUNC
975  */
976 HWTEST_F(IPCObjectProxyTest, ReleaseDatabusProtoTest003, TestSize.Level1)
977 {
978     sptr<IPCObjectProxy> object = new IPCObjectProxy(
979         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
980 
981     object->proto_ = IRemoteObject::IF_PROT_DATABUS;
982     object->ReleaseDatabusProto();
983     IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
984 
985     std::shared_ptr<MockSessionImpl> sessionMock = std::make_shared<MockSessionImpl>();
986     std::string serviceName = "testserviceName";
987     std::string serverDeviceId = "testserverDeviceId";
988     auto dbinderSessionObject = std::make_shared<DBinderSessionObject>(sessionMock, serviceName, serverDeviceId);
989 
990     auto session = current->proxyToSession_[1] = dbinderSessionObject;
991     ASSERT_TRUE(object->handle_ != 0);
992     current->proxyToSession_.clear();
993 }
994 
995 /**
996  * @tc.name: ReleaseDatabusProtoTest004
997  * @tc.desc: Verify the IPCObjectProxy::ReleaseDatabusProto function
998  * @tc.type: FUNC
999  */
1000 HWTEST_F(IPCObjectProxyTest, ReleaseDatabusProtoTest004, TestSize.Level1)
1001 {
1002     sptr<IPCObjectProxy> object = new IPCObjectProxy(
1003         1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
1004 
1005     object->proto_ = IRemoteObject::IF_PROT_DATABUS;
1006     IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent();
1007     current->proxyToSession_.clear();
1008     object->ReleaseDatabusProto();
1009     ASSERT_TRUE(object->handle_ != 0);
1010 }
1011