test_fixture.cpp 1.2 KB

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