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.

97 lines
3.2 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 "test_common.hpp"
  17. #include "action_tapping.h"
  18. using testing::_;
  19. using testing::InSequence;
  20. class Tapping : public TestFixture {};
  21. TEST_F(Tapping, TapA_SHFT_T_KeyReportsKey) {
  22. TestDriver driver;
  23. InSequence s;
  24. press_key(7, 0);
  25. // Tapping keys does nothing on press
  26. EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
  27. run_one_scan_loop();
  28. release_key(7, 0);
  29. // First we get the key press
  30. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
  31. // Then the release
  32. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  33. run_one_scan_loop();
  34. }
  35. TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) {
  36. TestDriver driver;
  37. InSequence s;
  38. press_key(7, 0);
  39. // Tapping keys does nothing on press
  40. EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
  41. idle_for(TAPPING_TERM);
  42. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
  43. run_one_scan_loop();
  44. }
  45. TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) {
  46. // See issue #1478 for more information
  47. TestDriver driver;
  48. InSequence s;
  49. press_key(7, 0);
  50. // Tapping keys does nothing on press
  51. EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
  52. run_one_scan_loop();
  53. release_key(7, 0);
  54. // First we get the key press
  55. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
  56. // Then the release
  57. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  58. run_one_scan_loop();
  59. // This sends KC_P, even if it should do nothing
  60. press_key(7, 0);
  61. // This test should not succed if everything works correctly
  62. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
  63. run_one_scan_loop();
  64. release_key(7, 0);
  65. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  66. idle_for(TAPPING_TERM + 1);
  67. // On the other hand, nothing is sent if we are outside the tapping term
  68. press_key(7, 0);
  69. EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
  70. run_one_scan_loop();
  71. release_key(7, 0);
  72. // First we get the key press
  73. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
  74. // Then the release
  75. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  76. idle_for(TAPPING_TERM + 1);
  77. // Now we are geting into strange territory, as the hold registers too early here
  78. // But the stranges part is:
  79. // If TAPPING_TERM + 1 above is changed to TAPPING_TERM or TAPPING_TERM + 2 it doesn't
  80. press_key(7, 0);
  81. // Shouldn't be called here really
  82. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).Times(1);
  83. idle_for(TAPPING_TERM);
  84. }