1ebbd5d14ad3b1e762d9fcfa026e19413cc857e05Jeff Brown/*
2ebbd5d14ad3b1e762d9fcfa026e19413cc857e05Jeff Brown * Copyright (C) 2010 The Android Open Source Project
3ebbd5d14ad3b1e762d9fcfa026e19413cc857e05Jeff Brown *
4ebbd5d14ad3b1e762d9fcfa026e19413cc857e05Jeff Brown * Licensed under the Apache License, Version 2.0 (the "License");
5ebbd5d14ad3b1e762d9fcfa026e19413cc857e05Jeff Brown * you may not use this file except in compliance with the License.
6ebbd5d14ad3b1e762d9fcfa026e19413cc857e05Jeff Brown * You may obtain a copy of the License at
7ebbd5d14ad3b1e762d9fcfa026e19413cc857e05Jeff Brown *
8ebbd5d14ad3b1e762d9fcfa026e19413cc857e05Jeff Brown *      http://www.apache.org/licenses/LICENSE-2.0
9ebbd5d14ad3b1e762d9fcfa026e19413cc857e05Jeff Brown *
10ebbd5d14ad3b1e762d9fcfa026e19413cc857e05Jeff Brown * Unless required by applicable law or agreed to in writing, software
11ebbd5d14ad3b1e762d9fcfa026e19413cc857e05Jeff Brown * distributed under the License is distributed on an "AS IS" BASIS,
12ebbd5d14ad3b1e762d9fcfa026e19413cc857e05Jeff Brown * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13ebbd5d14ad3b1e762d9fcfa026e19413cc857e05Jeff Brown * See the License for the specific language governing permissions and
14ebbd5d14ad3b1e762d9fcfa026e19413cc857e05Jeff Brown * limitations under the License.
15ebbd5d14ad3b1e762d9fcfa026e19413cc857e05Jeff Brown */
165c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
17b93a03f841d93498bfea6cc92a22faa34bce1337Mathias Agopian#include <androidfw/InputTransport.h>
185c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown#include <utils/Timers.h>
195c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown#include <utils/StopWatch.h>
205c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown#include <gtest/gtest.h>
215c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown#include <unistd.h>
225c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown#include <time.h>
235c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown#include <sys/mman.h>
245c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown#include <cutils/ashmem.h>
255c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
2608965ec67ada98f63f8ac879cc44c8b0e7ff046dMathias Agopian#include "TestHelpers.h"
275c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
285c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brownnamespace android {
295c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
305c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brownclass InputPublisherAndConsumerTest : public testing::Test {
315c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brownprotected:
325c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    sp<InputChannel> serverChannel, clientChannel;
335c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    InputPublisher* mPublisher;
345c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    InputConsumer* mConsumer;
355c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    PreallocatedInputEventFactory mEventFactory;
365c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
375c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    virtual void SetUp() {
385c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown        status_t result = InputChannel::openInputChannelPair(String8("channel name"),
395c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown                serverChannel, clientChannel);
405c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
415c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown        mPublisher = new InputPublisher(serverChannel);
425c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown        mConsumer = new InputConsumer(clientChannel);
435c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    }
445c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
455c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    virtual void TearDown() {
465c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown        if (mPublisher) {
475c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown            delete mPublisher;
485c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown            mPublisher = NULL;
495c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown        }
505c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
515c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown        if (mConsumer) {
525c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown            delete mConsumer;
535c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown            mConsumer = NULL;
545c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown        }
555c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
565c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown        serverChannel.clear();
575c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown        clientChannel.clear();
585c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    }
595c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
605c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    void PublishAndConsumeKeyEvent();
61cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown    void PublishAndConsumeMotionEvent();
625c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown};
635c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
645c225b1680e696ae8bbf505a1997d6f720672f74Jeff BrownTEST_F(InputPublisherAndConsumerTest, GetChannel_ReturnsTheChannel) {
655c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    EXPECT_EQ(serverChannel.get(), mPublisher->getChannel().get());
665c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    EXPECT_EQ(clientChannel.get(), mConsumer->getChannel().get());
675c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown}
685c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
695c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brownvoid InputPublisherAndConsumerTest::PublishAndConsumeKeyEvent() {
705c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    status_t status;
715c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
72072ec96a4900d4616574733646ee46311cb5d2cbJeff Brown    const uint32_t seq = 15;
735c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    const int32_t deviceId = 1;
74c5ed5910c9ef066cec6a13bbb404ec57b1e92637Jeff Brown    const int32_t source = AINPUT_SOURCE_KEYBOARD;
75c5ed5910c9ef066cec6a13bbb404ec57b1e92637Jeff Brown    const int32_t action = AKEY_EVENT_ACTION_DOWN;
76c5ed5910c9ef066cec6a13bbb404ec57b1e92637Jeff Brown    const int32_t flags = AKEY_EVENT_FLAG_FROM_SYSTEM;
77fd03582995e0fce963dd0fa0669e3211b74c0dd7Jeff Brown    const int32_t keyCode = AKEYCODE_ENTER;
785c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    const int32_t scanCode = 13;
79c5ed5910c9ef066cec6a13bbb404ec57b1e92637Jeff Brown    const int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON;
805c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    const int32_t repeatCount = 1;
815c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    const nsecs_t downTime = 3;
825c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    const nsecs_t eventTime = 4;
835c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
84072ec96a4900d4616574733646ee46311cb5d2cbJeff Brown    status = mPublisher->publishKeyEvent(seq, deviceId, source, action, flags,
855c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown            keyCode, scanCode, metaState, repeatCount, downTime, eventTime);
865c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    ASSERT_EQ(OK, status)
875c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown            << "publisher publishKeyEvent should return OK";
885c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
89072ec96a4900d4616574733646ee46311cb5d2cbJeff Brown    uint32_t consumeSeq;
905c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    InputEvent* event;
91771526c88f5cc4b56a41cb12aa06a28d377a07d5Jeff Brown    status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event);
925c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    ASSERT_EQ(OK, status)
935c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown            << "consumer consume should return OK";
945c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
955c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    ASSERT_TRUE(event != NULL)
965c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown            << "consumer should have returned non-NULL event";
97c5ed5910c9ef066cec6a13bbb404ec57b1e92637Jeff Brown    ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, event->getType())
985c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown            << "consumer should have returned a key event";
995c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
1005c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    KeyEvent* keyEvent = static_cast<KeyEvent*>(event);
101072ec96a4900d4616574733646ee46311cb5d2cbJeff Brown    EXPECT_EQ(seq, consumeSeq);
1025c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    EXPECT_EQ(deviceId, keyEvent->getDeviceId());
103c5ed5910c9ef066cec6a13bbb404ec57b1e92637Jeff Brown    EXPECT_EQ(source, keyEvent->getSource());
1045c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    EXPECT_EQ(action, keyEvent->getAction());
1055c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    EXPECT_EQ(flags, keyEvent->getFlags());
1065c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    EXPECT_EQ(keyCode, keyEvent->getKeyCode());
1075c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    EXPECT_EQ(scanCode, keyEvent->getScanCode());
1085c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    EXPECT_EQ(metaState, keyEvent->getMetaState());
1095c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    EXPECT_EQ(repeatCount, keyEvent->getRepeatCount());
1105c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    EXPECT_EQ(downTime, keyEvent->getDownTime());
1115c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    EXPECT_EQ(eventTime, keyEvent->getEventTime());
1125c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
113072ec96a4900d4616574733646ee46311cb5d2cbJeff Brown    status = mConsumer->sendFinishedSignal(seq, true);
1145c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    ASSERT_EQ(OK, status)
1155c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown            << "consumer sendFinishedSignal should return OK";
1165c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
117072ec96a4900d4616574733646ee46311cb5d2cbJeff Brown    uint32_t finishedSeq = 0;
1183915bb845b032dc184dba5e60970b803390ca3edJeff Brown    bool handled = false;
119072ec96a4900d4616574733646ee46311cb5d2cbJeff Brown    status = mPublisher->receiveFinishedSignal(&finishedSeq, &handled);
1205c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    ASSERT_EQ(OK, status)
1215c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown            << "publisher receiveFinishedSignal should return OK";
122072ec96a4900d4616574733646ee46311cb5d2cbJeff Brown    ASSERT_EQ(seq, finishedSeq)
123072ec96a4900d4616574733646ee46311cb5d2cbJeff Brown            << "publisher receiveFinishedSignal should have returned the original sequence number";
1243915bb845b032dc184dba5e60970b803390ca3edJeff Brown    ASSERT_TRUE(handled)
1253915bb845b032dc184dba5e60970b803390ca3edJeff Brown            << "publisher receiveFinishedSignal should have set handled to consumer's reply";
1265c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown}
1275c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
128cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brownvoid InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent() {
1295c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    status_t status;
1305c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
131072ec96a4900d4616574733646ee46311cb5d2cbJeff Brown    const uint32_t seq = 15;
1325c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    const int32_t deviceId = 1;
133c5ed5910c9ef066cec6a13bbb404ec57b1e92637Jeff Brown    const int32_t source = AINPUT_SOURCE_TOUCHSCREEN;
134c5ed5910c9ef066cec6a13bbb404ec57b1e92637Jeff Brown    const int32_t action = AMOTION_EVENT_ACTION_MOVE;
13585a3176704b5bfbeece9bd928369fbb76eec7dc6Jeff Brown    const int32_t flags = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED;
136c5ed5910c9ef066cec6a13bbb404ec57b1e92637Jeff Brown    const int32_t edgeFlags = AMOTION_EVENT_EDGE_FLAG_TOP;
137c5ed5910c9ef066cec6a13bbb404ec57b1e92637Jeff Brown    const int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON;
138fe9f8ab03a63b1037f07dd85799fbea80ec6adaaJeff Brown    const int32_t buttonState = AMOTION_EVENT_BUTTON_PRIMARY;
1395c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    const float xOffset = -10;
1405c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    const float yOffset = -20;
1415c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    const float xPrecision = 0.25;
1425c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    const float yPrecision = 0.5;
1435c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    const nsecs_t downTime = 3;
1445c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    const size_t pointerCount = 3;
145cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown    const nsecs_t eventTime = 4;
146fe9f8ab03a63b1037f07dd85799fbea80ec6adaaJeff Brown    PointerProperties pointerProperties[pointerCount];
147cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown    PointerCoords pointerCoords[pointerCount];
148fe9f8ab03a63b1037f07dd85799fbea80ec6adaaJeff Brown    for (size_t i = 0; i < pointerCount; i++) {
149fe9f8ab03a63b1037f07dd85799fbea80ec6adaaJeff Brown        pointerProperties[i].clear();
150fe9f8ab03a63b1037f07dd85799fbea80ec6adaaJeff Brown        pointerProperties[i].id = (i + 2) % pointerCount;
151fe9f8ab03a63b1037f07dd85799fbea80ec6adaaJeff Brown        pointerProperties[i].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
1525c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
153cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        pointerCoords[i].clear();
154cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, 100 * i);
155cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_Y, 200 * i);
156cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 0.5 * i);
157cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 0.7 * i);
158cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 1.5 * i);
159cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 1.7 * i);
160cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.5 * i);
161cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.7 * i);
162cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 3.5 * i);
1635c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    }
1645c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
165072ec96a4900d4616574733646ee46311cb5d2cbJeff Brown    status = mPublisher->publishMotionEvent(seq, deviceId, source, action, flags, edgeFlags,
166fe9f8ab03a63b1037f07dd85799fbea80ec6adaaJeff Brown            metaState, buttonState, xOffset, yOffset, xPrecision, yPrecision,
167cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown            downTime, eventTime, pointerCount,
168cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown            pointerProperties, pointerCoords);
1695c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    ASSERT_EQ(OK, status)
1705c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown            << "publisher publishMotionEvent should return OK";
1715c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
172072ec96a4900d4616574733646ee46311cb5d2cbJeff Brown    uint32_t consumeSeq;
1735c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    InputEvent* event;
174771526c88f5cc4b56a41cb12aa06a28d377a07d5Jeff Brown    status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event);
1755c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    ASSERT_EQ(OK, status)
1765c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown            << "consumer consume should return OK";
1775c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
1785c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    ASSERT_TRUE(event != NULL)
1795c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown            << "consumer should have returned non-NULL event";
180c5ed5910c9ef066cec6a13bbb404ec57b1e92637Jeff Brown    ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType())
1815c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown            << "consumer should have returned a motion event";
1825c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
1835c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    MotionEvent* motionEvent = static_cast<MotionEvent*>(event);
184072ec96a4900d4616574733646ee46311cb5d2cbJeff Brown    EXPECT_EQ(seq, consumeSeq);
1855c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    EXPECT_EQ(deviceId, motionEvent->getDeviceId());
186c5ed5910c9ef066cec6a13bbb404ec57b1e92637Jeff Brown    EXPECT_EQ(source, motionEvent->getSource());
1875c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    EXPECT_EQ(action, motionEvent->getAction());
18885a3176704b5bfbeece9bd928369fbb76eec7dc6Jeff Brown    EXPECT_EQ(flags, motionEvent->getFlags());
1895c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    EXPECT_EQ(edgeFlags, motionEvent->getEdgeFlags());
1905c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    EXPECT_EQ(metaState, motionEvent->getMetaState());
191fe9f8ab03a63b1037f07dd85799fbea80ec6adaaJeff Brown    EXPECT_EQ(buttonState, motionEvent->getButtonState());
1925c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    EXPECT_EQ(xPrecision, motionEvent->getXPrecision());
1935c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    EXPECT_EQ(yPrecision, motionEvent->getYPrecision());
1945c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    EXPECT_EQ(downTime, motionEvent->getDownTime());
195cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown    EXPECT_EQ(eventTime, motionEvent->getEventTime());
1965c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    EXPECT_EQ(pointerCount, motionEvent->getPointerCount());
197cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown    EXPECT_EQ(0U, motionEvent->getHistorySize());
1985c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
1995c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    for (size_t i = 0; i < pointerCount; i++) {
2005c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown        SCOPED_TRACE(i);
201fe9f8ab03a63b1037f07dd85799fbea80ec6adaaJeff Brown        EXPECT_EQ(pointerProperties[i].id, motionEvent->getPointerId(i));
202fe9f8ab03a63b1037f07dd85799fbea80ec6adaaJeff Brown        EXPECT_EQ(pointerProperties[i].toolType, motionEvent->getToolType(i));
2035c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
204cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X),
20591c69ab01539f7ba28708f41ec1835cc2920d0a0Jeff Brown                motionEvent->getRawX(i));
206cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y),
20791c69ab01539f7ba28708f41ec1835cc2920d0a0Jeff Brown                motionEvent->getRawY(i));
208cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X) + xOffset,
20991c69ab01539f7ba28708f41ec1835cc2920d0a0Jeff Brown                motionEvent->getX(i));
210cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y) + yOffset,
21191c69ab01539f7ba28708f41ec1835cc2920d0a0Jeff Brown                motionEvent->getY(i));
212cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE),
21391c69ab01539f7ba28708f41ec1835cc2920d0a0Jeff Brown                motionEvent->getPressure(i));
214cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_SIZE),
21591c69ab01539f7ba28708f41ec1835cc2920d0a0Jeff Brown                motionEvent->getSize(i));
216cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR),
21791c69ab01539f7ba28708f41ec1835cc2920d0a0Jeff Brown                motionEvent->getTouchMajor(i));
218cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR),
21991c69ab01539f7ba28708f41ec1835cc2920d0a0Jeff Brown                motionEvent->getTouchMinor(i));
220cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR),
22191c69ab01539f7ba28708f41ec1835cc2920d0a0Jeff Brown                motionEvent->getToolMajor(i));
222cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR),
22391c69ab01539f7ba28708f41ec1835cc2920d0a0Jeff Brown                motionEvent->getToolMinor(i));
224cbee6d6ede0499fb4a2c00bfc00d5db8d9ed5139Jeff Brown        EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION),
22591c69ab01539f7ba28708f41ec1835cc2920d0a0Jeff Brown                motionEvent->getOrientation(i));
2265c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    }
2275c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
228072ec96a4900d4616574733646ee46311cb5d2cbJeff Brown    status = mConsumer->sendFinishedSignal(seq, false);
2295c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    ASSERT_EQ(OK, status)
2305c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown            << "consumer sendFinishedSignal should return OK";
2315c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
232072ec96a4900d4616574733646ee46311cb5d2cbJeff Brown    uint32_t finishedSeq = 0;
2333915bb845b032dc184dba5e60970b803390ca3edJeff Brown    bool handled = true;
234072ec96a4900d4616574733646ee46311cb5d2cbJeff Brown    status = mPublisher->receiveFinishedSignal(&finishedSeq, &handled);
2355c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    ASSERT_EQ(OK, status)
2365c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown            << "publisher receiveFinishedSignal should return OK";
237072ec96a4900d4616574733646ee46311cb5d2cbJeff Brown    ASSERT_EQ(seq, finishedSeq)
238072ec96a4900d4616574733646ee46311cb5d2cbJeff Brown            << "publisher receiveFinishedSignal should have returned the original sequence number";
2393915bb845b032dc184dba5e60970b803390ca3edJeff Brown    ASSERT_FALSE(handled)
2403915bb845b032dc184dba5e60970b803390ca3edJeff Brown            << "publisher receiveFinishedSignal should have set handled to consumer's reply";
2415c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown}
2425c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
2435c225b1680e696ae8bbf505a1997d6f720672f74Jeff BrownTEST_F(InputPublisherAndConsumerTest, PublishKeyEvent_EndToEnd) {
2445c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
2455c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown}
2465c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
2475c225b1680e696ae8bbf505a1997d6f720672f74Jeff BrownTEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_EndToEnd) {
2485c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
2495c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown}
2505c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
2515c225b1680e696ae8bbf505a1997d6f720672f74Jeff BrownTEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenPointerCountLessThan1_ReturnsError) {
2525c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    status_t status;
2535c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    const size_t pointerCount = 0;
254fe9f8ab03a63b1037f07dd85799fbea80ec6adaaJeff Brown    PointerProperties pointerProperties[pointerCount];
2555c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    PointerCoords pointerCoords[pointerCount];
2565c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
257072ec96a4900d4616574733646ee46311cb5d2cbJeff Brown    status = mPublisher->publishMotionEvent(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
258fe9f8ab03a63b1037f07dd85799fbea80ec6adaaJeff Brown            pointerCount, pointerProperties, pointerCoords);
2595c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    ASSERT_EQ(BAD_VALUE, status)
2605c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown            << "publisher publishMotionEvent should return BAD_VALUE";
2615c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown}
2625c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
2635c225b1680e696ae8bbf505a1997d6f720672f74Jeff BrownTEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenPointerCountGreaterThanMax_ReturnsError) {
2645c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    status_t status;
2655c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    const size_t pointerCount = MAX_POINTERS + 1;
266fe9f8ab03a63b1037f07dd85799fbea80ec6adaaJeff Brown    PointerProperties pointerProperties[pointerCount];
2675c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    PointerCoords pointerCoords[pointerCount];
268fe9f8ab03a63b1037f07dd85799fbea80ec6adaaJeff Brown    for (size_t i = 0; i < pointerCount; i++) {
269fe9f8ab03a63b1037f07dd85799fbea80ec6adaaJeff Brown        pointerProperties[i].clear();
270fe9f8ab03a63b1037f07dd85799fbea80ec6adaaJeff Brown        pointerCoords[i].clear();
271fe9f8ab03a63b1037f07dd85799fbea80ec6adaaJeff Brown    }
2725c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
273072ec96a4900d4616574733646ee46311cb5d2cbJeff Brown    status = mPublisher->publishMotionEvent(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
274fe9f8ab03a63b1037f07dd85799fbea80ec6adaaJeff Brown            pointerCount, pointerProperties, pointerCoords);
2755c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    ASSERT_EQ(BAD_VALUE, status)
2765c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown            << "publisher publishMotionEvent should return BAD_VALUE";
2775c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown}
2785c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
2795c225b1680e696ae8bbf505a1997d6f720672f74Jeff BrownTEST_F(InputPublisherAndConsumerTest, PublishMultipleEvents_EndToEnd) {
2805c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
2815c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
2825c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
2835c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
2845c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown    ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
2855c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown}
2865c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown
2875c225b1680e696ae8bbf505a1997d6f720672f74Jeff Brown} // namespace android
288