• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "gtest/gtest.h"
17 
18 #include "iam_logger.h"
19 #include "iam_ptr.h"
20 
21 #include "pin_auth_executor_callback_hdi.h"
22 #include "iam_common_defines.h"
23 #include "mock_iexecute_callback.h"
24 
25 #define LOG_LABEL UserIam::Common::LABEL_PIN_AUTH_SA
26 
27 using namespace testing;
28 using namespace testing::ext;
29 using namespace OHOS::HDI::PinAuth::V1_0;
30 using namespace OHOS::UserIam::UserAuth;
31 using namespace OHOS::UserIam::Common;
32 
33 namespace OHOS {
34 namespace UserIam {
35 namespace PinAuth {
36 using IamResultCode = OHOS::UserIam::UserAuth::ResultCode;
37 class PinAuthExecutorCallbackHdiUnitTest : public testing::Test {
38 public:
39     static void SetUpTestCase();
40     static void TearDownTestCase();
41     void SetUp();
42     void TearDown();
43 };
44 
SetUpTestCase()45 void PinAuthExecutorCallbackHdiUnitTest ::SetUpTestCase()
46 {
47 }
48 
TearDownTestCase()49 void PinAuthExecutorCallbackHdiUnitTest ::TearDownTestCase()
50 {
51 }
52 
SetUp()53 void PinAuthExecutorCallbackHdiUnitTest ::SetUp()
54 {
55 }
56 
TearDown()57 void PinAuthExecutorCallbackHdiUnitTest ::TearDown()
58 {
59 }
60 
61 HWTEST_F(PinAuthExecutorCallbackHdiUnitTest, PinAuthExecutorCallback_OnResult_001, TestSize.Level0)
62 {
63     static const std::map<ResultCode, IamResultCode> data = {{SUCCESS, IamResultCode::SUCCESS},
64         {FAIL, IamResultCode::FAIL}, {GENERAL_ERROR, IamResultCode::GENERAL_ERROR},
65         {CANCELED, IamResultCode::CANCELED}, {TIMEOUT, IamResultCode::TIMEOUT},
66         {BUSY, IamResultCode::BUSY},
67         {INVALID_PARAMETERS, IamResultCode::INVALID_PARAMETERS},
68         {LOCKED, IamResultCode::LOCKED}};
69 
70     for (const auto &pair : data) {
71         auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
72         ASSERT_TRUE(executeCallback != nullptr);
73         std::vector<uint8_t> testExtraInfo = {1, 2, 3, 4, 5, 6};
74         EXPECT_CALL(*executeCallback, OnResult(_, _))
75             .Times(Exactly(1))
__anona24219ca0102(int32_t result, const std::vector<uint8_t> &extraInfo) 76             .WillOnce([&pair, &testExtraInfo](int32_t result, const std::vector<uint8_t> &extraInfo) {
77                 EXPECT_TRUE(result == pair.second);
78                 EXPECT_TRUE(testExtraInfo.size() == extraInfo.size());
79                 EXPECT_TRUE(std::equal(extraInfo.begin(), extraInfo.end(), testExtraInfo.begin()));
80             });
81         std::shared_ptr<PinAuthExecutorHdi> pinAuthExecutorHdi = MakeShared<PinAuthExecutorHdi>(nullptr);
82         const uint32_t tokenId = 123;
83         PinAuthExecutorCallbackHdi callbackHdi(executeCallback, pinAuthExecutorHdi, tokenId);
84         callbackHdi.OnResult(pair.first, testExtraInfo);
85     }
86 }
87 } // namespace PinAuth
88 } // namespace UserIam
89 } // namespace OHOS
90