|
18 | 18 |
|
19 | 19 | #include <android-base/logging.h> |
20 | 20 | #include <gtest/gtest.h> |
| 21 | +#include <input/AccelerationCurve.h> |
21 | 22 |
|
| 23 | +#include <log/log.h> |
22 | 24 | #include <thread> |
23 | 25 | #include "InputMapperTest.h" |
24 | 26 | #include "InterfaceMocks.h" |
| 27 | +#include "TestConstants.h" |
25 | 28 | #include "TestEventMatchers.h" |
26 | 29 |
|
27 | 30 | #define TAG "TouchpadInputMapper_test" |
@@ -190,4 +193,67 @@ TEST_F(TouchpadInputMapperTest, TouchpadHardwareState) { |
190 | 193 | mFakePolicy->assertTouchpadHardwareStateNotified(); |
191 | 194 | } |
192 | 195 |
|
| 196 | +TEST_F(TouchpadInputMapperTest, TouchpadAccelerationDisabled) { |
| 197 | + mReaderConfiguration.touchpadAccelerationEnabled = false; |
| 198 | + mReaderConfiguration.touchpadPointerSpeed = 3; |
| 199 | + |
| 200 | + std::list<NotifyArgs> args = |
| 201 | + mMapper->reconfigure(ARBITRARY_TIME, mReaderConfiguration, |
| 202 | + InputReaderConfiguration::Change::TOUCHPAD_SETTINGS); |
| 203 | + auto* touchpadMapper = static_cast<TouchpadInputMapper*>(mMapper.get()); |
| 204 | + |
| 205 | + const auto accelCurvePropsDisabled = |
| 206 | + touchpadMapper->getGesturePropertyForTesting("Pointer Accel Curve"); |
| 207 | + ASSERT_TRUE(accelCurvePropsDisabled.has_value()); |
| 208 | + std::vector<double> curveValuesDisabled = accelCurvePropsDisabled.value().getRealValues(); |
| 209 | + std::vector<AccelerationCurveSegment> curve = |
| 210 | + createFlatAccelerationCurve(mReaderConfiguration.touchpadPointerSpeed); |
| 211 | + double expectedBaseGain = curve[0].baseGain; |
| 212 | + ASSERT_EQ(curveValuesDisabled[0], std::numeric_limits<double>::infinity()); |
| 213 | + ASSERT_EQ(curveValuesDisabled[1], 0); |
| 214 | + ASSERT_NEAR(curveValuesDisabled[2], expectedBaseGain, EPSILON); |
| 215 | + ASSERT_EQ(curveValuesDisabled[3], 0); |
| 216 | +} |
| 217 | + |
| 218 | +TEST_F(TouchpadInputMapperTest, TouchpadAccelerationEnabled) { |
| 219 | + // Enable touchpad acceleration. |
| 220 | + mReaderConfiguration.touchpadAccelerationEnabled = true; |
| 221 | + mReaderConfiguration.touchpadPointerSpeed = 3; |
| 222 | + |
| 223 | + std::list<NotifyArgs> args = |
| 224 | + mMapper->reconfigure(ARBITRARY_TIME, mReaderConfiguration, |
| 225 | + InputReaderConfiguration::Change::TOUCHPAD_SETTINGS); |
| 226 | + ASSERT_THAT(args, testing::IsEmpty()); |
| 227 | + |
| 228 | + auto* touchpadMapper = static_cast<TouchpadInputMapper*>(mMapper.get()); |
| 229 | + |
| 230 | + // Get the acceleration curve properties when acceleration is enabled. |
| 231 | + const auto accelCurvePropsEnabled = |
| 232 | + touchpadMapper->getGesturePropertyForTesting("Pointer Accel Curve"); |
| 233 | + ASSERT_TRUE(accelCurvePropsEnabled.has_value()); |
| 234 | + |
| 235 | + // Get the curve values. |
| 236 | + std::vector<double> curveValuesEnabled = accelCurvePropsEnabled.value().getRealValues(); |
| 237 | + |
| 238 | + // Use createAccelerationCurveForPointerSensitivity to get expected curve segments. |
| 239 | + std::vector<AccelerationCurveSegment> expectedCurveSegments = |
| 240 | + createAccelerationCurveForPointerSensitivity(mReaderConfiguration.touchpadPointerSpeed); |
| 241 | + |
| 242 | + // Iterate through the segments and compare the values. |
| 243 | + for (size_t i = 0; i < expectedCurveSegments.size(); ++i) { |
| 244 | + // Check max speed. |
| 245 | + if (std::isinf(expectedCurveSegments[i].maxPointerSpeedMmPerS)) { |
| 246 | + ASSERT_TRUE(std::isinf(curveValuesEnabled[i * 4 + 0])); |
| 247 | + } else { |
| 248 | + ASSERT_NEAR(curveValuesEnabled[i * 4 + 0], |
| 249 | + expectedCurveSegments[i].maxPointerSpeedMmPerS, EPSILON); |
| 250 | + } |
| 251 | + |
| 252 | + // Check that the x^2 term is zero. |
| 253 | + ASSERT_NEAR(curveValuesEnabled[i * 4 + 1], 0, EPSILON); |
| 254 | + ASSERT_NEAR(curveValuesEnabled[i * 4 + 2], expectedCurveSegments[i].baseGain, EPSILON); |
| 255 | + ASSERT_NEAR(curveValuesEnabled[i * 4 + 3], expectedCurveSegments[i].reciprocal, EPSILON); |
| 256 | + } |
| 257 | +} |
| 258 | + |
193 | 259 | } // namespace android |
0 commit comments