diff options
Diffstat (limited to 'quantum/debounce/tests/debounce_test_common.h')
| -rw-r--r-- | quantum/debounce/tests/debounce_test_common.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/quantum/debounce/tests/debounce_test_common.h b/quantum/debounce/tests/debounce_test_common.h new file mode 100644 index 000000000..d87e31059 --- /dev/null +++ b/quantum/debounce/tests/debounce_test_common.h | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | /* Copyright 2021 Simon Arlott | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "gtest/gtest.h" | ||
| 18 | |||
| 19 | #include <initializer_list> | ||
| 20 | #include <list> | ||
| 21 | #include <string> | ||
| 22 | |||
| 23 | extern "C" { | ||
| 24 | #include "quantum.h" | ||
| 25 | #include "timer.h" | ||
| 26 | } | ||
| 27 | |||
| 28 | enum Direction { | ||
| 29 | DOWN, | ||
| 30 | UP, | ||
| 31 | }; | ||
| 32 | |||
| 33 | class MatrixTestEvent { | ||
| 34 | public: | ||
| 35 | MatrixTestEvent(int row, int col, Direction direction); | ||
| 36 | |||
| 37 | const int row_; | ||
| 38 | const int col_; | ||
| 39 | const Direction direction_; | ||
| 40 | }; | ||
| 41 | |||
| 42 | class DebounceTestEvent { | ||
| 43 | public: | ||
| 44 | // 0, {{0, 1, DOWN}}, {{0, 1, DOWN}}) | ||
| 45 | DebounceTestEvent(fast_timer_t time, | ||
| 46 | std::initializer_list<MatrixTestEvent> inputs, | ||
| 47 | std::initializer_list<MatrixTestEvent> outputs); | ||
| 48 | |||
| 49 | const fast_timer_t time_; | ||
| 50 | const std::list<MatrixTestEvent> inputs_; | ||
| 51 | const std::list<MatrixTestEvent> outputs_; | ||
| 52 | }; | ||
| 53 | |||
| 54 | class DebounceTest : public ::testing::Test { | ||
| 55 | protected: | ||
| 56 | void addEvents(std::initializer_list<DebounceTestEvent> events); | ||
| 57 | void runEvents(); | ||
| 58 | |||
| 59 | fast_timer_t time_offset_ = 7777; | ||
| 60 | bool time_jumps_ = false; | ||
| 61 | |||
| 62 | private: | ||
| 63 | static bool directionValue(Direction direction); | ||
| 64 | static std::string directionLabel(Direction direction); | ||
| 65 | |||
| 66 | void runEventsInternal(); | ||
| 67 | void runDebounce(bool changed); | ||
| 68 | void checkCookedMatrix(bool changed, const std::string &error_message); | ||
| 69 | void matrixUpdate(matrix_row_t matrix[], const std::string &name, const MatrixTestEvent &event); | ||
| 70 | |||
| 71 | std::string strTime(); | ||
| 72 | std::string strMatrix(matrix_row_t matrix[]); | ||
| 73 | |||
| 74 | std::list<DebounceTestEvent> events_; | ||
| 75 | |||
| 76 | matrix_row_t input_matrix_[MATRIX_ROWS]; | ||
| 77 | matrix_row_t raw_matrix_[MATRIX_ROWS]; | ||
| 78 | matrix_row_t cooked_matrix_[MATRIX_ROWS]; | ||
| 79 | matrix_row_t output_matrix_[MATRIX_ROWS]; | ||
| 80 | |||
| 81 | int extra_iterations_; | ||
| 82 | bool auto_advance_time_; | ||
| 83 | }; | ||
