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 "dbinder_service.h"
17 #include "gtest/gtest.h"
18 #include "rpc_log.h"
19 #include "log_tags.h"
20 #define private public
21 #include "dbinder_death_recipient.h"
22 #undef private
23 
24 using namespace testing::ext;
25 using namespace OHOS;
26 using namespace OHOS::HiviewDFX;
27 
28 class DbinderDeathRecipientUnitTest : public testing::Test {
29 public:
30     static void SetUpTestCase(void);
31     static void TearDownTestCase(void);
32     void SetUp();
33     void TearDown();
34     static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_ID_TEST, "DBinderRemoteListenerUnitTest" };
35 };
36 
SetUp()37 void DbinderDeathRecipientUnitTest::SetUp() {}
38 
TearDown()39 void DbinderDeathRecipientUnitTest::TearDown() {}
40 
SetUpTestCase()41 void DbinderDeathRecipientUnitTest::SetUpTestCase() {}
42 
TearDownTestCase()43 void DbinderDeathRecipientUnitTest::TearDownTestCase() {}
44 
45 /**
46  * @tc.name: OnRemoteDied001
47  * @tc.desc: Verify the OnRemoteDied function when remote is nullptr
48  * @tc.type: FUNC
49  */
50 HWTEST_F(DbinderDeathRecipientUnitTest, OnRemoteDied001, TestSize.Level1)
51 {
52     DbinderDeathRecipient dbinderDeathRecipient;
53     wptr<IRemoteObject> remote = nullptr;
54     dbinderDeathRecipient.OnRemoteDied(remote);
55 }
56 
57 /**
58  * @tc.name: OnRemoteDied002
59  * @tc.desc: Verify the OnRemoteDied function when remote is a valid object
60  * @tc.type: FUNC
61  */
62 HWTEST_F(DbinderDeathRecipientUnitTest, OnRemoteDied002, TestSize.Level1)
63 {
64     DbinderDeathRecipient dbinderDeathRecipient;
65     int handle = 1;
66     sptr<IRemoteObject> result = nullptr;
67     std::u16string descriptor = std::u16string();
68     result = new (std::nothrow) IPCObjectProxy(handle, descriptor);
69     ASSERT_TRUE(result != nullptr);
70     IRemoteObject *object = result.GetRefPtr();
71     wptr<IRemoteObject> remote = object;
72     dbinderDeathRecipient.OnRemoteDied(remote);
73 }