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