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 #include "session_impl.h"
21 #define private public
22 #include "dbinder_death_recipient.h"
23 #undef private
24
25 using namespace testing::ext;
26 using namespace OHOS;
27 using namespace OHOS::HiviewDFX;
28 using Communication::SoftBus::Session;
29 using Communication::SoftBus::SessionImpl;
30
31 class DbinderDeathRecipientUnitTest : public testing::Test {
32 public:
33 static void SetUpTestCase(void);
34 static void TearDownTestCase(void);
35 void SetUp();
36 void TearDown();
37 static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_ID_RPC, "DBinderRemoteListenerUnitTest" };
38 };
39
SetUp()40 void DbinderDeathRecipientUnitTest::SetUp() {}
41
TearDown()42 void DbinderDeathRecipientUnitTest::TearDown() {}
43
SetUpTestCase()44 void DbinderDeathRecipientUnitTest::SetUpTestCase() {}
45
TearDownTestCase()46 void DbinderDeathRecipientUnitTest::TearDownTestCase() {}
47
48 HWTEST_F(DbinderDeathRecipientUnitTest, OnRemoteDied001, TestSize.Level1)
49 {
50 DbinderDeathRecipient dbinderDeathRecipient;
51 wptr<IRemoteObject> remote = nullptr;
52 dbinderDeathRecipient.OnRemoteDied(remote);
53 }
54
55 HWTEST_F(DbinderDeathRecipientUnitTest, OnRemoteDied002, TestSize.Level1)
56 {
57 DbinderDeathRecipient dbinderDeathRecipient;
58 int handle = 1;
59 sptr<IRemoteObject> result = nullptr;
60 std::u16string descriptor = std::u16string();
61 result = new (std::nothrow) IPCObjectProxy(handle, descriptor);
62 IRemoteObject *object = result.GetRefPtr();
63 wptr<IRemoteObject> remote = object;
64 dbinderDeathRecipient.OnRemoteDied(remote);
65 }