• 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 "pin_auth_stub_test.h"
17 
18 #include "message_parcel.h"
19 
20 #include "iam_common_defines.h"
21 #include "mock_inputer_get_data.h"
22 #include "mock_pin_auth_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 PinAuthStubTest::SetUpTestCase()
31 {
32 }
33 
TearDownTestCase()34 void PinAuthStubTest::TearDownTestCase()
35 {
36 }
37 
SetUp()38 void PinAuthStubTest::SetUp()
39 {
40 }
41 
TearDown()42 void PinAuthStubTest::TearDown()
43 {
44 }
45 
46 HWTEST_F(PinAuthStubTest, PinAuthStubTestRegisterInputer, TestSize.Level0)
47 {
48     MockPinAuthService service;
49     MockInputerGetData *tempInputerGetData = new MockInputerGetData();
50     EXPECT_NE(tempInputerGetData, nullptr);
51     sptr<InputerGetData> testInputerGetData = static_cast<InputerGetData *>(tempInputerGetData);
52     EXPECT_NE(testInputerGetData, nullptr);
53     EXPECT_CALL(service, RegisterInputer(_)).Times(1);
54     ON_CALL(service, RegisterInputer)
55         .WillByDefault(
__anon62d38fba0102(const sptr<InputerGetData> &inputer) 56             [](const sptr<InputerGetData> &inputer) {
57                 if (inputer != nullptr) {
58                     std::vector<uint8_t> salt = {1, 2, 3, 4};
59                     inputer->OnGetData(10000, salt, nullptr);
60                 }
61                 return true;
62             }
63         );
64     EXPECT_CALL(*tempInputerGetData, OnGetData(_, _, _)).Times(1);
65 
66     MessageParcel data;
67     MessageParcel reply;
68 
69     EXPECT_TRUE(data.WriteInterfaceToken(PinAuthInterface::GetDescriptor()));
70     EXPECT_NE(testInputerGetData->AsObject(), nullptr);
71     EXPECT_TRUE(data.WriteRemoteObject(testInputerGetData->AsObject()));
72     uint32_t code = PinAuthInterface::REGISTER_INPUTER;
73     MessageOption option(MessageOption::TF_SYNC);
74 
75     EXPECT_EQ(service.OnRemoteRequest(code, data, reply, option), UserAuth::SUCCESS);
76     bool result = false;
77     EXPECT_EQ(reply.ReadBool(result), true);
78     EXPECT_EQ(result, true);
79 }
80 
81 HWTEST_F(PinAuthStubTest, PinAuthStubTestUnRegisterInputer001, TestSize.Level0)
82 {
83     MockPinAuthService service;
84     EXPECT_CALL(service, UnRegisterInputer()).Times(1);
85 
86     MessageParcel data;
87     MessageParcel reply;
88 
89     EXPECT_TRUE(data.WriteInterfaceToken(PinAuthInterface::GetDescriptor()));
90     uint32_t code = PinAuthInterface::UNREGISTER_INPUTER;
91     MessageOption option(MessageOption::TF_SYNC);
92 
93     EXPECT_EQ(service.OnRemoteRequest(code, data, reply, option), UserAuth::SUCCESS);
94 }
95 
96 HWTEST_F(PinAuthStubTest, PinAuthStubTestUnRegisterInputer002, TestSize.Level0)
97 {
98     MockPinAuthService service;
99 
100     MessageParcel data;
101     MessageParcel reply;
102 
103     uint32_t code = PinAuthInterface::UNREGISTER_INPUTER;
104     MessageOption option(MessageOption::TF_SYNC);
105 
106     EXPECT_EQ(service.OnRemoteRequest(code, data, reply, option), UserAuth::GENERAL_ERROR);
107 }
108 } // namespace PinAuth
109 } // namespace UserIam
110 } // namespace OHOS
111