Jeff Pu | 63f33c7 | 2022-07-28 16:06:23 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 | #include <android/binder_process.h> |
| 18 | #include <fingerprint.sysprop.h> |
| 19 | #include <gtest/gtest.h> |
| 20 | |
| 21 | #include <android-base/logging.h> |
| 22 | |
| 23 | #include "FakeFingerprintEngine.h" |
| 24 | #include "FakeFingerprintEngineUdfps.h" |
| 25 | |
| 26 | using namespace ::android::fingerprint::virt; |
| 27 | using namespace ::aidl::android::hardware::biometrics::fingerprint; |
| 28 | using namespace ::aidl::android::hardware::keymaster; |
| 29 | |
| 30 | namespace aidl::android::hardware::biometrics::fingerprint { |
| 31 | |
| 32 | class FakeFingerprintEngineUdfpsTest : public ::testing::Test { |
| 33 | protected: |
| 34 | void SetUp() override {} |
| 35 | |
| 36 | void TearDown() override { |
| 37 | // reset to default |
| 38 | FingerprintHalProperties::sensor_location(""); |
| 39 | } |
| 40 | |
| 41 | FakeFingerprintEngineUdfps mEngine; |
| 42 | }; |
| 43 | |
| 44 | bool isDefaultLocation(SensorLocation& sc) { |
| 45 | return (sc.sensorLocationX == FakeFingerprintEngineUdfps::defaultSensorLocationX && |
| 46 | sc.sensorLocationY == FakeFingerprintEngineUdfps::defaultSensorLocationY && |
| 47 | sc.sensorRadius == FakeFingerprintEngineUdfps::defaultSensorRadius && sc.display == ""); |
| 48 | } |
| 49 | |
Jeff Pu | 343ca94 | 2022-09-14 15:56:30 -0400 | [diff] [blame] | 50 | TEST_F(FakeFingerprintEngineUdfpsTest, getSensorLocationOk) { |
Jeff Pu | 63f33c7 | 2022-07-28 16:06:23 -0400 | [diff] [blame] | 51 | auto loc = "100:200:30"; |
| 52 | FingerprintHalProperties::sensor_location(loc); |
Jeff Pu | 343ca94 | 2022-09-14 15:56:30 -0400 | [diff] [blame] | 53 | SensorLocation sc = mEngine.getSensorLocation(); |
Jeff Pu | 63f33c7 | 2022-07-28 16:06:23 -0400 | [diff] [blame] | 54 | ASSERT_TRUE(sc.sensorLocationX == 100); |
| 55 | ASSERT_TRUE(sc.sensorLocationY == 200); |
| 56 | ASSERT_TRUE(sc.sensorRadius == 30); |
| 57 | |
| 58 | loc = "100:200:30:screen1"; |
| 59 | FingerprintHalProperties::sensor_location(loc); |
| 60 | sc = mEngine.getSensorLocation(); |
| 61 | ASSERT_TRUE(sc.sensorLocationX == 100); |
| 62 | ASSERT_TRUE(sc.sensorLocationY == 200); |
| 63 | ASSERT_TRUE(sc.sensorRadius == 30); |
| 64 | ASSERT_TRUE(sc.display == "screen1"); |
Jeff Pu | 343ca94 | 2022-09-14 15:56:30 -0400 | [diff] [blame] | 65 | } |
Jeff Pu | 63f33c7 | 2022-07-28 16:06:23 -0400 | [diff] [blame] | 66 | |
Jeff Pu | 343ca94 | 2022-09-14 15:56:30 -0400 | [diff] [blame] | 67 | TEST_F(FakeFingerprintEngineUdfpsTest, getSensorLocationBad) { |
| 68 | FingerprintHalProperties::sensor_location(""); |
| 69 | SensorLocation sc = mEngine.getSensorLocation(); |
| 70 | ASSERT_TRUE(isDefaultLocation(sc)); |
| 71 | |
| 72 | auto loc = "100"; |
Jeff Pu | 63f33c7 | 2022-07-28 16:06:23 -0400 | [diff] [blame] | 73 | FingerprintHalProperties::sensor_location(loc); |
| 74 | sc = mEngine.getSensorLocation(); |
| 75 | ASSERT_TRUE(isDefaultLocation(sc)); |
| 76 | |
| 77 | loc = "10:20"; |
| 78 | FingerprintHalProperties::sensor_location(loc); |
| 79 | sc = mEngine.getSensorLocation(); |
| 80 | ASSERT_TRUE(isDefaultLocation(sc)); |
| 81 | |
| 82 | loc = "10,20,5"; |
| 83 | FingerprintHalProperties::sensor_location(loc); |
| 84 | sc = mEngine.getSensorLocation(); |
| 85 | ASSERT_TRUE(isDefaultLocation(sc)); |
| 86 | |
| 87 | loc = "a:b:c"; |
| 88 | FingerprintHalProperties::sensor_location(loc); |
| 89 | sc = mEngine.getSensorLocation(); |
| 90 | ASSERT_TRUE(isDefaultLocation(sc)); |
| 91 | } |
| 92 | |
| 93 | // More |
| 94 | } // namespace aidl::android::hardware::biometrics::fingerprint |