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

Commit ce86cc37 authored by Harry Cutts's avatar Harry Cutts
Browse files

Make assertPosition a method of FakePointerController

This way it can be used in tests that aren't based on InputMapperTest.

Bug: 251196347
Test: m inputflinger_tests && \
    $ANDROID_HOST_OUT/nativetest64/inputflinger_tests/inputflinger_tests \
    --gtest_filter='*HardwareStateConverterTest*'
Test: atest inputflinger_tests
Change-Id: I39a7f08ac9b705d12e45acc3e3773b0046e80e5c
parent 47db1c71
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

#include "FakePointerController.h"

#include <gtest/gtest.h>

namespace android {

void FakePointerController::setBounds(float minX, float minY, float maxX, float maxY) {
@@ -56,6 +58,13 @@ void FakePointerController::setDisplayViewport(const DisplayViewport& viewport)
    mDisplayId = viewport.displayId;
}

void FakePointerController::assertPosition(float x, float y) {
    float actualX, actualY;
    getPosition(&actualX, &actualY);
    ASSERT_NEAR(x, actualX, 1);
    ASSERT_NEAR(y, actualY, 1);
}

bool FakePointerController::getBounds(float* outMinX, float* outMinY, float* outMaxX,
                                      float* outMaxY) const {
    *outMinX = mMinX;
+2 −0
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@ public:
    int32_t getDisplayId() const override;
    void setDisplayViewport(const DisplayViewport& viewport) override;

    void assertPosition(float x, float y);

private:
    bool getBounds(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const override;
    void move(float deltaX, float deltaY) override;
+0 −7
Original line number Diff line number Diff line
@@ -166,11 +166,4 @@ void InputMapperTest::assertPointerCoords(const PointerCoords& coords, float x,
    ASSERT_NEAR(distance, coords.getAxisValue(AMOTION_EVENT_AXIS_DISTANCE), EPSILON);
}

void InputMapperTest::assertPosition(const FakePointerController& controller, float x, float y) {
    float actualX, actualY;
    controller.getPosition(&actualX, &actualY);
    ASSERT_NEAR(x, actualX, 1);
    ASSERT_NEAR(y, actualY, 1);
}

} // namespace android
+0 −1
Original line number Diff line number Diff line
@@ -89,7 +89,6 @@ protected:
                                    float size, float touchMajor, float touchMinor, float toolMajor,
                                    float toolMinor, float orientation, float distance,
                                    float scaledAxisEpsilon = 1.f);
    static void assertPosition(const FakePointerController& controller, float x, float y);
};

} // namespace android
+6 −6
Original line number Diff line number Diff line
@@ -4344,7 +4344,7 @@ TEST_F(CursorInputMapperTest, Process_WhenModeIsPointer_ShouldMoveThePointerArou
    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, args.action);
    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
            110.0f, 220.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
    ASSERT_NO_FATAL_FAILURE(assertPosition(*mFakePointerController, 110.0f, 220.0f));
    ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(110.0f, 220.0f));
}

TEST_F(CursorInputMapperTest, Process_PointerCapture) {
@@ -4372,7 +4372,7 @@ TEST_F(CursorInputMapperTest, Process_PointerCapture) {
    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
            10.0f, 20.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
    ASSERT_NO_FATAL_FAILURE(assertPosition(*mFakePointerController, 100.0f, 200.0f));
    ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(100.0f, 200.0f));

    // Button press.
    process(mapper, ARBITRARY_TIME, READ_TIME, EV_KEY, BTN_MOUSE, 1);
@@ -4411,7 +4411,7 @@ TEST_F(CursorInputMapperTest, Process_PointerCapture) {
    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
            30.0f, 40.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
    ASSERT_NO_FATAL_FAILURE(assertPosition(*mFakePointerController, 100.0f, 200.0f));
    ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(100.0f, 200.0f));

    // Disable pointer capture and check that the device generation got bumped
    // and events are generated the usual way.
@@ -4431,7 +4431,7 @@ TEST_F(CursorInputMapperTest, Process_PointerCapture) {
    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, args.action);
    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
            110.0f, 220.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
    ASSERT_NO_FATAL_FAILURE(assertPosition(*mFakePointerController, 110.0f, 220.0f));
    ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(110.0f, 220.0f));
}

/**
@@ -4548,7 +4548,7 @@ TEST_F(CursorInputMapperTest, ConfigureDisplayId_NoAssociatedViewport) {
            AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
                  WithSource(AINPUT_SOURCE_MOUSE), WithDisplayId(SECONDARY_DISPLAY_ID),
                  WithCoords(110.0f, 220.0f))));
    ASSERT_NO_FATAL_FAILURE(assertPosition(*mFakePointerController, 110.0f, 220.0f));
    ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(110.0f, 220.0f));
}

TEST_F(CursorInputMapperTest, ConfigureDisplayId_WithAssociatedViewport) {
@@ -4575,7 +4575,7 @@ TEST_F(CursorInputMapperTest, ConfigureDisplayId_WithAssociatedViewport) {
            AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
                  WithSource(AINPUT_SOURCE_MOUSE), WithDisplayId(SECONDARY_DISPLAY_ID),
                  WithCoords(110.0f, 220.0f))));
    ASSERT_NO_FATAL_FAILURE(assertPosition(*mFakePointerController, 110.0f, 220.0f));
    ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(110.0f, 220.0f));
}

TEST_F(CursorInputMapperTest, ConfigureDisplayId_IgnoresEventsForMismatchedPointerDisplay) {