• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_stub_test.h"
17 
18 #include "message_parcel.h"
19 
20 #include "iam_common_defines.h"
21 #include "mock_inputer_set_data.h"
22 #include "mock_inputer_get_data_service.h"
23 
24 namespace OHOS {
25 namespace UserIam {
26 namespace PinAuth {
27 using namespace testing;
28 using namespace testing::ext;
29 
SetUpTestCase()30 void InputerGetDataStubTest::SetUpTestCase()
31 {
32 }
33 
TearDownTestCase()34 void InputerGetDataStubTest::TearDownTestCase()
35 {
36 }
37 
SetUp()38 void InputerGetDataStubTest::SetUp()
39 {
40 }
41 
TearDown()42 void InputerGetDataStubTest::TearDown()
43 {
44 }
45 
46 HWTEST_F(InputerGetDataStubTest, InputerGetDataStubTestOnGetData001, TestSize.Level0)
47 {
48     int32_t testAuthSubType = 10000;
49     std::vector<uint8_t> testSalt = {1, 2, 3, 4, 5};
50 
51     MockInputerGetDataService service;
52     EXPECT_CALL(service, OnGetData(_, _, _)).Times(1);
53     ON_CALL(service, OnGetData)
54         .WillByDefault(
55             [&testAuthSubType](int32_t authSubType, const std::vector<uint8_t> &salt,
__anoneb98dc620102(int32_t authSubType, const std::vector<uint8_t> &salt, const sptr<InputerSetData> &inputerSetData) 56                 const sptr<InputerSetData> &inputerSetData) {
57                     EXPECT_EQ(authSubType, testAuthSubType);
58                     EXPECT_THAT(salt, ElementsAre(1, 2, 3, 4, 5));
59                     if (inputerSetData != nullptr) {
60                         inputerSetData->OnSetData(authSubType, salt);
61                     }
62             }
63         );
64     MockInputerSetData *tempInputerSetData = new MockInputerSetData();
65     EXPECT_NE(tempInputerSetData, nullptr);
66     sptr<InputerSetData> testInputerSetData = static_cast<InputerSetData *>(tempInputerSetData);
67     EXPECT_CALL(*tempInputerSetData, OnSetData(_, _)).Times(1);
68 
69     MessageParcel data;
70     MessageParcel reply;
71 
72     EXPECT_TRUE(data.WriteInterfaceToken(InputerGetData::GetDescriptor()));
73     EXPECT_TRUE(data.WriteInt32(testAuthSubType));
74     EXPECT_TRUE(data.WriteUInt8Vector(testSalt));
75     EXPECT_NE(testInputerSetData->AsObject(), nullptr);
76     EXPECT_TRUE(data.WriteRemoteObject(testInputerSetData->AsObject()));
77     uint32_t code = InputerGetData::ON_GET_DATA;
78     MessageOption option(MessageOption::TF_SYNC);
79 
80     EXPECT_EQ(service.OnRemoteRequest(code, data, reply, option), UserAuth::SUCCESS);
81 }
82 
83 HWTEST_F(InputerGetDataStubTest, InputerGetDataStubTestOnGetData002, TestSize.Level0)
84 {
85     int32_t testAuthSubType = 10000;
86     std::vector<uint8_t> testSalt = {1, 2, 3, 4, 5};
87 
88     MockInputerGetDataService service;
89 
90     sptr<InputerSetData> testInputerSetData = new MockInputerSetData();
91     EXPECT_NE(testInputerSetData, nullptr);
92 
93     MessageParcel data;
94     MessageParcel reply;
95 
96     EXPECT_TRUE(data.WriteInt32(testAuthSubType));
97     EXPECT_TRUE(data.WriteUInt8Vector(testSalt));
98     EXPECT_NE(testInputerSetData->AsObject(), nullptr);
99     EXPECT_TRUE(data.WriteRemoteObject(testInputerSetData->AsObject()));
100     uint32_t code = InputerGetData::ON_GET_DATA;
101     MessageOption option(MessageOption::TF_SYNC);
102 
103     EXPECT_EQ(service.OnRemoteRequest(code, data, reply, option), UserAuth::GENERAL_ERROR);
104 }
105 } // namespace PinAuth
106 } // namespace UserIam
107 } // namespace OHOS
108