• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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 #ifndef __ANDROID_HAL_FINGERPRINT_TEST_COMMON__
18 #define __ANDROID_HAL_FINGERPRINT_TEST_COMMON__
19 
20 #include <gtest/gtest.h>
21 #include <hardware/hardware.h>
22 #include <hardware/fingerprint.h>
23 
24 namespace tests {
25 
26 static const uint16_t kVersion = HARDWARE_MODULE_API_VERSION(1, 0);
27 
28 class FingerprintModule : public testing::Test {
29  public:
FingerprintModule()30     FingerprintModule() :
31         fp_module_(NULL) {}
~FingerprintModule()32     ~FingerprintModule() {}
33  protected:
SetUp()34     virtual void SetUp() {
35         const hw_module_t *hw_module = NULL;
36         ASSERT_EQ(0, hw_get_module(FINGERPRINT_HARDWARE_MODULE_ID, &hw_module))
37                     << "Can't get fingerprint module";
38         ASSERT_TRUE(NULL != hw_module)
39                     << "hw_get_module didn't return a valid fingerprint module";
40 
41         fp_module_ = reinterpret_cast<const fingerprint_module_t*>(hw_module);
42     }
fp_module()43     const fingerprint_module_t* fp_module() { return fp_module_; }
44  private:
45     const fingerprint_module_t *fp_module_;
46 };
47 
48 class FingerprintDevice : public FingerprintModule {
49  public:
FingerprintDevice()50     FingerprintDevice() :
51         fp_device_(NULL) {}
~FingerprintDevice()52     ~FingerprintDevice() {}
53  protected:
SetUp()54     virtual void SetUp() {
55         FingerprintModule::SetUp();
56         hw_device_t *device = NULL;
57         ASSERT_TRUE(NULL != fp_module()->common.methods->open)
58                     << "Fingerprint open() is unimplemented";
59         ASSERT_EQ(0, fp_module()->common.methods->open(
60             (const hw_module_t*)fp_module(), NULL, &device))
61                 << "Can't open fingerprint device";
62         ASSERT_TRUE(NULL != device)
63                     << "Fingerprint open() returned a NULL device";
64         ASSERT_EQ(kVersion, device->version)
65                     << "Unsupported version";
66         fp_device_ = reinterpret_cast<fingerprint_device_t*>(device);
67     }
fp_device()68     fingerprint_device_t* fp_device() { return fp_device_; }
69  private:
70     fingerprint_device_t *fp_device_;
71 };
72 
73 }  // namespace tests
74 
75 #endif  // __ANDROID_HAL_FINGERPRINT_TEST_COMMON__
76