179a732c7Sopenharmony_ci/*
279a732c7Sopenharmony_ci * Copyright (c) 2022-2024 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_dm_pin_holder.h"
1779a732c7Sopenharmony_ci#include "dm_device_info.h"
1879a732c7Sopenharmony_ci
1979a732c7Sopenharmony_ci#include <unistd.h>
2079a732c7Sopenharmony_ci#include "accesstoken_kit.h"
2179a732c7Sopenharmony_ci#include "device_manager_notify.h"
2279a732c7Sopenharmony_ci#include "dm_constants.h"
2379a732c7Sopenharmony_ci#include "dm_log.h"
2479a732c7Sopenharmony_ci#include "ipc_authenticate_device_req.h"
2579a732c7Sopenharmony_ci#include "ipc_get_info_by_network_req.h"
2679a732c7Sopenharmony_ci#include "ipc_get_info_by_network_rsp.h"
2779a732c7Sopenharmony_ci#include "ipc_get_local_device_info_rsp.h"
2879a732c7Sopenharmony_ci#include "ipc_get_trustdevice_req.h"
2979a732c7Sopenharmony_ci#include "ipc_get_trustdevice_rsp.h"
3079a732c7Sopenharmony_ci#include "ipc_req.h"
3179a732c7Sopenharmony_ci#include "ipc_rsp.h"
3279a732c7Sopenharmony_ci#include "ipc_set_useroperation_req.h"
3379a732c7Sopenharmony_ci#include "ipc_skeleton.h"
3479a732c7Sopenharmony_ci#include "ipc_start_discovery_req.h"
3579a732c7Sopenharmony_ci#include "ipc_stop_discovery_req.h"
3679a732c7Sopenharmony_ci#include "ipc_publish_req.h"
3779a732c7Sopenharmony_ci#include "ipc_unpublish_req.h"
3879a732c7Sopenharmony_ci#include "ipc_unauthenticate_device_req.h"
3979a732c7Sopenharmony_ci#include "nativetoken_kit.h"
4079a732c7Sopenharmony_ci#include "nlohmann/json.hpp"
4179a732c7Sopenharmony_ci#include "securec.h"
4279a732c7Sopenharmony_ci#include "token_setproc.h"
4379a732c7Sopenharmony_ci#include "pin_holder.h"
4479a732c7Sopenharmony_ci#include "pinholder_session_callback.h"
4579a732c7Sopenharmony_ci#include "softbus_error_code.h"
4679a732c7Sopenharmony_ci
4779a732c7Sopenharmony_cinamespace OHOS {
4879a732c7Sopenharmony_cinamespace DistributedHardware {
4979a732c7Sopenharmony_civoid DmPinHolderTest::SetUp()
5079a732c7Sopenharmony_ci{
5179a732c7Sopenharmony_ci    const int32_t permsNum = 2;
5279a732c7Sopenharmony_ci    const int32_t indexZero = 0;
5379a732c7Sopenharmony_ci    const int32_t indexOne = 1;
5479a732c7Sopenharmony_ci    uint64_t tokenId;
5579a732c7Sopenharmony_ci    const char *perms[permsNum];
5679a732c7Sopenharmony_ci    perms[indexZero] = "ohos.permission.ACCESS_SERVICE_DM";
5779a732c7Sopenharmony_ci    perms[indexOne] = "ohos.permission.DISTRIBUTED_DATASYNC";
5879a732c7Sopenharmony_ci    NativeTokenInfoParams infoInstance = {
5979a732c7Sopenharmony_ci        .dcapsNum = 0,
6079a732c7Sopenharmony_ci        .permsNum = permsNum,
6179a732c7Sopenharmony_ci        .aclsNum = 0,
6279a732c7Sopenharmony_ci        .dcaps = NULL,
6379a732c7Sopenharmony_ci        .perms = perms,
6479a732c7Sopenharmony_ci        .acls = NULL,
6579a732c7Sopenharmony_ci        .processName = "CollaborationFwk",
6679a732c7Sopenharmony_ci        .aplStr = "system_core",
6779a732c7Sopenharmony_ci    };
6879a732c7Sopenharmony_ci    tokenId = GetAccessTokenId(&infoInstance);
6979a732c7Sopenharmony_ci    SetSelfTokenID(tokenId);
7079a732c7Sopenharmony_ci    OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
7179a732c7Sopenharmony_ci}
7279a732c7Sopenharmony_ci
7379a732c7Sopenharmony_civoid DmPinHolderTest::TearDown()
7479a732c7Sopenharmony_ci{
7579a732c7Sopenharmony_ci}
7679a732c7Sopenharmony_ci
7779a732c7Sopenharmony_civoid DmPinHolderTest::SetUpTestCase()
7879a732c7Sopenharmony_ci{
7979a732c7Sopenharmony_ci}
8079a732c7Sopenharmony_ci
8179a732c7Sopenharmony_civoid DmPinHolderTest::TearDownTestCase()
8279a732c7Sopenharmony_ci{
8379a732c7Sopenharmony_ci}
8479a732c7Sopenharmony_ci
8579a732c7Sopenharmony_civoid DmPinHolderCallbackTest::OnCreateResult(int32_t result)
8679a732c7Sopenharmony_ci{
8779a732c7Sopenharmony_ci    std::cout << "OnCreateResult " << result << std::endl;
8879a732c7Sopenharmony_ci}
8979a732c7Sopenharmony_ci
9079a732c7Sopenharmony_civoid DmPinHolderCallbackTest::OnDestroyResult(int32_t result)
9179a732c7Sopenharmony_ci{
9279a732c7Sopenharmony_ci    std::cout << "OnDestroyResult " << result << std::endl;
9379a732c7Sopenharmony_ci}
9479a732c7Sopenharmony_ci
9579a732c7Sopenharmony_civoid DmPinHolderCallbackTest::OnPinHolderDestroy(DmPinType pinType, const std::string &payload)
9679a732c7Sopenharmony_ci{
9779a732c7Sopenharmony_ci    std::cout << "OnPinHolderDestroy" << std::endl;
9879a732c7Sopenharmony_ci    std::cout << "pinType: " << pinType << std::endl;
9979a732c7Sopenharmony_ci}
10079a732c7Sopenharmony_ci
10179a732c7Sopenharmony_civoid DmPinHolderCallbackTest::OnPinHolderCreate(const std::string &deviceId, DmPinType pinType,
10279a732c7Sopenharmony_ci    const std::string &payload)
10379a732c7Sopenharmony_ci{
10479a732c7Sopenharmony_ci    std::cout << "OnPinHolderCreate" << std::endl;
10579a732c7Sopenharmony_ci    std::cout << "pinType: " << pinType << std::endl;
10679a732c7Sopenharmony_ci    std::cout << "payload: " << payload << std::endl;
10779a732c7Sopenharmony_ci}
10879a732c7Sopenharmony_ci
10979a732c7Sopenharmony_civoid DmPinHolderCallbackTest::OnPinHolderEvent(DmPinHolderEvent event, int32_t result, const std::string &content)
11079a732c7Sopenharmony_ci{
11179a732c7Sopenharmony_ci    std::cout << "OnPinHolderEvent" << std::endl;
11279a732c7Sopenharmony_ci    std::cout << "result: " << result << std::endl;
11379a732c7Sopenharmony_ci    std::cout << "content: " << content << std::endl;
11479a732c7Sopenharmony_ci}
11579a732c7Sopenharmony_ci
11679a732c7Sopenharmony_ciconstexpr int32_t MSG_TYPE_CREATE_PIN_HOLDER = 600;
11779a732c7Sopenharmony_ciconstexpr int32_t MSG_TYPE_CREATE_PIN_HOLDER_RESP = 601;
11879a732c7Sopenharmony_ciconstexpr int32_t MSG_TYPE_DESTROY_PIN_HOLDER = 650;
11979a732c7Sopenharmony_ciconstexpr int32_t MSG_TYPE_DESTROY_PIN_HOLDER_RESP = 651;
12079a732c7Sopenharmony_ci
12179a732c7Sopenharmony_ciconstexpr const char* TAG_PIN_TYPE = "PIN_TYPE";
12279a732c7Sopenharmony_ciconstexpr const char* TAG_PAYLOAD = "PAYLOAD";
12379a732c7Sopenharmony_ciconstexpr const char* TAG_REPLY = "REPLY";
12479a732c7Sopenharmony_cinamespace {
12579a732c7Sopenharmony_ci/**
12679a732c7Sopenharmony_ci * @tc.name: InitDeviceManager_001
12779a732c7Sopenharmony_ci * @tc.desc: 1. set packName not null
12879a732c7Sopenharmony_ci *              set dmInitCallback not null
12979a732c7Sopenharmony_ci *           2. call DeviceManagerImpl::InitDeviceManager with parameter
13079a732c7Sopenharmony_ci *           4. check ret is DM_OK
13179a732c7Sopenharmony_ci * deviceTypeId
13279a732c7Sopenharmony_ci * @tc.type: FUNC
13379a732c7Sopenharmony_ci * @tc.require: AR000GHSJK
13479a732c7Sopenharmony_ci */
13579a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, RegisterPinHolderCallback_101, testing::ext::TestSize.Level0)
13679a732c7Sopenharmony_ci{
13779a732c7Sopenharmony_ci    // 1. set packName not null
13879a732c7Sopenharmony_ci    std::string packName = "com.ohos.dmtest";
13979a732c7Sopenharmony_ci    // 2. set dmInitCallback not null
14079a732c7Sopenharmony_ci    std::shared_ptr<DmInitCallbackTest> callback = std::make_shared<DmInitCallbackTest>();
14179a732c7Sopenharmony_ci    int32_t ret = DeviceManager::GetInstance().InitDeviceManager(packName, callback);
14279a732c7Sopenharmony_ci
14379a732c7Sopenharmony_ci    std::shared_ptr<DmPinHolderCallbackTest> pinHolderCallback = std::make_shared<DmPinHolderCallbackTest>();
14479a732c7Sopenharmony_ci    ret = DeviceManager::GetInstance().RegisterPinHolderCallback(packName, pinHolderCallback);
14579a732c7Sopenharmony_ci    // 3. check ret is DM_OK
14679a732c7Sopenharmony_ci    ASSERT_EQ(ret, DM_OK);
14779a732c7Sopenharmony_ci    DeviceManager::GetInstance().UnInitDeviceManager(packName);
14879a732c7Sopenharmony_ci}
14979a732c7Sopenharmony_ci
15079a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, RegisterPinHolderCallback_102, testing::ext::TestSize.Level0)
15179a732c7Sopenharmony_ci{
15279a732c7Sopenharmony_ci    std::string packName = "com.ohos.dmtest";
15379a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
15479a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
15579a732c7Sopenharmony_ci    pinHolder->session_ = nullptr;
15679a732c7Sopenharmony_ci    int32_t ret = pinHolder->RegisterPinHolderCallback(packName);
15779a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_FAILED);
15879a732c7Sopenharmony_ci}
15979a732c7Sopenharmony_ci
16079a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, RegisterPinHolderCallback_103, testing::ext::TestSize.Level0)
16179a732c7Sopenharmony_ci{
16279a732c7Sopenharmony_ci    std::string packName = "com.ohos.dmtest";
16379a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
16479a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
16579a732c7Sopenharmony_ci    pinHolder->session_ = std::make_shared<PinHolderSession>();
16679a732c7Sopenharmony_ci    int32_t ret = pinHolder->RegisterPinHolderCallback(packName);
16779a732c7Sopenharmony_ci    ASSERT_EQ(ret, DM_OK);
16879a732c7Sopenharmony_ci}
16979a732c7Sopenharmony_ci
17079a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, CreatePinholder_101, testing::ext::TestSize.Level0)
17179a732c7Sopenharmony_ci{
17279a732c7Sopenharmony_ci    std::string packName = "com.ohos.dmtest";
17379a732c7Sopenharmony_ci    std::shared_ptr<DmInitCallbackTest> callback = std::make_shared<DmInitCallbackTest>();
17479a732c7Sopenharmony_ci    int32_t ret = DeviceManager::GetInstance().InitDeviceManager(packName, callback);
17579a732c7Sopenharmony_ci
17679a732c7Sopenharmony_ci    std::shared_ptr<DmPinHolderCallbackTest> pinHolderCallback = std::make_shared<DmPinHolderCallbackTest>();
17779a732c7Sopenharmony_ci    ret = DeviceManager::GetInstance().RegisterPinHolderCallback(packName, pinHolderCallback);
17879a732c7Sopenharmony_ci    PeerTargetId targetId;
17979a732c7Sopenharmony_ci    DmPinType pinType = NUMBER_PIN_CODE;
18079a732c7Sopenharmony_ci    std::string payload = "";
18179a732c7Sopenharmony_ci    ret = DeviceManager::GetInstance().CreatePinHolder(packName, targetId, pinType, payload);
18279a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
18379a732c7Sopenharmony_ci    DeviceManager::GetInstance().UnInitDeviceManager(packName);
18479a732c7Sopenharmony_ci}
18579a732c7Sopenharmony_ci
18679a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, CreatePinholder_102, testing::ext::TestSize.Level0)
18779a732c7Sopenharmony_ci{
18879a732c7Sopenharmony_ci    std::string packName = "com.ohos.dmtest";
18979a732c7Sopenharmony_ci    PeerTargetId targetId;
19079a732c7Sopenharmony_ci    DmPinType pinType = DmPinType::NUMBER_PIN_CODE;
19179a732c7Sopenharmony_ci    std::string payload;
19279a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
19379a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
19479a732c7Sopenharmony_ci    pinHolder->registerPkgName_ = "";
19579a732c7Sopenharmony_ci    int32_t ret = pinHolder->CreatePinHolder(packName, targetId, pinType, payload);
19679a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_FAILED);
19779a732c7Sopenharmony_ci}
19879a732c7Sopenharmony_ci
19979a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, CreatePinholder_103, testing::ext::TestSize.Level0)
20079a732c7Sopenharmony_ci{
20179a732c7Sopenharmony_ci    std::string packName = "com.ohos.dmtest";
20279a732c7Sopenharmony_ci    PeerTargetId targetId;
20379a732c7Sopenharmony_ci    DmPinType pinType = DmPinType::NUMBER_PIN_CODE;
20479a732c7Sopenharmony_ci    std::string payload;
20579a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
20679a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
20779a732c7Sopenharmony_ci    pinHolder->registerPkgName_ = "dmtest";
20879a732c7Sopenharmony_ci    int32_t ret = pinHolder->CreatePinHolder(packName, targetId, pinType, payload);
20979a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_FAILED);
21079a732c7Sopenharmony_ci}
21179a732c7Sopenharmony_ci
21279a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, CreatePinholder_105, testing::ext::TestSize.Level0)
21379a732c7Sopenharmony_ci{
21479a732c7Sopenharmony_ci    std::string packName = "com.ohos.dmtest";
21579a732c7Sopenharmony_ci    PeerTargetId targetId = {
21679a732c7Sopenharmony_ci        .deviceId = "",
21779a732c7Sopenharmony_ci        .brMac = "",
21879a732c7Sopenharmony_ci        .bleMac = "",
21979a732c7Sopenharmony_ci        .wifiIp = "",
22079a732c7Sopenharmony_ci    };
22179a732c7Sopenharmony_ci
22279a732c7Sopenharmony_ci    DmPinType pinType = DmPinType::NUMBER_PIN_CODE;
22379a732c7Sopenharmony_ci    std::string payload;
22479a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
22579a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
22679a732c7Sopenharmony_ci    pinHolder->registerPkgName_ = packName;
22779a732c7Sopenharmony_ci    int32_t ret = pinHolder->CreatePinHolder(packName, targetId, pinType, payload);
22879a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
22979a732c7Sopenharmony_ci}
23079a732c7Sopenharmony_ci
23179a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, CreatePinholder_106, testing::ext::TestSize.Level0)
23279a732c7Sopenharmony_ci{
23379a732c7Sopenharmony_ci    std::string packName = "com.ohos.dmtest";
23479a732c7Sopenharmony_ci    PeerTargetId targetId = {
23579a732c7Sopenharmony_ci        .deviceId = "deviceId",
23679a732c7Sopenharmony_ci        .brMac = "brMac",
23779a732c7Sopenharmony_ci        .bleMac = "bleMac",
23879a732c7Sopenharmony_ci        .wifiIp = "wifiIp",
23979a732c7Sopenharmony_ci    };
24079a732c7Sopenharmony_ci
24179a732c7Sopenharmony_ci    DmPinType pinType = DmPinType::NUMBER_PIN_CODE;
24279a732c7Sopenharmony_ci    std::string payload;
24379a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
24479a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
24579a732c7Sopenharmony_ci    pinHolder->registerPkgName_ = packName;
24679a732c7Sopenharmony_ci    pinHolder->listener_ = nullptr;
24779a732c7Sopenharmony_ci    int32_t ret = pinHolder->CreatePinHolder(packName, targetId, pinType, payload);
24879a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_FAILED);
24979a732c7Sopenharmony_ci}
25079a732c7Sopenharmony_ci
25179a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, CreatePinholder_107, testing::ext::TestSize.Level0)
25279a732c7Sopenharmony_ci{
25379a732c7Sopenharmony_ci    std::string packName = "com.ohos.dmtest";
25479a732c7Sopenharmony_ci    PeerTargetId targetId = {
25579a732c7Sopenharmony_ci        .deviceId = "deviceId",
25679a732c7Sopenharmony_ci        .brMac = "brMac",
25779a732c7Sopenharmony_ci        .bleMac = "bleMac",
25879a732c7Sopenharmony_ci        .wifiIp = "wifiIp",
25979a732c7Sopenharmony_ci    };
26079a732c7Sopenharmony_ci
26179a732c7Sopenharmony_ci    DmPinType pinType = DmPinType::NUMBER_PIN_CODE;
26279a732c7Sopenharmony_ci    std::string payload;
26379a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
26479a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
26579a732c7Sopenharmony_ci    pinHolder->registerPkgName_ = packName;
26679a732c7Sopenharmony_ci    pinHolder->session_ = nullptr;
26779a732c7Sopenharmony_ci    int32_t ret = pinHolder->CreatePinHolder(packName, targetId, pinType, payload);
26879a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_FAILED);
26979a732c7Sopenharmony_ci}
27079a732c7Sopenharmony_ci
27179a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, CreatePinholder_108, testing::ext::TestSize.Level0)
27279a732c7Sopenharmony_ci{
27379a732c7Sopenharmony_ci    std::string packName = "com.ohos.dmtest";
27479a732c7Sopenharmony_ci    PeerTargetId targetId = {
27579a732c7Sopenharmony_ci        .deviceId = "deviceId",
27679a732c7Sopenharmony_ci        .brMac = "brMac",
27779a732c7Sopenharmony_ci        .bleMac = "bleMac",
27879a732c7Sopenharmony_ci        .wifiIp = "wifiIp",
27979a732c7Sopenharmony_ci    };
28079a732c7Sopenharmony_ci
28179a732c7Sopenharmony_ci    DmPinType pinType = DmPinType::NUMBER_PIN_CODE;
28279a732c7Sopenharmony_ci    std::string payload;
28379a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
28479a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
28579a732c7Sopenharmony_ci    pinHolder->registerPkgName_ = packName;
28679a732c7Sopenharmony_ci    pinHolder->sourceState_ = SOURCE_CREATE;
28779a732c7Sopenharmony_ci    int32_t ret = pinHolder->CreatePinHolder(packName, targetId, pinType, payload);
28879a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_FAILED);
28979a732c7Sopenharmony_ci}
29079a732c7Sopenharmony_ci
29179a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, DestroyPinHolder_101, testing::ext::TestSize.Level0)
29279a732c7Sopenharmony_ci{
29379a732c7Sopenharmony_ci    std::string packName = "com.ohos.dmtest";
29479a732c7Sopenharmony_ci    PeerTargetId targetId = {
29579a732c7Sopenharmony_ci        .deviceId = "deviceId",
29679a732c7Sopenharmony_ci        .brMac = "brMac",
29779a732c7Sopenharmony_ci        .bleMac = "bleMac",
29879a732c7Sopenharmony_ci        .wifiIp = "wifiIp",
29979a732c7Sopenharmony_ci    };
30079a732c7Sopenharmony_ci    DmPinType pinType = DmPinType::NUMBER_PIN_CODE;
30179a732c7Sopenharmony_ci    std::string payload;
30279a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
30379a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
30479a732c7Sopenharmony_ci    pinHolder->listener_ = nullptr;
30579a732c7Sopenharmony_ci    int32_t ret = pinHolder->DestroyPinHolder(packName, targetId, pinType, payload);
30679a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_FAILED);
30779a732c7Sopenharmony_ci}
30879a732c7Sopenharmony_ci
30979a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, DestroyPinHolder_102, testing::ext::TestSize.Level0)
31079a732c7Sopenharmony_ci{
31179a732c7Sopenharmony_ci    std::string packName = "com.ohos.dmtest";
31279a732c7Sopenharmony_ci    PeerTargetId targetId = {
31379a732c7Sopenharmony_ci        .deviceId = "deviceId",
31479a732c7Sopenharmony_ci        .brMac = "brMac",
31579a732c7Sopenharmony_ci        .bleMac = "bleMac",
31679a732c7Sopenharmony_ci        .wifiIp = "wifiIp",
31779a732c7Sopenharmony_ci    };
31879a732c7Sopenharmony_ci    DmPinType pinType = DmPinType::NUMBER_PIN_CODE;
31979a732c7Sopenharmony_ci    std::string payload;
32079a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
32179a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
32279a732c7Sopenharmony_ci    pinHolder->session_ = nullptr;
32379a732c7Sopenharmony_ci    int32_t ret = pinHolder->DestroyPinHolder(packName, targetId, pinType, payload);
32479a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_FAILED);
32579a732c7Sopenharmony_ci}
32679a732c7Sopenharmony_ci
32779a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, DestroyPinHolder_103, testing::ext::TestSize.Level0)
32879a732c7Sopenharmony_ci{
32979a732c7Sopenharmony_ci    std::string packName = "com.ohos.dmtest";
33079a732c7Sopenharmony_ci    PeerTargetId targetId = {
33179a732c7Sopenharmony_ci        .deviceId = "deviceId",
33279a732c7Sopenharmony_ci        .brMac = "brMac",
33379a732c7Sopenharmony_ci        .bleMac = "bleMac",
33479a732c7Sopenharmony_ci        .wifiIp = "wifiIp",
33579a732c7Sopenharmony_ci    };
33679a732c7Sopenharmony_ci    DmPinType pinType = DmPinType::NUMBER_PIN_CODE;
33779a732c7Sopenharmony_ci    std::string payload;
33879a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
33979a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
34079a732c7Sopenharmony_ci    pinHolder->registerPkgName_ = "";
34179a732c7Sopenharmony_ci    int32_t ret = pinHolder->DestroyPinHolder(packName, targetId, pinType, payload);
34279a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_FAILED);
34379a732c7Sopenharmony_ci}
34479a732c7Sopenharmony_ci
34579a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, DestroyPinHolder_104, testing::ext::TestSize.Level0)
34679a732c7Sopenharmony_ci{
34779a732c7Sopenharmony_ci    std::string packName = "com.ohos.dmtest";
34879a732c7Sopenharmony_ci    PeerTargetId targetId = {
34979a732c7Sopenharmony_ci        .deviceId = "deviceId",
35079a732c7Sopenharmony_ci        .brMac = "brMac",
35179a732c7Sopenharmony_ci        .bleMac = "bleMac",
35279a732c7Sopenharmony_ci        .wifiIp = "wifiIp",
35379a732c7Sopenharmony_ci    };
35479a732c7Sopenharmony_ci    DmPinType pinType = DmPinType::NUMBER_PIN_CODE;
35579a732c7Sopenharmony_ci    std::string payload;
35679a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
35779a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
35879a732c7Sopenharmony_ci    pinHolder->registerPkgName_ = "dmtest";
35979a732c7Sopenharmony_ci    int32_t ret = pinHolder->DestroyPinHolder(packName, targetId, pinType, payload);
36079a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_FAILED);
36179a732c7Sopenharmony_ci}
36279a732c7Sopenharmony_ci
36379a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, DestroyPinHolder_105, testing::ext::TestSize.Level0)
36479a732c7Sopenharmony_ci{
36579a732c7Sopenharmony_ci    std::string packName = "com.ohos.dmtest";
36679a732c7Sopenharmony_ci    PeerTargetId targetId = {
36779a732c7Sopenharmony_ci        .deviceId = "",
36879a732c7Sopenharmony_ci        .brMac = "",
36979a732c7Sopenharmony_ci        .bleMac = "",
37079a732c7Sopenharmony_ci        .wifiIp = "",
37179a732c7Sopenharmony_ci    };
37279a732c7Sopenharmony_ci    DmPinType pinType = DmPinType::NUMBER_PIN_CODE;
37379a732c7Sopenharmony_ci    std::string payload;
37479a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
37579a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
37679a732c7Sopenharmony_ci    pinHolder->registerPkgName_ = packName;
37779a732c7Sopenharmony_ci    int32_t ret = pinHolder->DestroyPinHolder(packName, targetId, pinType, payload);
37879a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
37979a732c7Sopenharmony_ci}
38079a732c7Sopenharmony_ci
38179a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, DestroyPinHolder_106, testing::ext::TestSize.Level0)
38279a732c7Sopenharmony_ci{
38379a732c7Sopenharmony_ci    std::string packName = "com.ohos.dmtest";
38479a732c7Sopenharmony_ci    PeerTargetId targetId = {
38579a732c7Sopenharmony_ci        .deviceId = "deviceId",
38679a732c7Sopenharmony_ci        .brMac = "brMac",
38779a732c7Sopenharmony_ci        .bleMac = "bleMac",
38879a732c7Sopenharmony_ci        .wifiIp = "wifiIp",
38979a732c7Sopenharmony_ci    };
39079a732c7Sopenharmony_ci    DmPinType pinType = DmPinType::NUMBER_PIN_CODE;
39179a732c7Sopenharmony_ci    std::string payload;
39279a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
39379a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
39479a732c7Sopenharmony_ci    pinHolder->registerPkgName_ = packName;
39579a732c7Sopenharmony_ci    pinHolder->sessionId_ = 0;
39679a732c7Sopenharmony_ci    pinHolder->sourceState_ = SOURCE_DESTROY;
39779a732c7Sopenharmony_ci    pinHolder->listener_ = std::make_shared<IDeviceManagerServiceListenerTest>();
39879a732c7Sopenharmony_ci    int32_t ret = pinHolder->DestroyPinHolder(packName, targetId, pinType, payload);
39979a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_FAILED);
40079a732c7Sopenharmony_ci}
40179a732c7Sopenharmony_ci
40279a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, CreateGeneratePinHolderMsg_101, testing::ext::TestSize.Level0)
40379a732c7Sopenharmony_ci{
40479a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
40579a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
40679a732c7Sopenharmony_ci    pinHolder->listener_ = nullptr;
40779a732c7Sopenharmony_ci    int32_t ret = pinHolder->CreateGeneratePinHolderMsg();
40879a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_FAILED);
40979a732c7Sopenharmony_ci}
41079a732c7Sopenharmony_ci
41179a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, CreateGeneratePinHolderMsg_102, testing::ext::TestSize.Level0)
41279a732c7Sopenharmony_ci{
41379a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
41479a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
41579a732c7Sopenharmony_ci    pinHolder->session_ = nullptr;
41679a732c7Sopenharmony_ci    int32_t ret = pinHolder->CreateGeneratePinHolderMsg();
41779a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_FAILED);
41879a732c7Sopenharmony_ci}
41979a732c7Sopenharmony_ci
42079a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, ParseMsgType_101, testing::ext::TestSize.Level0)
42179a732c7Sopenharmony_ci{
42279a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
42379a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
42479a732c7Sopenharmony_ci    std::string message;
42579a732c7Sopenharmony_ci    int32_t ret = pinHolder->ParseMsgType(message);
42679a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_FAILED);
42779a732c7Sopenharmony_ci}
42879a732c7Sopenharmony_ci
42979a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, ProcessCreateMsg_101, testing::ext::TestSize.Level0)
43079a732c7Sopenharmony_ci{
43179a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
43279a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
43379a732c7Sopenharmony_ci    std::string message;
43479a732c7Sopenharmony_ci    pinHolder->listener_ = nullptr;
43579a732c7Sopenharmony_ci    pinHolder->ProcessCreateMsg(message);
43679a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
43779a732c7Sopenharmony_ci}
43879a732c7Sopenharmony_ci
43979a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, ProcessCreateMsg_102, testing::ext::TestSize.Level0)
44079a732c7Sopenharmony_ci{
44179a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
44279a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
44379a732c7Sopenharmony_ci    std::string message;
44479a732c7Sopenharmony_ci    pinHolder->session_ = nullptr;
44579a732c7Sopenharmony_ci    pinHolder->ProcessCreateMsg(message);
44679a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
44779a732c7Sopenharmony_ci}
44879a732c7Sopenharmony_ci
44979a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, ProcessCreateMsg_103, testing::ext::TestSize.Level0)
45079a732c7Sopenharmony_ci{
45179a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
45279a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
45379a732c7Sopenharmony_ci    nlohmann::json jsonObject;
45479a732c7Sopenharmony_ci    std::string message = jsonObject.dump();
45579a732c7Sopenharmony_ci    pinHolder->ProcessCreateMsg(message);
45679a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
45779a732c7Sopenharmony_ci}
45879a732c7Sopenharmony_ci
45979a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, ProcessCreateMsg_104, testing::ext::TestSize.Level0)
46079a732c7Sopenharmony_ci{
46179a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
46279a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
46379a732c7Sopenharmony_ci    nlohmann::json jsonObject;
46479a732c7Sopenharmony_ci    jsonObject[TAG_PIN_TYPE] = "TAG_PIN_TYPE";
46579a732c7Sopenharmony_ci    std::string message = jsonObject.dump();
46679a732c7Sopenharmony_ci    pinHolder->ProcessCreateMsg(message);
46779a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
46879a732c7Sopenharmony_ci}
46979a732c7Sopenharmony_ci
47079a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, ProcessCreateMsg_105, testing::ext::TestSize.Level0)
47179a732c7Sopenharmony_ci{
47279a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
47379a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
47479a732c7Sopenharmony_ci    nlohmann::json jsonObject;
47579a732c7Sopenharmony_ci    jsonObject[TAG_PIN_TYPE] = DmPinType::SUPER_SONIC;
47679a732c7Sopenharmony_ci    jsonObject[TAG_PAYLOAD] = DmPinType::SUPER_SONIC;
47779a732c7Sopenharmony_ci    std::string message = jsonObject.dump();
47879a732c7Sopenharmony_ci    pinHolder->ProcessCreateMsg(message);
47979a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
48079a732c7Sopenharmony_ci}
48179a732c7Sopenharmony_ci
48279a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, ProcessCreateRespMsg_101, testing::ext::TestSize.Level0)
48379a732c7Sopenharmony_ci{
48479a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
48579a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
48679a732c7Sopenharmony_ci    nlohmann::json jsonObject;
48779a732c7Sopenharmony_ci    std::string message = jsonObject.dump();
48879a732c7Sopenharmony_ci    pinHolder->ProcessCreateRespMsg(message);
48979a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
49079a732c7Sopenharmony_ci}
49179a732c7Sopenharmony_ci
49279a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, ProcessCreateRespMsg_102, testing::ext::TestSize.Level0)
49379a732c7Sopenharmony_ci{
49479a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
49579a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
49679a732c7Sopenharmony_ci    nlohmann::json jsonObject;
49779a732c7Sopenharmony_ci    jsonObject[TAG_REPLY] = DmPinType::NUMBER_PIN_CODE;
49879a732c7Sopenharmony_ci    std::string message = jsonObject.dump();
49979a732c7Sopenharmony_ci    pinHolder->listener_ = nullptr;
50079a732c7Sopenharmony_ci    pinHolder->ProcessCreateRespMsg(message);
50179a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
50279a732c7Sopenharmony_ci}
50379a732c7Sopenharmony_ci
50479a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, ProcessCreateRespMsg_103, testing::ext::TestSize.Level0)
50579a732c7Sopenharmony_ci{
50679a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
50779a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
50879a732c7Sopenharmony_ci    nlohmann::json jsonObject;
50979a732c7Sopenharmony_ci    jsonObject[TAG_REPLY] = DmPinType::SUPER_SONIC;
51079a732c7Sopenharmony_ci    std::string message = jsonObject.dump();
51179a732c7Sopenharmony_ci    pinHolder->session_ = nullptr;
51279a732c7Sopenharmony_ci    pinHolder->ProcessCreateRespMsg(message);
51379a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
51479a732c7Sopenharmony_ci}
51579a732c7Sopenharmony_ci
51679a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, ProcessCreateRespMsg_104, testing::ext::TestSize.Level0)
51779a732c7Sopenharmony_ci{
51879a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
51979a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
52079a732c7Sopenharmony_ci    nlohmann::json jsonObject;
52179a732c7Sopenharmony_ci    jsonObject[TAG_REPLY] = DmPinType::NUMBER_PIN_CODE;
52279a732c7Sopenharmony_ci    std::string message = jsonObject.dump();
52379a732c7Sopenharmony_ci    pinHolder->session_ = nullptr;
52479a732c7Sopenharmony_ci    pinHolder->ProcessCreateRespMsg(message);
52579a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
52679a732c7Sopenharmony_ci}
52779a732c7Sopenharmony_ci
52879a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, ProcessDestroyMsg_101, testing::ext::TestSize.Level0)
52979a732c7Sopenharmony_ci{
53079a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
53179a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
53279a732c7Sopenharmony_ci    std::string message;
53379a732c7Sopenharmony_ci    pinHolder->listener_ = nullptr;
53479a732c7Sopenharmony_ci    pinHolder->ProcessDestroyMsg(message);
53579a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
53679a732c7Sopenharmony_ci}
53779a732c7Sopenharmony_ci
53879a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, ProcessDestroyMsg_102, testing::ext::TestSize.Level0)
53979a732c7Sopenharmony_ci{
54079a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
54179a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
54279a732c7Sopenharmony_ci    std::string message;
54379a732c7Sopenharmony_ci    pinHolder->session_ = nullptr;
54479a732c7Sopenharmony_ci    pinHolder->ProcessDestroyMsg(message);
54579a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
54679a732c7Sopenharmony_ci}
54779a732c7Sopenharmony_ci
54879a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, ProcessDestroyMsg_103, testing::ext::TestSize.Level0)
54979a732c7Sopenharmony_ci{
55079a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
55179a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
55279a732c7Sopenharmony_ci    nlohmann::json jsonObject;
55379a732c7Sopenharmony_ci    std::string message = jsonObject.dump();
55479a732c7Sopenharmony_ci    pinHolder->ProcessDestroyMsg(message);
55579a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
55679a732c7Sopenharmony_ci}
55779a732c7Sopenharmony_ci
55879a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, ProcessDestroyMsg_104, testing::ext::TestSize.Level0)
55979a732c7Sopenharmony_ci{
56079a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
56179a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
56279a732c7Sopenharmony_ci    nlohmann::json jsonObject;
56379a732c7Sopenharmony_ci    jsonObject[TAG_PIN_TYPE] = "TAG_PIN_TYPE";
56479a732c7Sopenharmony_ci    std::string message = jsonObject.dump();
56579a732c7Sopenharmony_ci    pinHolder->ProcessDestroyMsg(message);
56679a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
56779a732c7Sopenharmony_ci}
56879a732c7Sopenharmony_ci
56979a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, ProcessDestroyMsg_105, testing::ext::TestSize.Level0)
57079a732c7Sopenharmony_ci{
57179a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
57279a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
57379a732c7Sopenharmony_ci    nlohmann::json jsonObject;
57479a732c7Sopenharmony_ci    jsonObject[TAG_PIN_TYPE] = DmPinType::SUPER_SONIC;
57579a732c7Sopenharmony_ci    jsonObject[TAG_PAYLOAD] = DmPinType::SUPER_SONIC;
57679a732c7Sopenharmony_ci    std::string message = jsonObject.dump();
57779a732c7Sopenharmony_ci    pinHolder->ProcessDestroyMsg(message);
57879a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
57979a732c7Sopenharmony_ci}
58079a732c7Sopenharmony_ci
58179a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, CloseSession_101, testing::ext::TestSize.Level0)
58279a732c7Sopenharmony_ci{
58379a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
58479a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
58579a732c7Sopenharmony_ci    std::string name;
58679a732c7Sopenharmony_ci    pinHolder->session_ = nullptr;
58779a732c7Sopenharmony_ci    pinHolder->CloseSession(name);
58879a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
58979a732c7Sopenharmony_ci}
59079a732c7Sopenharmony_ci
59179a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, OnDataReceived_101, testing::ext::TestSize.Level0)
59279a732c7Sopenharmony_ci{
59379a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
59479a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
59579a732c7Sopenharmony_ci    int32_t sessionId = 1;
59679a732c7Sopenharmony_ci    nlohmann::json jsonObject;
59779a732c7Sopenharmony_ci    jsonObject[TAG_MSG_TYPE] = MSG_TYPE_CREATE_PIN_HOLDER;
59879a732c7Sopenharmony_ci    std::string message = jsonObject.dump();
59979a732c7Sopenharmony_ci    pinHolder->OnDataReceived(sessionId, message);
60079a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
60179a732c7Sopenharmony_ci}
60279a732c7Sopenharmony_ci
60379a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, OnDataReceived_102, testing::ext::TestSize.Level0)
60479a732c7Sopenharmony_ci{
60579a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
60679a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
60779a732c7Sopenharmony_ci    int32_t sessionId = 1;
60879a732c7Sopenharmony_ci    nlohmann::json jsonObject;
60979a732c7Sopenharmony_ci    jsonObject[TAG_MSG_TYPE] = MSG_TYPE_CREATE_PIN_HOLDER_RESP;
61079a732c7Sopenharmony_ci    std::string message = jsonObject.dump();
61179a732c7Sopenharmony_ci    pinHolder->OnDataReceived(sessionId, message);
61279a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
61379a732c7Sopenharmony_ci}
61479a732c7Sopenharmony_ci
61579a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, OnDataReceived_103, testing::ext::TestSize.Level0)
61679a732c7Sopenharmony_ci{
61779a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
61879a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
61979a732c7Sopenharmony_ci    int32_t sessionId = 1;
62079a732c7Sopenharmony_ci    nlohmann::json jsonObject;
62179a732c7Sopenharmony_ci    jsonObject[TAG_MSG_TYPE] = MSG_TYPE_DESTROY_PIN_HOLDER;
62279a732c7Sopenharmony_ci    std::string message = jsonObject.dump();
62379a732c7Sopenharmony_ci    pinHolder->OnDataReceived(sessionId, message);
62479a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
62579a732c7Sopenharmony_ci}
62679a732c7Sopenharmony_ci
62779a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, OnDataReceived_104, testing::ext::TestSize.Level0)
62879a732c7Sopenharmony_ci{
62979a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
63079a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
63179a732c7Sopenharmony_ci    int32_t sessionId = 1;
63279a732c7Sopenharmony_ci    nlohmann::json jsonObject;
63379a732c7Sopenharmony_ci    jsonObject[TAG_MSG_TYPE] = MSG_TYPE_DESTROY_PIN_HOLDER_RESP;
63479a732c7Sopenharmony_ci    std::string message = jsonObject.dump();
63579a732c7Sopenharmony_ci    pinHolder->OnDataReceived(sessionId, message);
63679a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
63779a732c7Sopenharmony_ci}
63879a732c7Sopenharmony_ci
63979a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, OnDataReceived_105, testing::ext::TestSize.Level0)
64079a732c7Sopenharmony_ci{
64179a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
64279a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
64379a732c7Sopenharmony_ci    int32_t sessionId = 1;
64479a732c7Sopenharmony_ci    int32_t data = 300;
64579a732c7Sopenharmony_ci    nlohmann::json jsonObject;
64679a732c7Sopenharmony_ci    jsonObject[TAG_MSG_TYPE] = data;
64779a732c7Sopenharmony_ci    std::string message = jsonObject.dump();
64879a732c7Sopenharmony_ci    pinHolder->OnDataReceived(sessionId, message);
64979a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
65079a732c7Sopenharmony_ci}
65179a732c7Sopenharmony_ci
65279a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, GetPeerDeviceId_101, testing::ext::TestSize.Level0)
65379a732c7Sopenharmony_ci{
65479a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
65579a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
65679a732c7Sopenharmony_ci    int32_t sessionId = 1;
65779a732c7Sopenharmony_ci    std::string udidHash;
65879a732c7Sopenharmony_ci    pinHolder->GetPeerDeviceId(sessionId, udidHash);
65979a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
66079a732c7Sopenharmony_ci}
66179a732c7Sopenharmony_ci
66279a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, OnSessionOpened_101, testing::ext::TestSize.Level0)
66379a732c7Sopenharmony_ci{
66479a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
66579a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
66679a732c7Sopenharmony_ci    int32_t sessionId = 1;
66779a732c7Sopenharmony_ci    int32_t sessionSide = 0;
66879a732c7Sopenharmony_ci    int32_t result = 0;
66979a732c7Sopenharmony_ci    pinHolder->OnSessionOpened(sessionId, sessionSide, result);
67079a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
67179a732c7Sopenharmony_ci}
67279a732c7Sopenharmony_ci
67379a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, OnSessionOpened_102, testing::ext::TestSize.Level0)
67479a732c7Sopenharmony_ci{
67579a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
67679a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
67779a732c7Sopenharmony_ci    int32_t sessionId = 1;
67879a732c7Sopenharmony_ci    int32_t sessionSide = 1;
67979a732c7Sopenharmony_ci    int32_t result = 1;
68079a732c7Sopenharmony_ci    pinHolder ->listener_ = nullptr;
68179a732c7Sopenharmony_ci    pinHolder->OnSessionOpened(sessionId, sessionSide, result);
68279a732c7Sopenharmony_ci    ASSERT_NE(pinHolder->timer_, nullptr);
68379a732c7Sopenharmony_ci}
68479a732c7Sopenharmony_ci
68579a732c7Sopenharmony_ci
68679a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, CheckTargetIdVaild_101, testing::ext::TestSize.Level0)
68779a732c7Sopenharmony_ci{
68879a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
68979a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
69079a732c7Sopenharmony_ci    PeerTargetId targetId = {
69179a732c7Sopenharmony_ci        .deviceId = "",
69279a732c7Sopenharmony_ci        .brMac = "",
69379a732c7Sopenharmony_ci        .bleMac = "",
69479a732c7Sopenharmony_ci        .wifiIp = "",
69579a732c7Sopenharmony_ci    };
69679a732c7Sopenharmony_ci    int32_t ret = pinHolder->CheckTargetIdVaild(targetId);
69779a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
69879a732c7Sopenharmony_ci}
69979a732c7Sopenharmony_ci
70079a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, CheckTargetIdVaild_102, testing::ext::TestSize.Level0)
70179a732c7Sopenharmony_ci{
70279a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
70379a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
70479a732c7Sopenharmony_ci    PeerTargetId targetId = {
70579a732c7Sopenharmony_ci        .deviceId = "deviceId",
70679a732c7Sopenharmony_ci        .brMac = "brMac",
70779a732c7Sopenharmony_ci        .bleMac = "bleMac",
70879a732c7Sopenharmony_ci        .wifiIp = "wifiIp",
70979a732c7Sopenharmony_ci    };
71079a732c7Sopenharmony_ci    int32_t ret = pinHolder->CheckTargetIdVaild(targetId);
71179a732c7Sopenharmony_ci    ASSERT_EQ(ret, DM_OK);
71279a732c7Sopenharmony_ci}
71379a732c7Sopenharmony_ci
71479a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, NotifyPinHolderEvent_101, testing::ext::TestSize.Level0)
71579a732c7Sopenharmony_ci{
71679a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
71779a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
71879a732c7Sopenharmony_ci    std::string packName = "com.ohos.dmtest";
71979a732c7Sopenharmony_ci    std::string event = "event";
72079a732c7Sopenharmony_ci    int32_t ret = pinHolder->NotifyPinHolderEvent(packName, event);
72179a732c7Sopenharmony_ci    ASSERT_EQ(ret, ERR_DM_FAILED);
72279a732c7Sopenharmony_ci}
72379a732c7Sopenharmony_ci
72479a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, OpenSessionServer_101, testing::ext::TestSize.Level0)
72579a732c7Sopenharmony_ci{
72679a732c7Sopenharmony_ci    std::shared_ptr<PinHolderSession> pinHolderSession = std::make_shared<PinHolderSession>();
72779a732c7Sopenharmony_ci    PeerTargetId targetId = {
72879a732c7Sopenharmony_ci        .deviceId = "deviceId",
72979a732c7Sopenharmony_ci        .brMac = "brMac",
73079a732c7Sopenharmony_ci        .bleMac = "bleMac",
73179a732c7Sopenharmony_ci        .wifiIp = "wifiIp",
73279a732c7Sopenharmony_ci    };
73379a732c7Sopenharmony_ci    int32_t ret = pinHolderSession->OpenSessionServer(targetId);
73479a732c7Sopenharmony_ci    EXPECT_NE(ret, -1);
73579a732c7Sopenharmony_ci}
73679a732c7Sopenharmony_ci
73779a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, CloseSessionServer_101, testing::ext::TestSize.Level0)
73879a732c7Sopenharmony_ci{
73979a732c7Sopenharmony_ci    std::shared_ptr<PinHolderSession> pinHolderSession = std::make_shared<PinHolderSession>();
74079a732c7Sopenharmony_ci    int32_t sessionId = 1;
74179a732c7Sopenharmony_ci    int32_t ret = pinHolderSession->CloseSessionServer(sessionId);
74279a732c7Sopenharmony_ci    EXPECT_EQ(ret, DM_OK);
74379a732c7Sopenharmony_ci}
74479a732c7Sopenharmony_ci
74579a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, OnSessionOpened_103, testing::ext::TestSize.Level0)
74679a732c7Sopenharmony_ci{
74779a732c7Sopenharmony_ci    std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<IDeviceManagerServiceListenerTest>();
74879a732c7Sopenharmony_ci    std::shared_ptr<PinHolder> pinHolder = std::make_shared<PinHolder>(listener);
74979a732c7Sopenharmony_ci    std::shared_ptr<PinHolderSession> pinHolderSession = std::make_shared<PinHolderSession>();
75079a732c7Sopenharmony_ci    pinHolderSession->RegisterSessionCallback(pinHolder);
75179a732c7Sopenharmony_ci    int sessionId = 1;
75279a732c7Sopenharmony_ci    int result = 1;
75379a732c7Sopenharmony_ci    int ret = pinHolderSession->OnSessionOpened(sessionId, result);
75479a732c7Sopenharmony_ci    int closeSessionId = 2;
75579a732c7Sopenharmony_ci    pinHolderSession->OnSessionClosed(closeSessionId);
75679a732c7Sopenharmony_ci    EXPECT_EQ(ret, DM_OK);
75779a732c7Sopenharmony_ci}
75879a732c7Sopenharmony_ci
75979a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, SendData_101, testing::ext::TestSize.Level0)
76079a732c7Sopenharmony_ci{
76179a732c7Sopenharmony_ci    std::shared_ptr<PinHolderSession> pinHolderSession = std::make_shared<PinHolderSession>();
76279a732c7Sopenharmony_ci    int32_t sessionId = 6;
76379a732c7Sopenharmony_ci    std::string message = "123456";
76479a732c7Sopenharmony_ci    int32_t ret = pinHolderSession->SendData(sessionId, message);
76579a732c7Sopenharmony_ci    EXPECT_EQ(ret, ERR_DM_FAILED);
76679a732c7Sopenharmony_ci}
76779a732c7Sopenharmony_ci
76879a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, SendData_102, testing::ext::TestSize.Level0)
76979a732c7Sopenharmony_ci{
77079a732c7Sopenharmony_ci    std::shared_ptr<PinHolderSession> pinHolderSession = std::make_shared<PinHolderSession>();
77179a732c7Sopenharmony_ci    int32_t sessionId = 6;
77279a732c7Sopenharmony_ci    std::string message = R"(
77379a732c7Sopenharmony_ci    {
77479a732c7Sopenharmony_ci        "MSG_TYPE" : "789"
77579a732c7Sopenharmony_ci    }
77679a732c7Sopenharmony_ci    )";
77779a732c7Sopenharmony_ci    int32_t ret = pinHolderSession->SendData(sessionId, message);
77879a732c7Sopenharmony_ci    EXPECT_EQ(ret, ERR_DM_FAILED);
77979a732c7Sopenharmony_ci}
78079a732c7Sopenharmony_ci
78179a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, SendData_103, testing::ext::TestSize.Level0)
78279a732c7Sopenharmony_ci{
78379a732c7Sopenharmony_ci    std::shared_ptr<PinHolderSession> pinHolderSession = std::make_shared<PinHolderSession>();
78479a732c7Sopenharmony_ci    int32_t sessionId = 6;
78579a732c7Sopenharmony_ci    std::string message = R"(
78679a732c7Sopenharmony_ci    {
78779a732c7Sopenharmony_ci        "MSG_TYPE" : 100
78879a732c7Sopenharmony_ci    }
78979a732c7Sopenharmony_ci    )";
79079a732c7Sopenharmony_ci    int32_t ret = pinHolderSession->SendData(sessionId, message);
79179a732c7Sopenharmony_ci    EXPECT_NE(ret, DM_OK);
79279a732c7Sopenharmony_ci}
79379a732c7Sopenharmony_ci
79479a732c7Sopenharmony_ciHWTEST_F(DmPinHolderTest, GetAddrByTargetId_101, testing::ext::TestSize.Level0)
79579a732c7Sopenharmony_ci{
79679a732c7Sopenharmony_ci    std::shared_ptr<PinHolderSession> pinHolderSession = std::make_shared<PinHolderSession>();
79779a732c7Sopenharmony_ci    PeerTargetId targetId = {
79879a732c7Sopenharmony_ci        .deviceId = "deviceIdTest",
79979a732c7Sopenharmony_ci        .brMac = "brMacTest",
80079a732c7Sopenharmony_ci        .bleMac = "bleMacTest",
80179a732c7Sopenharmony_ci        .wifiIp = "wifiIpTest",
80279a732c7Sopenharmony_ci        .wifiPort = 369,
80379a732c7Sopenharmony_ci    };
80479a732c7Sopenharmony_ci    ConnectionAddr addr;
80579a732c7Sopenharmony_ci    int32_t ret = pinHolderSession->GetAddrByTargetId(targetId, addr);
80679a732c7Sopenharmony_ci    EXPECT_EQ(ret, DM_OK);
80779a732c7Sopenharmony_ci}
80879a732c7Sopenharmony_ci} // namespace
80979a732c7Sopenharmony_ci} // namespace DistributedHardware
81079a732c7Sopenharmony_ci} // namespace OHOS