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_proxy_test.h"
17
18 #include "iam_common_defines.h"
19 #include "iam_ptr.h"
20 #include "mock_inputer_get_data_service.h"
21 #include "mock_remote_object.h"
22 #include "mock_pin_auth_service.h"
23 #include "pin_auth_proxy.h"
24
25 namespace OHOS {
26 namespace UserIam {
27 namespace PinAuth {
28 using namespace testing;
29 using namespace testing::ext;
30
SetUpTestCase()31 void PinAuthProxyTest::SetUpTestCase()
32 {
33 }
34
TearDownTestCase()35 void PinAuthProxyTest::TearDownTestCase()
36 {
37 }
38
SetUp()39 void PinAuthProxyTest::SetUp()
40 {
41 }
42
TearDown()43 void PinAuthProxyTest::TearDown()
44 {
45 }
46
47 HWTEST_F(PinAuthProxyTest, PinAuthProxyTestRegisterInputer001, TestSize.Level0)
48 {
49 sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
50 EXPECT_NE(obj, nullptr);
51 auto proxy = Common::MakeShared<PinAuthProxy>(obj);
52 EXPECT_NE(proxy, nullptr);
53 sptr<InputerGetData> testInputerGetData(new (std::nothrow) MockInputerGetDataService());
54 EXPECT_NE(testInputerGetData, nullptr);
55
56 auto service = Common::MakeShared<MockPinAuthService>();
57 EXPECT_NE(service, nullptr);
58 EXPECT_CALL(*service, RegisterInputer(_))
59 .Times(Exactly(1))
__anonffeb4b150102(const sptr<InputerGetData> &inputer) 60 .WillOnce([&testInputerGetData](const sptr<InputerGetData> &inputer) {
61 EXPECT_EQ(inputer, testInputerGetData);
62 return true;
63 });
64 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
65 ON_CALL(*obj, SendRequest)
__anonffeb4b150202(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 66 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
67 return service->OnRemoteRequest(code, data, reply, option);
68 });
69 EXPECT_EQ(proxy->RegisterInputer(testInputerGetData), true);
70 }
71
72 HWTEST_F(PinAuthProxyTest, PinAuthProxyTestRegisterInputer002, TestSize.Level0)
73 {
74 sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
75 EXPECT_NE(obj, nullptr);
76 auto proxy = Common::MakeShared<PinAuthProxy>(obj);
77 EXPECT_NE(proxy, nullptr);
78 sptr<InputerGetData> testInputerGetData(nullptr);
79
80 EXPECT_EQ(proxy->RegisterInputer(testInputerGetData), false);
81 }
82
83 HWTEST_F(PinAuthProxyTest, PinAuthProxyTestUnRegisterInputer, TestSize.Level0)
84 {
85 sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
86 EXPECT_NE(obj, nullptr);
87 auto proxy = Common::MakeShared<PinAuthProxy>(obj);
88 EXPECT_NE(proxy, nullptr);
89 sptr<InputerGetData> testInputerGetData(new (std::nothrow) MockInputerGetDataService());
90 EXPECT_NE(testInputerGetData, nullptr);
91
92 auto service = Common::MakeShared<MockPinAuthService>();
93 EXPECT_NE(service, nullptr);
94 EXPECT_CALL(*service, UnRegisterInputer()).Times(1);
95
96 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
97 ON_CALL(*obj, SendRequest)
__anonffeb4b150302(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 98 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
99 return service->OnRemoteRequest(code, data, reply, option);
100 });
101 proxy->UnRegisterInputer();
102 }
103 } // namespace PinAuth
104 } // namespace UserIam
105 } // namespace OHOS
106