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 "user_auth_callback_proxy_test.h"
17
18 #include "iam_ptr.h"
19 #include "mock_remote_object.h"
20 #include "user_auth_callback_proxy.h"
21 #include "user_auth_interface.h"
22
23 namespace OHOS {
24 namespace UserIam {
25 namespace UserAuth {
26 using namespace testing;
27 using namespace testing::ext;
28
SetUpTestCase()29 void UserAuthCallbackProxyTest::SetUpTestCase()
30 {
31 }
32
TearDownTestCase()33 void UserAuthCallbackProxyTest::TearDownTestCase()
34 {
35 }
36
SetUp()37 void UserAuthCallbackProxyTest::SetUp()
38 {
39 }
40
TearDown()41 void UserAuthCallbackProxyTest::TearDown()
42 {
43 }
44
45 HWTEST_F(UserAuthCallbackProxyTest, TestOnResult_001, TestSize.Level0)
46 {
47 sptr<MockRemoteObject> obj = new MockRemoteObject();
48 EXPECT_NE(obj, nullptr);
49 EXPECT_CALL(*obj, SendRequest(_, _, _, _))
50 .WillOnce(
__anon65f0616a0102(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 51 [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
52 EXPECT_EQ(code, UserAuthInterface::USER_AUTH_ON_RESULT);
53 return OHOS::NO_ERROR;
54 }
55 );
56
57 auto proxy = Common::MakeShared<UserAuthCallbackProxy>(obj);
58 EXPECT_NE(proxy, nullptr);
59
60 int32_t result = 0;
61 Attributes extraInfo;
62 proxy->OnResult(result, extraInfo);
63 }
64
65 HWTEST_F(UserAuthCallbackProxyTest, TestOnAcquireInfo_001, TestSize.Level0)
66 {
67 sptr<MockRemoteObject> obj = new MockRemoteObject();
68 EXPECT_NE(obj, nullptr);
69 EXPECT_CALL(*obj, SendRequest(_, _, _, _))
70 .WillOnce(
__anon65f0616a0202(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 71 [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
72 EXPECT_EQ(code, UserAuthInterface::USER_AUTH_ACQUIRE_INFO);
73 return OHOS::NO_ERROR;
74 }
75 );
76
77 auto proxy = Common::MakeShared<UserAuthCallbackProxy>(obj);
78 EXPECT_NE(proxy, nullptr);
79
80 int32_t module = 12;
81 int32_t acquireInfo = 20;
82 Attributes extraInfo;
83 proxy->OnAcquireInfo(module, acquireInfo, extraInfo);
84 }
85
86 HWTEST_F(UserAuthCallbackProxyTest, TestOnGetExecutorPropertyResult_001, TestSize.Level0)
87 {
88 sptr<MockRemoteObject> obj = new MockRemoteObject();
89 EXPECT_NE(obj, nullptr);
90 EXPECT_CALL(*obj, SendRequest(_, _, _, _))
91 .WillOnce(
__anon65f0616a0302(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 92 [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
93 EXPECT_EQ(code, UserAuthInterface::USER_AUTH_GET_EX_PROP);
94 return OHOS::NO_ERROR;
95 }
96 );
97
98 auto proxy = Common::MakeShared<GetExecutorPropertyCallbackProxy>(obj);
99 EXPECT_NE(proxy, nullptr);
100
101 int32_t result = 0;
102 Attributes attributes;
103 proxy->OnGetExecutorPropertyResult(result, attributes);
104 }
105
106 HWTEST_F(UserAuthCallbackProxyTest, TestOnSetExecutorPropertyResult_001, TestSize.Level0)
107 {
108 sptr<MockRemoteObject> obj = new MockRemoteObject();
109 EXPECT_NE(obj, nullptr);
110 EXPECT_CALL(*obj, SendRequest(_, _, _, _))
111 .WillOnce(
__anon65f0616a0402(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 112 [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
113 EXPECT_EQ(code, UserAuthInterface::USER_AUTH_SET_EX_PROP);
114 return OHOS::NO_ERROR;
115 }
116 );
117
118 auto proxy = Common::MakeShared<SetExecutorPropertyCallbackProxy>(obj);
119 EXPECT_NE(proxy, nullptr);
120
121 int32_t result = 0;
122 proxy->OnSetExecutorPropertyResult(result);
123 }
124 } // namespace UserAuth
125 } // namespace UserIam
126 } // namespace OHOS
127