test_fixture.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. layer_clear();
  29. clear_all_keys();
  30. // Run for a while to make sure all keys are completely released
  31. EXPECT_CALL(driver, send_keyboard_mock(_)).Times(AnyNumber());
  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(Between(0, 1));
  36. }
  37. void TestFixture::run_one_scan_loop() {
  38. keyboard_task();
  39. advance_time(1);
  40. }
  41. void TestFixture::idle_for(unsigned time) {
  42. for (unsigned i = 0; i < time; i++) {
  43. run_one_scan_loop();
  44. }
  45. }