InputMapperUnitTest: extract device creation from SetUp
When device creation occurs, configuration properties are copied from
the property map returned by EventHub::getConfiguration into the device
object. For this reason, some tests (such as the CursorInputMapper tests
that have yet to be migrated to InputMapperUnitTest) need to run some
setup code before the device is created. Other tests can simply call
createDevice immediately after InputMapperUnitTest::SetUp in their own
SetUp methods.
Bug: 283812079
Test: atest inputflinger_tests
Change-Id: I3ae3d407fb14e8f8ff061ec617003f423bce3f5e
diff --git a/services/inputflinger/tests/InputMapperTest.cpp b/services/inputflinger/tests/InputMapperTest.cpp
index 36be684..b9d7f4a 100644
--- a/services/inputflinger/tests/InputMapperTest.cpp
+++ b/services/inputflinger/tests/InputMapperTest.cpp
@@ -19,6 +19,7 @@
#include <InputReaderBase.h>
#include <gtest/gtest.h>
#include <ui/Rotation.h>
+#include <utils/Timers.h>
namespace android {
@@ -36,15 +37,21 @@
EXPECT_CALL(mMockInputReaderContext, getPolicy()).WillRepeatedly(Return(mFakePolicy.get()));
EXPECT_CALL(mMockInputReaderContext, getEventHub()).WillRepeatedly(Return(&mMockEventHub));
- InputDeviceIdentifier identifier;
- identifier.name = "device";
- identifier.location = "USB1";
- identifier.bus = 0;
- EXPECT_CALL(mMockEventHub, getDeviceIdentifier(EVENTHUB_ID)).WillRepeatedly(Return(identifier));
+ mIdentifier.name = "device";
+ mIdentifier.location = "USB1";
+ mIdentifier.bus = 0;
+ EXPECT_CALL(mMockEventHub, getDeviceIdentifier(EVENTHUB_ID))
+ .WillRepeatedly(Return(mIdentifier));
+}
+
+void InputMapperUnitTest::createDevice() {
mDevice = std::make_unique<InputDevice>(&mMockInputReaderContext, DEVICE_ID,
- /*generation=*/2, identifier);
+ /*generation=*/2, mIdentifier);
+ mDevice->addEmptyEventHubDevice(EVENTHUB_ID);
mDeviceContext = std::make_unique<InputDeviceContext>(*mDevice, EVENTHUB_ID);
+ std::list<NotifyArgs> _ =
+ mDevice->configure(systemTime(), mReaderConfiguration, /*changes=*/{});
}
void InputMapperUnitTest::setupAxis(int axis, bool valid, int32_t min, int32_t max,