keypress.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 "gtest/gtest.h"
  17. #include "gmock/gmock.h"
  18. #include "quantum.h"
  19. #include "test_driver.h"
  20. #include "test_matrix.h"
  21. #include "keyboard_report_util.h"
  22. #include "test_fixture.h"
  23. using testing::_;
  24. using testing::Return;
  25. class KeyPress : public TestFixture {};
  26. TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) {
  27. TestDriver driver;
  28. EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
  29. keyboard_task();
  30. }
  31. TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) {
  32. TestDriver driver;
  33. press_key(0, 0);
  34. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
  35. keyboard_task();
  36. release_key(0, 0);
  37. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  38. keyboard_task();
  39. }
  40. TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) {
  41. TestDriver driver;
  42. press_key(1, 0);
  43. press_key(0, 3);
  44. //Note that QMK only processes one key at a time
  45. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B)));
  46. keyboard_task();
  47. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C)));
  48. keyboard_task();
  49. release_key(1, 0);
  50. release_key(0, 3);
  51. //Note that the first key released is the first one in the matrix order
  52. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_C)));
  53. keyboard_task();
  54. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  55. keyboard_task();
  56. }
  57. TEST_F(KeyPress, ANonMappedKeyDoesNothing) {
  58. TestDriver driver;
  59. press_key(2, 0);
  60. EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
  61. keyboard_task();
  62. keyboard_task();
  63. }
  64. TEST_F(KeyPress, LeftShiftIsReportedCorrectly) {
  65. TestDriver driver;
  66. press_key(3, 0);
  67. press_key(0, 0);
  68. // Unfortunately modifiers are also processed in the wrong order
  69. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
  70. keyboard_task();
  71. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A, KC_LSFT)));
  72. keyboard_task();
  73. release_key(0, 0);
  74. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
  75. keyboard_task();
  76. release_key(3, 0);
  77. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  78. keyboard_task();
  79. }