keypress.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. }
  37. TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) {
  38. TestDriver driver;
  39. press_key(1, 0);
  40. press_key(0, 3);
  41. //Note that QMK only processes one key at a time
  42. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B)));
  43. keyboard_task();
  44. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C)));
  45. keyboard_task();
  46. }
  47. TEST_F(KeyPress, ANonMappedKeyDoesNothing) {
  48. TestDriver driver;
  49. press_key(2, 0);
  50. //Note that QMK only processes one key at a time
  51. EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
  52. keyboard_task();
  53. keyboard_task();
  54. }