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.

122 lines
4.0 KiB

  1. /* Copyright 2017 Fred Sundvik
  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, TapA_SHFT_T_KeyReportsKey) {
  25. TestDriver driver;
  26. InSequence s;
  27. auto key_shift_hold_p_tap = KeymapKey(0, 7, 0, SFT_T(KC_P));
  28. set_keymap({key_shift_hold_p_tap});
  29. // Tapping keys does nothing on press
  30. key_shift_hold_p_tap.press();
  31. EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
  32. run_one_scan_loop();
  33. // First we get the key press
  34. key_shift_hold_p_tap.release();
  35. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
  36. // Then the release
  37. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  38. run_one_scan_loop();
  39. }
  40. TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) {
  41. TestDriver driver;
  42. InSequence s;
  43. auto mod_tap_hold_key = KeymapKey(0, 7, 0, SFT_T(KC_P));
  44. set_keymap({mod_tap_hold_key});
  45. mod_tap_hold_key.press();
  46. // Tapping keys does nothing on press
  47. EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
  48. idle_for(TAPPING_TERM);
  49. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
  50. run_one_scan_loop();
  51. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  52. mod_tap_hold_key.release();
  53. run_one_scan_loop();
  54. }
  55. TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) {
  56. // See issue #1478 for more information
  57. TestDriver driver;
  58. InSequence s;
  59. auto key_shift_hold_p_tap = KeymapKey(0, 7, 0, SFT_T(KC_P));
  60. set_keymap({key_shift_hold_p_tap});
  61. // Tapping keys does nothing on press
  62. key_shift_hold_p_tap.press();
  63. EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
  64. run_one_scan_loop();
  65. key_shift_hold_p_tap.release();
  66. // First we get the key press
  67. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
  68. // Then the release
  69. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  70. run_one_scan_loop();
  71. // This sends KC_P, even if it should do nothing
  72. key_shift_hold_p_tap.press();
  73. // This test should not succed if everything works correctly
  74. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
  75. run_one_scan_loop();
  76. key_shift_hold_p_tap.release();
  77. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  78. idle_for(TAPPING_TERM + 1);
  79. // On the other hand, nothing is sent if we are outside the tapping term
  80. key_shift_hold_p_tap.press();
  81. EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
  82. run_one_scan_loop();
  83. key_shift_hold_p_tap.release();
  84. // First we get the key press
  85. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
  86. // Then the release
  87. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  88. idle_for(TAPPING_TERM + 1);
  89. // Now we are geting into strange territory, as the hold registers too early here
  90. // But the stranges part is:
  91. // If TAPPING_TERM + 1 above is changed to TAPPING_TERM or TAPPING_TERM + 2 it doesn't
  92. key_shift_hold_p_tap.press();
  93. // Shouldn't be called here really
  94. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).Times(1);
  95. idle_for(TAPPING_TERM);
  96. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  97. key_shift_hold_p_tap.release();
  98. run_one_scan_loop();
  99. }