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

Commit 7ecbb998 authored by Harry Cutts's avatar Harry Cutts
Browse files

CursorInputMapper: move unit tests to InputMapperUnitTest

This puts most of CursorInputMapper's unit tests in one place
(CursorInputMapper_test.cpp) and under one input mapper testing system,
which will hopefully simplify future additions to the tests. The only
CursorInputMapper tests remaining to be migrated are those which rely on
setting an associated viewport, which I'm saving for a follow-up CL
since they'll need the introduction of a fake InputDeviceContext.

Also make a few smaller clean-ups:

* underscores have been removed from test names, as they can cause
  problems in gTest;
* assertions have been moved to the newer style using matchers,
  improving conciseness and readability;
* tests for the creation of NotifyKeyArgs for certain mouse buttons have
  been parameterized.

Bug: 283812079
Test: atest inputflinger_tests
Change-Id: I0f0307dc57edcc62d0ce24b15bf0d9e8b8b915c6
parent 1b5bde47
Loading
Loading
Loading
Loading
+1026 −10

File changed.

Preview size limit exceeded, changes collapsed.

+4 −0
Original line number Diff line number Diff line
@@ -28,6 +28,10 @@ void FakePointerController::setBounds(float minX, float minY, float maxX, float
    mMaxY = maxY;
}

void FakePointerController::clearBounds() {
    mHaveBounds = false;
}

const std::map<int32_t, std::vector<int32_t>>& FakePointerController::getSpots() {
    return mSpotsByDisplay;
}
+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ public:
    virtual ~FakePointerController() {}

    void setBounds(float minX, float minY, float maxX, float maxY);
    void clearBounds();
    const std::map<int32_t, std::vector<int32_t>>& getSpots();

    void setPosition(float x, float y) override;
+10 −9
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ namespace android {

using testing::Return;

void InputMapperUnitTest::SetUp() {
void InputMapperUnitTest::SetUpWithBus(int bus) {
    mFakePointerController = std::make_shared<FakePointerController>();
    mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
    mFakePointerController->setPosition(INITIAL_CURSOR_X, INITIAL_CURSOR_Y);
@@ -40,9 +40,12 @@ void InputMapperUnitTest::SetUp() {

    mIdentifier.name = "device";
    mIdentifier.location = "USB1";
    mIdentifier.bus = 0;
    mIdentifier.bus = bus;
    EXPECT_CALL(mMockEventHub, getDeviceIdentifier(EVENTHUB_ID))
            .WillRepeatedly(Return(mIdentifier));
    EXPECT_CALL(mMockEventHub, getConfiguration(EVENTHUB_ID)).WillRepeatedly([&](int32_t) {
        return mPropertyMap;
    });
}

void InputMapperUnitTest::createDevice() {
@@ -222,8 +225,8 @@ std::list<NotifyArgs> InputMapperTest::handleTimeout(InputMapper& mapper, nsecs_
    return generatedArgs;
}

void InputMapperTest::assertMotionRange(const InputDeviceInfo& info, int32_t axis, uint32_t source,
                                        float min, float max, float flat, float fuzz) {
void assertMotionRange(const InputDeviceInfo& info, int32_t axis, uint32_t source, float min,
                       float max, float flat, float fuzz) {
    const InputDeviceInfo::MotionRange* range = info.getMotionRange(axis, source);
    ASSERT_TRUE(range != nullptr) << "Axis: " << axis << " Source: " << source;
    ASSERT_EQ(axis, range->axis) << "Axis: " << axis << " Source: " << source;
@@ -234,11 +237,9 @@ void InputMapperTest::assertMotionRange(const InputDeviceInfo& info, int32_t axi
    ASSERT_NEAR(fuzz, range->fuzz, EPSILON) << "Axis: " << axis << " Source: " << source;
}

void InputMapperTest::assertPointerCoords(const PointerCoords& coords, float x, float y,
                                          float pressure, float size, float touchMajor,
                                          float touchMinor, float toolMajor, float toolMinor,
                                          float orientation, float distance,
                                          float scaledAxisEpsilon) {
void assertPointerCoords(const PointerCoords& coords, float x, float y, float pressure, float size,
                         float touchMajor, float touchMinor, float toolMajor, float toolMinor,
                         float orientation, float distance, float scaledAxisEpsilon) {
    ASSERT_NEAR(x, coords.getAxisValue(AMOTION_EVENT_AXIS_X), scaledAxisEpsilon);
    ASSERT_NEAR(y, coords.getAxisValue(AMOTION_EVENT_AXIS_Y), scaledAxisEpsilon);
    ASSERT_NEAR(pressure, coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), EPSILON);
+11 −8
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
#include "InterfaceMocks.h"
#include "TestConstants.h"
#include "TestInputListener.h"
#include "input/PropertyMap.h"

namespace android {

@@ -41,7 +42,8 @@ protected:
    static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000;
    static constexpr float INITIAL_CURSOR_X = 400;
    static constexpr float INITIAL_CURSOR_Y = 240;
    virtual void SetUp() override;
    virtual void SetUp() override { SetUpWithBus(0); }
    virtual void SetUpWithBus(int bus);

    /**
     * Initializes mDevice and mDeviceContext. When this happens, mDevice takes a copy of
@@ -72,6 +74,7 @@ protected:
    InputReaderConfiguration mReaderConfiguration;
    // The mapper should be created by the subclasses.
    std::unique_ptr<InputMapper> mMapper;
    PropertyMap mPropertyMap;
};

/**
@@ -138,13 +141,13 @@ protected:
    void resetMapper(InputMapper& mapper, nsecs_t when);

    std::list<NotifyArgs> handleTimeout(InputMapper& mapper, nsecs_t when);

    static void assertMotionRange(const InputDeviceInfo& info, int32_t axis, uint32_t source,
                                  float min, float max, float flat, float fuzz);
    static void assertPointerCoords(const PointerCoords& coords, float x, float y, float pressure,
                                    float size, float touchMajor, float touchMinor, float toolMajor,
                                    float toolMinor, float orientation, float distance,
                                    float scaledAxisEpsilon = 1.f);
};

void assertMotionRange(const InputDeviceInfo& info, int32_t axis, uint32_t source, float min,
                       float max, float flat, float fuzz);

void assertPointerCoords(const PointerCoords& coords, float x, float y, float pressure, float size,
                         float touchMajor, float touchMinor, float toolMajor, float toolMinor,
                         float orientation, float distance, float scaledAxisEpsilon = 1.f);

} // namespace android
Loading