test_tapping.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. TestDriver driver;
  47. InSequence s;
  48. press_key(7, 0);
  49. // Tapping keys does nothing on press
  50. EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
  51. run_one_scan_loop();
  52. release_key(7, 0);
  53. // First we get the key press
  54. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
  55. // Then the release
  56. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  57. run_one_scan_loop();
  58. // This sends KC_P, even if it should do nothing
  59. press_key(7, 0);
  60. // This test should not succed if everything works correctly
  61. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
  62. run_one_scan_loop();
  63. release_key(7, 0);
  64. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  65. idle_for(TAPPING_TERM + 1);
  66. // On the other hand, nothing is sent if we are outside the tapping term
  67. press_key(7, 0);
  68. EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
  69. run_one_scan_loop();
  70. release_key(7, 0);
  71. // First we get the key press
  72. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
  73. // Then the release
  74. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  75. idle_for(TAPPING_TERM + 1);
  76. // Now we are geting into strange territory, as the hold registers too early here
  77. // But the stranges part is:
  78. // If TAPPING_TERM + 1 above is changed to TAPPING_TERM or TAPPING_TERM + 2 it doesn't
  79. press_key(7, 0);
  80. // Shouldn't be called here really
  81. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).Times(1);
  82. idle_for(TAPPING_TERM);
  83. }