Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1b5bde47 authored by Harry Cutts's avatar Harry Cutts
Browse files

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
parent f2de636e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ class CursorInputMapperUnitTest : public InputMapperUnitTest {
protected:
    void SetUp() override {
        InputMapperUnitTest::SetUp();
        createDevice();

        // Current scan code state - all keys are UP by default
        setScanCodeState(KeyState::UP,
+13 −6
Original line number Diff line number Diff line
@@ -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 @@ void InputMapperUnitTest::SetUp() {
    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,
+8 −0
Original line number Diff line number Diff line
@@ -43,6 +43,13 @@ protected:
    static constexpr float INITIAL_CURSOR_Y = 240;
    virtual void SetUp() override;

    /**
     * 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);
@@ -54,6 +61,7 @@ protected:
    std::list<NotifyArgs> process(int32_t type, int32_t code, int32_t value);
    std::list<NotifyArgs> process(nsecs_t when, int32_t type, int32_t code, int32_t value);

    InputDeviceIdentifier mIdentifier;
    MockEventHubInterface mMockEventHub;
    sp<FakeInputReaderPolicy> mFakePolicy;
    std::shared_ptr<FakePointerController> mFakePointerController;
+1 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ protected:

    void SetUp() override {
        InputMapperUnitTest::SetUp();
        createDevice();

        // set key-codes expected in tests
        for (const auto& [scanCode, outKeycode] : mKeyCodeMap) {
+5 −0
Original line number Diff line number Diff line
@@ -23,6 +23,11 @@ class MultiTouchMotionAccumulatorTest : public InputMapperUnitTest {
protected:
    static constexpr size_t SLOT_COUNT = 8;

    void SetUp() override {
        InputMapperUnitTest::SetUp();
        createDevice();
    }

    MultiTouchMotionAccumulator mMotionAccumulator;

    void processMotionEvent(int32_t type, int32_t code, int32_t value) {
Loading