blob: 5ddc85877cf1ac82b8400fe4c06dec2fab5de48b [file] [log] [blame]
Jeff Brown5912f952013-07-01 19:10:31 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "TestHelpers.h"
18
19#include <unistd.h>
20#include <sys/mman.h>
21#include <time.h>
22
23#include <cutils/ashmem.h>
24#include <gtest/gtest.h>
25#include <input/InputTransport.h>
26#include <utils/Timers.h>
27#include <utils/StopWatch.h>
28
29namespace android {
30
31class InputPublisherAndConsumerTest : public testing::Test {
32protected:
Siarhei Vishniakoud2588272020-07-10 11:15:40 -050033 std::shared_ptr<InputChannel> mServerChannel, mClientChannel;
34 std::unique_ptr<InputPublisher> mPublisher;
35 std::unique_ptr<InputConsumer> mConsumer;
Jeff Brown5912f952013-07-01 19:10:31 -070036 PreallocatedInputEventFactory mEventFactory;
37
Siarhei Vishniakoud2588272020-07-10 11:15:40 -050038 void SetUp() override {
39 std::unique_ptr<InputChannel> serverChannel, clientChannel;
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -080040 status_t result = InputChannel::openInputChannelPair("channel name",
Jeff Brown5912f952013-07-01 19:10:31 -070041 serverChannel, clientChannel);
Siarhei Vishniakou54d3e182020-01-15 17:38:38 -080042 ASSERT_EQ(OK, result);
Siarhei Vishniakoud2588272020-07-10 11:15:40 -050043 mServerChannel = std::move(serverChannel);
44 mClientChannel = std::move(clientChannel);
Jeff Brown5912f952013-07-01 19:10:31 -070045
Siarhei Vishniakoud2588272020-07-10 11:15:40 -050046 mPublisher = std::make_unique<InputPublisher>(mServerChannel);
47 mConsumer = std::make_unique<InputConsumer>(mClientChannel);
Jeff Brown5912f952013-07-01 19:10:31 -070048 }
49
50 void PublishAndConsumeKeyEvent();
51 void PublishAndConsumeMotionEvent();
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -080052 void PublishAndConsumeFocusEvent();
Jeff Brown5912f952013-07-01 19:10:31 -070053};
54
55TEST_F(InputPublisherAndConsumerTest, GetChannel_ReturnsTheChannel) {
Siarhei Vishniakoud2588272020-07-10 11:15:40 -050056 EXPECT_EQ(mServerChannel.get(), mPublisher->getChannel().get());
57 EXPECT_EQ(mClientChannel.get(), mConsumer->getChannel().get());
Jeff Brown5912f952013-07-01 19:10:31 -070058}
59
60void InputPublisherAndConsumerTest::PublishAndConsumeKeyEvent() {
61 status_t status;
62
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +010063 constexpr uint32_t seq = 15;
Garfield Tanff1f1bb2020-01-28 13:24:04 -080064 int32_t eventId = InputEvent::nextId();
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +010065 constexpr int32_t deviceId = 1;
Siarhei Vishniakou3826d472020-01-27 10:44:40 -060066 constexpr uint32_t source = AINPUT_SOURCE_KEYBOARD;
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +010067 constexpr int32_t displayId = ADISPLAY_ID_DEFAULT;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -060068 constexpr std::array<uint8_t, 32> hmac = {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21,
69 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,
70 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +010071 constexpr int32_t action = AKEY_EVENT_ACTION_DOWN;
72 constexpr int32_t flags = AKEY_EVENT_FLAG_FROM_SYSTEM;
73 constexpr int32_t keyCode = AKEYCODE_ENTER;
74 constexpr int32_t scanCode = 13;
75 constexpr int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON;
76 constexpr int32_t repeatCount = 1;
77 constexpr nsecs_t downTime = 3;
78 constexpr nsecs_t eventTime = 4;
Jeff Brown5912f952013-07-01 19:10:31 -070079
Garfield Tanff1f1bb2020-01-28 13:24:04 -080080 status = mPublisher->publishKeyEvent(seq, eventId, deviceId, source, displayId, hmac, action,
81 flags, keyCode, scanCode, metaState, repeatCount, downTime,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -060082 eventTime);
Jeff Brown5912f952013-07-01 19:10:31 -070083 ASSERT_EQ(OK, status)
84 << "publisher publishKeyEvent should return OK";
85
86 uint32_t consumeSeq;
87 InputEvent* event;
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -080088 status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event);
Jeff Brown5912f952013-07-01 19:10:31 -070089 ASSERT_EQ(OK, status)
90 << "consumer consume should return OK";
91
Yi Kong5bed83b2018-07-17 12:53:47 -070092 ASSERT_TRUE(event != nullptr)
Jeff Brown5912f952013-07-01 19:10:31 -070093 << "consumer should have returned non-NULL event";
94 ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, event->getType())
95 << "consumer should have returned a key event";
96
97 KeyEvent* keyEvent = static_cast<KeyEvent*>(event);
98 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -080099 EXPECT_EQ(eventId, keyEvent->getId());
Jeff Brown5912f952013-07-01 19:10:31 -0700100 EXPECT_EQ(deviceId, keyEvent->getDeviceId());
101 EXPECT_EQ(source, keyEvent->getSource());
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100102 EXPECT_EQ(displayId, keyEvent->getDisplayId());
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600103 EXPECT_EQ(hmac, keyEvent->getHmac());
Jeff Brown5912f952013-07-01 19:10:31 -0700104 EXPECT_EQ(action, keyEvent->getAction());
105 EXPECT_EQ(flags, keyEvent->getFlags());
106 EXPECT_EQ(keyCode, keyEvent->getKeyCode());
107 EXPECT_EQ(scanCode, keyEvent->getScanCode());
108 EXPECT_EQ(metaState, keyEvent->getMetaState());
109 EXPECT_EQ(repeatCount, keyEvent->getRepeatCount());
110 EXPECT_EQ(downTime, keyEvent->getDownTime());
111 EXPECT_EQ(eventTime, keyEvent->getEventTime());
112
113 status = mConsumer->sendFinishedSignal(seq, true);
114 ASSERT_EQ(OK, status)
115 << "consumer sendFinishedSignal should return OK";
116
117 uint32_t finishedSeq = 0;
118 bool handled = false;
119 status = mPublisher->receiveFinishedSignal(&finishedSeq, &handled);
120 ASSERT_EQ(OK, status)
121 << "publisher receiveFinishedSignal should return OK";
122 ASSERT_EQ(seq, finishedSeq)
123 << "publisher receiveFinishedSignal should have returned the original sequence number";
124 ASSERT_TRUE(handled)
125 << "publisher receiveFinishedSignal should have set handled to consumer's reply";
126}
127
128void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent() {
129 status_t status;
130
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800131 constexpr uint32_t seq = 15;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800132 int32_t eventId = InputEvent::nextId();
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800133 constexpr int32_t deviceId = 1;
Siarhei Vishniakou3826d472020-01-27 10:44:40 -0600134 constexpr uint32_t source = AINPUT_SOURCE_TOUCHSCREEN;
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100135 constexpr int32_t displayId = ADISPLAY_ID_DEFAULT;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600136 constexpr std::array<uint8_t, 32> hmac = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
137 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
138 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800139 constexpr int32_t action = AMOTION_EVENT_ACTION_MOVE;
140 constexpr int32_t actionButton = 0;
141 constexpr int32_t flags = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED;
142 constexpr int32_t edgeFlags = AMOTION_EVENT_EDGE_FLAG_TOP;
143 constexpr int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON;
144 constexpr int32_t buttonState = AMOTION_EVENT_BUTTON_PRIMARY;
Siarhei Vishniakou16a2e302019-01-14 19:21:45 -0800145 constexpr MotionClassification classification = MotionClassification::AMBIGUOUS_GESTURE;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600146 constexpr float xScale = 2;
147 constexpr float yScale = 3;
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800148 constexpr float xOffset = -10;
149 constexpr float yOffset = -20;
150 constexpr float xPrecision = 0.25;
151 constexpr float yPrecision = 0.5;
Garfield Tan00f511d2019-06-12 16:55:40 -0700152 constexpr float xCursorPosition = 1.3;
153 constexpr float yCursorPosition = 50.6;
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800154 constexpr nsecs_t downTime = 3;
155 constexpr size_t pointerCount = 3;
156 constexpr nsecs_t eventTime = 4;
Jeff Brown5912f952013-07-01 19:10:31 -0700157 PointerProperties pointerProperties[pointerCount];
158 PointerCoords pointerCoords[pointerCount];
159 for (size_t i = 0; i < pointerCount; i++) {
160 pointerProperties[i].clear();
161 pointerProperties[i].id = (i + 2) % pointerCount;
162 pointerProperties[i].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
163
164 pointerCoords[i].clear();
165 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, 100 * i);
166 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_Y, 200 * i);
167 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 0.5 * i);
168 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 0.7 * i);
169 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 1.5 * i);
170 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 1.7 * i);
171 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.5 * i);
172 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.7 * i);
173 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 3.5 * i);
174 }
175
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800176 status = mPublisher->publishMotionEvent(seq, eventId, deviceId, source, displayId, hmac, action,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600177 actionButton, flags, edgeFlags, metaState, buttonState,
178 classification, xScale, yScale, xOffset, yOffset,
179 xPrecision, yPrecision, xCursorPosition,
180 yCursorPosition, downTime, eventTime, pointerCount,
181 pointerProperties, pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700182 ASSERT_EQ(OK, status)
183 << "publisher publishMotionEvent should return OK";
184
185 uint32_t consumeSeq;
186 InputEvent* event;
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800187 status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event);
Jeff Brown5912f952013-07-01 19:10:31 -0700188 ASSERT_EQ(OK, status)
189 << "consumer consume should return OK";
190
Yi Kong5bed83b2018-07-17 12:53:47 -0700191 ASSERT_TRUE(event != nullptr)
Jeff Brown5912f952013-07-01 19:10:31 -0700192 << "consumer should have returned non-NULL event";
193 ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType())
194 << "consumer should have returned a motion event";
195
196 MotionEvent* motionEvent = static_cast<MotionEvent*>(event);
197 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800198 EXPECT_EQ(eventId, motionEvent->getId());
Jeff Brown5912f952013-07-01 19:10:31 -0700199 EXPECT_EQ(deviceId, motionEvent->getDeviceId());
200 EXPECT_EQ(source, motionEvent->getSource());
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800201 EXPECT_EQ(displayId, motionEvent->getDisplayId());
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600202 EXPECT_EQ(hmac, motionEvent->getHmac());
Jeff Brown5912f952013-07-01 19:10:31 -0700203 EXPECT_EQ(action, motionEvent->getAction());
204 EXPECT_EQ(flags, motionEvent->getFlags());
205 EXPECT_EQ(edgeFlags, motionEvent->getEdgeFlags());
206 EXPECT_EQ(metaState, motionEvent->getMetaState());
207 EXPECT_EQ(buttonState, motionEvent->getButtonState());
Siarhei Vishniakou16a2e302019-01-14 19:21:45 -0800208 EXPECT_EQ(classification, motionEvent->getClassification());
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600209 EXPECT_EQ(xScale, motionEvent->getXScale());
210 EXPECT_EQ(yScale, motionEvent->getYScale());
211 EXPECT_EQ(xOffset, motionEvent->getXOffset());
212 EXPECT_EQ(yOffset, motionEvent->getYOffset());
Jeff Brown5912f952013-07-01 19:10:31 -0700213 EXPECT_EQ(xPrecision, motionEvent->getXPrecision());
214 EXPECT_EQ(yPrecision, motionEvent->getYPrecision());
Garfield Tan00f511d2019-06-12 16:55:40 -0700215 EXPECT_EQ(xCursorPosition, motionEvent->getRawXCursorPosition());
216 EXPECT_EQ(yCursorPosition, motionEvent->getRawYCursorPosition());
chaviw82357092020-01-28 13:13:06 -0800217 EXPECT_EQ(xCursorPosition * xScale + xOffset, motionEvent->getXCursorPosition());
218 EXPECT_EQ(yCursorPosition * yScale + yOffset, motionEvent->getYCursorPosition());
Jeff Brown5912f952013-07-01 19:10:31 -0700219 EXPECT_EQ(downTime, motionEvent->getDownTime());
220 EXPECT_EQ(eventTime, motionEvent->getEventTime());
221 EXPECT_EQ(pointerCount, motionEvent->getPointerCount());
222 EXPECT_EQ(0U, motionEvent->getHistorySize());
223
224 for (size_t i = 0; i < pointerCount; i++) {
225 SCOPED_TRACE(i);
226 EXPECT_EQ(pointerProperties[i].id, motionEvent->getPointerId(i));
227 EXPECT_EQ(pointerProperties[i].toolType, motionEvent->getToolType(i));
228
229 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X),
230 motionEvent->getRawX(i));
231 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y),
232 motionEvent->getRawY(i));
chaviw82357092020-01-28 13:13:06 -0800233 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X) * xScale + xOffset,
234 motionEvent->getX(i));
235 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y) * yScale + yOffset,
236 motionEvent->getY(i));
Jeff Brown5912f952013-07-01 19:10:31 -0700237 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE),
238 motionEvent->getPressure(i));
239 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_SIZE),
240 motionEvent->getSize(i));
241 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR),
242 motionEvent->getTouchMajor(i));
243 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR),
244 motionEvent->getTouchMinor(i));
245 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR),
246 motionEvent->getToolMajor(i));
247 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR),
248 motionEvent->getToolMinor(i));
249 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION),
250 motionEvent->getOrientation(i));
251 }
252
253 status = mConsumer->sendFinishedSignal(seq, false);
254 ASSERT_EQ(OK, status)
255 << "consumer sendFinishedSignal should return OK";
256
257 uint32_t finishedSeq = 0;
258 bool handled = true;
259 status = mPublisher->receiveFinishedSignal(&finishedSeq, &handled);
260 ASSERT_EQ(OK, status)
261 << "publisher receiveFinishedSignal should return OK";
262 ASSERT_EQ(seq, finishedSeq)
263 << "publisher receiveFinishedSignal should have returned the original sequence number";
264 ASSERT_FALSE(handled)
265 << "publisher receiveFinishedSignal should have set handled to consumer's reply";
266}
267
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800268void InputPublisherAndConsumerTest::PublishAndConsumeFocusEvent() {
269 status_t status;
270
271 constexpr uint32_t seq = 15;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800272 int32_t eventId = InputEvent::nextId();
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800273 constexpr bool hasFocus = true;
274 constexpr bool inTouchMode = true;
275
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800276 status = mPublisher->publishFocusEvent(seq, eventId, hasFocus, inTouchMode);
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800277 ASSERT_EQ(OK, status) << "publisher publishKeyEvent should return OK";
278
279 uint32_t consumeSeq;
280 InputEvent* event;
281 status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event);
282 ASSERT_EQ(OK, status) << "consumer consume should return OK";
283
284 ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
285 ASSERT_EQ(AINPUT_EVENT_TYPE_FOCUS, event->getType())
286 << "consumer should have returned a focus event";
287
288 FocusEvent* focusEvent = static_cast<FocusEvent*>(event);
289 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800290 EXPECT_EQ(eventId, focusEvent->getId());
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800291 EXPECT_EQ(hasFocus, focusEvent->getHasFocus());
292 EXPECT_EQ(inTouchMode, focusEvent->getInTouchMode());
293
294 status = mConsumer->sendFinishedSignal(seq, true);
295 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
296
297 uint32_t finishedSeq = 0;
298 bool handled = false;
299 status = mPublisher->receiveFinishedSignal(&finishedSeq, &handled);
300 ASSERT_EQ(OK, status) << "publisher receiveFinishedSignal should return OK";
301 ASSERT_EQ(seq, finishedSeq)
302 << "publisher receiveFinishedSignal should have returned the original sequence number";
303 ASSERT_TRUE(handled)
304 << "publisher receiveFinishedSignal should have set handled to consumer's reply";
305}
306
Jeff Brown5912f952013-07-01 19:10:31 -0700307TEST_F(InputPublisherAndConsumerTest, PublishKeyEvent_EndToEnd) {
308 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
309}
310
311TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_EndToEnd) {
312 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
313}
314
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800315TEST_F(InputPublisherAndConsumerTest, PublishFocusEvent_EndToEnd) {
316 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeFocusEvent());
317}
318
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800319TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenSequenceNumberIsZero_ReturnsError) {
Jeff Brown5912f952013-07-01 19:10:31 -0700320 status_t status;
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800321 const size_t pointerCount = 1;
Jeff Brown5912f952013-07-01 19:10:31 -0700322 PointerProperties pointerProperties[pointerCount];
323 PointerCoords pointerCoords[pointerCount];
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800324 for (size_t i = 0; i < pointerCount; i++) {
325 pointerProperties[i].clear();
326 pointerCoords[i].clear();
327 }
Jeff Brown5912f952013-07-01 19:10:31 -0700328
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800329 status = mPublisher->publishMotionEvent(0, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
330 0, 0, 0, MotionClassification::NONE, 1 /* xScale */,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600331 1 /* yScale */, 0, 0, 0, 0,
332 AMOTION_EVENT_INVALID_CURSOR_POSITION,
333 AMOTION_EVENT_INVALID_CURSOR_POSITION, 0, 0,
334 pointerCount, pointerProperties, pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700335 ASSERT_EQ(BAD_VALUE, status)
336 << "publisher publishMotionEvent should return BAD_VALUE";
337}
338
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800339TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenPointerCountLessThan1_ReturnsError) {
340 status_t status;
341 const size_t pointerCount = 0;
342 PointerProperties pointerProperties[pointerCount];
343 PointerCoords pointerCoords[pointerCount];
344
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800345 status = mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
346 0, 0, 0, MotionClassification::NONE, 1 /* xScale */,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600347 1 /* yScale */, 0, 0, 0, 0,
348 AMOTION_EVENT_INVALID_CURSOR_POSITION,
349 AMOTION_EVENT_INVALID_CURSOR_POSITION, 0, 0,
350 pointerCount, pointerProperties, pointerCoords);
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800351 ASSERT_EQ(BAD_VALUE, status)
352 << "publisher publishMotionEvent should return BAD_VALUE";
353}
354
355TEST_F(InputPublisherAndConsumerTest,
356 PublishMotionEvent_WhenPointerCountGreaterThanMax_ReturnsError) {
Jeff Brown5912f952013-07-01 19:10:31 -0700357 status_t status;
358 const size_t pointerCount = MAX_POINTERS + 1;
359 PointerProperties pointerProperties[pointerCount];
360 PointerCoords pointerCoords[pointerCount];
361 for (size_t i = 0; i < pointerCount; i++) {
362 pointerProperties[i].clear();
363 pointerCoords[i].clear();
364 }
365
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800366 status = mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
367 0, 0, 0, MotionClassification::NONE, 1 /* xScale */,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600368 1 /* yScale */, 0, 0, 0, 0,
369 AMOTION_EVENT_INVALID_CURSOR_POSITION,
370 AMOTION_EVENT_INVALID_CURSOR_POSITION, 0, 0,
371 pointerCount, pointerProperties, pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700372 ASSERT_EQ(BAD_VALUE, status)
373 << "publisher publishMotionEvent should return BAD_VALUE";
374}
375
376TEST_F(InputPublisherAndConsumerTest, PublishMultipleEvents_EndToEnd) {
377 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
378 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
379 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800380 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeFocusEvent());
Jeff Brown5912f952013-07-01 19:10:31 -0700381 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
382 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
383}
384
385} // namespace android