1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "UTTest_pin_auth_ui.h"
17 
18 #include <unistd.h>
19 #include <memory>
20 
21 #include "dm_ability_manager.h"
22 #include "dm_constants.h"
23 #include "dm_log.h"
24 #include "nlohmann/json.hpp"
25 #include "device_manager_service_listener.h"
26 
27 namespace OHOS {
28 namespace DistributedHardware {
SetUp()29 void PinAuthUiTest::SetUp()
30 {
31 }
32 
TearDown()33 void PinAuthUiTest::TearDown()
34 {
35 }
36 
SetUpTestCase()37 void PinAuthUiTest::SetUpTestCase()
38 {
39 }
40 
TearDownTestCase()41 void PinAuthUiTest::TearDownTestCase()
42 {
43 }
44 
45 namespace {
46 std::shared_ptr<DeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>();
47 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
48 std::shared_ptr<HiChainConnector> hiChainConnector = std::make_shared<HiChainConnector>();
49 std::shared_ptr<HiChainAuthConnector> hiChainAuthConnector = std::make_shared<HiChainAuthConnector>();
50 std::shared_ptr<DmAuthManager> authManager =
51     std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector);
52 /**
53  * @tc.name: PinAuthUi::ShowPinDialog_001
54  * @tc.desc: Call ShowPinDialog to check whether the return value is ERR_DM_POINT_NULL
55  * @tc.type: FUNC
56  * @tc.require: AR000GHSJK
57  */
58 HWTEST_F(PinAuthUiTest, ShowPinDialog_001, testing::ext::TestSize.Level0)
59 {
60     std::shared_ptr<PinAuthUi> pinAuthUi = std::make_shared<PinAuthUi>();
61     int32_t code = 123456;
62     int32_t ret = pinAuthUi->ShowPinDialog(code, nullptr);
63     ASSERT_EQ(ret, ERR_DM_FAILED);
64 }
65 
66 /**
67  * @tc.name: PinAuthUi::ShowPinDialog_002
68  * @tc.desc: Call ShowPinDialog to check whether the return value is DM_OK
69  * @tc.type: FUNC
70  * @tc.require: AR000GHSJK
71  */
72 HWTEST_F(PinAuthUiTest, ShowPinDialog_002, testing::ext::TestSize.Level0)
73 {
74     std::shared_ptr<PinAuthUi> pinAuthUi = std::make_shared<PinAuthUi>();
75     int32_t code = 123456;
76     int32_t ret = pinAuthUi->ShowPinDialog(code, authManager);
77     ASSERT_EQ(ret, ERR_DM_FAILED);
78 }
79 
80 /**
81  * @tc.name: PinAuthUi::ShowPinDialog_001
82  * @tc.desc: Call InputPinDialog to check whether the return value is ERR_DM_POINT_NULL
83  * @tc.type: FUNC
84  * @tc.require: AR000GHSJK
85  */
86 HWTEST_F(PinAuthUiTest, InputPinDialog_001, testing::ext::TestSize.Level0)
87 {
88     std::shared_ptr<PinAuthUi> pinAuthUi = std::make_shared<PinAuthUi>();
89     int32_t ret = pinAuthUi->InputPinDialog(nullptr);
90     ASSERT_EQ(ret, ERR_DM_FAILED);
91 }
92 
93 /**
94  * @tc.name: PinAuthUi::ShowPinDialog_001
95  * @tc.desc: Call InputPinDialog to check whether the return value is DM_OK
96  * @tc.type: FUNC
97  * @tc.require: AR000GHSJK
98  */
99 HWTEST_F(PinAuthUiTest, InputPinDialog_002, testing::ext::TestSize.Level0)
100 {
101     std::shared_ptr<PinAuthUi> pinAuthUi = std::make_shared<PinAuthUi>();
102     int32_t ret = pinAuthUi->InputPinDialog(authManager);
103     ASSERT_EQ(ret, ERR_DM_FAILED);
104 }
105 }
106 } // namespace DistributedHardware
107 } // namespace OHOS
108