blob: a0a0f5a3dec8a6736580b34e1674f86918c1cada [file] [log] [blame]
Prabir Pradhan739dca42022-09-09 20:12:01 +00001/*
2 * Copyright (C) 2022 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
Prabir Pradhan48108662022-09-09 21:22:04 +000017#pragma once
Prabir Pradhan739dca42022-09-09 20:12:01 +000018
Harry Cuttsc5748d12022-12-02 17:30:18 +000019#include <cmath>
Prabir Pradhan7b6502d2023-10-06 04:08:39 +000020#include <compare>
Harry Cuttsc5748d12022-12-02 17:30:18 +000021
Prabir Pradhan7b6502d2023-10-06 04:08:39 +000022#include <android-base/stringprintf.h>
Prabir Pradhan739dca42022-09-09 20:12:01 +000023#include <android/input.h>
24#include <gmock/gmock.h>
25#include <gtest/gtest.h>
Prabir Pradhanda20b172022-09-26 17:01:18 +000026#include <input/Input.h>
Prabir Pradhan7b6502d2023-10-06 04:08:39 +000027#include <input/PrintTools.h>
Prabir Pradhan739dca42022-09-09 20:12:01 +000028
Siarhei Vishniakoub237f9e2023-07-21 16:42:23 -070029#include "NotifyArgs.h"
Harry Cutts8743f182023-05-17 12:03:49 +000030#include "TestConstants.h"
31
Prabir Pradhan739dca42022-09-09 20:12:01 +000032namespace android {
33
Prabir Pradhan7b6502d2023-10-06 04:08:39 +000034struct PointF {
35 float x;
36 float y;
37 auto operator<=>(const PointF&) const = default;
38};
39
40inline std::string pointFToString(const PointF& p) {
41 return std::string("(") + std::to_string(p.x) + ", " + std::to_string(p.y) + ")";
42}
43
44/// Source
45class WithSourceMatcher {
46public:
47 using is_gtest_matcher = void;
48 explicit WithSourceMatcher(uint32_t source) : mSource(source) {}
49
50 bool MatchAndExplain(const NotifyMotionArgs& args, std::ostream*) const {
51 return mSource == args.source;
52 }
53
54 bool MatchAndExplain(const NotifyKeyArgs& args, std::ostream*) const {
55 return mSource == args.source;
56 }
57
58 bool MatchAndExplain(const InputEvent& event, std::ostream*) const {
59 return mSource == event.getSource();
60 }
61
62 void DescribeTo(std::ostream* os) const {
63 *os << "with source " << inputEventSourceToString(mSource);
64 }
65
66 void DescribeNegationTo(std::ostream* os) const { *os << "wrong source"; }
67
68private:
69 const uint32_t mSource;
70};
71
72inline WithSourceMatcher WithSource(uint32_t source) {
73 return WithSourceMatcher(source);
Prabir Pradhan739dca42022-09-09 20:12:01 +000074}
75
Siarhei Vishniakoub237f9e2023-07-21 16:42:23 -070076/// Key action
77class WithKeyActionMatcher {
78public:
79 using is_gtest_matcher = void;
80 explicit WithKeyActionMatcher(int32_t action) : mAction(action) {}
Prabir Pradhan739dca42022-09-09 20:12:01 +000081
Siarhei Vishniakoub237f9e2023-07-21 16:42:23 -070082 bool MatchAndExplain(const NotifyKeyArgs& args, std::ostream*) const {
83 return mAction == args.action;
84 }
85
86 bool MatchAndExplain(const KeyEvent& event, std::ostream*) const {
87 return mAction == event.getAction();
88 }
89
90 void DescribeTo(std::ostream* os) const {
91 *os << "with key action " << KeyEvent::actionToString(mAction);
92 }
93
94 void DescribeNegationTo(std::ostream* os) const { *os << "wrong action"; }
95
96private:
97 const int32_t mAction;
98};
99
Prabir Pradhan7b6502d2023-10-06 04:08:39 +0000100inline WithKeyActionMatcher WithKeyAction(int32_t action) {
101 return WithKeyActionMatcher(action);
102}
Siarhei Vishniakoub237f9e2023-07-21 16:42:23 -0700103
104/// Motion action
105class WithMotionActionMatcher {
106public:
107 using is_gtest_matcher = void;
108 explicit WithMotionActionMatcher(int32_t action) : mAction(action) {}
109
110 bool MatchAndExplain(const NotifyMotionArgs& args, std::ostream*) const {
111 bool matches = mAction == args.action;
112 if (args.action == AMOTION_EVENT_ACTION_CANCEL) {
113 matches &= (args.flags & AMOTION_EVENT_FLAG_CANCELED) != 0;
114 }
115 return matches;
116 }
117
118 bool MatchAndExplain(const MotionEvent& event, std::ostream*) const {
119 bool matches = mAction == event.getAction();
120 if (event.getAction() == AMOTION_EVENT_ACTION_CANCEL) {
121 matches &= (event.getFlags() & AMOTION_EVENT_FLAG_CANCELED) != 0;
122 }
123 return matches;
124 }
125
126 void DescribeTo(std::ostream* os) const {
127 *os << "with motion action " << MotionEvent::actionToString(mAction);
128 if (mAction == AMOTION_EVENT_ACTION_CANCEL) {
129 *os << " and FLAG_CANCELED";
130 }
131 }
132
133 void DescribeNegationTo(std::ostream* os) const { *os << "wrong action"; }
134
135private:
136 const int32_t mAction;
137};
138
Prabir Pradhan7b6502d2023-10-06 04:08:39 +0000139inline WithMotionActionMatcher WithMotionAction(int32_t action) {
140 return WithMotionActionMatcher(action);
141}
Siarhei Vishniakoub237f9e2023-07-21 16:42:23 -0700142
143/// Display Id
144class WithDisplayIdMatcher {
145public:
146 using is_gtest_matcher = void;
147 explicit WithDisplayIdMatcher(int32_t displayId) : mDisplayId(displayId) {}
148
149 bool MatchAndExplain(const NotifyMotionArgs& args, std::ostream*) const {
150 return mDisplayId == args.displayId;
151 }
152
153 bool MatchAndExplain(const NotifyKeyArgs& args, std::ostream*) const {
154 return mDisplayId == args.displayId;
155 }
156
157 bool MatchAndExplain(const InputEvent& event, std::ostream*) const {
158 return mDisplayId == event.getDisplayId();
159 }
160
161 void DescribeTo(std::ostream* os) const { *os << "with display id " << mDisplayId; }
162
163 void DescribeNegationTo(std::ostream* os) const { *os << "wrong display id"; }
164
165private:
166 const int32_t mDisplayId;
167};
168
Prabir Pradhan7b6502d2023-10-06 04:08:39 +0000169inline WithDisplayIdMatcher WithDisplayId(int32_t displayId) {
170 return WithDisplayIdMatcher(displayId);
171}
Siarhei Vishniakoub237f9e2023-07-21 16:42:23 -0700172
173/// Device Id
174class WithDeviceIdMatcher {
175public:
176 using is_gtest_matcher = void;
177 explicit WithDeviceIdMatcher(int32_t deviceId) : mDeviceId(deviceId) {}
178
179 bool MatchAndExplain(const NotifyMotionArgs& args, std::ostream*) const {
180 return mDeviceId == args.deviceId;
181 }
182
183 bool MatchAndExplain(const NotifyKeyArgs& args, std::ostream*) const {
184 return mDeviceId == args.deviceId;
185 }
186
Prabir Pradhan85cf63e2023-08-07 21:02:13 +0000187 bool MatchAndExplain(const NotifyDeviceResetArgs& args, std::ostream*) const {
188 return mDeviceId == args.deviceId;
189 }
190
Siarhei Vishniakoub237f9e2023-07-21 16:42:23 -0700191 bool MatchAndExplain(const InputEvent& event, std::ostream*) const {
192 return mDeviceId == event.getDeviceId();
193 }
194
195 void DescribeTo(std::ostream* os) const { *os << "with device id " << mDeviceId; }
196
197 void DescribeNegationTo(std::ostream* os) const { *os << "wrong device id"; }
198
199private:
200 const int32_t mDeviceId;
201};
202
Prabir Pradhan7b6502d2023-10-06 04:08:39 +0000203inline WithDeviceIdMatcher WithDeviceId(int32_t deviceId) {
204 return WithDeviceIdMatcher(deviceId);
205}
206
207/// Flags
208class WithFlagsMatcher {
209public:
210 using is_gtest_matcher = void;
211 explicit WithFlagsMatcher(int32_t flags) : mFlags(flags) {}
212
213 bool MatchAndExplain(const NotifyMotionArgs& args, std::ostream*) const {
214 return mFlags == args.flags;
215 }
216
217 bool MatchAndExplain(const NotifyKeyArgs& args, std::ostream*) const {
218 return mFlags == args.flags;
219 }
220
221 bool MatchAndExplain(const MotionEvent& event, std::ostream*) const {
222 return mFlags == event.getFlags();
223 }
224
225 bool MatchAndExplain(const KeyEvent& event, std::ostream*) const {
226 return mFlags == event.getFlags();
227 }
228
229 void DescribeTo(std::ostream* os) const {
230 *os << "with flags " << base::StringPrintf("0x%x", mFlags);
231 }
232
233 void DescribeNegationTo(std::ostream* os) const { *os << "wrong flags"; }
234
235private:
236 const int32_t mFlags;
237};
238
239inline WithFlagsMatcher WithFlags(int32_t flags) {
240 return WithFlagsMatcher(flags);
241}
242
243/// DownTime
244class WithDownTimeMatcher {
245public:
246 using is_gtest_matcher = void;
247 explicit WithDownTimeMatcher(nsecs_t downTime) : mDownTime(downTime) {}
248
249 bool MatchAndExplain(const NotifyMotionArgs& args, std::ostream*) const {
250 return mDownTime == args.downTime;
251 }
252
253 bool MatchAndExplain(const NotifyKeyArgs& args, std::ostream*) const {
254 return mDownTime == args.downTime;
255 }
256
257 bool MatchAndExplain(const MotionEvent& event, std::ostream*) const {
258 return mDownTime == event.getDownTime();
259 }
260
261 bool MatchAndExplain(const KeyEvent& event, std::ostream*) const {
262 return mDownTime == event.getDownTime();
263 }
264
265 void DescribeTo(std::ostream* os) const { *os << "with down time " << mDownTime; }
266
267 void DescribeNegationTo(std::ostream* os) const { *os << "wrong down time"; }
268
269private:
270 const nsecs_t mDownTime;
271};
272
273inline WithDownTimeMatcher WithDownTime(nsecs_t downTime) {
274 return WithDownTimeMatcher(downTime);
275}
276
277/// Coordinate matcher
278class WithCoordsMatcher {
279public:
280 using is_gtest_matcher = void;
281 explicit WithCoordsMatcher(size_t pointerIndex, float x, float y)
282 : mPointerIndex(pointerIndex), mX(x), mY(y) {}
283
284 bool MatchAndExplain(const MotionEvent& event, std::ostream* os) const {
285 if (mPointerIndex >= event.getPointerCount()) {
286 *os << "Pointer index " << mPointerIndex << " is out of bounds";
287 return false;
288 }
289
290 bool matches = mX == event.getX(mPointerIndex) && mY == event.getY(mPointerIndex);
291 if (!matches) {
292 *os << "expected coords (" << mX << ", " << mY << ") at pointer index " << mPointerIndex
293 << ", but got (" << event.getX(mPointerIndex) << ", " << event.getY(mPointerIndex)
294 << ")";
295 }
296 return matches;
297 }
298
299 bool MatchAndExplain(const NotifyMotionArgs& event, std::ostream* os) const {
300 if (mPointerIndex >= event.pointerCoords.size()) {
301 *os << "Pointer index " << mPointerIndex << " is out of bounds";
302 return false;
303 }
304
305 bool matches = mX == event.pointerCoords[mPointerIndex].getX() &&
306 mY == event.pointerCoords[mPointerIndex].getY();
307 if (!matches) {
308 *os << "expected coords (" << mX << ", " << mY << ") at pointer index " << mPointerIndex
309 << ", but got (" << event.pointerCoords[mPointerIndex].getX() << ", "
310 << event.pointerCoords[mPointerIndex].getY() << ")";
311 }
312 return matches;
313 }
314
315 void DescribeTo(std::ostream* os) const {
316 *os << "with coords (" << mX << ", " << mY << ") at pointer index " << mPointerIndex;
317 }
318
319 void DescribeNegationTo(std::ostream* os) const { *os << "wrong coords"; }
320
321private:
322 const size_t mPointerIndex;
323 const float mX;
324 const float mY;
325};
326
327inline WithCoordsMatcher WithCoords(float x, float y) {
328 return WithCoordsMatcher(0, x, y);
329}
330
331inline WithCoordsMatcher WithPointerCoords(size_t pointerIndex, float x, float y) {
332 return WithCoordsMatcher(pointerIndex, x, y);
333}
334
335/// Raw coordinate matcher
336class WithRawCoordsMatcher {
337public:
338 using is_gtest_matcher = void;
339 explicit WithRawCoordsMatcher(size_t pointerIndex, float rawX, float rawY)
340 : mPointerIndex(pointerIndex), mRawX(rawX), mRawY(rawY) {}
341
342 bool MatchAndExplain(const MotionEvent& event, std::ostream* os) const {
343 if (mPointerIndex >= event.getPointerCount()) {
344 *os << "Pointer index " << mPointerIndex << " is out of bounds";
345 return false;
346 }
347
348 bool matches =
349 mRawX == event.getRawX(mPointerIndex) && mRawY == event.getRawY(mPointerIndex);
350 if (!matches) {
351 *os << "expected raw coords (" << mRawX << ", " << mRawY << ") at pointer index "
352 << mPointerIndex << ", but got (" << event.getRawX(mPointerIndex) << ", "
353 << event.getRawY(mPointerIndex) << ")";
354 }
355 return matches;
356 }
357
358 void DescribeTo(std::ostream* os) const {
359 *os << "with raw coords (" << mRawX << ", " << mRawY << ") at pointer index "
360 << mPointerIndex;
361 }
362
363 void DescribeNegationTo(std::ostream* os) const { *os << "wrong raw coords"; }
364
365private:
366 const size_t mPointerIndex;
367 const float mRawX;
368 const float mRawY;
369};
370
371inline WithRawCoordsMatcher WithRawCoords(float rawX, float rawY) {
372 return WithRawCoordsMatcher(0, rawX, rawY);
373}
374
375inline WithRawCoordsMatcher WithPointerRawCoords(size_t pointerIndex, float rawX, float rawY) {
376 return WithRawCoordsMatcher(pointerIndex, rawX, rawY);
377}
378
379/// Pointer count
380class WithPointerCountMatcher {
381public:
382 using is_gtest_matcher = void;
383 explicit WithPointerCountMatcher(size_t pointerCount) : mPointerCount(pointerCount) {}
384
385 bool MatchAndExplain(const MotionEvent& event, std::ostream* os) const {
386 if (event.getPointerCount() != mPointerCount) {
387 *os << "expected pointer count " << mPointerCount << ", but got "
388 << event.getPointerCount();
389 return false;
390 }
391 return true;
392 }
393
394 bool MatchAndExplain(const NotifyMotionArgs& event, std::ostream* os) const {
395 if (event.pointerCoords.size() != mPointerCount) {
396 *os << "expected pointer count " << mPointerCount << ", but got "
397 << event.pointerCoords.size();
398 return false;
399 }
400 return true;
401 }
402
403 void DescribeTo(std::ostream* os) const { *os << "with pointer count " << mPointerCount; }
404
405 void DescribeNegationTo(std::ostream* os) const { *os << "wrong pointer count"; }
406
407private:
408 const size_t mPointerCount;
409};
410
411inline WithPointerCountMatcher WithPointerCount(size_t pointerCount) {
412 return WithPointerCountMatcher(pointerCount);
413}
414
415/// Pointers matcher
416class WithPointersMatcher {
417public:
418 using is_gtest_matcher = void;
419 explicit WithPointersMatcher(std::map<int32_t, PointF> pointers) : mPointers(pointers) {}
420
421 bool MatchAndExplain(const MotionEvent& event, std::ostream* os) const {
422 std::map<int32_t, PointF> actualPointers;
423 for (size_t pointerIndex = 0; pointerIndex < event.getPointerCount(); pointerIndex++) {
424 const int32_t pointerId = event.getPointerId(pointerIndex);
425 actualPointers[pointerId] = {event.getX(pointerIndex), event.getY(pointerIndex)};
426 }
427
428 if (mPointers != actualPointers) {
429 *os << "expected pointers " << dumpMap(mPointers, constToString, pointFToString)
430 << ", but got " << dumpMap(actualPointers, constToString, pointFToString);
431 return false;
432 }
433 return true;
434 }
435
436 bool MatchAndExplain(const NotifyMotionArgs& event, std::ostream* os) const {
437 std::map<int32_t, PointF> actualPointers;
438 for (size_t pointerIndex = 0; pointerIndex < event.pointerCoords.size(); pointerIndex++) {
439 const int32_t pointerId = event.pointerProperties[pointerIndex].id;
440 actualPointers[pointerId] = {event.pointerCoords[pointerIndex].getX(),
441 event.pointerCoords[pointerIndex].getY()};
442 }
443
444 if (mPointers != actualPointers) {
445 *os << "expected pointers " << dumpMap(mPointers, constToString, pointFToString)
446 << ", but got " << dumpMap(actualPointers, constToString, pointFToString);
447 return false;
448 }
449 return true;
450 }
451
452 void DescribeTo(std::ostream* os) const {
453 *os << "with pointers " << dumpMap(mPointers, constToString, pointFToString);
454 }
455
456 void DescribeNegationTo(std::ostream* os) const { *os << "wrong pointers"; }
457
458private:
459 const std::map<int32_t, PointF> mPointers;
460};
461
462inline WithPointersMatcher WithPointers(
463 const std::map<int32_t /*id*/, PointF /*coords*/>& pointers) {
464 return WithPointersMatcher(pointers);
465}
Prabir Pradhan484d55a2022-10-14 23:17:16 +0000466
Prabir Pradhanb0dad3a2023-11-02 20:52:47 +0000467/// Key code
468class WithKeyCodeMatcher {
469public:
470 using is_gtest_matcher = void;
471 explicit WithKeyCodeMatcher(int32_t keyCode) : mKeyCode(keyCode) {}
472
473 bool MatchAndExplain(const NotifyKeyArgs& args, std::ostream*) const {
474 return mKeyCode == args.keyCode;
475 }
476
477 bool MatchAndExplain(const KeyEvent& event, std::ostream*) const {
478 return mKeyCode == event.getKeyCode();
479 }
480
481 void DescribeTo(std::ostream* os) const {
482 *os << "with key code " << KeyEvent::getLabel(mKeyCode);
483 }
484
485 void DescribeNegationTo(std::ostream* os) const { *os << "wrong key code"; }
486
487private:
488 const int32_t mKeyCode;
489};
490
491inline WithKeyCodeMatcher WithKeyCode(int32_t keyCode) {
492 return WithKeyCodeMatcher(keyCode);
Prabir Pradhane1a41a82022-10-14 18:06:50 +0000493}
494
Siarhei Vishniakoub237f9e2023-07-21 16:42:23 -0700495MATCHER_P(WithRepeatCount, repeatCount, "KeyEvent with specified repeat count") {
496 return arg.getRepeatCount() == repeatCount;
497}
498
Harry Cuttsbb24e272023-03-21 10:49:47 +0000499MATCHER_P2(WithPointerId, index, id, "MotionEvent with specified pointer ID for pointer index") {
500 const auto argPointerId = arg.pointerProperties[index].id;
501 *result_listener << "expected pointer with index " << index << " to have ID " << argPointerId;
502 return argPointerId == id;
503}
504
Siarhei Vishniakou5197ce62023-09-19 08:27:05 -0700505MATCHER_P2(WithCursorPosition, x, y, "InputEvent with specified cursor position") {
506 const auto argX = arg.xCursorPosition;
507 const auto argY = arg.yCursorPosition;
508 *result_listener << "expected cursor position (" << x << ", " << y << "), but got (" << argX
509 << ", " << argY << ")";
510 return (isnan(x) ? isnan(argX) : x == argX) && (isnan(y) ? isnan(argY) : y == argY);
511}
512
Harry Cutts4fb941a2022-12-14 19:14:04 +0000513MATCHER_P2(WithRelativeMotion, x, y, "InputEvent with specified relative motion") {
514 const auto argX = arg.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X);
515 const auto argY = arg.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y);
516 *result_listener << "expected relative motion (" << x << ", " << y << "), but got (" << argX
517 << ", " << argY << ")";
518 return argX == x && argY == y;
519}
520
Harry Cuttsc5748d12022-12-02 17:30:18 +0000521MATCHER_P3(WithGestureOffset, dx, dy, epsilon,
522 "InputEvent with specified touchpad gesture offset") {
523 const auto argGestureX = arg.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_GESTURE_X_OFFSET);
524 const auto argGestureY = arg.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_GESTURE_Y_OFFSET);
525 const double xDiff = fabs(argGestureX - dx);
526 const double yDiff = fabs(argGestureY - dy);
527 *result_listener << "expected gesture offset (" << dx << ", " << dy << ") within " << epsilon
528 << ", but got (" << argGestureX << ", " << argGestureY << ")";
529 return xDiff <= epsilon && yDiff <= epsilon;
530}
531
Harry Cuttsef400b22022-12-16 21:26:24 +0000532MATCHER_P3(WithGestureScrollDistance, x, y, epsilon,
533 "InputEvent with specified touchpad gesture scroll distance") {
534 const auto argXDistance =
535 arg.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_GESTURE_SCROLL_X_DISTANCE);
536 const auto argYDistance =
537 arg.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_GESTURE_SCROLL_Y_DISTANCE);
538 const double xDiff = fabs(argXDistance - x);
539 const double yDiff = fabs(argYDistance - y);
540 *result_listener << "expected gesture offset (" << x << ", " << y << ") within " << epsilon
541 << ", but got (" << argXDistance << ", " << argYDistance << ")";
542 return xDiff <= epsilon && yDiff <= epsilon;
543}
544
Harry Cuttsb1e83552022-12-20 11:02:26 +0000545MATCHER_P2(WithGesturePinchScaleFactor, factor, epsilon,
546 "InputEvent with specified touchpad pinch gesture scale factor") {
547 const auto argScaleFactor =
548 arg.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_GESTURE_PINCH_SCALE_FACTOR);
549 *result_listener << "expected gesture scale factor " << factor << " within " << epsilon
550 << " but got " << argScaleFactor;
551 return fabs(argScaleFactor - factor) <= epsilon;
552}
553
Harry Cutts8743f182023-05-17 12:03:49 +0000554MATCHER_P(WithGestureSwipeFingerCount, count,
555 "InputEvent with specified touchpad swipe finger count") {
556 const auto argFingerCount =
557 arg.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_GESTURE_SWIPE_FINGER_COUNT);
558 *result_listener << "expected gesture swipe finger count " << count << " but got "
559 << argFingerCount;
560 return fabs(argFingerCount - count) <= EPSILON;
561}
562
Prabir Pradhanafabcde2022-09-27 19:32:43 +0000563MATCHER_P(WithPressure, pressure, "InputEvent with specified pressure") {
564 const auto argPressure = arg.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE);
Prabir Pradhan7d04c4b2022-10-28 19:23:26 +0000565 *result_listener << "expected pressure " << pressure << ", but got " << argPressure;
566 return argPressure == pressure;
Prabir Pradhanafabcde2022-09-27 19:32:43 +0000567}
568
Harry Cuttsbb24e272023-03-21 10:49:47 +0000569MATCHER_P2(WithTouchDimensions, maj, min, "InputEvent with specified touch dimensions") {
570 const auto argMajor = arg.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR);
571 const auto argMinor = arg.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR);
572 *result_listener << "expected touch dimensions " << maj << " major x " << min
573 << " minor, but got " << argMajor << " major x " << argMinor << " minor";
574 return argMajor == maj && argMinor == min;
575}
576
577MATCHER_P2(WithToolDimensions, maj, min, "InputEvent with specified tool dimensions") {
578 const auto argMajor = arg.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR);
579 const auto argMinor = arg.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR);
580 *result_listener << "expected tool dimensions " << maj << " major x " << min
581 << " minor, but got " << argMajor << " major x " << argMinor << " minor";
582 return argMajor == maj && argMinor == min;
583}
584
Prabir Pradhanda20b172022-09-26 17:01:18 +0000585MATCHER_P(WithToolType, toolType, "InputEvent with specified tool type") {
586 const auto argToolType = arg.pointerProperties[0].toolType;
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700587 *result_listener << "expected tool type " << ftl::enum_string(toolType) << ", but got "
588 << ftl::enum_string(argToolType);
Prabir Pradhanda20b172022-09-26 17:01:18 +0000589 return argToolType == toolType;
590}
591
Harry Cuttsbb24e272023-03-21 10:49:47 +0000592MATCHER_P2(WithPointerToolType, pointer, toolType,
593 "InputEvent with specified tool type for pointer") {
594 const auto argToolType = arg.pointerProperties[pointer].toolType;
595 *result_listener << "expected pointer " << pointer << " to have tool type "
596 << ftl::enum_string(toolType) << ", but got " << ftl::enum_string(argToolType);
597 return argToolType == toolType;
598}
599
Harry Cuttsc5748d12022-12-02 17:30:18 +0000600MATCHER_P(WithMotionClassification, classification,
601 "InputEvent with specified MotionClassification") {
602 *result_listener << "expected classification " << motionClassificationToString(classification)
603 << ", but got " << motionClassificationToString(arg.classification);
604 return arg.classification == classification;
605}
606
Prabir Pradhan4f05b5f2022-10-11 21:24:07 +0000607MATCHER_P(WithButtonState, buttons, "InputEvent with specified button state") {
608 *result_listener << "expected button state " << buttons << ", but got " << arg.buttonState;
609 return arg.buttonState == buttons;
610}
611
Harry Cutts4fb941a2022-12-14 19:14:04 +0000612MATCHER_P(WithActionButton, actionButton, "InputEvent with specified action button") {
613 *result_listener << "expected action button " << actionButton << ", but got "
614 << arg.actionButton;
615 return arg.actionButton == actionButton;
616}
617
Prabir Pradhan2f37bcb2022-11-08 20:41:28 +0000618MATCHER_P(WithEventTime, eventTime, "InputEvent with specified eventTime") {
619 *result_listener << "expected event time " << eventTime << ", but got " << arg.eventTime;
620 return arg.eventTime == eventTime;
621}
622
Harry Cuttsef400b22022-12-16 21:26:24 +0000623MATCHER_P(WithDownTime, downTime, "InputEvent with specified downTime") {
624 *result_listener << "expected down time " << downTime << ", but got " << arg.downTime;
625 return arg.downTime == downTime;
626}
627
Prabir Pradhana9df3162022-12-05 23:57:27 +0000628MATCHER_P2(WithPrecision, xPrecision, yPrecision, "MotionEvent with specified precision") {
629 *result_listener << "expected x-precision " << xPrecision << " and y-precision " << yPrecision
630 << ", but got " << arg.xPrecision << " and " << arg.yPrecision;
631 return arg.xPrecision == xPrecision && arg.yPrecision == yPrecision;
632}
633
Prabir Pradhan739dca42022-09-09 20:12:01 +0000634} // namespace android