• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     MockInputerSetData *tempInputerSetData = new MockInputerSetData();
56     EXPECT_NE(tempInputerSetData, nullptr);
57     sptr<InputerSetData> testInputerSetData = static_cast<InputerSetData *>(tempInputerSetData);
58     EXPECT_NE(testInputerSetData, nullptr);
59 
60     EXPECT_CALL(*tempInputerSetData, OnSetData(_, _))
61         .Times(Exactly(1))
__anon32c672360102(int32_t authSubType, std::vector<uint8_t> data) 62         .WillOnce([&testAuthSubType, &testScrypt](int32_t authSubType, std::vector<uint8_t> data) {
63             EXPECT_EQ(authSubType, testAuthSubType);
64             EXPECT_THAT(data, ElementsAreArray(testScrypt));
65             return;
66         });
67 
68     auto inputerDataImpl = Common::MakeShared<InputerDataImpl>(testSalt, testInputerSetData);
69     EXPECT_NE(inputerDataImpl, nullptr);
70 
71     inputerDataImpl->OnSetData(testAuthSubType, testData);
72 }
73 } // namespace PinAuth
74 } // namespace UserIam
75 } // namespace OHOS
76