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

Commit f71138d4 authored by Harry Cutts's avatar Harry Cutts Committed by Android (Google) Code Review
Browse files

Merge changes I0f0307dc,I3ae3d407 into main

* changes:
  CursorInputMapper: move unit tests to InputMapperUnitTest
  InputMapperUnitTest: extract device creation from SetUp
parents 3bcf2082 7ecbb998
Loading
Loading
Loading
Loading
+1026 −9

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;
+22 −14
Original line number Diff line number Diff line
@@ -19,12 +19,13 @@
#include <InputReaderBase.h>
#include <gtest/gtest.h>
#include <ui/Rotation.h>
#include <utils/Timers.h>

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);
@@ -36,15 +37,24 @@ 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 = bus;
    EXPECT_CALL(mMockEventHub, getDeviceIdentifier(EVENTHUB_ID))
            .WillRepeatedly(Return(mIdentifier));
    EXPECT_CALL(mMockEventHub, getConfiguration(EVENTHUB_ID)).WillRepeatedly([&](int32_t) {
        return mPropertyMap;
    });
}

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,
@@ -215,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;
@@ -227,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);
+19 −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,15 @@ 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
     * 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);

@@ -54,6 +63,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;
@@ -64,6 +74,7 @@ protected:
    InputReaderConfiguration mReaderConfiguration;
    // The mapper should be created by the subclasses.
    std::unique_ptr<InputMapper> mMapper;
    PropertyMap mPropertyMap;
};

/**
@@ -130,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