test.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #include "keyboard_report_util.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. TEST(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) {
  32. TestDriver driver;
  33. EXPECT_CALL(driver, send_keyboard_mock(_));
  34. keyboard_init();
  35. EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0));
  36. EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
  37. keyboard_task();
  38. }
  39. TEST(KeyPress, CorrectKeyIsReportedWhenPressed) {
  40. TestDriver driver;
  41. EXPECT_CALL(driver, send_keyboard_mock(_));
  42. keyboard_init();
  43. press_key(0, 0);
  44. EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0));
  45. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
  46. keyboard_task();
  47. }
  48. TEST(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) {
  49. TestDriver driver;
  50. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  51. keyboard_init();
  52. press_key(1, 0);
  53. press_key(0, 1);
  54. EXPECT_CALL(driver, keyboard_leds_mock()).WillRepeatedly(Return(0));
  55. //TODO: This is a left-over from the previous test and need to be fixed
  56. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
  57. keyboard_task();
  58. //Note that QMK only processes one key at a time
  59. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B)));
  60. keyboard_task();
  61. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C)));
  62. keyboard_task();
  63. }