Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | |
| 17 | #define LOG_TAG "VelocityTracker_test" |
| 18 | |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 19 | #include <math.h> |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 20 | #include <array> |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 21 | #include <chrono> |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 22 | #include <limits> |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 23 | |
| 24 | #include <android-base/stringprintf.h> |
chaviw | 09c8d2d | 2020-08-24 15:48:26 -0700 | [diff] [blame] | 25 | #include <attestation/HmacKeyManager.h> |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 26 | #include <gtest/gtest.h> |
| 27 | #include <input/VelocityTracker.h> |
| 28 | |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 29 | using std::literals::chrono_literals::operator""ms; |
| 30 | using std::literals::chrono_literals::operator""ns; |
| 31 | using std::literals::chrono_literals::operator""us; |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 32 | using android::base::StringPrintf; |
| 33 | |
| 34 | namespace android { |
| 35 | |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 36 | constexpr ui::LogicalDisplayId DISPLAY_ID = ui::LogicalDisplayId::DEFAULT; // default display id |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 37 | |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 38 | constexpr int32_t DEFAULT_POINTER_ID = 0; // pointer ID used for manually defined tests |
| 39 | |
| 40 | // velocity must be in the range (1-tol)*EV <= velocity <= (1+tol)*EV |
| 41 | // here EV = expected value, tol = VELOCITY_TOLERANCE |
| 42 | constexpr float VELOCITY_TOLERANCE = 0.2; |
| 43 | |
Yeabkal Wubshit | 9b4443f | 2023-02-23 23:35:07 -0800 | [diff] [blame] | 44 | // quadratic velocity must be within 0.001% of the target value |
| 45 | constexpr float QUADRATIC_VELOCITY_TOLERANCE = 0.00001; |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 46 | |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 47 | // --- VelocityTrackerTest --- |
| 48 | class VelocityTrackerTest : public testing::Test { }; |
| 49 | |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 50 | /* |
| 51 | * Similar to EXPECT_NEAR, but ensures that the difference between the two float values |
| 52 | * is at most a certain fraction of the target value. |
| 53 | * If fraction is zero, require exact match. |
| 54 | */ |
| 55 | static void EXPECT_NEAR_BY_FRACTION(float actual, float target, float fraction) { |
| 56 | float tolerance = fabsf(target * fraction); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 57 | |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 58 | if (target == 0 && fraction != 0) { |
| 59 | // If target is zero, this would force actual == target, which is too harsh. |
| 60 | // Relax this requirement a little. The value is determined empirically from the |
| 61 | // coefficients computed by the quadratic least squares algorithms. |
| 62 | tolerance = 1E-6; |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 63 | } |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 64 | EXPECT_NEAR(actual, target, tolerance); |
| 65 | } |
| 66 | |
Yeabkal Wubshit | a15e599 | 2022-09-29 19:00:19 -0700 | [diff] [blame] | 67 | static void checkVelocity(std::optional<float> Vactual, std::optional<float> Vtarget) { |
| 68 | if (Vactual != std::nullopt) { |
| 69 | if (Vtarget == std::nullopt) { |
| 70 | FAIL() << "Expected no velocity, but found " << *Vactual; |
| 71 | } |
| 72 | EXPECT_NEAR_BY_FRACTION(*Vactual, *Vtarget, VELOCITY_TOLERANCE); |
| 73 | } else if (Vtarget != std::nullopt) { |
| 74 | FAIL() << "Expected velocity, but found no velocity"; |
| 75 | } |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 78 | struct Position { |
Siarhei Vishniakou | 01ca486 | 2019-03-06 13:22:13 -0800 | [diff] [blame] | 79 | float x; |
| 80 | float y; |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 81 | |
Siarhei Vishniakou | c36d21e | 2023-01-17 09:59:38 -0800 | [diff] [blame] | 82 | bool isResampled = false; |
| 83 | |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 84 | /** |
| 85 | * If both values are NAN, then this is considered to be an empty entry (no pointer data). |
| 86 | * If only one of the values is NAN, this is still a valid entry, |
| 87 | * because we may only care about a single axis. |
| 88 | */ |
| 89 | bool isValid() const { |
| 90 | return !(isnan(x) && isnan(y)); |
| 91 | } |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 92 | }; |
| 93 | |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 94 | struct PlanarMotionEventEntry { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 95 | std::chrono::nanoseconds eventTime; |
| 96 | std::vector<Position> positions; |
| 97 | }; |
| 98 | |
| 99 | static BitSet32 getValidPointers(const std::vector<Position>& positions) { |
| 100 | BitSet32 pointers; |
| 101 | for (size_t i = 0; i < positions.size(); i++) { |
| 102 | if (positions[i].isValid()) { |
| 103 | pointers.markBit(i); |
| 104 | } |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 105 | } |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 106 | return pointers; |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 107 | } |
| 108 | |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 109 | static uint32_t getChangingPointerId(BitSet32 pointers, BitSet32 otherPointers) { |
| 110 | BitSet32 difference(pointers.value ^ otherPointers.value); |
| 111 | uint32_t pointerId = difference.clearFirstMarkedBit(); |
| 112 | EXPECT_EQ(0U, difference.value) << "Only 1 pointer can enter or leave at a time"; |
| 113 | return pointerId; |
| 114 | } |
| 115 | |
| 116 | static int32_t resolveAction(const std::vector<Position>& lastPositions, |
| 117 | const std::vector<Position>& currentPositions, |
| 118 | const std::vector<Position>& nextPositions) { |
| 119 | BitSet32 pointers = getValidPointers(currentPositions); |
| 120 | const uint32_t pointerCount = pointers.count(); |
| 121 | |
| 122 | BitSet32 lastPointers = getValidPointers(lastPositions); |
| 123 | const uint32_t lastPointerCount = lastPointers.count(); |
| 124 | if (lastPointerCount < pointerCount) { |
| 125 | // A new pointer is down |
| 126 | uint32_t pointerId = getChangingPointerId(pointers, lastPointers); |
| 127 | return AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 128 | (pointerId << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); |
| 129 | } |
| 130 | |
| 131 | BitSet32 nextPointers = getValidPointers(nextPositions); |
| 132 | const uint32_t nextPointerCount = nextPointers.count(); |
| 133 | if (pointerCount > nextPointerCount) { |
| 134 | // An existing pointer is leaving |
| 135 | uint32_t pointerId = getChangingPointerId(pointers, nextPointers); |
| 136 | return AMOTION_EVENT_ACTION_POINTER_UP | |
| 137 | (pointerId << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); |
| 138 | } |
| 139 | |
| 140 | return AMOTION_EVENT_ACTION_MOVE; |
| 141 | } |
| 142 | |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 143 | static std::vector<MotionEvent> createAxisScrollMotionEventStream( |
| 144 | const std::vector<std::pair<std::chrono::nanoseconds, float>>& motions) { |
| 145 | std::vector<MotionEvent> events; |
| 146 | for (const auto& [timeStamp, value] : motions) { |
| 147 | EXPECT_TRUE(!isnan(value)) << "The entry at pointerId must be valid"; |
| 148 | |
| 149 | PointerCoords coords[1]; |
| 150 | coords[0].setAxisValue(AMOTION_EVENT_AXIS_SCROLL, value); |
| 151 | |
| 152 | PointerProperties properties[1]; |
| 153 | properties[0].id = DEFAULT_POINTER_ID; |
| 154 | |
| 155 | MotionEvent event; |
| 156 | ui::Transform identityTransform; |
Harry Cutts | 82c791c | 2023-03-10 17:15:07 +0000 | [diff] [blame] | 157 | event.initialize(InputEvent::nextId(), /*deviceId=*/5, AINPUT_SOURCE_ROTARY_ENCODER, |
Siarhei Vishniakou | cfbee53 | 2024-05-10 13:41:35 -0700 | [diff] [blame] | 158 | ui::LogicalDisplayId::INVALID, INVALID_HMAC, AMOTION_EVENT_ACTION_SCROLL, |
Harry Cutts | 82c791c | 2023-03-10 17:15:07 +0000 | [diff] [blame] | 159 | /*actionButton=*/0, /*flags=*/0, AMOTION_EVENT_EDGE_FLAG_NONE, AMETA_NONE, |
| 160 | /*buttonState=*/0, MotionClassification::NONE, identityTransform, |
| 161 | /*xPrecision=*/0, /*yPrecision=*/0, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 162 | AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, /*downTime=*/0, |
| 163 | timeStamp.count(), /*pointerCount=*/1, properties, coords); |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 164 | |
| 165 | events.emplace_back(event); |
| 166 | } |
| 167 | |
| 168 | return events; |
| 169 | } |
| 170 | |
| 171 | static std::vector<MotionEvent> createTouchMotionEventStream( |
| 172 | const std::vector<PlanarMotionEventEntry>& motions) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 173 | if (motions.empty()) { |
| 174 | ADD_FAILURE() << "Need at least 1 sample to create a MotionEvent. Received empty vector."; |
| 175 | } |
| 176 | |
| 177 | std::vector<MotionEvent> events; |
| 178 | for (size_t i = 0; i < motions.size(); i++) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 179 | const PlanarMotionEventEntry& entry = motions[i]; |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 180 | BitSet32 pointers = getValidPointers(entry.positions); |
| 181 | const uint32_t pointerCount = pointers.count(); |
| 182 | |
| 183 | int32_t action; |
| 184 | if (i == 0) { |
| 185 | action = AMOTION_EVENT_ACTION_DOWN; |
| 186 | EXPECT_EQ(1U, pointerCount) << "First event should only have 1 pointer"; |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 187 | } else if ((i == motions.size() - 1) && pointerCount == 1) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 188 | action = AMOTION_EVENT_ACTION_UP; |
| 189 | } else { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 190 | const PlanarMotionEventEntry& previousEntry = motions[i-1]; |
| 191 | const PlanarMotionEventEntry& nextEntry = motions[i+1]; |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 192 | action = resolveAction(previousEntry.positions, entry.positions, nextEntry.positions); |
| 193 | } |
| 194 | |
| 195 | PointerCoords coords[pointerCount]; |
| 196 | PointerProperties properties[pointerCount]; |
| 197 | uint32_t pointerIndex = 0; |
| 198 | while(!pointers.isEmpty()) { |
| 199 | uint32_t pointerId = pointers.clearFirstMarkedBit(); |
| 200 | |
| 201 | coords[pointerIndex].clear(); |
| 202 | // We are treating column positions as pointerId |
Siarhei Vishniakou | c36d21e | 2023-01-17 09:59:38 -0800 | [diff] [blame] | 203 | const Position& position = entry.positions[pointerId]; |
| 204 | EXPECT_TRUE(position.isValid()) << "The entry at " << pointerId << " must be valid"; |
| 205 | coords[pointerIndex].setAxisValue(AMOTION_EVENT_AXIS_X, position.x); |
| 206 | coords[pointerIndex].setAxisValue(AMOTION_EVENT_AXIS_Y, position.y); |
| 207 | coords[pointerIndex].isResampled = position.isResampled; |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 208 | |
| 209 | properties[pointerIndex].id = pointerId; |
Siarhei Vishniakou | 09a8fe4 | 2022-07-21 17:27:03 -0700 | [diff] [blame] | 210 | properties[pointerIndex].toolType = ToolType::FINGER; |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 211 | pointerIndex++; |
| 212 | } |
| 213 | EXPECT_EQ(pointerIndex, pointerCount); |
| 214 | |
| 215 | MotionEvent event; |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 216 | ui::Transform identityTransform; |
Harry Cutts | 82c791c | 2023-03-10 17:15:07 +0000 | [diff] [blame] | 217 | event.initialize(InputEvent::nextId(), /*deviceId=*/0, AINPUT_SOURCE_TOUCHSCREEN, |
| 218 | DISPLAY_ID, INVALID_HMAC, action, /*actionButton=*/0, /*flags=*/0, |
| 219 | AMOTION_EVENT_EDGE_FLAG_NONE, AMETA_NONE, /*buttonState=*/0, |
| 220 | MotionClassification::NONE, identityTransform, /*xPrecision=*/0, |
| 221 | /*yPrecision=*/0, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 222 | AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, /*downTime=*/0, |
Evan Rosky | 0957669 | 2021-07-01 12:22:09 -0700 | [diff] [blame] | 223 | entry.eventTime.count(), pointerCount, properties, coords); |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 224 | |
| 225 | events.emplace_back(event); |
| 226 | } |
| 227 | |
| 228 | return events; |
| 229 | } |
| 230 | |
Siarhei Vishniakou | 318005c | 2023-10-24 18:05:59 -0700 | [diff] [blame] | 231 | static std::optional<float> computeVelocity(const VelocityTracker::Strategy strategy, |
| 232 | const std::vector<MotionEvent>& events, int32_t axis, |
| 233 | uint32_t pointerId = DEFAULT_POINTER_ID) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 234 | VelocityTracker vt(strategy); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 235 | |
Siarhei Vishniakou | 318005c | 2023-10-24 18:05:59 -0700 | [diff] [blame] | 236 | for (const MotionEvent& event : events) { |
| 237 | vt.addMovement(event); |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 238 | } |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 239 | |
Yeabkal Wubshit | 871cc8a | 2022-09-26 17:46:28 -0700 | [diff] [blame] | 240 | return vt.getVelocity(axis, pointerId); |
| 241 | } |
| 242 | |
Siarhei Vishniakou | 318005c | 2023-10-24 18:05:59 -0700 | [diff] [blame] | 243 | static std::optional<float> computePlanarVelocity( |
Yeabkal Wubshit | 871cc8a | 2022-09-26 17:46:28 -0700 | [diff] [blame] | 244 | const VelocityTracker::Strategy strategy, |
Siarhei Vishniakou | 318005c | 2023-10-24 18:05:59 -0700 | [diff] [blame] | 245 | const std::vector<PlanarMotionEventEntry>& motions, int32_t axis, uint32_t pointerId) { |
| 246 | std::vector<MotionEvent> events = createTouchMotionEventStream(motions); |
| 247 | return computeVelocity(strategy, events, axis, pointerId); |
Yeabkal Wubshit | 871cc8a | 2022-09-26 17:46:28 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | static void computeAndCheckVelocity(const VelocityTracker::Strategy strategy, |
| 251 | const std::vector<PlanarMotionEventEntry>& motions, |
Yeabkal Wubshit | a15e599 | 2022-09-29 19:00:19 -0700 | [diff] [blame] | 252 | int32_t axis, std::optional<float> targetVelocity, |
Yeabkal Wubshit | 871cc8a | 2022-09-26 17:46:28 -0700 | [diff] [blame] | 253 | uint32_t pointerId = DEFAULT_POINTER_ID) { |
Yeabkal Wubshit | a15e599 | 2022-09-29 19:00:19 -0700 | [diff] [blame] | 254 | checkVelocity(computePlanarVelocity(strategy, motions, axis, pointerId), targetVelocity); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 255 | } |
| 256 | |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 257 | static void computeAndCheckAxisScrollVelocity( |
| 258 | const VelocityTracker::Strategy strategy, |
| 259 | const std::vector<std::pair<std::chrono::nanoseconds, float>>& motions, |
| 260 | std::optional<float> targetVelocity) { |
Siarhei Vishniakou | 318005c | 2023-10-24 18:05:59 -0700 | [diff] [blame] | 261 | std::vector<MotionEvent> events = createAxisScrollMotionEventStream(motions); |
| 262 | checkVelocity(computeVelocity(strategy, events, AMOTION_EVENT_AXIS_SCROLL), targetVelocity); |
Siarhei Vishniakou | 8a2e589 | 2023-08-14 13:59:40 -0700 | [diff] [blame] | 263 | // The strategy LSQ2 is not compatible with AXIS_SCROLL. In those situations, we should fall |
| 264 | // back to a strategy that supports differential axes. |
Siarhei Vishniakou | 318005c | 2023-10-24 18:05:59 -0700 | [diff] [blame] | 265 | checkVelocity(computeVelocity(VelocityTracker::Strategy::LSQ2, events, |
Siarhei Vishniakou | 8a2e589 | 2023-08-14 13:59:40 -0700 | [diff] [blame] | 266 | AMOTION_EVENT_AXIS_SCROLL), |
| 267 | targetVelocity); |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Yeabkal Wubshit | 9b4443f | 2023-02-23 23:35:07 -0800 | [diff] [blame] | 270 | static void computeAndCheckQuadraticVelocity(const std::vector<PlanarMotionEventEntry>& motions, |
| 271 | float velocity) { |
Siarhei Vishniakou | 318005c | 2023-10-24 18:05:59 -0700 | [diff] [blame] | 272 | std::optional<float> velocityX = |
| 273 | computePlanarVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 274 | DEFAULT_POINTER_ID); |
| 275 | std::optional<float> velocityY = |
| 276 | computePlanarVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 277 | DEFAULT_POINTER_ID); |
Yeabkal Wubshit | 9b4443f | 2023-02-23 23:35:07 -0800 | [diff] [blame] | 278 | ASSERT_TRUE(velocityX); |
| 279 | ASSERT_TRUE(velocityY); |
| 280 | |
| 281 | EXPECT_NEAR_BY_FRACTION(*velocityX, velocity, QUADRATIC_VELOCITY_TOLERANCE); |
| 282 | EXPECT_NEAR_BY_FRACTION(*velocityY, velocity, QUADRATIC_VELOCITY_TOLERANCE); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 285 | /* |
Yeabkal Wubshit | eca273c | 2022-10-05 19:06:40 -0700 | [diff] [blame] | 286 | *================== VelocityTracker tests that do not require test motion data ==================== |
| 287 | */ |
| 288 | TEST(SimpleVelocityTrackerTest, TestSupportedAxis) { |
| 289 | // Note that we are testing up to the max possible axis value, plus 3 more values. We are going |
| 290 | // beyond the max value to add a bit more protection. "3" is chosen arbitrarily to cover a few |
| 291 | // more values beyond the max. |
| 292 | for (int32_t axis = 0; axis <= AMOTION_EVENT_MAXIMUM_VALID_AXIS_VALUE + 3; axis++) { |
| 293 | switch (axis) { |
| 294 | case AMOTION_EVENT_AXIS_X: |
| 295 | case AMOTION_EVENT_AXIS_Y: |
| 296 | case AMOTION_EVENT_AXIS_SCROLL: |
| 297 | EXPECT_TRUE(VelocityTracker::isAxisSupported(axis)) << axis << " is supported"; |
| 298 | break; |
| 299 | default: |
| 300 | EXPECT_FALSE(VelocityTracker::isAxisSupported(axis)) << axis << " is NOT supported"; |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | /* |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 306 | * ================== VelocityTracker tests generated manually ===================================== |
| 307 | */ |
Yeabkal Wubshit | 871cc8a | 2022-09-26 17:46:28 -0700 | [diff] [blame] | 308 | TEST_F(VelocityTrackerTest, TestDefaultStrategiesForPlanarAxes) { |
| 309 | std::vector<PlanarMotionEventEntry> motions = {{10ms, {{2, 4}}}, |
| 310 | {20ms, {{4, 12}}}, |
| 311 | {30ms, {{6, 20}}}, |
| 312 | {40ms, {{10, 30}}}}; |
| 313 | |
Siarhei Vishniakou | 318005c | 2023-10-24 18:05:59 -0700 | [diff] [blame] | 314 | EXPECT_EQ(computePlanarVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 315 | DEFAULT_POINTER_ID), |
Yeabkal Wubshit | 871cc8a | 2022-09-26 17:46:28 -0700 | [diff] [blame] | 316 | computePlanarVelocity(VelocityTracker::Strategy::DEFAULT, motions, |
Siarhei Vishniakou | 318005c | 2023-10-24 18:05:59 -0700 | [diff] [blame] | 317 | AMOTION_EVENT_AXIS_X, DEFAULT_POINTER_ID)); |
| 318 | EXPECT_EQ(computePlanarVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 319 | DEFAULT_POINTER_ID), |
Yeabkal Wubshit | 871cc8a | 2022-09-26 17:46:28 -0700 | [diff] [blame] | 320 | computePlanarVelocity(VelocityTracker::Strategy::DEFAULT, motions, |
Siarhei Vishniakou | 318005c | 2023-10-24 18:05:59 -0700 | [diff] [blame] | 321 | AMOTION_EVENT_AXIS_Y, DEFAULT_POINTER_ID)); |
Yeabkal Wubshit | 871cc8a | 2022-09-26 17:46:28 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 324 | TEST_F(VelocityTrackerTest, TestComputedVelocity) { |
| 325 | VelocityTracker::ComputedVelocity computedVelocity; |
| 326 | |
Harry Cutts | 82c791c | 2023-03-10 17:15:07 +0000 | [diff] [blame] | 327 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_X, /*id=*/0, /*velocity=*/200); |
| 328 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_X, /*id=*/26U, /*velocity=*/400); |
| 329 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_X, /*id=*/27U, /*velocity=*/650); |
| 330 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_X, MAX_POINTER_ID, /*velocity=*/750); |
| 331 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_Y, /*id=*/0, /*velocity=*/1000); |
| 332 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_Y, /*id=*/26U, /*velocity=*/2000); |
| 333 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_Y, /*id=*/27U, /*velocity=*/3000); |
| 334 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_Y, MAX_POINTER_ID, /*velocity=*/4000); |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 335 | |
| 336 | // Check the axes/indices with velocity. |
Harry Cutts | 82c791c | 2023-03-10 17:15:07 +0000 | [diff] [blame] | 337 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, /*id=*/0U)), 200); |
| 338 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, /*id=*/26U)), 400); |
| 339 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, /*id=*/27U)), 650); |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 340 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, MAX_POINTER_ID)), 750); |
Harry Cutts | 82c791c | 2023-03-10 17:15:07 +0000 | [diff] [blame] | 341 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, /*id=*/0U)), 1000); |
| 342 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, /*id=*/26U)), 2000); |
| 343 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, /*id=*/27U)), 3000); |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 344 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, MAX_POINTER_ID)), 4000); |
| 345 | for (uint32_t id = 0; id <= MAX_POINTER_ID; id++) { |
| 346 | // Since no data was added for AXIS_SCROLL, expect empty value for the axis for any id. |
| 347 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_SCROLL, id)) |
| 348 | << "Empty scroll data expected at id=" << id; |
| 349 | if (id == 0 || id == 26U || id == 27U || id == MAX_POINTER_ID) { |
| 350 | // Already checked above; continue. |
| 351 | continue; |
| 352 | } |
| 353 | // No data was added to X/Y for this id, expect empty value. |
| 354 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, id)) |
| 355 | << "Empty X data expected at id=" << id; |
| 356 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, id)) |
| 357 | << "Empty Y data expected at id=" << id; |
| 358 | } |
| 359 | // Out-of-bounds ids should given empty values. |
| 360 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, -1)); |
| 361 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, MAX_POINTER_ID + 1)); |
| 362 | } |
| 363 | |
Siarhei Vishniakou | c36d21e | 2023-01-17 09:59:38 -0800 | [diff] [blame] | 364 | /** |
| 365 | * For a single pointer, the resampled data is ignored. |
| 366 | */ |
| 367 | TEST_F(VelocityTrackerTest, SinglePointerResampledData) { |
| 368 | std::vector<PlanarMotionEventEntry> motions = {{10ms, {{1, 2}}}, |
| 369 | {20ms, {{2, 4}}}, |
| 370 | {30ms, {{3, 6}}}, |
| 371 | {35ms, {{30, 60, .isResampled = true}}}, |
| 372 | {40ms, {{4, 8}}}}; |
| 373 | |
| 374 | computeAndCheckVelocity(VelocityTracker::Strategy::DEFAULT, motions, AMOTION_EVENT_AXIS_X, 100); |
| 375 | computeAndCheckVelocity(VelocityTracker::Strategy::DEFAULT, motions, AMOTION_EVENT_AXIS_Y, 200); |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * For multiple pointers, the resampled data is ignored on a per-pointer basis. If a certain pointer |
| 380 | * does not have a resampled value, all of the points are used. |
| 381 | */ |
| 382 | TEST_F(VelocityTrackerTest, MultiPointerResampledData) { |
| 383 | std::vector<PlanarMotionEventEntry> motions = { |
| 384 | {0ms, {{0, 0}}}, |
| 385 | {10ms, {{1, 0}, {1, 0}}}, |
| 386 | {20ms, {{2, 0}, {2, 0}}}, |
| 387 | {30ms, {{3, 0}, {3, 0}}}, |
| 388 | {35ms, {{30, 0, .isResampled = true}, {30, 0}}}, |
| 389 | {40ms, {{4, 0}, {4, 0}}}, |
| 390 | {45ms, {{5, 0}}}, // ACTION_UP |
| 391 | }; |
| 392 | |
| 393 | // Sample at t=35ms breaks trend. It's marked as resampled for the first pointer, so it should |
| 394 | // be ignored, and the resulting velocity should be linear. For the second pointer, it's not |
| 395 | // resampled, so it should cause the velocity to be non-linear. |
| 396 | computeAndCheckVelocity(VelocityTracker::Strategy::DEFAULT, motions, AMOTION_EVENT_AXIS_X, 100, |
| 397 | /*pointerId=*/0); |
| 398 | computeAndCheckVelocity(VelocityTracker::Strategy::DEFAULT, motions, AMOTION_EVENT_AXIS_X, 3455, |
| 399 | /*pointerId=*/1); |
| 400 | } |
| 401 | |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 402 | TEST_F(VelocityTrackerTest, TestGetComputedVelocity) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 403 | std::vector<PlanarMotionEventEntry> motions = { |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 404 | {235089067457000ns, {{528.00, 0}}}, {235089084684000ns, {{527.00, 0}}}, |
| 405 | {235089093349000ns, {{527.00, 0}}}, {235089095677625ns, {{527.00, 0}}}, |
| 406 | {235089101859000ns, {{527.00, 0}}}, {235089110378000ns, {{528.00, 0}}}, |
| 407 | {235089112497111ns, {{528.25, 0}}}, {235089118760000ns, {{531.00, 0}}}, |
| 408 | {235089126686000ns, {{535.00, 0}}}, {235089129316820ns, {{536.33, 0}}}, |
| 409 | {235089135199000ns, {{540.00, 0}}}, {235089144297000ns, {{546.00, 0}}}, |
| 410 | {235089146136443ns, {{547.21, 0}}}, {235089152923000ns, {{553.00, 0}}}, |
| 411 | {235089160784000ns, {{559.00, 0}}}, {235089162955851ns, {{560.66, 0}}}, |
| 412 | {235089162955851ns, {{560.66, 0}}}, // ACTION_UP |
| 413 | }; |
| 414 | VelocityTracker vt(VelocityTracker::Strategy::IMPULSE); |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 415 | std::vector<MotionEvent> events = createTouchMotionEventStream(motions); |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 416 | for (const MotionEvent& event : events) { |
Siarhei Vishniakou | 318005c | 2023-10-24 18:05:59 -0700 | [diff] [blame] | 417 | vt.addMovement(event); |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | float maxFloat = std::numeric_limits<float>::max(); |
| 421 | VelocityTracker::ComputedVelocity computedVelocity; |
Harry Cutts | 82c791c | 2023-03-10 17:15:07 +0000 | [diff] [blame] | 422 | computedVelocity = vt.getComputedVelocity(/*units=*/1000, maxFloat); |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 423 | checkVelocity(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, DEFAULT_POINTER_ID)), |
| 424 | 764.345703); |
| 425 | |
| 426 | // Expect X velocity to be scaled with respective to provided units. |
Harry Cutts | 82c791c | 2023-03-10 17:15:07 +0000 | [diff] [blame] | 427 | computedVelocity = vt.getComputedVelocity(/*units=*/1000000, maxFloat); |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 428 | checkVelocity(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, DEFAULT_POINTER_ID)), |
| 429 | 764345.703); |
| 430 | |
| 431 | // Expect X velocity to be clamped by provided max velocity. |
Harry Cutts | 82c791c | 2023-03-10 17:15:07 +0000 | [diff] [blame] | 432 | computedVelocity = vt.getComputedVelocity(/*units=*/1000000, 1000); |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 433 | checkVelocity(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, DEFAULT_POINTER_ID)), 1000); |
| 434 | |
| 435 | // All 0 data for Y; expect 0 velocity. |
| 436 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, DEFAULT_POINTER_ID)), 0); |
| 437 | |
| 438 | // No data for scroll-axis; expect empty velocity. |
| 439 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_SCROLL, DEFAULT_POINTER_ID)); |
| 440 | } |
| 441 | |
Yeabkal Wubshit | 47ff708 | 2022-09-10 23:09:15 -0700 | [diff] [blame] | 442 | TEST_F(VelocityTrackerTest, TestApiInteractionsWithNoMotionEvents) { |
| 443 | VelocityTracker vt(VelocityTracker::Strategy::DEFAULT); |
| 444 | |
| 445 | EXPECT_FALSE(vt.getVelocity(AMOTION_EVENT_AXIS_X, DEFAULT_POINTER_ID)); |
| 446 | |
Yeabkal Wubshit | 47ff708 | 2022-09-10 23:09:15 -0700 | [diff] [blame] | 447 | VelocityTracker::ComputedVelocity computedVelocity = vt.getComputedVelocity(1000, 1000); |
| 448 | for (uint32_t id = 0; id <= MAX_POINTER_ID; id++) { |
| 449 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, id)); |
| 450 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, id)); |
| 451 | } |
| 452 | |
| 453 | EXPECT_EQ(-1, vt.getActivePointerId()); |
| 454 | |
| 455 | // Make sure that the clearing functions execute without an issue. |
Siarhei Vishniakou | 8d23203 | 2023-01-11 08:17:21 -0800 | [diff] [blame] | 456 | vt.clearPointer(7U); |
Yeabkal Wubshit | 47ff708 | 2022-09-10 23:09:15 -0700 | [diff] [blame] | 457 | vt.clear(); |
| 458 | } |
| 459 | |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 460 | TEST_F(VelocityTrackerTest, ThreePointsPositiveVelocityTest) { |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 461 | // Same coordinate is reported 2 times in a row |
| 462 | // It is difficult to determine the correct answer here, but at least the direction |
| 463 | // of the reported velocity should be positive. |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 464 | std::vector<PlanarMotionEventEntry> motions = { |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 465 | {0ms, {{273, 0}}}, |
| 466 | {12585us, {{293, 0}}}, |
| 467 | {14730us, {{293, 0}}}, |
| 468 | {14730us, {{293, 0}}}, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 469 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 470 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 471 | 1600); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | TEST_F(VelocityTrackerTest, ThreePointsZeroVelocityTest) { |
| 475 | // Same coordinate is reported 3 times in a row |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 476 | std::vector<PlanarMotionEventEntry> motions = { |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 477 | {0ms, {{293, 0}}}, |
| 478 | {6132us, {{293, 0}}}, |
| 479 | {11283us, {{293, 0}}}, |
| 480 | {11283us, {{293, 0}}}, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 481 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 482 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, 0); |
| 483 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, 0); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | TEST_F(VelocityTrackerTest, ThreePointsLinearVelocityTest) { |
| 487 | // Fixed velocity at 5 points per 10 milliseconds |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 488 | std::vector<PlanarMotionEventEntry> motions = { |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 489 | {0ms, {{0, 0}}}, {10ms, {{5, 0}}}, {20ms, {{10, 0}}}, {20ms, {{10, 0}}}, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 490 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 491 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, 500); |
| 492 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, 500); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 493 | } |
| 494 | |
Siarhei Vishniakou | 318005c | 2023-10-24 18:05:59 -0700 | [diff] [blame] | 495 | /** |
| 496 | * When the stream is terminated with ACTION_CANCEL, the resulting velocity should be 0. |
| 497 | */ |
| 498 | TEST_F(VelocityTrackerTest, ActionCancelResultsInZeroVelocity) { |
| 499 | std::vector<PlanarMotionEventEntry> motions = { |
| 500 | {0ms, {{0, 0}}}, // DOWN |
| 501 | {10ms, {{5, 10}}}, // MOVE |
| 502 | {20ms, {{10, 20}}}, // MOVE |
| 503 | {20ms, {{10, 20}}}, // ACTION_UP |
| 504 | }; |
| 505 | std::vector<MotionEvent> events = createTouchMotionEventStream(motions); |
| 506 | // By default, `createTouchMotionEventStream` produces an event stream that terminates with |
| 507 | // ACTION_UP. We need to manually change it to ACTION_CANCEL. |
| 508 | MotionEvent& lastEvent = events.back(); |
| 509 | lastEvent.setAction(AMOTION_EVENT_ACTION_CANCEL); |
| 510 | lastEvent.setFlags(lastEvent.getFlags() | AMOTION_EVENT_FLAG_CANCELED); |
| 511 | const int32_t pointerId = lastEvent.getPointerId(0); |
| 512 | checkVelocity(computeVelocity(VelocityTracker::Strategy::IMPULSE, events, AMOTION_EVENT_AXIS_X, |
| 513 | pointerId), |
| 514 | /*targetVelocity*/ std::nullopt); |
| 515 | checkVelocity(computeVelocity(VelocityTracker::Strategy::IMPULSE, events, AMOTION_EVENT_AXIS_Y, |
| 516 | pointerId), |
| 517 | /*targetVelocity*/ std::nullopt); |
| 518 | checkVelocity(computeVelocity(VelocityTracker::Strategy::LSQ2, events, AMOTION_EVENT_AXIS_X, |
| 519 | pointerId), |
| 520 | /*targetVelocity*/ std::nullopt); |
| 521 | checkVelocity(computeVelocity(VelocityTracker::Strategy::LSQ2, events, AMOTION_EVENT_AXIS_Y, |
| 522 | pointerId), |
| 523 | /*targetVelocity*/ std::nullopt); |
| 524 | } |
| 525 | |
| 526 | /** |
| 527 | * When the stream is terminated with ACTION_CANCEL, the resulting velocity should be 0. |
| 528 | */ |
| 529 | TEST_F(VelocityTrackerTest, ActionPointerCancelResultsInZeroVelocityForThatPointer) { |
| 530 | std::vector<PlanarMotionEventEntry> motions = { |
| 531 | {0ms, {{0, 5}, {NAN, NAN}}}, // DOWN |
| 532 | {0ms, {{0, 5}, {10, 15}}}, // POINTER_DOWN |
| 533 | {10ms, {{5, 10}, {15, 20}}}, // MOVE |
| 534 | {20ms, {{10, 15}, {20, 25}}}, // MOVE |
| 535 | {30ms, {{10, 15}, {20, 25}}}, // POINTER_UP |
| 536 | {30ms, {{10, 15}, {NAN, NAN}}}, // UP |
| 537 | }; |
| 538 | std::vector<MotionEvent> events = createTouchMotionEventStream(motions); |
| 539 | // Cancel the lifting pointer of the ACTION_POINTER_UP event |
| 540 | MotionEvent& pointerUpEvent = events.rbegin()[1]; |
| 541 | pointerUpEvent.setFlags(pointerUpEvent.getFlags() | AMOTION_EVENT_FLAG_CANCELED); |
| 542 | const int32_t pointerId = pointerUpEvent.getPointerId(pointerUpEvent.getActionIndex()); |
| 543 | // Double check the stream |
| 544 | ASSERT_EQ(1, pointerId); |
| 545 | ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP, pointerUpEvent.getActionMasked()); |
| 546 | ASSERT_EQ(AMOTION_EVENT_ACTION_UP, events.back().getActionMasked()); |
| 547 | |
| 548 | // Ensure the velocity of the lifting pointer is zero |
| 549 | checkVelocity(computeVelocity(VelocityTracker::Strategy::IMPULSE, events, AMOTION_EVENT_AXIS_X, |
| 550 | pointerId), |
| 551 | /*targetVelocity*/ std::nullopt); |
| 552 | checkVelocity(computeVelocity(VelocityTracker::Strategy::IMPULSE, events, AMOTION_EVENT_AXIS_Y, |
| 553 | pointerId), |
| 554 | /*targetVelocity*/ std::nullopt); |
| 555 | checkVelocity(computeVelocity(VelocityTracker::Strategy::LSQ2, events, AMOTION_EVENT_AXIS_X, |
| 556 | pointerId), |
| 557 | /*targetVelocity*/ std::nullopt); |
| 558 | checkVelocity(computeVelocity(VelocityTracker::Strategy::LSQ2, events, AMOTION_EVENT_AXIS_Y, |
| 559 | pointerId), |
| 560 | /*targetVelocity*/ std::nullopt); |
| 561 | |
| 562 | // The remaining pointer should have the correct velocity. |
| 563 | const int32_t remainingPointerId = events.back().getPointerId(0); |
| 564 | ASSERT_EQ(0, remainingPointerId); |
| 565 | checkVelocity(computeVelocity(VelocityTracker::Strategy::IMPULSE, events, AMOTION_EVENT_AXIS_X, |
| 566 | remainingPointerId), |
| 567 | /*targetVelocity*/ 500); |
| 568 | checkVelocity(computeVelocity(VelocityTracker::Strategy::IMPULSE, events, AMOTION_EVENT_AXIS_Y, |
| 569 | remainingPointerId), |
| 570 | /*targetVelocity*/ 500); |
| 571 | checkVelocity(computeVelocity(VelocityTracker::Strategy::LSQ2, events, AMOTION_EVENT_AXIS_X, |
| 572 | remainingPointerId), |
| 573 | /*targetVelocity*/ 500); |
| 574 | checkVelocity(computeVelocity(VelocityTracker::Strategy::LSQ2, events, AMOTION_EVENT_AXIS_Y, |
| 575 | remainingPointerId), |
| 576 | /*targetVelocity*/ 500); |
| 577 | } |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 578 | |
| 579 | /** |
| 580 | * ================== VelocityTracker tests generated by recording real events ===================== |
| 581 | * |
| 582 | * To add a test, record the input coordinates and event times to all calls |
| 583 | * to void VelocityTracker::addMovement(const MotionEvent* event). |
| 584 | * Also record all calls to VelocityTracker::clear(). |
| 585 | * Finally, record the output of VelocityTracker::getVelocity(...) |
| 586 | * This will give you the necessary data to create a new test. |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 587 | * |
| 588 | * Another good way to generate this data is to use 'dumpsys input' just after the event has |
| 589 | * occurred. |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 590 | */ |
| 591 | |
| 592 | // --------------- Recorded by hand on swordfish --------------------------------------------------- |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 593 | TEST_F(VelocityTrackerTest, SwordfishFlingDown) { |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 594 | // Recording of a fling on Swordfish that could cause a fling in the wrong direction |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 595 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 596 | { 0ms, {{271, 96}} }, |
| 597 | { 16071042ns, {{269.786346, 106.922775}} }, |
| 598 | { 35648403ns, {{267.983063, 156.660034}} }, |
| 599 | { 52313925ns, {{262.638397, 220.339081}} }, |
| 600 | { 68976522ns, {{266.138824, 331.581116}} }, |
| 601 | { 85639375ns, {{274.79245, 428.113159}} }, |
| 602 | { 96948871ns, {{274.79245, 428.113159}} }, |
| 603 | { 96948871ns, {{274.79245, 428.113159}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 604 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 605 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 606 | 623.577637); |
| 607 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 608 | 5970.7309); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | // --------------- Recorded by hand on sailfish, generated by a script ----------------------------- |
| 612 | // For some of these tests, the X-direction velocity checking has been removed, because the lsq2 |
| 613 | // and the impulse VelocityTrackerStrategies did not agree within 20%. |
| 614 | // Since the flings were recorded in the Y-direction, the intentional user action should only |
| 615 | // be relevant for the Y axis. |
| 616 | // There have been also cases where lsq2 and impulse disagreed more than 20% in the Y-direction. |
| 617 | // Those recordings have been discarded because we didn't feel one strategy's interpretation was |
| 618 | // more correct than another's but didn't want to increase the tolerance for the entire test suite. |
| 619 | // |
| 620 | // There are 18 tests total below: 9 in the positive Y direction and 9 in the opposite. |
| 621 | // The recordings were loosely binned into 3 categories - slow, faster, and fast, which roughly |
| 622 | // characterizes the velocity of the finger motion. |
| 623 | // These can be treated approximately as: |
| 624 | // slow - less than 1 page gets scrolled |
| 625 | // faster - more than 1 page gets scrolled, but less than 3 |
| 626 | // fast - entire list is scrolled (fling is done as hard as possible) |
| 627 | |
| 628 | TEST_F(VelocityTrackerTest, SailfishFlingUpSlow1) { |
| 629 | // Sailfish - fling up - slow - 1 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 630 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 631 | { 235089067457000ns, {{528.00, 983.00}} }, |
| 632 | { 235089084684000ns, {{527.00, 981.00}} }, |
| 633 | { 235089093349000ns, {{527.00, 977.00}} }, |
| 634 | { 235089095677625ns, {{527.00, 975.93}} }, |
| 635 | { 235089101859000ns, {{527.00, 970.00}} }, |
| 636 | { 235089110378000ns, {{528.00, 960.00}} }, |
| 637 | { 235089112497111ns, {{528.25, 957.51}} }, |
| 638 | { 235089118760000ns, {{531.00, 946.00}} }, |
| 639 | { 235089126686000ns, {{535.00, 931.00}} }, |
| 640 | { 235089129316820ns, {{536.33, 926.02}} }, |
| 641 | { 235089135199000ns, {{540.00, 914.00}} }, |
| 642 | { 235089144297000ns, {{546.00, 896.00}} }, |
| 643 | { 235089146136443ns, {{547.21, 892.36}} }, |
| 644 | { 235089152923000ns, {{553.00, 877.00}} }, |
| 645 | { 235089160784000ns, {{559.00, 851.00}} }, |
| 646 | { 235089162955851ns, {{560.66, 843.82}} }, |
| 647 | { 235089162955851ns, {{560.66, 843.82}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 648 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 649 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
Siarhei Vishniakou | e37bcec | 2021-09-28 14:24:32 -0700 | [diff] [blame] | 650 | 764.345703); |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 651 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 652 | 951.698181); |
| 653 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 654 | -3604.819336); |
| 655 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 656 | -3044.966064); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | |
| 660 | TEST_F(VelocityTrackerTest, SailfishFlingUpSlow2) { |
| 661 | // Sailfish - fling up - slow - 2 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 662 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 663 | { 235110560704000ns, {{522.00, 1107.00}} }, |
| 664 | { 235110575764000ns, {{522.00, 1107.00}} }, |
| 665 | { 235110584385000ns, {{522.00, 1107.00}} }, |
| 666 | { 235110588421179ns, {{521.52, 1106.52}} }, |
| 667 | { 235110592830000ns, {{521.00, 1106.00}} }, |
| 668 | { 235110601385000ns, {{520.00, 1104.00}} }, |
| 669 | { 235110605088160ns, {{519.14, 1102.27}} }, |
| 670 | { 235110609952000ns, {{518.00, 1100.00}} }, |
| 671 | { 235110618353000ns, {{517.00, 1093.00}} }, |
| 672 | { 235110621755146ns, {{516.60, 1090.17}} }, |
| 673 | { 235110627010000ns, {{517.00, 1081.00}} }, |
| 674 | { 235110634785000ns, {{518.00, 1063.00}} }, |
| 675 | { 235110638422450ns, {{518.87, 1052.58}} }, |
| 676 | { 235110643161000ns, {{520.00, 1039.00}} }, |
| 677 | { 235110651767000ns, {{524.00, 1011.00}} }, |
| 678 | { 235110655089581ns, {{525.54, 1000.19}} }, |
| 679 | { 235110660368000ns, {{530.00, 980.00}} }, |
| 680 | { 235110660368000ns, {{530.00, 980.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 681 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 682 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 683 | -4096.583008); |
| 684 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 685 | -3455.094238); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | |
| 689 | TEST_F(VelocityTrackerTest, SailfishFlingUpSlow3) { |
| 690 | // Sailfish - fling up - slow - 3 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 691 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 692 | { 792536237000ns, {{580.00, 1317.00}} }, |
| 693 | { 792541538987ns, {{580.63, 1311.94}} }, |
| 694 | { 792544613000ns, {{581.00, 1309.00}} }, |
| 695 | { 792552301000ns, {{583.00, 1295.00}} }, |
| 696 | { 792558362309ns, {{585.13, 1282.92}} }, |
| 697 | { 792560828000ns, {{586.00, 1278.00}} }, |
| 698 | { 792569446000ns, {{589.00, 1256.00}} }, |
| 699 | { 792575185095ns, {{591.54, 1241.41}} }, |
| 700 | { 792578491000ns, {{593.00, 1233.00}} }, |
| 701 | { 792587044000ns, {{597.00, 1211.00}} }, |
| 702 | { 792592008172ns, {{600.28, 1195.92}} }, |
| 703 | { 792594616000ns, {{602.00, 1188.00}} }, |
| 704 | { 792603129000ns, {{607.00, 1167.00}} }, |
| 705 | { 792608831290ns, {{609.48, 1155.83}} }, |
| 706 | { 792612321000ns, {{611.00, 1149.00}} }, |
| 707 | { 792620768000ns, {{615.00, 1131.00}} }, |
| 708 | { 792625653873ns, {{617.32, 1121.73}} }, |
| 709 | { 792629200000ns, {{619.00, 1115.00}} }, |
| 710 | { 792629200000ns, {{619.00, 1115.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 711 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 712 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 713 | 574.33429); |
| 714 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 715 | 617.40564); |
| 716 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 717 | -2361.982666); |
| 718 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 719 | -2500.055664); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | |
| 723 | TEST_F(VelocityTrackerTest, SailfishFlingUpFaster1) { |
| 724 | // Sailfish - fling up - faster - 1 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 725 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 726 | { 235160420675000ns, {{610.00, 1042.00}} }, |
| 727 | { 235160428220000ns, {{609.00, 1026.00}} }, |
| 728 | { 235160436544000ns, {{609.00, 1024.00}} }, |
| 729 | { 235160441852394ns, {{609.64, 1020.82}} }, |
| 730 | { 235160444878000ns, {{610.00, 1019.00}} }, |
| 731 | { 235160452673000ns, {{613.00, 1006.00}} }, |
| 732 | { 235160458519743ns, {{617.18, 992.06}} }, |
| 733 | { 235160461061000ns, {{619.00, 986.00}} }, |
| 734 | { 235160469798000ns, {{627.00, 960.00}} }, |
| 735 | { 235160475186713ns, {{632.22, 943.02}} }, |
| 736 | { 235160478051000ns, {{635.00, 934.00}} }, |
| 737 | { 235160486489000ns, {{644.00, 906.00}} }, |
| 738 | { 235160491853697ns, {{649.56, 890.56}} }, |
| 739 | { 235160495177000ns, {{653.00, 881.00}} }, |
| 740 | { 235160504148000ns, {{662.00, 858.00}} }, |
| 741 | { 235160509231495ns, {{666.81, 845.37}} }, |
| 742 | { 235160512603000ns, {{670.00, 837.00}} }, |
| 743 | { 235160520366000ns, {{679.00, 814.00}} }, |
| 744 | { 235160520366000ns, {{679.00, 814.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 745 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 746 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 747 | 1274.141724); |
| 748 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 749 | 1438.53186); |
| 750 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 751 | -3001.4348); |
| 752 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 753 | -3695.859619); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | |
| 757 | TEST_F(VelocityTrackerTest, SailfishFlingUpFaster2) { |
| 758 | // Sailfish - fling up - faster - 2 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 759 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 760 | { 847153808000ns, {{576.00, 1264.00}} }, |
| 761 | { 847171174000ns, {{576.00, 1262.00}} }, |
| 762 | { 847179640000ns, {{576.00, 1257.00}} }, |
| 763 | { 847185187540ns, {{577.41, 1249.22}} }, |
| 764 | { 847187487000ns, {{578.00, 1246.00}} }, |
| 765 | { 847195710000ns, {{581.00, 1227.00}} }, |
| 766 | { 847202027059ns, {{583.93, 1209.40}} }, |
| 767 | { 847204324000ns, {{585.00, 1203.00}} }, |
| 768 | { 847212672000ns, {{590.00, 1176.00}} }, |
| 769 | { 847218861395ns, {{594.36, 1157.11}} }, |
| 770 | { 847221190000ns, {{596.00, 1150.00}} }, |
| 771 | { 847230484000ns, {{602.00, 1124.00}} }, |
| 772 | { 847235701400ns, {{607.56, 1103.83}} }, |
| 773 | { 847237986000ns, {{610.00, 1095.00}} }, |
| 774 | { 847237986000ns, {{610.00, 1095.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 775 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 776 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 777 | -4280.07959); |
| 778 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 779 | -4241.004395); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | |
| 783 | TEST_F(VelocityTrackerTest, SailfishFlingUpFaster3) { |
| 784 | // Sailfish - fling up - faster - 3 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 785 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 786 | { 235200532789000ns, {{507.00, 1084.00}} }, |
| 787 | { 235200549221000ns, {{507.00, 1083.00}} }, |
| 788 | { 235200557841000ns, {{507.00, 1081.00}} }, |
| 789 | { 235200558051189ns, {{507.00, 1080.95}} }, |
| 790 | { 235200566314000ns, {{507.00, 1078.00}} }, |
| 791 | { 235200574876586ns, {{508.97, 1070.12}} }, |
| 792 | { 235200575006000ns, {{509.00, 1070.00}} }, |
| 793 | { 235200582900000ns, {{514.00, 1054.00}} }, |
| 794 | { 235200591276000ns, {{525.00, 1023.00}} }, |
| 795 | { 235200591701829ns, {{525.56, 1021.42}} }, |
| 796 | { 235200600064000ns, {{542.00, 976.00}} }, |
| 797 | { 235200608519000ns, {{563.00, 911.00}} }, |
| 798 | { 235200608527086ns, {{563.02, 910.94}} }, |
| 799 | { 235200616933000ns, {{590.00, 844.00}} }, |
| 800 | { 235200616933000ns, {{590.00, 844.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 801 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 802 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 803 | -8715.686523); |
| 804 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 805 | -7639.026367); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | |
| 809 | TEST_F(VelocityTrackerTest, SailfishFlingUpFast1) { |
| 810 | // Sailfish - fling up - fast - 1 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 811 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 812 | { 920922149000ns, {{561.00, 1412.00}} }, |
| 813 | { 920930185000ns, {{559.00, 1377.00}} }, |
| 814 | { 920930262463ns, {{558.98, 1376.66}} }, |
| 815 | { 920938547000ns, {{559.00, 1371.00}} }, |
| 816 | { 920947096857ns, {{562.91, 1342.68}} }, |
| 817 | { 920947302000ns, {{563.00, 1342.00}} }, |
| 818 | { 920955502000ns, {{577.00, 1272.00}} }, |
| 819 | { 920963931021ns, {{596.87, 1190.54}} }, |
| 820 | { 920963987000ns, {{597.00, 1190.00}} }, |
| 821 | { 920972530000ns, {{631.00, 1093.00}} }, |
| 822 | { 920980765511ns, {{671.31, 994.68}} }, |
| 823 | { 920980906000ns, {{672.00, 993.00}} }, |
| 824 | { 920989261000ns, {{715.00, 903.00}} }, |
| 825 | { 920989261000ns, {{715.00, 903.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 826 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 827 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 828 | 5670.329102); |
| 829 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 830 | 5991.866699); |
| 831 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 832 | -13021.101562); |
| 833 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 834 | -15093.995117); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | |
| 838 | TEST_F(VelocityTrackerTest, SailfishFlingUpFast2) { |
| 839 | // Sailfish - fling up - fast - 2 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 840 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 841 | { 235247153233000ns, {{518.00, 1168.00}} }, |
| 842 | { 235247170452000ns, {{517.00, 1167.00}} }, |
| 843 | { 235247178908000ns, {{515.00, 1159.00}} }, |
| 844 | { 235247179556213ns, {{514.85, 1158.39}} }, |
| 845 | { 235247186821000ns, {{515.00, 1125.00}} }, |
| 846 | { 235247195265000ns, {{521.00, 1051.00}} }, |
| 847 | { 235247196389476ns, {{521.80, 1041.15}} }, |
| 848 | { 235247203649000ns, {{538.00, 932.00}} }, |
| 849 | { 235247212253000ns, {{571.00, 794.00}} }, |
| 850 | { 235247213222491ns, {{574.72, 778.45}} }, |
| 851 | { 235247220736000ns, {{620.00, 641.00}} }, |
| 852 | { 235247220736000ns, {{620.00, 641.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 853 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 854 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 855 | -20286.958984); |
| 856 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 857 | -20494.587891); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | |
| 861 | TEST_F(VelocityTrackerTest, SailfishFlingUpFast3) { |
| 862 | // Sailfish - fling up - fast - 3 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 863 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 864 | { 235302568736000ns, {{529.00, 1167.00}} }, |
| 865 | { 235302576644000ns, {{523.00, 1140.00}} }, |
| 866 | { 235302579395063ns, {{520.91, 1130.61}} }, |
| 867 | { 235302585140000ns, {{522.00, 1130.00}} }, |
| 868 | { 235302593615000ns, {{527.00, 1065.00}} }, |
| 869 | { 235302596207444ns, {{528.53, 1045.12}} }, |
| 870 | { 235302602102000ns, {{559.00, 872.00}} }, |
| 871 | { 235302610545000ns, {{652.00, 605.00}} }, |
| 872 | { 235302613019881ns, {{679.26, 526.73}} }, |
| 873 | { 235302613019881ns, {{679.26, 526.73}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 874 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 875 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 876 | -39295.941406); |
| 877 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 878 | -36461.421875); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | |
| 882 | TEST_F(VelocityTrackerTest, SailfishFlingDownSlow1) { |
| 883 | // Sailfish - fling down - slow - 1 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 884 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 885 | { 235655749552755ns, {{582.00, 432.49}} }, |
| 886 | { 235655750638000ns, {{582.00, 433.00}} }, |
| 887 | { 235655758865000ns, {{582.00, 440.00}} }, |
| 888 | { 235655766221523ns, {{581.16, 448.43}} }, |
| 889 | { 235655767594000ns, {{581.00, 450.00}} }, |
| 890 | { 235655776044000ns, {{580.00, 462.00}} }, |
| 891 | { 235655782890696ns, {{579.18, 474.35}} }, |
| 892 | { 235655784360000ns, {{579.00, 477.00}} }, |
| 893 | { 235655792795000ns, {{578.00, 496.00}} }, |
| 894 | { 235655799559531ns, {{576.27, 515.04}} }, |
| 895 | { 235655800612000ns, {{576.00, 518.00}} }, |
| 896 | { 235655809535000ns, {{574.00, 542.00}} }, |
| 897 | { 235655816988015ns, {{572.17, 564.86}} }, |
| 898 | { 235655817685000ns, {{572.00, 567.00}} }, |
| 899 | { 235655825981000ns, {{569.00, 595.00}} }, |
| 900 | { 235655833808653ns, {{566.26, 620.60}} }, |
| 901 | { 235655834541000ns, {{566.00, 623.00}} }, |
| 902 | { 235655842893000ns, {{563.00, 649.00}} }, |
| 903 | { 235655842893000ns, {{563.00, 649.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 904 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 905 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 906 | -419.749695); |
| 907 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 908 | -398.303894); |
| 909 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 910 | 3309.016357); |
| 911 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 912 | 3969.099854); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | |
| 916 | TEST_F(VelocityTrackerTest, SailfishFlingDownSlow2) { |
| 917 | // Sailfish - fling down - slow - 2 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 918 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 919 | { 235671152083370ns, {{485.24, 558.28}} }, |
| 920 | { 235671154126000ns, {{485.00, 559.00}} }, |
| 921 | { 235671162497000ns, {{484.00, 566.00}} }, |
| 922 | { 235671168750511ns, {{483.27, 573.29}} }, |
| 923 | { 235671171071000ns, {{483.00, 576.00}} }, |
| 924 | { 235671179390000ns, {{482.00, 588.00}} }, |
| 925 | { 235671185417210ns, {{481.31, 598.98}} }, |
| 926 | { 235671188173000ns, {{481.00, 604.00}} }, |
| 927 | { 235671196371000ns, {{480.00, 624.00}} }, |
| 928 | { 235671202084196ns, {{479.27, 639.98}} }, |
| 929 | { 235671204235000ns, {{479.00, 646.00}} }, |
| 930 | { 235671212554000ns, {{478.00, 673.00}} }, |
| 931 | { 235671219471011ns, {{476.39, 697.12}} }, |
| 932 | { 235671221159000ns, {{476.00, 703.00}} }, |
| 933 | { 235671229592000ns, {{474.00, 734.00}} }, |
| 934 | { 235671236281462ns, {{472.43, 758.38}} }, |
| 935 | { 235671238098000ns, {{472.00, 765.00}} }, |
| 936 | { 235671246532000ns, {{470.00, 799.00}} }, |
| 937 | { 235671246532000ns, {{470.00, 799.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 938 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 939 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 940 | -262.80426); |
| 941 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 942 | -243.665344); |
| 943 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 944 | 4215.682129); |
| 945 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 946 | 4587.986816); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | |
| 950 | TEST_F(VelocityTrackerTest, SailfishFlingDownSlow3) { |
| 951 | // Sailfish - fling down - slow - 3 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 952 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 953 | { 170983201000ns, {{557.00, 533.00}} }, |
| 954 | { 171000668000ns, {{556.00, 534.00}} }, |
| 955 | { 171007359750ns, {{554.73, 535.27}} }, |
| 956 | { 171011197000ns, {{554.00, 536.00}} }, |
| 957 | { 171017660000ns, {{552.00, 540.00}} }, |
| 958 | { 171024201831ns, {{549.97, 544.73}} }, |
| 959 | { 171027333000ns, {{549.00, 547.00}} }, |
| 960 | { 171034603000ns, {{545.00, 557.00}} }, |
| 961 | { 171041043371ns, {{541.98, 567.55}} }, |
| 962 | { 171043147000ns, {{541.00, 571.00}} }, |
| 963 | { 171051052000ns, {{536.00, 586.00}} }, |
| 964 | { 171051052000ns, {{536.00, 586.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 965 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 966 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 967 | -723.413513); |
| 968 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 969 | -651.038452); |
| 970 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 971 | 2091.502441); |
| 972 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 973 | 1934.517456); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | |
| 977 | TEST_F(VelocityTrackerTest, SailfishFlingDownFaster1) { |
| 978 | // Sailfish - fling down - faster - 1 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 979 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 980 | { 235695280333000ns, {{558.00, 451.00}} }, |
| 981 | { 235695283971237ns, {{558.43, 454.45}} }, |
| 982 | { 235695289038000ns, {{559.00, 462.00}} }, |
| 983 | { 235695297388000ns, {{561.00, 478.00}} }, |
| 984 | { 235695300638465ns, {{561.83, 486.25}} }, |
| 985 | { 235695305265000ns, {{563.00, 498.00}} }, |
| 986 | { 235695313591000ns, {{564.00, 521.00}} }, |
| 987 | { 235695317305492ns, {{564.43, 532.68}} }, |
| 988 | { 235695322181000ns, {{565.00, 548.00}} }, |
| 989 | { 235695330709000ns, {{565.00, 577.00}} }, |
| 990 | { 235695333972227ns, {{565.00, 588.10}} }, |
| 991 | { 235695339250000ns, {{565.00, 609.00}} }, |
| 992 | { 235695347839000ns, {{565.00, 642.00}} }, |
| 993 | { 235695351313257ns, {{565.00, 656.18}} }, |
| 994 | { 235695356412000ns, {{565.00, 677.00}} }, |
| 995 | { 235695364899000ns, {{563.00, 710.00}} }, |
| 996 | { 235695368118682ns, {{562.24, 722.52}} }, |
| 997 | { 235695373403000ns, {{564.00, 744.00}} }, |
| 998 | { 235695373403000ns, {{564.00, 744.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 999 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 1000 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 1001 | 4254.639648); |
| 1002 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 1003 | 4698.415039); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | |
| 1007 | TEST_F(VelocityTrackerTest, SailfishFlingDownFaster2) { |
| 1008 | // Sailfish - fling down - faster - 2 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1009 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1010 | { 235709624766000ns, {{535.00, 579.00}} }, |
| 1011 | { 235709642256000ns, {{534.00, 580.00}} }, |
| 1012 | { 235709643350278ns, {{533.94, 580.06}} }, |
| 1013 | { 235709650760000ns, {{532.00, 584.00}} }, |
| 1014 | { 235709658615000ns, {{530.00, 593.00}} }, |
| 1015 | { 235709660170495ns, {{529.60, 594.78}} }, |
| 1016 | { 235709667095000ns, {{527.00, 606.00}} }, |
| 1017 | { 235709675616000ns, {{524.00, 628.00}} }, |
| 1018 | { 235709676983261ns, {{523.52, 631.53}} }, |
| 1019 | { 235709684289000ns, {{521.00, 652.00}} }, |
| 1020 | { 235709692763000ns, {{518.00, 682.00}} }, |
| 1021 | { 235709693804993ns, {{517.63, 685.69}} }, |
| 1022 | { 235709701438000ns, {{515.00, 709.00}} }, |
| 1023 | { 235709709830000ns, {{512.00, 739.00}} }, |
| 1024 | { 235709710626776ns, {{511.72, 741.85}} }, |
| 1025 | { 235709710626776ns, {{511.72, 741.85}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 1026 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 1027 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 1028 | -430.440247); |
| 1029 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 1030 | -447.600311); |
| 1031 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 1032 | 3953.859375); |
| 1033 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 1034 | 4316.155273); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | |
| 1038 | TEST_F(VelocityTrackerTest, SailfishFlingDownFaster3) { |
| 1039 | // Sailfish - fling down - faster - 3 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1040 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1041 | { 235727628927000ns, {{540.00, 440.00}} }, |
| 1042 | { 235727636810000ns, {{537.00, 454.00}} }, |
| 1043 | { 235727646176000ns, {{536.00, 454.00}} }, |
| 1044 | { 235727653586628ns, {{535.12, 456.65}} }, |
| 1045 | { 235727654557000ns, {{535.00, 457.00}} }, |
| 1046 | { 235727663024000ns, {{534.00, 465.00}} }, |
| 1047 | { 235727670410103ns, {{533.04, 479.45}} }, |
| 1048 | { 235727670691000ns, {{533.00, 480.00}} }, |
| 1049 | { 235727679255000ns, {{531.00, 501.00}} }, |
| 1050 | { 235727687233704ns, {{529.09, 526.73}} }, |
| 1051 | { 235727687628000ns, {{529.00, 528.00}} }, |
| 1052 | { 235727696113000ns, {{526.00, 558.00}} }, |
| 1053 | { 235727704057546ns, {{523.18, 588.98}} }, |
| 1054 | { 235727704576000ns, {{523.00, 591.00}} }, |
| 1055 | { 235727713099000ns, {{520.00, 626.00}} }, |
| 1056 | { 235727720880776ns, {{516.33, 655.36}} }, |
| 1057 | { 235727721580000ns, {{516.00, 658.00}} }, |
| 1058 | { 235727721580000ns, {{516.00, 658.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 1059 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 1060 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 1061 | 4484.617676); |
| 1062 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 1063 | 4927.92627); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | |
| 1067 | TEST_F(VelocityTrackerTest, SailfishFlingDownFast1) { |
| 1068 | // Sailfish - fling down - fast - 1 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1069 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1070 | { 235762352849000ns, {{467.00, 286.00}} }, |
| 1071 | { 235762360250000ns, {{443.00, 344.00}} }, |
| 1072 | { 235762362787412ns, {{434.77, 363.89}} }, |
| 1073 | { 235762368807000ns, {{438.00, 359.00}} }, |
| 1074 | { 235762377220000ns, {{425.00, 423.00}} }, |
| 1075 | { 235762379608561ns, {{421.31, 441.17}} }, |
| 1076 | { 235762385698000ns, {{412.00, 528.00}} }, |
| 1077 | { 235762394133000ns, {{406.00, 648.00}} }, |
| 1078 | { 235762396429369ns, {{404.37, 680.67}} }, |
| 1079 | { 235762396429369ns, {{404.37, 680.67}} }, //ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 1080 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 1081 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 1082 | 14227.0224); |
| 1083 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 1084 | 16064.685547); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | |
| 1088 | TEST_F(VelocityTrackerTest, SailfishFlingDownFast2) { |
| 1089 | // Sailfish - fling down - fast - 2 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1090 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1091 | { 235772487188000ns, {{576.00, 204.00}} }, |
| 1092 | { 235772495159000ns, {{553.00, 236.00}} }, |
| 1093 | { 235772503568000ns, {{551.00, 240.00}} }, |
| 1094 | { 235772508192247ns, {{545.55, 254.17}} }, |
| 1095 | { 235772512051000ns, {{541.00, 266.00}} }, |
| 1096 | { 235772520794000ns, {{520.00, 337.00}} }, |
| 1097 | { 235772525015263ns, {{508.92, 394.43}} }, |
| 1098 | { 235772529174000ns, {{498.00, 451.00}} }, |
| 1099 | { 235772537635000ns, {{484.00, 589.00}} }, |
| 1100 | { 235772537635000ns, {{484.00, 589.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 1101 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 1102 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 1103 | 18660.048828); |
| 1104 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 1105 | 16918.439453); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | |
| 1109 | TEST_F(VelocityTrackerTest, SailfishFlingDownFast3) { |
| 1110 | // Sailfish - fling down - fast - 3 |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1111 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1112 | { 507650295000ns, {{628.00, 233.00}} }, |
| 1113 | { 507658234000ns, {{605.00, 269.00}} }, |
| 1114 | { 507666784000ns, {{601.00, 274.00}} }, |
| 1115 | { 507669660483ns, {{599.65, 275.68}} }, |
| 1116 | { 507675427000ns, {{582.00, 308.00}} }, |
| 1117 | { 507683740000ns, {{541.00, 404.00}} }, |
| 1118 | { 507686506238ns, {{527.36, 435.95}} }, |
| 1119 | { 507692220000ns, {{487.00, 581.00}} }, |
| 1120 | { 507700707000ns, {{454.00, 792.00}} }, |
| 1121 | { 507703352649ns, {{443.71, 857.77}} }, |
| 1122 | { 507703352649ns, {{443.71, 857.77}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 1123 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 1124 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 1125 | -4111.8173); |
| 1126 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 1127 | -6388.48877); |
| 1128 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 1129 | 29765.908203); |
| 1130 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 1131 | 28354.796875); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 1132 | } |
| 1133 | |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1134 | /** |
| 1135 | * ================== Multiple pointers ============================================================ |
| 1136 | * |
Yeabkal Wubshit | a15e599 | 2022-09-29 19:00:19 -0700 | [diff] [blame] | 1137 | * Three fingers quickly tap the screen. Since this is a tap, the velocities should be empty. |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1138 | * If the events with POINTER_UP or POINTER_DOWN are not handled correctly (these should not be |
| 1139 | * part of the fitted data), this can cause large velocity values to be reported instead. |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1140 | */ |
Yeabkal Wubshit | 9b4443f | 2023-02-23 23:35:07 -0800 | [diff] [blame] | 1141 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategy_ThreeFingerTap) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1142 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1143 | { 0us, {{1063, 1128}, {NAN, NAN}, {NAN, NAN}} }, |
| 1144 | { 10800us, {{1063, 1128}, {682, 1318}, {NAN, NAN}} }, // POINTER_DOWN |
| 1145 | { 10800us, {{1063, 1128}, {682, 1318}, {397, 1747}} }, // POINTER_DOWN |
| 1146 | { 267300us, {{1063, 1128}, {682, 1318}, {397, 1747}} }, // POINTER_UP |
| 1147 | { 267300us, {{1063, 1128}, {NAN, NAN}, {397, 1747}} }, // POINTER_UP |
| 1148 | { 272700us, {{1063, 1128}, {NAN, NAN}, {NAN, NAN}} }, |
| 1149 | }; |
| 1150 | |
Yeabkal Wubshit | a15e599 | 2022-09-29 19:00:19 -0700 | [diff] [blame] | 1151 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 1152 | std::nullopt); |
| 1153 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 1154 | std::nullopt); |
| 1155 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 1156 | std::nullopt); |
| 1157 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 1158 | std::nullopt); |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | /** |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 1162 | * ================= Pointer liftoff =============================================================== |
| 1163 | */ |
| 1164 | |
| 1165 | /** |
| 1166 | * The last movement of a pointer is always ACTION_POINTER_UP or ACTION_UP. If there's a short delay |
| 1167 | * between the last ACTION_MOVE and the next ACTION_POINTER_UP or ACTION_UP, velocity should not be |
| 1168 | * affected by the liftoff. |
| 1169 | */ |
| 1170 | TEST_F(VelocityTrackerTest, ShortDelayBeforeActionUp) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1171 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 1172 | {0ms, {{10, 0}}}, {10ms, {{20, 0}}}, {20ms, {{30, 0}}}, {30ms, {{30, 0}}}, // ACTION_UP |
| 1173 | }; |
| 1174 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 1175 | 1000); |
| 1176 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, 1000); |
| 1177 | } |
| 1178 | |
| 1179 | /** |
| 1180 | * The last movement of a single pointer is ACTION_UP. If there's a long delay between the last |
Yeabkal Wubshit | a15e599 | 2022-09-29 19:00:19 -0700 | [diff] [blame] | 1181 | * ACTION_MOVE and the final ACTION_UP, velocity should be reported as empty because the pointer |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 1182 | * should be assumed to have stopped. |
| 1183 | */ |
| 1184 | TEST_F(VelocityTrackerTest, LongDelayBeforeActionUp) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1185 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 1186 | {0ms, {{10, 0}}}, |
| 1187 | {10ms, {{20, 0}}}, |
| 1188 | {20ms, {{30, 0}}}, |
| 1189 | {3000ms, {{30, 0}}}, // ACTION_UP |
| 1190 | }; |
Yeabkal Wubshit | a15e599 | 2022-09-29 19:00:19 -0700 | [diff] [blame] | 1191 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 1192 | std::nullopt); |
| 1193 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 1194 | std::nullopt); |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | /** |
| 1198 | * The last movement of a pointer is always ACTION_POINTER_UP or ACTION_UP. If there's a long delay |
| 1199 | * before ACTION_POINTER_UP event, the movement should be assumed to have stopped. |
Yeabkal Wubshit | a15e599 | 2022-09-29 19:00:19 -0700 | [diff] [blame] | 1200 | * The final velocity should be reported as empty for all pointers. |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 1201 | */ |
| 1202 | TEST_F(VelocityTrackerTest, LongDelayBeforeActionPointerUp) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1203 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 1204 | {0ms, {{10, 0}}}, |
| 1205 | {10ms, {{20, 0}, {100, 0}}}, |
| 1206 | {20ms, {{30, 0}, {200, 0}}}, |
| 1207 | {30ms, {{30, 0}, {300, 0}}}, |
| 1208 | {40ms, {{30, 0}, {400, 0}}}, |
| 1209 | {3000ms, {{30, 0}}}, // ACTION_POINTER_UP |
| 1210 | }; |
Yeabkal Wubshit | a15e599 | 2022-09-29 19:00:19 -0700 | [diff] [blame] | 1211 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 1212 | std::nullopt, |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 1213 | /*pointerId*/ 0); |
Yeabkal Wubshit | a15e599 | 2022-09-29 19:00:19 -0700 | [diff] [blame] | 1214 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 1215 | std::nullopt, |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 1216 | /*pointerId*/ 0); |
Yeabkal Wubshit | a15e599 | 2022-09-29 19:00:19 -0700 | [diff] [blame] | 1217 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 1218 | std::nullopt, |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 1219 | /*pointerId*/ 1); |
Yeabkal Wubshit | a15e599 | 2022-09-29 19:00:19 -0700 | [diff] [blame] | 1220 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 1221 | std::nullopt, |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 1222 | /*pointerId*/ 1); |
| 1223 | } |
| 1224 | |
| 1225 | /** |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1226 | * ================== Tests for least squares fitting ============================================== |
| 1227 | * |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1228 | * Special care must be taken when constructing tests for LeastSquaresVelocityTrackerStrategy |
Yeabkal Wubshit | 9b4443f | 2023-02-23 23:35:07 -0800 | [diff] [blame] | 1229 | * getVelocity function. In particular: |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1230 | * - inside the function, time gets converted from nanoseconds to seconds |
| 1231 | * before being used in the fit. |
| 1232 | * - any values that are older than 100 ms are being discarded. |
| 1233 | * - the newest time gets subtracted from all of the other times before being used in the fit. |
| 1234 | * So these tests have to be designed with those limitations in mind. |
| 1235 | * |
| 1236 | * General approach for the tests below: |
| 1237 | * We only used timestamps in milliseconds, 0 ms, 1 ms, and 2 ms, to be sure that |
| 1238 | * we are well within the HORIZON range. |
| 1239 | * When specifying the expected values of the coefficients, we treat the x values as if |
| 1240 | * they were in ms. Then, to adjust for the time units, the coefficients get progressively |
| 1241 | * multiplied by powers of 1E3. |
| 1242 | * For example: |
| 1243 | * data: t(ms), x |
| 1244 | * 1 ms, 1 |
| 1245 | * 2 ms, 4 |
| 1246 | * 3 ms, 9 |
| 1247 | * The coefficients are (0, 0, 1). |
| 1248 | * In the test, we would convert these coefficients to (0*(1E3)^0, 0*(1E3)^1, 1*(1E3)^2). |
| 1249 | */ |
Yeabkal Wubshit | 9b4443f | 2023-02-23 23:35:07 -0800 | [diff] [blame] | 1250 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategy_Constant) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1251 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1252 | { 0ms, {{1, 1}} }, // 0 s |
| 1253 | { 1ms, {{1, 1}} }, // 0.001 s |
| 1254 | { 2ms, {{1, 1}} }, // 0.002 s |
| 1255 | { 2ms, {{1, 1}} }, // ACTION_UP |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1256 | }; |
| 1257 | // The data used for the fit will be as follows: |
| 1258 | // time(s), position |
| 1259 | // -0.002, 1 |
| 1260 | // -0.001, 1 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1261 | // -0.ms, 1 |
Yeabkal Wubshit | 9b4443f | 2023-02-23 23:35:07 -0800 | [diff] [blame] | 1262 | computeAndCheckQuadraticVelocity(motions, 0); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | /* |
| 1266 | * Straight line y = x :: the constant and quadratic coefficients are zero. |
| 1267 | */ |
Yeabkal Wubshit | 9b4443f | 2023-02-23 23:35:07 -0800 | [diff] [blame] | 1268 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategy_Linear) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1269 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1270 | { 0ms, {{-2, -2}} }, |
| 1271 | { 1ms, {{-1, -1}} }, |
| 1272 | { 2ms, {{-0, -0}} }, |
| 1273 | { 2ms, {{-0, -0}} }, // ACTION_UP |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1274 | }; |
| 1275 | // The data used for the fit will be as follows: |
| 1276 | // time(s), position |
| 1277 | // -0.002, -2 |
| 1278 | // -0.001, -1 |
| 1279 | // -0.000, 0 |
Yeabkal Wubshit | 9b4443f | 2023-02-23 23:35:07 -0800 | [diff] [blame] | 1280 | computeAndCheckQuadraticVelocity(motions, 1E3); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | /* |
| 1284 | * Parabola |
| 1285 | */ |
Yeabkal Wubshit | 9b4443f | 2023-02-23 23:35:07 -0800 | [diff] [blame] | 1286 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategy_Parabolic) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1287 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1288 | { 0ms, {{1, 1}} }, |
| 1289 | { 1ms, {{4, 4}} }, |
| 1290 | { 2ms, {{8, 8}} }, |
| 1291 | { 2ms, {{8, 8}} }, // ACTION_UP |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1292 | }; |
| 1293 | // The data used for the fit will be as follows: |
| 1294 | // time(s), position |
| 1295 | // -0.002, 1 |
| 1296 | // -0.001, 4 |
| 1297 | // -0.000, 8 |
Yeabkal Wubshit | 9b4443f | 2023-02-23 23:35:07 -0800 | [diff] [blame] | 1298 | computeAndCheckQuadraticVelocity(motions, 4.5E3); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | /* |
| 1302 | * Parabola |
| 1303 | */ |
Yeabkal Wubshit | 9b4443f | 2023-02-23 23:35:07 -0800 | [diff] [blame] | 1304 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategy_Parabolic2) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1305 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1306 | { 0ms, {{1, 1}} }, |
| 1307 | { 1ms, {{4, 4}} }, |
| 1308 | { 2ms, {{9, 9}} }, |
| 1309 | { 2ms, {{9, 9}} }, // ACTION_UP |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1310 | }; |
| 1311 | // The data used for the fit will be as follows: |
| 1312 | // time(s), position |
| 1313 | // -0.002, 1 |
| 1314 | // -0.001, 4 |
| 1315 | // -0.000, 9 |
Yeabkal Wubshit | 9b4443f | 2023-02-23 23:35:07 -0800 | [diff] [blame] | 1316 | computeAndCheckQuadraticVelocity(motions, 6E3); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | /* |
| 1320 | * Parabola :: y = x^2 :: the constant and linear coefficients are zero. |
| 1321 | */ |
Yeabkal Wubshit | 9b4443f | 2023-02-23 23:35:07 -0800 | [diff] [blame] | 1322 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategy_Parabolic3) { |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1323 | std::vector<PlanarMotionEventEntry> motions = { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1324 | { 0ms, {{4, 4}} }, |
| 1325 | { 1ms, {{1, 1}} }, |
| 1326 | { 2ms, {{0, 0}} }, |
| 1327 | { 2ms, {{0, 0}} }, // ACTION_UP |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1328 | }; |
| 1329 | // The data used for the fit will be as follows: |
| 1330 | // time(s), position |
| 1331 | // -0.002, 4 |
| 1332 | // -0.001, 1 |
| 1333 | // -0.000, 0 |
Yeabkal Wubshit | 9b4443f | 2023-02-23 23:35:07 -0800 | [diff] [blame] | 1334 | computeAndCheckQuadraticVelocity(motions, 0E3); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1335 | } |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 1336 | |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1337 | // Recorded by hand on sailfish, but only the diffs are taken to test cumulative axis velocity. |
| 1338 | TEST_F(VelocityTrackerTest, AxisScrollVelocity) { |
| 1339 | std::vector<std::pair<std::chrono::nanoseconds, float>> motions = { |
| 1340 | {235089067457000ns, 0.00}, {235089084684000ns, -1.00}, {235089093349000ns, 0.00}, |
| 1341 | {235089095677625ns, 0.00}, {235089101859000ns, 0.00}, {235089110378000ns, 0.00}, |
| 1342 | {235089112497111ns, 0.25}, {235089118760000ns, 1.75}, {235089126686000ns, 4.00}, |
| 1343 | {235089129316820ns, 1.33}, {235089135199000ns, 3.67}, {235089144297000ns, 6.00}, |
| 1344 | {235089146136443ns, 1.21}, {235089152923000ns, 5.79}, {235089160784000ns, 6.00}, |
| 1345 | {235089162955851ns, 1.66}, |
| 1346 | }; |
| 1347 | |
| 1348 | computeAndCheckAxisScrollVelocity(VelocityTracker::Strategy::IMPULSE, motions, {764.345703}); |
| 1349 | } |
| 1350 | |
| 1351 | // --------------- Recorded by hand on a Wear OS device using a rotating side button --------------- |
| 1352 | TEST_F(VelocityTrackerTest, AxisScrollVelocity_ScrollDown) { |
| 1353 | std::vector<std::pair<std::chrono::nanoseconds, float>> motions = { |
| 1354 | {224598065152ns, -0.050100}, {224621871104ns, -0.133600}, {224645464064ns, -0.551100}, |
| 1355 | {224669171712ns, -0.801600}, {224687063040ns, -1.035400}, {224706691072ns, -0.484300}, |
| 1356 | {224738213888ns, -0.334000}, {224754401280ns, -0.083500}, |
| 1357 | }; |
| 1358 | |
| 1359 | computeAndCheckAxisScrollVelocity(VelocityTracker::Strategy::IMPULSE, motions, {-27.86}); |
| 1360 | } |
| 1361 | |
| 1362 | TEST_F(VelocityTrackerTest, AxisScrollVelocity_ScrollUp) { |
| 1363 | std::vector<std::pair<std::chrono::nanoseconds, float>> motions = { |
| 1364 | {269606010880ns, 0.050100}, {269626064896ns, 0.217100}, {269641973760ns, 0.267200}, |
| 1365 | {269658079232ns, 0.267200}, {269674217472ns, 0.267200}, {269690683392ns, 0.367400}, |
| 1366 | {269706133504ns, 0.551100}, {269722173440ns, 0.501000}, |
| 1367 | }; |
| 1368 | |
| 1369 | computeAndCheckAxisScrollVelocity(VelocityTracker::Strategy::IMPULSE, motions, {31.92}); |
| 1370 | } |
| 1371 | |
| 1372 | TEST_F(VelocityTrackerTest, AxisScrollVelocity_ScrollDown_ThenUp_ThenDown) { |
| 1373 | std::vector<std::pair<std::chrono::nanoseconds, float>> motions = { |
| 1374 | {2580534001664ns, -0.033400}, {2580549992448ns, -0.133600}, |
| 1375 | {2580566769664ns, -0.250500}, {2580581974016ns, -0.183700}, |
| 1376 | {2580597964800ns, -0.267200}, {2580613955584ns, -0.551100}, |
| 1377 | {2580635189248ns, -0.601200}, {2580661927936ns, -0.450900}, |
| 1378 | {2580683161600ns, -0.417500}, {2580705705984ns, -0.150300}, |
| 1379 | {2580722745344ns, -0.016700}, {2580786446336ns, 0.050100}, |
| 1380 | {2580801912832ns, 0.150300}, {2580822360064ns, 0.300600}, |
| 1381 | {2580838088704ns, 0.300600}, {2580854341632ns, 0.400800}, |
| 1382 | {2580869808128ns, 0.517700}, {2580886061056ns, 0.501000}, |
| 1383 | {2580905984000ns, 0.350700}, {2580921974784ns, 0.350700}, |
| 1384 | {2580937965568ns, 0.066800}, {2580974665728ns, 0.016700}, |
| 1385 | {2581034434560ns, -0.066800}, {2581049901056ns, -0.116900}, |
| 1386 | {2581070610432ns, -0.317300}, {2581086076928ns, -0.200400}, |
| 1387 | {2581101805568ns, -0.233800}, {2581118058496ns, -0.417500}, |
| 1388 | {2581134049280ns, -0.417500}, {2581150040064ns, -0.367400}, |
| 1389 | {2581166030848ns, -0.267200}, {2581181759488ns, -0.150300}, |
| 1390 | {2581199847424ns, -0.066800}, |
| 1391 | }; |
| 1392 | |
| 1393 | computeAndCheckAxisScrollVelocity(VelocityTracker::Strategy::IMPULSE, motions, {-9.73}); |
| 1394 | } |
| 1395 | |
| 1396 | // ------------------------------- Hand generated test cases --------------------------------------- |
Yeabkal Wubshit | 871cc8a | 2022-09-26 17:46:28 -0700 | [diff] [blame] | 1397 | TEST_F(VelocityTrackerTest, TestDefaultStrategyForAxisScroll) { |
| 1398 | std::vector<std::pair<std::chrono::nanoseconds, float>> motions = { |
| 1399 | {10ms, 20}, |
| 1400 | {20ms, 25}, |
| 1401 | {30ms, 50}, |
| 1402 | {40ms, 100}, |
| 1403 | }; |
| 1404 | |
Siarhei Vishniakou | 318005c | 2023-10-24 18:05:59 -0700 | [diff] [blame] | 1405 | std::vector<MotionEvent> events = createAxisScrollMotionEventStream(motions); |
| 1406 | EXPECT_EQ(computeVelocity(VelocityTracker::Strategy::IMPULSE, events, |
Yeabkal Wubshit | 871cc8a | 2022-09-26 17:46:28 -0700 | [diff] [blame] | 1407 | AMOTION_EVENT_AXIS_SCROLL), |
Siarhei Vishniakou | 318005c | 2023-10-24 18:05:59 -0700 | [diff] [blame] | 1408 | computeVelocity(VelocityTracker::Strategy::DEFAULT, events, |
Yeabkal Wubshit | 871cc8a | 2022-09-26 17:46:28 -0700 | [diff] [blame] | 1409 | AMOTION_EVENT_AXIS_SCROLL)); |
| 1410 | } |
| 1411 | |
Yeabkal Wubshit | 0bb5e59 | 2022-09-14 01:22:28 -0700 | [diff] [blame] | 1412 | TEST_F(VelocityTrackerTest, AxisScrollVelocity_SimilarDifferentialValues) { |
| 1413 | std::vector<std::pair<std::chrono::nanoseconds, float>> motions = {{1ns, 2.12}, {3ns, 2.12}, |
| 1414 | {7ns, 2.12}, {8ns, 2.12}, |
| 1415 | {15ns, 2.12}, {18ns, 2.12}}; |
| 1416 | |
| 1417 | computeAndCheckAxisScrollVelocity(VelocityTracker::Strategy::IMPULSE, motions, {1690236059.86}); |
| 1418 | } |
| 1419 | |
| 1420 | TEST_F(VelocityTrackerTest, AxisScrollVelocity_OnlyTwoValues) { |
| 1421 | std::vector<std::pair<std::chrono::nanoseconds, float>> motions = {{1ms, 5}, {2ms, 10}}; |
| 1422 | |
| 1423 | computeAndCheckAxisScrollVelocity(VelocityTracker::Strategy::IMPULSE, motions, {10000}); |
| 1424 | } |
| 1425 | |
| 1426 | TEST_F(VelocityTrackerTest, AxisScrollVelocity_ConstantVelocity) { |
| 1427 | std::vector<std::pair<std::chrono::nanoseconds, float>> motions = {{1ms, 20}, {2ms, 20}, |
| 1428 | {3ms, 20}, {4ms, 20}, |
| 1429 | {5ms, 20}, {6ms, 20}}; |
| 1430 | |
| 1431 | computeAndCheckAxisScrollVelocity(VelocityTracker::Strategy::IMPULSE, motions, {20000}); |
| 1432 | } |
| 1433 | |
| 1434 | TEST_F(VelocityTrackerTest, AxisScrollVelocity_NoMotion) { |
| 1435 | std::vector<std::pair<std::chrono::nanoseconds, float>> motions = {{1ns, 0}, {2ns, 0}, |
| 1436 | {3ns, 0}, {4ns, 0}, |
| 1437 | {5ns, 0}, {6ns, 0}}; |
| 1438 | |
| 1439 | computeAndCheckAxisScrollVelocity(VelocityTracker::Strategy::IMPULSE, motions, {0}); |
| 1440 | } |
| 1441 | |
| 1442 | TEST_F(VelocityTrackerTest, AxisScrollVelocity_NoData) { |
| 1443 | std::vector<std::pair<std::chrono::nanoseconds, float>> motions = {}; |
| 1444 | |
| 1445 | computeAndCheckAxisScrollVelocity(VelocityTracker::Strategy::IMPULSE, motions, std::nullopt); |
| 1446 | } |
| 1447 | |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 1448 | } // namespace android |