You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.3 KiB

  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. #include "gtest/gtest.h"
  17. #include <initializer_list>
  18. #include <list>
  19. #include <string>
  20. extern "C" {
  21. #include "quantum.h"
  22. #include "timer.h"
  23. }
  24. enum Direction {
  25. DOWN,
  26. UP,
  27. };
  28. class MatrixTestEvent {
  29. public:
  30. MatrixTestEvent(int row, int col, Direction direction);
  31. const int row_;
  32. const int col_;
  33. const Direction direction_;
  34. };
  35. class DebounceTestEvent {
  36. public:
  37. // 0, {{0, 1, DOWN}}, {{0, 1, DOWN}})
  38. DebounceTestEvent(fast_timer_t time, std::initializer_list<MatrixTestEvent> inputs, std::initializer_list<MatrixTestEvent> outputs);
  39. const fast_timer_t time_;
  40. const std::list<MatrixTestEvent> inputs_;
  41. const std::list<MatrixTestEvent> outputs_;
  42. };
  43. class DebounceTest : public ::testing::Test {
  44. protected:
  45. void addEvents(std::initializer_list<DebounceTestEvent> events);
  46. void runEvents();
  47. fast_timer_t time_offset_ = 7777;
  48. bool time_jumps_ = false;
  49. private:
  50. static bool directionValue(Direction direction);
  51. static std::string directionLabel(Direction direction);
  52. void runEventsInternal();
  53. void runDebounce(bool changed);
  54. void checkCookedMatrix(bool changed, const std::string &error_message);
  55. void matrixUpdate(matrix_row_t matrix[], const std::string &name, const MatrixTestEvent &event);
  56. std::string strTime();
  57. std::string strMatrix(matrix_row_t matrix[]);
  58. std::list<DebounceTestEvent> events_;
  59. matrix_row_t input_matrix_[MATRIX_ROWS];
  60. matrix_row_t raw_matrix_[MATRIX_ROWS];
  61. matrix_row_t cooked_matrix_[MATRIX_ROWS];
  62. matrix_row_t output_matrix_[MATRIX_ROWS];
  63. int extra_iterations_;
  64. bool auto_advance_time_;
  65. };