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
51 MockInputerDataImpl inputerDataImpl;
52 EXPECT_CALL(inputerDataImpl, OnSetData(_, _, _)).Times(1);
53 ON_CALL(inputerDataImpl, OnSetData)
54 .WillByDefault([&testAuthSubType, &testErrorCode]
__anon7d4fa2e40102(int32_t authSubType, std::vector<uint8_t> data, int32_t errorCode) 55 (int32_t authSubType, std::vector<uint8_t> data, int32_t errorCode) {
56 EXPECT_EQ(authSubType, testAuthSubType);
57 EXPECT_THAT(data, ElementsAre(1, 2, 3, 4, 5));
58 EXPECT_EQ(errorCode, testErrorCode);
59 }
60 );
61
62 MessageParcel data;
63 MessageParcel reply;
64
65 EXPECT_TRUE(data.WriteInterfaceToken(InputerSetData::GetDescriptor()));
66 EXPECT_TRUE(data.WriteInt32(testAuthSubType));
67 EXPECT_TRUE(data.WriteUInt8Vector(testData));
68 EXPECT_TRUE(data.WriteInt32(testErrorCode));
69 uint32_t code = InputerSetDataInterfaceCode::ON_SET_DATA;
70 MessageOption option(MessageOption::TF_SYNC);
71
72 EXPECT_EQ(inputerDataImpl.OnRemoteRequest(code, data, reply, option), UserAuth::SUCCESS);
73 }
74
75 HWTEST_F(InputerSetDataStubTest, InputerSetDataStubTestOnSetData002, TestSize.Level0)
76 {
77 int32_t testAuthSubType = 10000;
78 std::vector<uint8_t> testData = {1, 2, 3, 4, 5};
79 int32_t testErrorCode = 0;
80
81 MockInputerDataImpl inputerDataImpl;
82
83 MessageParcel data;
84 MessageParcel reply;
85
86 EXPECT_TRUE(data.WriteInt32(testAuthSubType));
87 EXPECT_TRUE(data.WriteUInt8Vector(testData));
88 EXPECT_TRUE(data.WriteInt32(testErrorCode));
89 uint32_t code = InputerSetDataInterfaceCode::ON_SET_DATA;
90 MessageOption option(MessageOption::TF_SYNC);
91
92 EXPECT_EQ(inputerDataImpl.OnRemoteRequest(code, data, reply, option), UserAuth::GENERAL_ERROR);
93 }
94 } // namespace PinAuth
95 } // namespace UserIam
96 } // namespace OHOS
97