blob: 3bc21fa2965617bf79fe4988455d2113f821b645 [file] [log] [blame]
Jeff Brownf4a4ec22010-06-16 01:53:36 -07001//
2// Copyright 2010 The Android Open Source Project
3//
4
5#include <ui/InputTransport.h>
6#include <utils/Timers.h>
7#include <utils/StopWatch.h>
8#include <gtest/gtest.h>
9#include <unistd.h>
10#include <time.h>
11#include <sys/mman.h>
12#include <cutils/ashmem.h>
13
14#include "../../utils/tests/TestHelpers.h"
15
16namespace android {
17
18class InputPublisherAndConsumerTest : public testing::Test {
19protected:
20 sp<InputChannel> serverChannel, clientChannel;
21 InputPublisher* mPublisher;
22 InputConsumer* mConsumer;
23 PreallocatedInputEventFactory mEventFactory;
24
25 virtual void SetUp() {
26 status_t result = InputChannel::openInputChannelPair(String8("channel name"),
27 serverChannel, clientChannel);
28
29 mPublisher = new InputPublisher(serverChannel);
30 mConsumer = new InputConsumer(clientChannel);
31 }
32
33 virtual void TearDown() {
34 if (mPublisher) {
35 delete mPublisher;
36 mPublisher = NULL;
37 }
38
39 if (mConsumer) {
40 delete mConsumer;
41 mConsumer = NULL;
42 }
43
44 serverChannel.clear();
45 clientChannel.clear();
46 }
47
48 void Initialize();
49 void PublishAndConsumeKeyEvent();
50 void PublishAndConsumeMotionEvent(
51 size_t samplesToAppendBeforeDispatch = 0,
52 size_t samplesToAppendAfterDispatch = 0);
53};
54
55TEST_F(InputPublisherAndConsumerTest, GetChannel_ReturnsTheChannel) {
56 EXPECT_EQ(serverChannel.get(), mPublisher->getChannel().get());
57 EXPECT_EQ(clientChannel.get(), mConsumer->getChannel().get());
58}
59
60void InputPublisherAndConsumerTest::Initialize() {
61 status_t status;
62
63 status = mPublisher->initialize();
64 ASSERT_EQ(OK, status)
65 << "publisher initialize should return OK";
66
67 status = mConsumer->initialize();
68 ASSERT_EQ(OK, status)
69 << "consumer initialize should return OK";
70}
71
72void InputPublisherAndConsumerTest::PublishAndConsumeKeyEvent() {
73 status_t status;
74
75 const int32_t deviceId = 1;
Jeff Brown5c1ed842010-07-14 18:48:53 -070076 const int32_t source = AINPUT_SOURCE_KEYBOARD;
77 const int32_t action = AKEY_EVENT_ACTION_DOWN;
78 const int32_t flags = AKEY_EVENT_FLAG_FROM_SYSTEM;
Jeff Brown8575a872010-06-30 16:10:35 -070079 const int32_t keyCode = AKEYCODE_ENTER;
Jeff Brownf4a4ec22010-06-16 01:53:36 -070080 const int32_t scanCode = 13;
Jeff Brown5c1ed842010-07-14 18:48:53 -070081 const int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON;
Jeff Brownf4a4ec22010-06-16 01:53:36 -070082 const int32_t repeatCount = 1;
83 const nsecs_t downTime = 3;
84 const nsecs_t eventTime = 4;
85
Jeff Brown5c1ed842010-07-14 18:48:53 -070086 status = mPublisher->publishKeyEvent(deviceId, source, action, flags,
Jeff Brownf4a4ec22010-06-16 01:53:36 -070087 keyCode, scanCode, metaState, repeatCount, downTime, eventTime);
88 ASSERT_EQ(OK, status)
89 << "publisher publishKeyEvent should return OK";
90
91 status = mPublisher->sendDispatchSignal();
92 ASSERT_EQ(OK, status)
93 << "publisher sendDispatchSignal should return OK";
94
95 status = mConsumer->receiveDispatchSignal();
96 ASSERT_EQ(OK, status)
97 << "consumer receiveDispatchSignal should return OK";
98
99 InputEvent* event;
100 status = mConsumer->consume(& mEventFactory, & event);
101 ASSERT_EQ(OK, status)
102 << "consumer consume should return OK";
103
104 ASSERT_TRUE(event != NULL)
105 << "consumer should have returned non-NULL event";
Jeff Brown5c1ed842010-07-14 18:48:53 -0700106 ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, event->getType())
Jeff Brownf4a4ec22010-06-16 01:53:36 -0700107 << "consumer should have returned a key event";
108
109 KeyEvent* keyEvent = static_cast<KeyEvent*>(event);
110 EXPECT_EQ(deviceId, keyEvent->getDeviceId());
Jeff Brown5c1ed842010-07-14 18:48:53 -0700111 EXPECT_EQ(source, keyEvent->getSource());
Jeff Brownf4a4ec22010-06-16 01:53:36 -0700112 EXPECT_EQ(action, keyEvent->getAction());
113 EXPECT_EQ(flags, keyEvent->getFlags());
114 EXPECT_EQ(keyCode, keyEvent->getKeyCode());
115 EXPECT_EQ(scanCode, keyEvent->getScanCode());
116 EXPECT_EQ(metaState, keyEvent->getMetaState());
117 EXPECT_EQ(repeatCount, keyEvent->getRepeatCount());
118 EXPECT_EQ(downTime, keyEvent->getDownTime());
119 EXPECT_EQ(eventTime, keyEvent->getEventTime());
120
121 status = mConsumer->sendFinishedSignal();
122 ASSERT_EQ(OK, status)
123 << "consumer sendFinishedSignal should return OK";
124
125 status = mPublisher->receiveFinishedSignal();
126 ASSERT_EQ(OK, status)
127 << "publisher receiveFinishedSignal should return OK";
128
129 status = mPublisher->reset();
130 ASSERT_EQ(OK, status)
131 << "publisher reset should return OK";
132}
133
134void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent(
135 size_t samplesToAppendBeforeDispatch, size_t samplesToAppendAfterDispatch) {
136 status_t status;
137
138 const int32_t deviceId = 1;
Jeff Brown5c1ed842010-07-14 18:48:53 -0700139 const int32_t source = AINPUT_SOURCE_TOUCHSCREEN;
140 const int32_t action = AMOTION_EVENT_ACTION_MOVE;
141 const int32_t edgeFlags = AMOTION_EVENT_EDGE_FLAG_TOP;
142 const int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON;
Jeff Brownf4a4ec22010-06-16 01:53:36 -0700143 const float xOffset = -10;
144 const float yOffset = -20;
145 const float xPrecision = 0.25;
146 const float yPrecision = 0.5;
147 const nsecs_t downTime = 3;
148 const size_t pointerCount = 3;
149 const int32_t pointerIds[pointerCount] = { 2, 0, 1 };
150
151 Vector<nsecs_t> sampleEventTimes;
152 Vector<PointerCoords> samplePointerCoords;
153
154 for (size_t i = 0; i <= samplesToAppendAfterDispatch + samplesToAppendBeforeDispatch; i++) {
155 sampleEventTimes.push(i + 10);
156 for (size_t j = 0; j < pointerCount; j++) {
157 samplePointerCoords.push();
158 samplePointerCoords.editTop().x = 100 * i + j;
159 samplePointerCoords.editTop().y = 200 * i + j;
160 samplePointerCoords.editTop().pressure = 0.5 * i + j;
161 samplePointerCoords.editTop().size = 0.7 * i + j;
Jeff Brown5c1ed842010-07-14 18:48:53 -0700162 samplePointerCoords.editTop().touchMajor = 1.5 * i + j;
163 samplePointerCoords.editTop().touchMinor = 1.7 * i + j;
164 samplePointerCoords.editTop().toolMajor = 2.5 * i + j;
165 samplePointerCoords.editTop().toolMinor = 2.7 * i + j;
166 samplePointerCoords.editTop().orientation = 3.5 * i + j;
Jeff Brownf4a4ec22010-06-16 01:53:36 -0700167 }
168 }
169
Jeff Brown5c1ed842010-07-14 18:48:53 -0700170 status = mPublisher->publishMotionEvent(deviceId, source, action, edgeFlags,
Jeff Brownf4a4ec22010-06-16 01:53:36 -0700171 metaState, xOffset, yOffset, xPrecision, yPrecision,
172 downTime, sampleEventTimes[0], pointerCount, pointerIds, samplePointerCoords.array());
173 ASSERT_EQ(OK, status)
174 << "publisher publishMotionEvent should return OK";
175
176 for (size_t i = 0; i < samplesToAppendBeforeDispatch; i++) {
177 size_t sampleIndex = i + 1;
178 status = mPublisher->appendMotionSample(sampleEventTimes[sampleIndex],
179 samplePointerCoords.array() + sampleIndex * pointerCount);
180 ASSERT_EQ(OK, status)
181 << "publisher appendMotionEvent should return OK";
182 }
183
184 status = mPublisher->sendDispatchSignal();
185 ASSERT_EQ(OK, status)
186 << "publisher sendDispatchSignal should return OK";
187
188 for (size_t i = 0; i < samplesToAppendAfterDispatch; i++) {
189 size_t sampleIndex = i + 1 + samplesToAppendBeforeDispatch;
190 status = mPublisher->appendMotionSample(sampleEventTimes[sampleIndex],
191 samplePointerCoords.array() + sampleIndex * pointerCount);
192 ASSERT_EQ(OK, status)
193 << "publisher appendMotionEvent should return OK";
194 }
195
196 status = mConsumer->receiveDispatchSignal();
197 ASSERT_EQ(OK, status)
198 << "consumer receiveDispatchSignal should return OK";
199
200 InputEvent* event;
201 status = mConsumer->consume(& mEventFactory, & event);
202 ASSERT_EQ(OK, status)
203 << "consumer consume should return OK";
204
205 ASSERT_TRUE(event != NULL)
206 << "consumer should have returned non-NULL event";
Jeff Brown5c1ed842010-07-14 18:48:53 -0700207 ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType())
Jeff Brownf4a4ec22010-06-16 01:53:36 -0700208 << "consumer should have returned a motion event";
209
210 size_t lastSampleIndex = samplesToAppendBeforeDispatch + samplesToAppendAfterDispatch;
211
212 MotionEvent* motionEvent = static_cast<MotionEvent*>(event);
213 EXPECT_EQ(deviceId, motionEvent->getDeviceId());
Jeff Brown5c1ed842010-07-14 18:48:53 -0700214 EXPECT_EQ(source, motionEvent->getSource());
Jeff Brownf4a4ec22010-06-16 01:53:36 -0700215 EXPECT_EQ(action, motionEvent->getAction());
216 EXPECT_EQ(edgeFlags, motionEvent->getEdgeFlags());
217 EXPECT_EQ(metaState, motionEvent->getMetaState());
218 EXPECT_EQ(xPrecision, motionEvent->getXPrecision());
219 EXPECT_EQ(yPrecision, motionEvent->getYPrecision());
220 EXPECT_EQ(downTime, motionEvent->getDownTime());
221 EXPECT_EQ(sampleEventTimes[lastSampleIndex], motionEvent->getEventTime());
222 EXPECT_EQ(pointerCount, motionEvent->getPointerCount());
223 EXPECT_EQ(lastSampleIndex, motionEvent->getHistorySize());
224
225 for (size_t i = 0; i < pointerCount; i++) {
226 SCOPED_TRACE(i);
227 EXPECT_EQ(pointerIds[i], motionEvent->getPointerId(i));
228 }
229
230 for (size_t sampleIndex = 0; sampleIndex < lastSampleIndex; sampleIndex++) {
231 SCOPED_TRACE(sampleIndex);
232 EXPECT_EQ(sampleEventTimes[sampleIndex],
233 motionEvent->getHistoricalEventTime(sampleIndex));
234 for (size_t i = 0; i < pointerCount; i++) {
235 SCOPED_TRACE(i);
236 size_t offset = sampleIndex * pointerCount + i;
237 EXPECT_EQ(samplePointerCoords[offset].x,
238 motionEvent->getHistoricalRawX(i, sampleIndex));
239 EXPECT_EQ(samplePointerCoords[offset].y,
240 motionEvent->getHistoricalRawY(i, sampleIndex));
241 EXPECT_EQ(samplePointerCoords[offset].x + xOffset,
242 motionEvent->getHistoricalX(i, sampleIndex));
243 EXPECT_EQ(samplePointerCoords[offset].y + yOffset,
244 motionEvent->getHistoricalY(i, sampleIndex));
245 EXPECT_EQ(samplePointerCoords[offset].pressure,
246 motionEvent->getHistoricalPressure(i, sampleIndex));
247 EXPECT_EQ(samplePointerCoords[offset].size,
248 motionEvent->getHistoricalSize(i, sampleIndex));
Jeff Brown5c1ed842010-07-14 18:48:53 -0700249 EXPECT_EQ(samplePointerCoords[offset].touchMajor,
250 motionEvent->getHistoricalTouchMajor(i, sampleIndex));
251 EXPECT_EQ(samplePointerCoords[offset].touchMinor,
252 motionEvent->getHistoricalTouchMinor(i, sampleIndex));
253 EXPECT_EQ(samplePointerCoords[offset].toolMajor,
254 motionEvent->getHistoricalToolMajor(i, sampleIndex));
255 EXPECT_EQ(samplePointerCoords[offset].toolMinor,
256 motionEvent->getHistoricalToolMinor(i, sampleIndex));
257 EXPECT_EQ(samplePointerCoords[offset].orientation,
258 motionEvent->getHistoricalOrientation(i, sampleIndex));
Jeff Brownf4a4ec22010-06-16 01:53:36 -0700259 }
260 }
261
262 SCOPED_TRACE(lastSampleIndex);
263 EXPECT_EQ(sampleEventTimes[lastSampleIndex], motionEvent->getEventTime());
264 for (size_t i = 0; i < pointerCount; i++) {
265 SCOPED_TRACE(i);
266 size_t offset = lastSampleIndex * pointerCount + i;
267 EXPECT_EQ(samplePointerCoords[offset].x, motionEvent->getRawX(i));
268 EXPECT_EQ(samplePointerCoords[offset].y, motionEvent->getRawY(i));
269 EXPECT_EQ(samplePointerCoords[offset].x + xOffset, motionEvent->getX(i));
270 EXPECT_EQ(samplePointerCoords[offset].y + yOffset, motionEvent->getY(i));
271 EXPECT_EQ(samplePointerCoords[offset].pressure, motionEvent->getPressure(i));
272 EXPECT_EQ(samplePointerCoords[offset].size, motionEvent->getSize(i));
Jeff Brown5c1ed842010-07-14 18:48:53 -0700273 EXPECT_EQ(samplePointerCoords[offset].touchMajor, motionEvent->getTouchMajor(i));
274 EXPECT_EQ(samplePointerCoords[offset].touchMinor, motionEvent->getTouchMinor(i));
275 EXPECT_EQ(samplePointerCoords[offset].toolMajor, motionEvent->getToolMajor(i));
276 EXPECT_EQ(samplePointerCoords[offset].toolMinor, motionEvent->getToolMinor(i));
277 EXPECT_EQ(samplePointerCoords[offset].orientation, motionEvent->getOrientation(i));
Jeff Brownf4a4ec22010-06-16 01:53:36 -0700278 }
279
280 status = mConsumer->sendFinishedSignal();
281 ASSERT_EQ(OK, status)
282 << "consumer sendFinishedSignal should return OK";
283
284 status = mPublisher->receiveFinishedSignal();
285 ASSERT_EQ(OK, status)
286 << "publisher receiveFinishedSignal should return OK";
287
288 status = mPublisher->reset();
289 ASSERT_EQ(OK, status)
290 << "publisher reset should return OK";
291}
292
293TEST_F(InputPublisherAndConsumerTest, PublishKeyEvent_EndToEnd) {
294 ASSERT_NO_FATAL_FAILURE(Initialize());
295 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
296}
297
298TEST_F(InputPublisherAndConsumerTest, PublishKeyEvent_WhenNotReset_ReturnsError) {
299 status_t status;
300 ASSERT_NO_FATAL_FAILURE(Initialize());
301
302 status = mPublisher->publishKeyEvent(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
303 ASSERT_EQ(OK, status)
304 << "publisher publishKeyEvent should return OK first time";
305
306 status = mPublisher->publishKeyEvent(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
307 ASSERT_EQ(INVALID_OPERATION, status)
308 << "publisher publishKeyEvent should return INVALID_OPERATION because "
309 "the publisher was not reset";
310}
311
312TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_EndToEnd) {
313 ASSERT_NO_FATAL_FAILURE(Initialize());
314 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
315}
316
317TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenNotReset_ReturnsError) {
318 status_t status;
319 ASSERT_NO_FATAL_FAILURE(Initialize());
320
321 const size_t pointerCount = 1;
322 int32_t pointerIds[pointerCount] = { 0 };
Jeff Brown5c1ed842010-07-14 18:48:53 -0700323 PointerCoords pointerCoords[pointerCount] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
Jeff Brownf4a4ec22010-06-16 01:53:36 -0700324
325 status = mPublisher->publishMotionEvent(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
326 pointerCount, pointerIds, pointerCoords);
327 ASSERT_EQ(OK, status)
328 << "publisher publishMotionEvent should return OK";
329
330 status = mPublisher->publishMotionEvent(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
331 pointerCount, pointerIds, pointerCoords);
332 ASSERT_EQ(INVALID_OPERATION, status)
333 << "publisher publishMotionEvent should return INVALID_OPERATION because ";
334 "the publisher was not reset";
335}
336
337TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenPointerCountLessThan1_ReturnsError) {
338 status_t status;
339 ASSERT_NO_FATAL_FAILURE(Initialize());
340
341 const size_t pointerCount = 0;
342 int32_t pointerIds[pointerCount];
343 PointerCoords pointerCoords[pointerCount];
344
345 status = mPublisher->publishMotionEvent(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
346 pointerCount, pointerIds, pointerCoords);
347 ASSERT_EQ(BAD_VALUE, status)
348 << "publisher publishMotionEvent should return BAD_VALUE";
349}
350
351TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenPointerCountGreaterThanMax_ReturnsError) {
352 status_t status;
353 ASSERT_NO_FATAL_FAILURE(Initialize());
354
355 const size_t pointerCount = MAX_POINTERS + 1;
356 int32_t pointerIds[pointerCount];
357 PointerCoords pointerCoords[pointerCount];
358
359 status = mPublisher->publishMotionEvent(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
360 pointerCount, pointerIds, pointerCoords);
361 ASSERT_EQ(BAD_VALUE, status)
362 << "publisher publishMotionEvent should return BAD_VALUE";
363}
364
365TEST_F(InputPublisherAndConsumerTest, PublishMultipleEvents_EndToEnd) {
366 ASSERT_NO_FATAL_FAILURE(Initialize());
367 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
368 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
369 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
370 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
371 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
372}
373
374TEST_F(InputPublisherAndConsumerTest, AppendMotionSample_WhenCalledBeforeDispatchSignal_AppendsSamples) {
375 status_t status;
376 ASSERT_NO_FATAL_FAILURE(Initialize());
377 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent(3, 0));
378}
379
380TEST_F(InputPublisherAndConsumerTest, AppendMotionSample_WhenCalledAfterDispatchSignalAndNotConsumed_AppendsSamples) {
381 status_t status;
382 ASSERT_NO_FATAL_FAILURE(Initialize());
383 ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent(0, 4));
384}
385
386TEST_F(InputPublisherAndConsumerTest, AppendMotionSample_WhenNoMotionEventPublished_ReturnsError) {
387 status_t status;
388 ASSERT_NO_FATAL_FAILURE(Initialize());
389
390 PointerCoords pointerCoords[1];
391 status = mPublisher->appendMotionSample(0, pointerCoords);
392 ASSERT_EQ(INVALID_OPERATION, status)
393 << "publisher appendMotionSample should return INVALID_OPERATION";
394}
395
396TEST_F(InputPublisherAndConsumerTest, AppendMotionSample_WhenPublishedMotionEventIsNotAMove_ReturnsError) {
397 status_t status;
398 ASSERT_NO_FATAL_FAILURE(Initialize());
399
400 const size_t pointerCount = MAX_POINTERS;
401 int32_t pointerIds[pointerCount];
402 PointerCoords pointerCoords[pointerCount];
403
Jeff Brown5c1ed842010-07-14 18:48:53 -0700404 status = mPublisher->publishMotionEvent(0, 0, AMOTION_EVENT_ACTION_DOWN,
Jeff Brownf4a4ec22010-06-16 01:53:36 -0700405 0, 0, 0, 0, 0, 0, 0, 0, pointerCount, pointerIds, pointerCoords);
406 ASSERT_EQ(OK, status);
407
408 status = mPublisher->appendMotionSample(0, pointerCoords);
409 ASSERT_EQ(INVALID_OPERATION, status)
410 << "publisher appendMotionSample should return INVALID_OPERATION";
411}
412
413TEST_F(InputPublisherAndConsumerTest, AppendMotionSample_WhenAlreadyConsumed_ReturnsError) {
414 status_t status;
415 ASSERT_NO_FATAL_FAILURE(Initialize());
416
417 const size_t pointerCount = MAX_POINTERS;
418 int32_t pointerIds[pointerCount];
419 PointerCoords pointerCoords[pointerCount];
420
Jeff Brown5c1ed842010-07-14 18:48:53 -0700421 status = mPublisher->publishMotionEvent(0, 0, AMOTION_EVENT_ACTION_MOVE,
Jeff Brownf4a4ec22010-06-16 01:53:36 -0700422 0, 0, 0, 0, 0, 0, 0, 0, pointerCount, pointerIds, pointerCoords);
423 ASSERT_EQ(OK, status);
424
425 status = mPublisher->sendDispatchSignal();
426 ASSERT_EQ(OK, status);
427
428 status = mConsumer->receiveDispatchSignal();
429 ASSERT_EQ(OK, status);
430
431 InputEvent* event;
432 status = mConsumer->consume(& mEventFactory, & event);
433 ASSERT_EQ(OK, status);
434
435 status = mPublisher->appendMotionSample(0, pointerCoords);
436 ASSERT_EQ(status_t(FAILED_TRANSACTION), status)
437 << "publisher appendMotionSample should return FAILED_TRANSACTION";
438}
439
440TEST_F(InputPublisherAndConsumerTest, AppendMotionSample_WhenBufferFull_ReturnsError) {
441 status_t status;
442 ASSERT_NO_FATAL_FAILURE(Initialize());
443
444 const size_t pointerCount = MAX_POINTERS;
445 int32_t pointerIds[pointerCount];
446 PointerCoords pointerCoords[pointerCount];
447
Jeff Brown5c1ed842010-07-14 18:48:53 -0700448 status = mPublisher->publishMotionEvent(0, 0, AMOTION_EVENT_ACTION_MOVE,
Jeff Brownf4a4ec22010-06-16 01:53:36 -0700449 0, 0, 0, 0, 0, 0, 0, 0, pointerCount, pointerIds, pointerCoords);
450 ASSERT_EQ(OK, status);
451
452 for (int count = 1;; count++) {
453 ASSERT_LT(count, 100000) << "should eventually reach OOM";
454
455 status = mPublisher->appendMotionSample(0, pointerCoords);
456 if (status != OK) {
457 ASSERT_GT(count, 12) << "should be able to add at least a dozen samples";
458 ASSERT_EQ(NO_MEMORY, status)
459 << "publisher appendMotionSample should return NO_MEMORY when buffer is full";
460 break;
461 }
462 }
463
464 status = mPublisher->appendMotionSample(0, pointerCoords);
465 ASSERT_EQ(NO_MEMORY, status)
466 << "publisher appendMotionSample should return NO_MEMORY persistently until reset";
467}
468
469} // namespace android