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 <gtest/gtest.h>
16 #include "access_token_adapter.h"
17 #define private public
18 #define protected public
19 #include "binder_invoker.h"
20 #include "binder_connector.h"
21 #undef protected
22 #undef private
23 #include "ipc_object_proxy.h"
24 #include "ipc_object_stub.h"
25 #include "ipc_process_skeleton.h"
26 #include "sys_binder.h"
27
28 using namespace testing::ext;
29 using namespace OHOS;
30
31 class BinderInvokerUnitTest : public testing::Test {
32 public:
33 static void SetUpTestCase(void);
34 static void TearDownTestCase(void);
35 void SetUp();
36 void TearDown();
37 };
38
SetUpTestCase()39 void BinderInvokerUnitTest::SetUpTestCase()
40 {}
41
TearDownTestCase()42 void BinderInvokerUnitTest::TearDownTestCase()
43 {}
44
SetUp()45 void BinderInvokerUnitTest::SetUp()
46 {}
47
TearDown()48 void BinderInvokerUnitTest::TearDown()
49 {}
50
51 /**
52 * @tc.name: SetCallingIdentityTest001
53 * @tc.desc: Verify the SetCallingIdentityTest001 function
54 * @tc.type: FUNC
55 */
56 HWTEST_F(BinderInvokerUnitTest, SetCallingIdentityTest001, TestSize.Level1)
57 {
58 BinderInvoker binderInvoker;
59 std::string identity;
60 bool ret = binderInvoker.SetCallingIdentity(identity);
61 EXPECT_EQ(ret, false);
62 identity = "aaa";
63 ret = binderInvoker.SetCallingIdentity(identity);
64 EXPECT_EQ(ret, false);
65 }
66
67 /**
68 * @tc.name: SetCallingIdentityTest002
69 * @tc.desc: Override SetCallingIdentity branch
70 * @tc.type: FUNC
71 */
72 HWTEST_F(BinderInvokerUnitTest, SetCallingIdentityTest002, TestSize.Level1)
73 {
74 BinderInvoker binderInvoker;
75 std::string token = binderInvoker.ResetCallingIdentity();
76 EXPECT_FALSE(token.empty());
77 bool ret = binderInvoker.SetCallingIdentity(token);
78 EXPECT_TRUE(ret);
79 }
80
81 /**
82 * @tc.name: ReadFileDescriptor001
83 * @tc.desc: Verify the ReadFileDescriptor function
84 * @tc.type: FUNC
85 */
86 HWTEST_F(BinderInvokerUnitTest, ReadFileDescriptor001, TestSize.Level1)
87 {
88 BinderInvoker binderInvoker;
89 Parcel parcel;
90 int ret = binderInvoker.ReadFileDescriptor(parcel);
91 EXPECT_EQ(ret, -1);
92 }
93
94 /**
95 * @tc.name: ReadFileDescriptor002
96 * @tc.desc: Verify the ReadFileDescriptor function
97 * @tc.type: FUNC
98 */
99 HWTEST_F(BinderInvokerUnitTest, ReadFileDescriptor002, TestSize.Level1)
100 {
101 BinderInvoker binderInvoker;
102 Parcel parcel;
103 flat_binder_object tr {};
104 tr.flags = 1;
105 tr.hdr.type = -1;
106 parcel.WriteBuffer(&tr, sizeof(flat_binder_object));
107 int ret = binderInvoker.ReadFileDescriptor(parcel);
108 EXPECT_EQ(ret, -1);
109 }
110
111 /**
112 * @tc.name: UnflattenObject001
113 * @tc.desc: Verify the UnflattenObject function
114 * @tc.type: FUNC
115 */
116 HWTEST_F(BinderInvokerUnitTest, UnflattenObject001, TestSize.Level1)
117 {
118 BinderInvoker binderInvoker;
119 Parcel parcel;
120 sptr<IRemoteObject> ret = binderInvoker.UnflattenObject(parcel);
121 EXPECT_EQ(ret, nullptr);
122 }
123
124 /**
125 * @tc.name: UnflattenObject002
126 * @tc.desc: Verify the UnflattenObject function
127 * @tc.type: FUNC
128 */
129 HWTEST_F(BinderInvokerUnitTest, UnflattenObject002, TestSize.Level1)
130 {
131 BinderInvoker binderInvoker;
132 Parcel parcel;
133 flat_binder_object tr {};
134 tr.flags = 1;
135 tr.hdr.type = -1;
136 parcel.WriteBuffer(&tr, sizeof(flat_binder_object));
137 sptr<IRemoteObject> ret = binderInvoker.UnflattenObject(parcel);
138 EXPECT_EQ(ret, nullptr);
139 }
140
141 /**
142 * @tc.name: SetRegistryObject001
143 * @tc.desc: Verify the SetRegistryObject function
144 * @tc.type: FUNC
145 */
146 HWTEST_F(BinderInvokerUnitTest, SetRegistryObject001, TestSize.Level1)
147 {
148 BinderInvoker binderInvoker;
149 binderInvoker.binderConnector_->driverFD_ = 0;
150 sptr<IRemoteObject> testStub = new IPCObjectStub(u"testStub");
151 bool ret = binderInvoker.SetRegistryObject(testStub);
152 EXPECT_EQ(ret, false);
153 }
154
155 /**
156 * @tc.name: SetRegistryObject002
157 * @tc.desc: Verify the SetRegistryObject function
158 * @tc.type: FUNC
159 */
160 HWTEST_F(BinderInvokerUnitTest, SetRegistryObject002, TestSize.Level1)
161 {
162 BinderInvoker binderInvoker;
163 binderInvoker.binderConnector_ = nullptr;
164 sptr<IRemoteObject> testStub = new IPCObjectStub(u"testStub");
165 bool ret = binderInvoker.SetRegistryObject(testStub);
166 EXPECT_EQ(ret, false);
167 }
168
169 /**
170 * @tc.name: SetRegistryObject003
171 * @tc.desc: Verify the SetRegistryObject function
172 * @tc.type: FUNC
173 */
174 HWTEST_F(BinderInvokerUnitTest, SetRegistryObject003, TestSize.Level1)
175 {
176 BinderInvoker binderInvoker;
177 sptr<IRemoteObject> testProxy = new IPCObjectProxy(5, u"testproxy");
178 bool ret = binderInvoker.SetRegistryObject(testProxy);
179 EXPECT_EQ(ret, false);
180 }
181
182 /**
183 * @tc.name: GetSAMgrObjectTest001
184 * @tc.desc: Verify the GetSAMgrObject function
185 * @tc.type: FUNC
186 */
187 HWTEST_F(BinderInvokerUnitTest, GetSAMgrObjectTest001, TestSize.Level1)
188 {
189 #ifndef CONFIG_IPC_SINGLE
190 BinderInvoker binderInvoker;
191 IPCProcessSkeleton* current = IPCProcessSkeleton::GetCurrent();
192 if (current != nullptr) {
193 EXPECT_EQ(binderInvoker.GetSAMgrObject(), current->GetRegistryObject());
194 } else {
195 EXPECT_EQ(binderInvoker.GetSAMgrObject(), nullptr);
196 }
197 #endif
198 }
199
200 /**
201 * @tc.name: SetMaxWorkThreadTest001
202 * @tc.desc: Verify the SetMaxWorkThread function
203 * @tc.type: FUNC
204 */
205 HWTEST_F(BinderInvokerUnitTest, SetMaxWorkThreadTest001, TestSize.Level1)
206 {
207 BinderInvoker binderInvoker;
208 binderInvoker.binderConnector_ = nullptr;
209 EXPECT_EQ(binderInvoker.SetMaxWorkThread(10), false);
210 }
211
212 /**
213 * @tc.name: FlushCommandsTest001
214 * @tc.desc: Verify the FlushCommands function
215 * @tc.type: FUNC
216 */
217 HWTEST_F(BinderInvokerUnitTest, FlushCommandsTest001, TestSize.Level1)
218 {
219 BinderInvoker binderInvoker;
220 binderInvoker.binderConnector_ = nullptr;
221 EXPECT_EQ(binderInvoker.FlushCommands(nullptr), IPC_INVOKER_CONNECT_ERR);
222 }
223
224 /**
225 * @tc.name: ExitCurrentThreadTest001
226 * @tc.desc: Verify the ExitCurrentThread function
227 * @tc.type: FUNC
228 */
229 HWTEST_F(BinderInvokerUnitTest, ExitCurrentThreadTest001, TestSize.Level1)
230 {
231 BinderInvoker binderInvoker;
232 binderInvoker.binderConnector_ = nullptr;
233 binderInvoker.ExitCurrentThread();
234 EXPECT_EQ(binderInvoker.binderConnector_, nullptr);
235 }
236
237 /**
238 * @tc.name: OnAttemptAcquireTest001
239 * @tc.desc: Verify the OnAttemptAcquire function
240 * @tc.type: FUNC
241 */
242 HWTEST_F(BinderInvokerUnitTest, OnAttemptAcquireTest001, TestSize.Level1)
243 {
244 BinderInvoker binderInvoker;
245 sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
246 binderInvoker.input_.WritePointer((uintptr_t)testStub->GetRefCounter());
247 binderInvoker.OnAttemptAcquire();
248 EXPECT_NE(reinterpret_cast<RefCounter *>(testStub->GetRefCounter()), nullptr);
249 }
250
251 /**
252 * @tc.name: OnAttemptAcquireTest002
253 * @tc.desc: Verify the OnAttemptAcquire function
254 * @tc.type: FUNC
255 */
256 HWTEST_F(BinderInvokerUnitTest, OnAttemptAcquireTest002, TestSize.Level1)
257 {
258 BinderInvoker binderInvoker;
259 void* test = nullptr;
260 binderInvoker.input_.WritePointer((uintptr_t)test);
261 binderInvoker.OnAttemptAcquire();
262
263 uintptr_t refsPtr = binderInvoker.input_.WritePointer((uintptr_t)test);
264 auto *refs = reinterpret_cast<RefCounter *>(refsPtr);
265 EXPECT_TRUE(refs != nullptr);
266 }
267
268 /**
269 * @tc.name: HandleReplyTest001
270 * @tc.desc: Verify the HandleReply function
271 * @tc.type: FUNC
272 */
273 HWTEST_F(BinderInvokerUnitTest, HandleReplyTest001, TestSize.Level1)
274 {
275 BinderInvoker binderInvoker;
276 EXPECT_EQ(binderInvoker.HandleReply(nullptr), IPC_INVOKER_INVALID_DATA_ERR);
277 }
278
279 /**
280 * @tc.name: HandleReplyTest002
281 * @tc.desc: Verify the HandleReply function
282 * @tc.type: FUNC
283 */
284 HWTEST_F(BinderInvokerUnitTest, HandleReplyTest002, TestSize.Level1)
285 {
286 binder_transaction_data transactionData;
287 BinderInvoker binderInvoker;
288 binderInvoker.input_.WriteBuffer(&transactionData, sizeof(binder_transaction_data));
289 EXPECT_EQ(binderInvoker.HandleReply(nullptr), IPC_INVOKER_INVALID_REPLY_ERR);
290 }
291
292 /**
293 * @tc.name: HandleCommandsInnerTest001
294 * @tc.desc: Verify the HandleCommandsInner function
295 * @tc.type: FUNC
296 */
297 HWTEST_F(BinderInvokerUnitTest, HandleCommandsInnerTest001, TestSize.Level1)
298 {
299 BinderInvoker binderInvoker;
300 EXPECT_EQ(binderInvoker.HandleCommandsInner(BR_ERROR), ERR_NONE);
301 }
302
303 /**
304 * @tc.name: HandleCommandsInnerTest002
305 * @tc.desc: Verify the HandleCommandsInner function
306 * @tc.type: FUNC
307 */
308 HWTEST_F(BinderInvokerUnitTest, HandleCommandsInnerTest002, TestSize.Level1)
309 {
310 BinderInvoker binderInvoker;
311 EXPECT_EQ(binderInvoker.HandleCommandsInner(BR_ATTEMPT_ACQUIRE), ERR_NONE);
312 }
313
314 /**
315 * @tc.name: HandleCommandsInnerTest003
316 * @tc.desc: Verify the HandleCommandsInner function
317 * @tc.type: FUNC
318 */
319 HWTEST_F(BinderInvokerUnitTest, HandleCommandsInnerTest003, TestSize.Level1)
320 {
321 BinderInvoker binderInvoker;
322 EXPECT_EQ(binderInvoker.HandleCommandsInner(BR_TRANSACTION), IPC_INVOKER_INVALID_DATA_ERR);
323 }
324
325 /**
326 * @tc.name: HandleCommandsInnerTest004
327 * @tc.desc: Verify the HandleCommandsInner function
328 * @tc.type: FUNC
329 */
330 HWTEST_F(BinderInvokerUnitTest, HandleCommandsInnerTest004, TestSize.Level1)
331 {
332 BinderInvoker binderInvoker;
333 EXPECT_EQ(binderInvoker.HandleCommandsInner(BR_SPAWN_LOOPER), ERR_NONE);
334 }
335
336 /**
337 * @tc.name: HandleCommandsInnerTest005
338 * @tc.desc: Verify the HandleCommandsInner function
339 * @tc.type: FUNC
340 */
341 HWTEST_F(BinderInvokerUnitTest, HandleCommandsInnerTest005, TestSize.Level1)
342 {
343 BinderInvoker binderInvoker;
344 EXPECT_EQ(binderInvoker.HandleCommandsInner(BR_FINISHED), -ERR_TIMED_OUT);
345 }
346
347 /**
348 * @tc.name: HandleCommandsInnerTest006
349 * @tc.desc: Verify the HandleCommandsInner function
350 * @tc.type: FUNC
351 */
352 HWTEST_F(BinderInvokerUnitTest, HandleCommandsInnerTest006, TestSize.Level1)
353 {
354 BinderInvoker binderInvoker;
355 uint32_t cmd = BR_DEAD_BINDER;
356 EXPECT_EQ(binderInvoker.HandleCommandsInner(cmd), ERR_NONE);
357 }
358
359 /**
360 * @tc.name: HandleCommandsInnerTest007
361 * @tc.desc: Verify the HandleCommandsInner function
362 * @tc.type: FUNC
363 */
364 HWTEST_F(BinderInvokerUnitTest, HandleCommandsInnerTest007, TestSize.Level1)
365 {
366 BinderInvoker binderInvoker;
367 uint32_t cmd = -1;
368 EXPECT_EQ(binderInvoker.HandleCommandsInner(cmd), IPC_INVOKER_ON_TRANSACT_ERR);
369 }
370
371 /**
372 * @tc.name: TransactWithDriverTest001
373 * @tc.desc: Verify the TransactWithDriver function
374 * @tc.type: FUNC
375 */
376 HWTEST_F(BinderInvokerUnitTest, TransactWithDriverTest001, TestSize.Level1)
377 {
378 BinderInvoker binderInvoker;
379 binderInvoker.binderConnector_ = nullptr;
380 EXPECT_EQ(binderInvoker.TransactWithDriver(true), IPC_INVOKER_CONNECT_ERR);
381 }
382
383 /**
384 * @tc.name: StartWorkLoopTest001
385 * @tc.desc: Override StartWorkLoop branch
386 * @tc.type: FUNC
387 */
388 HWTEST_F(BinderInvokerUnitTest, StartWorkLoopTest001, TestSize.Level1)
389 {
390 BinderInvoker binderInvoker;
391 binderInvoker.input_.WriteUint32(BR_TRANSACTION);
392 binderInvoker.isMainWorkThread = false;
393 binderInvoker.StartWorkLoop();
394
395 EXPECT_TRUE(binderInvoker.HandleCommands(BR_TRANSACTION) == IPC_INVOKER_INVALID_DATA_ERR);
396 EXPECT_TRUE(binderInvoker.isMainWorkThread == false);
397 }
398
399 /**
400 * @tc.name: HandleCommandsTest001
401 * @tc.desc: Override HandleCommands branch
402 * @tc.type: FUNC
403 */
404 HWTEST_F(BinderInvokerUnitTest, HandleCommandsTest001, TestSize.Level1)
405 {
406 BinderInvoker binderInvoker;
407 uint32_t cmd = BR_FINISHED;
408 int error = binderInvoker.HandleCommands(cmd);
409 EXPECT_EQ(error, -ERR_TIMED_OUT);
410 }
411
412 /**
413 * @tc.name: JoinProcessThreadTest001
414 * @tc.desc: Override JoinProcessThread branch
415 * @tc.type: FUNC
416 */
417 HWTEST_F(BinderInvokerUnitTest, JoinProcessThreadTest001, TestSize.Level1)
418 {
419 BinderInvoker binderInvoker;
420 bool initiative = false;
421 binderInvoker.JoinProcessThread(initiative);
422 EXPECT_TRUE(initiative == false);
423 }
424
425 /**
426 * @tc.name: WaitForCompletionTest001
427 * @tc.desc: Override WaitForCompletion branch
428 * @tc.type: FUNC
429 */
430 HWTEST_F(BinderInvokerUnitTest, WaitForCompletionTest001, TestSize.Level1)
431 {
432 BinderInvoker binderInvoker;
433 binderInvoker.input_.WriteUint32(BR_FAILED_REPLY);
434 MessageParcel reply;
435 int32_t acquireResult = 1;
436 int error = binderInvoker.WaitForCompletion(&reply, &acquireResult);
437 EXPECT_EQ(error, static_cast<int>(BR_FAILED_REPLY));
438 }
439
440 /**
441 * @tc.name: WaitForCompletionTest002
442 * @tc.desc: Override WaitForCompletion branch
443 * @tc.type: FUNC
444 */
445 HWTEST_F(BinderInvokerUnitTest, WaitForCompletionTest002, TestSize.Level1)
446 {
447 BinderInvoker binderInvoker;
448 binderInvoker.input_.WriteUint32(BR_ACQUIRE_RESULT);
449 MessageParcel reply;
450 int32_t acquireResult;
451 int error = binderInvoker.WaitForCompletion(&reply, &acquireResult);
452 EXPECT_EQ(error, ERR_NONE);
453 }
454
455 /**
456 * @tc.name: WaitForCompletionTest003
457 * @tc.desc: Override WaitForCompletion branch
458 * @tc.type: FUNC
459 */
460 HWTEST_F(BinderInvokerUnitTest, WaitForCompletionTest003, TestSize.Level1)
461 {
462 BinderInvoker binderInvoker;
463 binderInvoker.input_.WriteUint32(BR_TRANSLATION_COMPLETE);
464 MessageParcel reply;
465 int32_t acquireResult;
466 int error = binderInvoker.WaitForCompletion(&reply, &acquireResult);
467 EXPECT_EQ(error, ERR_NONE);
468 }
469
470 /**
471 * @tc.name: GetCallerPidTest001
472 * @tc.desc: Override GetCallerPid branch
473 * @tc.type: FUNC
474 */
475 HWTEST_F(BinderInvokerUnitTest, GetCallerPidTest001, TestSize.Level1)
476 {
477 BinderInvoker binderInvoker;
478 binderInvoker.callerPid_ = 1;
479 EXPECT_EQ(binderInvoker.GetCallerPid(), 1);
480 }
481
482 /**
483 * @tc.name: GetCallerUidTest001
484 * @tc.desc: Override GetCallerUid branch
485 * @tc.type: FUNC
486 */
487 HWTEST_F(BinderInvokerUnitTest, GetCallerUidTest001, TestSize.Level1)
488 {
489 BinderInvoker binderInvoker;
490 binderInvoker.callerUid_ = 1;
491 EXPECT_EQ(binderInvoker.GetCallerUid(), 1);
492 }
493
494 /**
495 * @tc.name: GetCallerTokenIDTest001
496 * @tc.desc: Override GetCallerTokenID branch
497 * @tc.type: FUNC
498 */
499 HWTEST_F(BinderInvokerUnitTest, GetCallerTokenIDTest001, TestSize.Level1)
500 {
501 BinderInvoker binderInvoker;
502 binderInvoker.callerTokenID_ = 1;
503 EXPECT_EQ(binderInvoker.GetCallerTokenID(), 1);
504 }
505
506 /**
507 * @tc.name: GetLocalDeviceIDTest001
508 * @tc.desc: Override GetLocalDeviceID branch
509 * @tc.type: FUNC
510 */
511 HWTEST_F(BinderInvokerUnitTest, GetLocalDeviceIDTest001, TestSize.Level1)
512 {
513 BinderInvoker binderInvoker;
514 EXPECT_EQ(binderInvoker.GetLocalDeviceID(), "");
515 }
516
517 /**
518 * @tc.name: GetCallerDeviceIDTest001
519 * @tc.desc: Override GetCallerDeviceID branch
520 * @tc.type: FUNC
521 */
522 HWTEST_F(BinderInvokerUnitTest, GetCallerDeviceIDTest001, TestSize.Level1)
523 {
524 BinderInvoker binderInvoker;
525 EXPECT_EQ(binderInvoker.GetCallerDeviceID(), "");
526 }
527
528 /**
529 * @tc.name: IsLocalCallingTest001
530 * @tc.desc: Override IsLocalCalling branch
531 * @tc.type: FUNC
532 */
533 HWTEST_F(BinderInvokerUnitTest, IsLocalCallingTest001, TestSize.Level1)
534 {
535 BinderInvoker binderInvoker;
536 EXPECT_EQ(binderInvoker.IsLocalCalling(), true);
537 }
538
539 /**
540 * @tc.name: FlattenObjectTest001
541 * @tc.desc: Override FlattenObject branch
542 * @tc.type: FUNC
543 */
544 HWTEST_F(BinderInvokerUnitTest, FlattenObjectTest001, TestSize.Level1)
545 {
546 BinderInvoker binderInvoker;
547 OHOS::Parcel parcel;
548 const IRemoteObject* object = nullptr;
549 EXPECT_EQ(binderInvoker.FlattenObject(parcel, object), false);
550 }
551
552 #ifndef CONFIG_IPC_SINGLE
553 /**
554 * @tc.name: TranslateIRemoteObjectTest001
555 * @tc.desc: Override TranslateIRemoteObject branch
556 * @tc.type: FUNC
557 */
558 HWTEST_F(BinderInvokerUnitTest, TranslateIRemoteObjectTest001, TestSize.Level1)
559 {
560 BinderInvoker binderInvoker;
561 int32_t cmd = 1;
562 sptr<IRemoteObject> testStub = new IPCObjectStub(u"testStub");
563 BinderConnector *binderConnector = BinderConnector::GetInstance();
564 binderConnector->driverFD_ = 1;
565 auto ret = binderInvoker.TranslateIRemoteObject(cmd, testStub);
566 EXPECT_EQ(ret, -IPC_INVOKER_TRANSLATE_ERR);
567 }
568
569 /**
570 * @tc.name: TranslateIRemoteObjectTest002
571 * @tc.desc: Override TranslateIRemoteObject branch
572 * @tc.type: FUNC
573 */
574 HWTEST_F(BinderInvokerUnitTest, TranslateIRemoteObjectTest002, TestSize.Level1)
575 {
576 BinderInvoker binderInvoker;
577 int32_t cmd = 1;
578 binderInvoker.binderConnector_ = nullptr;
579 sptr<IRemoteObject> testStub = new IPCObjectStub(u"testStub");
580 auto ret = binderInvoker.TranslateIRemoteObject(cmd, testStub);
581 EXPECT_EQ(ret, -IPC_INVOKER_CONNECT_ERR);
582 }
583
584 /**
585 * @tc.name: TranslateIRemoteObjectTest003
586 * @tc.desc: Override TranslateIRemoteObject branch
587 * @tc.type: FUNC
588 */
589 HWTEST_F(BinderInvokerUnitTest, TranslateIRemoteObjectTest003, TestSize.Level1)
590 {
591 BinderInvoker binderInvoker;
592 int32_t cmd = 1;
593 BinderConnector *binderConnector = BinderConnector::GetInstance();
594 binderConnector->driverFD_ = -1;
595 sptr<IRemoteObject> testStub = new IPCObjectStub(u"testStub");
596 auto ret = binderInvoker.TranslateIRemoteObject(cmd, testStub);
597 EXPECT_EQ(ret, -IPC_INVOKER_CONNECT_ERR);
598 }
599 #endif
600
601 /**
602 * @tc.name: GetSelfTokenIDTest002
603 * @tc.desc: Override GetSelfTokenID branch
604 * @tc.type: FUNC
605 */
606 HWTEST_F(BinderInvokerUnitTest, GetSelfTokenIDTest002, TestSize.Level1)
607 {
608 BinderInvoker binderInvoker;
609 binderInvoker.binderConnector_ = nullptr;
610 auto ret = binderInvoker.GetSelfTokenID();
611 EXPECT_EQ(ret, 0);
612 }
613
614 /**
615 * @tc.name: GetSelfTokenIDTest003
616 * @tc.desc: Override GetSelfTokenID branch
617 * @tc.type: FUNC
618 */
619 HWTEST_F(BinderInvokerUnitTest, GetSelfTokenIDTest003, TestSize.Level1)
620 {
621 BinderInvoker binderInvoker;
622 BinderConnector *binderConnector = BinderConnector::GetInstance();
623 binderConnector->driverFD_ = -1;
624 auto ret = binderInvoker.GetSelfTokenID();
625 EXPECT_EQ(ret, 0);
626 }
627
628 /**
629 * @tc.name: GetCallerTokenIDTest003
630 * @tc.desc: Override GetCallerTokenID branch
631 * @tc.type: FUNC
632 */
633 HWTEST_F(BinderInvokerUnitTest, GetCallerTokenIDTest003, TestSize.Level1)
634 {
635 BinderInvoker binderInvoker;
636 binderInvoker.callerTokenID_ = 0;
637 binderInvoker.callerUid_ = 1;
638 auto ret = binderInvoker.GetCallerTokenID();
639 EXPECT_EQ(ret, 1);
640 }