• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "iam_logger.h"
19 #include "iam_ptr.h"
20 
21 #include "face_auth_defines.h"
22 #include "face_auth_driver_hdi.h"
23 #include "mock_face_auth_interface_adapter.h"
24 #include "mock_iall_in_one_executor.h"
25 #include "mock_iface_auth_interface.h"
26 
27 #define LOG_TAG "FACE_AUTH_SA"
28 
29 using namespace testing;
30 using namespace testing::ext;
31 using namespace OHOS::UserIam::Common;
32 
33 namespace OHOS {
34 namespace UserIam {
35 namespace FaceAuth {
36 class FaceAuthDriverHdiUnitTest : public testing::Test {
37 public:
38     static void SetUpTestCase();
39     static void TearDownTestCase();
40     void SetUp();
41     void TearDown();
42 };
43 
SetUpTestCase()44 void FaceAuthDriverHdiUnitTest::SetUpTestCase()
45 {
46 }
47 
TearDownTestCase()48 void FaceAuthDriverHdiUnitTest::TearDownTestCase()
49 {
50 }
51 
SetUp()52 void FaceAuthDriverHdiUnitTest::SetUp()
53 {
54 }
55 
TearDown()56 void FaceAuthDriverHdiUnitTest::TearDown()
57 {
58 }
59 
60 HWTEST_F(FaceAuthDriverHdiUnitTest, FaceAuthDriverHdi_GetExecutorListTest_001, TestSize.Level0)
61 {
62     FaceAuthDriverHdi driverHdi(nullptr);
63     std::vector<std::shared_ptr<UserAuth::IAuthExecutorHdi>> executorList;
64     driverHdi.GetExecutorList(executorList);
65     EXPECT_TRUE(executorList.size() == 0);
66 }
67 
68 HWTEST_F(FaceAuthDriverHdiUnitTest, FaceAuthDriverHdi_GetExecutorListTest_002, TestSize.Level0)
69 {
70     auto adapter = MakeShared<MockFaceAuthInterfaceAdapter>();
71     ASSERT_TRUE(adapter != nullptr);
72     EXPECT_CALL(*adapter, Get()).Times(Exactly(1)).WillOnce(Return(nullptr));
73 
74     FaceAuthDriverHdi driverHdi(adapter);
75     std::vector<std::shared_ptr<UserAuth::IAuthExecutorHdi>> executorList;
76     driverHdi.GetExecutorList(executorList);
77     EXPECT_TRUE(executorList.size() == 0);
78 }
79 
80 HWTEST_F(FaceAuthDriverHdiUnitTest, FaceAuthDriverHdi_GetExecutorListTest_003, TestSize.Level0)
81 {
82     sptr<MockIFaceAuthInterface> interface(new (std::nothrow) MockIFaceAuthInterface());
83     ASSERT_TRUE(interface != nullptr);
84     EXPECT_CALL(*interface, GetExecutorList(_)).Times(Exactly(1));
85 
86     auto adapter = MakeShared<MockFaceAuthInterfaceAdapter>();
87     ASSERT_TRUE(adapter != nullptr);
88     EXPECT_CALL(*adapter, Get()).Times(Exactly(1)).WillOnce(Return(interface));
89 
90     FaceAuthDriverHdi driverHdi(adapter);
91     std::vector<std::shared_ptr<UserAuth::IAuthExecutorHdi>> executorList;
92     driverHdi.GetExecutorList(executorList);
93     EXPECT_TRUE(executorList.size() == 0);
94 }
95 
96 HWTEST_F(FaceAuthDriverHdiUnitTest, FaceAuthDriverHdi_GetExecutorListTest_004, TestSize.Level0)
97 {
98     sptr<MockIFaceAuthInterface> interface(new (std::nothrow) MockIFaceAuthInterface());
99     ASSERT_TRUE(interface != nullptr);
100     EXPECT_CALL(*interface, GetExecutorList(_))
101         .Times(Exactly(1))
__anon2b9939a00102(std::vector<sptr<IAllInOneExecutor>> &list) 102         .WillOnce([](std::vector<sptr<IAllInOneExecutor>> &list) { return static_cast<int32_t>(HDF_FAILURE); });
103 
104     auto adapter = MakeShared<MockFaceAuthInterfaceAdapter>();
105     ASSERT_TRUE(adapter != nullptr);
106     EXPECT_CALL(*adapter, Get()).Times(Exactly(1)).WillOnce(Return(interface));
107 
108     FaceAuthDriverHdi driverHdi(adapter);
109     std::vector<std::shared_ptr<UserAuth::IAuthExecutorHdi>> executorList;
110     driverHdi.GetExecutorList(executorList);
111     EXPECT_TRUE(executorList.size() == 0);
112 }
113 
114 HWTEST_F(FaceAuthDriverHdiUnitTest, FaceAuthDriverHdi_GetExecutorListTest_005, TestSize.Level0)
115 {
116     sptr<MockIFaceAuthInterface> interface(new (std::nothrow) MockIFaceAuthInterface());
117     ASSERT_TRUE(interface != nullptr);
118     EXPECT_CALL(*interface, GetExecutorList(_))
119         .Times(Exactly(1))
__anon2b9939a00202(std::vector<sptr<IAllInOneExecutor>> &list) 120         .WillOnce([](std::vector<sptr<IAllInOneExecutor>> &list) { return static_cast<int32_t>(HDF_SUCCESS); });
121 
122     auto adapter = MakeShared<MockFaceAuthInterfaceAdapter>();
123     ASSERT_TRUE(adapter != nullptr);
124     EXPECT_CALL(*adapter, Get()).Times(Exactly(1)).WillOnce(Return(interface));
125 
126     FaceAuthDriverHdi driverHdi(adapter);
127     std::vector<std::shared_ptr<UserAuth::IAuthExecutorHdi>> executorList;
128     driverHdi.GetExecutorList(executorList);
129     EXPECT_TRUE(executorList.size() == 0);
130 }
131 
132 HWTEST_F(FaceAuthDriverHdiUnitTest, FaceAuthDriverHdi_GetExecutorListTest_006, TestSize.Level0)
133 {
134     sptr<MockIFaceAuthInterface> interface(new (std::nothrow) MockIFaceAuthInterface());
135     ASSERT_TRUE(interface != nullptr);
136     EXPECT_CALL(*interface, GetExecutorList(_))
137         .Times(Exactly(1))
__anon2b9939a00302(std::vector<sptr<IAllInOneExecutor>> &list) 138         .WillOnce([](std::vector<sptr<IAllInOneExecutor>> &list) {
139             auto executor = sptr<IAllInOneExecutor>(new (std::nothrow) MockIAllInOneExecutor());
140             EXPECT_TRUE(executor != nullptr);
141             list.push_back(executor);
142             return static_cast<int32_t>(HDF_SUCCESS);
143         });
144 
145     auto adapter = MakeShared<MockFaceAuthInterfaceAdapter>();
146     ASSERT_TRUE(adapter != nullptr);
147     EXPECT_CALL(*adapter, Get()).Times(Exactly(1)).WillOnce(Return(interface));
148 
149     FaceAuthDriverHdi driverHdi(adapter);
150     std::vector<std::shared_ptr<UserAuth::IAuthExecutorHdi>> executorList;
151     driverHdi.GetExecutorList(executorList);
152     EXPECT_TRUE(executorList.size() == 1);
153 }
154 
155 HWTEST_F(FaceAuthDriverHdiUnitTest, FaceAuthDriverHdi_GetExecutorListTest_007, TestSize.Level0)
156 {
157     sptr<MockIFaceAuthInterface> interface(new (std::nothrow) MockIFaceAuthInterface());
158     ASSERT_TRUE(interface != nullptr);
159     EXPECT_CALL(*interface, GetExecutorList(_))
160         .Times(Exactly(1))
__anon2b9939a00402(std::vector<sptr<IAllInOneExecutor>> &list) 161         .WillOnce([](std::vector<sptr<IAllInOneExecutor>> &list) {
162             list.push_back(sptr<IAllInOneExecutor>(nullptr));
163             auto executor = sptr<IAllInOneExecutor>(new (std::nothrow) MockIAllInOneExecutor());
164             EXPECT_TRUE(executor != nullptr);
165             list.push_back(executor);
166             list.push_back(sptr<IAllInOneExecutor>(nullptr));
167             executor = sptr<IAllInOneExecutor>(new (std::nothrow) MockIAllInOneExecutor());
168             EXPECT_TRUE(executor != nullptr);
169             list.push_back(executor);
170             return static_cast<int32_t>(HDF_SUCCESS);
171         });
172 
173     auto adapter = MakeShared<MockFaceAuthInterfaceAdapter>();
174     ASSERT_TRUE(adapter != nullptr);
175     EXPECT_CALL(*adapter, Get()).Times(Exactly(1)).WillOnce(Return(interface));
176 
177     FaceAuthDriverHdi driverHdi(adapter);
178     std::vector<std::shared_ptr<UserAuth::IAuthExecutorHdi>> executorList;
179     driverHdi.GetExecutorList(executorList);
180     EXPECT_TRUE(executorList.size() == 2);
181 }
182 
183 HWTEST_F(FaceAuthDriverHdiUnitTest, FaceAuthDriverHdi_GetExecutorListTest_008, TestSize.Level0)
184 {
185     sptr<MockIFaceAuthInterface> interface(new (std::nothrow) MockIFaceAuthInterface());
186     ASSERT_TRUE(interface != nullptr);
187     EXPECT_CALL(*interface, GetExecutorList(_))
188         .Times(Exactly(1))
__anon2b9939a00502(std::vector<sptr<IAllInOneExecutor>> &list) 189         .WillOnce([](std::vector<sptr<IAllInOneExecutor>> &list) {
190             auto executor = sptr<IAllInOneExecutor>(new (std::nothrow) MockIAllInOneExecutor());
191             EXPECT_TRUE(executor != nullptr);
192             list.push_back(executor);
193             return static_cast<int32_t>(HDF_FAILURE);
194         });
195 
196     auto adapter = MakeShared<MockFaceAuthInterfaceAdapter>();
197     ASSERT_TRUE(adapter != nullptr);
198     EXPECT_CALL(*adapter, Get()).Times(Exactly(1)).WillOnce(Return(interface));
199 
200     FaceAuthDriverHdi driverHdi(adapter);
201     std::vector<std::shared_ptr<UserAuth::IAuthExecutorHdi>> executorList;
202     driverHdi.GetExecutorList(executorList);
203     EXPECT_TRUE(executorList.size() == 0);
204 }
205 
206 HWTEST_F(FaceAuthDriverHdiUnitTest, FaceAuthDriverHdi_OnHdiDisconnectTest_001, TestSize.Level0)
207 {
208     sptr<MockIFaceAuthInterface> interface(new (std::nothrow) MockIFaceAuthInterface());
209     ASSERT_TRUE(interface != nullptr);
210     EXPECT_CALL(*interface, GetExecutorList(_))
211         .Times(Exactly(1))
__anon2b9939a00602(std::vector<sptr<IAllInOneExecutor>> &list) 212         .WillOnce([](std::vector<sptr<IAllInOneExecutor>> &list) {
213             auto executor = sptr<IAllInOneExecutor>(new (std::nothrow) MockIAllInOneExecutor());
214             EXPECT_TRUE(executor != nullptr);
215             list.push_back(executor);
216             return static_cast<int32_t>(HDF_SUCCESS);
217         });
218 
219     auto adapter = MakeShared<MockFaceAuthInterfaceAdapter>();
220     ASSERT_TRUE(adapter != nullptr);
221     EXPECT_CALL(*adapter, Get()).Times(Exactly(1)).WillOnce(Return(interface));
222 
223     FaceAuthDriverHdi driverHdi(adapter);
224     std::vector<std::shared_ptr<UserAuth::IAuthExecutorHdi>> executorList;
225     driverHdi.GetExecutorList(executorList);
226     EXPECT_TRUE(executorList.size() == 1);
227     driverHdi.OnHdiDisconnect();
228 }
229 
230 HWTEST_F(FaceAuthDriverHdiUnitTest, FaceAuthDriverHdi_SetBufferProducer_001, TestSize.Level0)
231 {
232     sptr<MockIFaceAuthInterface> interface(new (std::nothrow) MockIFaceAuthInterface());
233     ASSERT_TRUE(interface != nullptr);
234     EXPECT_CALL(*interface, SetBufferProducer(_))
235         .Times(Exactly(1))
__anon2b9939a00702(const sptr<BufferProducerSequenceable> &producer) 236         .WillOnce([](const sptr<BufferProducerSequenceable> &producer) { return static_cast<int32_t>(HDF_SUCCESS); });
237 
238     auto adapter = MakeShared<MockFaceAuthInterfaceAdapter>();
239     ASSERT_TRUE(adapter != nullptr);
240     EXPECT_CALL(*adapter, Get()).Times(Exactly(1)).WillOnce(Return(interface));
241 
242     FaceAuthDriverHdi driverHdi(adapter);
243     std::vector<std::shared_ptr<UserAuth::IAuthExecutorHdi>> executorList;
244     sptr<IBufferProducer> producer = nullptr;
245     int32_t ret = driverHdi.SetBufferProducer(producer);
246     EXPECT_EQ(ret, FACE_AUTH_SUCCESS);
247 }
248 
249 HWTEST_F(FaceAuthDriverHdiUnitTest, FaceAuthDriverHdi_SetBufferProducer_002, TestSize.Level0)
250 {
251     sptr<MockIFaceAuthInterface> interface(new (std::nothrow) MockIFaceAuthInterface());
252     ASSERT_TRUE(interface != nullptr);
253     EXPECT_CALL(*interface, SetBufferProducer(_))
254         .Times(Exactly(1))
255         .WillOnce(
__anon2b9939a00802(const sptr<BufferProducerSequenceable> &producer) 256             [](const sptr<BufferProducerSequenceable> &producer) { return static_cast<int32_t>(FACE_AUTH_ERROR); });
257 
258     auto adapter = MakeShared<MockFaceAuthInterfaceAdapter>();
259     ASSERT_TRUE(adapter != nullptr);
260     EXPECT_CALL(*adapter, Get()).Times(Exactly(1)).WillOnce(Return(interface));
261 
262     FaceAuthDriverHdi driverHdi(adapter);
263     std::vector<std::shared_ptr<UserAuth::IAuthExecutorHdi>> executorList;
264     sptr<IBufferProducer> producer = nullptr;
265     int32_t ret = driverHdi.SetBufferProducer(producer);
266     EXPECT_EQ(ret, FACE_AUTH_ERROR);
267 }
268 } // namespace FaceAuth
269 } // namespace UserIam
270 } // namespace OHOS
271