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 "dbinder_session_object.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 "ipc_object_stub.h"
26 #include "ipc_thread_pool.h"
27 #include "stub_refcount_object.h"
28 #undef private
29
30 using namespace testing::ext;
31 using namespace OHOS;
32
33 namespace {
34 }
35 class IPCThreadSkeletonUnitTest : public testing::Test {
36 public:
37 static void SetUpTestCase(void);
38 static void TearDownTestCase(void);
39 void SetUp();
40 void TearDown();
41 };
42
SetUpTestCase()43 void IPCThreadSkeletonUnitTest::SetUpTestCase()
44 {
45 }
46
TearDownTestCase()47 void IPCThreadSkeletonUnitTest::TearDownTestCase()
48 {
49 }
50
SetUp()51 void IPCThreadSkeletonUnitTest::SetUp() {}
52
TearDown()53 void IPCThreadSkeletonUnitTest::TearDown() {}
54
55 /**
56 * @tc.name: GetRegistryObjectTest001
57 * @tc.desc: Verify the GetRegistryObject function
58 * @tc.type: FUNC
59 */
60 HWTEST_F(IPCThreadSkeletonUnitTest, GetRegistryObjectTest001, TestSize.Level1)
61 {
62 IPCThreadSkeleton *skeleton = IPCThreadSkeleton::GetCurrent();
63 ASSERT_TRUE(skeleton != nullptr);
64
65 sptr<IPCObjectProxy> objectProxy = new IPCObjectProxy(1);
66
67 IRemoteInvoker *object = skeleton->GetProxyInvoker(objectProxy.GetRefPtr());
68 EXPECT_NE(object, nullptr);
69 }
70
71 /**
72 * @tc.name: GetRegistryObjectTest002
73 * @tc.desc: Verify the GetRegistryObject function
74 * @tc.type: FUNC
75 */
76 HWTEST_F(IPCThreadSkeletonUnitTest, GetRegistryObjectTest002, TestSize.Level1)
77 {
78 IPCThreadSkeleton *skeleton = IPCThreadSkeleton::GetCurrent();
79 ASSERT_TRUE(skeleton != nullptr);
80
81 IRemoteInvoker *object = skeleton->GetProxyInvoker(nullptr);
82 EXPECT_EQ(object, nullptr);
83 }
84
85 /**
86 * @tc.name: GetRegistryObjectTest003
87 * @tc.desc: Verify the GetRegistryObject function
88 * @tc.type: FUNC
89 */
90 HWTEST_F(IPCThreadSkeletonUnitTest, GetRegistryObjectTest003, TestSize.Level1)
91 {
92 IPCThreadSkeleton *skeleton = IPCThreadSkeleton::GetCurrent();
93 ASSERT_TRUE(skeleton != nullptr);
94
95 sptr<IPCObjectStub> objectStub = new IPCObjectStub(u"testObject");
96
97 IRemoteInvoker *object = skeleton->GetProxyInvoker(objectStub.GetRefPtr());
98 EXPECT_EQ(object, nullptr);
99 }