blob: 4f53dc9ec4eefb556741e05c2cc642f7f7f35419 [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
chaviw09c8d2d2020-08-24 15:48:26 -070023#include <attestation/HmacKeyManager.h>
Jeff Brown5912f952013-07-01 19:10:31 -070024#include <cutils/ashmem.h>
25#include <gtest/gtest.h>
26#include <input/InputTransport.h>
Jeff Brown5912f952013-07-01 19:10:31 -070027#include <utils/StopWatch.h>
chaviw09c8d2d2020-08-24 15:48:26 -070028#include <utils/Timers.h>
Jeff Brown5912f952013-07-01 19:10:31 -070029
30namespace android {
31
32class InputPublisherAndConsumerTest : public testing::Test {
33protected:
Siarhei Vishniakoud2588272020-07-10 11:15:40 -050034 std::shared_ptr<InputChannel> mServerChannel, mClientChannel;
35 std::unique_ptr<InputPublisher> mPublisher;
36 std::unique_ptr<InputConsumer> mConsumer;
Jeff Brown5912f952013-07-01 19:10:31 -070037 PreallocatedInputEventFactory mEventFactory;
38
Siarhei Vishniakoud2588272020-07-10 11:15:40 -050039 void SetUp() override {
40 std::unique_ptr<InputChannel> serverChannel, clientChannel;
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -080041 status_t result = InputChannel::openInputChannelPair("channel name",
Jeff Brown5912f952013-07-01 19:10:31 -070042 serverChannel, clientChannel);
Siarhei Vishniakou54d3e182020-01-15 17:38:38 -080043 ASSERT_EQ(OK, result);
Siarhei Vishniakoud2588272020-07-10 11:15:40 -050044 mServerChannel = std::move(serverChannel);
45 mClientChannel = std::move(clientChannel);
Jeff Brown5912f952013-07-01 19:10:31 -070046
Siarhei Vishniakoud2588272020-07-10 11:15:40 -050047 mPublisher = std::make_unique<InputPublisher>(mServerChannel);
48 mConsumer = std::make_unique<InputConsumer>(mClientChannel);
Jeff Brown5912f952013-07-01 19:10:31 -070049 }
50
51 void PublishAndConsumeKeyEvent();
52 void PublishAndConsumeMotionEvent();
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -080053 void PublishAndConsumeFocusEvent();
Jeff Brown5912f952013-07-01 19:10:31 -070054};
55
56TEST_F(InputPublisherAndConsumerTest, GetChannel_ReturnsTheChannel) {
Siarhei Vishniakoua1188f52020-10-20 20:14:52 -050057 ASSERT_NE(nullptr, mPublisher->getChannel());
58 ASSERT_NE(nullptr, mConsumer->getChannel());
Siarhei Vishniakoud2588272020-07-10 11:15:40 -050059 EXPECT_EQ(mServerChannel.get(), mPublisher->getChannel().get());
60 EXPECT_EQ(mClientChannel.get(), mConsumer->getChannel().get());
Siarhei Vishniakoua1188f52020-10-20 20:14:52 -050061 ASSERT_EQ(mPublisher->getChannel()->getConnectionToken(),
62 mConsumer->getChannel()->getConnectionToken());
Jeff Brown5912f952013-07-01 19:10:31 -070063}
64
65void InputPublisherAndConsumerTest::PublishAndConsumeKeyEvent() {
66 status_t status;
67
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +010068 constexpr uint32_t seq = 15;
Garfield Tanff1f1bb2020-01-28 13:24:04 -080069 int32_t eventId = InputEvent::nextId();
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +010070 constexpr int32_t deviceId = 1;
Siarhei Vishniakou3826d472020-01-27 10:44:40 -060071 constexpr uint32_t source = AINPUT_SOURCE_KEYBOARD;
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +010072 constexpr int32_t displayId = ADISPLAY_ID_DEFAULT;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -060073 constexpr std::array<uint8_t, 32> hmac = {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21,
74 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,
75 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +010076 constexpr int32_t action = AKEY_EVENT_ACTION_DOWN;
77 constexpr int32_t flags = AKEY_EVENT_FLAG_FROM_SYSTEM;
78 constexpr int32_t keyCode = AKEYCODE_ENTER;
79 constexpr int32_t scanCode = 13;
80 constexpr int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON;
81 constexpr int32_t repeatCount = 1;
82 constexpr nsecs_t downTime = 3;
83 constexpr nsecs_t eventTime = 4;
Jeff Brown5912f952013-07-01 19:10:31 -070084
Garfield Tanff1f1bb2020-01-28 13:24:04 -080085 status = mPublisher->publishKeyEvent(seq, eventId, deviceId, source, displayId, hmac, action,
86 flags, keyCode, scanCode, metaState, repeatCount, downTime,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -060087 eventTime);
Jeff Brown5912f952013-07-01 19:10:31 -070088 ASSERT_EQ(OK, status)
89 << "publisher publishKeyEvent should return OK";
90
91 uint32_t consumeSeq;
92 InputEvent* event;
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -080093 status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event);
Jeff Brown5912f952013-07-01 19:10:31 -070094 ASSERT_EQ(OK, status)
95 << "consumer consume should return OK";
96
Yi Kong5bed83b2018-07-17 12:53:47 -070097 ASSERT_TRUE(event != nullptr)
Jeff Brown5912f952013-07-01 19:10:31 -070098 << "consumer should have returned non-NULL event";
99 ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, event->getType())
100 << "consumer should have returned a key event";
101
102 KeyEvent* keyEvent = static_cast<KeyEvent*>(event);
103 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800104 EXPECT_EQ(eventId, keyEvent->getId());
Jeff Brown5912f952013-07-01 19:10:31 -0700105 EXPECT_EQ(deviceId, keyEvent->getDeviceId());
106 EXPECT_EQ(source, keyEvent->getSource());
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100107 EXPECT_EQ(displayId, keyEvent->getDisplayId());
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600108 EXPECT_EQ(hmac, keyEvent->getHmac());
Jeff Brown5912f952013-07-01 19:10:31 -0700109 EXPECT_EQ(action, keyEvent->getAction());
110 EXPECT_EQ(flags, keyEvent->getFlags());
111 EXPECT_EQ(keyCode, keyEvent->getKeyCode());
112 EXPECT_EQ(scanCode, keyEvent->getScanCode());
113 EXPECT_EQ(metaState, keyEvent->getMetaState());
114 EXPECT_EQ(repeatCount, keyEvent->getRepeatCount());
115 EXPECT_EQ(downTime, keyEvent->getDownTime());
116 EXPECT_EQ(eventTime, keyEvent->getEventTime());
117
118 status = mConsumer->sendFinishedSignal(seq, true);
119 ASSERT_EQ(OK, status)
120 << "consumer sendFinishedSignal should return OK";
121
122 uint32_t finishedSeq = 0;
123 bool handled = false;
124 status = mPublisher->receiveFinishedSignal(&finishedSeq, &handled);
125 ASSERT_EQ(OK, status)
126 << "publisher receiveFinishedSignal should return OK";
127 ASSERT_EQ(seq, finishedSeq)
128 << "publisher receiveFinishedSignal should have returned the original sequence number";
129 ASSERT_TRUE(handled)
130 << "publisher receiveFinishedSignal should have set handled to consumer's reply";
131}
132
133void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent() {
134 status_t status;
135
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800136 constexpr uint32_t seq = 15;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800137 int32_t eventId = InputEvent::nextId();
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800138 constexpr int32_t deviceId = 1;
Siarhei Vishniakou3826d472020-01-27 10:44:40 -0600139 constexpr uint32_t source = AINPUT_SOURCE_TOUCHSCREEN;
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100140 constexpr int32_t displayId = ADISPLAY_ID_DEFAULT;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600141 constexpr std::array<uint8_t, 32> hmac = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
142 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
143 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800144 constexpr int32_t action = AMOTION_EVENT_ACTION_MOVE;
145 constexpr int32_t actionButton = 0;
146 constexpr int32_t flags = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED;
147 constexpr int32_t edgeFlags = AMOTION_EVENT_EDGE_FLAG_TOP;
148 constexpr int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON;
149 constexpr int32_t buttonState = AMOTION_EVENT_BUTTON_PRIMARY;
Siarhei Vishniakou16a2e302019-01-14 19:21:45 -0800150 constexpr MotionClassification classification = MotionClassification::AMBIGUOUS_GESTURE;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600151 constexpr float xScale = 2;
152 constexpr float yScale = 3;
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800153 constexpr float xOffset = -10;
154 constexpr float yOffset = -20;
155 constexpr float xPrecision = 0.25;
156 constexpr float yPrecision = 0.5;
Garfield Tan00f511d2019-06-12 16:55:40 -0700157 constexpr float xCursorPosition = 1.3;
158 constexpr float yCursorPosition = 50.6;
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800159 constexpr nsecs_t downTime = 3;
160 constexpr size_t pointerCount = 3;
161 constexpr nsecs_t eventTime = 4;
Jeff Brown5912f952013-07-01 19:10:31 -0700162 PointerProperties pointerProperties[pointerCount];
163 PointerCoords pointerCoords[pointerCount];
164 for (size_t i = 0; i < pointerCount; i++) {
165 pointerProperties[i].clear();
166 pointerProperties[i].id = (i + 2) % pointerCount;
167 pointerProperties[i].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
168
169 pointerCoords[i].clear();
170 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, 100 * i);
171 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_Y, 200 * i);
172 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 0.5 * i);
173 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 0.7 * i);
174 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 1.5 * i);
175 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 1.7 * i);
176 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.5 * i);
177 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.7 * i);
178 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 3.5 * i);
179 }
180
chaviw9eaa22c2020-07-01 16:21:27 -0700181 ui::Transform transform;
182 transform.set({xScale, 0, xOffset, 0, yScale, yOffset, 0, 0, 1});
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800183 status = mPublisher->publishMotionEvent(seq, eventId, deviceId, source, displayId, hmac, action,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600184 actionButton, flags, edgeFlags, metaState, buttonState,
chaviw9eaa22c2020-07-01 16:21:27 -0700185 classification, transform, xPrecision, yPrecision,
186 xCursorPosition, yCursorPosition, downTime, eventTime,
187 pointerCount, pointerProperties, pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700188 ASSERT_EQ(OK, status)
189 << "publisher publishMotionEvent should return OK";
190
191 uint32_t consumeSeq;
192 InputEvent* event;
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800193 status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event);
Jeff Brown5912f952013-07-01 19:10:31 -0700194 ASSERT_EQ(OK, status)
195 << "consumer consume should return OK";
196
Yi Kong5bed83b2018-07-17 12:53:47 -0700197 ASSERT_TRUE(event != nullptr)
Jeff Brown5912f952013-07-01 19:10:31 -0700198 << "consumer should have returned non-NULL event";
199 ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType())
200 << "consumer should have returned a motion event";
201
202 MotionEvent* motionEvent = static_cast<MotionEvent*>(event);
203 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800204 EXPECT_EQ(eventId, motionEvent->getId());
Jeff Brown5912f952013-07-01 19:10:31 -0700205 EXPECT_EQ(deviceId, motionEvent->getDeviceId());
206 EXPECT_EQ(source, motionEvent->getSource());
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800207 EXPECT_EQ(displayId, motionEvent->getDisplayId());
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600208 EXPECT_EQ(hmac, motionEvent->getHmac());
Jeff Brown5912f952013-07-01 19:10:31 -0700209 EXPECT_EQ(action, motionEvent->getAction());
210 EXPECT_EQ(flags, motionEvent->getFlags());
211 EXPECT_EQ(edgeFlags, motionEvent->getEdgeFlags());
212 EXPECT_EQ(metaState, motionEvent->getMetaState());
213 EXPECT_EQ(buttonState, motionEvent->getButtonState());
Siarhei Vishniakou16a2e302019-01-14 19:21:45 -0800214 EXPECT_EQ(classification, motionEvent->getClassification());
chaviw9eaa22c2020-07-01 16:21:27 -0700215 EXPECT_EQ(transform, motionEvent->getTransform());
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600216 EXPECT_EQ(xOffset, motionEvent->getXOffset());
217 EXPECT_EQ(yOffset, motionEvent->getYOffset());
Jeff Brown5912f952013-07-01 19:10:31 -0700218 EXPECT_EQ(xPrecision, motionEvent->getXPrecision());
219 EXPECT_EQ(yPrecision, motionEvent->getYPrecision());
Garfield Tan00f511d2019-06-12 16:55:40 -0700220 EXPECT_EQ(xCursorPosition, motionEvent->getRawXCursorPosition());
221 EXPECT_EQ(yCursorPosition, motionEvent->getRawYCursorPosition());
chaviw82357092020-01-28 13:13:06 -0800222 EXPECT_EQ(xCursorPosition * xScale + xOffset, motionEvent->getXCursorPosition());
223 EXPECT_EQ(yCursorPosition * yScale + yOffset, motionEvent->getYCursorPosition());
Jeff Brown5912f952013-07-01 19:10:31 -0700224 EXPECT_EQ(downTime, motionEvent->getDownTime());
225 EXPECT_EQ(eventTime, motionEvent->getEventTime());
226 EXPECT_EQ(pointerCount, motionEvent->getPointerCount());
227 EXPECT_EQ(0U, motionEvent->getHistorySize());
228
229 for (size_t i = 0; i < pointerCount; i++) {
230 SCOPED_TRACE(i);
231 EXPECT_EQ(pointerProperties[i].id, motionEvent->getPointerId(i));
232 EXPECT_EQ(pointerProperties[i].toolType, motionEvent->getToolType(i));
233
234 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X),
235 motionEvent->getRawX(i));
236 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y),
237 motionEvent->getRawY(i));
chaviw82357092020-01-28 13:13:06 -0800238 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X) * xScale + xOffset,
239 motionEvent->getX(i));
240 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y) * yScale + yOffset,
241 motionEvent->getY(i));
Jeff Brown5912f952013-07-01 19:10:31 -0700242 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE),
243 motionEvent->getPressure(i));
244 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_SIZE),
245 motionEvent->getSize(i));
246 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR),
247 motionEvent->getTouchMajor(i));
248 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR),
249 motionEvent->getTouchMinor(i));
250 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR),
251 motionEvent->getToolMajor(i));
252 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR),
253 motionEvent->getToolMinor(i));
254 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION),
255 motionEvent->getOrientation(i));
256 }
257
258 status = mConsumer->sendFinishedSignal(seq, false);
259 ASSERT_EQ(OK, status)
260 << "consumer sendFinishedSignal should return OK";
261
262 uint32_t finishedSeq = 0;
263 bool handled = true;
264 status = mPublisher->receiveFinishedSignal(&finishedSeq, &handled);
265 ASSERT_EQ(OK, status)
266 << "publisher receiveFinishedSignal should return OK";
267 ASSERT_EQ(seq, finishedSeq)
268 << "publisher receiveFinishedSignal should have returned the original sequence number";
269 ASSERT_FALSE(handled)
270 << "publisher receiveFinishedSignal should have set handled to consumer's reply";
271}
272
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800273void InputPublisherAndConsumerTest::PublishAndConsumeFocusEvent() {
274 status_t status;
275
276 constexpr uint32_t seq = 15;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800277 int32_t eventId = InputEvent::nextId();
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800278 constexpr bool hasFocus = true;
279 constexpr bool inTouchMode = true;
280
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800281 status = mPublisher->publishFocusEvent(seq, eventId, hasFocus, inTouchMode);
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800282 ASSERT_EQ(OK, status) << "publisher publishKeyEvent should return OK";
283
284 uint32_t consumeSeq;
285 InputEvent* event;
286 status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event);
287 ASSERT_EQ(OK, status) << "consumer consume should return OK";
288
289 ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
290 ASSERT_EQ(AINPUT_EVENT_TYPE_FOCUS, event->getType())
291 << "consumer should have returned a focus event";
292
293 FocusEvent* focusEvent = static_cast<FocusEvent*>(event);
294 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800295 EXPECT_EQ(eventId, focusEvent->getId());
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800296 EXPECT_EQ(hasFocus, focusEvent->getHasFocus());
297 EXPECT_EQ(inTouchMode, focusEvent->getInTouchMode());
298
299 status = mConsumer->sendFinishedSignal(seq, true);
300 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
301
302 uint32_t finishedSeq = 0;
303 bool handled = false;
304 status = mPublisher->receiveFinishedSignal(&finishedSeq, &handled);
305 ASSERT_EQ(OK, status) << "publisher receiveFinishedSignal should return OK";
306 ASSERT_EQ(seq, finishedSeq)
307 << "publisher receiveFinishedSignal should have returned the original sequence number";
308 ASSERT_TRUE(handled)
309 << "publisher receiveFinishedSignal should have set handled to consumer's reply";
310}
311
Jeff Brown5912f952013-07-01 19:10:31 -0700312TEST_F(InputPublisherAndConsumerTest, PublishKeyEvent_EndToEnd) {
313 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
314}
315
316TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_EndToEnd) {
317 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
318}
319
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800320TEST_F(InputPublisherAndConsumerTest, PublishFocusEvent_EndToEnd) {
321 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeFocusEvent());
322}
323
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800324TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenSequenceNumberIsZero_ReturnsError) {
Jeff Brown5912f952013-07-01 19:10:31 -0700325 status_t status;
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800326 const size_t pointerCount = 1;
Jeff Brown5912f952013-07-01 19:10:31 -0700327 PointerProperties pointerProperties[pointerCount];
328 PointerCoords pointerCoords[pointerCount];
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800329 for (size_t i = 0; i < pointerCount; i++) {
330 pointerProperties[i].clear();
331 pointerCoords[i].clear();
332 }
Jeff Brown5912f952013-07-01 19:10:31 -0700333
chaviw9eaa22c2020-07-01 16:21:27 -0700334 ui::Transform identityTransform;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800335 status = mPublisher->publishMotionEvent(0, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
chaviw9eaa22c2020-07-01 16:21:27 -0700336 0, 0, 0, MotionClassification::NONE, identityTransform,
337 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600338 AMOTION_EVENT_INVALID_CURSOR_POSITION, 0, 0,
339 pointerCount, pointerProperties, pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700340 ASSERT_EQ(BAD_VALUE, status)
341 << "publisher publishMotionEvent should return BAD_VALUE";
342}
343
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800344TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenPointerCountLessThan1_ReturnsError) {
345 status_t status;
346 const size_t pointerCount = 0;
347 PointerProperties pointerProperties[pointerCount];
348 PointerCoords pointerCoords[pointerCount];
349
chaviw9eaa22c2020-07-01 16:21:27 -0700350 ui::Transform identityTransform;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800351 status = mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
chaviw9eaa22c2020-07-01 16:21:27 -0700352 0, 0, 0, MotionClassification::NONE, identityTransform,
353 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600354 AMOTION_EVENT_INVALID_CURSOR_POSITION, 0, 0,
355 pointerCount, pointerProperties, pointerCoords);
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800356 ASSERT_EQ(BAD_VALUE, status)
357 << "publisher publishMotionEvent should return BAD_VALUE";
358}
359
360TEST_F(InputPublisherAndConsumerTest,
361 PublishMotionEvent_WhenPointerCountGreaterThanMax_ReturnsError) {
Jeff Brown5912f952013-07-01 19:10:31 -0700362 status_t status;
363 const size_t pointerCount = MAX_POINTERS + 1;
364 PointerProperties pointerProperties[pointerCount];
365 PointerCoords pointerCoords[pointerCount];
366 for (size_t i = 0; i < pointerCount; i++) {
367 pointerProperties[i].clear();
368 pointerCoords[i].clear();
369 }
370
chaviw9eaa22c2020-07-01 16:21:27 -0700371 ui::Transform identityTransform;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800372 status = mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
chaviw9eaa22c2020-07-01 16:21:27 -0700373 0, 0, 0, MotionClassification::NONE, identityTransform,
374 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600375 AMOTION_EVENT_INVALID_CURSOR_POSITION, 0, 0,
376 pointerCount, pointerProperties, pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700377 ASSERT_EQ(BAD_VALUE, status)
378 << "publisher publishMotionEvent should return BAD_VALUE";
379}
380
381TEST_F(InputPublisherAndConsumerTest, PublishMultipleEvents_EndToEnd) {
382 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
383 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
384 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800385 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeFocusEvent());
Jeff Brown5912f952013-07-01 19:10:31 -0700386 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
387 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
388}
389
390} // namespace android