• 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 "credential_info_test.h"
17 #include "credential_info_impl.h"
18 namespace OHOS {
19 namespace UserIam {
20 namespace UserAuth {
21 using namespace testing;
22 using namespace testing::ext;
23 using HdiCredential = OHOS::HDI::UserAuth::V1_0::CredentialInfo;
24 
SetUpTestCase()25 void CredentialInfoTest::SetUpTestCase()
26 {
27 }
28 
TearDownTestCase()29 void CredentialInfoTest::TearDownTestCase()
30 {
31 }
32 
SetUp()33 void CredentialInfoTest::SetUp()
34 {
35 }
36 
TearDown()37 void CredentialInfoTest::TearDown()
38 {
39 }
40 
41 HWTEST_F(CredentialInfoTest, GetCredentialId, TestSize.Level0)
42 {
43     int32_t userId = 100;
44     HdiCredential info = {
45         .credentialId = 1,
46         .executorIndex = 2,
47         .templateId = 3,
48         .authType = static_cast<OHOS::HDI::UserAuth::V1_0::AuthType>(4),
49         .executorMatcher = 5,
50         .executorSensorHint = 6,
51     };
52 
53     CredentialInfoImpl CredentialInfoImpl(userId, info);
54     uint64_t ret = CredentialInfoImpl.GetCredentialId();
55     EXPECT_EQ(ret, info.credentialId);
56 }
57 
58 HWTEST_F(CredentialInfoTest, GetUserId, TestSize.Level0)
59 {
60     int32_t userId = 100;
61     HdiCredential info = {
62         .credentialId = 1,
63         .executorIndex = 2,
64         .templateId = 3,
65         .authType = static_cast<OHOS::HDI::UserAuth::V1_0::AuthType>(4),
66         .executorMatcher = 5,
67         .executorSensorHint = 6,
68     };
69     CredentialInfoImpl CredentialInfoImpl(userId, info);
70     int32_t ret = CredentialInfoImpl.GetUserId();
71     EXPECT_EQ(ret, userId);
72 }
73 
74 HWTEST_F(CredentialInfoTest, GetExecutorIndex, TestSize.Level0)
75 {
76     int32_t userId = 100;
77     HdiCredential info = {
78         .credentialId = 1,
79         .executorIndex = 2,
80         .templateId = 3,
81         .authType = static_cast<OHOS::HDI::UserAuth::V1_0::AuthType>(4),
82         .executorMatcher = 5,
83         .executorSensorHint = 6,
84     };
85     CredentialInfoImpl CredentialInfoImpl(userId, info);
86     uint64_t ret = CredentialInfoImpl.GetExecutorIndex();
87     EXPECT_EQ(ret, info.executorIndex);
88 }
89 
90 HWTEST_F(CredentialInfoTest, GetTemplateId, TestSize.Level0)
91 {
92     int32_t userId = 100;
93     HdiCredential info = {
94         .credentialId = 1,
95         .executorIndex = 2,
96         .templateId = 3,
97         .authType = static_cast<OHOS::HDI::UserAuth::V1_0::AuthType>(4),
98         .executorMatcher = 5,
99         .executorSensorHint = 6,
100     };
101     CredentialInfoImpl CredentialInfoImpl(userId, info);
102     uint64_t ret = CredentialInfoImpl.GetTemplateId();
103     EXPECT_EQ(ret, info.templateId);
104 }
105 
106 HWTEST_F(CredentialInfoTest, GetAuthType, TestSize.Level0)
107 {
108     int32_t userId = 100;
109     HdiCredential info = {
110         .credentialId = 1,
111         .executorIndex = 2,
112         .templateId = 3,
113         .authType = static_cast<OHOS::HDI::UserAuth::V1_0::AuthType>(4),
114         .executorMatcher = 5,
115         .executorSensorHint = 6,
116     };
117     CredentialInfoImpl CredentialInfoImpl(userId, info);
118     AuthType ret = CredentialInfoImpl.GetAuthType();
119     EXPECT_EQ(static_cast<uint32_t>(ret), static_cast<uint32_t>(info.authType));
120 }
121 
122 HWTEST_F(CredentialInfoTest, GetExecutorSensorHint, TestSize.Level0)
123 {
124     int32_t userId = 100;
125     HdiCredential info = {
126         .credentialId = 1,
127         .executorIndex = 2,
128         .templateId = 3,
129         .authType = static_cast<OHOS::HDI::UserAuth::V1_0::AuthType>(4),
130         .executorMatcher = 5,
131         .executorSensorHint = 6,
132     };
133     CredentialInfoImpl CredentialInfoImpl(userId, info);
134     uint32_t ret = CredentialInfoImpl.GetExecutorSensorHint();
135     EXPECT_EQ(ret, info.executorSensorHint);
136 }
137 
138 HWTEST_F(CredentialInfoTest, GetExecutorMatcher, TestSize.Level0)
139 {
140     int32_t userId = 100;
141     HdiCredential info = {
142         .credentialId = 1,
143         .executorIndex = 2,
144         .templateId = 3,
145         .authType = static_cast<OHOS::HDI::UserAuth::V1_0::AuthType>(4),
146         .executorMatcher = 5,
147         .executorSensorHint = 6,
148     };
149     CredentialInfoImpl CredentialInfoImpl(userId, info);
150     uint32_t ret = CredentialInfoImpl.GetExecutorMatcher();
151     EXPECT_EQ(ret, info.executorMatcher);
152 }
153 } // namespace UserAuth
154 } // namespace UserIam
155 } // namespace OHOS
156