logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

test_auto_shift.cpp (3654B)


  1. /* Copyright 2022 Isaac Elenbaas
  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::AnyNumber;
  24. using testing::InSequence;
  25. class AutoShiftRepeat : public TestFixture {};
  26. TEST_F(AutoShiftRepeat, tap_regular_key_cancelling_another_key_hold) {
  27. TestDriver driver;
  28. InSequence s;
  29. auto repeat_key = KeymapKey(0, 1, 0, KC_P);
  30. auto regular_key = KeymapKey(0, 2, 0, KC_A);
  31. set_keymap({repeat_key, regular_key});
  32. /* Press repeat key. */
  33. EXPECT_NO_REPORT(driver);
  34. repeat_key.press();
  35. run_one_scan_loop();
  36. testing::Mock::VerifyAndClearExpectations(&driver);
  37. /* Press regular key. */
  38. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(testing::AnyNumber());
  39. EXPECT_REPORT(driver, (KC_P));
  40. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(testing::AnyNumber());
  41. regular_key.press();
  42. run_one_scan_loop();
  43. testing::Mock::VerifyAndClearExpectations(&driver);
  44. /* Release regular key. */
  45. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(testing::AnyNumber());
  46. EXPECT_REPORT(driver, (KC_A));
  47. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(testing::AnyNumber());
  48. regular_key.release();
  49. run_one_scan_loop();
  50. testing::Mock::VerifyAndClearExpectations(&driver);
  51. /* Release repeat key. */
  52. EXPECT_NO_REPORT(driver);
  53. repeat_key.release();
  54. run_one_scan_loop();
  55. testing::Mock::VerifyAndClearExpectations(&driver);
  56. }
  57. TEST_F(AutoShiftRepeat, tap_regular_key_while_another_key_is_held) {
  58. TestDriver driver;
  59. InSequence s;
  60. auto repeat_key = KeymapKey(0, 1, 0, KC_P);
  61. auto regular_key = KeymapKey(0, 2, 0, KC_A);
  62. set_keymap({repeat_key, regular_key});
  63. /* Press repeat key. */
  64. EXPECT_NO_REPORT(driver);
  65. repeat_key.press();
  66. run_one_scan_loop();
  67. testing::Mock::VerifyAndClearExpectations(&driver);
  68. /* Idle for auto-repeat to kick in. */
  69. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).Times(AnyNumber());
  70. EXPECT_REPORT(driver, (KC_LSFT, KC_P));
  71. idle_for(AUTO_SHIFT_TIMEOUT);
  72. run_one_scan_loop();
  73. testing::Mock::VerifyAndClearExpectations(&driver);
  74. /* Press regular key. */
  75. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).Times(AnyNumber());
  76. EXPECT_NO_REPORT(driver);
  77. regular_key.press();
  78. run_one_scan_loop();
  79. testing::Mock::VerifyAndClearExpectations(&driver);
  80. /* Release regular key. */
  81. EXPECT_REPORT(driver, (KC_P, KC_A));
  82. EXPECT_REPORT(driver, (KC_P));
  83. regular_key.release();
  84. run_one_scan_loop();
  85. testing::Mock::VerifyAndClearExpectations(&driver);
  86. /* Release repeat key. */
  87. EXPECT_EMPTY_REPORT(driver);
  88. repeat_key.release();
  89. run_one_scan_loop();
  90. testing::Mock::VerifyAndClearExpectations(&driver);
  91. }