logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

test_invertandrotate.cpp (2296B)


  1. // Copyright 2024 Dasky (@daskygit)
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "gtest/gtest.h"
  4. #include "mouse_report_util.hpp"
  5. #include "test_common.hpp"
  6. #include "test_pointing_device_driver.h"
  7. using testing::_;
  8. struct SimpleReport {
  9. int16_t x;
  10. int16_t y;
  11. int16_t h;
  12. int16_t v;
  13. };
  14. class Pointing : public TestFixture {};
  15. class PointingInvertAndRotateParametrized : public ::testing::WithParamInterface<std::pair<SimpleReport, SimpleReport>>, public Pointing {};
  16. TEST_P(PointingInvertAndRotateParametrized, PointingInvertAndRotateOrder) {
  17. TestDriver driver;
  18. SimpleReport input = GetParam().first;
  19. SimpleReport expectations = GetParam().second;
  20. pd_set_x(input.x);
  21. pd_set_y(input.y);
  22. pd_set_h(input.h);
  23. pd_set_v(input.v);
  24. EXPECT_MOUSE_REPORT(driver, (expectations.x, expectations.y, expectations.h, expectations.v, 0));
  25. run_one_scan_loop();
  26. // EXPECT_EMPTY_MOUSE_REPORT(driver);
  27. pd_clear_movement();
  28. run_one_scan_loop();
  29. EXPECT_NO_MOUSE_REPORT(driver);
  30. run_one_scan_loop();
  31. VERIFY_AND_CLEAR(driver);
  32. }
  33. // clang-format off
  34. INSTANTIATE_TEST_CASE_P(
  35. InvertAndRotate,
  36. PointingInvertAndRotateParametrized,
  37. ::testing::Values(
  38. // Input Expected // Actual Result - Rotate 90 then Invert X
  39. std::make_pair(SimpleReport{ -1, 0, 0, 0}, SimpleReport{ 0, 1, 0, 0}), // LEFT - DOWN
  40. std::make_pair(SimpleReport{ 0, -1, 0, 0}, SimpleReport{ 1, 0, 0, 0}), // UP - RIGHT
  41. std::make_pair(SimpleReport{ 1, 0, 0, 0}, SimpleReport{ 0, -1, 0, 0}), // RIGHT - UP
  42. std::make_pair(SimpleReport{ 0, 1, 0, 0}, SimpleReport{ -1, 0, 0, 0}) // DOWN - LEFT
  43. // Input Expected // Invert X then Rotate 90
  44. // std::make_pair(SimpleReport{ -1, 0, 0, 0}, SimpleReport{ 0, -1, 0, 0}), // LEFT - UP
  45. // std::make_pair(SimpleReport{ 0, -1, 0, 0}, SimpleReport{ -1, 0, 0, 0}), // UP - LEFT
  46. // std::make_pair(SimpleReport{ 1, 0, 0, 0}, SimpleReport{ 0, 1, 0, 0}), // RIGHT - DOWN
  47. // std::make_pair(SimpleReport{ 0, 1, 0, 0}, SimpleReport{ 1, 0, 0, 0}) // DOWN - RIGHT
  48. ));
  49. // clang-format on