logo

qmk_firmware

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

test_one_shot_keys.cpp (2918B)


  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 "action_util.h"
  17. #include "keyboard_report_util.hpp"
  18. #include "test_common.hpp"
  19. using testing::_;
  20. using testing::InSequence;
  21. class OneShot : public TestFixture {};
  22. TEST_F(OneShot, OSMWithoutAdditionalKeypressDoesNothing) {
  23. TestDriver driver;
  24. auto osm_key = KeymapKey(0, 0, 0, OSM(MOD_LSFT), KC_LSFT);
  25. set_keymap({osm_key});
  26. /* Press and release OSM key*/
  27. EXPECT_NO_REPORT(driver);
  28. osm_key.press();
  29. EXPECT_REPORT(driver, (osm_key.report_code));
  30. run_one_scan_loop();
  31. EXPECT_NO_REPORT(driver);
  32. osm_key.release();
  33. EXPECT_EMPTY_REPORT(driver);
  34. run_one_scan_loop();
  35. VERIFY_AND_CLEAR(driver);
  36. }
  37. TEST_F(OneShot, OSL_No_ReportPress) {
  38. TestDriver driver;
  39. auto osl_key = KeymapKey{0, 0, 0, OSL(1)};
  40. auto empty_key = KeymapKey{0, 1, 0, KC_NO};
  41. auto regular_key = KeymapKey{1, 1, 0, KC_A};
  42. set_keymap({osl_key, empty_key, regular_key});
  43. /* Press OSL key */
  44. EXPECT_NO_REPORT(driver);
  45. osl_key.press();
  46. run_one_scan_loop();
  47. VERIFY_AND_CLEAR(driver);
  48. /* Release OSL key */
  49. EXPECT_NO_REPORT(driver);
  50. osl_key.release();
  51. run_one_scan_loop();
  52. VERIFY_AND_CLEAR(driver);
  53. /* Press regular key */
  54. EXPECT_NO_REPORT(driver);
  55. regular_key.press();
  56. run_one_scan_loop();
  57. VERIFY_AND_CLEAR(driver);
  58. /* Release regular key */
  59. EXPECT_NO_REPORT(driver);
  60. regular_key.release();
  61. run_one_scan_loop();
  62. VERIFY_AND_CLEAR(driver);
  63. }
  64. TEST_F(OneShot, OSL_ReportPress) {
  65. TestDriver driver;
  66. auto osl_key = KeymapKey{0, 0, 0, OSL(1)};
  67. auto empty_key = KeymapKey{0, 1, 0, KC_NO};
  68. auto regular_key = KeymapKey{1, 1, 0, KC_A};
  69. set_keymap({osl_key, empty_key, regular_key});
  70. /* Press OSL key */
  71. osl_key.press();
  72. run_one_scan_loop();
  73. EXPECT_NO_REPORT(driver);
  74. /* Press regular key */
  75. regular_key.press();
  76. run_one_scan_loop();
  77. EXPECT_NO_REPORT(driver);
  78. /* Release regular key */
  79. regular_key.release();
  80. run_one_scan_loop();
  81. EXPECT_NO_REPORT(driver);
  82. /* Release OSL key */
  83. osl_key.release();
  84. run_one_scan_loop();
  85. EXPECT_NO_REPORT(driver);
  86. VERIFY_AND_CLEAR(driver);
  87. }