Add touchscreen rotation precision tests
Add tests to verify that a touchscreen that is associated with a display
produces exactly the correct coordinates in four of the display's
orientations.
In these tests, the touchscreen is configured in the default
orientation. We then verify that when the display is rotated,
we get the expected values.
Bug: 236798672
Bug: 257118693
Test: atest inputflinger_tests
Change-Id: Ibf98556406c7eda09a747ebb61a402a9d5bd8539
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index eb7f082..9892697 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -6990,6 +6990,44 @@
}
}
+TEST_P(TouchscreenPrecisionTestsFixture, RotationPrecisionWhenOrientationAware) {
+ static const std::map<ui::Rotation /*rotation*/, std::array<vec2, 4> /*mappedCorners*/>
+ kMappedCorners = {
+ {ui::ROTATION_0, {{{0, 0}, {479.5, 0}, {479.5, 799.75}, {0, 799.75}}}},
+ {ui::ROTATION_90, {{{0.5, 0}, {480, 0}, {480, 799.75}, {0.5, 799.75}}}},
+ {ui::ROTATION_180, {{{0.5, 0.25}, {480, 0.25}, {480, 800}, {0.5, 800}}}},
+ {ui::ROTATION_270, {{{0, 0.25}, {479.5, 0.25}, {479.5, 800}, {0, 800}}}},
+ };
+
+ const ui::Rotation displayRotation = GetParam();
+
+ addConfigurationProperty("touch.deviceType", "touchScreen");
+ prepareDisplay(displayRotation);
+
+ SingleTouchInputMapper& mapper = addMapperAndConfigure<SingleTouchInputMapper>();
+
+ const auto& expectedPoints = kMappedCorners.at(displayRotation);
+
+ // Test all four corners.
+ for (int i = 0; i < 4; i++) {
+ const auto& expected = expectedPoints[i];
+ const auto& raw = kRawCorners[i];
+ processDown(mapper, raw.x, raw.y);
+ processSync(mapper);
+ ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(
+ AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
+ WithCoords(expected.x, expected.y), WithPrecision(2, 4))))
+ << "Failed to process raw point (" << raw.x << ", " << raw.y << ") "
+ << "with display rotation " << ui::toCString(displayRotation)
+ << ", expected point (" << expected.x << ", " << expected.y << ").";
+ processUp(mapper);
+ processSync(mapper);
+ ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(
+ AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
+ WithCoords(expected.x, expected.y))));
+ }
+}
+
// Run the precision tests for all rotations.
INSTANTIATE_TEST_SUITE_P(TouchscreenPrecisionTests, TouchscreenPrecisionTestsFixture,
::testing::Values(ui::ROTATION_0, ui::ROTATION_90, ui::ROTATION_180,