blob: 7c0021fb26a878ebcee5204985b9e96bb3fc42ad [file] [log] [blame]
Jeff Pu63f33c72022-07-28 16:06:23 -04001/*
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
26using namespace ::android::fingerprint::virt;
27using namespace ::aidl::android::hardware::biometrics::fingerprint;
28using namespace ::aidl::android::hardware::keymaster;
29
30namespace aidl::android::hardware::biometrics::fingerprint {
31
32class 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
44bool isDefaultLocation(SensorLocation& sc) {
45 return (sc.sensorLocationX == FakeFingerprintEngineUdfps::defaultSensorLocationX &&
46 sc.sensorLocationY == FakeFingerprintEngineUdfps::defaultSensorLocationY &&
47 sc.sensorRadius == FakeFingerprintEngineUdfps::defaultSensorRadius && sc.display == "");
48}
49
Jeff Pu343ca942022-09-14 15:56:30 -040050TEST_F(FakeFingerprintEngineUdfpsTest, getSensorLocationOk) {
Jeff Pu63f33c72022-07-28 16:06:23 -040051 auto loc = "100:200:30";
52 FingerprintHalProperties::sensor_location(loc);
Jeff Pu343ca942022-09-14 15:56:30 -040053 SensorLocation sc = mEngine.getSensorLocation();
Jeff Pu63f33c72022-07-28 16:06:23 -040054 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 Pu343ca942022-09-14 15:56:30 -040065}
Jeff Pu63f33c72022-07-28 16:06:23 -040066
Jeff Pu343ca942022-09-14 15:56:30 -040067TEST_F(FakeFingerprintEngineUdfpsTest, getSensorLocationBad) {
68 FingerprintHalProperties::sensor_location("");
69 SensorLocation sc = mEngine.getSensorLocation();
70 ASSERT_TRUE(isDefaultLocation(sc));
71
72 auto loc = "100";
Jeff Pu63f33c72022-07-28 16:06:23 -040073 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