test.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  26. [0] = {
  27. {KC_A, KC_B},
  28. {KC_C, KC_D}
  29. },
  30. };
  31. class KeyPress : public TestFixture {};
  32. TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) {
  33. TestDriver driver;
  34. EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0));
  35. EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
  36. keyboard_task();
  37. }
  38. TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) {
  39. TestDriver driver;
  40. press_key(0, 0);
  41. EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0));
  42. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
  43. keyboard_task();
  44. }
  45. TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) {
  46. TestDriver driver;
  47. press_key(1, 0);
  48. press_key(0, 1);
  49. EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0));
  50. //Note that QMK only processes one key at a time
  51. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B)));
  52. keyboard_task();
  53. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C)));
  54. keyboard_task();
  55. }