keypress.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. }