Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 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 | */ |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 16 | #include <gestures/HardwareStateConverter.h> |
| 17 | |
| 18 | #include <memory> |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 19 | |
| 20 | #include <EventHub.h> |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 21 | #include <gtest/gtest.h> |
| 22 | #include <linux/input-event-codes.h> |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 23 | #include <utils/StrongPointer.h> |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 24 | |
| 25 | #include "FakeEventHub.h" |
| 26 | #include "FakeInputReaderPolicy.h" |
| 27 | #include "InstrumentedInputReader.h" |
Harry Cutts | bb24e27 | 2023-03-21 10:49:47 +0000 | [diff] [blame^] | 28 | #include "MultiTouchMotionAccumulator.h" |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 29 | #include "TestConstants.h" |
| 30 | #include "TestInputListener.h" |
| 31 | |
| 32 | namespace android { |
| 33 | |
| 34 | class HardwareStateConverterTest : public testing::Test { |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 35 | public: |
| 36 | HardwareStateConverterTest() |
| 37 | : mFakeEventHub(std::make_shared<FakeEventHub>()), |
| 38 | mFakePolicy(sp<FakeInputReaderPolicy>::make()), |
| 39 | mReader(mFakeEventHub, mFakePolicy, mFakeListener), |
| 40 | mDevice(newDevice()), |
| 41 | mDeviceContext(*mDevice, EVENTHUB_ID) { |
Harry Cutts | bb24e27 | 2023-03-21 10:49:47 +0000 | [diff] [blame^] | 42 | const size_t slotCount = 8; |
| 43 | mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_SLOT, 0, slotCount - 1, 0, 0, 0); |
| 44 | mAccumulator.configure(mDeviceContext, slotCount, /*usingSlotsProtocol=*/true); |
| 45 | mConverter = std::make_unique<HardwareStateConverter>(mDeviceContext, mAccumulator); |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 48 | protected: |
| 49 | static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000; |
| 50 | static constexpr int32_t EVENTHUB_ID = 1; |
| 51 | |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 52 | std::shared_ptr<InputDevice> newDevice() { |
| 53 | InputDeviceIdentifier identifier; |
| 54 | identifier.name = "device"; |
| 55 | identifier.location = "USB1"; |
| 56 | identifier.bus = 0; |
| 57 | std::shared_ptr<InputDevice> device = |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 58 | std::make_shared<InputDevice>(mReader.getContext(), DEVICE_ID, /*generation=*/2, |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 59 | identifier); |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 60 | mReader.pushNextDevice(device); |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 61 | mFakeEventHub->addDevice(EVENTHUB_ID, identifier.name, InputDeviceClass::TOUCHPAD, |
| 62 | identifier.bus); |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 63 | mReader.loopOnce(); |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 64 | return device; |
| 65 | } |
| 66 | |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 67 | void processAxis(nsecs_t when, int32_t type, int32_t code, int32_t value) { |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 68 | RawEvent event; |
| 69 | event.when = when; |
| 70 | event.readTime = READ_TIME; |
| 71 | event.deviceId = EVENTHUB_ID; |
| 72 | event.type = type; |
| 73 | event.code = code; |
| 74 | event.value = value; |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 75 | std::optional<SelfContainedHardwareState> schs = mConverter->processRawEvent(&event); |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 76 | EXPECT_FALSE(schs.has_value()); |
| 77 | } |
| 78 | |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 79 | std::optional<SelfContainedHardwareState> processSync(nsecs_t when) { |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 80 | RawEvent event; |
| 81 | event.when = when; |
| 82 | event.readTime = READ_TIME; |
| 83 | event.deviceId = EVENTHUB_ID; |
| 84 | event.type = EV_SYN; |
| 85 | event.code = SYN_REPORT; |
| 86 | event.value = 0; |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 87 | return mConverter->processRawEvent(&event); |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | std::shared_ptr<FakeEventHub> mFakeEventHub; |
| 91 | sp<FakeInputReaderPolicy> mFakePolicy; |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 92 | TestInputListener mFakeListener; |
| 93 | InstrumentedInputReader mReader; |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 94 | std::shared_ptr<InputDevice> mDevice; |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 95 | InputDeviceContext mDeviceContext; |
Harry Cutts | bb24e27 | 2023-03-21 10:49:47 +0000 | [diff] [blame^] | 96 | MultiTouchMotionAccumulator mAccumulator; |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 97 | std::unique_ptr<HardwareStateConverter> mConverter; |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | TEST_F(HardwareStateConverterTest, OneFinger) { |
| 101 | const nsecs_t time = 1500000000; |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 102 | |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 103 | processAxis(time, EV_ABS, ABS_MT_SLOT, 0); |
| 104 | processAxis(time, EV_ABS, ABS_MT_TRACKING_ID, 123); |
| 105 | processAxis(time, EV_ABS, ABS_MT_POSITION_X, 50); |
| 106 | processAxis(time, EV_ABS, ABS_MT_POSITION_Y, 100); |
| 107 | processAxis(time, EV_ABS, ABS_MT_TOUCH_MAJOR, 5); |
| 108 | processAxis(time, EV_ABS, ABS_MT_TOUCH_MINOR, 4); |
| 109 | processAxis(time, EV_ABS, ABS_MT_PRESSURE, 42); |
| 110 | processAxis(time, EV_ABS, ABS_MT_ORIENTATION, 2); |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 111 | |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 112 | processAxis(time, EV_ABS, ABS_X, 50); |
| 113 | processAxis(time, EV_ABS, ABS_Y, 100); |
| 114 | processAxis(time, EV_ABS, ABS_PRESSURE, 42); |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 115 | |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 116 | processAxis(time, EV_KEY, BTN_TOUCH, 1); |
| 117 | processAxis(time, EV_KEY, BTN_TOOL_FINGER, 1); |
| 118 | std::optional<SelfContainedHardwareState> schs = processSync(time); |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 119 | |
| 120 | ASSERT_TRUE(schs.has_value()); |
| 121 | const HardwareState& state = schs->state; |
| 122 | EXPECT_NEAR(1.5, state.timestamp, EPSILON); |
| 123 | EXPECT_EQ(0, state.buttons_down); |
| 124 | EXPECT_EQ(1, state.touch_cnt); |
| 125 | |
| 126 | ASSERT_EQ(1, state.finger_cnt); |
| 127 | const FingerState& finger = state.fingers[0]; |
| 128 | EXPECT_EQ(123, finger.tracking_id); |
| 129 | EXPECT_NEAR(50, finger.position_x, EPSILON); |
| 130 | EXPECT_NEAR(100, finger.position_y, EPSILON); |
| 131 | EXPECT_NEAR(5, finger.touch_major, EPSILON); |
| 132 | EXPECT_NEAR(4, finger.touch_minor, EPSILON); |
| 133 | EXPECT_NEAR(42, finger.pressure, EPSILON); |
| 134 | EXPECT_NEAR(2, finger.orientation, EPSILON); |
| 135 | EXPECT_EQ(0u, finger.flags); |
| 136 | |
| 137 | EXPECT_EQ(0, state.rel_x); |
| 138 | EXPECT_EQ(0, state.rel_y); |
| 139 | EXPECT_EQ(0, state.rel_wheel); |
| 140 | EXPECT_EQ(0, state.rel_wheel_hi_res); |
| 141 | EXPECT_EQ(0, state.rel_hwheel); |
| 142 | EXPECT_NEAR(0.0, state.msc_timestamp, EPSILON); |
| 143 | } |
| 144 | |
| 145 | TEST_F(HardwareStateConverterTest, TwoFingers) { |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 146 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_SLOT, 0); |
| 147 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_TRACKING_ID, 123); |
| 148 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_POSITION_X, 50); |
| 149 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_POSITION_Y, 100); |
| 150 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_TOUCH_MAJOR, 5); |
| 151 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_TOUCH_MINOR, 4); |
| 152 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_PRESSURE, 42); |
| 153 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_ORIENTATION, 2); |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 154 | |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 155 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_SLOT, 1); |
| 156 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_TRACKING_ID, 456); |
| 157 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_POSITION_X, -20); |
| 158 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_POSITION_Y, 40); |
| 159 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_TOUCH_MAJOR, 8); |
| 160 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_TOUCH_MINOR, 7); |
| 161 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_PRESSURE, 21); |
| 162 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_ORIENTATION, 1); |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 163 | |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 164 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_X, 50); |
| 165 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_Y, 100); |
| 166 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_PRESSURE, 42); |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 167 | |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 168 | processAxis(ARBITRARY_TIME, EV_KEY, BTN_TOUCH, 1); |
| 169 | processAxis(ARBITRARY_TIME, EV_KEY, BTN_TOOL_DOUBLETAP, 1); |
| 170 | std::optional<SelfContainedHardwareState> schs = processSync(ARBITRARY_TIME); |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 171 | |
| 172 | ASSERT_TRUE(schs.has_value()); |
| 173 | ASSERT_EQ(2, schs->state.finger_cnt); |
| 174 | const FingerState& finger1 = schs->state.fingers[0]; |
| 175 | EXPECT_EQ(123, finger1.tracking_id); |
| 176 | EXPECT_NEAR(50, finger1.position_x, EPSILON); |
| 177 | EXPECT_NEAR(100, finger1.position_y, EPSILON); |
| 178 | EXPECT_NEAR(5, finger1.touch_major, EPSILON); |
| 179 | EXPECT_NEAR(4, finger1.touch_minor, EPSILON); |
| 180 | EXPECT_NEAR(42, finger1.pressure, EPSILON); |
| 181 | EXPECT_NEAR(2, finger1.orientation, EPSILON); |
| 182 | EXPECT_EQ(0u, finger1.flags); |
| 183 | |
| 184 | const FingerState& finger2 = schs->state.fingers[1]; |
| 185 | EXPECT_EQ(456, finger2.tracking_id); |
| 186 | EXPECT_NEAR(-20, finger2.position_x, EPSILON); |
| 187 | EXPECT_NEAR(40, finger2.position_y, EPSILON); |
| 188 | EXPECT_NEAR(8, finger2.touch_major, EPSILON); |
| 189 | EXPECT_NEAR(7, finger2.touch_minor, EPSILON); |
| 190 | EXPECT_NEAR(21, finger2.pressure, EPSILON); |
| 191 | EXPECT_NEAR(1, finger2.orientation, EPSILON); |
| 192 | EXPECT_EQ(0u, finger2.flags); |
| 193 | } |
| 194 | |
Harry Cutts | b2e4794 | 2023-02-24 17:47:44 +0000 | [diff] [blame] | 195 | TEST_F(HardwareStateConverterTest, OnePalm) { |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 196 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_SLOT, 0); |
| 197 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_PALM); |
| 198 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_TRACKING_ID, 123); |
| 199 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_POSITION_X, 50); |
| 200 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_POSITION_Y, 100); |
Harry Cutts | b2e4794 | 2023-02-24 17:47:44 +0000 | [diff] [blame] | 201 | |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 202 | processAxis(ARBITRARY_TIME, EV_KEY, BTN_TOUCH, 1); |
Harry Cutts | 195c5f8 | 2023-03-30 15:20:38 +0000 | [diff] [blame] | 203 | processAxis(ARBITRARY_TIME, EV_KEY, BTN_TOOL_FINGER, 1); |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 204 | std::optional<SelfContainedHardwareState> schs = processSync(ARBITRARY_TIME); |
Harry Cutts | b2e4794 | 2023-02-24 17:47:44 +0000 | [diff] [blame] | 205 | ASSERT_TRUE(schs.has_value()); |
Harry Cutts | 195c5f8 | 2023-03-30 15:20:38 +0000 | [diff] [blame] | 206 | EXPECT_EQ(0, schs->state.touch_cnt); |
Harry Cutts | b2e4794 | 2023-02-24 17:47:44 +0000 | [diff] [blame] | 207 | EXPECT_EQ(0, schs->state.finger_cnt); |
| 208 | } |
| 209 | |
| 210 | TEST_F(HardwareStateConverterTest, OneFingerTurningIntoAPalm) { |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 211 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_SLOT, 0); |
| 212 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER); |
| 213 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_TRACKING_ID, 123); |
| 214 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_POSITION_X, 50); |
| 215 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_POSITION_Y, 100); |
Harry Cutts | b2e4794 | 2023-02-24 17:47:44 +0000 | [diff] [blame] | 216 | |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 217 | processAxis(ARBITRARY_TIME, EV_KEY, BTN_TOUCH, 1); |
Harry Cutts | 195c5f8 | 2023-03-30 15:20:38 +0000 | [diff] [blame] | 218 | processAxis(ARBITRARY_TIME, EV_KEY, BTN_TOOL_FINGER, 1); |
Harry Cutts | b2e4794 | 2023-02-24 17:47:44 +0000 | [diff] [blame] | 219 | |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 220 | std::optional<SelfContainedHardwareState> schs = processSync(ARBITRARY_TIME); |
Harry Cutts | b2e4794 | 2023-02-24 17:47:44 +0000 | [diff] [blame] | 221 | ASSERT_TRUE(schs.has_value()); |
Harry Cutts | 195c5f8 | 2023-03-30 15:20:38 +0000 | [diff] [blame] | 222 | EXPECT_EQ(1, schs->state.touch_cnt); |
Harry Cutts | b2e4794 | 2023-02-24 17:47:44 +0000 | [diff] [blame] | 223 | EXPECT_EQ(1, schs->state.finger_cnt); |
| 224 | |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 225 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_PALM); |
| 226 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_POSITION_X, 51); |
| 227 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_POSITION_Y, 99); |
Harry Cutts | b2e4794 | 2023-02-24 17:47:44 +0000 | [diff] [blame] | 228 | |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 229 | schs = processSync(ARBITRARY_TIME); |
Harry Cutts | b2e4794 | 2023-02-24 17:47:44 +0000 | [diff] [blame] | 230 | ASSERT_TRUE(schs.has_value()); |
Harry Cutts | 195c5f8 | 2023-03-30 15:20:38 +0000 | [diff] [blame] | 231 | EXPECT_EQ(0, schs->state.touch_cnt); |
Harry Cutts | 9892a30 | 2023-03-22 15:38:10 +0000 | [diff] [blame] | 232 | ASSERT_EQ(0, schs->state.finger_cnt); |
Harry Cutts | b2e4794 | 2023-02-24 17:47:44 +0000 | [diff] [blame] | 233 | |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 234 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_POSITION_X, 53); |
| 235 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_POSITION_Y, 97); |
Harry Cutts | b2e4794 | 2023-02-24 17:47:44 +0000 | [diff] [blame] | 236 | |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 237 | schs = processSync(ARBITRARY_TIME); |
Harry Cutts | b2e4794 | 2023-02-24 17:47:44 +0000 | [diff] [blame] | 238 | ASSERT_TRUE(schs.has_value()); |
Harry Cutts | 195c5f8 | 2023-03-30 15:20:38 +0000 | [diff] [blame] | 239 | EXPECT_EQ(0, schs->state.touch_cnt); |
Harry Cutts | b2e4794 | 2023-02-24 17:47:44 +0000 | [diff] [blame] | 240 | EXPECT_EQ(0, schs->state.finger_cnt); |
| 241 | |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 242 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER); |
| 243 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_POSITION_X, 55); |
| 244 | processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_POSITION_Y, 95); |
| 245 | schs = processSync(ARBITRARY_TIME); |
Harry Cutts | b2e4794 | 2023-02-24 17:47:44 +0000 | [diff] [blame] | 246 | ASSERT_TRUE(schs.has_value()); |
Harry Cutts | 195c5f8 | 2023-03-30 15:20:38 +0000 | [diff] [blame] | 247 | EXPECT_EQ(1, schs->state.touch_cnt); |
Harry Cutts | b2e4794 | 2023-02-24 17:47:44 +0000 | [diff] [blame] | 248 | ASSERT_EQ(1, schs->state.finger_cnt); |
| 249 | const FingerState& newFinger = schs->state.fingers[0]; |
| 250 | EXPECT_EQ(123, newFinger.tracking_id); |
| 251 | EXPECT_NEAR(55, newFinger.position_x, EPSILON); |
| 252 | EXPECT_NEAR(95, newFinger.position_y, EPSILON); |
| 253 | } |
| 254 | |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 255 | TEST_F(HardwareStateConverterTest, ButtonPressed) { |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 256 | processAxis(ARBITRARY_TIME, EV_KEY, BTN_LEFT, 1); |
| 257 | std::optional<SelfContainedHardwareState> schs = processSync(ARBITRARY_TIME); |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 258 | |
| 259 | ASSERT_TRUE(schs.has_value()); |
| 260 | EXPECT_EQ(GESTURES_BUTTON_LEFT, schs->state.buttons_down); |
| 261 | } |
| 262 | |
| 263 | TEST_F(HardwareStateConverterTest, MscTimestamp) { |
Harry Cutts | f30d7a2 | 2023-03-30 13:44:41 +0000 | [diff] [blame] | 264 | processAxis(ARBITRARY_TIME, EV_MSC, MSC_TIMESTAMP, 1200000); |
| 265 | std::optional<SelfContainedHardwareState> schs = processSync(ARBITRARY_TIME); |
Harry Cutts | 47db1c7 | 2022-12-13 19:20:47 +0000 | [diff] [blame] | 266 | |
| 267 | ASSERT_TRUE(schs.has_value()); |
| 268 | EXPECT_NEAR(1.2, schs->state.msc_timestamp, EPSILON); |
| 269 | } |
| 270 | |
| 271 | } // namespace android |