1 /*
2 * Copyright (c) 2022-2024 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 "services_pin_auth_manager_test.h"
17
18 #include <openssl/sha.h>
19
20 #include "iam_ptr.h"
21 #include "pin_auth_manager.h"
22 #include "mock_iall_in_one_executor.h"
23 #include "mock_icollector_executor.h"
24 #include "mock_inputer_get_data.h"
25 #include "mock_inputer_set_data.h"
26
27 namespace OHOS {
28 namespace UserIam {
29 namespace PinAuth {
30 using namespace testing;
31 using namespace testing::ext;
32
SetUpTestCase()33 void ServicesPinAuthManagerTest::SetUpTestCase()
34 {
35 }
36
TearDownTestCase()37 void ServicesPinAuthManagerTest::TearDownTestCase()
38 {
39 }
40
SetUp()41 void ServicesPinAuthManagerTest::SetUp()
42 {
43 }
44
TearDown()45 void ServicesPinAuthManagerTest::TearDown()
46 {
47 }
48
49 HWTEST_F(ServicesPinAuthManagerTest, ServicesPinAuthManagerTest001, TestSize.Level0)
50 {
51 uint32_t tokenId = 1;
52 sptr<InputerGetData> inputer(nullptr);
53 EXPECT_NO_THROW(PinAuthManager::GetInstance().RegisterInputer(tokenId, inputer));
54 }
55
56 HWTEST_F(ServicesPinAuthManagerTest, GetInputerLockTest001, TestSize.Level0)
57 {
58 uint32_t tokenId = 1;
59 sptr<InputerGetData> inputer(new (std::nothrow) MockInputerGetData());
60 PinAuthManager::GetInstance().RegisterInputer(tokenId, inputer);
61 EXPECT_NE(PinAuthManager::GetInstance().GetInputerLock(tokenId), nullptr);
62 PinAuthManager::GetInstance().UnRegisterInputer(tokenId);
63 }
64
65 HWTEST_F(ServicesPinAuthManagerTest, OnRemoteDiedTest001, TestSize.Level0)
66 {
67 uint32_t tokenId = 1;
68 sptr<InputerGetData> inputer(new (std::nothrow) MockInputerGetData());
69 PinAuthManager::GetInstance().RegisterInputer(tokenId, inputer);
70 EXPECT_NO_THROW(PinAuthManager::GetInstance().pinAuthDeathMap_[tokenId]->OnRemoteDied(nullptr));
71 }
72
73 HWTEST_F(ServicesPinAuthManagerTest, OnRemoteDiedTest002, TestSize.Level0)
74 {
75 uint32_t tokenId = 1;
76 sptr<InputerGetData> inputer(new (std::nothrow) MockInputerGetData());
77 PinAuthManager::GetInstance().RegisterInputer(tokenId, inputer);
78 EXPECT_NO_THROW(PinAuthManager::GetInstance().pinAuthDeathMap_[tokenId]->OnRemoteDied(inputer));
79 }
80 } // namespace PinAuth
81 } // namespace UserIam
82 } // namespace OHOS
83