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