test_fixture.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "test_fixture.hpp"
  2. #include "gmock/gmock.h"
  3. #include "test_driver.hpp"
  4. #include "test_matrix.h"
  5. #include "keyboard.h"
  6. #include "action.h"
  7. #include "action_tapping.h"
  8. extern "C" {
  9. #include "debug.h"
  10. #include "eeconfig.h"
  11. #include "action_layer.h"
  12. void set_time(uint32_t t);
  13. void advance_time(uint32_t ms);
  14. }
  15. using testing::_;
  16. using testing::AnyNumber;
  17. using testing::Between;
  18. using testing::Return;
  19. void TestFixture::SetUpTestCase() {
  20. // The following is enough to bootstrap the values set in main
  21. eeconfig_init_quantum();
  22. eeconfig_update_debug(debug_config.raw);
  23. TestDriver driver;
  24. EXPECT_CALL(driver, send_keyboard_mock(_));
  25. keyboard_init();
  26. }
  27. void TestFixture::TearDownTestCase() {}
  28. TestFixture::TestFixture() {}
  29. TestFixture::~TestFixture() {
  30. TestDriver driver;
  31. // Run for a while to make sure all keys are completely released
  32. EXPECT_CALL(driver, send_keyboard_mock(_)).Times(AnyNumber());
  33. layer_clear();
  34. clear_all_keys();
  35. idle_for(TAPPING_TERM + 10);
  36. testing::Mock::VerifyAndClearExpectations(&driver);
  37. // Verify that the matrix really is cleared
  38. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(0);
  39. idle_for(TAPPING_TERM + 10);
  40. }
  41. void TestFixture::run_one_scan_loop() {
  42. keyboard_task();
  43. advance_time(1);
  44. }
  45. void TestFixture::idle_for(unsigned time) {
  46. for (unsigned i = 0; i < time; i++) {
  47. run_one_scan_loop();
  48. }
  49. }