test_keypress.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. using testing::_;
  18. using testing::Return;
  19. class KeyPress : public TestFixture {};
  20. TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) {
  21. TestDriver driver;
  22. EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
  23. keyboard_task();
  24. }
  25. TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) {
  26. TestDriver driver;
  27. press_key(0, 0);
  28. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
  29. keyboard_task();
  30. release_key(0, 0);
  31. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  32. keyboard_task();
  33. }
  34. TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) {
  35. TestDriver driver;
  36. press_key(1, 0);
  37. press_key(0, 3);
  38. //Note that QMK only processes one key at a time
  39. //See issue #1476 for more information
  40. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B)));
  41. keyboard_task();
  42. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C)));
  43. keyboard_task();
  44. release_key(1, 0);
  45. release_key(0, 3);
  46. //Note that the first key released is the first one in the matrix order
  47. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_C)));
  48. keyboard_task();
  49. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  50. keyboard_task();
  51. }
  52. TEST_F(KeyPress, ANonMappedKeyDoesNothing) {
  53. TestDriver driver;
  54. press_key(2, 0);
  55. EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
  56. keyboard_task();
  57. keyboard_task();
  58. }
  59. TEST_F(KeyPress, LeftShiftIsReportedCorrectly) {
  60. TestDriver driver;
  61. press_key(3, 0);
  62. press_key(0, 0);
  63. // Unfortunately modifiers are also processed in the wrong order
  64. // See issue #1476 for more information
  65. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
  66. keyboard_task();
  67. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A, KC_LSFT)));
  68. keyboard_task();
  69. release_key(0, 0);
  70. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
  71. keyboard_task();
  72. release_key(3, 0);
  73. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  74. keyboard_task();
  75. }
  76. TEST_F(KeyPress, PressLeftShiftAndControl) {
  77. TestDriver driver;
  78. press_key(3, 0);
  79. press_key(5, 0);
  80. // Unfortunately modifiers are also processed in the wrong order
  81. // See issue #1476 for more information
  82. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
  83. keyboard_task();
  84. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_LCTRL)));
  85. keyboard_task();
  86. }
  87. TEST_F(KeyPress, LeftAndRightShiftCanBePressedAtTheSameTime) {
  88. TestDriver driver;
  89. press_key(3, 0);
  90. press_key(4, 0);
  91. // Unfortunately modifiers are also processed in the wrong order
  92. // See issue #1476 for more information
  93. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
  94. keyboard_task();
  95. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_RSFT)));
  96. keyboard_task();
  97. }
  98. TEST_F(KeyPress, RightShiftLeftControlAndCharWithTheSameKey) {
  99. TestDriver driver;
  100. press_key(6, 0);
  101. // BUG: The press is split into two reports
  102. // BUG: It reports RSFT instead of LSFT
  103. // See issue #524 for more information
  104. // The underlying cause is that we use only one bit to represent the right hand
  105. // modifiers.
  106. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL)));
  107. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL, KC_O)));
  108. keyboard_task();
  109. release_key(6, 0);
  110. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL)));
  111. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  112. keyboard_task();
  113. }