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