179a732c7Sopenharmony_ci/*
279a732c7Sopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
379a732c7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
479a732c7Sopenharmony_ci * you may not use this file except in compliance with the License.
579a732c7Sopenharmony_ci * You may obtain a copy of the License at
679a732c7Sopenharmony_ci *
779a732c7Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
879a732c7Sopenharmony_ci *
979a732c7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1079a732c7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1179a732c7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1279a732c7Sopenharmony_ci * See the License for the specific language governing permissions and
1379a732c7Sopenharmony_ci * limitations under the License.
1479a732c7Sopenharmony_ci */
1579a732c7Sopenharmony_ci
1679a732c7Sopenharmony_ci#include "UTTest_ipc_client_manager.h"
1779a732c7Sopenharmony_ci
1879a732c7Sopenharmony_ci#include "device_manager_ipc_interface_code.h"
1979a732c7Sopenharmony_ci#include "device_manager_notify.h"
2079a732c7Sopenharmony_ci#include "dm_device_info.h"
2179a732c7Sopenharmony_ci#include "ipc_client_stub.h"
2279a732c7Sopenharmony_ci#include "ipc_register_listener_req.h"
2379a732c7Sopenharmony_ci#include "ipc_remote_broker.h"
2479a732c7Sopenharmony_ci#include "iremote_object.h"
2579a732c7Sopenharmony_ci#include "iservice_registry.h"
2679a732c7Sopenharmony_ci#include "dm_constants.h"
2779a732c7Sopenharmony_ci#include "system_ability_definition.h"
2879a732c7Sopenharmony_ci
2979a732c7Sopenharmony_ci#include <unistd.h>
3079a732c7Sopenharmony_ci
3179a732c7Sopenharmony_cinamespace OHOS {
3279a732c7Sopenharmony_cinamespace DistributedHardware {
3379a732c7Sopenharmony_civoid IpcClientManagerTest::SetUp()
3479a732c7Sopenharmony_ci{
3579a732c7Sopenharmony_ci}
3679a732c7Sopenharmony_ci
3779a732c7Sopenharmony_civoid IpcClientManagerTest::TearDown()
3879a732c7Sopenharmony_ci{
3979a732c7Sopenharmony_ci}
4079a732c7Sopenharmony_ci
4179a732c7Sopenharmony_civoid IpcClientManagerTest::SetUpTestCase()
4279a732c7Sopenharmony_ci{
4379a732c7Sopenharmony_ci}
4479a732c7Sopenharmony_ci
4579a732c7Sopenharmony_civoid IpcClientManagerTest::TearDownTestCase()
4679a732c7Sopenharmony_ci{
4779a732c7Sopenharmony_ci}
4879a732c7Sopenharmony_ci
4979a732c7Sopenharmony_cinamespace {
5079a732c7Sopenharmony_ci    /**
5179a732c7Sopenharmony_ci * @tc.name: OnRemoteDied_001
5279a732c7Sopenharmony_ci * @tc.desc: 1. new a dmInterface
5379a732c7Sopenharmony_ci *           2. set IpcClientManager dmInterface_ not null
5479a732c7Sopenharmony_ci *           3. call ClientInit
5579a732c7Sopenharmony_ci *           4. check ret is DM_OK
5679a732c7Sopenharmony_ci * @tc.type: FUNC
5779a732c7Sopenharmony_ci * @tc.require: AR000GHSJK
5879a732c7Sopenharmony_ci */
5979a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, OnRemoteDied_001, testing::ext::TestSize.Level0)
6079a732c7Sopenharmony_ci{
6179a732c7Sopenharmony_ci    // 1. set pkgName not null
6279a732c7Sopenharmony_ci    std::string pkgName = "com.ohos.test";
6379a732c7Sopenharmony_ci    // set dmInitCallback not null
6479a732c7Sopenharmony_ci    int count = 0;
6579a732c7Sopenharmony_ci    std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count);
6679a732c7Sopenharmony_ci    // 2. set checkMap null
6779a732c7Sopenharmony_ci    std::shared_ptr<DmInitCallback> checkMap = nullptr;
6879a732c7Sopenharmony_ci    // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
6979a732c7Sopenharmony_ci    DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
7079a732c7Sopenharmony_ci    // 4. Get checkMap from DeviceManagerNotify
7179a732c7Sopenharmony_ci    checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
7279a732c7Sopenharmony_ci    // 5. check checkMap not null
7379a732c7Sopenharmony_ci    ASSERT_NE(checkMap, nullptr);
7479a732c7Sopenharmony_ci    // 6. call DeviceManagerNotify OnRemoteDied
7579a732c7Sopenharmony_ci    DeviceManagerNotify::GetInstance().OnRemoteDied();
7679a732c7Sopenharmony_ci    // 7. check if dmInitCallback OnRemoteDied called
7779a732c7Sopenharmony_ci    ASSERT_EQ(count, 1);
7879a732c7Sopenharmony_ci}
7979a732c7Sopenharmony_ci
8079a732c7Sopenharmony_ci/**
8179a732c7Sopenharmony_ci * @tc.name: ClientInit_001
8279a732c7Sopenharmony_ci * @tc.desc: 1. new a dmInterface
8379a732c7Sopenharmony_ci *           2. set IpcClientManager dmInterface_ not null
8479a732c7Sopenharmony_ci *           3. call ClientInit
8579a732c7Sopenharmony_ci *           4. check ret is not ERR_DM_FAILED
8679a732c7Sopenharmony_ci * @tc.type: FUNC
8779a732c7Sopenharmony_ci * @tc.require: AR000GHSJK
8879a732c7Sopenharmony_ci */
8979a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, ClientInit_001, testing::ext::TestSize.Level0)
9079a732c7Sopenharmony_ci{
9179a732c7Sopenharmony_ci    // 1. new a dmInterface
9279a732c7Sopenharmony_ci    auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
9379a732c7Sopenharmony_ci    auto object = samgr->CheckSystemAbility(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID);
9479a732c7Sopenharmony_ci    sptr<IpcRemoteBroker> dmInterface = iface_cast<IpcRemoteBroker>(object);
9579a732c7Sopenharmony_ci    // 2. set IpcClientManager dmInterface_ not null
9679a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
9779a732c7Sopenharmony_ci    instance->dmInterface_ = dmInterface;
9879a732c7Sopenharmony_ci    // 3. call ClientInit
9979a732c7Sopenharmony_ci    int ret = instance->ClientInit();
10079a732c7Sopenharmony_ci    // 4. check ret is not ERR_DM_FAILED
10179a732c7Sopenharmony_ci    ASSERT_NE(ret, ERR_DM_FAILED);
10279a732c7Sopenharmony_ci}
10379a732c7Sopenharmony_ci
10479a732c7Sopenharmony_ci/**
10579a732c7Sopenharmony_ci * @tc.name: ClientInit_002
10679a732c7Sopenharmony_ci * @tc.desc: 1. new a dmInterface
10779a732c7Sopenharmony_ci *           2. set IpcClientManager dmInterface_ not null
10879a732c7Sopenharmony_ci *           3. call ClientInit
10979a732c7Sopenharmony_ci *           4. check ret is not ERR_DM_FAILED
11079a732c7Sopenharmony_ci * @tc.type: FUNC
11179a732c7Sopenharmony_ci * @tc.require: AR000GHSJK
11279a732c7Sopenharmony_ci */
11379a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, ClientInit_002, testing::ext::TestSize.Level0)
11479a732c7Sopenharmony_ci{
11579a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
11679a732c7Sopenharmony_ci    // 3. call ClientInit
11779a732c7Sopenharmony_ci    int ret = instance->ClientInit();
11879a732c7Sopenharmony_ci    // 4. check ret is not ERR_DM_FAILED
11979a732c7Sopenharmony_ci    ASSERT_NE(ret, ERR_DM_FAILED);
12079a732c7Sopenharmony_ci}
12179a732c7Sopenharmony_ci
12279a732c7Sopenharmony_ci/**
12379a732c7Sopenharmony_ci * @tc.name: Init_001
12479a732c7Sopenharmony_ci * @tc.desc: 1. new a listener
12579a732c7Sopenharmony_ci *           2. set a pkgName not null
12679a732c7Sopenharmony_ci *           3. add listener and pkgName in dmListener_ Map
12779a732c7Sopenharmony_ci *           4. call Init with pkgName
12879a732c7Sopenharmony_ci *           5. check ret is not ERR_DM_FAILED
12979a732c7Sopenharmony_ci * @tc.type: FUNC
13079a732c7Sopenharmony_ci * @tc.require: AR000GHSJK
13179a732c7Sopenharmony_ci */
13279a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, Init_001, testing::ext::TestSize.Level0)
13379a732c7Sopenharmony_ci{
13479a732c7Sopenharmony_ci    // 1. new a listener
13579a732c7Sopenharmony_ci    sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub());
13679a732c7Sopenharmony_ci    // 2. set a pkgName not null
13779a732c7Sopenharmony_ci    std::string pkgName = "com.ohos.test";
13879a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
13979a732c7Sopenharmony_ci    // 3. add listener and pkgName in dmListener_ Map
14079a732c7Sopenharmony_ci    instance->dmListener_[pkgName] = listener;
14179a732c7Sopenharmony_ci    // 4. call Init with pkgName
14279a732c7Sopenharmony_ci    int32_t ret = instance->Init(pkgName);
14379a732c7Sopenharmony_ci    // 5. check ret is not ERR_DM_FAILED
14479a732c7Sopenharmony_ci    ASSERT_NE(ret, ERR_DM_FAILED);
14579a732c7Sopenharmony_ci}
14679a732c7Sopenharmony_ci
14779a732c7Sopenharmony_ci/**
14879a732c7Sopenharmony_ci * @tc.name: Init_002
14979a732c7Sopenharmony_ci * @tc.desc: 1. set pkcName not null
15079a732c7Sopenharmony_ci *           2. Mock IpcClientServerProxy SendCmd return ERR_DM_FAILED
15179a732c7Sopenharmony_ci *           3. call Init with pkgName
15279a732c7Sopenharmony_ci *           4. check ret is ERR_DM_FAILED
15379a732c7Sopenharmony_ci * @tc.type: FUNC
15479a732c7Sopenharmony_ci * @tc.require: AR000GHSJK
15579a732c7Sopenharmony_ci */
15679a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, Init_002, testing::ext::TestSize.Level0)
15779a732c7Sopenharmony_ci{
15879a732c7Sopenharmony_ci    // 1. set pkcName not null
15979a732c7Sopenharmony_ci    std::string pkgName = "com.ohos.test";
16079a732c7Sopenharmony_ci    // 2. Mock IpcClientServerProxy SendCmd return ERR_DM_FAILED
16179a732c7Sopenharmony_ci    sptr<IRemoteObject> remoteObject = nullptr;
16279a732c7Sopenharmony_ci    auto mockInstance = new MockIpcClientManager(remoteObject);
16379a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
16479a732c7Sopenharmony_ci    instance->dmInterface_ = mockInstance;
16579a732c7Sopenharmony_ci    EXPECT_CALL(*mockInstance, SendCmd(testing::_, testing::_, testing::_))
16679a732c7Sopenharmony_ci                .Times(1).WillOnce(testing::Return(ERR_DM_FAILED));
16779a732c7Sopenharmony_ci    // 3. call Init with pkgName
16879a732c7Sopenharmony_ci    int32_t ret = instance->Init(pkgName);
16979a732c7Sopenharmony_ci    // 4. check ret is ERR_DM_FAILED
17079a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_FAILED);
17179a732c7Sopenharmony_ci}
17279a732c7Sopenharmony_ci
17379a732c7Sopenharmony_ci/**
17479a732c7Sopenharmony_ci * @tc.name: Init_003
17579a732c7Sopenharmony_ci * @tc.desc: 1. set pkcName not null
17679a732c7Sopenharmony_ci *           2. Mock IpcClientServerProxy SendCmd return DM_OK
17779a732c7Sopenharmony_ci *           3. call Init with pkgName
17879a732c7Sopenharmony_ci *           4. check ret is DM_OK
17979a732c7Sopenharmony_ci * @tc.type: FUNC
18079a732c7Sopenharmony_ci * @tc.require: AR000GHSJK
18179a732c7Sopenharmony_ci */
18279a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, Init_003, testing::ext::TestSize.Level0)
18379a732c7Sopenharmony_ci{
18479a732c7Sopenharmony_ci    // 1. set pkcName not null
18579a732c7Sopenharmony_ci    std::string pkgName = "com.ohos.test";
18679a732c7Sopenharmony_ci    // 2. Mock IpcClientServerProxy SendCmd return DM_OK
18779a732c7Sopenharmony_ci    sptr<IRemoteObject> remoteObject = nullptr;
18879a732c7Sopenharmony_ci    auto mockInstance = new MockIpcClientManager(remoteObject);
18979a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
19079a732c7Sopenharmony_ci    instance->dmInterface_ = mockInstance;
19179a732c7Sopenharmony_ci    EXPECT_CALL(*mockInstance, SendCmd(testing::_, testing::_, testing::_))
19279a732c7Sopenharmony_ci                .Times(1).WillOnce(testing::Return(DM_OK));
19379a732c7Sopenharmony_ci    // 3. call Init with pkgName
19479a732c7Sopenharmony_ci    int32_t ret = instance->Init(pkgName);
19579a732c7Sopenharmony_ci    // 4. check ret is DM_OK
19679a732c7Sopenharmony_ci    ASSERT_EQ(ret, DM_OK);
19779a732c7Sopenharmony_ci}
19879a732c7Sopenharmony_ci
19979a732c7Sopenharmony_ci/**
20079a732c7Sopenharmony_ci * @tc.name: Init_004
20179a732c7Sopenharmony_ci * @tc.desc: 1. set pkcName not null
20279a732c7Sopenharmony_ci *           2. Mock IpcClientServerProxy SendCmd return DM_OK
20379a732c7Sopenharmony_ci *           3. call Init with pkgName
20479a732c7Sopenharmony_ci *           4. check ret is DM_OK
20579a732c7Sopenharmony_ci * @tc.type: FUNC
20679a732c7Sopenharmony_ci * @tc.require: AR000GHSJK
20779a732c7Sopenharmony_ci */
20879a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, Init_004, testing::ext::TestSize.Level0)
20979a732c7Sopenharmony_ci{
21079a732c7Sopenharmony_ci    // 1. set pkcName not null
21179a732c7Sopenharmony_ci    std::string pkgName = "com.ohos.test";
21279a732c7Sopenharmony_ci    // 2. Mock IpcClientServerProxy SendCmd return DEVICEMANAGER_SERVICE_NOT_READY
21379a732c7Sopenharmony_ci    sptr<IRemoteObject> remoteObject = nullptr;
21479a732c7Sopenharmony_ci    auto mockInstance = new MockIpcClientManager(remoteObject);
21579a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
21679a732c7Sopenharmony_ci    instance->dmInterface_ = mockInstance;
21779a732c7Sopenharmony_ci    EXPECT_CALL(*mockInstance, SendCmd(testing::_, testing::_, testing::_))
21879a732c7Sopenharmony_ci                .Times(1).WillOnce(testing::Return(ERR_DM_INIT_FAILED));
21979a732c7Sopenharmony_ci    // 3. call Init with pkgName
22079a732c7Sopenharmony_ci    int32_t ret = instance->Init(pkgName);
22179a732c7Sopenharmony_ci    // 4. check ret is DEVICEMANAGER_OK
22279a732c7Sopenharmony_ci    ASSERT_EQ(ret, ret);
22379a732c7Sopenharmony_ci}
22479a732c7Sopenharmony_ci
22579a732c7Sopenharmony_ci/**
22679a732c7Sopenharmony_ci * @tc.name: Init_005
22779a732c7Sopenharmony_ci * @tc.desc:  1. set pkcName not null
22879a732c7Sopenharmony_ci *            2. Mock IpcClientServerProxy SendCmd return ERR_DM_IPC_RESPOND_FAILED
22979a732c7Sopenharmony_ci *            3. call Init with pkgName
23079a732c7Sopenharmony_ci *            4. check ret is ERR_DM_IPC_RESPOND_FAILED
23179a732c7Sopenharmony_ci * @tc.type: FUNC
23279a732c7Sopenharmony_ci * @tc.require: AR000GHSJK
23379a732c7Sopenharmony_ci */
23479a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, Init_005, testing::ext::TestSize.Level0)
23579a732c7Sopenharmony_ci{
23679a732c7Sopenharmony_ci    // 1. set pkcName not null
23779a732c7Sopenharmony_ci    std::string pkgName = "com.ohos.test";
23879a732c7Sopenharmony_ci    // 2. Mock IpcClientServerProxy SendCmd return DM_OK
23979a732c7Sopenharmony_ci    sptr<IRemoteObject> remoteObject = nullptr;
24079a732c7Sopenharmony_ci    auto mockInstance = new MockIpcClientManager(remoteObject);
24179a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
24279a732c7Sopenharmony_ci    instance->dmInterface_ = mockInstance;
24379a732c7Sopenharmony_ci    EXPECT_CALL(*mockInstance, SendCmd(testing::_, testing::_, testing::_))
24479a732c7Sopenharmony_ci                .Times(1).WillOnce(testing::Return(ERR_DM_IPC_RESPOND_FAILED));
24579a732c7Sopenharmony_ci    // 3. call Init with pkgName
24679a732c7Sopenharmony_ci    int32_t ret = instance->Init(pkgName);
24779a732c7Sopenharmony_ci    // 4. check ret is ERR_DM_IPC_RESPOND_FAILED
24879a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_IPC_RESPOND_FAILED);
24979a732c7Sopenharmony_ci}
25079a732c7Sopenharmony_ci
25179a732c7Sopenharmony_ci/**
25279a732c7Sopenharmony_ci * @tc.name: UnInit_001
25379a732c7Sopenharmony_ci * @tc.desc:  1. set pkgName null
25479a732c7Sopenharmony_ci *               set IpcClientManager dmInterface_ null
25579a732c7Sopenharmony_ci *            2. call UnInit with pkgName
25679a732c7Sopenharmony_ci *            3. check ret is ERR_DM_INPUT_PARA_INVALID
25779a732c7Sopenharmony_ci * @tc.type: FUNC
25879a732c7Sopenharmony_ci * @tc.require: AR000GHSJK
25979a732c7Sopenharmony_ci */
26079a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, UnInit1, testing::ext::TestSize.Level0)
26179a732c7Sopenharmony_ci{
26279a732c7Sopenharmony_ci    // 1. set pkgName null
26379a732c7Sopenharmony_ci    std::string pkgName;
26479a732c7Sopenharmony_ci    // set IpcClientManager dmInterface_ null
26579a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
26679a732c7Sopenharmony_ci    instance->dmInterface_ = nullptr;
26779a732c7Sopenharmony_ci    // 2. call UnInit with pkgName
26879a732c7Sopenharmony_ci    int32_t ret = instance->UnInit(pkgName);
26979a732c7Sopenharmony_ci    // 3. check ret is ERR_DM_INPUT_PARA_INVALID
27079a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
27179a732c7Sopenharmony_ci}
27279a732c7Sopenharmony_ci
27379a732c7Sopenharmony_ci/**
27479a732c7Sopenharmony_ci * @tc.name: UnInit_002
27579a732c7Sopenharmony_ci * @tc.desc:  1. set pkgName not null
27679a732c7Sopenharmony_ci *            2. Mock IpcClientServerProxy SendCmd return ERR_DM_FAILED
27779a732c7Sopenharmony_ci *            3. set IpcClientManager dmInterface_ not null
27879a732c7Sopenharmony_ci *            4. set IpcClientManager dmListener_ not null
27979a732c7Sopenharmony_ci *            5. call UnInit with pkgName
28079a732c7Sopenharmony_ci *            6. check ret is ERR_DM_FAILED
28179a732c7Sopenharmony_ci * @tc.type: FUNC
28279a732c7Sopenharmony_ci * @tc.require: AR000GHSJK
28379a732c7Sopenharmony_ci */
28479a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, UnInit_002, testing::ext::TestSize.Level0)
28579a732c7Sopenharmony_ci{
28679a732c7Sopenharmony_ci    // 1. set pkgName not null
28779a732c7Sopenharmony_ci    std::string pkgName = "com.ohos.test";
28879a732c7Sopenharmony_ci    // 2. Mock IpcClientServerProxy SendCmd return ERR_DM_FAILED
28979a732c7Sopenharmony_ci    sptr<IRemoteObject> remoteObject = nullptr;
29079a732c7Sopenharmony_ci    auto mockInstance = new MockIpcClientManager(remoteObject);
29179a732c7Sopenharmony_ci    EXPECT_CALL(*mockInstance, SendCmd(testing::_, testing::_, testing::_))
29279a732c7Sopenharmony_ci                .Times(1).WillOnce(testing::Return(ERR_DM_FAILED));
29379a732c7Sopenharmony_ci    // 3. set IpcClientManager dmInterface_ not null
29479a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
29579a732c7Sopenharmony_ci    instance->dmInterface_ = mockInstance;
29679a732c7Sopenharmony_ci    // 4. set IpcClientManager dmListener_ not null
29779a732c7Sopenharmony_ci    sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub());
29879a732c7Sopenharmony_ci    instance->dmListener_[pkgName] = listener;
29979a732c7Sopenharmony_ci    // 5. call UnInit with pkgName
30079a732c7Sopenharmony_ci    int32_t ret = instance->UnInit(pkgName);
30179a732c7Sopenharmony_ci    // 6. check ret is ERR_DM_FAILED
30279a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_FAILED);
30379a732c7Sopenharmony_ci}
30479a732c7Sopenharmony_ci
30579a732c7Sopenharmony_ci/**
30679a732c7Sopenharmony_ci * @tc.name: UnInit_003
30779a732c7Sopenharmony_ci * @tc.desc:  1. set pkgName not null
30879a732c7Sopenharmony_ci *            2. Mock IpcClientServerProxy SendCmd return DM_OK
30979a732c7Sopenharmony_ci *            3. set IpcClientManager dmInterface_ not null
31079a732c7Sopenharmony_ci *            4. set IpcClientManager dmListener_ not null
31179a732c7Sopenharmony_ci *            5. call UnInit with pkgName
31279a732c7Sopenharmony_ci *            6. check ret is DM_OK
31379a732c7Sopenharmony_ci * @tc.type: FUNC
31479a732c7Sopenharmony_ci * @tc.require: AR000GHSJK
31579a732c7Sopenharmony_ci */
31679a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, UnInit_003, testing::ext::TestSize.Level0)
31779a732c7Sopenharmony_ci{
31879a732c7Sopenharmony_ci    // 1. set pkgName not null
31979a732c7Sopenharmony_ci    std::string pkgName = "com.ohos.test";
32079a732c7Sopenharmony_ci    // 2. Mock IpcClientServerProxy SendCmd return DM_OK
32179a732c7Sopenharmony_ci    sptr<IRemoteObject> remoteObject = nullptr;
32279a732c7Sopenharmony_ci    auto mockInstance = new MockIpcClientManager(remoteObject);
32379a732c7Sopenharmony_ci    EXPECT_CALL(*mockInstance, SendCmd(testing::_, testing::_, testing::_))
32479a732c7Sopenharmony_ci                .Times(1).WillOnce(testing::Return(DM_OK));
32579a732c7Sopenharmony_ci    // 3. set IpcClientManager dmInterface_ not null
32679a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
32779a732c7Sopenharmony_ci    instance->dmInterface_ = mockInstance;
32879a732c7Sopenharmony_ci    // 4. set IpcClientManager dmListener_ not null
32979a732c7Sopenharmony_ci    sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub());
33079a732c7Sopenharmony_ci    instance->dmListener_[pkgName] = listener;
33179a732c7Sopenharmony_ci    // 5. call UnInit with pkgName
33279a732c7Sopenharmony_ci    int32_t ret = instance->UnInit(pkgName);
33379a732c7Sopenharmony_ci    // 6. check ret is DM_OK
33479a732c7Sopenharmony_ci    ASSERT_EQ(ret, DM_OK);
33579a732c7Sopenharmony_ci}
33679a732c7Sopenharmony_ci
33779a732c7Sopenharmony_ci/**
33879a732c7Sopenharmony_ci * @tc.name: UnInit_004
33979a732c7Sopenharmony_ci * @tc.desc:  1. set pkgName not null
34079a732c7Sopenharmony_ci *            2. Mock IpcClientServerProxy SendCmd return ERR_DM_INIT_FAILED
34179a732c7Sopenharmony_ci *            3. set IpcClientManager dmInterface_ not null
34279a732c7Sopenharmony_ci *            4. set IpcClientManager dmListener_ not null
34379a732c7Sopenharmony_ci *            5. call UnInit with pkgName
34479a732c7Sopenharmony_ci *            6. check ret is ERR_DM_INIT_FAILED
34579a732c7Sopenharmony_ci * @tc.type: FUNC
34679a732c7Sopenharmony_ci * @tc.require: AR000GHSJK
34779a732c7Sopenharmony_ci */
34879a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, UnInit_004, testing::ext::TestSize.Level0)
34979a732c7Sopenharmony_ci{
35079a732c7Sopenharmony_ci    // 1. set pkgName not null
35179a732c7Sopenharmony_ci    std::string pkgName = "com.ohos.test";
35279a732c7Sopenharmony_ci    // 2. Mock IpcClientServerProxy SendCmd return ERR_DM_INIT_FAILED
35379a732c7Sopenharmony_ci    sptr<IRemoteObject> remoteObject = nullptr;
35479a732c7Sopenharmony_ci    auto mockInstance = new MockIpcClientManager(remoteObject);
35579a732c7Sopenharmony_ci    EXPECT_CALL(*mockInstance, SendCmd(testing::_, testing::_, testing::_))
35679a732c7Sopenharmony_ci                .Times(1).WillOnce(testing::Return(ERR_DM_INIT_FAILED));
35779a732c7Sopenharmony_ci    // 3. set IpcClientManager dmInterface_ not null
35879a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
35979a732c7Sopenharmony_ci    instance->dmInterface_ = mockInstance;
36079a732c7Sopenharmony_ci    // 4. set IpcClientManager dmListener_ not null
36179a732c7Sopenharmony_ci    sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub());
36279a732c7Sopenharmony_ci    instance->dmListener_[pkgName] = listener;
36379a732c7Sopenharmony_ci    // 5. call UnInit with pkgName
36479a732c7Sopenharmony_ci    int32_t ret = instance->UnInit(pkgName);
36579a732c7Sopenharmony_ci    // 6. check ret is ERR_DM_INIT_FAILED
36679a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_INIT_FAILED);
36779a732c7Sopenharmony_ci}
36879a732c7Sopenharmony_ci
36979a732c7Sopenharmony_ci/**
37079a732c7Sopenharmony_ci * @tc.name: UnInit_005
37179a732c7Sopenharmony_ci * @tc.desc:  1. set pkgName not null
37279a732c7Sopenharmony_ci *            2. Mock IpcClientServerProxy SendCmd return ERR_DM_IPC_SEND_REQUEST_FAILED
37379a732c7Sopenharmony_ci *            3. set IpcClientManager dmInterface_ not null
37479a732c7Sopenharmony_ci *            4. set IpcClientManager dmListener_ not null
37579a732c7Sopenharmony_ci *            5. call UnInit with pkgName
37679a732c7Sopenharmony_ci *            6. check ret is ERR_DM_IPC_SEND_REQUEST_FAILED
37779a732c7Sopenharmony_ci * @tc.type: FUNC
37879a732c7Sopenharmony_ci * @tc.require: AR000GHSJK
37979a732c7Sopenharmony_ci */
38079a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, UnInit_005, testing::ext::TestSize.Level0)
38179a732c7Sopenharmony_ci{
38279a732c7Sopenharmony_ci    // 1. set pkgName not null
38379a732c7Sopenharmony_ci    std::string pkgName = "com.ohos.test";
38479a732c7Sopenharmony_ci    // 2. Mock IpcClientServerProxy SendCmd return ERR_DM_IPC_SEND_REQUEST_FAILED
38579a732c7Sopenharmony_ci    sptr<IRemoteObject> remoteObject = nullptr;
38679a732c7Sopenharmony_ci    auto mockInstance = new MockIpcClientManager(remoteObject);
38779a732c7Sopenharmony_ci    EXPECT_CALL(*mockInstance, SendCmd(testing::_, testing::_, testing::_))
38879a732c7Sopenharmony_ci                .Times(1).WillOnce(testing::Return(ERR_DM_IPC_SEND_REQUEST_FAILED));
38979a732c7Sopenharmony_ci    // 3. set IpcClientManager dmInterface_ not null
39079a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
39179a732c7Sopenharmony_ci    instance->dmInterface_ = mockInstance;
39279a732c7Sopenharmony_ci    // 4. set IpcClientManager dmListener_ not null
39379a732c7Sopenharmony_ci    sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub());
39479a732c7Sopenharmony_ci    instance->dmListener_[pkgName] = listener;
39579a732c7Sopenharmony_ci    // 5. call UnInit with pkgName
39679a732c7Sopenharmony_ci    int32_t ret = instance->UnInit(pkgName);
39779a732c7Sopenharmony_ci    // 6. check ret is ERR_DM_IPC_SEND_REQUEST_FAILED
39879a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_IPC_SEND_REQUEST_FAILED);
39979a732c7Sopenharmony_ci}
40079a732c7Sopenharmony_ci
40179a732c7Sopenharmony_ci/**
40279a732c7Sopenharmony_ci * @tc.name: SendRequest_001
40379a732c7Sopenharmony_ci * @tc.desc:  1. set pkgName null
40479a732c7Sopenharmony_ci *            2. set IpcClientManager dmInterface_null
40579a732c7Sopenharmony_ci *            3. call SendRequest with parameter
40679a732c7Sopenharmony_ci *            4. check ret is ERR_DM_INIT_FAILED
40779a732c7Sopenharmony_ci * @tc.type: FUNC
40879a732c7Sopenharmony_ci * @tc.require: AR000GHSJK
40979a732c7Sopenharmony_ci */
41079a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, SendRequest_001, testing::ext::TestSize.Level0)
41179a732c7Sopenharmony_ci{
41279a732c7Sopenharmony_ci    // 1. set pkgName null
41379a732c7Sopenharmony_ci    std::string pkgName = "";
41479a732c7Sopenharmony_ci    std::shared_ptr<IpcReq> req = std::make_shared<IpcReq>();
41579a732c7Sopenharmony_ci    std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
41679a732c7Sopenharmony_ci    req->SetPkgName(pkgName);
41779a732c7Sopenharmony_ci    // 2. set IpcClientManager dmInterface_null
41879a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
41979a732c7Sopenharmony_ci    instance->dmInterface_ = nullptr;
42079a732c7Sopenharmony_ci    // 3. call SendRequest with parameter
42179a732c7Sopenharmony_ci    int ret = instance->SendRequest(0, req, rsp);
42279a732c7Sopenharmony_ci    // 4. check ret is ERR_DM_INIT_FAILED
42379a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_INIT_FAILED);
42479a732c7Sopenharmony_ci}
42579a732c7Sopenharmony_ci
42679a732c7Sopenharmony_ci/**
42779a732c7Sopenharmony_ci * @tc.name: SendRequest_002
42879a732c7Sopenharmony_ci * @tc.desc:  1. set pkgName not null
42979a732c7Sopenharmony_ci *            2. Mock IpcClientServerProxy SendCmd return ERR_DM_FAILED
43079a732c7Sopenharmony_ci *            3. set IpcClientManager dmInterface_ not null
43179a732c7Sopenharmony_ci *            4. set IpcClientManager dmListener_ not null
43279a732c7Sopenharmony_ci *            5. call SendRequest with parameter
43379a732c7Sopenharmony_ci *            6. check ret is ERR_DM_FAILED
43479a732c7Sopenharmony_ci * @tc.type: FUNC
43579a732c7Sopenharmony_ci * @tc.require: AR000GHSJK
43679a732c7Sopenharmony_ci */
43779a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, SendRequest_002, testing::ext::TestSize.Level0)
43879a732c7Sopenharmony_ci{
43979a732c7Sopenharmony_ci    // 1. set pkgName not null
44079a732c7Sopenharmony_ci    std::string pkgName = "com.ohos.test";
44179a732c7Sopenharmony_ci    std::shared_ptr<IpcReq> req = std::make_shared<IpcReq>();
44279a732c7Sopenharmony_ci    std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
44379a732c7Sopenharmony_ci    req->SetPkgName(pkgName);
44479a732c7Sopenharmony_ci    // 2. Mock IpcClientServerProxy SendCmd return ERR_DM_FAILED
44579a732c7Sopenharmony_ci    sptr<IRemoteObject> remoteObject = nullptr;
44679a732c7Sopenharmony_ci    auto mockInstance = new MockIpcClientManager(remoteObject);
44779a732c7Sopenharmony_ci    EXPECT_CALL(*mockInstance, SendCmd(testing::_, testing::_, testing::_))
44879a732c7Sopenharmony_ci                .Times(1).WillOnce(testing::Return(ERR_DM_FAILED));
44979a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
45079a732c7Sopenharmony_ci    // 3. set IpcClientManager dmInterface_ not null
45179a732c7Sopenharmony_ci    instance->dmInterface_ = mockInstance;
45279a732c7Sopenharmony_ci    sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub());
45379a732c7Sopenharmony_ci    // 4. set IpcClientManager dmListener_ not null
45479a732c7Sopenharmony_ci    instance->dmListener_[pkgName] = listener;
45579a732c7Sopenharmony_ci    // 5. call SendRequest with parameter
45679a732c7Sopenharmony_ci    int ret = instance->SendRequest(0, req, rsp);
45779a732c7Sopenharmony_ci    // 6. check ret is ERR_DM_FAILED
45879a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_FAILED);
45979a732c7Sopenharmony_ci}
46079a732c7Sopenharmony_ci
46179a732c7Sopenharmony_ci/**
46279a732c7Sopenharmony_ci * @tc.name: SendRequest_003
46379a732c7Sopenharmony_ci * @tc.desc:  1. set pkgName not null
46479a732c7Sopenharmony_ci *            2. Mock IpcClientServerProxy SendCmd return DM_OK
46579a732c7Sopenharmony_ci *            3. set IpcClientManager dmInterface_ not null
46679a732c7Sopenharmony_ci *            4. set IpcClientManager dmListener_ not null
46779a732c7Sopenharmony_ci *            5. call SendRequest with parameter
46879a732c7Sopenharmony_ci *            6. check ret is DM_OK
46979a732c7Sopenharmony_ci * @tc.type: FUNC
47079a732c7Sopenharmony_ci * @tc.require: AR000GHSJK
47179a732c7Sopenharmony_ci */
47279a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, SendRequest_003, testing::ext::TestSize.Level0)
47379a732c7Sopenharmony_ci{
47479a732c7Sopenharmony_ci    // 1. set pkgName not null
47579a732c7Sopenharmony_ci    std::string pkgName = "com.ohos.test";
47679a732c7Sopenharmony_ci    std::shared_ptr<IpcReq> req = std::make_shared<IpcReq>();
47779a732c7Sopenharmony_ci    std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
47879a732c7Sopenharmony_ci    req->SetPkgName(pkgName);
47979a732c7Sopenharmony_ci    // 2. Mock IpcClientServerProxy SendCmd return DM_OK
48079a732c7Sopenharmony_ci    sptr<IRemoteObject> remoteObject = nullptr;
48179a732c7Sopenharmony_ci    auto mockInstance = new MockIpcClientManager(remoteObject);
48279a732c7Sopenharmony_ci    EXPECT_CALL(*mockInstance, SendCmd(testing::_, testing::_, testing::_))
48379a732c7Sopenharmony_ci                .Times(1).WillOnce(testing::Return(DM_OK));
48479a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
48579a732c7Sopenharmony_ci    // 3. set IpcClientManager dmInterface_ not null
48679a732c7Sopenharmony_ci    instance->dmInterface_ = mockInstance;
48779a732c7Sopenharmony_ci    sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub());
48879a732c7Sopenharmony_ci    // 4. set IpcClientManager dmListener_ not null
48979a732c7Sopenharmony_ci    instance->dmListener_[pkgName] = listener;
49079a732c7Sopenharmony_ci    // 5. call SendRequest with parameter
49179a732c7Sopenharmony_ci    int ret = instance->SendRequest(0, req, rsp);
49279a732c7Sopenharmony_ci    // 6. check ret is DM_OK
49379a732c7Sopenharmony_ci    ASSERT_EQ(ret, DM_OK);
49479a732c7Sopenharmony_ci}
49579a732c7Sopenharmony_ci
49679a732c7Sopenharmony_ci/**
49779a732c7Sopenharmony_ci * @tc.name: SendRequest_004
49879a732c7Sopenharmony_ci * @tc.desc:  1. set pkgName not null
49979a732c7Sopenharmony_ci *            2. Mock IpcClientServerProxy SendCmd return ERR_DM_INIT_FAILED
50079a732c7Sopenharmony_ci *            3. set IpcClientManager dmInterface_ not null
50179a732c7Sopenharmony_ci *            4. set IpcClientManager dmListener_ not null
50279a732c7Sopenharmony_ci *            5. call SendRequest with parameter
50379a732c7Sopenharmony_ci *            6. check ret is ERR_DM_INIT_FAILED
50479a732c7Sopenharmony_ci * @tc.type: FUNC
50579a732c7Sopenharmony_ci * @tc.require: AR000GHSJK
50679a732c7Sopenharmony_ci */
50779a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, SendRequest_004, testing::ext::TestSize.Level0)
50879a732c7Sopenharmony_ci{
50979a732c7Sopenharmony_ci    // 1. set pkgName not null
51079a732c7Sopenharmony_ci    std::string pkgName = "com.ohos.test";
51179a732c7Sopenharmony_ci    std::shared_ptr<IpcReq> req = std::make_shared<IpcReq>();
51279a732c7Sopenharmony_ci    std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
51379a732c7Sopenharmony_ci    req->SetPkgName(pkgName);
51479a732c7Sopenharmony_ci    // 2. Mock IpcClientServerProxy SendCmd return ERR_DM_INIT_FAILED
51579a732c7Sopenharmony_ci    sptr<IRemoteObject> remoteObject = nullptr;
51679a732c7Sopenharmony_ci    auto mockInstance = new MockIpcClientManager(remoteObject);
51779a732c7Sopenharmony_ci    EXPECT_CALL(*mockInstance, SendCmd(testing::_, testing::_, testing::_))
51879a732c7Sopenharmony_ci                .Times(1).WillOnce(testing::Return(ERR_DM_INIT_FAILED));
51979a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
52079a732c7Sopenharmony_ci    // 3. set IpcClientManager dmInterface_ not null
52179a732c7Sopenharmony_ci    instance->dmInterface_ = mockInstance;
52279a732c7Sopenharmony_ci    sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub());
52379a732c7Sopenharmony_ci    // 4. set IpcClientManager dmListener_ not null
52479a732c7Sopenharmony_ci    instance->dmListener_[pkgName] = listener;
52579a732c7Sopenharmony_ci    // 5. call SendRequest with parameter
52679a732c7Sopenharmony_ci    int ret = instance->SendRequest(0, req, rsp);
52779a732c7Sopenharmony_ci    // 6. check ret is ERR_DM_INIT_FAILED
52879a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_INIT_FAILED);
52979a732c7Sopenharmony_ci}
53079a732c7Sopenharmony_ci
53179a732c7Sopenharmony_ci/**
53279a732c7Sopenharmony_ci * @tc.name: SendRequest_005
53379a732c7Sopenharmony_ci * @tc.desc:  1. set pkgName not null
53479a732c7Sopenharmony_ci *            2. Mock IpcClientServerProxy SendCmd return ERR_DM_IPC_SEND_REQUEST_FAILED
53579a732c7Sopenharmony_ci *            3. set IpcClientManager dmInterface_ not null
53679a732c7Sopenharmony_ci *            4. set IpcClientManager dmListener_ not null
53779a732c7Sopenharmony_ci *            5. call SendRequest with parameter
53879a732c7Sopenharmony_ci *            6. check ret is ERR_DM_IPC_SEND_REQUEST_FAILED
53979a732c7Sopenharmony_ci * @tc.type: FUNC
54079a732c7Sopenharmony_ci * @tc.require: AR000GHSJK
54179a732c7Sopenharmony_ci */
54279a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, SendRequest_005, testing::ext::TestSize.Level0)
54379a732c7Sopenharmony_ci{
54479a732c7Sopenharmony_ci    // 1. set pkgName not null
54579a732c7Sopenharmony_ci    std::string pkgName = "com.ohos.test";
54679a732c7Sopenharmony_ci    std::shared_ptr<IpcReq> req = std::make_shared<IpcReq>();
54779a732c7Sopenharmony_ci    std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
54879a732c7Sopenharmony_ci    req->SetPkgName(pkgName);
54979a732c7Sopenharmony_ci    // 2. Mock IpcClientServerProxy SendCmd return ERR_DM_IPC_SEND_REQUEST_FAILED
55079a732c7Sopenharmony_ci    sptr<IRemoteObject> remoteObject = nullptr;
55179a732c7Sopenharmony_ci    auto mockInstance = new MockIpcClientManager(remoteObject);
55279a732c7Sopenharmony_ci    EXPECT_CALL(*mockInstance, SendCmd(testing::_, testing::_, testing::_))
55379a732c7Sopenharmony_ci                .Times(1).WillOnce(testing::Return(ERR_DM_IPC_SEND_REQUEST_FAILED));
55479a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
55579a732c7Sopenharmony_ci    // 3. set IpcClientManager dmInterface_ not null
55679a732c7Sopenharmony_ci    instance->dmInterface_ = mockInstance;
55779a732c7Sopenharmony_ci    sptr<IpcClientStub> listener = sptr<IpcClientStub>(new IpcClientStub());
55879a732c7Sopenharmony_ci    // 4. set IpcClientManager dmListener_ not null
55979a732c7Sopenharmony_ci    instance->dmListener_[pkgName] = listener;
56079a732c7Sopenharmony_ci    // 5. call SendRequest with parameter
56179a732c7Sopenharmony_ci    int ret = instance->SendRequest(0, req, rsp);
56279a732c7Sopenharmony_ci    // 6. check ret is ERR_DM_IPC_SEND_REQUEST_FAILED
56379a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_IPC_SEND_REQUEST_FAILED);
56479a732c7Sopenharmony_ci}
56579a732c7Sopenharmony_ci
56679a732c7Sopenharmony_ci/**
56779a732c7Sopenharmony_ci * @tc.name: SendRequest_006
56879a732c7Sopenharmony_ci * @tc.type: FUNC
56979a732c7Sopenharmony_ci */
57079a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, SendRequest_006, testing::ext::TestSize.Level0)
57179a732c7Sopenharmony_ci{
57279a732c7Sopenharmony_ci    std::string pkgName = "com.ohos.test";
57379a732c7Sopenharmony_ci    std::shared_ptr<IpcReq> req = std::make_shared<IpcReq>();
57479a732c7Sopenharmony_ci    std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
57579a732c7Sopenharmony_ci    req->SetPkgName(pkgName);
57679a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
57779a732c7Sopenharmony_ci    instance->dmInterface_ = nullptr;
57879a732c7Sopenharmony_ci    int ret = instance->SendRequest(IPC_MSG_BUTT, req, rsp);
57979a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_UNSUPPORTED_IPC_COMMAND);
58079a732c7Sopenharmony_ci}
58179a732c7Sopenharmony_ci
58279a732c7Sopenharmony_ci/**
58379a732c7Sopenharmony_ci * @tc.name: SendRequest_007
58479a732c7Sopenharmony_ci * @tc.type: FUNC
58579a732c7Sopenharmony_ci */
58679a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, SendRequest_007, testing::ext::TestSize.Level0)
58779a732c7Sopenharmony_ci{
58879a732c7Sopenharmony_ci    std::string pkgName = "com.ohos.test";
58979a732c7Sopenharmony_ci    std::shared_ptr<IpcReq> req = std::make_shared<IpcReq>();
59079a732c7Sopenharmony_ci    std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
59179a732c7Sopenharmony_ci    req->SetPkgName(pkgName);
59279a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
59379a732c7Sopenharmony_ci    instance->dmInterface_ = nullptr;
59479a732c7Sopenharmony_ci    int ret = instance->SendRequest(-1, req, rsp);
59579a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_UNSUPPORTED_IPC_COMMAND);
59679a732c7Sopenharmony_ci}
59779a732c7Sopenharmony_ci
59879a732c7Sopenharmony_ci/**
59979a732c7Sopenharmony_ci * @tc.name: SendRequest_008
60079a732c7Sopenharmony_ci * @tc.type: FUNC
60179a732c7Sopenharmony_ci */
60279a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, SendRequest_008, testing::ext::TestSize.Level0)
60379a732c7Sopenharmony_ci{
60479a732c7Sopenharmony_ci    std::string pkgName = "com.ohos.test";
60579a732c7Sopenharmony_ci    std::shared_ptr<IpcReq> req = nullptr;
60679a732c7Sopenharmony_ci    std::shared_ptr<IpcRsp> rsp = std::make_shared<IpcRsp>();
60779a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
60879a732c7Sopenharmony_ci    instance->dmInterface_ = nullptr;
60979a732c7Sopenharmony_ci    int ret = instance->SendRequest(0, req, rsp);
61079a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
61179a732c7Sopenharmony_ci}
61279a732c7Sopenharmony_ci
61379a732c7Sopenharmony_ci/**
61479a732c7Sopenharmony_ci * @tc.name: SendRequest_009
61579a732c7Sopenharmony_ci * @tc.type: FUNC
61679a732c7Sopenharmony_ci */
61779a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, SendRequest_009, testing::ext::TestSize.Level0)
61879a732c7Sopenharmony_ci{
61979a732c7Sopenharmony_ci    std::string pkgName = "";
62079a732c7Sopenharmony_ci    std::shared_ptr<IpcReq> req = std::make_shared<IpcReq>();
62179a732c7Sopenharmony_ci    std::shared_ptr<IpcRsp> rsp = nullptr;
62279a732c7Sopenharmony_ci    req->SetPkgName(pkgName);
62379a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
62479a732c7Sopenharmony_ci    instance->dmInterface_ = nullptr;
62579a732c7Sopenharmony_ci    int ret = instance->SendRequest(0, req, rsp);
62679a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
62779a732c7Sopenharmony_ci}
62879a732c7Sopenharmony_ci
62979a732c7Sopenharmony_ci/**
63079a732c7Sopenharmony_ci * @tc.name: OnDmServiceDied_001
63179a732c7Sopenharmony_ci * @tc.desc: 1. set IpcClientManager dmInterface_null
63279a732c7Sopenharmony_ci *           2. call OnDmServiceDied
63379a732c7Sopenharmony_ci *           3. check ret is ERR_DM_POINT_NULL
63479a732c7Sopenharmony_ci * @tc.type: FUNC
63579a732c7Sopenharmony_ci */
63679a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, OnDmServiceDied_001, testing::ext::TestSize.Level0)
63779a732c7Sopenharmony_ci{
63879a732c7Sopenharmony_ci    // 1. set IpcClientManager dmInterface_null
63979a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
64079a732c7Sopenharmony_ci    instance->dmInterface_ = nullptr;
64179a732c7Sopenharmony_ci    // 2. call OnDmServiceDied
64279a732c7Sopenharmony_ci    int32_t ret = instance->OnDmServiceDied();
64379a732c7Sopenharmony_ci    // 3. check ret is false
64479a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_POINT_NULL);
64579a732c7Sopenharmony_ci}
64679a732c7Sopenharmony_ci
64779a732c7Sopenharmony_ci/**
64879a732c7Sopenharmony_ci * @tc.name: OnDmServiceDied_002
64979a732c7Sopenharmony_ci * @tc.desc: 1. set IpcClientManager dmInterface_null
65079a732c7Sopenharmony_ci *           3. call OnDmServiceDied
65179a732c7Sopenharmony_ci *           4. check ret is DM_OK
65279a732c7Sopenharmony_ci * @tc.type: FUNC
65379a732c7Sopenharmony_ci */
65479a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, OnDmServiceDied_002, testing::ext::TestSize.Level0)
65579a732c7Sopenharmony_ci{
65679a732c7Sopenharmony_ci    // 1. set IpcClientManager dmInterface_null
65779a732c7Sopenharmony_ci    sptr<IRemoteObject> remoteObject = nullptr;
65879a732c7Sopenharmony_ci    auto mockInstance = new MockIpcClientManager(remoteObject);
65979a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
66079a732c7Sopenharmony_ci    instance->dmInterface_ = mockInstance;
66179a732c7Sopenharmony_ci    // 2. call OnDmServiceDied
66279a732c7Sopenharmony_ci    int32_t ret = instance->OnDmServiceDied();
66379a732c7Sopenharmony_ci    // 3. check ret is DM_OK
66479a732c7Sopenharmony_ci    ASSERT_EQ(ret, DM_OK);
66579a732c7Sopenharmony_ci}
66679a732c7Sopenharmony_ci
66779a732c7Sopenharmony_ci/**
66879a732c7Sopenharmony_ci * @tc.name: OnDmServiceDied_003
66979a732c7Sopenharmony_ci * @tc.desc: 1. set IpcClientManager dmInterface_null
67079a732c7Sopenharmony_ci *           3. call OnDmServiceDied
67179a732c7Sopenharmony_ci *           4. check ret is DM_OK
67279a732c7Sopenharmony_ci * @tc.type: FUNC
67379a732c7Sopenharmony_ci */
67479a732c7Sopenharmony_ciHWTEST_F(IpcClientManagerTest, OnDmServiceDied_003, testing::ext::TestSize.Level0)
67579a732c7Sopenharmony_ci{
67679a732c7Sopenharmony_ci    // 1. set IpcClientManager dmInterface_null
67779a732c7Sopenharmony_ci    auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
67879a732c7Sopenharmony_ci    auto object = samgr->CheckSystemAbility(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID);
67979a732c7Sopenharmony_ci    sptr<IpcRemoteBroker> dmInterface = iface_cast<IpcRemoteBroker>(object);
68079a732c7Sopenharmony_ci    std::shared_ptr<IpcClientManager> instance = std::make_shared<IpcClientManager>();
68179a732c7Sopenharmony_ci    instance->dmInterface_ = dmInterface;
68279a732c7Sopenharmony_ci    instance->dmRecipient_ = sptr<DmDeathRecipient>(new DmDeathRecipient());
68379a732c7Sopenharmony_ci    // 2. call OnDmServiceDied
68479a732c7Sopenharmony_ci    int32_t ret = instance->OnDmServiceDied();
68579a732c7Sopenharmony_ci    // 3. check ret is DM_OK
68679a732c7Sopenharmony_ci    ASSERT_EQ(ret, DM_OK);
68779a732c7Sopenharmony_ci}
68879a732c7Sopenharmony_ci} // namespace
68979a732c7Sopenharmony_ci
69079a732c7Sopenharmony_ciDmInitCallbackTest::DmInitCallbackTest(int &count) : DmInitCallback()
69179a732c7Sopenharmony_ci{
69279a732c7Sopenharmony_ci    count_ = &count;
69379a732c7Sopenharmony_ci}
69479a732c7Sopenharmony_ci
69579a732c7Sopenharmony_civoid DmInitCallbackTest::OnRemoteDied()
69679a732c7Sopenharmony_ci{
69779a732c7Sopenharmony_ci     *count_ = *count_ + 1;
69879a732c7Sopenharmony_ci}
69979a732c7Sopenharmony_ci} // namespace DistributedHardware
70079a732c7Sopenharmony_ci} // namespace OHOS
701