xref: /aosp_15_r20/frameworks/native/services/inputflinger/tests/InputMapperTest.cpp (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright 2022 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #include "InputMapperTest.h"
18*38e8c45fSAndroid Build Coastguard Worker 
19*38e8c45fSAndroid Build Coastguard Worker #include <InputReaderBase.h>
20*38e8c45fSAndroid Build Coastguard Worker #include <gtest/gtest.h>
21*38e8c45fSAndroid Build Coastguard Worker #include <ui/Rotation.h>
22*38e8c45fSAndroid Build Coastguard Worker #include <utils/Timers.h>
23*38e8c45fSAndroid Build Coastguard Worker 
24*38e8c45fSAndroid Build Coastguard Worker #include "NotifyArgs.h"
25*38e8c45fSAndroid Build Coastguard Worker 
26*38e8c45fSAndroid Build Coastguard Worker namespace android {
27*38e8c45fSAndroid Build Coastguard Worker 
28*38e8c45fSAndroid Build Coastguard Worker using testing::_;
29*38e8c45fSAndroid Build Coastguard Worker using testing::NiceMock;
30*38e8c45fSAndroid Build Coastguard Worker using testing::Return;
31*38e8c45fSAndroid Build Coastguard Worker using testing::ReturnRef;
32*38e8c45fSAndroid Build Coastguard Worker 
SetUpWithBus(int bus)33*38e8c45fSAndroid Build Coastguard Worker void InputMapperUnitTest::SetUpWithBus(int bus) {
34*38e8c45fSAndroid Build Coastguard Worker     mFakePolicy = sp<FakeInputReaderPolicy>::make();
35*38e8c45fSAndroid Build Coastguard Worker 
36*38e8c45fSAndroid Build Coastguard Worker     EXPECT_CALL(mMockInputReaderContext, getPolicy()).WillRepeatedly(Return(mFakePolicy.get()));
37*38e8c45fSAndroid Build Coastguard Worker 
38*38e8c45fSAndroid Build Coastguard Worker     EXPECT_CALL(mMockInputReaderContext, getEventHub()).WillRepeatedly(Return(&mMockEventHub));
39*38e8c45fSAndroid Build Coastguard Worker 
40*38e8c45fSAndroid Build Coastguard Worker     mIdentifier.name = "device";
41*38e8c45fSAndroid Build Coastguard Worker     mIdentifier.location = "USB1";
42*38e8c45fSAndroid Build Coastguard Worker     mIdentifier.bus = bus;
43*38e8c45fSAndroid Build Coastguard Worker     EXPECT_CALL(mMockEventHub, getDeviceIdentifier(EVENTHUB_ID))
44*38e8c45fSAndroid Build Coastguard Worker             .WillRepeatedly(Return(mIdentifier));
45*38e8c45fSAndroid Build Coastguard Worker     EXPECT_CALL(mMockEventHub, getConfiguration(EVENTHUB_ID)).WillRepeatedly([&](int32_t) {
46*38e8c45fSAndroid Build Coastguard Worker         return mPropertyMap;
47*38e8c45fSAndroid Build Coastguard Worker     });
48*38e8c45fSAndroid Build Coastguard Worker 
49*38e8c45fSAndroid Build Coastguard Worker     mDevice = std::make_unique<NiceMock<MockInputDevice>>(&mMockInputReaderContext, DEVICE_ID,
50*38e8c45fSAndroid Build Coastguard Worker                                                           /*generation=*/2, mIdentifier);
51*38e8c45fSAndroid Build Coastguard Worker     ON_CALL((*mDevice), getConfiguration).WillByDefault(ReturnRef(mPropertyMap));
52*38e8c45fSAndroid Build Coastguard Worker     mDeviceContext = std::make_unique<InputDeviceContext>(*mDevice, EVENTHUB_ID);
53*38e8c45fSAndroid Build Coastguard Worker }
54*38e8c45fSAndroid Build Coastguard Worker 
setupAxis(int axis,bool valid,int32_t min,int32_t max,int32_t resolution,int32_t flat,int32_t fuzz)55*38e8c45fSAndroid Build Coastguard Worker void InputMapperUnitTest::setupAxis(int axis, bool valid, int32_t min, int32_t max,
56*38e8c45fSAndroid Build Coastguard Worker                                     int32_t resolution, int32_t flat, int32_t fuzz) {
57*38e8c45fSAndroid Build Coastguard Worker     EXPECT_CALL(mMockEventHub, getAbsoluteAxisInfo(EVENTHUB_ID, axis))
58*38e8c45fSAndroid Build Coastguard Worker             .WillRepeatedly(Return(valid ? std::optional<RawAbsoluteAxisInfo>{{
59*38e8c45fSAndroid Build Coastguard Worker                                                    .minValue = min,
60*38e8c45fSAndroid Build Coastguard Worker                                                    .maxValue = max,
61*38e8c45fSAndroid Build Coastguard Worker                                                    .flat = flat,
62*38e8c45fSAndroid Build Coastguard Worker                                                    .fuzz = fuzz,
63*38e8c45fSAndroid Build Coastguard Worker                                                    .resolution = resolution,
64*38e8c45fSAndroid Build Coastguard Worker                                            }}
65*38e8c45fSAndroid Build Coastguard Worker                                          : std::nullopt));
66*38e8c45fSAndroid Build Coastguard Worker }
67*38e8c45fSAndroid Build Coastguard Worker 
expectScanCodes(bool present,std::set<int> scanCodes)68*38e8c45fSAndroid Build Coastguard Worker void InputMapperUnitTest::expectScanCodes(bool present, std::set<int> scanCodes) {
69*38e8c45fSAndroid Build Coastguard Worker     for (const auto& scanCode : scanCodes) {
70*38e8c45fSAndroid Build Coastguard Worker         EXPECT_CALL(mMockEventHub, hasScanCode(EVENTHUB_ID, scanCode))
71*38e8c45fSAndroid Build Coastguard Worker                 .WillRepeatedly(testing::Return(present));
72*38e8c45fSAndroid Build Coastguard Worker     }
73*38e8c45fSAndroid Build Coastguard Worker }
74*38e8c45fSAndroid Build Coastguard Worker 
setScanCodeState(KeyState state,std::set<int> scanCodes)75*38e8c45fSAndroid Build Coastguard Worker void InputMapperUnitTest::setScanCodeState(KeyState state, std::set<int> scanCodes) {
76*38e8c45fSAndroid Build Coastguard Worker     for (const auto& scanCode : scanCodes) {
77*38e8c45fSAndroid Build Coastguard Worker         EXPECT_CALL(mMockEventHub, getScanCodeState(EVENTHUB_ID, scanCode))
78*38e8c45fSAndroid Build Coastguard Worker                 .WillRepeatedly(testing::Return(static_cast<int>(state)));
79*38e8c45fSAndroid Build Coastguard Worker     }
80*38e8c45fSAndroid Build Coastguard Worker }
81*38e8c45fSAndroid Build Coastguard Worker 
setKeyCodeState(KeyState state,std::set<int> keyCodes)82*38e8c45fSAndroid Build Coastguard Worker void InputMapperUnitTest::setKeyCodeState(KeyState state, std::set<int> keyCodes) {
83*38e8c45fSAndroid Build Coastguard Worker     for (const auto& keyCode : keyCodes) {
84*38e8c45fSAndroid Build Coastguard Worker         EXPECT_CALL(mMockEventHub, getKeyCodeState(EVENTHUB_ID, keyCode))
85*38e8c45fSAndroid Build Coastguard Worker                 .WillRepeatedly(testing::Return(static_cast<int>(state)));
86*38e8c45fSAndroid Build Coastguard Worker     }
87*38e8c45fSAndroid Build Coastguard Worker }
88*38e8c45fSAndroid Build Coastguard Worker 
setSwitchState(int32_t state,std::set<int32_t> switchCodes)89*38e8c45fSAndroid Build Coastguard Worker void InputMapperUnitTest::setSwitchState(int32_t state, std::set<int32_t> switchCodes) {
90*38e8c45fSAndroid Build Coastguard Worker     for (const auto& switchCode : switchCodes) {
91*38e8c45fSAndroid Build Coastguard Worker         EXPECT_CALL(mMockEventHub, getSwitchState(EVENTHUB_ID, switchCode))
92*38e8c45fSAndroid Build Coastguard Worker                 .WillRepeatedly(testing::Return(static_cast<int>(state)));
93*38e8c45fSAndroid Build Coastguard Worker     }
94*38e8c45fSAndroid Build Coastguard Worker }
95*38e8c45fSAndroid Build Coastguard Worker 
process(int32_t type,int32_t code,int32_t value)96*38e8c45fSAndroid Build Coastguard Worker std::list<NotifyArgs> InputMapperUnitTest::process(int32_t type, int32_t code, int32_t value) {
97*38e8c45fSAndroid Build Coastguard Worker     nsecs_t when = systemTime(SYSTEM_TIME_MONOTONIC);
98*38e8c45fSAndroid Build Coastguard Worker     return process(when, type, code, value);
99*38e8c45fSAndroid Build Coastguard Worker }
100*38e8c45fSAndroid Build Coastguard Worker 
process(nsecs_t when,int32_t type,int32_t code,int32_t value)101*38e8c45fSAndroid Build Coastguard Worker std::list<NotifyArgs> InputMapperUnitTest::process(nsecs_t when, int32_t type, int32_t code,
102*38e8c45fSAndroid Build Coastguard Worker                                                    int32_t value) {
103*38e8c45fSAndroid Build Coastguard Worker     return process(when, when, type, code, value);
104*38e8c45fSAndroid Build Coastguard Worker }
105*38e8c45fSAndroid Build Coastguard Worker 
process(nsecs_t when,nsecs_t readTime,int32_t type,int32_t code,int32_t value)106*38e8c45fSAndroid Build Coastguard Worker std::list<NotifyArgs> InputMapperUnitTest::process(nsecs_t when, nsecs_t readTime, int32_t type,
107*38e8c45fSAndroid Build Coastguard Worker                                                    int32_t code, int32_t value) {
108*38e8c45fSAndroid Build Coastguard Worker     RawEvent event;
109*38e8c45fSAndroid Build Coastguard Worker     event.when = when;
110*38e8c45fSAndroid Build Coastguard Worker     event.readTime = readTime;
111*38e8c45fSAndroid Build Coastguard Worker     event.deviceId = mMapper->getDeviceContext().getEventHubId();
112*38e8c45fSAndroid Build Coastguard Worker     event.type = type;
113*38e8c45fSAndroid Build Coastguard Worker     event.code = code;
114*38e8c45fSAndroid Build Coastguard Worker     event.value = value;
115*38e8c45fSAndroid Build Coastguard Worker     return mMapper->process(event);
116*38e8c45fSAndroid Build Coastguard Worker }
117*38e8c45fSAndroid Build Coastguard Worker 
118*38e8c45fSAndroid Build Coastguard Worker const char* InputMapperTest::DEVICE_NAME = "device";
119*38e8c45fSAndroid Build Coastguard Worker const char* InputMapperTest::DEVICE_LOCATION = "USB1";
120*38e8c45fSAndroid Build Coastguard Worker const ftl::Flags<InputDeviceClass> InputMapperTest::DEVICE_CLASSES =
121*38e8c45fSAndroid Build Coastguard Worker         ftl::Flags<InputDeviceClass>(0); // not needed for current tests
122*38e8c45fSAndroid Build Coastguard Worker 
SetUp(ftl::Flags<InputDeviceClass> classes,int bus)123*38e8c45fSAndroid Build Coastguard Worker void InputMapperTest::SetUp(ftl::Flags<InputDeviceClass> classes, int bus) {
124*38e8c45fSAndroid Build Coastguard Worker     mFakeEventHub = std::make_unique<FakeEventHub>();
125*38e8c45fSAndroid Build Coastguard Worker     mFakePolicy = sp<FakeInputReaderPolicy>::make();
126*38e8c45fSAndroid Build Coastguard Worker     mFakeListener = std::make_unique<TestInputListener>();
127*38e8c45fSAndroid Build Coastguard Worker     mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy, *mFakeListener);
128*38e8c45fSAndroid Build Coastguard Worker     mDevice = newDevice(DEVICE_ID, DEVICE_NAME, DEVICE_LOCATION, EVENTHUB_ID, classes, bus);
129*38e8c45fSAndroid Build Coastguard Worker     // Consume the device reset notification generated when adding a new device.
130*38e8c45fSAndroid Build Coastguard Worker     mFakeListener->assertNotifyDeviceResetWasCalled();
131*38e8c45fSAndroid Build Coastguard Worker }
132*38e8c45fSAndroid Build Coastguard Worker 
SetUp()133*38e8c45fSAndroid Build Coastguard Worker void InputMapperTest::SetUp() {
134*38e8c45fSAndroid Build Coastguard Worker     SetUp(DEVICE_CLASSES);
135*38e8c45fSAndroid Build Coastguard Worker }
136*38e8c45fSAndroid Build Coastguard Worker 
TearDown()137*38e8c45fSAndroid Build Coastguard Worker void InputMapperTest::TearDown() {
138*38e8c45fSAndroid Build Coastguard Worker     mFakeListener.reset();
139*38e8c45fSAndroid Build Coastguard Worker     mFakePolicy.clear();
140*38e8c45fSAndroid Build Coastguard Worker }
141*38e8c45fSAndroid Build Coastguard Worker 
addConfigurationProperty(const char * key,const char * value)142*38e8c45fSAndroid Build Coastguard Worker void InputMapperTest::addConfigurationProperty(const char* key, const char* value) {
143*38e8c45fSAndroid Build Coastguard Worker     mFakeEventHub->addConfigurationProperty(EVENTHUB_ID, key, value);
144*38e8c45fSAndroid Build Coastguard Worker }
145*38e8c45fSAndroid Build Coastguard Worker 
configureDevice(ConfigurationChanges changes)146*38e8c45fSAndroid Build Coastguard Worker std::list<NotifyArgs> InputMapperTest::configureDevice(ConfigurationChanges changes) {
147*38e8c45fSAndroid Build Coastguard Worker     using namespace ftl::flag_operators;
148*38e8c45fSAndroid Build Coastguard Worker     if (!changes.any() ||
149*38e8c45fSAndroid Build Coastguard Worker         (changes.any(InputReaderConfiguration::Change::DISPLAY_INFO |
150*38e8c45fSAndroid Build Coastguard Worker                      InputReaderConfiguration::Change::POINTER_CAPTURE |
151*38e8c45fSAndroid Build Coastguard Worker                      InputReaderConfiguration::Change::DEVICE_TYPE))) {
152*38e8c45fSAndroid Build Coastguard Worker         mReader->requestRefreshConfiguration(changes);
153*38e8c45fSAndroid Build Coastguard Worker         mReader->loopOnce();
154*38e8c45fSAndroid Build Coastguard Worker     }
155*38e8c45fSAndroid Build Coastguard Worker     std::list<NotifyArgs> out =
156*38e8c45fSAndroid Build Coastguard Worker             mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), changes);
157*38e8c45fSAndroid Build Coastguard Worker     // Loop the reader to flush the input listener queue.
158*38e8c45fSAndroid Build Coastguard Worker     for (const NotifyArgs& args : out) {
159*38e8c45fSAndroid Build Coastguard Worker         mFakeListener->notify(args);
160*38e8c45fSAndroid Build Coastguard Worker     }
161*38e8c45fSAndroid Build Coastguard Worker     mReader->loopOnce();
162*38e8c45fSAndroid Build Coastguard Worker     return out;
163*38e8c45fSAndroid Build Coastguard Worker }
164*38e8c45fSAndroid Build Coastguard Worker 
newDevice(int32_t deviceId,const std::string & name,const std::string & location,int32_t eventHubId,ftl::Flags<InputDeviceClass> classes,int bus)165*38e8c45fSAndroid Build Coastguard Worker std::shared_ptr<InputDevice> InputMapperTest::newDevice(int32_t deviceId, const std::string& name,
166*38e8c45fSAndroid Build Coastguard Worker                                                         const std::string& location,
167*38e8c45fSAndroid Build Coastguard Worker                                                         int32_t eventHubId,
168*38e8c45fSAndroid Build Coastguard Worker                                                         ftl::Flags<InputDeviceClass> classes,
169*38e8c45fSAndroid Build Coastguard Worker                                                         int bus) {
170*38e8c45fSAndroid Build Coastguard Worker     InputDeviceIdentifier identifier;
171*38e8c45fSAndroid Build Coastguard Worker     identifier.name = name;
172*38e8c45fSAndroid Build Coastguard Worker     identifier.location = location;
173*38e8c45fSAndroid Build Coastguard Worker     identifier.bus = bus;
174*38e8c45fSAndroid Build Coastguard Worker     std::shared_ptr<InputDevice> device =
175*38e8c45fSAndroid Build Coastguard Worker             std::make_shared<InputDevice>(mReader->getContext(), deviceId, DEVICE_GENERATION,
176*38e8c45fSAndroid Build Coastguard Worker                                           identifier);
177*38e8c45fSAndroid Build Coastguard Worker     mReader->pushNextDevice(device);
178*38e8c45fSAndroid Build Coastguard Worker     mFakeEventHub->addDevice(eventHubId, name, classes, bus);
179*38e8c45fSAndroid Build Coastguard Worker     mReader->loopOnce();
180*38e8c45fSAndroid Build Coastguard Worker     return device;
181*38e8c45fSAndroid Build Coastguard Worker }
182*38e8c45fSAndroid Build Coastguard Worker 
setDisplayInfoAndReconfigure(ui::LogicalDisplayId displayId,int32_t width,int32_t height,ui::Rotation orientation,const std::string & uniqueId,std::optional<uint8_t> physicalPort,ViewportType viewportType)183*38e8c45fSAndroid Build Coastguard Worker void InputMapperTest::setDisplayInfoAndReconfigure(ui::LogicalDisplayId displayId, int32_t width,
184*38e8c45fSAndroid Build Coastguard Worker                                                    int32_t height, ui::Rotation orientation,
185*38e8c45fSAndroid Build Coastguard Worker                                                    const std::string& uniqueId,
186*38e8c45fSAndroid Build Coastguard Worker                                                    std::optional<uint8_t> physicalPort,
187*38e8c45fSAndroid Build Coastguard Worker                                                    ViewportType viewportType) {
188*38e8c45fSAndroid Build Coastguard Worker     mFakePolicy->addDisplayViewport(displayId, width, height, orientation, /* isActive= */ true,
189*38e8c45fSAndroid Build Coastguard Worker                                     uniqueId, physicalPort, viewportType);
190*38e8c45fSAndroid Build Coastguard Worker     configureDevice(InputReaderConfiguration::Change::DISPLAY_INFO);
191*38e8c45fSAndroid Build Coastguard Worker }
192*38e8c45fSAndroid Build Coastguard Worker 
clearViewports()193*38e8c45fSAndroid Build Coastguard Worker void InputMapperTest::clearViewports() {
194*38e8c45fSAndroid Build Coastguard Worker     mFakePolicy->clearViewports();
195*38e8c45fSAndroid Build Coastguard Worker }
196*38e8c45fSAndroid Build Coastguard Worker 
process(InputMapper & mapper,nsecs_t when,nsecs_t readTime,int32_t type,int32_t code,int32_t value)197*38e8c45fSAndroid Build Coastguard Worker std::list<NotifyArgs> InputMapperTest::process(InputMapper& mapper, nsecs_t when, nsecs_t readTime,
198*38e8c45fSAndroid Build Coastguard Worker                                                int32_t type, int32_t code, int32_t value) {
199*38e8c45fSAndroid Build Coastguard Worker     RawEvent event;
200*38e8c45fSAndroid Build Coastguard Worker     event.when = when;
201*38e8c45fSAndroid Build Coastguard Worker     event.readTime = readTime;
202*38e8c45fSAndroid Build Coastguard Worker     event.deviceId = mapper.getDeviceContext().getEventHubId();
203*38e8c45fSAndroid Build Coastguard Worker     event.type = type;
204*38e8c45fSAndroid Build Coastguard Worker     event.code = code;
205*38e8c45fSAndroid Build Coastguard Worker     event.value = value;
206*38e8c45fSAndroid Build Coastguard Worker     std::list<NotifyArgs> processArgList = mapper.process(event);
207*38e8c45fSAndroid Build Coastguard Worker     for (const NotifyArgs& args : processArgList) {
208*38e8c45fSAndroid Build Coastguard Worker         mFakeListener->notify(args);
209*38e8c45fSAndroid Build Coastguard Worker     }
210*38e8c45fSAndroid Build Coastguard Worker     // Loop the reader to flush the input listener queue.
211*38e8c45fSAndroid Build Coastguard Worker     mReader->loopOnce();
212*38e8c45fSAndroid Build Coastguard Worker     return processArgList;
213*38e8c45fSAndroid Build Coastguard Worker }
214*38e8c45fSAndroid Build Coastguard Worker 
resetMapper(InputMapper & mapper,nsecs_t when)215*38e8c45fSAndroid Build Coastguard Worker void InputMapperTest::resetMapper(InputMapper& mapper, nsecs_t when) {
216*38e8c45fSAndroid Build Coastguard Worker     const auto resetArgs = mapper.reset(when);
217*38e8c45fSAndroid Build Coastguard Worker     for (const auto args : resetArgs) {
218*38e8c45fSAndroid Build Coastguard Worker         mFakeListener->notify(args);
219*38e8c45fSAndroid Build Coastguard Worker     }
220*38e8c45fSAndroid Build Coastguard Worker     // Loop the reader to flush the input listener queue.
221*38e8c45fSAndroid Build Coastguard Worker     mReader->loopOnce();
222*38e8c45fSAndroid Build Coastguard Worker }
223*38e8c45fSAndroid Build Coastguard Worker 
handleTimeout(InputMapper & mapper,nsecs_t when)224*38e8c45fSAndroid Build Coastguard Worker std::list<NotifyArgs> InputMapperTest::handleTimeout(InputMapper& mapper, nsecs_t when) {
225*38e8c45fSAndroid Build Coastguard Worker     std::list<NotifyArgs> generatedArgs = mapper.timeoutExpired(when);
226*38e8c45fSAndroid Build Coastguard Worker     for (const NotifyArgs& args : generatedArgs) {
227*38e8c45fSAndroid Build Coastguard Worker         mFakeListener->notify(args);
228*38e8c45fSAndroid Build Coastguard Worker     }
229*38e8c45fSAndroid Build Coastguard Worker     // Loop the reader to flush the input listener queue.
230*38e8c45fSAndroid Build Coastguard Worker     mReader->loopOnce();
231*38e8c45fSAndroid Build Coastguard Worker     return generatedArgs;
232*38e8c45fSAndroid Build Coastguard Worker }
233*38e8c45fSAndroid Build Coastguard Worker 
assertMotionRange(const InputDeviceInfo & info,int32_t axis,uint32_t source,float min,float max,float flat,float fuzz)234*38e8c45fSAndroid Build Coastguard Worker void assertMotionRange(const InputDeviceInfo& info, int32_t axis, uint32_t source, float min,
235*38e8c45fSAndroid Build Coastguard Worker                        float max, float flat, float fuzz) {
236*38e8c45fSAndroid Build Coastguard Worker     const InputDeviceInfo::MotionRange* range = info.getMotionRange(axis, source);
237*38e8c45fSAndroid Build Coastguard Worker     ASSERT_TRUE(range != nullptr) << "Axis: " << axis << " Source: " << source;
238*38e8c45fSAndroid Build Coastguard Worker     ASSERT_EQ(axis, range->axis) << "Axis: " << axis << " Source: " << source;
239*38e8c45fSAndroid Build Coastguard Worker     ASSERT_EQ(source, range->source) << "Axis: " << axis << " Source: " << source;
240*38e8c45fSAndroid Build Coastguard Worker     ASSERT_NEAR(min, range->min, EPSILON) << "Axis: " << axis << " Source: " << source;
241*38e8c45fSAndroid Build Coastguard Worker     ASSERT_NEAR(max, range->max, EPSILON) << "Axis: " << axis << " Source: " << source;
242*38e8c45fSAndroid Build Coastguard Worker     ASSERT_NEAR(flat, range->flat, EPSILON) << "Axis: " << axis << " Source: " << source;
243*38e8c45fSAndroid Build Coastguard Worker     ASSERT_NEAR(fuzz, range->fuzz, EPSILON) << "Axis: " << axis << " Source: " << source;
244*38e8c45fSAndroid Build Coastguard Worker }
245*38e8c45fSAndroid Build Coastguard Worker 
assertPointerCoords(const PointerCoords & coords,float x,float y,float pressure,float size,float touchMajor,float touchMinor,float toolMajor,float toolMinor,float orientation,float distance,float scaledAxisEpsilon)246*38e8c45fSAndroid Build Coastguard Worker void assertPointerCoords(const PointerCoords& coords, float x, float y, float pressure, float size,
247*38e8c45fSAndroid Build Coastguard Worker                          float touchMajor, float touchMinor, float toolMajor, float toolMinor,
248*38e8c45fSAndroid Build Coastguard Worker                          float orientation, float distance, float scaledAxisEpsilon) {
249*38e8c45fSAndroid Build Coastguard Worker     ASSERT_NEAR(x, coords.getAxisValue(AMOTION_EVENT_AXIS_X), scaledAxisEpsilon);
250*38e8c45fSAndroid Build Coastguard Worker     ASSERT_NEAR(y, coords.getAxisValue(AMOTION_EVENT_AXIS_Y), scaledAxisEpsilon);
251*38e8c45fSAndroid Build Coastguard Worker     ASSERT_NEAR(pressure, coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), EPSILON);
252*38e8c45fSAndroid Build Coastguard Worker     ASSERT_NEAR(size, coords.getAxisValue(AMOTION_EVENT_AXIS_SIZE), EPSILON);
253*38e8c45fSAndroid Build Coastguard Worker     ASSERT_NEAR(touchMajor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR), scaledAxisEpsilon);
254*38e8c45fSAndroid Build Coastguard Worker     ASSERT_NEAR(touchMinor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR), scaledAxisEpsilon);
255*38e8c45fSAndroid Build Coastguard Worker     ASSERT_NEAR(toolMajor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR), scaledAxisEpsilon);
256*38e8c45fSAndroid Build Coastguard Worker     ASSERT_NEAR(toolMinor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR), scaledAxisEpsilon);
257*38e8c45fSAndroid Build Coastguard Worker     ASSERT_NEAR(orientation, coords.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION), EPSILON);
258*38e8c45fSAndroid Build Coastguard Worker     ASSERT_NEAR(distance, coords.getAxisValue(AMOTION_EVENT_AXIS_DISTANCE), EPSILON);
259*38e8c45fSAndroid Build Coastguard Worker }
260*38e8c45fSAndroid Build Coastguard Worker 
261*38e8c45fSAndroid Build Coastguard Worker } // namespace android
262