blob: 3a7d20bfa2e02382360e5bb62faa722073537aac [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 Vishniakouce5ab082020-07-09 17:03:21 -050033 std::shared_ptr<InputChannel> serverChannel, clientChannel;
Jeff Brown5912f952013-07-01 19:10:31 -070034 InputPublisher* mPublisher;
35 InputConsumer* mConsumer;
36 PreallocatedInputEventFactory mEventFactory;
37
38 virtual void SetUp() {
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -080039 status_t result = InputChannel::openInputChannelPair("channel name",
Jeff Brown5912f952013-07-01 19:10:31 -070040 serverChannel, clientChannel);
Siarhei Vishniakou54d3e182020-01-15 17:38:38 -080041 ASSERT_EQ(OK, result);
Jeff Brown5912f952013-07-01 19:10:31 -070042
43 mPublisher = new InputPublisher(serverChannel);
44 mConsumer = new InputConsumer(clientChannel);
45 }
46
47 virtual void TearDown() {
48 if (mPublisher) {
49 delete mPublisher;
Yi Kong5bed83b2018-07-17 12:53:47 -070050 mPublisher = nullptr;
Jeff Brown5912f952013-07-01 19:10:31 -070051 }
52
53 if (mConsumer) {
54 delete mConsumer;
Yi Kong5bed83b2018-07-17 12:53:47 -070055 mConsumer = nullptr;
Jeff Brown5912f952013-07-01 19:10:31 -070056 }
57
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -050058 serverChannel.reset();
59 clientChannel.reset();
Jeff Brown5912f952013-07-01 19:10:31 -070060 }
61
62 void PublishAndConsumeKeyEvent();
63 void PublishAndConsumeMotionEvent();
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -080064 void PublishAndConsumeFocusEvent();
Jeff Brown5912f952013-07-01 19:10:31 -070065};
66
67TEST_F(InputPublisherAndConsumerTest, GetChannel_ReturnsTheChannel) {
68 EXPECT_EQ(serverChannel.get(), mPublisher->getChannel().get());
69 EXPECT_EQ(clientChannel.get(), mConsumer->getChannel().get());
70}
71
72void InputPublisherAndConsumerTest::PublishAndConsumeKeyEvent() {
73 status_t status;
74
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +010075 constexpr uint32_t seq = 15;
Garfield Tanff1f1bb2020-01-28 13:24:04 -080076 int32_t eventId = InputEvent::nextId();
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +010077 constexpr int32_t deviceId = 1;
Siarhei Vishniakou3826d472020-01-27 10:44:40 -060078 constexpr uint32_t source = AINPUT_SOURCE_KEYBOARD;
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +010079 constexpr int32_t displayId = ADISPLAY_ID_DEFAULT;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -060080 constexpr std::array<uint8_t, 32> hmac = {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21,
81 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,
82 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +010083 constexpr int32_t action = AKEY_EVENT_ACTION_DOWN;
84 constexpr int32_t flags = AKEY_EVENT_FLAG_FROM_SYSTEM;
85 constexpr int32_t keyCode = AKEYCODE_ENTER;
86 constexpr int32_t scanCode = 13;
87 constexpr int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON;
88 constexpr int32_t repeatCount = 1;
89 constexpr nsecs_t downTime = 3;
90 constexpr nsecs_t eventTime = 4;
Jeff Brown5912f952013-07-01 19:10:31 -070091
Garfield Tanff1f1bb2020-01-28 13:24:04 -080092 status = mPublisher->publishKeyEvent(seq, eventId, deviceId, source, displayId, hmac, action,
93 flags, keyCode, scanCode, metaState, repeatCount, downTime,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -060094 eventTime);
Jeff Brown5912f952013-07-01 19:10:31 -070095 ASSERT_EQ(OK, status)
96 << "publisher publishKeyEvent should return OK";
97
98 uint32_t consumeSeq;
99 InputEvent* event;
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800100 status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event);
Jeff Brown5912f952013-07-01 19:10:31 -0700101 ASSERT_EQ(OK, status)
102 << "consumer consume should return OK";
103
Yi Kong5bed83b2018-07-17 12:53:47 -0700104 ASSERT_TRUE(event != nullptr)
Jeff Brown5912f952013-07-01 19:10:31 -0700105 << "consumer should have returned non-NULL event";
106 ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, event->getType())
107 << "consumer should have returned a key event";
108
109 KeyEvent* keyEvent = static_cast<KeyEvent*>(event);
110 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800111 EXPECT_EQ(eventId, keyEvent->getId());
Jeff Brown5912f952013-07-01 19:10:31 -0700112 EXPECT_EQ(deviceId, keyEvent->getDeviceId());
113 EXPECT_EQ(source, keyEvent->getSource());
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100114 EXPECT_EQ(displayId, keyEvent->getDisplayId());
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600115 EXPECT_EQ(hmac, keyEvent->getHmac());
Jeff Brown5912f952013-07-01 19:10:31 -0700116 EXPECT_EQ(action, keyEvent->getAction());
117 EXPECT_EQ(flags, keyEvent->getFlags());
118 EXPECT_EQ(keyCode, keyEvent->getKeyCode());
119 EXPECT_EQ(scanCode, keyEvent->getScanCode());
120 EXPECT_EQ(metaState, keyEvent->getMetaState());
121 EXPECT_EQ(repeatCount, keyEvent->getRepeatCount());
122 EXPECT_EQ(downTime, keyEvent->getDownTime());
123 EXPECT_EQ(eventTime, keyEvent->getEventTime());
124
125 status = mConsumer->sendFinishedSignal(seq, true);
126 ASSERT_EQ(OK, status)
127 << "consumer sendFinishedSignal should return OK";
128
129 uint32_t finishedSeq = 0;
130 bool handled = false;
131 status = mPublisher->receiveFinishedSignal(&finishedSeq, &handled);
132 ASSERT_EQ(OK, status)
133 << "publisher receiveFinishedSignal should return OK";
134 ASSERT_EQ(seq, finishedSeq)
135 << "publisher receiveFinishedSignal should have returned the original sequence number";
136 ASSERT_TRUE(handled)
137 << "publisher receiveFinishedSignal should have set handled to consumer's reply";
138}
139
140void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent() {
141 status_t status;
142
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800143 constexpr uint32_t seq = 15;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800144 int32_t eventId = InputEvent::nextId();
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800145 constexpr int32_t deviceId = 1;
Siarhei Vishniakou3826d472020-01-27 10:44:40 -0600146 constexpr uint32_t source = AINPUT_SOURCE_TOUCHSCREEN;
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100147 constexpr int32_t displayId = ADISPLAY_ID_DEFAULT;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600148 constexpr std::array<uint8_t, 32> hmac = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
149 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
150 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800151 constexpr int32_t action = AMOTION_EVENT_ACTION_MOVE;
152 constexpr int32_t actionButton = 0;
153 constexpr int32_t flags = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED;
154 constexpr int32_t edgeFlags = AMOTION_EVENT_EDGE_FLAG_TOP;
155 constexpr int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON;
156 constexpr int32_t buttonState = AMOTION_EVENT_BUTTON_PRIMARY;
Siarhei Vishniakou16a2e302019-01-14 19:21:45 -0800157 constexpr MotionClassification classification = MotionClassification::AMBIGUOUS_GESTURE;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600158 constexpr float xScale = 2;
159 constexpr float yScale = 3;
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800160 constexpr float xOffset = -10;
161 constexpr float yOffset = -20;
162 constexpr float xPrecision = 0.25;
163 constexpr float yPrecision = 0.5;
Garfield Tan00f511d2019-06-12 16:55:40 -0700164 constexpr float xCursorPosition = 1.3;
165 constexpr float yCursorPosition = 50.6;
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800166 constexpr nsecs_t downTime = 3;
167 constexpr size_t pointerCount = 3;
168 constexpr nsecs_t eventTime = 4;
Jeff Brown5912f952013-07-01 19:10:31 -0700169 PointerProperties pointerProperties[pointerCount];
170 PointerCoords pointerCoords[pointerCount];
171 for (size_t i = 0; i < pointerCount; i++) {
172 pointerProperties[i].clear();
173 pointerProperties[i].id = (i + 2) % pointerCount;
174 pointerProperties[i].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
175
176 pointerCoords[i].clear();
177 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, 100 * i);
178 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_Y, 200 * i);
179 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 0.5 * i);
180 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 0.7 * i);
181 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 1.5 * i);
182 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 1.7 * i);
183 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.5 * i);
184 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.7 * i);
185 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 3.5 * i);
186 }
187
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800188 status = mPublisher->publishMotionEvent(seq, eventId, deviceId, source, displayId, hmac, action,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600189 actionButton, flags, edgeFlags, metaState, buttonState,
190 classification, xScale, yScale, xOffset, yOffset,
191 xPrecision, yPrecision, xCursorPosition,
192 yCursorPosition, downTime, eventTime, pointerCount,
193 pointerProperties, pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700194 ASSERT_EQ(OK, status)
195 << "publisher publishMotionEvent should return OK";
196
197 uint32_t consumeSeq;
198 InputEvent* event;
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800199 status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event);
Jeff Brown5912f952013-07-01 19:10:31 -0700200 ASSERT_EQ(OK, status)
201 << "consumer consume should return OK";
202
Yi Kong5bed83b2018-07-17 12:53:47 -0700203 ASSERT_TRUE(event != nullptr)
Jeff Brown5912f952013-07-01 19:10:31 -0700204 << "consumer should have returned non-NULL event";
205 ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType())
206 << "consumer should have returned a motion event";
207
208 MotionEvent* motionEvent = static_cast<MotionEvent*>(event);
209 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800210 EXPECT_EQ(eventId, motionEvent->getId());
Jeff Brown5912f952013-07-01 19:10:31 -0700211 EXPECT_EQ(deviceId, motionEvent->getDeviceId());
212 EXPECT_EQ(source, motionEvent->getSource());
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800213 EXPECT_EQ(displayId, motionEvent->getDisplayId());
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600214 EXPECT_EQ(hmac, motionEvent->getHmac());
Jeff Brown5912f952013-07-01 19:10:31 -0700215 EXPECT_EQ(action, motionEvent->getAction());
216 EXPECT_EQ(flags, motionEvent->getFlags());
217 EXPECT_EQ(edgeFlags, motionEvent->getEdgeFlags());
218 EXPECT_EQ(metaState, motionEvent->getMetaState());
219 EXPECT_EQ(buttonState, motionEvent->getButtonState());
Siarhei Vishniakou16a2e302019-01-14 19:21:45 -0800220 EXPECT_EQ(classification, motionEvent->getClassification());
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600221 EXPECT_EQ(xScale, motionEvent->getXScale());
222 EXPECT_EQ(yScale, motionEvent->getYScale());
223 EXPECT_EQ(xOffset, motionEvent->getXOffset());
224 EXPECT_EQ(yOffset, motionEvent->getYOffset());
Jeff Brown5912f952013-07-01 19:10:31 -0700225 EXPECT_EQ(xPrecision, motionEvent->getXPrecision());
226 EXPECT_EQ(yPrecision, motionEvent->getYPrecision());
Garfield Tan00f511d2019-06-12 16:55:40 -0700227 EXPECT_EQ(xCursorPosition, motionEvent->getRawXCursorPosition());
228 EXPECT_EQ(yCursorPosition, motionEvent->getRawYCursorPosition());
chaviw82357092020-01-28 13:13:06 -0800229 EXPECT_EQ(xCursorPosition * xScale + xOffset, motionEvent->getXCursorPosition());
230 EXPECT_EQ(yCursorPosition * yScale + yOffset, motionEvent->getYCursorPosition());
Jeff Brown5912f952013-07-01 19:10:31 -0700231 EXPECT_EQ(downTime, motionEvent->getDownTime());
232 EXPECT_EQ(eventTime, motionEvent->getEventTime());
233 EXPECT_EQ(pointerCount, motionEvent->getPointerCount());
234 EXPECT_EQ(0U, motionEvent->getHistorySize());
235
236 for (size_t i = 0; i < pointerCount; i++) {
237 SCOPED_TRACE(i);
238 EXPECT_EQ(pointerProperties[i].id, motionEvent->getPointerId(i));
239 EXPECT_EQ(pointerProperties[i].toolType, motionEvent->getToolType(i));
240
241 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X),
242 motionEvent->getRawX(i));
243 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y),
244 motionEvent->getRawY(i));
chaviw82357092020-01-28 13:13:06 -0800245 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X) * xScale + xOffset,
246 motionEvent->getX(i));
247 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y) * yScale + yOffset,
248 motionEvent->getY(i));
Jeff Brown5912f952013-07-01 19:10:31 -0700249 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE),
250 motionEvent->getPressure(i));
251 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_SIZE),
252 motionEvent->getSize(i));
253 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR),
254 motionEvent->getTouchMajor(i));
255 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR),
256 motionEvent->getTouchMinor(i));
257 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR),
258 motionEvent->getToolMajor(i));
259 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR),
260 motionEvent->getToolMinor(i));
261 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION),
262 motionEvent->getOrientation(i));
263 }
264
265 status = mConsumer->sendFinishedSignal(seq, false);
266 ASSERT_EQ(OK, status)
267 << "consumer sendFinishedSignal should return OK";
268
269 uint32_t finishedSeq = 0;
270 bool handled = true;
271 status = mPublisher->receiveFinishedSignal(&finishedSeq, &handled);
272 ASSERT_EQ(OK, status)
273 << "publisher receiveFinishedSignal should return OK";
274 ASSERT_EQ(seq, finishedSeq)
275 << "publisher receiveFinishedSignal should have returned the original sequence number";
276 ASSERT_FALSE(handled)
277 << "publisher receiveFinishedSignal should have set handled to consumer's reply";
278}
279
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800280void InputPublisherAndConsumerTest::PublishAndConsumeFocusEvent() {
281 status_t status;
282
283 constexpr uint32_t seq = 15;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800284 int32_t eventId = InputEvent::nextId();
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800285 constexpr bool hasFocus = true;
286 constexpr bool inTouchMode = true;
287
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800288 status = mPublisher->publishFocusEvent(seq, eventId, hasFocus, inTouchMode);
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800289 ASSERT_EQ(OK, status) << "publisher publishKeyEvent should return OK";
290
291 uint32_t consumeSeq;
292 InputEvent* event;
293 status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event);
294 ASSERT_EQ(OK, status) << "consumer consume should return OK";
295
296 ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
297 ASSERT_EQ(AINPUT_EVENT_TYPE_FOCUS, event->getType())
298 << "consumer should have returned a focus event";
299
300 FocusEvent* focusEvent = static_cast<FocusEvent*>(event);
301 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800302 EXPECT_EQ(eventId, focusEvent->getId());
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800303 EXPECT_EQ(hasFocus, focusEvent->getHasFocus());
304 EXPECT_EQ(inTouchMode, focusEvent->getInTouchMode());
305
306 status = mConsumer->sendFinishedSignal(seq, true);
307 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
308
309 uint32_t finishedSeq = 0;
310 bool handled = false;
311 status = mPublisher->receiveFinishedSignal(&finishedSeq, &handled);
312 ASSERT_EQ(OK, status) << "publisher receiveFinishedSignal should return OK";
313 ASSERT_EQ(seq, finishedSeq)
314 << "publisher receiveFinishedSignal should have returned the original sequence number";
315 ASSERT_TRUE(handled)
316 << "publisher receiveFinishedSignal should have set handled to consumer's reply";
317}
318
Jeff Brown5912f952013-07-01 19:10:31 -0700319TEST_F(InputPublisherAndConsumerTest, PublishKeyEvent_EndToEnd) {
320 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
321}
322
323TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_EndToEnd) {
324 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
325}
326
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800327TEST_F(InputPublisherAndConsumerTest, PublishFocusEvent_EndToEnd) {
328 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeFocusEvent());
329}
330
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800331TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenSequenceNumberIsZero_ReturnsError) {
Jeff Brown5912f952013-07-01 19:10:31 -0700332 status_t status;
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800333 const size_t pointerCount = 1;
Jeff Brown5912f952013-07-01 19:10:31 -0700334 PointerProperties pointerProperties[pointerCount];
335 PointerCoords pointerCoords[pointerCount];
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800336 for (size_t i = 0; i < pointerCount; i++) {
337 pointerProperties[i].clear();
338 pointerCoords[i].clear();
339 }
Jeff Brown5912f952013-07-01 19:10:31 -0700340
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800341 status = mPublisher->publishMotionEvent(0, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
342 0, 0, 0, MotionClassification::NONE, 1 /* xScale */,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600343 1 /* yScale */, 0, 0, 0, 0,
344 AMOTION_EVENT_INVALID_CURSOR_POSITION,
345 AMOTION_EVENT_INVALID_CURSOR_POSITION, 0, 0,
346 pointerCount, pointerProperties, pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700347 ASSERT_EQ(BAD_VALUE, status)
348 << "publisher publishMotionEvent should return BAD_VALUE";
349}
350
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800351TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenPointerCountLessThan1_ReturnsError) {
352 status_t status;
353 const size_t pointerCount = 0;
354 PointerProperties pointerProperties[pointerCount];
355 PointerCoords pointerCoords[pointerCount];
356
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800357 status = mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
358 0, 0, 0, MotionClassification::NONE, 1 /* xScale */,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600359 1 /* yScale */, 0, 0, 0, 0,
360 AMOTION_EVENT_INVALID_CURSOR_POSITION,
361 AMOTION_EVENT_INVALID_CURSOR_POSITION, 0, 0,
362 pointerCount, pointerProperties, pointerCoords);
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800363 ASSERT_EQ(BAD_VALUE, status)
364 << "publisher publishMotionEvent should return BAD_VALUE";
365}
366
367TEST_F(InputPublisherAndConsumerTest,
368 PublishMotionEvent_WhenPointerCountGreaterThanMax_ReturnsError) {
Jeff Brown5912f952013-07-01 19:10:31 -0700369 status_t status;
370 const size_t pointerCount = MAX_POINTERS + 1;
371 PointerProperties pointerProperties[pointerCount];
372 PointerCoords pointerCoords[pointerCount];
373 for (size_t i = 0; i < pointerCount; i++) {
374 pointerProperties[i].clear();
375 pointerCoords[i].clear();
376 }
377
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800378 status = mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
379 0, 0, 0, MotionClassification::NONE, 1 /* xScale */,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600380 1 /* yScale */, 0, 0, 0, 0,
381 AMOTION_EVENT_INVALID_CURSOR_POSITION,
382 AMOTION_EVENT_INVALID_CURSOR_POSITION, 0, 0,
383 pointerCount, pointerProperties, pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700384 ASSERT_EQ(BAD_VALUE, status)
385 << "publisher publishMotionEvent should return BAD_VALUE";
386}
387
388TEST_F(InputPublisherAndConsumerTest, PublishMultipleEvents_EndToEnd) {
389 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
390 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
391 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800392 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeFocusEvent());
Jeff Brown5912f952013-07-01 19:10:31 -0700393 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
394 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
395}
396
397} // namespace android