test_keymap_key.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* Copyright 2021 Stefan Kerkmann
  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 "test_keymap_key.hpp"
  17. #include <iomanip>
  18. #include <cstdint>
  19. #include <ios>
  20. #include "matrix.h"
  21. #include "test_logger.hpp"
  22. #include "gtest/gtest-message.h"
  23. #include "gtest/gtest.h"
  24. #include "timer.h"
  25. void KeymapKey::press() {
  26. EXPECT_FALSE(matrix_is_on(position.row, position.col)) << "tried to press key " << this->name << " that was already pressed! Check the test code." << std::endl;
  27. press_key(this->position.col, this->position.row);
  28. this->timestamp_pressed = timer_read32();
  29. test_logger.trace() << std::setw(10) << std::left << "pressed: " << this->name << std::endl;
  30. }
  31. void KeymapKey::release() {
  32. EXPECT_TRUE(matrix_is_on(this->position.row, this->position.col)) << "tried to release key " << this->name << " that wasn't pressed before! Check the test code." << std::endl;
  33. release_key(this->position.col, this->position.row);
  34. uint32_t now = timer_read32();
  35. test_logger.trace() << std::setw(10) << std::left << "released: " << this->name << " was pressed for " << now - this->timestamp_pressed << "ms" << std::endl;
  36. }