test_tapping.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* Copyright 2021 Stefan Kerkmann
  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 "keyboard_report_util.hpp"
  17. #include "keycode.h"
  18. #include "test_common.hpp"
  19. #include "action_tapping.h"
  20. #include "test_keymap_key.hpp"
  21. using testing::_;
  22. using testing::InSequence;
  23. class Tapping : public TestFixture {};
  24. TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) {
  25. TestDriver driver;
  26. InSequence s;
  27. auto mod_tap_hold_key = KeymapKey(0, 7, 0, SFT_T(KC_P));
  28. set_keymap({mod_tap_hold_key});
  29. EXPECT_NO_REPORT(driver);
  30. mod_tap_hold_key.press();
  31. idle_for(TAPPING_TERM);
  32. testing::Mock::VerifyAndClearExpectations(&driver);
  33. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
  34. run_one_scan_loop();
  35. testing::Mock::VerifyAndClearExpectations(&driver);
  36. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  37. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
  38. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  39. mod_tap_hold_key.release();
  40. run_one_scan_loop();
  41. testing::Mock::VerifyAndClearExpectations(&driver);
  42. }
  43. TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) {
  44. TestDriver driver;
  45. InSequence s;
  46. auto key_shift_hold_p_tap = KeymapKey(0, 7, 0, SFT_T(KC_P));
  47. set_keymap({key_shift_hold_p_tap});
  48. /* Press mod_tap_hold key */
  49. EXPECT_NO_REPORT(driver);
  50. key_shift_hold_p_tap.press();
  51. run_one_scan_loop();
  52. testing::Mock::VerifyAndClearExpectations(&driver);
  53. /* Release mod_tap_hold key */
  54. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
  55. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  56. key_shift_hold_p_tap.release();
  57. run_one_scan_loop();
  58. testing::Mock::VerifyAndClearExpectations(&driver);
  59. /* Press mod_tap_hold key again */
  60. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
  61. key_shift_hold_p_tap.press();
  62. run_one_scan_loop();
  63. testing::Mock::VerifyAndClearExpectations(&driver);
  64. /* Release mod_tap_hold key again */
  65. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  66. key_shift_hold_p_tap.release();
  67. idle_for(TAPPING_TERM + 1);
  68. testing::Mock::VerifyAndClearExpectations(&driver);
  69. /* Press mod_tap_hold key again */
  70. EXPECT_NO_REPORT(driver);
  71. key_shift_hold_p_tap.press();
  72. run_one_scan_loop();
  73. testing::Mock::VerifyAndClearExpectations(&driver);
  74. /* Release mod_tap_hold key again */
  75. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
  76. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  77. key_shift_hold_p_tap.release();
  78. idle_for(TAPPING_TERM + 1);
  79. testing::Mock::VerifyAndClearExpectations(&driver);
  80. /* Press mod_tap_hold key again */
  81. EXPECT_NO_REPORT(driver);
  82. key_shift_hold_p_tap.press();
  83. idle_for(TAPPING_TERM);
  84. testing::Mock::VerifyAndClearExpectations(&driver);
  85. /* Release mod_tap_hold key again */
  86. /* TODO: Why is KC_LSFT send? */
  87. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
  88. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  89. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
  90. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  91. key_shift_hold_p_tap.release();
  92. run_one_scan_loop();
  93. testing::Mock::VerifyAndClearExpectations(&driver);
  94. }