blob: 1452745d016db65b65cc814053d71fdabea62391 [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 Vishniakoud2588272020-07-10 11:15:40 -050057 EXPECT_EQ(mServerChannel.get(), mPublisher->getChannel().get());
58 EXPECT_EQ(mClientChannel.get(), mConsumer->getChannel().get());
Jeff Brown5912f952013-07-01 19:10:31 -070059}
60
61void InputPublisherAndConsumerTest::PublishAndConsumeKeyEvent() {
62 status_t status;
63
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +010064 constexpr uint32_t seq = 15;
Garfield Tanff1f1bb2020-01-28 13:24:04 -080065 int32_t eventId = InputEvent::nextId();
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +010066 constexpr int32_t deviceId = 1;
Siarhei Vishniakou3826d472020-01-27 10:44:40 -060067 constexpr uint32_t source = AINPUT_SOURCE_KEYBOARD;
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +010068 constexpr int32_t displayId = ADISPLAY_ID_DEFAULT;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -060069 constexpr std::array<uint8_t, 32> hmac = {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21,
70 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,
71 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +010072 constexpr int32_t action = AKEY_EVENT_ACTION_DOWN;
73 constexpr int32_t flags = AKEY_EVENT_FLAG_FROM_SYSTEM;
74 constexpr int32_t keyCode = AKEYCODE_ENTER;
75 constexpr int32_t scanCode = 13;
76 constexpr int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON;
77 constexpr int32_t repeatCount = 1;
78 constexpr nsecs_t downTime = 3;
79 constexpr nsecs_t eventTime = 4;
Jeff Brown5912f952013-07-01 19:10:31 -070080
Garfield Tanff1f1bb2020-01-28 13:24:04 -080081 status = mPublisher->publishKeyEvent(seq, eventId, deviceId, source, displayId, hmac, action,
82 flags, keyCode, scanCode, metaState, repeatCount, downTime,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -060083 eventTime);
Jeff Brown5912f952013-07-01 19:10:31 -070084 ASSERT_EQ(OK, status)
85 << "publisher publishKeyEvent should return OK";
86
87 uint32_t consumeSeq;
88 InputEvent* event;
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -080089 status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event);
Jeff Brown5912f952013-07-01 19:10:31 -070090 ASSERT_EQ(OK, status)
91 << "consumer consume should return OK";
92
Yi Kong5bed83b2018-07-17 12:53:47 -070093 ASSERT_TRUE(event != nullptr)
Jeff Brown5912f952013-07-01 19:10:31 -070094 << "consumer should have returned non-NULL event";
95 ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, event->getType())
96 << "consumer should have returned a key event";
97
98 KeyEvent* keyEvent = static_cast<KeyEvent*>(event);
99 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800100 EXPECT_EQ(eventId, keyEvent->getId());
Jeff Brown5912f952013-07-01 19:10:31 -0700101 EXPECT_EQ(deviceId, keyEvent->getDeviceId());
102 EXPECT_EQ(source, keyEvent->getSource());
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100103 EXPECT_EQ(displayId, keyEvent->getDisplayId());
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600104 EXPECT_EQ(hmac, keyEvent->getHmac());
Jeff Brown5912f952013-07-01 19:10:31 -0700105 EXPECT_EQ(action, keyEvent->getAction());
106 EXPECT_EQ(flags, keyEvent->getFlags());
107 EXPECT_EQ(keyCode, keyEvent->getKeyCode());
108 EXPECT_EQ(scanCode, keyEvent->getScanCode());
109 EXPECT_EQ(metaState, keyEvent->getMetaState());
110 EXPECT_EQ(repeatCount, keyEvent->getRepeatCount());
111 EXPECT_EQ(downTime, keyEvent->getDownTime());
112 EXPECT_EQ(eventTime, keyEvent->getEventTime());
113
114 status = mConsumer->sendFinishedSignal(seq, true);
115 ASSERT_EQ(OK, status)
116 << "consumer sendFinishedSignal should return OK";
117
118 uint32_t finishedSeq = 0;
119 bool handled = false;
120 status = mPublisher->receiveFinishedSignal(&finishedSeq, &handled);
121 ASSERT_EQ(OK, status)
122 << "publisher receiveFinishedSignal should return OK";
123 ASSERT_EQ(seq, finishedSeq)
124 << "publisher receiveFinishedSignal should have returned the original sequence number";
125 ASSERT_TRUE(handled)
126 << "publisher receiveFinishedSignal should have set handled to consumer's reply";
127}
128
129void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent() {
130 status_t status;
131
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800132 constexpr uint32_t seq = 15;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800133 int32_t eventId = InputEvent::nextId();
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800134 constexpr int32_t deviceId = 1;
Siarhei Vishniakou3826d472020-01-27 10:44:40 -0600135 constexpr uint32_t source = AINPUT_SOURCE_TOUCHSCREEN;
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100136 constexpr int32_t displayId = ADISPLAY_ID_DEFAULT;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600137 constexpr std::array<uint8_t, 32> hmac = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
138 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
139 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800140 constexpr int32_t action = AMOTION_EVENT_ACTION_MOVE;
141 constexpr int32_t actionButton = 0;
142 constexpr int32_t flags = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED;
143 constexpr int32_t edgeFlags = AMOTION_EVENT_EDGE_FLAG_TOP;
144 constexpr int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON;
145 constexpr int32_t buttonState = AMOTION_EVENT_BUTTON_PRIMARY;
Siarhei Vishniakou16a2e302019-01-14 19:21:45 -0800146 constexpr MotionClassification classification = MotionClassification::AMBIGUOUS_GESTURE;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600147 constexpr float xScale = 2;
148 constexpr float yScale = 3;
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800149 constexpr float xOffset = -10;
150 constexpr float yOffset = -20;
151 constexpr float xPrecision = 0.25;
152 constexpr float yPrecision = 0.5;
Garfield Tan00f511d2019-06-12 16:55:40 -0700153 constexpr float xCursorPosition = 1.3;
154 constexpr float yCursorPosition = 50.6;
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800155 constexpr nsecs_t downTime = 3;
156 constexpr size_t pointerCount = 3;
157 constexpr nsecs_t eventTime = 4;
Jeff Brown5912f952013-07-01 19:10:31 -0700158 PointerProperties pointerProperties[pointerCount];
159 PointerCoords pointerCoords[pointerCount];
160 for (size_t i = 0; i < pointerCount; i++) {
161 pointerProperties[i].clear();
162 pointerProperties[i].id = (i + 2) % pointerCount;
163 pointerProperties[i].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
164
165 pointerCoords[i].clear();
166 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, 100 * i);
167 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_Y, 200 * i);
168 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 0.5 * i);
169 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 0.7 * i);
170 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 1.5 * i);
171 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 1.7 * i);
172 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.5 * i);
173 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.7 * i);
174 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 3.5 * i);
175 }
176
chaviw9eaa22c2020-07-01 16:21:27 -0700177 ui::Transform transform;
178 transform.set({xScale, 0, xOffset, 0, yScale, yOffset, 0, 0, 1});
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800179 status = mPublisher->publishMotionEvent(seq, eventId, deviceId, source, displayId, hmac, action,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600180 actionButton, flags, edgeFlags, metaState, buttonState,
chaviw9eaa22c2020-07-01 16:21:27 -0700181 classification, transform, xPrecision, yPrecision,
182 xCursorPosition, yCursorPosition, downTime, eventTime,
183 pointerCount, pointerProperties, pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700184 ASSERT_EQ(OK, status)
185 << "publisher publishMotionEvent should return OK";
186
187 uint32_t consumeSeq;
188 InputEvent* event;
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800189 status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event);
Jeff Brown5912f952013-07-01 19:10:31 -0700190 ASSERT_EQ(OK, status)
191 << "consumer consume should return OK";
192
Yi Kong5bed83b2018-07-17 12:53:47 -0700193 ASSERT_TRUE(event != nullptr)
Jeff Brown5912f952013-07-01 19:10:31 -0700194 << "consumer should have returned non-NULL event";
195 ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType())
196 << "consumer should have returned a motion event";
197
198 MotionEvent* motionEvent = static_cast<MotionEvent*>(event);
199 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800200 EXPECT_EQ(eventId, motionEvent->getId());
Jeff Brown5912f952013-07-01 19:10:31 -0700201 EXPECT_EQ(deviceId, motionEvent->getDeviceId());
202 EXPECT_EQ(source, motionEvent->getSource());
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800203 EXPECT_EQ(displayId, motionEvent->getDisplayId());
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600204 EXPECT_EQ(hmac, motionEvent->getHmac());
Jeff Brown5912f952013-07-01 19:10:31 -0700205 EXPECT_EQ(action, motionEvent->getAction());
206 EXPECT_EQ(flags, motionEvent->getFlags());
207 EXPECT_EQ(edgeFlags, motionEvent->getEdgeFlags());
208 EXPECT_EQ(metaState, motionEvent->getMetaState());
209 EXPECT_EQ(buttonState, motionEvent->getButtonState());
Siarhei Vishniakou16a2e302019-01-14 19:21:45 -0800210 EXPECT_EQ(classification, motionEvent->getClassification());
chaviw9eaa22c2020-07-01 16:21:27 -0700211 EXPECT_EQ(transform, motionEvent->getTransform());
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600212 EXPECT_EQ(xOffset, motionEvent->getXOffset());
213 EXPECT_EQ(yOffset, motionEvent->getYOffset());
Jeff Brown5912f952013-07-01 19:10:31 -0700214 EXPECT_EQ(xPrecision, motionEvent->getXPrecision());
215 EXPECT_EQ(yPrecision, motionEvent->getYPrecision());
Garfield Tan00f511d2019-06-12 16:55:40 -0700216 EXPECT_EQ(xCursorPosition, motionEvent->getRawXCursorPosition());
217 EXPECT_EQ(yCursorPosition, motionEvent->getRawYCursorPosition());
chaviw82357092020-01-28 13:13:06 -0800218 EXPECT_EQ(xCursorPosition * xScale + xOffset, motionEvent->getXCursorPosition());
219 EXPECT_EQ(yCursorPosition * yScale + yOffset, motionEvent->getYCursorPosition());
Jeff Brown5912f952013-07-01 19:10:31 -0700220 EXPECT_EQ(downTime, motionEvent->getDownTime());
221 EXPECT_EQ(eventTime, motionEvent->getEventTime());
222 EXPECT_EQ(pointerCount, motionEvent->getPointerCount());
223 EXPECT_EQ(0U, motionEvent->getHistorySize());
224
225 for (size_t i = 0; i < pointerCount; i++) {
226 SCOPED_TRACE(i);
227 EXPECT_EQ(pointerProperties[i].id, motionEvent->getPointerId(i));
228 EXPECT_EQ(pointerProperties[i].toolType, motionEvent->getToolType(i));
229
230 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X),
231 motionEvent->getRawX(i));
232 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y),
233 motionEvent->getRawY(i));
chaviw82357092020-01-28 13:13:06 -0800234 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X) * xScale + xOffset,
235 motionEvent->getX(i));
236 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y) * yScale + yOffset,
237 motionEvent->getY(i));
Jeff Brown5912f952013-07-01 19:10:31 -0700238 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE),
239 motionEvent->getPressure(i));
240 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_SIZE),
241 motionEvent->getSize(i));
242 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR),
243 motionEvent->getTouchMajor(i));
244 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR),
245 motionEvent->getTouchMinor(i));
246 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR),
247 motionEvent->getToolMajor(i));
248 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR),
249 motionEvent->getToolMinor(i));
250 EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION),
251 motionEvent->getOrientation(i));
252 }
253
254 status = mConsumer->sendFinishedSignal(seq, false);
255 ASSERT_EQ(OK, status)
256 << "consumer sendFinishedSignal should return OK";
257
258 uint32_t finishedSeq = 0;
259 bool handled = true;
260 status = mPublisher->receiveFinishedSignal(&finishedSeq, &handled);
261 ASSERT_EQ(OK, status)
262 << "publisher receiveFinishedSignal should return OK";
263 ASSERT_EQ(seq, finishedSeq)
264 << "publisher receiveFinishedSignal should have returned the original sequence number";
265 ASSERT_FALSE(handled)
266 << "publisher receiveFinishedSignal should have set handled to consumer's reply";
267}
268
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800269void InputPublisherAndConsumerTest::PublishAndConsumeFocusEvent() {
270 status_t status;
271
272 constexpr uint32_t seq = 15;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800273 int32_t eventId = InputEvent::nextId();
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800274 constexpr bool hasFocus = true;
275 constexpr bool inTouchMode = true;
276
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800277 status = mPublisher->publishFocusEvent(seq, eventId, hasFocus, inTouchMode);
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800278 ASSERT_EQ(OK, status) << "publisher publishKeyEvent should return OK";
279
280 uint32_t consumeSeq;
281 InputEvent* event;
282 status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event);
283 ASSERT_EQ(OK, status) << "consumer consume should return OK";
284
285 ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
286 ASSERT_EQ(AINPUT_EVENT_TYPE_FOCUS, event->getType())
287 << "consumer should have returned a focus event";
288
289 FocusEvent* focusEvent = static_cast<FocusEvent*>(event);
290 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800291 EXPECT_EQ(eventId, focusEvent->getId());
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800292 EXPECT_EQ(hasFocus, focusEvent->getHasFocus());
293 EXPECT_EQ(inTouchMode, focusEvent->getInTouchMode());
294
295 status = mConsumer->sendFinishedSignal(seq, true);
296 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
297
298 uint32_t finishedSeq = 0;
299 bool handled = false;
300 status = mPublisher->receiveFinishedSignal(&finishedSeq, &handled);
301 ASSERT_EQ(OK, status) << "publisher receiveFinishedSignal should return OK";
302 ASSERT_EQ(seq, finishedSeq)
303 << "publisher receiveFinishedSignal should have returned the original sequence number";
304 ASSERT_TRUE(handled)
305 << "publisher receiveFinishedSignal should have set handled to consumer's reply";
306}
307
Jeff Brown5912f952013-07-01 19:10:31 -0700308TEST_F(InputPublisherAndConsumerTest, PublishKeyEvent_EndToEnd) {
309 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
310}
311
312TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_EndToEnd) {
313 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
314}
315
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800316TEST_F(InputPublisherAndConsumerTest, PublishFocusEvent_EndToEnd) {
317 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeFocusEvent());
318}
319
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800320TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenSequenceNumberIsZero_ReturnsError) {
Jeff Brown5912f952013-07-01 19:10:31 -0700321 status_t status;
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800322 const size_t pointerCount = 1;
Jeff Brown5912f952013-07-01 19:10:31 -0700323 PointerProperties pointerProperties[pointerCount];
324 PointerCoords pointerCoords[pointerCount];
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800325 for (size_t i = 0; i < pointerCount; i++) {
326 pointerProperties[i].clear();
327 pointerCoords[i].clear();
328 }
Jeff Brown5912f952013-07-01 19:10:31 -0700329
chaviw9eaa22c2020-07-01 16:21:27 -0700330 ui::Transform identityTransform;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800331 status = mPublisher->publishMotionEvent(0, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
chaviw9eaa22c2020-07-01 16:21:27 -0700332 0, 0, 0, MotionClassification::NONE, identityTransform,
333 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600334 AMOTION_EVENT_INVALID_CURSOR_POSITION, 0, 0,
335 pointerCount, pointerProperties, pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700336 ASSERT_EQ(BAD_VALUE, status)
337 << "publisher publishMotionEvent should return BAD_VALUE";
338}
339
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800340TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenPointerCountLessThan1_ReturnsError) {
341 status_t status;
342 const size_t pointerCount = 0;
343 PointerProperties pointerProperties[pointerCount];
344 PointerCoords pointerCoords[pointerCount];
345
chaviw9eaa22c2020-07-01 16:21:27 -0700346 ui::Transform identityTransform;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800347 status = mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
chaviw9eaa22c2020-07-01 16:21:27 -0700348 0, 0, 0, MotionClassification::NONE, identityTransform,
349 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600350 AMOTION_EVENT_INVALID_CURSOR_POSITION, 0, 0,
351 pointerCount, pointerProperties, pointerCoords);
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800352 ASSERT_EQ(BAD_VALUE, status)
353 << "publisher publishMotionEvent should return BAD_VALUE";
354}
355
356TEST_F(InputPublisherAndConsumerTest,
357 PublishMotionEvent_WhenPointerCountGreaterThanMax_ReturnsError) {
Jeff Brown5912f952013-07-01 19:10:31 -0700358 status_t status;
359 const size_t pointerCount = MAX_POINTERS + 1;
360 PointerProperties pointerProperties[pointerCount];
361 PointerCoords pointerCoords[pointerCount];
362 for (size_t i = 0; i < pointerCount; i++) {
363 pointerProperties[i].clear();
364 pointerCoords[i].clear();
365 }
366
chaviw9eaa22c2020-07-01 16:21:27 -0700367 ui::Transform identityTransform;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800368 status = mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
chaviw9eaa22c2020-07-01 16:21:27 -0700369 0, 0, 0, MotionClassification::NONE, identityTransform,
370 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600371 AMOTION_EVENT_INVALID_CURSOR_POSITION, 0, 0,
372 pointerCount, pointerProperties, pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700373 ASSERT_EQ(BAD_VALUE, status)
374 << "publisher publishMotionEvent should return BAD_VALUE";
375}
376
377TEST_F(InputPublisherAndConsumerTest, PublishMultipleEvents_EndToEnd) {
378 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
379 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
380 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800381 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeFocusEvent());
Jeff Brown5912f952013-07-01 19:10:31 -0700382 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
383 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
384}
385
386} // namespace android