test_tap_hold.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_fixture.hpp"
  21. #include "test_keymap_key.hpp"
  22. using testing::_;
  23. using testing::InSequence;
  24. class PermissiveHold : public TestFixture {};
  25. TEST_F(PermissiveHold, tap_regular_key_while_mod_tap_key_is_held) {
  26. TestDriver driver;
  27. InSequence s;
  28. auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P));
  29. auto regular_key = KeymapKey(0, 2, 0, KC_A);
  30. set_keymap({mod_tap_hold_key, regular_key});
  31. /* Press mod-tap-hold key */
  32. EXPECT_NO_REPORT(driver);
  33. mod_tap_hold_key.press();
  34. run_one_scan_loop();
  35. testing::Mock::VerifyAndClearExpectations(&driver);
  36. /* Press regular key */
  37. EXPECT_NO_REPORT(driver);
  38. regular_key.press();
  39. run_one_scan_loop();
  40. testing::Mock::VerifyAndClearExpectations(&driver);
  41. /* Release regular key */
  42. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT)));
  43. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT, regular_key.report_code)));
  44. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT)));
  45. regular_key.release();
  46. run_one_scan_loop();
  47. testing::Mock::VerifyAndClearExpectations(&driver);
  48. /* Release mod-tap-hold key */
  49. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  50. mod_tap_hold_key.release();
  51. run_one_scan_loop();
  52. testing::Mock::VerifyAndClearExpectations(&driver);
  53. }
  54. TEST_F(PermissiveHold, tap_mod_tap_key_while_mod_tap_key_is_held) {
  55. TestDriver driver;
  56. InSequence s;
  57. auto first_mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P));
  58. auto second_mod_tap_hold_key = KeymapKey(0, 2, 0, RSFT_T(KC_A));
  59. set_keymap({first_mod_tap_hold_key, second_mod_tap_hold_key});
  60. /* Press first mod-tap-hold key */
  61. EXPECT_NO_REPORT(driver);
  62. first_mod_tap_hold_key.press();
  63. run_one_scan_loop();
  64. testing::Mock::VerifyAndClearExpectations(&driver);
  65. /* Press second mod-tap-hold key */
  66. EXPECT_NO_REPORT(driver);
  67. second_mod_tap_hold_key.press();
  68. run_one_scan_loop();
  69. testing::Mock::VerifyAndClearExpectations(&driver);
  70. /* Release second mod-tap-hold key */
  71. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT)));
  72. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT, second_mod_tap_hold_key.report_code)));
  73. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT)));
  74. second_mod_tap_hold_key.release();
  75. run_one_scan_loop();
  76. testing::Mock::VerifyAndClearExpectations(&driver);
  77. /* Release first mod-tap-hold key */
  78. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  79. first_mod_tap_hold_key.release();
  80. run_one_scan_loop();
  81. testing::Mock::VerifyAndClearExpectations(&driver);
  82. }
  83. TEST_F(PermissiveHold, tap_regular_key_while_layer_tap_key_is_held) {
  84. TestDriver driver;
  85. InSequence s;
  86. auto layer_tap_hold_key = KeymapKey(0, 1, 0, LT(1, KC_P));
  87. auto regular_key = KeymapKey(0, 2, 0, KC_A);
  88. auto layer_key = KeymapKey(1, 2, 0, KC_B);
  89. set_keymap({layer_tap_hold_key, regular_key, layer_key});
  90. /* Press layer-tap-hold key */
  91. EXPECT_NO_REPORT(driver);
  92. layer_tap_hold_key.press();
  93. run_one_scan_loop();
  94. testing::Mock::VerifyAndClearExpectations(&driver);
  95. /* Press regular key */
  96. EXPECT_NO_REPORT(driver);
  97. regular_key.press();
  98. run_one_scan_loop();
  99. testing::Mock::VerifyAndClearExpectations(&driver);
  100. /* Release regular key */
  101. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(layer_key.report_code)));
  102. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  103. regular_key.release();
  104. run_one_scan_loop();
  105. testing::Mock::VerifyAndClearExpectations(&driver);
  106. /* Release layer-tap-hold key */
  107. EXPECT_NO_REPORT(driver);
  108. layer_tap_hold_key.release();
  109. run_one_scan_loop();
  110. testing::Mock::VerifyAndClearExpectations(&driver);
  111. }