xref: /aosp_15_r20/hardware/libhardware/tests/fingerprint/fingerprint_test_fixtures.h (revision e01b6f769022e40d0923dee176e8dc7cd1d52984)
1*e01b6f76SAndroid Build Coastguard Worker /*
2*e01b6f76SAndroid Build Coastguard Worker  * Copyright (C) 2014 The Android Open Source Project
3*e01b6f76SAndroid Build Coastguard Worker  *
4*e01b6f76SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*e01b6f76SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*e01b6f76SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*e01b6f76SAndroid Build Coastguard Worker  *
8*e01b6f76SAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*e01b6f76SAndroid Build Coastguard Worker  *
10*e01b6f76SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*e01b6f76SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*e01b6f76SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*e01b6f76SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*e01b6f76SAndroid Build Coastguard Worker  * limitations under the License.
15*e01b6f76SAndroid Build Coastguard Worker  */
16*e01b6f76SAndroid Build Coastguard Worker 
17*e01b6f76SAndroid Build Coastguard Worker #ifndef __ANDROID_HAL_FINGERPRINT_TEST_COMMON__
18*e01b6f76SAndroid Build Coastguard Worker #define __ANDROID_HAL_FINGERPRINT_TEST_COMMON__
19*e01b6f76SAndroid Build Coastguard Worker 
20*e01b6f76SAndroid Build Coastguard Worker #include <gtest/gtest.h>
21*e01b6f76SAndroid Build Coastguard Worker #include <hardware/hardware.h>
22*e01b6f76SAndroid Build Coastguard Worker #include <hardware/fingerprint.h>
23*e01b6f76SAndroid Build Coastguard Worker 
24*e01b6f76SAndroid Build Coastguard Worker namespace tests {
25*e01b6f76SAndroid Build Coastguard Worker 
26*e01b6f76SAndroid Build Coastguard Worker static const uint16_t kVersion = HARDWARE_MODULE_API_VERSION(1, 0);
27*e01b6f76SAndroid Build Coastguard Worker 
28*e01b6f76SAndroid Build Coastguard Worker class FingerprintModule : public testing::Test {
29*e01b6f76SAndroid Build Coastguard Worker  public:
FingerprintModule()30*e01b6f76SAndroid Build Coastguard Worker     FingerprintModule() :
31*e01b6f76SAndroid Build Coastguard Worker         fp_module_(NULL) {}
~FingerprintModule()32*e01b6f76SAndroid Build Coastguard Worker     ~FingerprintModule() {}
33*e01b6f76SAndroid Build Coastguard Worker  protected:
SetUp()34*e01b6f76SAndroid Build Coastguard Worker     virtual void SetUp() {
35*e01b6f76SAndroid Build Coastguard Worker         const hw_module_t *hw_module = NULL;
36*e01b6f76SAndroid Build Coastguard Worker         ASSERT_EQ(0, hw_get_module(FINGERPRINT_HARDWARE_MODULE_ID, &hw_module))
37*e01b6f76SAndroid Build Coastguard Worker                     << "Can't get fingerprint module";
38*e01b6f76SAndroid Build Coastguard Worker         ASSERT_TRUE(NULL != hw_module)
39*e01b6f76SAndroid Build Coastguard Worker                     << "hw_get_module didn't return a valid fingerprint module";
40*e01b6f76SAndroid Build Coastguard Worker 
41*e01b6f76SAndroid Build Coastguard Worker         fp_module_ = reinterpret_cast<const fingerprint_module_t*>(hw_module);
42*e01b6f76SAndroid Build Coastguard Worker     }
fp_module()43*e01b6f76SAndroid Build Coastguard Worker     const fingerprint_module_t* fp_module() { return fp_module_; }
44*e01b6f76SAndroid Build Coastguard Worker  private:
45*e01b6f76SAndroid Build Coastguard Worker     const fingerprint_module_t *fp_module_;
46*e01b6f76SAndroid Build Coastguard Worker };
47*e01b6f76SAndroid Build Coastguard Worker 
48*e01b6f76SAndroid Build Coastguard Worker class FingerprintDevice : public FingerprintModule {
49*e01b6f76SAndroid Build Coastguard Worker  public:
FingerprintDevice()50*e01b6f76SAndroid Build Coastguard Worker     FingerprintDevice() :
51*e01b6f76SAndroid Build Coastguard Worker         fp_device_(NULL) {}
~FingerprintDevice()52*e01b6f76SAndroid Build Coastguard Worker     ~FingerprintDevice() {}
53*e01b6f76SAndroid Build Coastguard Worker  protected:
SetUp()54*e01b6f76SAndroid Build Coastguard Worker     virtual void SetUp() {
55*e01b6f76SAndroid Build Coastguard Worker         FingerprintModule::SetUp();
56*e01b6f76SAndroid Build Coastguard Worker         hw_device_t *device = NULL;
57*e01b6f76SAndroid Build Coastguard Worker         ASSERT_TRUE(NULL != fp_module()->common.methods->open)
58*e01b6f76SAndroid Build Coastguard Worker                     << "Fingerprint open() is unimplemented";
59*e01b6f76SAndroid Build Coastguard Worker         ASSERT_EQ(0, fp_module()->common.methods->open(
60*e01b6f76SAndroid Build Coastguard Worker             (const hw_module_t*)fp_module(), NULL, &device))
61*e01b6f76SAndroid Build Coastguard Worker                 << "Can't open fingerprint device";
62*e01b6f76SAndroid Build Coastguard Worker         ASSERT_TRUE(NULL != device)
63*e01b6f76SAndroid Build Coastguard Worker                     << "Fingerprint open() returned a NULL device";
64*e01b6f76SAndroid Build Coastguard Worker         ASSERT_EQ(kVersion, device->version)
65*e01b6f76SAndroid Build Coastguard Worker                     << "Unsupported version";
66*e01b6f76SAndroid Build Coastguard Worker         fp_device_ = reinterpret_cast<fingerprint_device_t*>(device);
67*e01b6f76SAndroid Build Coastguard Worker     }
fp_device()68*e01b6f76SAndroid Build Coastguard Worker     fingerprint_device_t* fp_device() { return fp_device_; }
69*e01b6f76SAndroid Build Coastguard Worker  private:
70*e01b6f76SAndroid Build Coastguard Worker     fingerprint_device_t *fp_device_;
71*e01b6f76SAndroid Build Coastguard Worker };
72*e01b6f76SAndroid Build Coastguard Worker 
73*e01b6f76SAndroid Build Coastguard Worker }  // namespace tests
74*e01b6f76SAndroid Build Coastguard Worker 
75*e01b6f76SAndroid Build Coastguard Worker #endif  // __ANDROID_HAL_FINGERPRINT_TEST_COMMON__
76