1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define ASSERT_OK(v) ASSERT_TRUE(v.isOk())
18 
19 #include <android/hardware/biometrics/fingerprint/2.3/IBiometricsFingerprint.h>
20 #include <gtest/gtest.h>
21 #include <hidl/GtestPrinter.h>
22 #include <hidl/HidlSupport.h>
23 #include <hidl/ServiceManagement.h>
24 
25 namespace {
26 
27 namespace hidl_interface_2_3 = android::hardware::biometrics::fingerprint::V2_3;
28 
29 using hidl_interface_2_3::IBiometricsFingerprint;
30 
31 using android::sp;
32 
33 // Callback arguments that need to be captured for the tests.
34 struct FingerprintCallbackArgs {};
35 
36 class FingerprintHidlTest : public ::testing::TestWithParam<std::string> {
37   public:
SetUp()38     void SetUp() override {
39         mService = IBiometricsFingerprint::getService(GetParam());
40         ASSERT_NE(mService, nullptr);
41     }
42 
43     sp<IBiometricsFingerprint> mService;
44 };
45 
46 // This method returns true or false depending on the implementation.
TEST_P(FingerprintHidlTest,isUdfpsTest)47 TEST_P(FingerprintHidlTest, isUdfpsTest) {
48     // Arbitrary ID
49     uint32_t sensorId = 1234;
50     ASSERT_OK(mService->isUdfps(sensorId));
51 }
52 
53 // This method that doesn't return anything.
TEST_P(FingerprintHidlTest,onFingerDownTest)54 TEST_P(FingerprintHidlTest, onFingerDownTest) {
55     ASSERT_OK(mService->onFingerDown(1, 2, 3.0f, 4.0f));
56 }
57 
58 // This method that doesn't return anything.
TEST_P(FingerprintHidlTest,onFingerUp)59 TEST_P(FingerprintHidlTest, onFingerUp) {
60     ASSERT_OK(mService->onFingerUp());
61 }
62 
63 }  // anonymous namespace
64 
65 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(FingerprintHidlTest);
66 INSTANTIATE_TEST_SUITE_P(PerInstance, FingerprintHidlTest,
67                          testing::ValuesIn(android::hardware::getAllHalInstanceNames(
68                                  IBiometricsFingerprint::descriptor)),
69                          android::hardware::PrintInstanceNameToString);
70