logo

qmk_firmware

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

test_mousekeys.cpp (4089B)


  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. using testing::_;
  7. struct MouseKeyExpectations {
  8. int16_t x;
  9. int16_t y;
  10. int16_t h;
  11. int16_t v;
  12. uint16_t button_mask;
  13. };
  14. class Mousekey : public TestFixture {};
  15. class MousekeyParametrized : public ::testing::WithParamInterface<std::pair<KeymapKey, MouseKeyExpectations>>, public Mousekey {};
  16. TEST_F(Mousekey, SendMouseNotCalledWhenNoKeyIsPressed) {
  17. TestDriver driver;
  18. EXPECT_NO_MOUSE_REPORT(driver);
  19. run_one_scan_loop();
  20. }
  21. TEST_F(Mousekey, PressAndHoldCursorUpIsCorrectlyReported) {
  22. TestDriver driver;
  23. KeymapKey mouse_key = KeymapKey{0, 0, 0, QK_MOUSE_CURSOR_UP};
  24. set_keymap({mouse_key});
  25. EXPECT_MOUSE_REPORT(driver, (0, -8, 0, 0, 0));
  26. mouse_key.press();
  27. run_one_scan_loop();
  28. EXPECT_MOUSE_REPORT(driver, (0, -2, 0, 0, 0));
  29. idle_for(MOUSEKEY_INTERVAL);
  30. EXPECT_EMPTY_MOUSE_REPORT(driver);
  31. mouse_key.release();
  32. run_one_scan_loop();
  33. VERIFY_AND_CLEAR(driver);
  34. }
  35. TEST_F(Mousekey, PressAndHoldButtonOneCorrectlyReported) {
  36. TestDriver driver;
  37. KeymapKey mouse_key = KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_1};
  38. set_keymap({mouse_key});
  39. EXPECT_MOUSE_REPORT(driver, (0, 0, 0, 0, 1));
  40. mouse_key.press();
  41. run_one_scan_loop();
  42. idle_for(MOUSEKEY_INTERVAL);
  43. EXPECT_EMPTY_MOUSE_REPORT(driver);
  44. mouse_key.release();
  45. run_one_scan_loop();
  46. VERIFY_AND_CLEAR(driver);
  47. }
  48. TEST_P(MousekeyParametrized, PressAndReleaseIsCorrectlyReported) {
  49. TestDriver driver;
  50. KeymapKey mouse_key = GetParam().first;
  51. MouseKeyExpectations expectations = GetParam().second;
  52. set_keymap({mouse_key});
  53. EXPECT_MOUSE_REPORT(driver, (expectations.x, expectations.y, expectations.h, expectations.v, expectations.button_mask));
  54. mouse_key.press();
  55. run_one_scan_loop();
  56. EXPECT_EMPTY_MOUSE_REPORT(driver);
  57. mouse_key.release();
  58. run_one_scan_loop();
  59. EXPECT_NO_MOUSE_REPORT(driver);
  60. run_one_scan_loop();
  61. VERIFY_AND_CLEAR(driver);
  62. }
  63. // clang-format off
  64. INSTANTIATE_TEST_CASE_P(
  65. Keys,
  66. MousekeyParametrized,
  67. ::testing::Values(
  68. // Key , X, Y, H, V, Buttons Mask
  69. std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_1}, MouseKeyExpectations{ 0, 0, 0, 0, 1}),
  70. std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_2}, MouseKeyExpectations{ 0, 0, 0, 0, 2}),
  71. std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_3}, MouseKeyExpectations{ 0, 0, 0, 0, 4}),
  72. std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_4}, MouseKeyExpectations{ 0, 0, 0, 0, 8}),
  73. std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_5}, MouseKeyExpectations{ 0, 0, 0, 0, 16}),
  74. std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_6}, MouseKeyExpectations{ 0, 0, 0, 0, 32}),
  75. std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_7}, MouseKeyExpectations{ 0, 0, 0, 0, 64}),
  76. std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_BUTTON_8}, MouseKeyExpectations{ 0, 0, 0, 0, 128}),
  77. std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_CURSOR_UP}, MouseKeyExpectations{ 0,-8, 0, 0, 0}),
  78. std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_CURSOR_DOWN}, MouseKeyExpectations{ 0, 8, 0, 0, 0}),
  79. std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_CURSOR_LEFT}, MouseKeyExpectations{-8, 0, 0, 0, 0}),
  80. std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_CURSOR_RIGHT}, MouseKeyExpectations{ 8, 0, 0, 0, 0}),
  81. std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_WHEEL_UP}, MouseKeyExpectations{ 0, 0, 0, 1, 0}),
  82. std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_WHEEL_DOWN}, MouseKeyExpectations{ 0, 0, 0,-1, 0}),
  83. std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_WHEEL_LEFT}, MouseKeyExpectations{ 0, 0,-1, 0, 0}),
  84. std::make_pair(KeymapKey{0, 0, 0, QK_MOUSE_WHEEL_RIGHT}, MouseKeyExpectations{ 0, 0, 1, 0, 0})
  85. ));
  86. // clang-format on