Mock InputDevice in the InputMapper unit tests
This makes the InputMapperUnitTest subclasses easier to test, as the
tests will not have to rely on the behavior of actual InputDevice
implementation.
Unfortunately, this means InputDevice must now be a virtual class to
allow its mocked subclass to define its behavior for the methods that we
want to change. In this CL, we take the approach of only marking the
methods that we need to customize as virtual to avoid the overhead of
vtable lookups at runtime.
An alternative approach would be to introduce a type parameter to
InputDeviceContext to allow us to specify a different InputDevice
implementation in the tests. This would eliminate any addtional runtime
overheads resulting from vtable lookups. However, this would mean every
InputMapper class would need to have this new type parameter, adding
verbosity and complextity to the codebase. For this reason, the virtual
member approach was preferred.
Bug: 354270482
Bug: 353128452
Test: atest inputflinger_tests
Flag: EXEMPT refactor
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:31d05c4c78e7924e4bb6dc45092e612a9c7d5bfb)
Merged-In: Id7e103e1f04812c92ee8ecfdfe1e75a9949efa9e
Change-Id: Id7e103e1f04812c92ee8ecfdfe1e75a9949efa9e
diff --git a/services/inputflinger/tests/InputMapperTest.h b/services/inputflinger/tests/InputMapperTest.h
index 5bd8cda..870e11b 100644
--- a/services/inputflinger/tests/InputMapperTest.h
+++ b/services/inputflinger/tests/InputMapperTest.h
@@ -43,13 +43,6 @@
virtual void SetUp() override { SetUpWithBus(0); }
virtual void SetUpWithBus(int bus);
- /**
- * Initializes mDevice and mDeviceContext. When this happens, mDevice takes a copy of
- * mPropertyMap, so tests that need to set configuration properties should do so before calling
- * this. Others will most likely want to call it in their SetUp method.
- */
- void createDevice();
-
void setupAxis(int axis, bool valid, int32_t min, int32_t max, int32_t resolution);
void expectScanCodes(bool present, std::set<int> scanCodes);
@@ -65,7 +58,7 @@
MockEventHubInterface mMockEventHub;
sp<FakeInputReaderPolicy> mFakePolicy;
MockInputReaderContext mMockInputReaderContext;
- std::unique_ptr<InputDevice> mDevice;
+ std::unique_ptr<MockInputDevice> mDevice;
std::unique_ptr<InputDeviceContext> mDeviceContext;
InputReaderConfiguration mReaderConfiguration;