• 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::UserIam::UserAuth;
30 using namespace OHOS::UserIam::Common;
31 
32 namespace OHOS {
33 namespace UserIam {
34 namespace PinAuth {
35 using IamResultCode = OHOS::UserIam::UserAuth::ResultCode;
36 class PinAuthExecutorCallbackHdiUnitTest : public testing::Test {
37 public:
38     static void SetUpTestCase();
39     static void TearDownTestCase();
40     void SetUp();
41     void TearDown();
42 };
43 
SetUpTestCase()44 void PinAuthExecutorCallbackHdiUnitTest ::SetUpTestCase()
45 {
46 }
47 
TearDownTestCase()48 void PinAuthExecutorCallbackHdiUnitTest ::TearDownTestCase()
49 {
50 }
51 
SetUp()52 void PinAuthExecutorCallbackHdiUnitTest ::SetUp()
53 {
54 }
55 
TearDown()56 void PinAuthExecutorCallbackHdiUnitTest ::TearDown()
57 {
58 }
59 
60 HWTEST_F(PinAuthExecutorCallbackHdiUnitTest, PinAuthExecutorCallback_OnResult_001, TestSize.Level0)
61 {
62     static const std::map<ResultCode, IamResultCode> data = {{SUCCESS, IamResultCode::SUCCESS},
63         {FAIL, IamResultCode::FAIL}, {GENERAL_ERROR, IamResultCode::GENERAL_ERROR},
64         {CANCELED, IamResultCode::CANCELED}, {TIMEOUT, IamResultCode::TIMEOUT},
65         {BUSY, IamResultCode::BUSY},
66         {INVALID_PARAMETERS, IamResultCode::INVALID_PARAMETERS},
67         {LOCKED, IamResultCode::LOCKED}};
68 
69     for (const auto &pair : data) {
70         auto executeCallback = MakeShared<UserIam::UserAuth::MockIExecuteCallback>();
71         ASSERT_TRUE(executeCallback != nullptr);
72         std::vector<uint8_t> testExtraInfo = {1, 2, 3, 4, 5, 6};
73         EXPECT_CALL(*executeCallback, OnResult(_, _))
74             .Times(Exactly(1))
__anon6217f3e80102(int32_t result, const std::vector<uint8_t> &extraInfo) 75             .WillOnce([&pair, &testExtraInfo](int32_t result, const std::vector<uint8_t> &extraInfo) {
76                 EXPECT_TRUE(result == pair.second);
77                 EXPECT_TRUE(testExtraInfo.size() == extraInfo.size());
78                 EXPECT_TRUE(std::equal(extraInfo.begin(), extraInfo.end(), testExtraInfo.begin()));
79             });
80         std::shared_ptr<PinAuthExecutorHdi> pinAuthExecutorHdi = MakeShared<PinAuthExecutorHdi>(nullptr);
81         const uint32_t tokenId = 123;
82         PinAuthExecutorCallbackHdi callbackHdi(executeCallback, pinAuthExecutorHdi, tokenId);
83         callbackHdi.OnResult(pair.first, testExtraInfo);
84     }
85 }
86 } // namespace PinAuth
87 } // namespace UserIam
88 } // namespace OHOS
89