test.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 "keyboard.h"
  20. #include "test_driver.h"
  21. #include "test_matrix.h"
  22. using testing::_;
  23. using testing::Return;
  24. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  25. [0] = {
  26. {KC_A, KC_B},
  27. {KC_C, KC_D}
  28. },
  29. };
  30. TEST(Basic, SendKeyboardIsNotCalledWhenNoKeyIsPressed) {
  31. TestDriver driver;
  32. EXPECT_CALL(driver, send_keyboard_mock(_));
  33. keyboard_init();
  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(Basic, SendKeyboardIsCalledWhenAKeyIsPressed) {
  39. TestDriver driver;
  40. EXPECT_CALL(driver, send_keyboard_mock(_));
  41. keyboard_init();
  42. press_key(0, 0);
  43. EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0));
  44. EXPECT_CALL(driver, send_keyboard_mock(_));
  45. keyboard_task();
  46. }