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> |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 27 | #include <gui/constants.h> |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 28 | #include <input/VelocityTracker.h> |
| 29 | |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 30 | using std::literals::chrono_literals::operator""ms; |
| 31 | using std::literals::chrono_literals::operator""ns; |
| 32 | using std::literals::chrono_literals::operator""us; |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 33 | using android::base::StringPrintf; |
| 34 | |
| 35 | namespace android { |
| 36 | |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 37 | constexpr int32_t DISPLAY_ID = ADISPLAY_ID_DEFAULT; // default display id |
| 38 | |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 39 | constexpr int32_t DEFAULT_POINTER_ID = 0; // pointer ID used for manually defined tests |
| 40 | |
| 41 | // velocity must be in the range (1-tol)*EV <= velocity <= (1+tol)*EV |
| 42 | // here EV = expected value, tol = VELOCITY_TOLERANCE |
| 43 | constexpr float VELOCITY_TOLERANCE = 0.2; |
| 44 | |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 45 | // estimate coefficients must be within 0.001% of the target value |
| 46 | constexpr float COEFFICIENT_TOLERANCE = 0.00001; |
| 47 | |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 48 | // --- VelocityTrackerTest --- |
| 49 | class VelocityTrackerTest : public testing::Test { }; |
| 50 | |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 51 | /* |
| 52 | * Similar to EXPECT_NEAR, but ensures that the difference between the two float values |
| 53 | * is at most a certain fraction of the target value. |
| 54 | * If fraction is zero, require exact match. |
| 55 | */ |
| 56 | static void EXPECT_NEAR_BY_FRACTION(float actual, float target, float fraction) { |
| 57 | float tolerance = fabsf(target * fraction); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 58 | |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 59 | if (target == 0 && fraction != 0) { |
| 60 | // If target is zero, this would force actual == target, which is too harsh. |
| 61 | // Relax this requirement a little. The value is determined empirically from the |
| 62 | // coefficients computed by the quadratic least squares algorithms. |
| 63 | tolerance = 1E-6; |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 64 | } |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 65 | EXPECT_NEAR(actual, target, tolerance); |
| 66 | } |
| 67 | |
| 68 | static void checkVelocity(float Vactual, float Vtarget) { |
| 69 | EXPECT_NEAR_BY_FRACTION(Vactual, Vtarget, VELOCITY_TOLERANCE); |
| 70 | } |
| 71 | |
| 72 | static void checkCoefficient(float actual, float target) { |
| 73 | EXPECT_NEAR_BY_FRACTION(actual, target, COEFFICIENT_TOLERANCE); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 76 | struct Position { |
Siarhei Vishniakou | 01ca486 | 2019-03-06 13:22:13 -0800 | [diff] [blame] | 77 | float x; |
| 78 | float y; |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
| 81 | * If both values are NAN, then this is considered to be an empty entry (no pointer data). |
| 82 | * If only one of the values is NAN, this is still a valid entry, |
| 83 | * because we may only care about a single axis. |
| 84 | */ |
| 85 | bool isValid() const { |
| 86 | return !(isnan(x) && isnan(y)); |
| 87 | } |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 88 | }; |
| 89 | |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 90 | struct MotionEventEntry { |
| 91 | std::chrono::nanoseconds eventTime; |
| 92 | std::vector<Position> positions; |
| 93 | }; |
| 94 | |
| 95 | static BitSet32 getValidPointers(const std::vector<Position>& positions) { |
| 96 | BitSet32 pointers; |
| 97 | for (size_t i = 0; i < positions.size(); i++) { |
| 98 | if (positions[i].isValid()) { |
| 99 | pointers.markBit(i); |
| 100 | } |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 101 | } |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 102 | return pointers; |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 103 | } |
| 104 | |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 105 | static uint32_t getChangingPointerId(BitSet32 pointers, BitSet32 otherPointers) { |
| 106 | BitSet32 difference(pointers.value ^ otherPointers.value); |
| 107 | uint32_t pointerId = difference.clearFirstMarkedBit(); |
| 108 | EXPECT_EQ(0U, difference.value) << "Only 1 pointer can enter or leave at a time"; |
| 109 | return pointerId; |
| 110 | } |
| 111 | |
| 112 | static int32_t resolveAction(const std::vector<Position>& lastPositions, |
| 113 | const std::vector<Position>& currentPositions, |
| 114 | const std::vector<Position>& nextPositions) { |
| 115 | BitSet32 pointers = getValidPointers(currentPositions); |
| 116 | const uint32_t pointerCount = pointers.count(); |
| 117 | |
| 118 | BitSet32 lastPointers = getValidPointers(lastPositions); |
| 119 | const uint32_t lastPointerCount = lastPointers.count(); |
| 120 | if (lastPointerCount < pointerCount) { |
| 121 | // A new pointer is down |
| 122 | uint32_t pointerId = getChangingPointerId(pointers, lastPointers); |
| 123 | return AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 124 | (pointerId << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); |
| 125 | } |
| 126 | |
| 127 | BitSet32 nextPointers = getValidPointers(nextPositions); |
| 128 | const uint32_t nextPointerCount = nextPointers.count(); |
| 129 | if (pointerCount > nextPointerCount) { |
| 130 | // An existing pointer is leaving |
| 131 | uint32_t pointerId = getChangingPointerId(pointers, nextPointers); |
| 132 | return AMOTION_EVENT_ACTION_POINTER_UP | |
| 133 | (pointerId << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); |
| 134 | } |
| 135 | |
| 136 | return AMOTION_EVENT_ACTION_MOVE; |
| 137 | } |
| 138 | |
| 139 | static std::vector<MotionEvent> createMotionEventStream( |
| 140 | const std::vector<MotionEventEntry>& motions) { |
| 141 | if (motions.empty()) { |
| 142 | ADD_FAILURE() << "Need at least 1 sample to create a MotionEvent. Received empty vector."; |
| 143 | } |
| 144 | |
| 145 | std::vector<MotionEvent> events; |
| 146 | for (size_t i = 0; i < motions.size(); i++) { |
| 147 | const MotionEventEntry& entry = motions[i]; |
| 148 | BitSet32 pointers = getValidPointers(entry.positions); |
| 149 | const uint32_t pointerCount = pointers.count(); |
| 150 | |
| 151 | int32_t action; |
| 152 | if (i == 0) { |
| 153 | action = AMOTION_EVENT_ACTION_DOWN; |
| 154 | EXPECT_EQ(1U, pointerCount) << "First event should only have 1 pointer"; |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 155 | } else if ((i == motions.size() - 1) && pointerCount == 1) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 156 | action = AMOTION_EVENT_ACTION_UP; |
| 157 | } else { |
| 158 | const MotionEventEntry& previousEntry = motions[i-1]; |
| 159 | const MotionEventEntry& nextEntry = motions[i+1]; |
| 160 | action = resolveAction(previousEntry.positions, entry.positions, nextEntry.positions); |
| 161 | } |
| 162 | |
| 163 | PointerCoords coords[pointerCount]; |
| 164 | PointerProperties properties[pointerCount]; |
| 165 | uint32_t pointerIndex = 0; |
| 166 | while(!pointers.isEmpty()) { |
| 167 | uint32_t pointerId = pointers.clearFirstMarkedBit(); |
| 168 | |
| 169 | coords[pointerIndex].clear(); |
| 170 | // We are treating column positions as pointerId |
| 171 | EXPECT_TRUE(entry.positions[pointerId].isValid()) << |
| 172 | "The entry at pointerId must be valid"; |
| 173 | coords[pointerIndex].setAxisValue(AMOTION_EVENT_AXIS_X, entry.positions[pointerId].x); |
| 174 | coords[pointerIndex].setAxisValue(AMOTION_EVENT_AXIS_Y, entry.positions[pointerId].y); |
| 175 | |
| 176 | properties[pointerIndex].id = pointerId; |
| 177 | properties[pointerIndex].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; |
| 178 | pointerIndex++; |
| 179 | } |
| 180 | EXPECT_EQ(pointerIndex, pointerCount); |
| 181 | |
| 182 | MotionEvent event; |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 183 | ui::Transform identityTransform; |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 184 | event.initialize(InputEvent::nextId(), 0 /*deviceId*/, AINPUT_SOURCE_TOUCHSCREEN, |
| 185 | DISPLAY_ID, INVALID_HMAC, action, 0 /*actionButton*/, 0 /*flags*/, |
| 186 | AMOTION_EVENT_EDGE_FLAG_NONE, AMETA_NONE, 0 /*buttonState*/, |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 187 | MotionClassification::NONE, identityTransform, 0 /*xPrecision*/, |
| 188 | 0 /*yPrecision*/, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 189 | AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform, 0 /*downTime*/, |
Evan Rosky | 0957669 | 2021-07-01 12:22:09 -0700 | [diff] [blame] | 190 | entry.eventTime.count(), pointerCount, properties, coords); |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 191 | |
| 192 | events.emplace_back(event); |
| 193 | } |
| 194 | |
| 195 | return events; |
| 196 | } |
| 197 | |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 198 | static void computeAndCheckVelocity(const VelocityTracker::Strategy strategy, |
| 199 | const std::vector<MotionEventEntry>& motions, int32_t axis, |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 200 | float targetVelocity, uint32_t pointerId = DEFAULT_POINTER_ID) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 201 | VelocityTracker vt(strategy); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 202 | |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 203 | std::vector<MotionEvent> events = createMotionEventStream(motions); |
| 204 | for (MotionEvent event : events) { |
| 205 | vt.addMovement(&event); |
| 206 | } |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 207 | |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 208 | checkVelocity(vt.getVelocity(axis, pointerId).value_or(0), targetVelocity); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 209 | } |
| 210 | |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 211 | static void computeAndCheckQuadraticEstimate(const std::vector<MotionEventEntry>& motions, |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 212 | const std::array<float, 3>& coefficients) { |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 213 | VelocityTracker vt(VelocityTracker::Strategy::LSQ2); |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 214 | std::vector<MotionEvent> events = createMotionEventStream(motions); |
| 215 | for (MotionEvent event : events) { |
| 216 | vt.addMovement(&event); |
| 217 | } |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 218 | VelocityTracker::Estimator estimatorX; |
| 219 | VelocityTracker::Estimator estimatorY; |
| 220 | EXPECT_TRUE(vt.getEstimator(AMOTION_EVENT_AXIS_X, 0, &estimatorX)); |
| 221 | EXPECT_TRUE(vt.getEstimator(AMOTION_EVENT_AXIS_Y, 0, &estimatorY)); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 222 | for (size_t i = 0; i< coefficients.size(); i++) { |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 223 | checkCoefficient(estimatorX.coeff[i], coefficients[i]); |
| 224 | checkCoefficient(estimatorY.coeff[i], coefficients[i]); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 228 | /* |
| 229 | * ================== VelocityTracker tests generated manually ===================================== |
| 230 | */ |
Yeabkal Wubshit | 384ab0f | 2022-09-09 16:39:18 +0000 | [diff] [blame] | 231 | TEST_F(VelocityTrackerTest, TestComputedVelocity) { |
| 232 | VelocityTracker::ComputedVelocity computedVelocity; |
| 233 | |
| 234 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_X, 0 /*id*/, 200 /*velocity*/); |
| 235 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_X, 26U /*id*/, 400 /*velocity*/); |
| 236 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_X, 27U /*id*/, 650 /*velocity*/); |
| 237 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_X, MAX_POINTER_ID, 750 /*velocity*/); |
| 238 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_Y, 0 /*id*/, 1000 /*velocity*/); |
| 239 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_Y, 26U /*id*/, 2000 /*velocity*/); |
| 240 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_Y, 27U /*id*/, 3000 /*velocity*/); |
| 241 | computedVelocity.addVelocity(AMOTION_EVENT_AXIS_Y, MAX_POINTER_ID, 4000 /*velocity*/); |
| 242 | |
| 243 | // Check the axes/indices with velocity. |
| 244 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, 0U /*id*/)), 200); |
| 245 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, 26U /*id*/)), 400); |
| 246 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, 27U /*id*/)), 650); |
| 247 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, MAX_POINTER_ID)), 750); |
| 248 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, 0U /*id*/)), 1000); |
| 249 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, 26U /*id*/)), 2000); |
| 250 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, 27U /*id*/)), 3000); |
| 251 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, MAX_POINTER_ID)), 4000); |
| 252 | for (uint32_t id = 0; id <= MAX_POINTER_ID; id++) { |
| 253 | // Since no data was added for AXIS_SCROLL, expect empty value for the axis for any id. |
| 254 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_SCROLL, id)) |
| 255 | << "Empty scroll data expected at id=" << id; |
| 256 | if (id == 0 || id == 26U || id == 27U || id == MAX_POINTER_ID) { |
| 257 | // Already checked above; continue. |
| 258 | continue; |
| 259 | } |
| 260 | // No data was added to X/Y for this id, expect empty value. |
| 261 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, id)) |
| 262 | << "Empty X data expected at id=" << id; |
| 263 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, id)) |
| 264 | << "Empty Y data expected at id=" << id; |
| 265 | } |
| 266 | // Out-of-bounds ids should given empty values. |
| 267 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, -1)); |
| 268 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, MAX_POINTER_ID + 1)); |
| 269 | } |
| 270 | |
| 271 | TEST_F(VelocityTrackerTest, TestGetComputedVelocity) { |
| 272 | std::vector<MotionEventEntry> motions = { |
| 273 | {235089067457000ns, {{528.00, 0}}}, {235089084684000ns, {{527.00, 0}}}, |
| 274 | {235089093349000ns, {{527.00, 0}}}, {235089095677625ns, {{527.00, 0}}}, |
| 275 | {235089101859000ns, {{527.00, 0}}}, {235089110378000ns, {{528.00, 0}}}, |
| 276 | {235089112497111ns, {{528.25, 0}}}, {235089118760000ns, {{531.00, 0}}}, |
| 277 | {235089126686000ns, {{535.00, 0}}}, {235089129316820ns, {{536.33, 0}}}, |
| 278 | {235089135199000ns, {{540.00, 0}}}, {235089144297000ns, {{546.00, 0}}}, |
| 279 | {235089146136443ns, {{547.21, 0}}}, {235089152923000ns, {{553.00, 0}}}, |
| 280 | {235089160784000ns, {{559.00, 0}}}, {235089162955851ns, {{560.66, 0}}}, |
| 281 | {235089162955851ns, {{560.66, 0}}}, // ACTION_UP |
| 282 | }; |
| 283 | VelocityTracker vt(VelocityTracker::Strategy::IMPULSE); |
| 284 | std::vector<MotionEvent> events = createMotionEventStream(motions); |
| 285 | for (const MotionEvent& event : events) { |
| 286 | vt.addMovement(&event); |
| 287 | } |
| 288 | |
| 289 | float maxFloat = std::numeric_limits<float>::max(); |
| 290 | VelocityTracker::ComputedVelocity computedVelocity; |
| 291 | computedVelocity = vt.getComputedVelocity(1000 /* units */, maxFloat); |
| 292 | checkVelocity(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, DEFAULT_POINTER_ID)), |
| 293 | 764.345703); |
| 294 | |
| 295 | // Expect X velocity to be scaled with respective to provided units. |
| 296 | computedVelocity = vt.getComputedVelocity(1000000 /* units */, maxFloat); |
| 297 | checkVelocity(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, DEFAULT_POINTER_ID)), |
| 298 | 764345.703); |
| 299 | |
| 300 | // Expect X velocity to be clamped by provided max velocity. |
| 301 | computedVelocity = vt.getComputedVelocity(1000000 /* units */, 1000); |
| 302 | checkVelocity(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, DEFAULT_POINTER_ID)), 1000); |
| 303 | |
| 304 | // All 0 data for Y; expect 0 velocity. |
| 305 | EXPECT_EQ(*(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, DEFAULT_POINTER_ID)), 0); |
| 306 | |
| 307 | // No data for scroll-axis; expect empty velocity. |
| 308 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_SCROLL, DEFAULT_POINTER_ID)); |
| 309 | } |
| 310 | |
Yeabkal Wubshit | 47ff708 | 2022-09-10 23:09:15 -0700 | [diff] [blame^] | 311 | TEST_F(VelocityTrackerTest, TestApiInteractionsWithNoMotionEvents) { |
| 312 | VelocityTracker vt(VelocityTracker::Strategy::DEFAULT); |
| 313 | |
| 314 | EXPECT_FALSE(vt.getVelocity(AMOTION_EVENT_AXIS_X, DEFAULT_POINTER_ID)); |
| 315 | |
| 316 | VelocityTracker::Estimator estimator; |
| 317 | EXPECT_FALSE(vt.getEstimator(AMOTION_EVENT_AXIS_X, DEFAULT_POINTER_ID, &estimator)); |
| 318 | |
| 319 | VelocityTracker::ComputedVelocity computedVelocity = vt.getComputedVelocity(1000, 1000); |
| 320 | for (uint32_t id = 0; id <= MAX_POINTER_ID; id++) { |
| 321 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_X, id)); |
| 322 | EXPECT_FALSE(computedVelocity.getVelocity(AMOTION_EVENT_AXIS_Y, id)); |
| 323 | } |
| 324 | |
| 325 | EXPECT_EQ(-1, vt.getActivePointerId()); |
| 326 | |
| 327 | // Make sure that the clearing functions execute without an issue. |
| 328 | vt.clearPointers(BitSet32(7U)); |
| 329 | vt.clear(); |
| 330 | } |
| 331 | |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 332 | TEST_F(VelocityTrackerTest, ThreePointsPositiveVelocityTest) { |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 333 | // Same coordinate is reported 2 times in a row |
| 334 | // It is difficult to determine the correct answer here, but at least the direction |
| 335 | // of the reported velocity should be positive. |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 336 | std::vector<MotionEventEntry> motions = { |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 337 | {0ms, {{273, 0}}}, |
| 338 | {12585us, {{293, 0}}}, |
| 339 | {14730us, {{293, 0}}}, |
| 340 | {14730us, {{293, 0}}}, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 341 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 342 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 343 | 1600); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | TEST_F(VelocityTrackerTest, ThreePointsZeroVelocityTest) { |
| 347 | // Same coordinate is reported 3 times in a row |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 348 | std::vector<MotionEventEntry> motions = { |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 349 | {0ms, {{293, 0}}}, |
| 350 | {6132us, {{293, 0}}}, |
| 351 | {11283us, {{293, 0}}}, |
| 352 | {11283us, {{293, 0}}}, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 353 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 354 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, 0); |
| 355 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, 0); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | TEST_F(VelocityTrackerTest, ThreePointsLinearVelocityTest) { |
| 359 | // Fixed velocity at 5 points per 10 milliseconds |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 360 | std::vector<MotionEventEntry> motions = { |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 361 | {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] | 362 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 363 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, 500); |
| 364 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, 500); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | |
| 368 | /** |
| 369 | * ================== VelocityTracker tests generated by recording real events ===================== |
| 370 | * |
| 371 | * To add a test, record the input coordinates and event times to all calls |
| 372 | * to void VelocityTracker::addMovement(const MotionEvent* event). |
| 373 | * Also record all calls to VelocityTracker::clear(). |
| 374 | * Finally, record the output of VelocityTracker::getVelocity(...) |
| 375 | * This will give you the necessary data to create a new test. |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 376 | * |
| 377 | * Another good way to generate this data is to use 'dumpsys input' just after the event has |
| 378 | * occurred. |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 379 | */ |
| 380 | |
| 381 | // --------------- Recorded by hand on swordfish --------------------------------------------------- |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 382 | TEST_F(VelocityTrackerTest, SwordfishFlingDown) { |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 383 | // Recording of a fling on Swordfish that could cause a fling in the wrong direction |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 384 | std::vector<MotionEventEntry> motions = { |
| 385 | { 0ms, {{271, 96}} }, |
| 386 | { 16071042ns, {{269.786346, 106.922775}} }, |
| 387 | { 35648403ns, {{267.983063, 156.660034}} }, |
| 388 | { 52313925ns, {{262.638397, 220.339081}} }, |
| 389 | { 68976522ns, {{266.138824, 331.581116}} }, |
| 390 | { 85639375ns, {{274.79245, 428.113159}} }, |
| 391 | { 96948871ns, {{274.79245, 428.113159}} }, |
| 392 | { 96948871ns, {{274.79245, 428.113159}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 393 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 394 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 395 | 623.577637); |
| 396 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 397 | 5970.7309); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | // --------------- Recorded by hand on sailfish, generated by a script ----------------------------- |
| 401 | // For some of these tests, the X-direction velocity checking has been removed, because the lsq2 |
| 402 | // and the impulse VelocityTrackerStrategies did not agree within 20%. |
| 403 | // Since the flings were recorded in the Y-direction, the intentional user action should only |
| 404 | // be relevant for the Y axis. |
| 405 | // There have been also cases where lsq2 and impulse disagreed more than 20% in the Y-direction. |
| 406 | // Those recordings have been discarded because we didn't feel one strategy's interpretation was |
| 407 | // more correct than another's but didn't want to increase the tolerance for the entire test suite. |
| 408 | // |
| 409 | // There are 18 tests total below: 9 in the positive Y direction and 9 in the opposite. |
| 410 | // The recordings were loosely binned into 3 categories - slow, faster, and fast, which roughly |
| 411 | // characterizes the velocity of the finger motion. |
| 412 | // These can be treated approximately as: |
| 413 | // slow - less than 1 page gets scrolled |
| 414 | // faster - more than 1 page gets scrolled, but less than 3 |
| 415 | // fast - entire list is scrolled (fling is done as hard as possible) |
| 416 | |
| 417 | TEST_F(VelocityTrackerTest, SailfishFlingUpSlow1) { |
| 418 | // Sailfish - fling up - slow - 1 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 419 | std::vector<MotionEventEntry> motions = { |
| 420 | { 235089067457000ns, {{528.00, 983.00}} }, |
| 421 | { 235089084684000ns, {{527.00, 981.00}} }, |
| 422 | { 235089093349000ns, {{527.00, 977.00}} }, |
| 423 | { 235089095677625ns, {{527.00, 975.93}} }, |
| 424 | { 235089101859000ns, {{527.00, 970.00}} }, |
| 425 | { 235089110378000ns, {{528.00, 960.00}} }, |
| 426 | { 235089112497111ns, {{528.25, 957.51}} }, |
| 427 | { 235089118760000ns, {{531.00, 946.00}} }, |
| 428 | { 235089126686000ns, {{535.00, 931.00}} }, |
| 429 | { 235089129316820ns, {{536.33, 926.02}} }, |
| 430 | { 235089135199000ns, {{540.00, 914.00}} }, |
| 431 | { 235089144297000ns, {{546.00, 896.00}} }, |
| 432 | { 235089146136443ns, {{547.21, 892.36}} }, |
| 433 | { 235089152923000ns, {{553.00, 877.00}} }, |
| 434 | { 235089160784000ns, {{559.00, 851.00}} }, |
| 435 | { 235089162955851ns, {{560.66, 843.82}} }, |
| 436 | { 235089162955851ns, {{560.66, 843.82}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 437 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 438 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
Siarhei Vishniakou | e37bcec | 2021-09-28 14:24:32 -0700 | [diff] [blame] | 439 | 764.345703); |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 440 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 441 | 951.698181); |
| 442 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 443 | -3604.819336); |
| 444 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 445 | -3044.966064); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | |
| 449 | TEST_F(VelocityTrackerTest, SailfishFlingUpSlow2) { |
| 450 | // Sailfish - fling up - slow - 2 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 451 | std::vector<MotionEventEntry> motions = { |
| 452 | { 235110560704000ns, {{522.00, 1107.00}} }, |
| 453 | { 235110575764000ns, {{522.00, 1107.00}} }, |
| 454 | { 235110584385000ns, {{522.00, 1107.00}} }, |
| 455 | { 235110588421179ns, {{521.52, 1106.52}} }, |
| 456 | { 235110592830000ns, {{521.00, 1106.00}} }, |
| 457 | { 235110601385000ns, {{520.00, 1104.00}} }, |
| 458 | { 235110605088160ns, {{519.14, 1102.27}} }, |
| 459 | { 235110609952000ns, {{518.00, 1100.00}} }, |
| 460 | { 235110618353000ns, {{517.00, 1093.00}} }, |
| 461 | { 235110621755146ns, {{516.60, 1090.17}} }, |
| 462 | { 235110627010000ns, {{517.00, 1081.00}} }, |
| 463 | { 235110634785000ns, {{518.00, 1063.00}} }, |
| 464 | { 235110638422450ns, {{518.87, 1052.58}} }, |
| 465 | { 235110643161000ns, {{520.00, 1039.00}} }, |
| 466 | { 235110651767000ns, {{524.00, 1011.00}} }, |
| 467 | { 235110655089581ns, {{525.54, 1000.19}} }, |
| 468 | { 235110660368000ns, {{530.00, 980.00}} }, |
| 469 | { 235110660368000ns, {{530.00, 980.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 470 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 471 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 472 | -4096.583008); |
| 473 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 474 | -3455.094238); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | |
| 478 | TEST_F(VelocityTrackerTest, SailfishFlingUpSlow3) { |
| 479 | // Sailfish - fling up - slow - 3 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 480 | std::vector<MotionEventEntry> motions = { |
| 481 | { 792536237000ns, {{580.00, 1317.00}} }, |
| 482 | { 792541538987ns, {{580.63, 1311.94}} }, |
| 483 | { 792544613000ns, {{581.00, 1309.00}} }, |
| 484 | { 792552301000ns, {{583.00, 1295.00}} }, |
| 485 | { 792558362309ns, {{585.13, 1282.92}} }, |
| 486 | { 792560828000ns, {{586.00, 1278.00}} }, |
| 487 | { 792569446000ns, {{589.00, 1256.00}} }, |
| 488 | { 792575185095ns, {{591.54, 1241.41}} }, |
| 489 | { 792578491000ns, {{593.00, 1233.00}} }, |
| 490 | { 792587044000ns, {{597.00, 1211.00}} }, |
| 491 | { 792592008172ns, {{600.28, 1195.92}} }, |
| 492 | { 792594616000ns, {{602.00, 1188.00}} }, |
| 493 | { 792603129000ns, {{607.00, 1167.00}} }, |
| 494 | { 792608831290ns, {{609.48, 1155.83}} }, |
| 495 | { 792612321000ns, {{611.00, 1149.00}} }, |
| 496 | { 792620768000ns, {{615.00, 1131.00}} }, |
| 497 | { 792625653873ns, {{617.32, 1121.73}} }, |
| 498 | { 792629200000ns, {{619.00, 1115.00}} }, |
| 499 | { 792629200000ns, {{619.00, 1115.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 500 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 501 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 502 | 574.33429); |
| 503 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 504 | 617.40564); |
| 505 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 506 | -2361.982666); |
| 507 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 508 | -2500.055664); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | |
| 512 | TEST_F(VelocityTrackerTest, SailfishFlingUpFaster1) { |
| 513 | // Sailfish - fling up - faster - 1 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 514 | std::vector<MotionEventEntry> motions = { |
| 515 | { 235160420675000ns, {{610.00, 1042.00}} }, |
| 516 | { 235160428220000ns, {{609.00, 1026.00}} }, |
| 517 | { 235160436544000ns, {{609.00, 1024.00}} }, |
| 518 | { 235160441852394ns, {{609.64, 1020.82}} }, |
| 519 | { 235160444878000ns, {{610.00, 1019.00}} }, |
| 520 | { 235160452673000ns, {{613.00, 1006.00}} }, |
| 521 | { 235160458519743ns, {{617.18, 992.06}} }, |
| 522 | { 235160461061000ns, {{619.00, 986.00}} }, |
| 523 | { 235160469798000ns, {{627.00, 960.00}} }, |
| 524 | { 235160475186713ns, {{632.22, 943.02}} }, |
| 525 | { 235160478051000ns, {{635.00, 934.00}} }, |
| 526 | { 235160486489000ns, {{644.00, 906.00}} }, |
| 527 | { 235160491853697ns, {{649.56, 890.56}} }, |
| 528 | { 235160495177000ns, {{653.00, 881.00}} }, |
| 529 | { 235160504148000ns, {{662.00, 858.00}} }, |
| 530 | { 235160509231495ns, {{666.81, 845.37}} }, |
| 531 | { 235160512603000ns, {{670.00, 837.00}} }, |
| 532 | { 235160520366000ns, {{679.00, 814.00}} }, |
| 533 | { 235160520366000ns, {{679.00, 814.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 534 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 535 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 536 | 1274.141724); |
| 537 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 538 | 1438.53186); |
| 539 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 540 | -3001.4348); |
| 541 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 542 | -3695.859619); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | |
| 546 | TEST_F(VelocityTrackerTest, SailfishFlingUpFaster2) { |
| 547 | // Sailfish - fling up - faster - 2 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 548 | std::vector<MotionEventEntry> motions = { |
| 549 | { 847153808000ns, {{576.00, 1264.00}} }, |
| 550 | { 847171174000ns, {{576.00, 1262.00}} }, |
| 551 | { 847179640000ns, {{576.00, 1257.00}} }, |
| 552 | { 847185187540ns, {{577.41, 1249.22}} }, |
| 553 | { 847187487000ns, {{578.00, 1246.00}} }, |
| 554 | { 847195710000ns, {{581.00, 1227.00}} }, |
| 555 | { 847202027059ns, {{583.93, 1209.40}} }, |
| 556 | { 847204324000ns, {{585.00, 1203.00}} }, |
| 557 | { 847212672000ns, {{590.00, 1176.00}} }, |
| 558 | { 847218861395ns, {{594.36, 1157.11}} }, |
| 559 | { 847221190000ns, {{596.00, 1150.00}} }, |
| 560 | { 847230484000ns, {{602.00, 1124.00}} }, |
| 561 | { 847235701400ns, {{607.56, 1103.83}} }, |
| 562 | { 847237986000ns, {{610.00, 1095.00}} }, |
| 563 | { 847237986000ns, {{610.00, 1095.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 564 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 565 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 566 | -4280.07959); |
| 567 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 568 | -4241.004395); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | |
| 572 | TEST_F(VelocityTrackerTest, SailfishFlingUpFaster3) { |
| 573 | // Sailfish - fling up - faster - 3 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 574 | std::vector<MotionEventEntry> motions = { |
| 575 | { 235200532789000ns, {{507.00, 1084.00}} }, |
| 576 | { 235200549221000ns, {{507.00, 1083.00}} }, |
| 577 | { 235200557841000ns, {{507.00, 1081.00}} }, |
| 578 | { 235200558051189ns, {{507.00, 1080.95}} }, |
| 579 | { 235200566314000ns, {{507.00, 1078.00}} }, |
| 580 | { 235200574876586ns, {{508.97, 1070.12}} }, |
| 581 | { 235200575006000ns, {{509.00, 1070.00}} }, |
| 582 | { 235200582900000ns, {{514.00, 1054.00}} }, |
| 583 | { 235200591276000ns, {{525.00, 1023.00}} }, |
| 584 | { 235200591701829ns, {{525.56, 1021.42}} }, |
| 585 | { 235200600064000ns, {{542.00, 976.00}} }, |
| 586 | { 235200608519000ns, {{563.00, 911.00}} }, |
| 587 | { 235200608527086ns, {{563.02, 910.94}} }, |
| 588 | { 235200616933000ns, {{590.00, 844.00}} }, |
| 589 | { 235200616933000ns, {{590.00, 844.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 590 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 591 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 592 | -8715.686523); |
| 593 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 594 | -7639.026367); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | |
| 598 | TEST_F(VelocityTrackerTest, SailfishFlingUpFast1) { |
| 599 | // Sailfish - fling up - fast - 1 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 600 | std::vector<MotionEventEntry> motions = { |
| 601 | { 920922149000ns, {{561.00, 1412.00}} }, |
| 602 | { 920930185000ns, {{559.00, 1377.00}} }, |
| 603 | { 920930262463ns, {{558.98, 1376.66}} }, |
| 604 | { 920938547000ns, {{559.00, 1371.00}} }, |
| 605 | { 920947096857ns, {{562.91, 1342.68}} }, |
| 606 | { 920947302000ns, {{563.00, 1342.00}} }, |
| 607 | { 920955502000ns, {{577.00, 1272.00}} }, |
| 608 | { 920963931021ns, {{596.87, 1190.54}} }, |
| 609 | { 920963987000ns, {{597.00, 1190.00}} }, |
| 610 | { 920972530000ns, {{631.00, 1093.00}} }, |
| 611 | { 920980765511ns, {{671.31, 994.68}} }, |
| 612 | { 920980906000ns, {{672.00, 993.00}} }, |
| 613 | { 920989261000ns, {{715.00, 903.00}} }, |
| 614 | { 920989261000ns, {{715.00, 903.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 615 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 616 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 617 | 5670.329102); |
| 618 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 619 | 5991.866699); |
| 620 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 621 | -13021.101562); |
| 622 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 623 | -15093.995117); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | |
| 627 | TEST_F(VelocityTrackerTest, SailfishFlingUpFast2) { |
| 628 | // Sailfish - fling up - fast - 2 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 629 | std::vector<MotionEventEntry> motions = { |
| 630 | { 235247153233000ns, {{518.00, 1168.00}} }, |
| 631 | { 235247170452000ns, {{517.00, 1167.00}} }, |
| 632 | { 235247178908000ns, {{515.00, 1159.00}} }, |
| 633 | { 235247179556213ns, {{514.85, 1158.39}} }, |
| 634 | { 235247186821000ns, {{515.00, 1125.00}} }, |
| 635 | { 235247195265000ns, {{521.00, 1051.00}} }, |
| 636 | { 235247196389476ns, {{521.80, 1041.15}} }, |
| 637 | { 235247203649000ns, {{538.00, 932.00}} }, |
| 638 | { 235247212253000ns, {{571.00, 794.00}} }, |
| 639 | { 235247213222491ns, {{574.72, 778.45}} }, |
| 640 | { 235247220736000ns, {{620.00, 641.00}} }, |
| 641 | { 235247220736000ns, {{620.00, 641.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 642 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 643 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 644 | -20286.958984); |
| 645 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 646 | -20494.587891); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | |
| 650 | TEST_F(VelocityTrackerTest, SailfishFlingUpFast3) { |
| 651 | // Sailfish - fling up - fast - 3 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 652 | std::vector<MotionEventEntry> motions = { |
| 653 | { 235302568736000ns, {{529.00, 1167.00}} }, |
| 654 | { 235302576644000ns, {{523.00, 1140.00}} }, |
| 655 | { 235302579395063ns, {{520.91, 1130.61}} }, |
| 656 | { 235302585140000ns, {{522.00, 1130.00}} }, |
| 657 | { 235302593615000ns, {{527.00, 1065.00}} }, |
| 658 | { 235302596207444ns, {{528.53, 1045.12}} }, |
| 659 | { 235302602102000ns, {{559.00, 872.00}} }, |
| 660 | { 235302610545000ns, {{652.00, 605.00}} }, |
| 661 | { 235302613019881ns, {{679.26, 526.73}} }, |
| 662 | { 235302613019881ns, {{679.26, 526.73}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 663 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 664 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 665 | -39295.941406); |
| 666 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 667 | -36461.421875); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | |
| 671 | TEST_F(VelocityTrackerTest, SailfishFlingDownSlow1) { |
| 672 | // Sailfish - fling down - slow - 1 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 673 | std::vector<MotionEventEntry> motions = { |
| 674 | { 235655749552755ns, {{582.00, 432.49}} }, |
| 675 | { 235655750638000ns, {{582.00, 433.00}} }, |
| 676 | { 235655758865000ns, {{582.00, 440.00}} }, |
| 677 | { 235655766221523ns, {{581.16, 448.43}} }, |
| 678 | { 235655767594000ns, {{581.00, 450.00}} }, |
| 679 | { 235655776044000ns, {{580.00, 462.00}} }, |
| 680 | { 235655782890696ns, {{579.18, 474.35}} }, |
| 681 | { 235655784360000ns, {{579.00, 477.00}} }, |
| 682 | { 235655792795000ns, {{578.00, 496.00}} }, |
| 683 | { 235655799559531ns, {{576.27, 515.04}} }, |
| 684 | { 235655800612000ns, {{576.00, 518.00}} }, |
| 685 | { 235655809535000ns, {{574.00, 542.00}} }, |
| 686 | { 235655816988015ns, {{572.17, 564.86}} }, |
| 687 | { 235655817685000ns, {{572.00, 567.00}} }, |
| 688 | { 235655825981000ns, {{569.00, 595.00}} }, |
| 689 | { 235655833808653ns, {{566.26, 620.60}} }, |
| 690 | { 235655834541000ns, {{566.00, 623.00}} }, |
| 691 | { 235655842893000ns, {{563.00, 649.00}} }, |
| 692 | { 235655842893000ns, {{563.00, 649.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 693 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 694 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 695 | -419.749695); |
| 696 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 697 | -398.303894); |
| 698 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 699 | 3309.016357); |
| 700 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 701 | 3969.099854); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | |
| 705 | TEST_F(VelocityTrackerTest, SailfishFlingDownSlow2) { |
| 706 | // Sailfish - fling down - slow - 2 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 707 | std::vector<MotionEventEntry> motions = { |
| 708 | { 235671152083370ns, {{485.24, 558.28}} }, |
| 709 | { 235671154126000ns, {{485.00, 559.00}} }, |
| 710 | { 235671162497000ns, {{484.00, 566.00}} }, |
| 711 | { 235671168750511ns, {{483.27, 573.29}} }, |
| 712 | { 235671171071000ns, {{483.00, 576.00}} }, |
| 713 | { 235671179390000ns, {{482.00, 588.00}} }, |
| 714 | { 235671185417210ns, {{481.31, 598.98}} }, |
| 715 | { 235671188173000ns, {{481.00, 604.00}} }, |
| 716 | { 235671196371000ns, {{480.00, 624.00}} }, |
| 717 | { 235671202084196ns, {{479.27, 639.98}} }, |
| 718 | { 235671204235000ns, {{479.00, 646.00}} }, |
| 719 | { 235671212554000ns, {{478.00, 673.00}} }, |
| 720 | { 235671219471011ns, {{476.39, 697.12}} }, |
| 721 | { 235671221159000ns, {{476.00, 703.00}} }, |
| 722 | { 235671229592000ns, {{474.00, 734.00}} }, |
| 723 | { 235671236281462ns, {{472.43, 758.38}} }, |
| 724 | { 235671238098000ns, {{472.00, 765.00}} }, |
| 725 | { 235671246532000ns, {{470.00, 799.00}} }, |
| 726 | { 235671246532000ns, {{470.00, 799.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 727 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 728 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 729 | -262.80426); |
| 730 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 731 | -243.665344); |
| 732 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 733 | 4215.682129); |
| 734 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 735 | 4587.986816); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | |
| 739 | TEST_F(VelocityTrackerTest, SailfishFlingDownSlow3) { |
| 740 | // Sailfish - fling down - slow - 3 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 741 | std::vector<MotionEventEntry> motions = { |
| 742 | { 170983201000ns, {{557.00, 533.00}} }, |
| 743 | { 171000668000ns, {{556.00, 534.00}} }, |
| 744 | { 171007359750ns, {{554.73, 535.27}} }, |
| 745 | { 171011197000ns, {{554.00, 536.00}} }, |
| 746 | { 171017660000ns, {{552.00, 540.00}} }, |
| 747 | { 171024201831ns, {{549.97, 544.73}} }, |
| 748 | { 171027333000ns, {{549.00, 547.00}} }, |
| 749 | { 171034603000ns, {{545.00, 557.00}} }, |
| 750 | { 171041043371ns, {{541.98, 567.55}} }, |
| 751 | { 171043147000ns, {{541.00, 571.00}} }, |
| 752 | { 171051052000ns, {{536.00, 586.00}} }, |
| 753 | { 171051052000ns, {{536.00, 586.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 754 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 755 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 756 | -723.413513); |
| 757 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 758 | -651.038452); |
| 759 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 760 | 2091.502441); |
| 761 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 762 | 1934.517456); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | |
| 766 | TEST_F(VelocityTrackerTest, SailfishFlingDownFaster1) { |
| 767 | // Sailfish - fling down - faster - 1 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 768 | std::vector<MotionEventEntry> motions = { |
| 769 | { 235695280333000ns, {{558.00, 451.00}} }, |
| 770 | { 235695283971237ns, {{558.43, 454.45}} }, |
| 771 | { 235695289038000ns, {{559.00, 462.00}} }, |
| 772 | { 235695297388000ns, {{561.00, 478.00}} }, |
| 773 | { 235695300638465ns, {{561.83, 486.25}} }, |
| 774 | { 235695305265000ns, {{563.00, 498.00}} }, |
| 775 | { 235695313591000ns, {{564.00, 521.00}} }, |
| 776 | { 235695317305492ns, {{564.43, 532.68}} }, |
| 777 | { 235695322181000ns, {{565.00, 548.00}} }, |
| 778 | { 235695330709000ns, {{565.00, 577.00}} }, |
| 779 | { 235695333972227ns, {{565.00, 588.10}} }, |
| 780 | { 235695339250000ns, {{565.00, 609.00}} }, |
| 781 | { 235695347839000ns, {{565.00, 642.00}} }, |
| 782 | { 235695351313257ns, {{565.00, 656.18}} }, |
| 783 | { 235695356412000ns, {{565.00, 677.00}} }, |
| 784 | { 235695364899000ns, {{563.00, 710.00}} }, |
| 785 | { 235695368118682ns, {{562.24, 722.52}} }, |
| 786 | { 235695373403000ns, {{564.00, 744.00}} }, |
| 787 | { 235695373403000ns, {{564.00, 744.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 788 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 789 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 790 | 4254.639648); |
| 791 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 792 | 4698.415039); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | |
| 796 | TEST_F(VelocityTrackerTest, SailfishFlingDownFaster2) { |
| 797 | // Sailfish - fling down - faster - 2 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 798 | std::vector<MotionEventEntry> motions = { |
| 799 | { 235709624766000ns, {{535.00, 579.00}} }, |
| 800 | { 235709642256000ns, {{534.00, 580.00}} }, |
| 801 | { 235709643350278ns, {{533.94, 580.06}} }, |
| 802 | { 235709650760000ns, {{532.00, 584.00}} }, |
| 803 | { 235709658615000ns, {{530.00, 593.00}} }, |
| 804 | { 235709660170495ns, {{529.60, 594.78}} }, |
| 805 | { 235709667095000ns, {{527.00, 606.00}} }, |
| 806 | { 235709675616000ns, {{524.00, 628.00}} }, |
| 807 | { 235709676983261ns, {{523.52, 631.53}} }, |
| 808 | { 235709684289000ns, {{521.00, 652.00}} }, |
| 809 | { 235709692763000ns, {{518.00, 682.00}} }, |
| 810 | { 235709693804993ns, {{517.63, 685.69}} }, |
| 811 | { 235709701438000ns, {{515.00, 709.00}} }, |
| 812 | { 235709709830000ns, {{512.00, 739.00}} }, |
| 813 | { 235709710626776ns, {{511.72, 741.85}} }, |
| 814 | { 235709710626776ns, {{511.72, 741.85}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 815 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 816 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 817 | -430.440247); |
| 818 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 819 | -447.600311); |
| 820 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 821 | 3953.859375); |
| 822 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 823 | 4316.155273); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | |
| 827 | TEST_F(VelocityTrackerTest, SailfishFlingDownFaster3) { |
| 828 | // Sailfish - fling down - faster - 3 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 829 | std::vector<MotionEventEntry> motions = { |
| 830 | { 235727628927000ns, {{540.00, 440.00}} }, |
| 831 | { 235727636810000ns, {{537.00, 454.00}} }, |
| 832 | { 235727646176000ns, {{536.00, 454.00}} }, |
| 833 | { 235727653586628ns, {{535.12, 456.65}} }, |
| 834 | { 235727654557000ns, {{535.00, 457.00}} }, |
| 835 | { 235727663024000ns, {{534.00, 465.00}} }, |
| 836 | { 235727670410103ns, {{533.04, 479.45}} }, |
| 837 | { 235727670691000ns, {{533.00, 480.00}} }, |
| 838 | { 235727679255000ns, {{531.00, 501.00}} }, |
| 839 | { 235727687233704ns, {{529.09, 526.73}} }, |
| 840 | { 235727687628000ns, {{529.00, 528.00}} }, |
| 841 | { 235727696113000ns, {{526.00, 558.00}} }, |
| 842 | { 235727704057546ns, {{523.18, 588.98}} }, |
| 843 | { 235727704576000ns, {{523.00, 591.00}} }, |
| 844 | { 235727713099000ns, {{520.00, 626.00}} }, |
| 845 | { 235727720880776ns, {{516.33, 655.36}} }, |
| 846 | { 235727721580000ns, {{516.00, 658.00}} }, |
| 847 | { 235727721580000ns, {{516.00, 658.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 848 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 849 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 850 | 4484.617676); |
| 851 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 852 | 4927.92627); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | |
| 856 | TEST_F(VelocityTrackerTest, SailfishFlingDownFast1) { |
| 857 | // Sailfish - fling down - fast - 1 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 858 | std::vector<MotionEventEntry> motions = { |
| 859 | { 235762352849000ns, {{467.00, 286.00}} }, |
| 860 | { 235762360250000ns, {{443.00, 344.00}} }, |
| 861 | { 235762362787412ns, {{434.77, 363.89}} }, |
| 862 | { 235762368807000ns, {{438.00, 359.00}} }, |
| 863 | { 235762377220000ns, {{425.00, 423.00}} }, |
| 864 | { 235762379608561ns, {{421.31, 441.17}} }, |
| 865 | { 235762385698000ns, {{412.00, 528.00}} }, |
| 866 | { 235762394133000ns, {{406.00, 648.00}} }, |
| 867 | { 235762396429369ns, {{404.37, 680.67}} }, |
| 868 | { 235762396429369ns, {{404.37, 680.67}} }, //ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 869 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 870 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 871 | 14227.0224); |
| 872 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 873 | 16064.685547); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | |
| 877 | TEST_F(VelocityTrackerTest, SailfishFlingDownFast2) { |
| 878 | // Sailfish - fling down - fast - 2 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 879 | std::vector<MotionEventEntry> motions = { |
| 880 | { 235772487188000ns, {{576.00, 204.00}} }, |
| 881 | { 235772495159000ns, {{553.00, 236.00}} }, |
| 882 | { 235772503568000ns, {{551.00, 240.00}} }, |
| 883 | { 235772508192247ns, {{545.55, 254.17}} }, |
| 884 | { 235772512051000ns, {{541.00, 266.00}} }, |
| 885 | { 235772520794000ns, {{520.00, 337.00}} }, |
| 886 | { 235772525015263ns, {{508.92, 394.43}} }, |
| 887 | { 235772529174000ns, {{498.00, 451.00}} }, |
| 888 | { 235772537635000ns, {{484.00, 589.00}} }, |
| 889 | { 235772537635000ns, {{484.00, 589.00}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 890 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 891 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 892 | 18660.048828); |
| 893 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 894 | 16918.439453); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | |
| 898 | TEST_F(VelocityTrackerTest, SailfishFlingDownFast3) { |
| 899 | // Sailfish - fling down - fast - 3 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 900 | std::vector<MotionEventEntry> motions = { |
| 901 | { 507650295000ns, {{628.00, 233.00}} }, |
| 902 | { 507658234000ns, {{605.00, 269.00}} }, |
| 903 | { 507666784000ns, {{601.00, 274.00}} }, |
| 904 | { 507669660483ns, {{599.65, 275.68}} }, |
| 905 | { 507675427000ns, {{582.00, 308.00}} }, |
| 906 | { 507683740000ns, {{541.00, 404.00}} }, |
| 907 | { 507686506238ns, {{527.36, 435.95}} }, |
| 908 | { 507692220000ns, {{487.00, 581.00}} }, |
| 909 | { 507700707000ns, {{454.00, 792.00}} }, |
| 910 | { 507703352649ns, {{443.71, 857.77}} }, |
| 911 | { 507703352649ns, {{443.71, 857.77}} }, // ACTION_UP |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 912 | }; |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 913 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 914 | -4111.8173); |
| 915 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, |
| 916 | -6388.48877); |
| 917 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, |
| 918 | 29765.908203); |
| 919 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, |
| 920 | 28354.796875); |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 921 | } |
| 922 | |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 923 | /** |
| 924 | * ================== Multiple pointers ============================================================ |
| 925 | * |
| 926 | * Three fingers quickly tap the screen. Since this is a tap, the velocities should be zero. |
| 927 | * If the events with POINTER_UP or POINTER_DOWN are not handled correctly (these should not be |
| 928 | * 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] | 929 | */ |
Siarhei Vishniakou | 346ac6a | 2019-04-10 09:58:05 -0700 | [diff] [blame] | 930 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategyEstimator_ThreeFingerTap) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 931 | std::vector<MotionEventEntry> motions = { |
| 932 | { 0us, {{1063, 1128}, {NAN, NAN}, {NAN, NAN}} }, |
| 933 | { 10800us, {{1063, 1128}, {682, 1318}, {NAN, NAN}} }, // POINTER_DOWN |
| 934 | { 10800us, {{1063, 1128}, {682, 1318}, {397, 1747}} }, // POINTER_DOWN |
| 935 | { 267300us, {{1063, 1128}, {682, 1318}, {397, 1747}} }, // POINTER_UP |
| 936 | { 267300us, {{1063, 1128}, {NAN, NAN}, {397, 1747}} }, // POINTER_UP |
| 937 | { 272700us, {{1063, 1128}, {NAN, NAN}, {NAN, NAN}} }, |
| 938 | }; |
| 939 | |
Siarhei Vishniakou | 346ac6a | 2019-04-10 09:58:05 -0700 | [diff] [blame] | 940 | // Velocity should actually be zero, but we expect 0.016 here instead. |
| 941 | // This is close enough to zero, and is likely caused by division by a very small number. |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 942 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, 0); |
| 943 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_Y, 0); |
Chris Ye | f859148 | 2020-04-17 11:49:17 -0700 | [diff] [blame] | 944 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, 0); |
| 945 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_Y, 0); |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | /** |
Siarhei Vishniakou | 9f26fc3 | 2022-06-17 22:13:57 +0000 | [diff] [blame] | 949 | * ================= Pointer liftoff =============================================================== |
| 950 | */ |
| 951 | |
| 952 | /** |
| 953 | * The last movement of a pointer is always ACTION_POINTER_UP or ACTION_UP. If there's a short delay |
| 954 | * between the last ACTION_MOVE and the next ACTION_POINTER_UP or ACTION_UP, velocity should not be |
| 955 | * affected by the liftoff. |
| 956 | */ |
| 957 | TEST_F(VelocityTrackerTest, ShortDelayBeforeActionUp) { |
| 958 | std::vector<MotionEventEntry> motions = { |
| 959 | {0ms, {{10, 0}}}, {10ms, {{20, 0}}}, {20ms, {{30, 0}}}, {30ms, {{30, 0}}}, // ACTION_UP |
| 960 | }; |
| 961 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, |
| 962 | 1000); |
| 963 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, 1000); |
| 964 | } |
| 965 | |
| 966 | /** |
| 967 | * The last movement of a single pointer is ACTION_UP. If there's a long delay between the last |
| 968 | * ACTION_MOVE and the final ACTION_UP, velocity should be reported as zero because the pointer |
| 969 | * should be assumed to have stopped. |
| 970 | */ |
| 971 | TEST_F(VelocityTrackerTest, LongDelayBeforeActionUp) { |
| 972 | std::vector<MotionEventEntry> motions = { |
| 973 | {0ms, {{10, 0}}}, |
| 974 | {10ms, {{20, 0}}}, |
| 975 | {20ms, {{30, 0}}}, |
| 976 | {3000ms, {{30, 0}}}, // ACTION_UP |
| 977 | }; |
| 978 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, 0); |
| 979 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, 0); |
| 980 | } |
| 981 | |
| 982 | /** |
| 983 | * The last movement of a pointer is always ACTION_POINTER_UP or ACTION_UP. If there's a long delay |
| 984 | * before ACTION_POINTER_UP event, the movement should be assumed to have stopped. |
| 985 | * The final velocity should be reported as zero for all pointers. |
| 986 | */ |
| 987 | TEST_F(VelocityTrackerTest, LongDelayBeforeActionPointerUp) { |
| 988 | std::vector<MotionEventEntry> motions = { |
| 989 | {0ms, {{10, 0}}}, |
| 990 | {10ms, {{20, 0}, {100, 0}}}, |
| 991 | {20ms, {{30, 0}, {200, 0}}}, |
| 992 | {30ms, {{30, 0}, {300, 0}}}, |
| 993 | {40ms, {{30, 0}, {400, 0}}}, |
| 994 | {3000ms, {{30, 0}}}, // ACTION_POINTER_UP |
| 995 | }; |
| 996 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, 0, |
| 997 | /*pointerId*/ 0); |
| 998 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, 0, |
| 999 | /*pointerId*/ 0); |
| 1000 | computeAndCheckVelocity(VelocityTracker::Strategy::IMPULSE, motions, AMOTION_EVENT_AXIS_X, 0, |
| 1001 | /*pointerId*/ 1); |
| 1002 | computeAndCheckVelocity(VelocityTracker::Strategy::LSQ2, motions, AMOTION_EVENT_AXIS_X, 0, |
| 1003 | /*pointerId*/ 1); |
| 1004 | } |
| 1005 | |
| 1006 | /** |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1007 | * ================== Tests for least squares fitting ============================================== |
| 1008 | * |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1009 | * Special care must be taken when constructing tests for LeastSquaresVelocityTrackerStrategy |
| 1010 | * getEstimator function. In particular: |
| 1011 | * - inside the function, time gets converted from nanoseconds to seconds |
| 1012 | * before being used in the fit. |
| 1013 | * - any values that are older than 100 ms are being discarded. |
| 1014 | * - the newest time gets subtracted from all of the other times before being used in the fit. |
| 1015 | * So these tests have to be designed with those limitations in mind. |
| 1016 | * |
| 1017 | * General approach for the tests below: |
| 1018 | * We only used timestamps in milliseconds, 0 ms, 1 ms, and 2 ms, to be sure that |
| 1019 | * we are well within the HORIZON range. |
| 1020 | * When specifying the expected values of the coefficients, we treat the x values as if |
| 1021 | * they were in ms. Then, to adjust for the time units, the coefficients get progressively |
| 1022 | * multiplied by powers of 1E3. |
| 1023 | * For example: |
| 1024 | * data: t(ms), x |
| 1025 | * 1 ms, 1 |
| 1026 | * 2 ms, 4 |
| 1027 | * 3 ms, 9 |
| 1028 | * The coefficients are (0, 0, 1). |
| 1029 | * In the test, we would convert these coefficients to (0*(1E3)^0, 0*(1E3)^1, 1*(1E3)^2). |
| 1030 | */ |
| 1031 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategyEstimator_Constant) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1032 | std::vector<MotionEventEntry> motions = { |
| 1033 | { 0ms, {{1, 1}} }, // 0 s |
| 1034 | { 1ms, {{1, 1}} }, // 0.001 s |
| 1035 | { 2ms, {{1, 1}} }, // 0.002 s |
| 1036 | { 2ms, {{1, 1}} }, // ACTION_UP |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1037 | }; |
| 1038 | // The data used for the fit will be as follows: |
| 1039 | // time(s), position |
| 1040 | // -0.002, 1 |
| 1041 | // -0.001, 1 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1042 | // -0.ms, 1 |
| 1043 | computeAndCheckQuadraticEstimate(motions, std::array<float, 3>({1, 0, 0})); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | /* |
| 1047 | * Straight line y = x :: the constant and quadratic coefficients are zero. |
| 1048 | */ |
| 1049 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategyEstimator_Linear) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1050 | std::vector<MotionEventEntry> motions = { |
| 1051 | { 0ms, {{-2, -2}} }, |
| 1052 | { 1ms, {{-1, -1}} }, |
| 1053 | { 2ms, {{-0, -0}} }, |
| 1054 | { 2ms, {{-0, -0}} }, // ACTION_UP |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1055 | }; |
| 1056 | // The data used for the fit will be as follows: |
| 1057 | // time(s), position |
| 1058 | // -0.002, -2 |
| 1059 | // -0.001, -1 |
| 1060 | // -0.000, 0 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1061 | computeAndCheckQuadraticEstimate(motions, std::array<float, 3>({0, 1E3, 0})); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | /* |
| 1065 | * Parabola |
| 1066 | */ |
| 1067 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategyEstimator_Parabolic) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1068 | std::vector<MotionEventEntry> motions = { |
| 1069 | { 0ms, {{1, 1}} }, |
| 1070 | { 1ms, {{4, 4}} }, |
| 1071 | { 2ms, {{8, 8}} }, |
| 1072 | { 2ms, {{8, 8}} }, // ACTION_UP |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1073 | }; |
| 1074 | // The data used for the fit will be as follows: |
| 1075 | // time(s), position |
| 1076 | // -0.002, 1 |
| 1077 | // -0.001, 4 |
| 1078 | // -0.000, 8 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1079 | computeAndCheckQuadraticEstimate(motions, std::array<float, 3>({8, 4.5E3, 0.5E6})); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | /* |
| 1083 | * Parabola |
| 1084 | */ |
| 1085 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategyEstimator_Parabolic2) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1086 | std::vector<MotionEventEntry> motions = { |
| 1087 | { 0ms, {{1, 1}} }, |
| 1088 | { 1ms, {{4, 4}} }, |
| 1089 | { 2ms, {{9, 9}} }, |
| 1090 | { 2ms, {{9, 9}} }, // ACTION_UP |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1091 | }; |
| 1092 | // The data used for the fit will be as follows: |
| 1093 | // time(s), position |
| 1094 | // -0.002, 1 |
| 1095 | // -0.001, 4 |
| 1096 | // -0.000, 9 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1097 | computeAndCheckQuadraticEstimate(motions, std::array<float, 3>({9, 6E3, 1E6})); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | /* |
| 1101 | * Parabola :: y = x^2 :: the constant and linear coefficients are zero. |
| 1102 | */ |
| 1103 | TEST_F(VelocityTrackerTest, LeastSquaresVelocityTrackerStrategyEstimator_Parabolic3) { |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1104 | std::vector<MotionEventEntry> motions = { |
| 1105 | { 0ms, {{4, 4}} }, |
| 1106 | { 1ms, {{1, 1}} }, |
| 1107 | { 2ms, {{0, 0}} }, |
| 1108 | { 2ms, {{0, 0}} }, // ACTION_UP |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1109 | }; |
| 1110 | // The data used for the fit will be as follows: |
| 1111 | // time(s), position |
| 1112 | // -0.002, 4 |
| 1113 | // -0.001, 1 |
| 1114 | // -0.000, 0 |
Siarhei Vishniakou | 651c1ea | 2019-04-09 14:12:41 -0700 | [diff] [blame] | 1115 | computeAndCheckQuadraticEstimate(motions, std::array<float, 3>({0, 0E3, 1E6})); |
Siarhei Vishniakou | f7e2d3e | 2018-09-07 16:38:18 -0700 | [diff] [blame] | 1116 | } |
Siarhei Vishniakou | d4b607e | 2017-06-13 12:21:59 +0100 | [diff] [blame] | 1117 | |
| 1118 | } // namespace android |