1 /*
2 * Copyright (c) 2022-2023 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_set_data_stub_test.h"
17
18 #include "message_parcel.h"
19
20 #include "iam_common_defines.h"
21 #include "mock_inputer_data_impl.h"
22
23 namespace OHOS {
24 namespace UserIam {
25 namespace PinAuth {
26 using namespace testing;
27 using namespace testing::ext;
28
SetUpTestCase()29 void InputerSetDataStubTest::SetUpTestCase()
30 {
31 }
32
TearDownTestCase()33 void InputerSetDataStubTest::TearDownTestCase()
34 {
35 }
36
SetUp()37 void InputerSetDataStubTest::SetUp()
38 {
39 }
40
TearDown()41 void InputerSetDataStubTest::TearDown()
42 {
43 }
44
45 HWTEST_F(InputerSetDataStubTest, InputerSetDataStubTestOnSetData001, TestSize.Level0)
46 {
47 int32_t testAuthSubType = 10000;
48 std::vector<uint8_t> testData = {1, 2, 3, 4, 5};
49 int32_t testErrorCode = 0;
50 uint32_t testPinLength = 0;
51
52 MockInputerDataImpl inputerDataImpl;
53 EXPECT_CALL(inputerDataImpl, OnSetData(_, _, _, _)).Times(1);
54 ON_CALL(inputerDataImpl, OnSetData)
55 .WillByDefault([&testAuthSubType, &testErrorCode, &testPinLength]
__anon3c3ca74e0102(int32_t authSubType, std::vector<uint8_t> data, uint32_t pinLength, int32_t errorCode) 56 (int32_t authSubType, std::vector<uint8_t> data, uint32_t pinLength, int32_t errorCode) {
57 EXPECT_EQ(authSubType, testAuthSubType);
58 EXPECT_THAT(data, ElementsAre(1, 2, 3, 4, 5));
59 EXPECT_EQ(pinLength, testPinLength);
60 EXPECT_EQ(errorCode, testErrorCode);
61 }
62 );
63
64 MessageParcel data;
65 MessageParcel reply;
66
67 EXPECT_TRUE(data.WriteInterfaceToken(InputerSetData::GetDescriptor()));
68 EXPECT_TRUE(data.WriteInt32(testAuthSubType));
69 EXPECT_TRUE(data.WriteUInt8Vector(testData));
70 EXPECT_TRUE(data.WriteUint32(testPinLength));
71 EXPECT_TRUE(data.WriteInt32(testErrorCode));
72 uint32_t code = InputerSetDataInterfaceCode::ON_SET_DATA;
73 MessageOption option(MessageOption::TF_SYNC);
74
75 EXPECT_EQ(inputerDataImpl.OnRemoteRequest(code, data, reply, option), UserAuth::SUCCESS);
76 }
77
78 HWTEST_F(InputerSetDataStubTest, InputerSetDataStubTestOnSetData002, TestSize.Level0)
79 {
80 int32_t testAuthSubType = 10000;
81 std::vector<uint8_t> testData = {1, 2, 3, 4, 5};
82 int32_t testErrorCode = 0;
83
84 MockInputerDataImpl inputerDataImpl;
85
86 MessageParcel data;
87 MessageParcel reply;
88
89 EXPECT_TRUE(data.WriteInt32(testAuthSubType));
90 EXPECT_TRUE(data.WriteUInt8Vector(testData));
91 EXPECT_TRUE(data.WriteInt32(testErrorCode));
92 uint32_t code = InputerSetDataInterfaceCode::ON_SET_DATA;
93 MessageOption option(MessageOption::TF_SYNC);
94
95 EXPECT_EQ(inputerDataImpl.OnRemoteRequest(code, data, reply, option), UserAuth::GENERAL_ERROR);
96 }
97 } // namespace PinAuth
98 } // namespace UserIam
99 } // namespace OHOS
100