1a34a8711Sopenharmony_ci/*
2a34a8711Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3a34a8711Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4a34a8711Sopenharmony_ci * you may not use this file except in compliance with the License.
5a34a8711Sopenharmony_ci * You may obtain a copy of the License at
6a34a8711Sopenharmony_ci *
7a34a8711Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8a34a8711Sopenharmony_ci *
9a34a8711Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10a34a8711Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11a34a8711Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12a34a8711Sopenharmony_ci * See the License for the specific language governing permissions and
13a34a8711Sopenharmony_ci * limitations under the License.
14a34a8711Sopenharmony_ci */
15a34a8711Sopenharmony_ci
16a34a8711Sopenharmony_ci#include <cstring>
17a34a8711Sopenharmony_ci#include "securec.h"
18a34a8711Sopenharmony_ci#define private public
19a34a8711Sopenharmony_ci#include "dbinder_service.h"
20a34a8711Sopenharmony_ci#undef private
21a34a8711Sopenharmony_ci#include "dbinder_remote_listener.h"
22a34a8711Sopenharmony_ci#include "gtest/gtest.h"
23a34a8711Sopenharmony_ci#include "rpc_feature_set.h"
24a34a8711Sopenharmony_ci#include "rpc_log.h"
25a34a8711Sopenharmony_ci#include "log_tags.h"
26a34a8711Sopenharmony_ci#include "string_ex.h"
27a34a8711Sopenharmony_ci
28a34a8711Sopenharmony_ciusing namespace testing::ext;
29a34a8711Sopenharmony_ciusing namespace OHOS;
30a34a8711Sopenharmony_ciusing namespace OHOS::HiviewDFX;
31a34a8711Sopenharmony_ci
32a34a8711Sopenharmony_cinamespace {
33a34a8711Sopenharmony_ciconstexpr int TEST_STUB_INDEX = 1234;
34a34a8711Sopenharmony_ci}
35a34a8711Sopenharmony_ci
36a34a8711Sopenharmony_ciclass DBinderServiceUnitTest : public testing::Test {
37a34a8711Sopenharmony_cipublic:
38a34a8711Sopenharmony_ci    static void SetUpTestCase(void);
39a34a8711Sopenharmony_ci    static void TearDownTestCase(void);
40a34a8711Sopenharmony_ci    void SetUp();
41a34a8711Sopenharmony_ci    void TearDown();
42a34a8711Sopenharmony_ci    static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_ID_TEST, "DBinderServiceUnitTest" };
43a34a8711Sopenharmony_ci};
44a34a8711Sopenharmony_ci
45a34a8711Sopenharmony_civoid DBinderServiceUnitTest::SetUp() {}
46a34a8711Sopenharmony_ci
47a34a8711Sopenharmony_civoid DBinderServiceUnitTest::TearDown() {}
48a34a8711Sopenharmony_ci
49a34a8711Sopenharmony_civoid DBinderServiceUnitTest::SetUpTestCase() {}
50a34a8711Sopenharmony_ci
51a34a8711Sopenharmony_civoid DBinderServiceUnitTest::TearDownTestCase() {}
52a34a8711Sopenharmony_ci
53a34a8711Sopenharmony_ciclass TestDeathRecipient : public IRemoteObject::DeathRecipient {
54a34a8711Sopenharmony_cipublic:
55a34a8711Sopenharmony_ci    TestDeathRecipient() {}
56a34a8711Sopenharmony_ci    virtual ~TestDeathRecipient() {}
57a34a8711Sopenharmony_ci    void OnRemoteDied(const wptr<IRemoteObject>& object) override {}
58a34a8711Sopenharmony_ci};
59a34a8711Sopenharmony_ci
60a34a8711Sopenharmony_ciclass TestRpcSystemAbilityCallback : public RpcSystemAbilityCallback {
61a34a8711Sopenharmony_cipublic:
62a34a8711Sopenharmony_ci    sptr<IRemoteObject> GetSystemAbilityFromRemote(int32_t systemAbilityId) override
63a34a8711Sopenharmony_ci    {
64a34a8711Sopenharmony_ci        return nullptr;
65a34a8711Sopenharmony_ci    }
66a34a8711Sopenharmony_ci
67a34a8711Sopenharmony_ci    bool LoadSystemAbilityFromRemote(const std::string& srcNetworkId, int32_t systemAbilityId) override
68a34a8711Sopenharmony_ci    {
69a34a8711Sopenharmony_ci        return true;
70a34a8711Sopenharmony_ci    }
71a34a8711Sopenharmony_ci    bool IsDistributedSystemAbility(int32_t systemAbilityId) override
72a34a8711Sopenharmony_ci    {
73a34a8711Sopenharmony_ci        return true;
74a34a8711Sopenharmony_ci    }
75a34a8711Sopenharmony_ci};
76a34a8711Sopenharmony_ci
77a34a8711Sopenharmony_ci/*
78a34a8711Sopenharmony_ci * @tc.name: ProcessOnSessionClosed001
79a34a8711Sopenharmony_ci * @tc.desc: Verify the ProcessOnSessionClosed function
80a34a8711Sopenharmony_ci * @tc.type: FUNC
81a34a8711Sopenharmony_ci */
82a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, ProcessOnSessionClosed001, TestSize.Level1)
83a34a8711Sopenharmony_ci{
84a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
85a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
86a34a8711Sopenharmony_ci    std::string networkId = "1234567890";
87a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->ProcessOnSessionClosed(networkId), true);
88a34a8711Sopenharmony_ci}
89a34a8711Sopenharmony_ci
90a34a8711Sopenharmony_ci/*
91a34a8711Sopenharmony_ci * @tc.name: ProcessOnSessionClosed002
92a34a8711Sopenharmony_ci * @tc.desc: Verify the ProcessOnSessionClosed function
93a34a8711Sopenharmony_ci * @tc.type: FUNC
94a34a8711Sopenharmony_ci */
95a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, ProcessOnSessionClosed002, TestSize.Level1)
96a34a8711Sopenharmony_ci{
97a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
98a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
99a34a8711Sopenharmony_ci    std::string networkId = "";
100a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->ProcessOnSessionClosed(networkId), true);
101a34a8711Sopenharmony_ci}
102a34a8711Sopenharmony_ci
103a34a8711Sopenharmony_ci/**
104a34a8711Sopenharmony_ci * @tc.name: StartDBinderService001
105a34a8711Sopenharmony_ci * @tc.desc: Verify the StartDBinderService function
106a34a8711Sopenharmony_ci * @tc.type: FUNC
107a34a8711Sopenharmony_ci */
108a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, StartDBinderService001, TestSize.Level1)
109a34a8711Sopenharmony_ci{
110a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
111a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
112a34a8711Sopenharmony_ci    std::shared_ptr<RpcSystemAbilityCallback> callbackImpl = nullptr;
113a34a8711Sopenharmony_ci    bool res = dBinderService->StartDBinderService(callbackImpl);
114a34a8711Sopenharmony_ci    EXPECT_EQ(res, false);
115a34a8711Sopenharmony_ci}
116a34a8711Sopenharmony_ci
117a34a8711Sopenharmony_ci/**
118a34a8711Sopenharmony_ci * @tc.name: StartDBinderService002
119a34a8711Sopenharmony_ci * @tc.desc: Verify the StartDBinderService function
120a34a8711Sopenharmony_ci * @tc.type: FUNC
121a34a8711Sopenharmony_ci */
122a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, StartDBinderService002, TestSize.Level1)
123a34a8711Sopenharmony_ci{
124a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
125a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
126a34a8711Sopenharmony_ci    std::shared_ptr<RpcSystemAbilityCallback> callbackImpl = nullptr;
127a34a8711Sopenharmony_ci    DBinderService::mainThreadCreated_ = true;
128a34a8711Sopenharmony_ci    bool res = dBinderService->StartDBinderService(callbackImpl);
129a34a8711Sopenharmony_ci    EXPECT_EQ(res, false);
130a34a8711Sopenharmony_ci}
131a34a8711Sopenharmony_ci
132a34a8711Sopenharmony_ci/**
133a34a8711Sopenharmony_ci * @tc.name: StartDBinderService003
134a34a8711Sopenharmony_ci * @tc.desc: Verify the StartDBinderService function
135a34a8711Sopenharmony_ci * @tc.type: FUNC
136a34a8711Sopenharmony_ci */
137a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, StartDBinderService003, TestSize.Level1)
138a34a8711Sopenharmony_ci{
139a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
140a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
141a34a8711Sopenharmony_ci    std::shared_ptr<RpcSystemAbilityCallback> callbackImpl = nullptr;
142a34a8711Sopenharmony_ci    DBinderService::mainThreadCreated_ = false;
143a34a8711Sopenharmony_ci    dBinderService->remoteListener_ = nullptr;
144a34a8711Sopenharmony_ci    bool res = dBinderService->StartDBinderService(callbackImpl);
145a34a8711Sopenharmony_ci    EXPECT_EQ(res, false);
146a34a8711Sopenharmony_ci}
147a34a8711Sopenharmony_ci
148a34a8711Sopenharmony_ci/**
149a34a8711Sopenharmony_ci * @tc.name: StartDBinderService004
150a34a8711Sopenharmony_ci * @tc.desc: Verify the StartDBinderService function
151a34a8711Sopenharmony_ci * @tc.type: FUNC
152a34a8711Sopenharmony_ci */
153a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, StartDBinderService004, TestSize.Level1)
154a34a8711Sopenharmony_ci{
155a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
156a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
157a34a8711Sopenharmony_ci    std::shared_ptr<RpcSystemAbilityCallback> callbackImpl = nullptr;
158a34a8711Sopenharmony_ci    DBinderService::mainThreadCreated_ = false;
159a34a8711Sopenharmony_ci    dBinderService->remoteListener_ = std::make_shared<DBinderRemoteListener>();
160a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService->remoteListener_ != nullptr);
161a34a8711Sopenharmony_ci    bool res = dBinderService->StartDBinderService(callbackImpl);
162a34a8711Sopenharmony_ci    EXPECT_EQ(res, true);
163a34a8711Sopenharmony_ci}
164a34a8711Sopenharmony_ci
165a34a8711Sopenharmony_ci/**
166a34a8711Sopenharmony_ci * @tc.name: ReStartRemoteListener001
167a34a8711Sopenharmony_ci * @tc.desc: Verify the ReStartRemoteListener function
168a34a8711Sopenharmony_ci * @tc.type: FUNC
169a34a8711Sopenharmony_ci */
170a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, ReStartRemoteListener001, TestSize.Level1)
171a34a8711Sopenharmony_ci{
172a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
173a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
174a34a8711Sopenharmony_ci    dBinderService->remoteListener_ = nullptr;
175a34a8711Sopenharmony_ci    bool res = dBinderService->ReStartRemoteListener();
176a34a8711Sopenharmony_ci    EXPECT_EQ(res, false);
177a34a8711Sopenharmony_ci}
178a34a8711Sopenharmony_ci
179a34a8711Sopenharmony_ci/**
180a34a8711Sopenharmony_ci * @tc.name: ReStartRemoteListener002
181a34a8711Sopenharmony_ci * @tc.desc: Verify the ReStartRemoteListener function
182a34a8711Sopenharmony_ci * @tc.type: FUNC
183a34a8711Sopenharmony_ci */
184a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, ReStartRemoteListener002, TestSize.Level1)
185a34a8711Sopenharmony_ci{
186a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
187a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
188a34a8711Sopenharmony_ci    dBinderService->remoteListener_ = std::make_shared<DBinderRemoteListener>();
189a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService->remoteListener_ != nullptr);
190a34a8711Sopenharmony_ci    bool res = dBinderService->ReStartRemoteListener();
191a34a8711Sopenharmony_ci    EXPECT_EQ(res, false);
192a34a8711Sopenharmony_ci}
193a34a8711Sopenharmony_ci
194a34a8711Sopenharmony_ci/**
195a34a8711Sopenharmony_ci * @tc.name: StartRemoteListener001
196a34a8711Sopenharmony_ci * @tc.desc: Verify the StartRemoteListener function
197a34a8711Sopenharmony_ci * @tc.type: FUNC
198a34a8711Sopenharmony_ci */
199a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, StartRemoteListener001, TestSize.Level1)
200a34a8711Sopenharmony_ci{
201a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
202a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
203a34a8711Sopenharmony_ci    dBinderService->remoteListener_ = nullptr;
204a34a8711Sopenharmony_ci    bool res = dBinderService->StartRemoteListener();
205a34a8711Sopenharmony_ci    EXPECT_EQ(res, false);
206a34a8711Sopenharmony_ci}
207a34a8711Sopenharmony_ci
208a34a8711Sopenharmony_ci/**
209a34a8711Sopenharmony_ci * @tc.name: StartRemoteListener002
210a34a8711Sopenharmony_ci * @tc.desc: Verify the StartRemoteListener function
211a34a8711Sopenharmony_ci * @tc.type: FUNC
212a34a8711Sopenharmony_ci */
213a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, StartRemoteListener002, TestSize.Level1)
214a34a8711Sopenharmony_ci{
215a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
216a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
217a34a8711Sopenharmony_ci    dBinderService->remoteListener_ = std::make_shared<DBinderRemoteListener>();
218a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService->remoteListener_ != nullptr);
219a34a8711Sopenharmony_ci    bool res = dBinderService->StartRemoteListener();
220a34a8711Sopenharmony_ci    EXPECT_EQ(res, true);
221a34a8711Sopenharmony_ci}
222a34a8711Sopenharmony_ci
223a34a8711Sopenharmony_ci/**
224a34a8711Sopenharmony_ci * @tc.name: RegisterRemoteProxy001
225a34a8711Sopenharmony_ci * @tc.desc: Verify the RegisterRemoteProxy function
226a34a8711Sopenharmony_ci * @tc.type: FUNC
227a34a8711Sopenharmony_ci */
228a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, RegisterRemoteProxy001, TestSize.Level1)
229a34a8711Sopenharmony_ci{
230a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
231a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
232a34a8711Sopenharmony_ci    std::u16string serviceName = std::u16string();
233a34a8711Sopenharmony_ci    sptr<IRemoteObject> binderObject = nullptr;
234a34a8711Sopenharmony_ci    bool res = dBinderService->RegisterRemoteProxy(serviceName, binderObject);
235a34a8711Sopenharmony_ci    EXPECT_EQ(res, false);
236a34a8711Sopenharmony_ci}
237a34a8711Sopenharmony_ci
238a34a8711Sopenharmony_ci/**
239a34a8711Sopenharmony_ci * @tc.name: RegisterRemoteProxy002
240a34a8711Sopenharmony_ci * @tc.desc: Verify the RegisterRemoteProxy function
241a34a8711Sopenharmony_ci * @tc.type: FUNC
242a34a8711Sopenharmony_ci */
243a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, RegisterRemoteProxy002, TestSize.Level1)
244a34a8711Sopenharmony_ci{
245a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
246a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
247a34a8711Sopenharmony_ci    std::u16string serviceName = std::u16string();
248a34a8711Sopenharmony_ci    int32_t systemAbilityId = 0;
249a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, systemAbilityId), false);
250a34a8711Sopenharmony_ci}
251a34a8711Sopenharmony_ci
252a34a8711Sopenharmony_ci/**
253a34a8711Sopenharmony_ci * @tc.name: QuerySessionObject001
254a34a8711Sopenharmony_ci * @tc.desc: Verify the QuerySessionObject function
255a34a8711Sopenharmony_ci * @tc.type: FUNC
256a34a8711Sopenharmony_ci */
257a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, QuerySessionObject001, TestSize.Level1)
258a34a8711Sopenharmony_ci{
259a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
260a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
261a34a8711Sopenharmony_ci    binder_uintptr_t stub = 0;
262a34a8711Sopenharmony_ci    std::shared_ptr<struct SessionInfo> testSession = nullptr;
263a34a8711Sopenharmony_ci    testSession = dBinderService->QuerySessionObject(stub);
264a34a8711Sopenharmony_ci    EXPECT_EQ(testSession, nullptr);
265a34a8711Sopenharmony_ci}
266a34a8711Sopenharmony_ci
267a34a8711Sopenharmony_ci/**
268a34a8711Sopenharmony_ci * @tc.name: QuerySessionObject002
269a34a8711Sopenharmony_ci * @tc.desc: Verify the QuerySessionObject function
270a34a8711Sopenharmony_ci * @tc.type: FUNC
271a34a8711Sopenharmony_ci */
272a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, QuerySessionObject002, TestSize.Level1)
273a34a8711Sopenharmony_ci{
274a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
275a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
276a34a8711Sopenharmony_ci    binder_uintptr_t stub = 0;
277a34a8711Sopenharmony_ci    std::shared_ptr<struct SessionInfo> Session = nullptr;
278a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->AttachSessionObject(Session, stub), true);
279a34a8711Sopenharmony_ci    std::shared_ptr<struct SessionInfo> testSession = dBinderService->QuerySessionObject(stub);
280a34a8711Sopenharmony_ci    EXPECT_EQ(testSession, Session);
281a34a8711Sopenharmony_ci}
282a34a8711Sopenharmony_ci
283a34a8711Sopenharmony_ci/**
284a34a8711Sopenharmony_ci * @tc.name: AttachDeathRecipient001
285a34a8711Sopenharmony_ci * @tc.desc: Verify the AttachDeathRecipient function
286a34a8711Sopenharmony_ci * @tc.type: FUNC
287a34a8711Sopenharmony_ci */
288a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, AttachDeathRecipient001, TestSize.Level1)
289a34a8711Sopenharmony_ci{
290a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
291a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
292a34a8711Sopenharmony_ci    sptr<IRemoteObject> object = nullptr;
293a34a8711Sopenharmony_ci    sptr<IRemoteObject::DeathRecipient> deathRecipient = nullptr;
294a34a8711Sopenharmony_ci    bool res = dBinderService->AttachDeathRecipient(object, deathRecipient);
295a34a8711Sopenharmony_ci    EXPECT_TRUE(res);
296a34a8711Sopenharmony_ci}
297a34a8711Sopenharmony_ci
298a34a8711Sopenharmony_ci/**
299a34a8711Sopenharmony_ci * @tc.name: AttachCallbackProxy001
300a34a8711Sopenharmony_ci * @tc.desc: Verify the AttachCallbackProxy function
301a34a8711Sopenharmony_ci * @tc.type: FUNC
302a34a8711Sopenharmony_ci */
303a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, AttachCallbackProxy001, TestSize.Level1)
304a34a8711Sopenharmony_ci{
305a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
306a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
307a34a8711Sopenharmony_ci    sptr<IRemoteObject> object = nullptr;
308a34a8711Sopenharmony_ci    DBinderServiceStub *dbStub = nullptr;
309a34a8711Sopenharmony_ci    bool res = dBinderService->AttachCallbackProxy(object, dbStub);
310a34a8711Sopenharmony_ci    EXPECT_TRUE(res);
311a34a8711Sopenharmony_ci}
312a34a8711Sopenharmony_ci
313a34a8711Sopenharmony_ci/**
314a34a8711Sopenharmony_ci * @tc.name: DetachProxyObject001
315a34a8711Sopenharmony_ci * @tc.desc: Verify the DetachProxyObject function
316a34a8711Sopenharmony_ci * @tc.type: FUNC
317a34a8711Sopenharmony_ci */
318a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, DetachProxyObject001, TestSize.Level1)
319a34a8711Sopenharmony_ci{
320a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
321a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
322a34a8711Sopenharmony_ci    binder_uintptr_t binderObject = 0;
323a34a8711Sopenharmony_ci    bool res = dBinderService->DetachProxyObject(binderObject);
324a34a8711Sopenharmony_ci    EXPECT_EQ(res, false);
325a34a8711Sopenharmony_ci}
326a34a8711Sopenharmony_ci
327a34a8711Sopenharmony_ci/**
328a34a8711Sopenharmony_ci * @tc.name: ConvertToSecureDeviceIDTest001
329a34a8711Sopenharmony_ci * @tc.desc: Verify the ConvertToSecureDeviceID function
330a34a8711Sopenharmony_ci * @tc.type: FUNC
331a34a8711Sopenharmony_ci */
332a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, ConvertToSecureDeviceIDTest001, TestSize.Level1)
333a34a8711Sopenharmony_ci{
334a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
335a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
336a34a8711Sopenharmony_ci    std::string deviceID;
337a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->ConvertToSecureDeviceID(deviceID), "****");
338a34a8711Sopenharmony_ci}
339a34a8711Sopenharmony_ci
340a34a8711Sopenharmony_ci/**
341a34a8711Sopenharmony_ci * @tc.name: ConvertToSecureDeviceIDTest002
342a34a8711Sopenharmony_ci * @tc.desc: Verify the ConvertToSecureDeviceID function
343a34a8711Sopenharmony_ci * @tc.type: FUNC
344a34a8711Sopenharmony_ci */
345a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, ConvertToSecureDeviceIDTest002, TestSize.Level1)
346a34a8711Sopenharmony_ci{
347a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
348a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
349a34a8711Sopenharmony_ci    std::string deviceID("123456");
350a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->ConvertToSecureDeviceID(deviceID),
351a34a8711Sopenharmony_ci    deviceID.substr(0, ENCRYPT_LENGTH) + "****" + deviceID.substr(strlen(deviceID.c_str()) - ENCRYPT_LENGTH));
352a34a8711Sopenharmony_ci}
353a34a8711Sopenharmony_ci
354a34a8711Sopenharmony_ci/**
355a34a8711Sopenharmony_ci * @tc.name: GetRemoteTransTypeTest003
356a34a8711Sopenharmony_ci * @tc.desc: Verify the GetRemoteTransType function
357a34a8711Sopenharmony_ci * @tc.type: FUNC
358a34a8711Sopenharmony_ci */
359a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, GetRemoteTransTypeTest003, TestSize.Level1)
360a34a8711Sopenharmony_ci{
361a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
362a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
363a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->GetRemoteTransType(), IRemoteObject::DATABUS_TYPE);
364a34a8711Sopenharmony_ci}
365a34a8711Sopenharmony_ci
366a34a8711Sopenharmony_ci/**
367a34a8711Sopenharmony_ci * @tc.name: StopRemoteListener001
368a34a8711Sopenharmony_ci * @tc.desc: Verify the StopRemoteListener function
369a34a8711Sopenharmony_ci * @tc.type: FUNC
370a34a8711Sopenharmony_ci */
371a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, StopRemoteListener001, TestSize.Level1)
372a34a8711Sopenharmony_ci{
373a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
374a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
375a34a8711Sopenharmony_ci    std::shared_ptr<DBinderRemoteListener> testListener = std::make_shared<DBinderRemoteListener>();
376a34a8711Sopenharmony_ci    EXPECT_TRUE(testListener != nullptr);
377a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->StartRemoteListener(), true);
378a34a8711Sopenharmony_ci    dBinderService->StopRemoteListener();
379a34a8711Sopenharmony_ci}
380a34a8711Sopenharmony_ci
381a34a8711Sopenharmony_ci/**
382a34a8711Sopenharmony_ci * @tc.name: GetRemoteTransType001
383a34a8711Sopenharmony_ci * @tc.desc: Verify the GetRemoteTransType function
384a34a8711Sopenharmony_ci * @tc.type: FUNC
385a34a8711Sopenharmony_ci */
386a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, GetRemoteListener001, TestSize.Level1)
387a34a8711Sopenharmony_ci{
388a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
389a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
390a34a8711Sopenharmony_ci    std::shared_ptr<DBinderRemoteListener> testDbinder = nullptr;
391a34a8711Sopenharmony_ci    testDbinder = dBinderService->GetRemoteListener();
392a34a8711Sopenharmony_ci    EXPECT_EQ(testDbinder, nullptr);
393a34a8711Sopenharmony_ci}
394a34a8711Sopenharmony_ci
395a34a8711Sopenharmony_ci/**
396a34a8711Sopenharmony_ci * @tc.name: GetRemoteListener002
397a34a8711Sopenharmony_ci * @tc.desc: Verify the GetRemoteListener function
398a34a8711Sopenharmony_ci * @tc.type: FUNC
399a34a8711Sopenharmony_ci */
400a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, GetRemoteListener002, TestSize.Level1)
401a34a8711Sopenharmony_ci{
402a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
403a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
404a34a8711Sopenharmony_ci    std::shared_ptr<DBinderRemoteListener> testListener = std::make_shared<DBinderRemoteListener>();
405a34a8711Sopenharmony_ci    EXPECT_TRUE(testListener != nullptr);
406a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->StartRemoteListener(), false);
407a34a8711Sopenharmony_ci    std::shared_ptr<DBinderRemoteListener> testDbinder = nullptr;
408a34a8711Sopenharmony_ci    testDbinder = dBinderService->GetRemoteListener();
409a34a8711Sopenharmony_ci}
410a34a8711Sopenharmony_ci
411a34a8711Sopenharmony_ci/**
412a34a8711Sopenharmony_ci * @tc.name: GetSeqNumber001
413a34a8711Sopenharmony_ci * @tc.desc: Verify the GetSeqNumber function
414a34a8711Sopenharmony_ci * @tc.type: FUNC
415a34a8711Sopenharmony_ci */
416a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, GetSeqNumber001, TestSize.Level1)
417a34a8711Sopenharmony_ci{
418a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
419a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
420a34a8711Sopenharmony_ci    dBinderService->seqNumber_ = 0;
421a34a8711Sopenharmony_ci    uint32_t ret = dBinderService->GetSeqNumber();
422a34a8711Sopenharmony_ci    EXPECT_EQ(ret, dBinderService->seqNumber_++);
423a34a8711Sopenharmony_ci}
424a34a8711Sopenharmony_ci
425a34a8711Sopenharmony_ci/**
426a34a8711Sopenharmony_ci * @tc.name: IsDeviceIdIllegal001
427a34a8711Sopenharmony_ci * @tc.desc: Verify the IsDeviceIdIllegal function
428a34a8711Sopenharmony_ci * @tc.type: FUNC
429a34a8711Sopenharmony_ci */
430a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, IsDeviceIdIllegal001, TestSize.Level1)
431a34a8711Sopenharmony_ci{
432a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
433a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
434a34a8711Sopenharmony_ci    std::string deviceID = "";
435a34a8711Sopenharmony_ci    bool res = dBinderService->IsDeviceIdIllegal(deviceID);
436a34a8711Sopenharmony_ci    EXPECT_EQ(res, true);
437a34a8711Sopenharmony_ci}
438a34a8711Sopenharmony_ci
439a34a8711Sopenharmony_ci/**
440a34a8711Sopenharmony_ci * @tc.name: IsDeviceIdIllegal002
441a34a8711Sopenharmony_ci * @tc.desc: Verify the IsDeviceIdIllegal function
442a34a8711Sopenharmony_ci * @tc.type: FUNC
443a34a8711Sopenharmony_ci */
444a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, IsDeviceIdIllegal002, TestSize.Level1)
445a34a8711Sopenharmony_ci{
446a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
447a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
448a34a8711Sopenharmony_ci    std::string deviceID = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
449a34a8711Sopenharmony_ci    bool res = dBinderService->IsDeviceIdIllegal(deviceID);
450a34a8711Sopenharmony_ci    EXPECT_EQ(res, true);
451a34a8711Sopenharmony_ci}
452a34a8711Sopenharmony_ci
453a34a8711Sopenharmony_ci/**
454a34a8711Sopenharmony_ci * @tc.name: IsDeviceIdIllegal003
455a34a8711Sopenharmony_ci * @tc.desc: Verify the IsDeviceIdIllegal function
456a34a8711Sopenharmony_ci * @tc.type: FUNC
457a34a8711Sopenharmony_ci */
458a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, IsDeviceIdIllegal003, TestSize.Level1)
459a34a8711Sopenharmony_ci{
460a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
461a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
462a34a8711Sopenharmony_ci    std::string deviceID = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
463a34a8711Sopenharmony_ci    bool res = dBinderService->IsDeviceIdIllegal(deviceID);
464a34a8711Sopenharmony_ci    EXPECT_EQ(res, false);
465a34a8711Sopenharmony_ci}
466a34a8711Sopenharmony_ci
467a34a8711Sopenharmony_ci/**
468a34a8711Sopenharmony_ci * @tc.name: CheckBinderObject001
469a34a8711Sopenharmony_ci * @tc.desc: Verify the CheckBinderObject function
470a34a8711Sopenharmony_ci * @tc.type: FUNC
471a34a8711Sopenharmony_ci */
472a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, CheckBinderObject001, TestSize.Level1)
473a34a8711Sopenharmony_ci{
474a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
475a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
476a34a8711Sopenharmony_ci    sptr<DBinderServiceStub> stub = nullptr;
477a34a8711Sopenharmony_ci    binder_uintptr_t binderObject = 1564618;
478a34a8711Sopenharmony_ci    bool res = dBinderService->CheckBinderObject(stub, binderObject);
479a34a8711Sopenharmony_ci    EXPECT_EQ(res, false);
480a34a8711Sopenharmony_ci}
481a34a8711Sopenharmony_ci
482a34a8711Sopenharmony_ci/**
483a34a8711Sopenharmony_ci * @tc.name: CheckBinderObject002
484a34a8711Sopenharmony_ci * @tc.desc: Verify the CheckBinderObject function
485a34a8711Sopenharmony_ci * @tc.type: FUNC
486a34a8711Sopenharmony_ci */
487a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, CheckBinderObject002, TestSize.Level1)
488a34a8711Sopenharmony_ci{
489a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
490a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
491a34a8711Sopenharmony_ci    const std::string serviceName = "abc";
492a34a8711Sopenharmony_ci    const std::string deviceID = "bcd";
493a34a8711Sopenharmony_ci    binder_uintptr_t binderObject = 1564618;
494a34a8711Sopenharmony_ci    sptr<DBinderServiceStub> stub = new DBinderServiceStub(serviceName, deviceID, binderObject);
495a34a8711Sopenharmony_ci    EXPECT_TRUE(stub != nullptr);
496a34a8711Sopenharmony_ci    bool res = dBinderService->CheckBinderObject(stub, binderObject);
497a34a8711Sopenharmony_ci    EXPECT_EQ(res, false);
498a34a8711Sopenharmony_ci}
499a34a8711Sopenharmony_ci
500a34a8711Sopenharmony_ci/**
501a34a8711Sopenharmony_ci * @tc.name: IsSameStubObject001
502a34a8711Sopenharmony_ci * @tc.desc: Verify the IsSameStubObject function
503a34a8711Sopenharmony_ci * @tc.type: FUNC
504a34a8711Sopenharmony_ci */
505a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, IsSameStubObject001, TestSize.Level1)
506a34a8711Sopenharmony_ci{
507a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
508a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
509a34a8711Sopenharmony_ci    sptr<DBinderServiceStub> stub = nullptr;
510a34a8711Sopenharmony_ci    std::u16string service = std::u16string();
511a34a8711Sopenharmony_ci    const std::string device = "";
512a34a8711Sopenharmony_ci    bool res = dBinderService->IsSameStubObject(stub, service, device);
513a34a8711Sopenharmony_ci    EXPECT_EQ(res, false);
514a34a8711Sopenharmony_ci}
515a34a8711Sopenharmony_ci
516a34a8711Sopenharmony_ci/**
517a34a8711Sopenharmony_ci * @tc.name: MakeRemoteBinder001
518a34a8711Sopenharmony_ci * @tc.desc: Verify the MakeRemoteBinder function
519a34a8711Sopenharmony_ci * @tc.type: FUNC
520a34a8711Sopenharmony_ci */
521a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, MakeRemoteBinder001, TestSize.Level1)
522a34a8711Sopenharmony_ci{
523a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
524a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
525a34a8711Sopenharmony_ci    std::u16string serviceName = std::u16string();
526a34a8711Sopenharmony_ci    std::string deviceID = "";
527a34a8711Sopenharmony_ci    binder_uintptr_t binderObject = 12345;
528a34a8711Sopenharmony_ci    uint32_t pid = 0;
529a34a8711Sopenharmony_ci    uint32_t uid = 0;
530a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->MakeRemoteBinder(serviceName, deviceID, binderObject, pid, uid), nullptr);
531a34a8711Sopenharmony_ci}
532a34a8711Sopenharmony_ci
533a34a8711Sopenharmony_ci/**
534a34a8711Sopenharmony_ci * @tc.name: MakeRemoteBinder002
535a34a8711Sopenharmony_ci * @tc.desc: Verify the MakeRemoteBinder function
536a34a8711Sopenharmony_ci * @tc.type: FUNC
537a34a8711Sopenharmony_ci */
538a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, MakeRemoteBinder002, TestSize.Level1)
539a34a8711Sopenharmony_ci{
540a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
541a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
542a34a8711Sopenharmony_ci    std::u16string serviceName;
543a34a8711Sopenharmony_ci    std::string deviceID("001");
544a34a8711Sopenharmony_ci    binder_uintptr_t binderObject = 12345;
545a34a8711Sopenharmony_ci    uint32_t pid = 0;
546a34a8711Sopenharmony_ci    uint32_t uid = 0;
547a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->MakeRemoteBinder(serviceName, deviceID, binderObject, pid, uid), nullptr);
548a34a8711Sopenharmony_ci}
549a34a8711Sopenharmony_ci
550a34a8711Sopenharmony_ci/**
551a34a8711Sopenharmony_ci * @tc.name: MakeRemoteBinderTest003
552a34a8711Sopenharmony_ci * @tc.desc: Verify the MakeRemoteBinder function
553a34a8711Sopenharmony_ci * @tc.type: FUNC
554a34a8711Sopenharmony_ci */
555a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, MakeRemoteBinderTest003, TestSize.Level1)
556a34a8711Sopenharmony_ci{
557a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
558a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
559a34a8711Sopenharmony_ci    std::u16string serviceName;
560a34a8711Sopenharmony_ci    std::string deviceID("001");
561a34a8711Sopenharmony_ci    binder_uintptr_t binderObject = 12345;
562a34a8711Sopenharmony_ci    uint32_t pid = 10;
563a34a8711Sopenharmony_ci    uint32_t uid = 10;
564a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->MakeRemoteBinder(serviceName, deviceID, binderObject, pid, uid), nullptr);
565a34a8711Sopenharmony_ci}
566a34a8711Sopenharmony_ci
567a34a8711Sopenharmony_ci/**
568a34a8711Sopenharmony_ci * @tc.name: SendEntryToRemote001
569a34a8711Sopenharmony_ci * @tc.desc: Verify the SendEntryToRemote function
570a34a8711Sopenharmony_ci * @tc.type: FUNC
571a34a8711Sopenharmony_ci */
572a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, SendEntryToRemote001, TestSize.Level1)
573a34a8711Sopenharmony_ci{
574a34a8711Sopenharmony_ci    std::string serviceName = "testServiceName";
575a34a8711Sopenharmony_ci    std::string deviceID = "testDeviceID";
576a34a8711Sopenharmony_ci    binder_uintptr_t binderObject = 161561;
577a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
578a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
579a34a8711Sopenharmony_ci    sptr<DBinderServiceStub> stub = new DBinderServiceStub(serviceName, deviceID, binderObject);
580a34a8711Sopenharmony_ci    EXPECT_TRUE(stub != nullptr);
581a34a8711Sopenharmony_ci    uint32_t seqNumber = 0;
582a34a8711Sopenharmony_ci    uint32_t pid = 0;
583a34a8711Sopenharmony_ci    uint32_t uid = 0;
584a34a8711Sopenharmony_ci    bool res = dBinderService->SendEntryToRemote(stub, seqNumber, pid, uid);
585a34a8711Sopenharmony_ci    EXPECT_EQ(res, false);
586a34a8711Sopenharmony_ci}
587a34a8711Sopenharmony_ci
588a34a8711Sopenharmony_ci/**
589a34a8711Sopenharmony_ci * @tc.name: CheckSystemAbilityId001
590a34a8711Sopenharmony_ci * @tc.desc: Verify the CheckSystemAbilityId function
591a34a8711Sopenharmony_ci * @tc.type: FUNC
592a34a8711Sopenharmony_ci */
593a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, CheckSystemAbilityId001, TestSize.Level1)
594a34a8711Sopenharmony_ci{
595a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
596a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
597a34a8711Sopenharmony_ci    int32_t systemAbilityId = 0x00000002;
598a34a8711Sopenharmony_ci    bool res = dBinderService->CheckSystemAbilityId(systemAbilityId);
599a34a8711Sopenharmony_ci    EXPECT_EQ(res, true);
600a34a8711Sopenharmony_ci}
601a34a8711Sopenharmony_ci
602a34a8711Sopenharmony_ci/**
603a34a8711Sopenharmony_ci * @tc.name: AllocFreeSocketPort001
604a34a8711Sopenharmony_ci * @tc.desc: Verify the AllocFreeSocketPort function
605a34a8711Sopenharmony_ci * @tc.type: FUNC
606a34a8711Sopenharmony_ci */
607a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, AllocFreeSocketPort001, TestSize.Level1)
608a34a8711Sopenharmony_ci{
609a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
610a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
611a34a8711Sopenharmony_ci    uint16_t ret = dBinderService->AllocFreeSocketPort();
612a34a8711Sopenharmony_ci    EXPECT_EQ(ret, 0);
613a34a8711Sopenharmony_ci}
614a34a8711Sopenharmony_ci
615a34a8711Sopenharmony_ci/**
616a34a8711Sopenharmony_ci * @tc.name: IsSameLoadSaItem001
617a34a8711Sopenharmony_ci * @tc.desc: Verify the IsSameLoadSaItem function
618a34a8711Sopenharmony_ci * @tc.type: FUNC
619a34a8711Sopenharmony_ci */
620a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, IsSameLoadSaItem001, TestSize.Level1)
621a34a8711Sopenharmony_ci{
622a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
623a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
624a34a8711Sopenharmony_ci    std::string srcNetworkId = "aaaaaaaaaaaaaa";
625a34a8711Sopenharmony_ci    int32_t systemAbilityId = 123;
626a34a8711Sopenharmony_ci    std::shared_ptr<DHandleEntryTxRx> loadSaItem = std::make_shared<DHandleEntryTxRx>();
627a34a8711Sopenharmony_ci    EXPECT_TRUE(loadSaItem != nullptr);
628a34a8711Sopenharmony_ci    loadSaItem->stubIndex = 123;
629a34a8711Sopenharmony_ci    strcpy_s(loadSaItem->deviceIdInfo.fromDeviceId, DEVICEID_LENGTH, "aaaaaaaaaaaaaa");
630a34a8711Sopenharmony_ci    bool res = dBinderService->IsSameLoadSaItem(srcNetworkId, systemAbilityId, loadSaItem);
631a34a8711Sopenharmony_ci    EXPECT_EQ(res, true);
632a34a8711Sopenharmony_ci}
633a34a8711Sopenharmony_ci
634a34a8711Sopenharmony_ci/**
635a34a8711Sopenharmony_ci * @tc.name: IsSameLoadSaItem002
636a34a8711Sopenharmony_ci * @tc.desc: Verify the IsSameLoadSaItem function
637a34a8711Sopenharmony_ci * @tc.type: FUNC
638a34a8711Sopenharmony_ci */
639a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, IsSameLoadSaItem002, TestSize.Level1)
640a34a8711Sopenharmony_ci{
641a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
642a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
643a34a8711Sopenharmony_ci    std::string srcNetworkId = "bbbbbbb";
644a34a8711Sopenharmony_ci    int32_t systemAbilityId = 123;
645a34a8711Sopenharmony_ci    std::shared_ptr<DHandleEntryTxRx> loadSaItem = std::make_shared<DHandleEntryTxRx>();
646a34a8711Sopenharmony_ci    EXPECT_TRUE(loadSaItem != nullptr);
647a34a8711Sopenharmony_ci    loadSaItem->stubIndex = 123;
648a34a8711Sopenharmony_ci    strcpy_s(loadSaItem->deviceIdInfo.fromDeviceId, DEVICEID_LENGTH, "aaaaaaaaaaaaaa");
649a34a8711Sopenharmony_ci    bool res = dBinderService->IsSameLoadSaItem(srcNetworkId, systemAbilityId, loadSaItem);
650a34a8711Sopenharmony_ci    EXPECT_EQ(res, false);
651a34a8711Sopenharmony_ci}
652a34a8711Sopenharmony_ci
653a34a8711Sopenharmony_ci/**
654a34a8711Sopenharmony_ci * @tc.name: IsSameLoadSaItem003
655a34a8711Sopenharmony_ci * @tc.desc: Verify the IsSameLoadSaItem function
656a34a8711Sopenharmony_ci * @tc.type: FUNC
657a34a8711Sopenharmony_ci */
658a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, IsSameLoadSaItem003, TestSize.Level1)
659a34a8711Sopenharmony_ci{
660a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
661a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
662a34a8711Sopenharmony_ci    std::string srcNetworkId = "aaaaaaaaaaaaaa";
663a34a8711Sopenharmony_ci    int32_t systemAbilityId = 321;
664a34a8711Sopenharmony_ci    std::shared_ptr<DHandleEntryTxRx> loadSaItem = std::make_shared<DHandleEntryTxRx>();
665a34a8711Sopenharmony_ci    EXPECT_TRUE(loadSaItem != nullptr);
666a34a8711Sopenharmony_ci    loadSaItem->stubIndex = 123;
667a34a8711Sopenharmony_ci    strcpy_s(loadSaItem->deviceIdInfo.fromDeviceId, DEVICEID_LENGTH, "aaaaaaaaaaaaaa");
668a34a8711Sopenharmony_ci    bool res = dBinderService->IsSameLoadSaItem(srcNetworkId, systemAbilityId, loadSaItem);
669a34a8711Sopenharmony_ci    EXPECT_EQ(res, false);
670a34a8711Sopenharmony_ci}
671a34a8711Sopenharmony_ci
672a34a8711Sopenharmony_ci/**
673a34a8711Sopenharmony_ci * @tc.name: OnRemoteInvokerMessage002
674a34a8711Sopenharmony_ci * @tc.desc: Verify the OnRemoteInvokerMessage function
675a34a8711Sopenharmony_ci * @tc.type: FUNC
676a34a8711Sopenharmony_ci */
677a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, OnRemoteInvokerMessage002, TestSize.Level1)
678a34a8711Sopenharmony_ci{
679a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
680a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
681a34a8711Sopenharmony_ci    std::shared_ptr<struct DHandleEntryTxRx> message = std::make_shared<DHandleEntryTxRx>();
682a34a8711Sopenharmony_ci    EXPECT_TRUE(message != nullptr);
683a34a8711Sopenharmony_ci    (void)memset_s(message.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
684a34a8711Sopenharmony_ci    message->stubIndex = TEST_STUB_INDEX;
685a34a8711Sopenharmony_ci    dBinderService->dbinderCallback_ = std::make_shared<TestRpcSystemAbilityCallback>();
686a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService->dbinderCallback_ != nullptr);
687a34a8711Sopenharmony_ci    bool res = dBinderService->OnRemoteInvokerMessage(message);
688a34a8711Sopenharmony_ci    EXPECT_EQ(res, true);
689a34a8711Sopenharmony_ci}
690a34a8711Sopenharmony_ci
691a34a8711Sopenharmony_ci/**
692a34a8711Sopenharmony_ci * @tc.name: GetDatabusNameByProxyTest001
693a34a8711Sopenharmony_ci * @tc.desc: Verify the GetDatabusNameByProxy function
694a34a8711Sopenharmony_ci * @tc.type: FUNC
695a34a8711Sopenharmony_ci */
696a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, GetDatabusNameByProxyTest001, TestSize.Level1)
697a34a8711Sopenharmony_ci{
698a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
699a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
700a34a8711Sopenharmony_ci    IPCObjectProxy* proxy = nullptr;
701a34a8711Sopenharmony_ci    std::string res = dBinderService->GetDatabusNameByProxy(proxy);
702a34a8711Sopenharmony_ci    EXPECT_EQ(res, "");
703a34a8711Sopenharmony_ci    IPCObjectProxy object(16);
704a34a8711Sopenharmony_ci    res = dBinderService->GetDatabusNameByProxy(&object);
705a34a8711Sopenharmony_ci    EXPECT_EQ(res, "");
706a34a8711Sopenharmony_ci}
707a34a8711Sopenharmony_ci
708a34a8711Sopenharmony_ci/**
709a34a8711Sopenharmony_ci * @tc.name: InvokerRemoteDBinderTest001
710a34a8711Sopenharmony_ci * @tc.desc: Verify the InvokerRemoteDBinder function
711a34a8711Sopenharmony_ci * @tc.type: FUNC
712a34a8711Sopenharmony_ci */
713a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, InvokerRemoteDBinderTest001, TestSize.Level1)
714a34a8711Sopenharmony_ci{
715a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
716a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
717a34a8711Sopenharmony_ci    sptr<DBinderServiceStub> stub = nullptr;
718a34a8711Sopenharmony_ci    uint32_t seqNumber = 123456;
719a34a8711Sopenharmony_ci    uint32_t pid = 0;
720a34a8711Sopenharmony_ci    uint32_t uid = 0;
721a34a8711Sopenharmony_ci    int32_t ret = dBinderService->InvokerRemoteDBinder(stub, seqNumber, pid, uid);
722a34a8711Sopenharmony_ci    EXPECT_EQ(ret, DBinderErrorCode::STUB_INVALID);
723a34a8711Sopenharmony_ci    std::string serviceName("testServer");
724a34a8711Sopenharmony_ci    std::string deviceID("123456");
725a34a8711Sopenharmony_ci    binder_uintptr_t binderObject = 100;
726a34a8711Sopenharmony_ci    stub = new DBinderServiceStub(serviceName, deviceID, binderObject);
727a34a8711Sopenharmony_ci    EXPECT_TRUE(stub != nullptr);
728a34a8711Sopenharmony_ci    ret = dBinderService->InvokerRemoteDBinder(stub, seqNumber, pid, uid);
729a34a8711Sopenharmony_ci    EXPECT_EQ(ret, DBinderErrorCode::SEND_MESSAGE_FAILED);
730a34a8711Sopenharmony_ci}
731a34a8711Sopenharmony_ci
732a34a8711Sopenharmony_ci/**
733a34a8711Sopenharmony_ci * @tc.name: CreateDatabusNameTest001
734a34a8711Sopenharmony_ci * @tc.desc: Verify the CreateDatabusName function
735a34a8711Sopenharmony_ci * @tc.type: FUNC
736a34a8711Sopenharmony_ci */
737a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, CreateDatabusNameTest001, TestSize.Level1)
738a34a8711Sopenharmony_ci{
739a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
740a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
741a34a8711Sopenharmony_ci    int pid = 0;
742a34a8711Sopenharmony_ci    int uid = 0;
743a34a8711Sopenharmony_ci    std::string res = dBinderService->CreateDatabusName(pid, uid);
744a34a8711Sopenharmony_ci    EXPECT_EQ(res, "");
745a34a8711Sopenharmony_ci    pid = 10;
746a34a8711Sopenharmony_ci    uid = 10;
747a34a8711Sopenharmony_ci    res = dBinderService->CreateDatabusName(pid, uid);
748a34a8711Sopenharmony_ci    EXPECT_EQ(res, "");
749a34a8711Sopenharmony_ci}
750a34a8711Sopenharmony_ci
751a34a8711Sopenharmony_ci/**
752a34a8711Sopenharmony_ci * @tc.name: FindServicesByDeviceIDTest001
753a34a8711Sopenharmony_ci * @tc.desc: Verify the FindServicesByDeviceID function
754a34a8711Sopenharmony_ci * @tc.type: FUNC
755a34a8711Sopenharmony_ci */
756a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, FindServicesByDeviceIDTest001, TestSize.Level1)
757a34a8711Sopenharmony_ci{
758a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
759a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
760a34a8711Sopenharmony_ci    std::string serviceName("testServer");
761a34a8711Sopenharmony_ci    std::string deviceID("123456");
762a34a8711Sopenharmony_ci    binder_uintptr_t binderObject = 100;
763a34a8711Sopenharmony_ci    sptr<DBinderServiceStub> dBinderServiceStub = new DBinderServiceStub(serviceName, deviceID, binderObject);
764a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderServiceStub != nullptr);
765a34a8711Sopenharmony_ci    dBinderService->DBinderStubRegisted_.push_back(dBinderServiceStub);
766a34a8711Sopenharmony_ci    std::list<std::u16string> serviceNames;
767a34a8711Sopenharmony_ci    serviceNames.push_back(Str8ToStr16(serviceName));
768a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->FindServicesByDeviceID(deviceID), serviceNames);
769a34a8711Sopenharmony_ci}
770a34a8711Sopenharmony_ci
771a34a8711Sopenharmony_ci/**
772a34a8711Sopenharmony_ci * @tc.name: NoticeDeviceDieTest001
773a34a8711Sopenharmony_ci * @tc.desc: Verify the NoticeDeviceDie function
774a34a8711Sopenharmony_ci * @tc.type: FUNC
775a34a8711Sopenharmony_ci */
776a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, NoticeDeviceDieTest001, TestSize.Level1)
777a34a8711Sopenharmony_ci{
778a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
779a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
780a34a8711Sopenharmony_ci    std::string deviceID;
781a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->NoticeDeviceDie(deviceID), DBINDER_SERVICE_INVALID_DATA_ERR);
782a34a8711Sopenharmony_ci}
783a34a8711Sopenharmony_ci
784a34a8711Sopenharmony_ci/**
785a34a8711Sopenharmony_ci * @tc.name: NoticeDeviceDieTest002
786a34a8711Sopenharmony_ci * @tc.desc: Verify the NoticeDeviceDie function
787a34a8711Sopenharmony_ci * @tc.type: FUNC
788a34a8711Sopenharmony_ci */
789a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, NoticeDeviceDieTest002, TestSize.Level1)
790a34a8711Sopenharmony_ci{
791a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
792a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
793a34a8711Sopenharmony_ci    std::string deviceID("123456");
794a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->NoticeDeviceDie(deviceID), DBINDER_SERVICE_NOTICE_DIE_ERR);
795a34a8711Sopenharmony_ci}
796a34a8711Sopenharmony_ci
797a34a8711Sopenharmony_ci/**
798a34a8711Sopenharmony_ci * @tc.name: NoticeDeviceDieTest003
799a34a8711Sopenharmony_ci * @tc.desc: Verify the NoticeDeviceDie function
800a34a8711Sopenharmony_ci * @tc.type: FUNC
801a34a8711Sopenharmony_ci */
802a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, NoticeDeviceDieTest003, TestSize.Level1)
803a34a8711Sopenharmony_ci{
804a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
805a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
806a34a8711Sopenharmony_ci    std::string deviceID("123456");
807a34a8711Sopenharmony_ci    dBinderService->remoteListener_ = std::make_shared<DBinderRemoteListener>();
808a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService->remoteListener_ != nullptr);
809a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->NoticeDeviceDie(deviceID), DBINDER_SERVICE_NOTICE_DIE_ERR);
810a34a8711Sopenharmony_ci}
811a34a8711Sopenharmony_ci
812a34a8711Sopenharmony_ci/**
813a34a8711Sopenharmony_ci * @tc.name: NoticeServiceDieTest001
814a34a8711Sopenharmony_ci * @tc.desc: Verify the NoticeServiceDie function
815a34a8711Sopenharmony_ci * @tc.type: FUNC
816a34a8711Sopenharmony_ci */
817a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, NoticeServiceDieTest001, TestSize.Level1)
818a34a8711Sopenharmony_ci{
819a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
820a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
821a34a8711Sopenharmony_ci    dBinderService->StartRemoteListener();
822a34a8711Sopenharmony_ci    std::u16string serviceName;
823a34a8711Sopenharmony_ci    std::string deviceID("123456");
824a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->NoticeServiceDie(serviceName, deviceID), DBINDER_SERVICE_INVALID_DATA_ERR);
825a34a8711Sopenharmony_ci}
826a34a8711Sopenharmony_ci
827a34a8711Sopenharmony_ci/**
828a34a8711Sopenharmony_ci * @tc.name: NoticeServiceDieInnerTest001
829a34a8711Sopenharmony_ci * @tc.desc: Verify the NoticeServiceDieInner function
830a34a8711Sopenharmony_ci * @tc.type: FUNC
831a34a8711Sopenharmony_ci */
832a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, NoticeServiceDieInnerTest001, TestSize.Level1)
833a34a8711Sopenharmony_ci{
834a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
835a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
836a34a8711Sopenharmony_ci    dBinderService->StartRemoteListener();
837a34a8711Sopenharmony_ci    std::u16string serviceName;
838a34a8711Sopenharmony_ci    std::string deviceID("123456");
839a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->NoticeServiceDieInner(serviceName, deviceID), DBINDER_SERVICE_INVALID_DATA_ERR);
840a34a8711Sopenharmony_ci}
841a34a8711Sopenharmony_ci
842a34a8711Sopenharmony_ci/**
843a34a8711Sopenharmony_ci * @tc.name: NoticeServiceDieInnerTest002
844a34a8711Sopenharmony_ci * @tc.desc: Verify the NoticeServiceDieInner function
845a34a8711Sopenharmony_ci * @tc.type: FUNC
846a34a8711Sopenharmony_ci */
847a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, NoticeServiceDieInnerTest002, TestSize.Level1)
848a34a8711Sopenharmony_ci{
849a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
850a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
851a34a8711Sopenharmony_ci    dBinderService->StartRemoteListener();
852a34a8711Sopenharmony_ci    std::u16string serviceName(u"test");
853a34a8711Sopenharmony_ci    std::string deviceID("123456");
854a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->NoticeServiceDieInner(serviceName, deviceID), ERR_NONE);
855a34a8711Sopenharmony_ci}
856a34a8711Sopenharmony_ci
857a34a8711Sopenharmony_ci/**
858a34a8711Sopenharmony_ci * @tc.name: NoticeServiceDieInnerTest003
859a34a8711Sopenharmony_ci * @tc.desc: Verify the NoticeServiceDieInner function
860a34a8711Sopenharmony_ci * @tc.type: FUNC
861a34a8711Sopenharmony_ci */
862a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, NoticeServiceDieInnerTest003, TestSize.Level1)
863a34a8711Sopenharmony_ci{
864a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
865a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
866a34a8711Sopenharmony_ci    dBinderService->StartRemoteListener();
867a34a8711Sopenharmony_ci    std::u16string serviceName(u"testServer");
868a34a8711Sopenharmony_ci    std::string deviceID("123456");
869a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->NoticeServiceDieInner(serviceName, deviceID), ERR_NONE);
870a34a8711Sopenharmony_ci}
871a34a8711Sopenharmony_ci
872a34a8711Sopenharmony_ci/**
873a34a8711Sopenharmony_ci * @tc.name: ProcessCallbackProxyTest001
874a34a8711Sopenharmony_ci * @tc.desc: Verify the ProcessCallbackProxy function
875a34a8711Sopenharmony_ci * @tc.type: FUNC
876a34a8711Sopenharmony_ci */
877a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, ProcessCallbackProxyTest001, TestSize.Level1)
878a34a8711Sopenharmony_ci{
879a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
880a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
881a34a8711Sopenharmony_ci    sptr<IRemoteObject> object = new IPCObjectProxy(16);
882a34a8711Sopenharmony_ci    EXPECT_TRUE(object != nullptr);
883a34a8711Sopenharmony_ci    std::string serviceName("testServer");
884a34a8711Sopenharmony_ci    std::string deviceID("123456");
885a34a8711Sopenharmony_ci    binder_uintptr_t binderObject = 100;
886a34a8711Sopenharmony_ci    sptr<DBinderServiceStub> dBinderServiceStub = new DBinderServiceStub(serviceName, deviceID, binderObject);
887a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderServiceStub != nullptr);
888a34a8711Sopenharmony_ci    bool res = dBinderService->AttachCallbackProxy(object, dBinderServiceStub.GetRefPtr());
889a34a8711Sopenharmony_ci    dBinderService->ProcessCallbackProxy(dBinderServiceStub);
890a34a8711Sopenharmony_ci    EXPECT_TRUE(res);
891a34a8711Sopenharmony_ci}
892a34a8711Sopenharmony_ci
893a34a8711Sopenharmony_ci/**
894a34a8711Sopenharmony_ci * @tc.name: NoticeCallbackProxyTest001
895a34a8711Sopenharmony_ci * @tc.desc: Verify the NoticeCallbackProxy function
896a34a8711Sopenharmony_ci * @tc.type: FUNC
897a34a8711Sopenharmony_ci */
898a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, NoticeCallbackProxyTest001, TestSize.Level1)
899a34a8711Sopenharmony_ci{
900a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
901a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
902a34a8711Sopenharmony_ci    sptr<IRemoteObject> object = new IPCObjectProxy(16);
903a34a8711Sopenharmony_ci    EXPECT_TRUE(object != nullptr);
904a34a8711Sopenharmony_ci    std::string serviceName("testServer");
905a34a8711Sopenharmony_ci    std::string deviceID("123456");
906a34a8711Sopenharmony_ci    binder_uintptr_t binderObject = 100;
907a34a8711Sopenharmony_ci    sptr<DBinderServiceStub> dBinderServiceStub = new DBinderServiceStub(serviceName, deviceID, binderObject);
908a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderServiceStub != nullptr);
909a34a8711Sopenharmony_ci    dBinderService->AttachCallbackProxy(object, dBinderServiceStub.GetRefPtr());
910a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->NoticeCallbackProxy(dBinderServiceStub), false);
911a34a8711Sopenharmony_ci}
912a34a8711Sopenharmony_ci
913a34a8711Sopenharmony_ci/**
914a34a8711Sopenharmony_ci * @tc.name: DetachCallbackProxyTest001
915a34a8711Sopenharmony_ci * @tc.desc: Verify the DetachCallbackProxy function
916a34a8711Sopenharmony_ci * @tc.type: FUNC
917a34a8711Sopenharmony_ci */
918a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, DetachCallbackProxyTest001, TestSize.Level1)
919a34a8711Sopenharmony_ci{
920a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
921a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
922a34a8711Sopenharmony_ci    sptr<IRemoteObject> object = new IPCObjectProxy(16);
923a34a8711Sopenharmony_ci    EXPECT_TRUE(object != nullptr);
924a34a8711Sopenharmony_ci    std::string serviceName("test1");
925a34a8711Sopenharmony_ci    std::string deviceID("12345");
926a34a8711Sopenharmony_ci    binder_uintptr_t binderObject = 100;
927a34a8711Sopenharmony_ci    sptr<DBinderServiceStub> dBinderServiceStub = new DBinderServiceStub(serviceName, deviceID, binderObject);
928a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderServiceStub != nullptr);
929a34a8711Sopenharmony_ci    dBinderService->AttachCallbackProxy(object, dBinderServiceStub.GetRefPtr());
930a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->DetachCallbackProxy(object), true);
931a34a8711Sopenharmony_ci}
932a34a8711Sopenharmony_ci
933a34a8711Sopenharmony_ci/**
934a34a8711Sopenharmony_ci * @tc.name: DetachCallbackProxyTest002
935a34a8711Sopenharmony_ci * @tc.desc: Verify the DetachCallbackProxy function
936a34a8711Sopenharmony_ci * @tc.type: FUNC
937a34a8711Sopenharmony_ci */
938a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, DetachCallbackProxyTest002, TestSize.Level1)
939a34a8711Sopenharmony_ci{
940a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
941a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
942a34a8711Sopenharmony_ci    sptr<IRemoteObject> object = new IPCObjectProxy(100);
943a34a8711Sopenharmony_ci    EXPECT_TRUE(object != nullptr);
944a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->DetachCallbackProxy(object), false);
945a34a8711Sopenharmony_ci}
946a34a8711Sopenharmony_ci
947a34a8711Sopenharmony_ci/**
948a34a8711Sopenharmony_ci * @tc.name: QueryDeathRecipientTest001
949a34a8711Sopenharmony_ci * @tc.desc: Verify the QueryDeathRecipient function
950a34a8711Sopenharmony_ci * @tc.type: FUNC
951a34a8711Sopenharmony_ci */
952a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, QueryDeathRecipientTest001, TestSize.Level1)
953a34a8711Sopenharmony_ci{
954a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
955a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
956a34a8711Sopenharmony_ci    sptr<IRemoteObject> object = new IPCObjectProxy(20);
957a34a8711Sopenharmony_ci    EXPECT_TRUE(object != nullptr);
958a34a8711Sopenharmony_ci    sptr<IRemoteObject::DeathRecipient> deathRecipient = new TestDeathRecipient();
959a34a8711Sopenharmony_ci    EXPECT_TRUE(deathRecipient != nullptr);
960a34a8711Sopenharmony_ci    dBinderService->AttachDeathRecipient(object, deathRecipient);
961a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->QueryDeathRecipient(object), deathRecipient);
962a34a8711Sopenharmony_ci}
963a34a8711Sopenharmony_ci
964a34a8711Sopenharmony_ci/**
965a34a8711Sopenharmony_ci * @tc.name: QueryDeathRecipientTest002
966a34a8711Sopenharmony_ci * @tc.desc: Verify the QueryDeathRecipient function
967a34a8711Sopenharmony_ci * @tc.type: FUNC
968a34a8711Sopenharmony_ci */
969a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, QueryDeathRecipientTest002, TestSize.Level1)
970a34a8711Sopenharmony_ci{
971a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
972a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
973a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->QueryDeathRecipient(nullptr), nullptr);
974a34a8711Sopenharmony_ci}
975a34a8711Sopenharmony_ci
976a34a8711Sopenharmony_ci/**
977a34a8711Sopenharmony_ci * @tc.name: AttachProxyObjectTest001
978a34a8711Sopenharmony_ci * @tc.desc: Verify the AttachProxyObject function
979a34a8711Sopenharmony_ci * @tc.type: FUNC
980a34a8711Sopenharmony_ci */
981a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, AttachProxyObjectTest001, TestSize.Level1)
982a34a8711Sopenharmony_ci{
983a34a8711Sopenharmony_ci    std::string name("Test");
984a34a8711Sopenharmony_ci    binder_uintptr_t binderObject = 10;
985a34a8711Sopenharmony_ci    binder_uintptr_t binderObject1 = 11;
986a34a8711Sopenharmony_ci    sptr<IRemoteObject> object = new IPCObjectProxy(16);
987a34a8711Sopenharmony_ci    EXPECT_TRUE(object != nullptr);
988a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
989a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
990a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->AttachProxyObject(object, binderObject), true);
991a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->QueryProxyObject(binderObject), object);
992a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->QueryProxyObject(binderObject1), nullptr);
993a34a8711Sopenharmony_ci}
994a34a8711Sopenharmony_ci
995a34a8711Sopenharmony_ci/**
996a34a8711Sopenharmony_ci * @tc.name: AttachProxyObjectTest002
997a34a8711Sopenharmony_ci * @tc.desc: Verify the AttachProxyObject function
998a34a8711Sopenharmony_ci * @tc.type: FUNC
999a34a8711Sopenharmony_ci */
1000a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, AttachProxyObjectTest002, TestSize.Level1)
1001a34a8711Sopenharmony_ci{
1002a34a8711Sopenharmony_ci    uint32_t seqNumber = 10;
1003a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1004a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
1005a34a8711Sopenharmony_ci    std::shared_ptr<OHOS::ThreadLockInfo> threadLockInfo = std::make_shared<OHOS::ThreadLockInfo>();
1006a34a8711Sopenharmony_ci    EXPECT_TRUE(threadLockInfo != nullptr);
1007a34a8711Sopenharmony_ci    dBinderService->AttachThreadLockInfo(seqNumber, "networkId", threadLockInfo);
1008a34a8711Sopenharmony_ci    dBinderService->WakeupThreadByStub(seqNumber);
1009a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService->QueryThreadLockInfo(seqNumber) != nullptr);
1010a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->QueryThreadLockInfo(seqNumber), threadLockInfo);
1011a34a8711Sopenharmony_ci    dBinderService->DetachThreadLockInfo(seqNumber);
1012a34a8711Sopenharmony_ci    dBinderService->WakeupThreadByStub(seqNumber);
1013a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService->QueryThreadLockInfo(seqNumber) == nullptr);
1014a34a8711Sopenharmony_ci}
1015a34a8711Sopenharmony_ci
1016a34a8711Sopenharmony_ci/**
1017a34a8711Sopenharmony_ci * @tc.name: MakeSessionByReplyMessageTest001
1018a34a8711Sopenharmony_ci * @tc.desc: Verify the MakeSessionByReplyMessage function
1019a34a8711Sopenharmony_ci * @tc.type: FUNC
1020a34a8711Sopenharmony_ci */
1021a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, MakeSessionByReplyMessageTest001, TestSize.Level1)
1022a34a8711Sopenharmony_ci{
1023a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1024a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
1025a34a8711Sopenharmony_ci    std::shared_ptr<struct DHandleEntryTxRx> replyMessage = std::make_shared<DHandleEntryTxRx>();
1026a34a8711Sopenharmony_ci    EXPECT_TRUE(replyMessage != nullptr);
1027a34a8711Sopenharmony_ci    (void)memset_s(replyMessage.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
1028a34a8711Sopenharmony_ci    dBinderService->MakeSessionByReplyMessage(replyMessage);
1029a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->HasDBinderStub(replyMessage->binderObject), false);
1030a34a8711Sopenharmony_ci
1031a34a8711Sopenharmony_ci    std::string serviceName("testServer");
1032a34a8711Sopenharmony_ci    std::string deviceID;
1033a34a8711Sopenharmony_ci    binder_uintptr_t binderObject = 161561;
1034a34a8711Sopenharmony_ci    sptr<DBinderServiceStub> stub = new DBinderServiceStub(serviceName, deviceID, binderObject);
1035a34a8711Sopenharmony_ci    EXPECT_TRUE(stub != nullptr);
1036a34a8711Sopenharmony_ci    replyMessage->stub = reinterpret_cast<binder_uintptr_t>(stub.GetRefPtr());
1037a34a8711Sopenharmony_ci    dBinderService->MakeSessionByReplyMessage(replyMessage);
1038a34a8711Sopenharmony_ci}
1039a34a8711Sopenharmony_ci
1040a34a8711Sopenharmony_ci/**
1041a34a8711Sopenharmony_ci * @tc.name: RegisterRemoteProxyTest001
1042a34a8711Sopenharmony_ci * @tc.desc: Verify the RegisterRemoteProxy function
1043a34a8711Sopenharmony_ci * @tc.type: FUNC
1044a34a8711Sopenharmony_ci */
1045a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, RegisterRemoteProxyTest001, TestSize.Level1)
1046a34a8711Sopenharmony_ci{
1047a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1048a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
1049a34a8711Sopenharmony_ci    std::u16string serviceName;
1050a34a8711Sopenharmony_ci    int32_t systemAbilityId = 1;
1051a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, systemAbilityId), false);
1052a34a8711Sopenharmony_ci    serviceName = u"testServer";
1053a34a8711Sopenharmony_ci    systemAbilityId = 0;
1054a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, systemAbilityId), false);
1055a34a8711Sopenharmony_ci    systemAbilityId = 1;
1056a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, systemAbilityId), true);
1057a34a8711Sopenharmony_ci}
1058a34a8711Sopenharmony_ci
1059a34a8711Sopenharmony_ci/**
1060a34a8711Sopenharmony_ci * @tc.name: RegisterRemoteProxyTest002
1061a34a8711Sopenharmony_ci * @tc.desc: Verify the RegisterRemoteProxy function
1062a34a8711Sopenharmony_ci * @tc.type: FUNC
1063a34a8711Sopenharmony_ci */
1064a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, RegisterRemoteProxyTest002, TestSize.Level1)
1065a34a8711Sopenharmony_ci{
1066a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1067a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
1068a34a8711Sopenharmony_ci    std::u16string serviceName;
1069a34a8711Sopenharmony_ci    sptr<IRemoteObject> binderObject = nullptr;
1070a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, binderObject), false);
1071a34a8711Sopenharmony_ci    serviceName = u"testServer";
1072a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, binderObject), false);
1073a34a8711Sopenharmony_ci    sptr<IRemoteObject> object = new IPCObjectProxy(16);
1074a34a8711Sopenharmony_ci    EXPECT_TRUE(object != nullptr);
1075a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->RegisterRemoteProxy(serviceName, object), true);
1076a34a8711Sopenharmony_ci}
1077a34a8711Sopenharmony_ci
1078a34a8711Sopenharmony_ci/**
1079a34a8711Sopenharmony_ci * @tc.name: GetRegisterServiceTest001
1080a34a8711Sopenharmony_ci * @tc.desc: Verify the GetRegisterService function
1081a34a8711Sopenharmony_ci * @tc.type: FUNC
1082a34a8711Sopenharmony_ci */
1083a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, GetRegisterServiceTest001, TestSize.Level1)
1084a34a8711Sopenharmony_ci{
1085a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1086a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
1087a34a8711Sopenharmony_ci    binder_uintptr_t binderObject = 1;
1088a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->GetRegisterService(binderObject), std::u16string());
1089a34a8711Sopenharmony_ci    std::u16string serviceName(u"testServer");
1090a34a8711Sopenharmony_ci    dBinderService->RegisterRemoteProxyInner(serviceName, binderObject);
1091a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->GetRegisterService(binderObject), serviceName);
1092a34a8711Sopenharmony_ci}
1093a34a8711Sopenharmony_ci
1094a34a8711Sopenharmony_ci/**
1095a34a8711Sopenharmony_ci * @tc.name: OnRemoteMessageTaskTest001
1096a34a8711Sopenharmony_ci * @tc.desc: Verify the OnRemoteMessageTask function
1097a34a8711Sopenharmony_ci * @tc.type: FUNC
1098a34a8711Sopenharmony_ci */
1099a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, OnRemoteMessageTaskTest001, TestSize.Level1)
1100a34a8711Sopenharmony_ci{
1101a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1102a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
1103a34a8711Sopenharmony_ci    std::shared_ptr<struct DHandleEntryTxRx> handleEntryTxRx = nullptr;
1104a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->OnRemoteMessageTask(handleEntryTxRx), false);
1105a34a8711Sopenharmony_ci    std::shared_ptr<DHandleEntryTxRx> message = std::make_shared<DHandleEntryTxRx>();
1106a34a8711Sopenharmony_ci    EXPECT_TRUE(message != nullptr);
1107a34a8711Sopenharmony_ci    message->head.len = 10;
1108a34a8711Sopenharmony_ci    message->head.version = 1;
1109a34a8711Sopenharmony_ci    message->transType = 0;
1110a34a8711Sopenharmony_ci    message->fromPort = 1;
1111a34a8711Sopenharmony_ci    message->toPort = 2;
1112a34a8711Sopenharmony_ci    message->stubIndex = 1;
1113a34a8711Sopenharmony_ci    message->seqNumber = 1;
1114a34a8711Sopenharmony_ci    message->binderObject = 10;
1115a34a8711Sopenharmony_ci    message->deviceIdInfo.tokenId = 1;
1116a34a8711Sopenharmony_ci    message->deviceIdInfo.fromDeviceId[0] = 't';
1117a34a8711Sopenharmony_ci    message->deviceIdInfo.toDeviceId[0] = 't';
1118a34a8711Sopenharmony_ci    message->stub = 10;
1119a34a8711Sopenharmony_ci    message->serviceNameLength = 10;
1120a34a8711Sopenharmony_ci    message->serviceName[0] = 't';
1121a34a8711Sopenharmony_ci    message->pid = 100;
1122a34a8711Sopenharmony_ci    message->uid = 100;
1123a34a8711Sopenharmony_ci    dBinderService->dbinderCallback_ = std::make_shared<TestRpcSystemAbilityCallback>();
1124a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService->dbinderCallback_ != nullptr);
1125a34a8711Sopenharmony_ci    message->dBinderCode = DBinderCode::MESSAGE_AS_INVOKER;
1126a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->OnRemoteMessageTask(message), true);
1127a34a8711Sopenharmony_ci    message->dBinderCode = DBinderCode::MESSAGE_AS_REPLY;
1128a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->OnRemoteMessageTask(message), true);
1129a34a8711Sopenharmony_ci    message->dBinderCode = DBinderCode::MESSAGE_AS_OBITUARY;
1130a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->OnRemoteMessageTask(message), false);
1131a34a8711Sopenharmony_ci    message->dBinderCode = DBinderCode::MESSAGE_AS_REMOTE_ERROR;
1132a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->OnRemoteMessageTask(message), true);
1133a34a8711Sopenharmony_ci}
1134a34a8711Sopenharmony_ci
1135a34a8711Sopenharmony_ci/**
1136a34a8711Sopenharmony_ci * @tc.name: OnRemoteInvokerDataBusMessageTest001
1137a34a8711Sopenharmony_ci * @tc.desc: Verify the OnRemoteInvokerDataBusMessage function
1138a34a8711Sopenharmony_ci * @tc.type: FUNC
1139a34a8711Sopenharmony_ci */
1140a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, OnRemoteInvokerDataBusMessageTest001, TestSize.Level1)
1141a34a8711Sopenharmony_ci{
1142a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1143a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
1144a34a8711Sopenharmony_ci    IPCObjectProxy* proxy = nullptr;
1145a34a8711Sopenharmony_ci    std::string remoteDeviceId;
1146a34a8711Sopenharmony_ci    int pid = 1;
1147a34a8711Sopenharmony_ci    int uid = 1;
1148a34a8711Sopenharmony_ci    uint32_t tokenId = 1;
1149a34a8711Sopenharmony_ci    std::shared_ptr<struct DHandleEntryTxRx> replyMessage = std::make_shared<DHandleEntryTxRx>();
1150a34a8711Sopenharmony_ci    EXPECT_TRUE(replyMessage != nullptr);
1151a34a8711Sopenharmony_ci    (void)memset_s(replyMessage.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
1152a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->OnRemoteInvokerDataBusMessage(
1153a34a8711Sopenharmony_ci        proxy, replyMessage, remoteDeviceId, pid, uid, tokenId), DBinderErrorCode::DEVICEID_INVALID);
1154a34a8711Sopenharmony_ci}
1155a34a8711Sopenharmony_ci
1156a34a8711Sopenharmony_ci/**
1157a34a8711Sopenharmony_ci * @tc.name: OnRemoteInvokerDataBusMessageTest002
1158a34a8711Sopenharmony_ci * @tc.desc: Verify the OnRemoteInvokerDataBusMessage function
1159a34a8711Sopenharmony_ci * @tc.type: FUNC
1160a34a8711Sopenharmony_ci */
1161a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, OnRemoteInvokerDataBusMessageTest002, TestSize.Level1)
1162a34a8711Sopenharmony_ci{
1163a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1164a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
1165a34a8711Sopenharmony_ci    std::string remoteDeviceId("test");
1166a34a8711Sopenharmony_ci    int pid = 1;
1167a34a8711Sopenharmony_ci    int uid = 1;
1168a34a8711Sopenharmony_ci    uint32_t tokenId = 1;
1169a34a8711Sopenharmony_ci    IPCObjectProxy objectProxy(0);
1170a34a8711Sopenharmony_ci    std::shared_ptr<struct DHandleEntryTxRx> replyMessage = std::make_shared<DHandleEntryTxRx>();
1171a34a8711Sopenharmony_ci    EXPECT_TRUE(replyMessage != nullptr);
1172a34a8711Sopenharmony_ci    (void)memset_s(replyMessage.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
1173a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->OnRemoteInvokerDataBusMessage(
1174a34a8711Sopenharmony_ci        &objectProxy, replyMessage, remoteDeviceId, pid, uid, tokenId), DBinderErrorCode::SESSION_NAME_NOT_FOUND);
1175a34a8711Sopenharmony_ci}
1176a34a8711Sopenharmony_ci
1177a34a8711Sopenharmony_ci/*
1178a34a8711Sopenharmony_ci * @tc.name: ProcessOnSessionClosedTest002
1179a34a8711Sopenharmony_ci * @tc.desc: Verify the ProcessOnSessionClosed function
1180a34a8711Sopenharmony_ci * @tc.type: FUNC
1181a34a8711Sopenharmony_ci */
1182a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, ProcessOnSessionClosedTest002, TestSize.Level1)
1183a34a8711Sopenharmony_ci{
1184a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1185a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
1186a34a8711Sopenharmony_ci    std::shared_ptr<OHOS::ThreadLockInfo> threadLockInfo = std::make_shared<OHOS::ThreadLockInfo>();
1187a34a8711Sopenharmony_ci    EXPECT_TRUE(threadLockInfo != nullptr);
1188a34a8711Sopenharmony_ci    uint32_t seqNumber = 10;
1189a34a8711Sopenharmony_ci    std::string networkId = "networkId";
1190a34a8711Sopenharmony_ci    dBinderService->AttachThreadLockInfo(seqNumber, networkId, threadLockInfo);
1191a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->ProcessOnSessionClosed(networkId), true);
1192a34a8711Sopenharmony_ci}
1193a34a8711Sopenharmony_ci
1194a34a8711Sopenharmony_ci/**
1195a34a8711Sopenharmony_ci * @tc.name: FindDBinderStub001
1196a34a8711Sopenharmony_ci * @tc.desc: Verify the FindDBinderStub function
1197a34a8711Sopenharmony_ci * @tc.type: FUNC
1198a34a8711Sopenharmony_ci */
1199a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, FindDBinderStub001, TestSize.Level1)
1200a34a8711Sopenharmony_ci{
1201a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1202a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
1203a34a8711Sopenharmony_ci    std::u16string service(u"test");
1204a34a8711Sopenharmony_ci    std::string device = "aaa";
1205a34a8711Sopenharmony_ci    binder_uintptr_t binderObject = 100;
1206a34a8711Sopenharmony_ci    sptr<DBinderServiceStub> testDdBinderStub1 = dBinderService->FindOrNewDBinderStub(service, device, binderObject);
1207a34a8711Sopenharmony_ci    EXPECT_TRUE(testDdBinderStub1 != nullptr);
1208a34a8711Sopenharmony_ci    sptr<DBinderServiceStub> testDdBinderStub2 = dBinderService->FindOrNewDBinderStub(service, device, binderObject);
1209a34a8711Sopenharmony_ci    EXPECT_TRUE(testDdBinderStub2 != nullptr);
1210a34a8711Sopenharmony_ci    EXPECT_EQ(testDdBinderStub1.GetRefPtr(), testDdBinderStub2.GetRefPtr());
1211a34a8711Sopenharmony_ci
1212a34a8711Sopenharmony_ci    sptr<DBinderServiceStub> testDdBinderStub3 = dBinderService->FindDBinderStub(service, device);
1213a34a8711Sopenharmony_ci    EXPECT_TRUE(testDdBinderStub3 != nullptr);
1214a34a8711Sopenharmony_ci    EXPECT_EQ(testDdBinderStub1.GetRefPtr(), testDdBinderStub3.GetRefPtr());
1215a34a8711Sopenharmony_ci
1216a34a8711Sopenharmony_ci    std::u16string service1(u"test1");
1217a34a8711Sopenharmony_ci    std::string device1 = "bbb";
1218a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->FindDBinderStub(service1, device1), nullptr);
1219a34a8711Sopenharmony_ci
1220a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->DeleteDBinderStub(service1, device1), false);
1221a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->DeleteDBinderStub(service, device), true);
1222a34a8711Sopenharmony_ci}
1223a34a8711Sopenharmony_ci
1224a34a8711Sopenharmony_ci/**
1225a34a8711Sopenharmony_ci * @tc.name: ReStartRemoteListenerTest001
1226a34a8711Sopenharmony_ci * @tc.desc: Verify the ReStartRemoteListener function
1227a34a8711Sopenharmony_ci * @tc.type: FUNC
1228a34a8711Sopenharmony_ci */
1229a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, ReStartRemoteListenerTest001, TestSize.Level1)
1230a34a8711Sopenharmony_ci{
1231a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1232a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
1233a34a8711Sopenharmony_ci    dBinderService->remoteListener_ = nullptr;
1234a34a8711Sopenharmony_ci    bool res = dBinderService->ReStartRemoteListener();
1235a34a8711Sopenharmony_ci    EXPECT_EQ(res, false);
1236a34a8711Sopenharmony_ci}
1237a34a8711Sopenharmony_ci
1238a34a8711Sopenharmony_ci/**
1239a34a8711Sopenharmony_ci * @tc.name: ReStartRemoteListenerTest002
1240a34a8711Sopenharmony_ci * @tc.desc: Verify the ReStartRemoteListener function
1241a34a8711Sopenharmony_ci * @tc.type: FUNC
1242a34a8711Sopenharmony_ci */
1243a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, ReStartRemoteListenerTest002, TestSize.Level1)
1244a34a8711Sopenharmony_ci{
1245a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1246a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
1247a34a8711Sopenharmony_ci    dBinderService->remoteListener_ = std::make_shared<DBinderRemoteListener>();
1248a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService->remoteListener_ != nullptr);
1249a34a8711Sopenharmony_ci    bool res = dBinderService->ReStartRemoteListener();
1250a34a8711Sopenharmony_ci    EXPECT_EQ(res, false);
1251a34a8711Sopenharmony_ci}
1252a34a8711Sopenharmony_ci
1253a34a8711Sopenharmony_ci/**
1254a34a8711Sopenharmony_ci * @tc.name: IsSameStubObjectTest002
1255a34a8711Sopenharmony_ci * @tc.desc: Verify the IsSameStubObject function
1256a34a8711Sopenharmony_ci * @tc.type: FUNC
1257a34a8711Sopenharmony_ci */
1258a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, IsSameStubObjectTest002, TestSize.Level1)
1259a34a8711Sopenharmony_ci{
1260a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1261a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
1262a34a8711Sopenharmony_ci    std::string serviceName = "test";
1263a34a8711Sopenharmony_ci    std::string deviceID = "001";
1264a34a8711Sopenharmony_ci    binder_uintptr_t binderObject = 1;
1265a34a8711Sopenharmony_ci    sptr<DBinderServiceStub> stub = new DBinderServiceStub(serviceName, deviceID, binderObject);
1266a34a8711Sopenharmony_ci    EXPECT_TRUE(stub != nullptr);
1267a34a8711Sopenharmony_ci    std::u16string service(u"test");
1268a34a8711Sopenharmony_ci    bool res = dBinderService->IsSameStubObject(stub, service, deviceID);
1269a34a8711Sopenharmony_ci    EXPECT_EQ(res, true);
1270a34a8711Sopenharmony_ci}
1271a34a8711Sopenharmony_ci
1272a34a8711Sopenharmony_ci/**
1273a34a8711Sopenharmony_ci * @tc.name: SendEntryToRemoteTest002
1274a34a8711Sopenharmony_ci * @tc.desc: Verify the SendEntryToRemote function
1275a34a8711Sopenharmony_ci * @tc.type: FUNC
1276a34a8711Sopenharmony_ci */
1277a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, SendEntryToRemoteTest002, TestSize.Level1)
1278a34a8711Sopenharmony_ci{
1279a34a8711Sopenharmony_ci    std::string serviceName("testServer");
1280a34a8711Sopenharmony_ci    std::string deviceID;
1281a34a8711Sopenharmony_ci    binder_uintptr_t binderObject = 161561;
1282a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1283a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
1284a34a8711Sopenharmony_ci    sptr<DBinderServiceStub> stub = new DBinderServiceStub(serviceName, deviceID, binderObject);
1285a34a8711Sopenharmony_ci    EXPECT_TRUE(stub != nullptr);
1286a34a8711Sopenharmony_ci    uint32_t seqNumber = 0;
1287a34a8711Sopenharmony_ci    uint32_t pid = 0;
1288a34a8711Sopenharmony_ci    uint32_t uid = 0;
1289a34a8711Sopenharmony_ci    bool res = dBinderService->SendEntryToRemote(stub, seqNumber, pid, uid);
1290a34a8711Sopenharmony_ci    EXPECT_EQ(res, false);
1291a34a8711Sopenharmony_ci}
1292a34a8711Sopenharmony_ci
1293a34a8711Sopenharmony_ci/**
1294a34a8711Sopenharmony_ci * @tc.name: PopLoadSaItemTest001
1295a34a8711Sopenharmony_ci * @tc.desc: Verify the PopLoadSaItem function
1296a34a8711Sopenharmony_ci * @tc.type: FUNC
1297a34a8711Sopenharmony_ci */
1298a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, PopLoadSaItemTest001, TestSize.Level1)
1299a34a8711Sopenharmony_ci{
1300a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1301a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
1302a34a8711Sopenharmony_ci    std::string srcNetworkId;
1303a34a8711Sopenharmony_ci    int32_t systemAbilityId = 1;
1304a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->PopLoadSaItem(srcNetworkId, systemAbilityId), nullptr);
1305a34a8711Sopenharmony_ci
1306a34a8711Sopenharmony_ci    srcNetworkId = "t";
1307a34a8711Sopenharmony_ci    std::shared_ptr<struct DHandleEntryTxRx> message = std::make_shared<DHandleEntryTxRx>();
1308a34a8711Sopenharmony_ci    EXPECT_TRUE(message != nullptr);
1309a34a8711Sopenharmony_ci    (void)memset_s(message.get(), sizeof(DHandleEntryTxRx), 0, sizeof(DHandleEntryTxRx));
1310a34a8711Sopenharmony_ci    message->stubIndex = systemAbilityId;
1311a34a8711Sopenharmony_ci    message->deviceIdInfo.fromDeviceId[0] = 't';
1312a34a8711Sopenharmony_ci    dBinderService->dbinderCallback_ = std::make_shared<TestRpcSystemAbilityCallback>();
1313a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService->dbinderCallback_ != nullptr);
1314a34a8711Sopenharmony_ci    dBinderService->OnRemoteInvokerMessage(message);
1315a34a8711Sopenharmony_ci    std::shared_ptr<DHandleEntryTxRx> dHandleEntryTxRx = dBinderService->PopLoadSaItem(srcNetworkId, systemAbilityId);
1316a34a8711Sopenharmony_ci    EXPECT_TRUE(dHandleEntryTxRx != nullptr);
1317a34a8711Sopenharmony_ci    sptr<IRemoteObject> remoteObject = nullptr;
1318a34a8711Sopenharmony_ci    dBinderService->LoadSystemAbilityComplete("test", 2, remoteObject);
1319a34a8711Sopenharmony_ci    dBinderService->LoadSystemAbilityComplete(srcNetworkId, systemAbilityId, remoteObject);
1320a34a8711Sopenharmony_ci    sptr<IRemoteObject> remoteObject1 = new IPCObjectProxy(1);
1321a34a8711Sopenharmony_ci    EXPECT_TRUE(remoteObject1 != nullptr);
1322a34a8711Sopenharmony_ci    dBinderService->LoadSystemAbilityComplete(srcNetworkId, systemAbilityId, remoteObject1);
1323a34a8711Sopenharmony_ci}
1324a34a8711Sopenharmony_ci
1325a34a8711Sopenharmony_ci/**
1326a34a8711Sopenharmony_ci * @tc.name: SendReplyMessageToRemote001
1327a34a8711Sopenharmony_ci * @tc.desc: Verify the SendReplyMessageToRemote function
1328a34a8711Sopenharmony_ci * @tc.type: FUNC
1329a34a8711Sopenharmony_ci */
1330a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, SendReplyMessageToRemote001, TestSize.Level1)
1331a34a8711Sopenharmony_ci{
1332a34a8711Sopenharmony_ci    uint32_t dBinderCode = 4;
1333a34a8711Sopenharmony_ci    uint32_t reason = 0;
1334a34a8711Sopenharmony_ci    std::shared_ptr<DHandleEntryTxRx> replyMessage = std::make_shared<DHandleEntryTxRx>();
1335a34a8711Sopenharmony_ci    EXPECT_TRUE(replyMessage != nullptr);
1336a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1337a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
1338a34a8711Sopenharmony_ci    dBinderService->remoteListener_ = std::make_shared<DBinderRemoteListener>();
1339a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService->remoteListener_ != nullptr);
1340a34a8711Sopenharmony_ci    dBinderService->SendReplyMessageToRemote(dBinderCode, reason, replyMessage);
1341a34a8711Sopenharmony_ci    dBinderCode = 1;
1342a34a8711Sopenharmony_ci    dBinderService->SendReplyMessageToRemote(dBinderCode, reason, replyMessage);
1343a34a8711Sopenharmony_ci    DBinderService *temp = new DBinderService();
1344a34a8711Sopenharmony_ci    EXPECT_TRUE(temp != nullptr);
1345a34a8711Sopenharmony_ci    DBinderService::instance_ = temp;
1346a34a8711Sopenharmony_ci    dBinderService = DBinderService::GetInstance();
1347a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
1348a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService, DBinderService::instance_);
1349a34a8711Sopenharmony_ci}
1350a34a8711Sopenharmony_ci
1351a34a8711Sopenharmony_ci/**
1352a34a8711Sopenharmony_ci * @tc.name: AddAsynMessageTask001
1353a34a8711Sopenharmony_ci * @tc.desc: Verify the AddAsynMessageTask function
1354a34a8711Sopenharmony_ci * @tc.type: FUNC
1355a34a8711Sopenharmony_ci */
1356a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, AddAsynMessageTask001, TestSize.Level1)
1357a34a8711Sopenharmony_ci{
1358a34a8711Sopenharmony_ci    std::shared_ptr<struct DHandleEntryTxRx> message = std::make_shared<struct DHandleEntryTxRx>();
1359a34a8711Sopenharmony_ci    EXPECT_NE(message.get(), nullptr);
1360a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1361a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
1362a34a8711Sopenharmony_ci    dBinderService->AddAsynMessageTask(message);
1363a34a8711Sopenharmony_ci}
1364a34a8711Sopenharmony_ci
1365a34a8711Sopenharmony_ci/**
1366a34a8711Sopenharmony_ci * @tc.name: IsSameSession002
1367a34a8711Sopenharmony_ci * @tc.desc: Verify the IsSameSession function
1368a34a8711Sopenharmony_ci * @tc.type: FUNC
1369a34a8711Sopenharmony_ci */
1370a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, IsSameSession002, TestSize.Level1)
1371a34a8711Sopenharmony_ci{
1372a34a8711Sopenharmony_ci    std::shared_ptr<struct SessionInfo> oldSession= std::make_shared<struct SessionInfo>();
1373a34a8711Sopenharmony_ci    EXPECT_NE(oldSession.get(), nullptr);
1374a34a8711Sopenharmony_ci    std::shared_ptr<struct SessionInfo> newSession= std::make_shared<struct SessionInfo>();
1375a34a8711Sopenharmony_ci    EXPECT_NE(newSession.get(), nullptr);
1376a34a8711Sopenharmony_ci    oldSession->stubIndex = 1;
1377a34a8711Sopenharmony_ci    oldSession->toPort = 2;
1378a34a8711Sopenharmony_ci    oldSession->fromPort = 3;
1379a34a8711Sopenharmony_ci    oldSession->type = 4;
1380a34a8711Sopenharmony_ci    oldSession->serviceName[0] = 't';
1381a34a8711Sopenharmony_ci    newSession->stubIndex = 2;
1382a34a8711Sopenharmony_ci    newSession->toPort = 2;
1383a34a8711Sopenharmony_ci    newSession->fromPort = 3;
1384a34a8711Sopenharmony_ci    newSession->type = 4;
1385a34a8711Sopenharmony_ci    newSession->serviceName[0] = 't';
1386a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1387a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
1388a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->IsSameSession(oldSession, newSession), false);
1389a34a8711Sopenharmony_ci    newSession->stubIndex = 1;
1390a34a8711Sopenharmony_ci    newSession->toPort = 12;
1391a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->IsSameSession(oldSession, newSession), false);
1392a34a8711Sopenharmony_ci    newSession->toPort = 2;
1393a34a8711Sopenharmony_ci    newSession->fromPort = 13;
1394a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->IsSameSession(oldSession, newSession), false);
1395a34a8711Sopenharmony_ci    newSession->fromPort = 3;
1396a34a8711Sopenharmony_ci    newSession->type = 14;
1397a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->IsSameSession(oldSession, newSession), false);
1398a34a8711Sopenharmony_ci    newSession->type = 4;
1399a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->IsSameSession(oldSession, newSession), true);
1400a34a8711Sopenharmony_ci}
1401a34a8711Sopenharmony_ci
1402a34a8711Sopenharmony_ci/**
1403a34a8711Sopenharmony_ci * @tc.name: AttachSessionObject001
1404a34a8711Sopenharmony_ci * @tc.desc: Verify the AttachSessionObject function
1405a34a8711Sopenharmony_ci * @tc.type: FUNC
1406a34a8711Sopenharmony_ci */
1407a34a8711Sopenharmony_ciHWTEST_F(DBinderServiceUnitTest, AttachSessionObject001, TestSize.Level1)
1408a34a8711Sopenharmony_ci{
1409a34a8711Sopenharmony_ci    std::shared_ptr<struct SessionInfo> object = nullptr;
1410a34a8711Sopenharmony_ci    binder_uintptr_t stub = 0;
1411a34a8711Sopenharmony_ci    sptr<DBinderService> dBinderService = DBinderService::GetInstance();
1412a34a8711Sopenharmony_ci    EXPECT_TRUE(dBinderService != nullptr);
1413a34a8711Sopenharmony_ci    EXPECT_EQ(dBinderService->AttachSessionObject(object, stub), true);
1414a34a8711Sopenharmony_ci}
1415