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 "inputer_data_impl_test.h"
17
18 #include "iam_ptr.h"
19 #include "inputer_data_impl.h"
20 #include "mock_inputer_set_data.h"
21 #include "scrypt.h"
22
23 namespace OHOS {
24 namespace UserIam {
25 namespace PinAuth {
26 using namespace testing;
27 using namespace testing::ext;
28
SetUpTestCase()29 void InputerDataImplTest::SetUpTestCase()
30 {
31 }
32
TearDownTestCase()33 void InputerDataImplTest::TearDownTestCase()
34 {
35 }
36
SetUp()37 void InputerDataImplTest::SetUp()
38 {
39 }
40
TearDown()41 void InputerDataImplTest::TearDown()
42 {
43 }
44
45 HWTEST_F(InputerDataImplTest, InputerDataImplTest001, TestSize.Level0)
46 {
47 int32_t testAuthSubType = 10000;
48 std::vector<uint8_t> testSalt = {1, 2, 3, 4, 5};
49 std::vector<uint8_t> testData = {6, 7, 8, 9};
50
51 auto scryptPtr = Common::MakeUnique<Scrypt>(testSalt);
52 EXPECT_NE(scryptPtr, nullptr);
53 std::vector<uint8_t> testScrypt = scryptPtr->GetScrypt(testData);
54
55 sptr<MockInputerSetData> tempInputerSetData(new (std::nothrow) MockInputerSetData());
56 EXPECT_NE(tempInputerSetData, nullptr);
57
58 EXPECT_CALL(*tempInputerSetData, OnSetData(_, _))
59 .Times(Exactly(1))
__anon982769150102(int32_t authSubType, std::vector<uint8_t> data) 60 .WillOnce([&testAuthSubType, &testScrypt](int32_t authSubType, std::vector<uint8_t> data) {
61 EXPECT_EQ(authSubType, testAuthSubType);
62 EXPECT_THAT(data, ElementsAreArray(testScrypt));
63 return;
64 });
65
66 auto inputerDataImpl = Common::MakeShared<InputerDataImpl>(testSalt, tempInputerSetData);
67 EXPECT_NE(inputerDataImpl, nullptr);
68
69 inputerDataImpl->OnSetData(testAuthSubType, testData);
70 }
71 } // namespace PinAuth
72 } // namespace UserIam
73 } // namespace OHOS
74