test_fixture.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 "action_layer.h"
  10. }
  11. extern "C" {
  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. TestDriver driver;
  21. EXPECT_CALL(driver, send_keyboard_mock(_));
  22. keyboard_init();
  23. }
  24. void TestFixture::TearDownTestCase() {}
  25. TestFixture::TestFixture() {}
  26. TestFixture::~TestFixture() {
  27. TestDriver driver;
  28. // Run for a while to make sure all keys are completely released
  29. EXPECT_CALL(driver, send_keyboard_mock(_)).Times(AnyNumber());
  30. layer_clear();
  31. clear_all_keys();
  32. idle_for(TAPPING_TERM + 10);
  33. testing::Mock::VerifyAndClearExpectations(&driver);
  34. // Verify that the matrix really is cleared
  35. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(0);
  36. idle_for(TAPPING_TERM + 10);
  37. }
  38. void TestFixture::run_one_scan_loop() {
  39. keyboard_task();
  40. advance_time(1);
  41. }
  42. void TestFixture::idle_for(unsigned time) {
  43. for (unsigned i = 0; i < time; i++) {
  44. run_one_scan_loop();
  45. }
  46. }