• 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 <gtest/gtest.h>
17 
18 #include "user_auth_funcs.h"
19 
20 extern "C" {
21     extern int32_t SetAuthResult(int32_t userId, uint32_t authType, const ExecutorResultInfo *info, AuthResult *result);
22 }
23 
24 namespace OHOS {
25 namespace UserIam {
26 namespace UserAuth {
27 using namespace testing;
28 using namespace testing::ext;
29 
30 class UserAuthFuncsTest : public testing::Test {
31 public:
SetUpTestCase()32     static void SetUpTestCase() {};
33 
TearDownTestCase()34     static void TearDownTestCase() {};
35 
SetUp()36     void SetUp() {};
37 
TearDown()38     void TearDown() {};
39 };
40 
41 HWTEST_F(UserAuthFuncsTest, TestGenerateSolutionFunc, TestSize.Level0)
42 {
43     AuthSolutionHal param = {};
44     EXPECT_EQ(GenerateSolutionFunc(param, nullptr), RESULT_BAD_PARAM);
45 }
46 
47 HWTEST_F(UserAuthFuncsTest, TestSetAuthResult, TestSize.Level0)
48 {
49     uint32_t authType = 1;
50     ExecutorResultInfo info = {};
51     info.result = 0;
52     info.rootSecret = nullptr;
53     AuthResult result = {};
54     EXPECT_EQ(SetAuthResult(0, authType, &info, &result), RESULT_NO_MEMORY);
55 }
56 
57 HWTEST_F(UserAuthFuncsTest, TestRequestAuthResultFunc, TestSize.Level0)
58 {
59     uint64_t contextId = 2131;
60     EXPECT_EQ(RequestAuthResultFunc(contextId, nullptr, nullptr, nullptr), RESULT_BAD_PARAM);
61     Buffer *scheduleResult = CreateBufferBySize(10);
62     UserAuthTokenHal token = {};
63     AuthResult result = {};
64     EXPECT_EQ(RequestAuthResultFunc(contextId, scheduleResult, nullptr, nullptr), RESULT_BAD_PARAM);
65     EXPECT_EQ(RequestAuthResultFunc(contextId, scheduleResult, &token, nullptr), RESULT_BAD_PARAM);
66     result.rootSecret = CreateBufferBySize(10);
67     EXPECT_EQ(RequestAuthResultFunc(contextId, scheduleResult, &token, &result), RESULT_BAD_PARAM);
68 }
69 } // namespace UserAuth
70 } // namespace UserIam
71 } // namespace OHOS
72