logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

test_keymap_key.cpp (1736B)


  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 <cstdint>
  18. #include <ios>
  19. #include "matrix.h"
  20. #include "test_logger.hpp"
  21. #include "gtest/gtest-message.h"
  22. #include "gtest/gtest.h"
  23. #include "timer.h"
  24. void KeymapKey::press() {
  25. 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;
  26. press_key(this->position.col, this->position.row);
  27. this->timestamp_pressed = timer_read32();
  28. test_logger.trace() << std::setw(10) << std::left << "pressed: " << this->name << std::endl;
  29. }
  30. void KeymapKey::release() {
  31. 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;
  32. release_key(this->position.col, this->position.row);
  33. uint32_t now = timer_read32();
  34. test_logger.trace() << std::setw(10) << std::left << "released: " << this->name << " was pressed for " << now - this->timestamp_pressed << "ms" << std::endl;
  35. }