Skip to content

Commit d62330d

Browse files
committed
KeyboardInputMapper: migrate most tests to InputMapperUnitTest
Some of these tests create multiple input devices and mappers, which I didn't have time to work out how to mimic using InputMapperUnitTest. The rest have been migrated. Notes: * Split out Process_UnknownKey from Process_SimpleKeyPress, since it's a separate behaviour to test * As far as I can tell, Process_KeyRemapping was just testing the remapping code in FakeEventHub, so I removed it * Process_WhenNotOrientationAware_ShouldNotRotateDPad now checks for a display ID of DISPLAY_ID, not INVALID. This is because the method called by KeyboardInputMapper to check orientation (getAssociatedViewport) will never return an orientation without also returning a valid display ID; setting one without the other appears to have been possible in the old testing infrastructure, but would only have affected state somewhere outside of KeyboardInputMapper. For similar reasons, removed the second half of DisplayIdConfigurationChange_NotOrientationAware. * MarkSupportedKeyCodes was removed, as the code to test it would have been too bulky to test a trivial one-liner (and it would basically have been a change detector). Test: atest --host inputflinger_tests Bug: 283812079 Flag: TEST_ONLY Change-Id: Id6d2eb4ec2bae6bd0e9a263209169785e40a6024
1 parent 6e56673 commit d62330d

6 files changed

Lines changed: 544 additions & 548 deletions

File tree

include/input/Input.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ enum class KeyboardType {
294294
NONE = AINPUT_KEYBOARD_TYPE_NONE,
295295
NON_ALPHABETIC = AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC,
296296
ALPHABETIC = AINPUT_KEYBOARD_TYPE_ALPHABETIC,
297+
ftl_first = NONE,
298+
ftl_last = ALPHABETIC,
297299
};
298300

299301
bool isStylusToolType(ToolType toolType);

services/inputflinger/reader/include/InputDevice.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class InputDevice {
4848
inline InputReaderContext* getContext() { return mContext; }
4949
inline int32_t getId() const { return mId; }
5050
inline int32_t getControllerNumber() const { return mControllerNumber; }
51-
inline int32_t getGeneration() const { return mGeneration; }
51+
inline virtual int32_t getGeneration() const { return mGeneration; }
5252
inline const std::string getName() const { return mIdentifier.name; }
5353
inline const std::string getDescriptor() { return mIdentifier.descriptor; }
5454
inline std::optional<std::string> getBluetoothAddress() const {
@@ -59,7 +59,7 @@ class InputDevice {
5959
inline virtual uint32_t getSources() const { return mSources; }
6060
inline bool hasEventHubDevices() const { return !mDevices.empty(); }
6161

62-
inline bool isExternal() { return mIsExternal; }
62+
inline virtual bool isExternal() { return mIsExternal; }
6363
inline std::optional<uint8_t> getAssociatedDisplayPort() const {
6464
return mAssociatedDisplayPort;
6565
}
@@ -79,7 +79,7 @@ class InputDevice {
7979

8080
inline bool isIgnored() { return !getMapperCount() && !mController; }
8181

82-
inline KeyboardType getKeyboardType() const { return mKeyboardType; }
82+
inline virtual KeyboardType getKeyboardType() const { return mKeyboardType; }
8383

8484
bool isEnabled();
8585

@@ -124,7 +124,7 @@ class InputDevice {
124124
int32_t getMetaState();
125125
void setKeyboardType(KeyboardType keyboardType);
126126

127-
void bumpGeneration();
127+
virtual void bumpGeneration();
128128

129129
[[nodiscard]] NotifyDeviceResetArgs notifyReset(nsecs_t when);
130130

services/inputflinger/tests/InputMapperTest.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,14 @@ std::list<NotifyArgs> InputMapperUnitTest::process(int32_t type, int32_t code, i
100100

101101
std::list<NotifyArgs> InputMapperUnitTest::process(nsecs_t when, int32_t type, int32_t code,
102102
int32_t value) {
103+
return process(when, when, type, code, value);
104+
}
105+
106+
std::list<NotifyArgs> InputMapperUnitTest::process(nsecs_t when, nsecs_t readTime, int32_t type,
107+
int32_t code, int32_t value) {
103108
RawEvent event;
104109
event.when = when;
105-
event.readTime = when;
110+
event.readTime = readTime;
106111
event.deviceId = mMapper->getDeviceContext().getEventHubId();
107112
event.type = type;
108113
event.code = code;

services/inputflinger/tests/InputMapperTest.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class InputMapperUnitTest : public testing::Test {
5656

5757
std::list<NotifyArgs> process(int32_t type, int32_t code, int32_t value);
5858
std::list<NotifyArgs> process(nsecs_t when, int32_t type, int32_t code, int32_t value);
59+
std::list<NotifyArgs> process(nsecs_t when, nsecs_t readTime, int32_t type, int32_t code,
60+
int32_t value);
5961

6062
InputDeviceIdentifier mIdentifier;
6163
MockEventHubInterface mMockEventHub;

services/inputflinger/tests/InterfaceMocks.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ class MockInputDevice : public InputDevice {
201201

202202
MOCK_METHOD(uint32_t, getSources, (), (const, override));
203203
MOCK_METHOD(std::optional<DisplayViewport>, getAssociatedViewport, (), (const));
204+
MOCK_METHOD(KeyboardType, getKeyboardType, (), (const, override));
204205
MOCK_METHOD(bool, isEnabled, (), ());
206+
MOCK_METHOD(bool, isExternal, (), (override));
205207

206208
MOCK_METHOD(void, dump, (std::string& dump, const std::string& eventHubDevStr), ());
207209
MOCK_METHOD(void, addEmptyEventHubDevice, (int32_t eventHubId), ());
@@ -249,8 +251,6 @@ class MockInputDevice : public InputDevice {
249251
MOCK_METHOD(int32_t, getMetaState, (), ());
250252
MOCK_METHOD(void, setKeyboardType, (KeyboardType keyboardType), ());
251253

252-
MOCK_METHOD(void, bumpGeneration, (), ());
253-
254254
MOCK_METHOD(const PropertyMap&, getConfiguration, (), (const, override));
255255

256256
MOCK_METHOD(NotifyDeviceResetArgs, notifyReset, (nsecs_t when), ());
@@ -260,5 +260,11 @@ class MockInputDevice : public InputDevice {
260260
MOCK_METHOD(void, updateLedState, (bool reset), ());
261261

262262
MOCK_METHOD(size_t, getMapperCount, (), ());
263+
264+
virtual int32_t getGeneration() const override { return mGeneration; }
265+
virtual void bumpGeneration() override { mGeneration++; }
266+
267+
private:
268+
int32_t mGeneration = 0;
263269
};
264270
} // namespace android

0 commit comments

Comments
 (0)