Skip to content

Commit 9c99cc1

Browse files
Treehugger RobotAndroid (Google) Code Review
authored andcommitted
Merge "Mocked device should be consistently external or internal" into main
2 parents 87cf0ef + 2f8c71a commit 9c99cc1

7 files changed

Lines changed: 24 additions & 21 deletions

services/inputflinger/tests/CursorInputMapper_test.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ namespace vd_flags = android::companion::virtualdevice::flags;
141141
*/
142142
class CursorInputMapperUnitTestBase : public InputMapperUnitTest {
143143
protected:
144-
void SetUp() override { SetUpWithBus(BUS_USB); }
145-
void SetUpWithBus(int bus) override {
146-
InputMapperUnitTest::SetUpWithBus(bus);
144+
void SetUp() override { SetUp(BUS_USB, /*isExternal=*/false); }
145+
void SetUp(int bus, bool isExternal) override {
146+
InputMapperUnitTest::SetUp(bus, isExternal);
147147

148148
// Current scan code state - all keys are UP by default
149149
setScanCodeState(KeyState::UP,
@@ -1142,7 +1142,9 @@ constexpr nsecs_t MAX_BLUETOOTH_SMOOTHING_DELTA = ms2ns(32);
11421142

11431143
class BluetoothCursorInputMapperUnitTest : public CursorInputMapperUnitTestBase {
11441144
protected:
1145-
void SetUp() override { SetUpWithBus(BUS_BLUETOOTH); }
1145+
void SetUp() override {
1146+
CursorInputMapperUnitTestBase::SetUp(BUS_BLUETOOTH, /*isExternal=*/true);
1147+
}
11461148
};
11471149

11481150
TEST_F(BluetoothCursorInputMapperUnitTest, TimestampSmoothening) {

services/inputflinger/tests/InputMapperTest.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ using testing::NiceMock;
3030
using testing::Return;
3131
using testing::ReturnRef;
3232

33-
void InputMapperUnitTest::SetUpWithBus(int bus) {
33+
void InputMapperUnitTest::SetUp(int bus, bool isExternal) {
3434
mFakePolicy = sp<FakeInputReaderPolicy>::make();
3535

3636
EXPECT_CALL(mMockInputReaderContext, getPolicy()).WillRepeatedly(Return(mFakePolicy.get()));
@@ -46,8 +46,9 @@ void InputMapperUnitTest::SetUpWithBus(int bus) {
4646
return mPropertyMap;
4747
});
4848

49-
mDevice = std::make_unique<NiceMock<MockInputDevice>>(&mMockInputReaderContext, DEVICE_ID,
50-
/*generation=*/2, mIdentifier);
49+
mDevice =
50+
std::make_unique<NiceMock<MockInputDevice>>(&mMockInputReaderContext, DEVICE_ID,
51+
/*generation=*/2, mIdentifier, isExternal);
5152
ON_CALL((*mDevice), getConfiguration).WillByDefault(ReturnRef(mPropertyMap));
5253
mDeviceContext = std::make_unique<InputDeviceContext>(*mDevice, EVENTHUB_ID);
5354
}

services/inputflinger/tests/InputMapperTest.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class InputMapperUnitTest : public testing::Test {
4040
protected:
4141
static constexpr int32_t EVENTHUB_ID = 1;
4242
static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000;
43-
virtual void SetUp() override { SetUpWithBus(0); }
44-
virtual void SetUpWithBus(int bus);
43+
virtual void SetUp() override { SetUp(/*bus=*/0, /*isExternal=*/false); }
44+
virtual void SetUp(int bus, bool isExternal);
4545

4646
void setupAxis(int axis, bool valid, int32_t min, int32_t max, int32_t resolution,
4747
int32_t flat = 0, int32_t fuzz = 0);

services/inputflinger/tests/InterfaceMocks.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,14 @@ class MockPointerChoreographerPolicyInterface : public PointerChoreographerPolic
196196
class MockInputDevice : public InputDevice {
197197
public:
198198
MockInputDevice(InputReaderContext* context, int32_t id, int32_t generation,
199-
const InputDeviceIdentifier& identifier)
200-
: InputDevice(context, id, generation, identifier) {}
199+
const InputDeviceIdentifier& identifier, bool isExternal)
200+
: InputDevice(context, id, generation, identifier), mIsExternal(isExternal) {}
201201

202202
MOCK_METHOD(uint32_t, getSources, (), (const, override));
203203
MOCK_METHOD(std::optional<DisplayViewport>, getAssociatedViewport, (), (const));
204204
MOCK_METHOD(KeyboardType, getKeyboardType, (), (const, override));
205205
MOCK_METHOD(bool, isEnabled, (), ());
206-
MOCK_METHOD(bool, isExternal, (), (override));
206+
bool isExternal() override { return mIsExternal; }
207207

208208
MOCK_METHOD(void, dump, (std::string& dump, const std::string& eventHubDevStr), ());
209209
MOCK_METHOD(void, addEmptyEventHubDevice, (int32_t eventHubId), ());
@@ -266,5 +266,6 @@ class MockInputDevice : public InputDevice {
266266

267267
private:
268268
int32_t mGeneration = 0;
269+
const bool mIsExternal;
269270
};
270271
} // namespace android

services/inputflinger/tests/KeyboardInputMapper_test.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,10 +1085,9 @@ TEST_F(KeyboardInputMapperTest, UsesSharedKeyboardSource) {
10851085
class KeyboardInputMapperTest_ExternalAlphabeticDevice : public KeyboardInputMapperUnitTest {
10861086
protected:
10871087
void SetUp() override {
1088-
InputMapperUnitTest::SetUp();
1088+
InputMapperUnitTest::SetUp(/*bus=*/0, /*isExternal=*/true);
10891089
ON_CALL((*mDevice), getSources).WillByDefault(Return(AINPUT_SOURCE_KEYBOARD));
10901090
ON_CALL((*mDevice), getKeyboardType).WillByDefault(Return(KeyboardType::ALPHABETIC));
1091-
ON_CALL((*mDevice), isExternal).WillByDefault(Return(true));
10921091
EXPECT_CALL(mMockEventHub, getDeviceClasses(EVENTHUB_ID))
10931092
.WillRepeatedly(Return(InputDeviceClass::KEYBOARD | InputDeviceClass::ALPHAKEY |
10941093
InputDeviceClass::EXTERNAL));
@@ -1102,10 +1101,9 @@ class KeyboardInputMapperTest_ExternalAlphabeticDevice : public KeyboardInputMap
11021101
class KeyboardInputMapperTest_ExternalNonAlphabeticDevice : public KeyboardInputMapperUnitTest {
11031102
protected:
11041103
void SetUp() override {
1105-
InputMapperUnitTest::SetUp();
1104+
InputMapperUnitTest::SetUp(/*bus=*/0, /*isExternal=*/true);
11061105
ON_CALL((*mDevice), getSources).WillByDefault(Return(AINPUT_SOURCE_KEYBOARD));
11071106
ON_CALL((*mDevice), getKeyboardType).WillByDefault(Return(KeyboardType::NON_ALPHABETIC));
1108-
ON_CALL((*mDevice), isExternal).WillByDefault(Return(true));
11091107
EXPECT_CALL(mMockEventHub, getDeviceClasses(EVENTHUB_ID))
11101108
.WillRepeatedly(Return(InputDeviceClass::KEYBOARD | InputDeviceClass::EXTERNAL));
11111109
mMapper = createInputMapper<KeyboardInputMapper>(*mDeviceContext, mReaderConfiguration,

services/inputflinger/tests/MultiTouchInputMapper_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ static constexpr int32_t ACTION_POINTER_1_DOWN =
5353
*/
5454
class MultiTouchInputMapperUnitTest : public InputMapperUnitTest {
5555
protected:
56-
void SetUp() override {
57-
InputMapperUnitTest::SetUp();
56+
void SetUp() override { SetUp(/*bus=*/0, /*isExternal=*/false); }
57+
void SetUp(int bus, bool isExternal) override {
58+
InputMapperUnitTest::SetUp(bus, isExternal);
5859

5960
// Present scan codes
6061
expectScanCodes(/*present=*/true,

services/inputflinger/tests/RotaryEncoderInputMapper_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ namespace vd_flags = android::companion::virtualdevice::flags;
8989
*/
9090
class RotaryEncoderInputMapperTest : public InputMapperUnitTest {
9191
protected:
92-
void SetUp() override { SetUpWithBus(BUS_USB); }
93-
void SetUpWithBus(int bus) override {
94-
InputMapperUnitTest::SetUpWithBus(bus);
92+
void SetUp() override { SetUp(/*bus=*/0, /*isExternal=*/false); }
93+
void SetUp(int bus, bool isExternal) override {
94+
InputMapperUnitTest::SetUp(bus, isExternal);
9595

9696
EXPECT_CALL(mMockEventHub, hasRelativeAxis(EVENTHUB_ID, REL_WHEEL))
9797
.WillRepeatedly(Return(true));

0 commit comments

Comments
 (0)