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

Commit 583ff19b authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Ibdd75ae6,If628a505 into main

* changes:
  s/TestInputListenerMatchers.h/TestEventMatchers.h
  Move all matchers from dispatcher tests to TestInputListenerMatchers
parents 6e1448f7 e3b28ddf
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -66,7 +66,6 @@ cc_test {
        "SyncQueue_test.cpp",
        "TimerProvider_test.cpp",
        "TestInputListener.cpp",
        "TestInputListenerMatchers.cpp",
        "TouchpadInputMapper_test.cpp",
        "KeyboardInputMapper_test.cpp",
        "UinputDevice.cpp",
+1 −1
Original line number Diff line number Diff line
@@ -29,8 +29,8 @@
#include "FakeInputReaderPolicy.h"
#include "InstrumentedInputReader.h"
#include "TestConstants.h"
#include "TestEventMatchers.h"
#include "TestInputListener.h"
#include "TestInputListenerMatchers.h"

namespace android {

+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@
#include "FakePointerController.h"
#include "InputMapperTest.h"
#include "InterfaceMocks.h"
#include "TestInputListenerMatchers.h"
#include "TestEventMatchers.h"

#define TAG "CursorInputMapper_test"

+1 −1
Original line number Diff line number Diff line
@@ -27,8 +27,8 @@
#include "InstrumentedInputReader.h"
#include "NotifyArgs.h"
#include "TestConstants.h"
#include "TestEventMatchers.h"
#include "TestInputListener.h"
#include "TestInputListenerMatchers.h"
#include "include/gestures.h"
#include "ui/Rotation.h"

+1 −69
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

#include "../dispatcher/InputDispatcher.h"
#include "../BlockingQueue.h"
#include "TestInputListenerMatchers.h"
#include "TestEventMatchers.h"

#include <NotifyArgsBuilders.h>
#include <android-base/properties.h>
@@ -136,16 +136,6 @@ static constexpr int expectedWallpaperFlags =

using ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID;

struct PointF {
    float x;
    float y;
    auto operator<=>(const PointF&) const = default;
};

inline std::string pointFToString(const PointF& p) {
    return std::string("(") + std::to_string(p.x) + ", " + std::to_string(p.y) + ")";
}

/**
 * Return a DOWN key event with KEYCODE_A.
 */
@@ -158,64 +148,6 @@ static KeyEvent getTestKeyEvent() {
    return event;
}

MATCHER_P(WithDownTime, downTime, "InputEvent with specified downTime") {
    *result_listener << "expected downTime " << downTime << ", but got " << arg.getDownTime();
    return arg.getDownTime() == downTime;
}

MATCHER_P(WithSource, source, "InputEvent with specified source") {
    *result_listener << "expected source " << inputEventSourceToString(source) << ", but got "
                     << inputEventSourceToString(arg.getSource());
    return arg.getSource() == source;
}

MATCHER_P(WithFlags, flags, "InputEvent with specified flags") {
    *result_listener << "expected flags " << std::hex << flags << ", but got " << arg.getFlags();
    return arg.getFlags() == flags;
}

MATCHER_P2(WithCoords, x, y, "MotionEvent with specified coordinates") {
    if (arg.getPointerCount() != 1) {
        *result_listener << "Expected 1 pointer, got " << arg.getPointerCount();
        return false;
    }
    const float receivedX = arg.getX(/*pointerIndex=*/0);
    const float receivedY = arg.getY(/*pointerIndex=*/0);
    *result_listener << "expected coords (" << x << ", " << y << "), but got (" << receivedX << ", "
                     << receivedY << ")";
    return receivedX == x && receivedY == y;
}

MATCHER_P2(WithRawCoords, x, y, "MotionEvent with specified raw coordinates") {
    if (arg.getPointerCount() != 1) {
        *result_listener << "Expected 1 pointer, got " << arg.getPointerCount();
        return false;
    }
    const float receivedX = arg.getRawX(/*pointerIndex=*/0);
    const float receivedY = arg.getRawY(/*pointerIndex=*/0);
    *result_listener << "expected raw coords (" << x << ", " << y << "), but got (" << receivedX
                     << ", " << receivedY << ")";
    return receivedX == x && receivedY == y;
}

MATCHER_P(WithPointerCount, pointerCount, "MotionEvent with specified number of pointers") {
    *result_listener << "expected pointerCount " << pointerCount << ", but got "
                     << arg.getPointerCount();
    return arg.getPointerCount() == pointerCount;
}

MATCHER_P(WithPointers, pointers, "MotionEvent with specified pointers") {
    // Build a map for the received pointers, by pointer id
    std::map<int32_t /*pointerId*/, PointF> actualPointers;
    for (size_t pointerIndex = 0; pointerIndex < arg.getPointerCount(); pointerIndex++) {
        const int32_t pointerId = arg.getPointerId(pointerIndex);
        actualPointers[pointerId] = {arg.getX(pointerIndex), arg.getY(pointerIndex)};
    }
    *result_listener << "expected pointers " << dumpMap(pointers, constToString, pointFToString)
                     << ", but got " << dumpMap(actualPointers, constToString, pointFToString);
    return pointers == actualPointers;
}

// --- FakeInputDispatcherPolicy ---

class FakeInputDispatcherPolicy : public InputDispatcherPolicyInterface {
Loading