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 "inputer_get_data_service_test.h"
17 
18 #include "iam_ptr.h"
19 #include "inputer_get_data_service.h"
20 #include "mock_inputer.h"
21 #include "mock_inputer_set_data.h"
22 
23 namespace OHOS {
24 namespace UserIam {
25 namespace PinAuth {
26 using namespace testing;
27 using namespace testing::ext;
28 
SetUpTestCase()29 void InputerGetDataServiceTest::SetUpTestCase()
30 {
31 }
32 
TearDownTestCase()33 void InputerGetDataServiceTest::TearDownTestCase()
34 {
35 }
36 
SetUp()37 void InputerGetDataServiceTest::SetUp()
38 {
39 }
40 
TearDown()41 void InputerGetDataServiceTest::TearDown()
42 {
43 }
44 
45 HWTEST_F(InputerGetDataServiceTest, InputerGetDataServiceTest001, TestSize.Level0)
46 {
47     int32_t testAuthSubType = 10000;
48     std::vector<uint8_t> testSalt = {1, 2, 3, 4, 5};
49     uint32_t testAlgoVersion = 0;
50     GetDataMode testMode = GET_DATA_MODE_ALL_IN_ONE_PIN_AUTH;
51     sptr<InputerSetData> testInputerSetData(new (std::nothrow) MockInputerSetData());
52     EXPECT_NE(testInputerSetData, nullptr);
53 
54     auto testInputer = Common::MakeShared<MockInputer>();
55     EXPECT_NE(testInputer, nullptr);
56 
57     EXPECT_CALL(*testInputer, OnGetData(_, _, _))
58         .Times(Exactly(1))
59         .WillOnce([&testAuthSubType](
__anon8b766c2b0102( int32_t authSubType, std::vector<uint8_t> challenge, std::shared_ptr<IInputerData> inputerData) 60             int32_t authSubType, std::vector<uint8_t> challenge, std::shared_ptr<IInputerData> inputerData) {
61             EXPECT_EQ(authSubType, testAuthSubType);
62             EXPECT_EQ(challenge.empty(), true);
63             return;
64         });
65 
66     auto service = Common::MakeShared<InputerGetDataService>(testInputer);
67     EXPECT_NE(service, nullptr);
68 
69     InputerGetDataParam getDataParam = {
70         .mode = testMode,
71         .authSubType = testAuthSubType,
72         .algoVersion = testAlgoVersion,
73         .algoParameter = testSalt,
74         .challenge = {},
75         .inputerSetData = testInputerSetData,
76     };
77     service->OnGetData(getDataParam);
78 }
79 
80 HWTEST_F(InputerGetDataServiceTest, InputerGetDataServiceTest002, TestSize.Level0)
81 {
82     int32_t testAuthSubType = 10000;
83     std::vector<uint8_t> testSalt = {1, 2, 3, 4, 5};
84     uint32_t testAlgoVersion = 0;
85     GetDataMode testMode = GET_DATA_MODE_ALL_IN_ONE_PIN_AUTH;
86 
87     auto testInputer = Common::MakeShared<MockInputer>();
88     EXPECT_NE(testInputer, nullptr);
89 
90     auto service = Common::MakeShared<InputerGetDataService>(testInputer);
91     EXPECT_NE(service, nullptr);
92 
93     InputerGetDataParam getDataParam = {
94         .mode = testMode,
95         .authSubType = testAuthSubType,
96         .algoVersion = testAlgoVersion,
97         .algoParameter = testSalt,
98         .challenge = {},
99         .inputerSetData = nullptr,
100     };
101     service->OnGetData(getDataParam);
102 }
103 
104 HWTEST_F(InputerGetDataServiceTest, InputerGetDataServiceTest003, TestSize.Level0)
105 {
106     int32_t testAuthSubType = 10000;
107     std::vector<uint8_t> testSalt = {1, 2, 3, 4, 5};
108     uint32_t testAlgoVersion = 0;
109     GetDataMode testMode = GET_DATA_MODE_ALL_IN_ONE_PIN_AUTH;
110     auto service = Common::MakeShared<InputerGetDataService>(nullptr);
111     EXPECT_NE(service, nullptr);
112     sptr<InputerSetData> testInputerSetData(new (std::nothrow) MockInputerSetData());
113 
114     InputerGetDataParam getDataParam = {
115         .mode = testMode,
116         .authSubType = testAuthSubType,
117         .algoVersion = testAlgoVersion,
118         .algoParameter = testSalt,
119         .challenge = {},
120         .inputerSetData = testInputerSetData,
121     };
122     EXPECT_NO_THROW(service->OnGetData(getDataParam));
123 }
124 } // namespace PinAuth
125 } // namespace UserIam
126 } // namespace OHOS
127