diff options
author | Denis Brockus <dbrockus@google.com> | 2023-03-20 10:26:49 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-03-21 17:29:12 +0000 |
commit | 1e3890f8c3637a4d61f60d660462e0fd9a29f716 (patch) | |
tree | 1e8240bdb03ed92e61b5e32248fd07670dca7d50 | |
parent | 852c64501bd7a6162d02f48f0faac7fef5080718 (diff) | |
download | libchrome-gestures-1e3890f8c3637a4d61f60d660462e0fd9a29f716.tar.gz |
Move Lookahead list.at() processing to common utilities
BUG=b:271591258
TEST=USE="coverage" FEATURES="test noclean" emerge-brya chromeos-base/gestures
Change-Id: Ief01adbe704e69704efad3af241b7a1b88d3e220
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/gestures/+/4352450
Reviewed-by: Harry Cutts <hcutts@chromium.org>
Auto-Submit: Denis Brockus <dbrockus@chromium.org>
Tested-by: Denis Brockus <dbrockus@chromium.org>
Code-Coverage: Harry Cutts <hcutts@chromium.org>
Commit-Queue: Harry Cutts <hcutts@chromium.org>
-rw-r--r-- | include/lookahead_filter_interpreter.h | 16 | ||||
-rw-r--r-- | src/lookahead_filter_interpreter.cc | 20 | ||||
-rw-r--r-- | src/lookahead_filter_interpreter_unittest.cc | 56 |
3 files changed, 7 insertions, 85 deletions
diff --git a/include/lookahead_filter_interpreter.h b/include/lookahead_filter_interpreter.h index 890919f..d3d4077 100644 --- a/include/lookahead_filter_interpreter.h +++ b/include/lookahead_filter_interpreter.h @@ -15,6 +15,7 @@ #include "include/gestures.h" #include "include/prop_registry.h" #include "include/tracer.h" +#include "include/util.h" #ifndef GESTURES_LOOKAHEAD_FILTER_INTERPRETER_H_ #define GESTURES_LOOKAHEAD_FILTER_INTERPRETER_H_ @@ -34,7 +35,6 @@ class LookaheadFilterInterpreter : public FilterInterpreter { FRIEND_TEST(LookaheadFilterInterpreterTest, SimpleTest); FRIEND_TEST(LookaheadFilterInterpreterTest, SpuriousCallbackTest); FRIEND_TEST(LookaheadFilterInterpreterTest, VariableDelayTest); - FRIEND_TEST(LookaheadFilterInterpreterTest, QStateListTest); public: LookaheadFilterInterpreter(PropRegistry* prop_reg, Interpreter* next, @@ -108,15 +108,13 @@ class LookaheadFilterInterpreter : public FilterInterpreter { stime_t ExtraVariableDelay() const; - typedef std::optional< - std::reference_wrapper< - LookaheadFilterInterpreter::QState - > - > OptionalRefQState; + typedef std::list<QState> QStateListType; + typedef std::optional<std::reference_wrapper<QState>> OptionalRefQState; - class QStateList : public std::list<QState> { - public: - OptionalRefQState at(int offset); + struct QStateList : public QStateListType { + OptionalRefQState at(int offset) { + return ListAt<OptionalRefQState, QStateListType>(*this, offset); + } } queue_; // The last id assigned to a contact (part of drumroll suppression) diff --git a/src/lookahead_filter_interpreter.cc b/src/lookahead_filter_interpreter.cc index 730becf..69156f5 100644 --- a/src/lookahead_filter_interpreter.cc +++ b/src/lookahead_filter_interpreter.cc @@ -587,24 +587,4 @@ void LookaheadFilterInterpreter::QState::set_state( state_.msc_timestamp = new_state.msc_timestamp; } -LookaheadFilterInterpreter::OptionalRefQState -LookaheadFilterInterpreter::QStateList::at(int offset) { - // Traverse to the appropriate offset - if (offset < 0) { - // negative offset is from end to begin - for (auto iter = rbegin(); iter != rend(); ++iter) { - if (++offset == 0) - return LookaheadFilterInterpreter::OptionalRefQState{*iter}; - } - } else { - // positive offset is from begin to end - for (auto iter = begin(); iter != end(); ++iter, --offset) { - if (offset == 0) - return LookaheadFilterInterpreter::OptionalRefQState{*iter}; - } - } - // Invalid offset - return std::nullopt; -} - } // namespace gestures diff --git a/src/lookahead_filter_interpreter_unittest.cc b/src/lookahead_filter_interpreter_unittest.cc index e4d02a9..ee99a0f 100644 --- a/src/lookahead_filter_interpreter_unittest.cc +++ b/src/lookahead_filter_interpreter_unittest.cc @@ -1276,60 +1276,4 @@ TEST(LookaheadFilterInterpreterTest, SemiMtNoTrackingIdAssignmentTest) { } } -TEST(LookaheadFilterInterpreterTest, QStateListTest) { - const size_t kMaxQNodes = 4; - - LookaheadFilterInterpreterTestInterpreter* base_interpreter = NULL; - std::unique_ptr<LookaheadFilterInterpreter> interpreter; - - HardwareProperties hwprops = { - 0, 0, 100, 100, // left, top, right, bottom - 1, // x res (pixels/mm) - 1, // y res (pixels/mm) - 25, 25, // scrn DPI X, Y - -1, // orientation minimum - 2, // orientation maximum - 2, 5, // max fingers, max_touch - 1, 1, 0, // t5r2, semi, button pad - 0, 0, // has wheel, vertical wheel is high resolution - 0, // haptic pad - }; - TestInterpreterWrapper wrapper(interpreter.get(), &hwprops); - - base_interpreter = new LookaheadFilterInterpreterTestInterpreter; - interpreter.reset(new LookaheadFilterInterpreter( - NULL, base_interpreter, NULL)); - wrapper.Reset(interpreter.get()); - - auto& queue = interpreter->queue_; - - EXPECT_TRUE(queue.empty()); - EXPECT_EQ(queue.size(), 0); - - // Use the default constructor one time... just for coverage - queue.push_front(LookaheadFilterInterpreter::QState()); - - for (size_t i{1}; i < kMaxQNodes; ++i) { - queue.push_front( - LookaheadFilterInterpreter::QState(hwprops.max_finger_cnt)); - } - EXPECT_EQ(queue.size(), kMaxQNodes); - EXPECT_EQ(&(queue.at(-1)->get()), &(queue.at(queue.size() - 1)->get())); - - for (size_t i = 0; i < kMaxQNodes; ++i) { - for (size_t j = 0; j < kMaxQNodes; ++j) { - if (i == j) { - EXPECT_EQ(&(queue.at(i)->get()), &(queue.at(j)->get())); - } else { - EXPECT_NE(&(queue.at(i)->get()), &(queue.at(j)->get())); - } - } - } - - int qnode_count = queue.size(); - EXPECT_EQ(queue.at(qnode_count), std::nullopt); - EXPECT_NE(queue.at(qnode_count - 1), std::nullopt); - EXPECT_EQ(queue.at(-qnode_count - 1), std::nullopt); - EXPECT_NE(queue.at(-qnode_count), std::nullopt); -} } // namespace gestures |