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_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](
__anon8cd1e2200102( 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 } // namespace PinAuth
80 } // namespace UserIam
81 } // namespace OHOS
82