Add current device consumption to InputConsumerNoResampling
Added current device consumption to InputConsumerNoResampling in
consumeBatchedInputEvents' body
Bug: 329776327
Flag: EXEMPT refactor
Test: TEST=libinput_tests; m $TEST && $ANDROID_HOST_OUT/nativetest64/$TEST/$TEST --gtest_filter="InputConsumerTest*"
Change-Id: Ibfcb28f019543a88b3ffada137199b1c3933d542
diff --git a/libs/input/tests/InputConsumer_test.cpp b/libs/input/tests/InputConsumer_test.cpp
index 55be453..dec78aa 100644
--- a/libs/input/tests/InputConsumer_test.cpp
+++ b/libs/input/tests/InputConsumer_test.cpp
@@ -20,9 +20,11 @@
#include <optional>
#include <utility>
+#include <TestEventMatchers.h>
#include <TestInputChannel.h>
#include <TestLooper.h>
#include <android-base/logging.h>
+#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <input/BlockingQueue.h>
#include <input/InputEventBuilders.h>
@@ -34,6 +36,10 @@
using std::chrono::nanoseconds;
+using ::testing::AllOf;
+using ::testing::Matcher;
+using ::testing::Not;
+
} // namespace
class InputConsumerTest : public testing::Test, public InputConsumerCallbacks {
@@ -47,7 +53,17 @@
std::make_unique<LegacyResampler>());
}
- void assertOnBatchedInputEventPendingWasCalled();
+ void assertOnBatchedInputEventPendingWasCalled() {
+ ASSERT_GT(mOnBatchedInputEventPendingInvocationCount, 0UL)
+ << "onBatchedInputEventPending has not been called.";
+ --mOnBatchedInputEventPendingInvocationCount;
+ }
+
+ void assertReceivedMotionEvent(const Matcher<MotionEvent>& matcher) {
+ std::unique_ptr<MotionEvent> motionEvent = mMotionEvents.pop();
+ ASSERT_NE(motionEvent, nullptr);
+ EXPECT_THAT(*motionEvent, matcher);
+ }
std::shared_ptr<TestInputChannel> mClientTestChannel;
std::shared_ptr<TestLooper> mTestLooper;
@@ -96,12 +112,6 @@
};
};
-void InputConsumerTest::assertOnBatchedInputEventPendingWasCalled() {
- ASSERT_GT(mOnBatchedInputEventPendingInvocationCount, 0UL)
- << "onBatchedInputEventPending has not been called.";
- --mOnBatchedInputEventPendingInvocationCount;
-}
-
TEST_F(InputConsumerTest, MessageStreamBatchedInMotionEvent) {
mClientTestChannel->enqueueMessage(InputMessageBuilder{InputMessage::Type::MOTION, /*seq=*/0}
.eventTime(nanoseconds{0ms}.count())
@@ -122,7 +132,7 @@
assertOnBatchedInputEventPendingWasCalled();
- mConsumer->consumeBatchedInputEvents(std::nullopt);
+ mConsumer->consumeBatchedInputEvents(/*frameTime=*/std::nullopt);
std::unique_ptr<MotionEvent> downMotionEvent = mMotionEvents.pop();
ASSERT_NE(downMotionEvent, nullptr);
@@ -182,4 +192,50 @@
mClientTestChannel->assertFinishMessage(/*seq=*/2, true);
mClientTestChannel->assertFinishMessage(/*seq=*/3, true);
}
+
+TEST_F(InputConsumerTest, BatchedEventsMultiDeviceConsumption) {
+ mClientTestChannel->enqueueMessage(InputMessageBuilder{InputMessage::Type::MOTION, /*seq=*/0}
+ .deviceId(0)
+ .action(AMOTION_EVENT_ACTION_DOWN)
+ .build());
+
+ mTestLooper->invokeCallback(mClientTestChannel->getFd(), ALOOPER_EVENT_INPUT);
+ assertReceivedMotionEvent(AllOf(WithDeviceId(0), WithMotionAction(AMOTION_EVENT_ACTION_DOWN)));
+
+ mClientTestChannel->enqueueMessage(InputMessageBuilder{InputMessage::Type::MOTION, /*seq=*/1}
+ .deviceId(0)
+ .action(AMOTION_EVENT_ACTION_MOVE)
+ .build());
+ mClientTestChannel->enqueueMessage(InputMessageBuilder{InputMessage::Type::MOTION, /*seq=*/2}
+ .deviceId(0)
+ .action(AMOTION_EVENT_ACTION_MOVE)
+ .build());
+ mClientTestChannel->enqueueMessage(InputMessageBuilder{InputMessage::Type::MOTION, /*seq=*/3}
+ .deviceId(0)
+ .action(AMOTION_EVENT_ACTION_MOVE)
+ .build());
+
+ mClientTestChannel->enqueueMessage(InputMessageBuilder{InputMessage::Type::MOTION, /*seq=*/4}
+ .deviceId(1)
+ .action(AMOTION_EVENT_ACTION_DOWN)
+ .build());
+
+ mTestLooper->invokeCallback(mClientTestChannel->getFd(), ALOOPER_EVENT_INPUT);
+ assertReceivedMotionEvent(AllOf(WithDeviceId(1), WithMotionAction(AMOTION_EVENT_ACTION_DOWN)));
+
+ mClientTestChannel->enqueueMessage(InputMessageBuilder{InputMessage::Type::MOTION, /*seq=*/5}
+ .deviceId(0)
+ .action(AMOTION_EVENT_ACTION_UP)
+ .build());
+
+ mTestLooper->invokeCallback(mClientTestChannel->getFd(), ALOOPER_EVENT_INPUT);
+ assertReceivedMotionEvent(AllOf(WithDeviceId(0), WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
+ Not(MotionEventIsResampled())));
+
+ mClientTestChannel->assertFinishMessage(/*seq=*/0, /*handled=*/true);
+ mClientTestChannel->assertFinishMessage(/*seq=*/4, /*handled=*/true);
+ mClientTestChannel->assertFinishMessage(/*seq=*/1, /*handled=*/true);
+ mClientTestChannel->assertFinishMessage(/*seq=*/2, /*handled=*/true);
+ mClientTestChannel->assertFinishMessage(/*seq=*/3, /*handled=*/true);
+}
} // namespace android