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_client_test.h"
17
18 #include "iam_ptr.h"
19 #include "user_auth_client.h"
20 #include "user_auth_client_impl.h"
21 #include "mock_ipc_client_utils.h"
22 #include "mock_remote_object.h"
23 #include "mock_user_auth_service.h"
24 #include "mock_user_auth_client_callback.h"
25
26 namespace OHOS {
27 namespace UserIam {
28 namespace UserAuth {
29 using namespace testing;
30 using namespace testing::ext;
31
SetUpTestCase()32 void UserAuthClientTest::SetUpTestCase()
33 {
34 }
35
TearDownTestCase()36 void UserAuthClientTest::TearDownTestCase()
37 {
38 }
39
SetUp()40 void UserAuthClientTest::SetUp()
41 {
42 }
43
TearDown()44 void UserAuthClientTest::TearDown()
45 {
46 }
47
48 HWTEST_F(UserAuthClientTest, UserAuthClientGetAvailableStatus001, TestSize.Level0)
49 {
50 AuthType testAuthType = FACE;
51 AuthTrustLevel testAtl = ATL1;
52
53 IpcClientUtils::ResetObj();
54 int32_t ret = UserAuthClientImpl::Instance().GetAvailableStatus(testAuthType, testAtl);
55 EXPECT_EQ(ret, GENERAL_ERROR);
56 }
57
58 HWTEST_F(UserAuthClientTest, UserAuthClientGetAvailableStatus002, TestSize.Level0)
59 {
60 int32_t testApiVersion = 9;
61 AuthType testAuthType = FACE;
62 AuthTrustLevel testAtl = ATL1;
63
64 auto service = Common::MakeShared<MockUserAuthService>();
65 EXPECT_NE(service, nullptr);
66 EXPECT_CALL(*service, GetAvailableStatus(_, _, _)).Times(1);
67 ON_CALL(*service, GetAvailableStatus)
68 .WillByDefault(
69 [&testApiVersion, &testAuthType, &testAtl](int32_t apiVersion, AuthType authType,
__anond184869b0102(int32_t apiVersion, AuthType authType, AuthTrustLevel authTrustLevel) 70 AuthTrustLevel authTrustLevel) {
71 EXPECT_EQ(apiVersion, testApiVersion);
72 EXPECT_EQ(authType, testAuthType);
73 EXPECT_EQ(authTrustLevel, testAtl);
74 return SUCCESS;
75 }
76 );
77 sptr<MockRemoteObject> obj = new MockRemoteObject();
78 EXPECT_NE(obj, nullptr);
79 IpcClientUtils::SetObj(obj);
80 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
81 ON_CALL(*obj, SendRequest)
__anond184869b0202(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 82 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
83 service->OnRemoteRequest(code, data, reply, option);
84 return OHOS::NO_ERROR;
85 });
86 int32_t ret = UserAuthClientImpl::Instance().GetAvailableStatus(testApiVersion, testAuthType, testAtl);
87 EXPECT_EQ(ret, SUCCESS);
88 IpcClientUtils::ResetObj();
89 }
90
91 HWTEST_F(UserAuthClientTest, UserAuthClientGetProperty001, TestSize.Level0)
92 {
93 int32_t testUserId = 200;
94 GetPropertyRequest testRequest = {};
95
96 std::shared_ptr<MockGetPropCallback> testCallback = nullptr;
97 UserAuthClient::GetInstance().GetProperty(testUserId, testRequest, testCallback);
98
99 IpcClientUtils::ResetObj();
100 testCallback = Common::MakeShared<MockGetPropCallback>();
101 EXPECT_NE(testCallback, nullptr);
102 EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
103 UserAuthClient::GetInstance().GetProperty(testUserId, testRequest, testCallback);
104 }
105
106 HWTEST_F(UserAuthClientTest, UserAuthClientGetProperty002, TestSize.Level0)
107 {
108 int32_t testUserId = 200;
109 GetPropertyRequest testRequest = {};
110 testRequest.authType = FACE;
111 testRequest.keys = {Attributes::ATTR_RESULT_CODE, Attributes::ATTR_SIGNATURE};
112
113 auto testCallback = Common::MakeShared<MockGetPropCallback>();
114 EXPECT_NE(testCallback, nullptr);
115 EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
116
117 auto service = Common::MakeShared<MockUserAuthService>();
118 EXPECT_NE(service, nullptr);
119 EXPECT_CALL(*service, GetProperty(_, _, _, _)).Times(1);
120 ON_CALL(*service, GetProperty)
121 .WillByDefault(
122 [&testUserId, &testRequest](int32_t userId, AuthType authType,
123 const std::vector<Attributes::AttributeKey> &keys,
__anond184869b0302(int32_t userId, AuthType authType, const std::vector<Attributes::AttributeKey> &keys, sptr<GetExecutorPropertyCallbackInterface> &callback) 124 sptr<GetExecutorPropertyCallbackInterface> &callback) {
125 EXPECT_EQ(userId, testUserId);
126 EXPECT_EQ(authType, testRequest.authType);
127 EXPECT_THAT(keys, ElementsAreArray(testRequest.keys));
128 if (callback != nullptr) {
129 Attributes extraInfo;
130 callback->OnGetExecutorPropertyResult(SUCCESS, extraInfo);
131 }
132 }
133 );
134 sptr<MockRemoteObject> obj = new MockRemoteObject();
135 EXPECT_NE(obj, nullptr);
136 IpcClientUtils::SetObj(obj);
137 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
138 ON_CALL(*obj, SendRequest)
__anond184869b0402(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 139 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
140 service->OnRemoteRequest(code, data, reply, option);
141 return OHOS::NO_ERROR;
142 });
143 UserAuthClient::GetInstance().GetProperty(testUserId, testRequest, testCallback);
144 IpcClientUtils::ResetObj();
145 }
146
147 HWTEST_F(UserAuthClientTest, UserAuthClientSetProperty001, TestSize.Level0)
148 {
149 int32_t testUserId = 200;
150 SetPropertyRequest testRequest = {};
151 std::shared_ptr<MockSetPropCallback> testCallback = nullptr;
152 UserAuthClient::GetInstance().SetProperty(testUserId, testRequest, testCallback);
153
154 IpcClientUtils::ResetObj();
155 testCallback = Common::MakeShared<MockSetPropCallback>();
156 EXPECT_NE(testCallback, nullptr);
157 EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
158 UserAuthClient::GetInstance().SetProperty(testUserId, testRequest, testCallback);
159 }
160
161 HWTEST_F(UserAuthClientTest, UserAuthClientSetProperty002, TestSize.Level0)
162 {
163 int32_t testUserId = 200;
164 SetPropertyRequest testRequest = {};
165 testRequest.authType = PIN;
166 testRequest.mode = PROPERTY_MODE_DEL;
167 EXPECT_EQ(testRequest.attrs.SetInt32Value(Attributes::ATTR_RESULT_CODE, FAIL), true);
168 auto testCallback = Common::MakeShared<MockSetPropCallback>();
169 EXPECT_NE(testCallback, nullptr);
170 EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
171
172 auto service = Common::MakeShared<MockUserAuthService>();
173 EXPECT_NE(service, nullptr);
174 EXPECT_CALL(*service, SetProperty(_, _, _, _)).Times(1);
175 ON_CALL(*service, SetProperty)
176 .WillByDefault(
177 [&testUserId, &testRequest](int32_t userId, AuthType authType, const Attributes &attributes,
__anond184869b0502(int32_t userId, AuthType authType, const Attributes &attributes, sptr<SetExecutorPropertyCallbackInterface> &callback) 178 sptr<SetExecutorPropertyCallbackInterface> &callback) {
179 EXPECT_EQ(userId, testUserId);
180 EXPECT_EQ(authType, testRequest.authType);
181 int32_t resultCode;
182 EXPECT_EQ(attributes.GetInt32Value(Attributes::ATTR_RESULT_CODE, resultCode), true);
183 EXPECT_EQ(resultCode, FAIL);
184 if (callback != nullptr) {
185 callback->OnSetExecutorPropertyResult(SUCCESS);
186 }
187 }
188 );
189 sptr<MockRemoteObject> obj = new MockRemoteObject();
190 EXPECT_NE(obj, nullptr);
191 IpcClientUtils::SetObj(obj);
192 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
193 ON_CALL(*obj, SendRequest)
__anond184869b0602(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 194 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
195 service->OnRemoteRequest(code, data, reply, option);
196 return OHOS::NO_ERROR;
197 });
198
199 UserAuthClient::GetInstance().SetProperty(testUserId, testRequest, testCallback);
200 IpcClientUtils::ResetObj();
201 }
202
203 HWTEST_F(UserAuthClientTest, UserAuthClientBeginNorthAuthentication001, TestSize.Level0)
204 {
205 int32_t testApiVersion = 8;
206 std::vector<uint8_t> testChallenge = {1, 2, 3, 4, 3, 2, 1, 0};
207 AuthType testAuthType = PIN;
208 AuthTrustLevel testAtl = ATL1;
209 std::shared_ptr<MockAuthenticationCallback> testCallback = nullptr;
210 uint64_t contextId = UserAuthClientImpl::Instance().BeginNorthAuthentication(testApiVersion, testChallenge,
211 testAuthType, testAtl, testCallback);
212 EXPECT_EQ(contextId, 0);
213
214 IpcClientUtils::ResetObj();
215 testCallback = Common::MakeShared<MockAuthenticationCallback>();
216 EXPECT_NE(testCallback, nullptr);
217 EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
218 contextId = UserAuthClientImpl::Instance().BeginNorthAuthentication(testApiVersion, testChallenge,
219 testAuthType, testAtl, testCallback);
220 EXPECT_EQ(contextId, 0);
221 }
222
223 HWTEST_F(UserAuthClientTest, UserAuthClientBeginNorthAuthentication002, TestSize.Level0)
224 {
225 int32_t testApiVersion = 9;
226 std::vector<uint8_t> testChallenge = {1, 2, 3, 4, 3, 2, 1, 0};
227 AuthType testAuthType = PIN;
228 AuthTrustLevel testAtl = ATL1;
229 auto testCallback = Common::MakeShared<MockAuthenticationCallback>();
230 EXPECT_NE(testCallback, nullptr);
231 EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
232
233 uint64_t testContextId = 15858;
234
235 auto service = Common::MakeShared<MockUserAuthService>();
236 EXPECT_NE(service, nullptr);
237 EXPECT_CALL(*service, Auth(_, _, _, _, _)).Times(1);
238 ON_CALL(*service, Auth)
239 .WillByDefault(
240 [&testApiVersion, &testChallenge, &testAuthType, &testAtl, &testContextId](int32_t apiVersion,
241 const std::vector<uint8_t> &challenge, AuthType authType, AuthTrustLevel authTrustLevel,
__anond184869b0702(int32_t apiVersion, const std::vector<uint8_t> &challenge, AuthType authType, AuthTrustLevel authTrustLevel, sptr<UserAuthCallbackInterface> &callback) 242 sptr<UserAuthCallbackInterface> &callback) {
243 EXPECT_EQ(apiVersion, testApiVersion);
244 EXPECT_THAT(challenge, ElementsAreArray(testChallenge));
245 EXPECT_EQ(authType, testAuthType);
246 EXPECT_EQ(authTrustLevel, testAtl);
247 if (callback != nullptr) {
248 Attributes extraInfo;
249 callback->OnResult(SUCCESS, extraInfo);
250 }
251 return testContextId;
252 }
253 );
254 sptr<MockRemoteObject> obj = new MockRemoteObject();
255 EXPECT_NE(obj, nullptr);
256 IpcClientUtils::SetObj(obj);
257 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
258 ON_CALL(*obj, SendRequest)
__anond184869b0802(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 259 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
260 service->OnRemoteRequest(code, data, reply, option);
261 return OHOS::NO_ERROR;
262 });
263
264 uint64_t contextId = UserAuthClientImpl::Instance().BeginNorthAuthentication(testApiVersion, testChallenge,
265 testAuthType, testAtl, testCallback);
266 EXPECT_EQ(contextId, testContextId);
267 IpcClientUtils::ResetObj();
268 }
269
270 HWTEST_F(UserAuthClientTest, UserAuthClientBeginAuthentication001, TestSize.Level0)
271 {
272 int32_t testUserId = 84548;
273 std::vector<uint8_t> testChallenge = {1, 2, 3, 4, 8, 7, 5, 4};
274 AuthType testAuthType = PIN;
275 AuthTrustLevel testAtl = ATL1;
276 std::shared_ptr<MockAuthenticationCallback> testCallback = nullptr;
277 uint64_t contextId = UserAuthClient::GetInstance().BeginAuthentication(testUserId, testChallenge,
278 testAuthType, testAtl, testCallback);
279 EXPECT_EQ(contextId, 0);
280
281 IpcClientUtils::ResetObj();
282 testCallback = Common::MakeShared<MockAuthenticationCallback>();
283 EXPECT_NE(testCallback, nullptr);
284 EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
285 contextId = UserAuthClient::GetInstance().BeginAuthentication(testUserId, testChallenge,
286 testAuthType, testAtl, testCallback);
287 EXPECT_EQ(contextId, 0);
288 }
289
290 HWTEST_F(UserAuthClientTest, UserAuthClientBeginAuthentication002, TestSize.Level0)
291 {
292 int32_t testUserId = 84548;
293 std::vector<uint8_t> testChallenge = {1, 2, 3, 4, 8, 7, 5, 4};
294 AuthType testAuthType = PIN;
295 AuthTrustLevel testAtl = ATL1;
296 auto testCallback = Common::MakeShared<MockAuthenticationCallback>();
297 EXPECT_NE(testCallback, nullptr);
298 EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
299
300 uint64_t testContextId = 15858;
301
302 auto service = Common::MakeShared<MockUserAuthService>();
303 EXPECT_NE(service, nullptr);
304 EXPECT_CALL(*service, AuthUser(_, _, _, _, _)).Times(1);
305 ON_CALL(*service, AuthUser)
306 .WillByDefault(
307 [&testUserId, &testChallenge, &testAuthType, &testAtl, &testContextId](int32_t userId,
308 const std::vector<uint8_t> &challenge, AuthType authType, AuthTrustLevel authTrustLevel,
__anond184869b0902(int32_t userId, const std::vector<uint8_t> &challenge, AuthType authType, AuthTrustLevel authTrustLevel, sptr<UserAuthCallbackInterface> &callback) 309 sptr<UserAuthCallbackInterface> &callback) {
310 EXPECT_EQ(userId, testUserId);
311 EXPECT_THAT(challenge, ElementsAreArray(testChallenge));
312 EXPECT_EQ(authType, testAuthType);
313 EXPECT_EQ(authTrustLevel, testAtl);
314 if (callback != nullptr) {
315 Attributes extraInfo;
316 callback->OnResult(SUCCESS, extraInfo);
317 }
318 return testContextId;
319 }
320 );
321 sptr<MockRemoteObject> obj = new MockRemoteObject();
322 EXPECT_NE(obj, nullptr);
323 IpcClientUtils::SetObj(obj);
324 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
325 ON_CALL(*obj, SendRequest)
__anond184869b0a02(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 326 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
327 service->OnRemoteRequest(code, data, reply, option);
328 return OHOS::NO_ERROR;
329 });
330
331 uint64_t contextId = UserAuthClient::GetInstance().BeginAuthentication(testUserId, testChallenge,
332 testAuthType, testAtl, testCallback);
333 EXPECT_EQ(contextId, testContextId);
334 IpcClientUtils::ResetObj();
335 }
336
337 HWTEST_F(UserAuthClientTest, UserAuthClientCancelAuthentication001, TestSize.Level0)
338 {
339 uint64_t testContextId = 12345562;
340
341 IpcClientUtils::ResetObj();
342 int32_t ret = UserAuthClient::GetInstance().CancelAuthentication(testContextId);
343 EXPECT_EQ(ret, GENERAL_ERROR);
344 }
345
346 HWTEST_F(UserAuthClientTest, UserAuthClientCancelAuthentication002, TestSize.Level0)
347 {
348 uint64_t testContextId = 12345562;
349
350 auto service = Common::MakeShared<MockUserAuthService>();
351 EXPECT_NE(service, nullptr);
352 EXPECT_CALL(*service, CancelAuthOrIdentify(_)).Times(1);
353 ON_CALL(*service, CancelAuthOrIdentify)
354 .WillByDefault(
__anond184869b0b02(uint64_t contextId) 355 [&testContextId](uint64_t contextId) {
356 EXPECT_EQ(contextId, testContextId);
357 return SUCCESS;
358 }
359 );
360 sptr<MockRemoteObject> obj = new MockRemoteObject();
361 EXPECT_NE(obj, nullptr);
362 IpcClientUtils::SetObj(obj);
363 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
364 ON_CALL(*obj, SendRequest)
__anond184869b0c02(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 365 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
366 service->OnRemoteRequest(code, data, reply, option);
367 return OHOS::NO_ERROR;
368 });
369
370 int32_t ret = UserAuthClient::GetInstance().CancelAuthentication(testContextId);
371 EXPECT_EQ(ret, SUCCESS);
372 IpcClientUtils::ResetObj();
373 }
374
375 HWTEST_F(UserAuthClientTest, UserAuthClientBeginIdentification001, TestSize.Level0)
376 {
377 std::vector<uint8_t> testChallenge = {4, 5, 6, 7, 3, 4, 1, 2};
378 AuthType testAuthType = FACE;
379 std::shared_ptr<MockIdentificationCallback> testCallback = nullptr;
380 uint64_t contextId = UserAuthClient::GetInstance().BeginIdentification(testChallenge, testAuthType, testCallback);
381 EXPECT_EQ(contextId, 0);
382
383 IpcClientUtils::ResetObj();
384 testCallback = Common::MakeShared<MockIdentificationCallback>();
385 EXPECT_NE(testCallback, nullptr);
386 EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
387 contextId = UserAuthClient::GetInstance().BeginIdentification(testChallenge, testAuthType, testCallback);
388 EXPECT_EQ(contextId, 0);
389 }
390
391 HWTEST_F(UserAuthClientTest, UserAuthClientBeginIdentification002, TestSize.Level0)
392 {
393 std::vector<uint8_t> testChallenge = {4, 5, 6, 7, 3, 4, 1, 2};
394 AuthType testAuthType = FACE;
395 auto testCallback = Common::MakeShared<MockIdentificationCallback>();
396 EXPECT_NE(testCallback, nullptr);
397 EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
398
399 uint64_t testContextId = 548781;
400
401 auto service = Common::MakeShared<MockUserAuthService>();
402 EXPECT_NE(service, nullptr);
403 EXPECT_CALL(*service, Identify(_, _, _)).Times(1);
404 ON_CALL(*service, Identify)
405 .WillByDefault(
406 [&testChallenge, &testAuthType, &testContextId](const std::vector<uint8_t> &challenge,
__anond184869b0d02(const std::vector<uint8_t> &challenge, AuthType authType, sptr<UserAuthCallbackInterface> &callback) 407 AuthType authType, sptr<UserAuthCallbackInterface> &callback) {
408 EXPECT_THAT(challenge, ElementsAreArray(testChallenge));
409 EXPECT_EQ(authType, testAuthType);
410 if (callback != nullptr) {
411 Attributes extraInfo;
412 callback->OnResult(SUCCESS, extraInfo);
413 }
414 return testContextId;
415 }
416 );
417 sptr<MockRemoteObject> obj = new MockRemoteObject();
418 EXPECT_NE(obj, nullptr);
419 IpcClientUtils::SetObj(obj);
420 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
421 ON_CALL(*obj, SendRequest)
__anond184869b0e02(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 422 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
423 service->OnRemoteRequest(code, data, reply, option);
424 return OHOS::NO_ERROR;
425 });
426
427 uint64_t contextId = UserAuthClient::GetInstance().BeginIdentification(testChallenge, testAuthType, testCallback);
428 EXPECT_EQ(contextId, testContextId);
429 IpcClientUtils::ResetObj();
430 }
431
432 HWTEST_F(UserAuthClientTest, UserAuthClientCancelIdentification001, TestSize.Level0)
433 {
434 uint64_t testContextId = 1221215;
435
436 IpcClientUtils::ResetObj();
437 int32_t ret = UserAuthClient::GetInstance().CancelIdentification(testContextId);
438 EXPECT_EQ(ret, GENERAL_ERROR);
439 }
440
441 HWTEST_F(UserAuthClientTest, UserAuthClientCancelIdentification002, TestSize.Level0)
442 {
443 uint64_t testContextId = 1221215;
444
445 auto service = Common::MakeShared<MockUserAuthService>();
446 EXPECT_NE(service, nullptr);
447 EXPECT_CALL(*service, CancelAuthOrIdentify(_)).Times(1);
448 ON_CALL(*service, CancelAuthOrIdentify)
449 .WillByDefault(
__anond184869b0f02(uint64_t contextId) 450 [&testContextId](uint64_t contextId) {
451 EXPECT_EQ(contextId, testContextId);
452 return SUCCESS;
453 }
454 );
455 sptr<MockRemoteObject> obj = new MockRemoteObject();
456 EXPECT_NE(obj, nullptr);
457 IpcClientUtils::SetObj(obj);
458 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
459 ON_CALL(*obj, SendRequest)
__anond184869b1002(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 460 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
461 service->OnRemoteRequest(code, data, reply, option);
462 return OHOS::NO_ERROR;
463 });
464
465 int32_t ret = UserAuthClient::GetInstance().CancelIdentification(testContextId);
466 EXPECT_EQ(ret, SUCCESS);
467 IpcClientUtils::ResetObj();
468 }
469
470 HWTEST_F(UserAuthClientTest, UserAuthClientGetVersion001, TestSize.Level0)
471 {
472 IpcClientUtils::ResetObj();
473 int32_t version = -1;
474 int32_t ret = UserAuthClientImpl::Instance().GetVersion(version);
475 EXPECT_EQ(ret, GENERAL_ERROR);
476 IpcClientUtils::ResetObj();
477 }
478
479 HWTEST_F(UserAuthClientTest, UserAuthClientGetVersion002, TestSize.Level0)
480 {
481 int32_t testVersion = 20000;
482
483 auto service = Common::MakeShared<MockUserAuthService>();
484 EXPECT_NE(service, nullptr);
485 EXPECT_CALL(*service, GetVersion(_)).Times(1);
486 ON_CALL(*service, GetVersion)
487 .WillByDefault(
__anond184869b1102(int32_t &version) 488 [&testVersion](int32_t &version) {
489 version = testVersion;
490 return SUCCESS;
491 }
492 );
493
494 sptr<MockRemoteObject> obj = new MockRemoteObject();
495 EXPECT_NE(obj, nullptr);
496 IpcClientUtils::SetObj(obj);
497 EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
498 ON_CALL(*obj, SendRequest)
__anond184869b1202(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 499 .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
500 service->OnRemoteRequest(code, data, reply, option);
501 return OHOS::NO_ERROR;
502 });
503 int32_t version;
504 int32_t result = UserAuthClientImpl::Instance().GetVersion(version);
505 EXPECT_EQ(result, SUCCESS);
506 EXPECT_EQ(version, testVersion);
507 IpcClientUtils::ResetObj();
508 }
509 } // namespace UserAuth
510 } // namespace UserIam
511 } // namespace OHOS