CursorInputMapper: move unit tests to InputMapperUnitTest
This puts most of CursorInputMapper's unit tests in one place
(CursorInputMapper_test.cpp) and under one input mapper testing system,
which will hopefully simplify future additions to the tests. The only
CursorInputMapper tests remaining to be migrated are those which rely on
setting an associated viewport, which I'm saving for a follow-up CL
since they'll need the introduction of a fake InputDeviceContext.
Also make a few smaller clean-ups:
* underscores have been removed from test names, as they can cause
problems in gTest;
* assertions have been moved to the newer style using matchers,
improving conciseness and readability;
* tests for the creation of NotifyKeyArgs for certain mouse buttons have
been parameterized.
Bug: 283812079
Test: atest inputflinger_tests
Change-Id: I0f0307dc57edcc62d0ce24b15bf0d9e8b8b915c6
diff --git a/services/inputflinger/tests/InputMapperTest.cpp b/services/inputflinger/tests/InputMapperTest.cpp
index b9d7f4a..5f43bd2 100644
--- a/services/inputflinger/tests/InputMapperTest.cpp
+++ b/services/inputflinger/tests/InputMapperTest.cpp
@@ -25,7 +25,7 @@
using testing::Return;
-void InputMapperUnitTest::SetUp() {
+void InputMapperUnitTest::SetUpWithBus(int bus) {
mFakePointerController = std::make_shared<FakePointerController>();
mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
mFakePointerController->setPosition(INITIAL_CURSOR_X, INITIAL_CURSOR_Y);
@@ -40,9 +40,12 @@
mIdentifier.name = "device";
mIdentifier.location = "USB1";
- mIdentifier.bus = 0;
+ mIdentifier.bus = bus;
EXPECT_CALL(mMockEventHub, getDeviceIdentifier(EVENTHUB_ID))
.WillRepeatedly(Return(mIdentifier));
+ EXPECT_CALL(mMockEventHub, getConfiguration(EVENTHUB_ID)).WillRepeatedly([&](int32_t) {
+ return mPropertyMap;
+ });
}
void InputMapperUnitTest::createDevice() {
@@ -222,8 +225,8 @@
return generatedArgs;
}
-void InputMapperTest::assertMotionRange(const InputDeviceInfo& info, int32_t axis, uint32_t source,
- float min, float max, float flat, float fuzz) {
+void assertMotionRange(const InputDeviceInfo& info, int32_t axis, uint32_t source, float min,
+ float max, float flat, float fuzz) {
const InputDeviceInfo::MotionRange* range = info.getMotionRange(axis, source);
ASSERT_TRUE(range != nullptr) << "Axis: " << axis << " Source: " << source;
ASSERT_EQ(axis, range->axis) << "Axis: " << axis << " Source: " << source;
@@ -234,11 +237,9 @@
ASSERT_NEAR(fuzz, range->fuzz, EPSILON) << "Axis: " << axis << " Source: " << source;
}
-void InputMapperTest::assertPointerCoords(const PointerCoords& coords, float x, float y,
- float pressure, float size, float touchMajor,
- float touchMinor, float toolMajor, float toolMinor,
- float orientation, float distance,
- float scaledAxisEpsilon) {
+void assertPointerCoords(const PointerCoords& coords, float x, float y, float pressure, float size,
+ float touchMajor, float touchMinor, float toolMajor, float toolMinor,
+ float orientation, float distance, float scaledAxisEpsilon) {
ASSERT_NEAR(x, coords.getAxisValue(AMOTION_EVENT_AXIS_X), scaledAxisEpsilon);
ASSERT_NEAR(y, coords.getAxisValue(AMOTION_EVENT_AXIS_Y), scaledAxisEpsilon);
ASSERT_NEAR(pressure, coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), EPSILON);