diff --git a/tests/basic/test_one_shot_keys.cpp b/tests/basic/test_one_shot_keys.cpp index 92db52f811e..1730d6cbb7d 100644 --- a/tests/basic/test_one_shot_keys.cpp +++ b/tests/basic/test_one_shot_keys.cpp @@ -15,8 +15,11 @@ */ #include "action_util.h" +#include "config.h" #include "keyboard_report_util.hpp" #include "test_common.hpp" +#include +#include using testing::_; using testing::InSequence; @@ -24,24 +27,19 @@ using testing::InSequence; class OneShot : public TestFixture {}; class OneShotParametrizedTestFixture : public ::testing::WithParamInterface>, public OneShot {}; -TEST_F(OneShot, OSMWithoutAdditionalKeypressDoesNothing) { +TEST_F(OneShot, OSMWithoutAdditionalKeypressSetsOneShotModsButDoesNotSendReport) { TestDriver driver; auto osm_key = KeymapKey(0, 0, 0, OSM(MOD_LSFT), KC_LSFT); + auto a_key = KeymapKey(0, 0, 0, KC_A); set_keymap({osm_key}); - /* Press and release OSM key*/ + /* Press and release OSM key should set one shot mods*/ EXPECT_NO_REPORT(driver); tap_key(osm_key); + EXPECT_EQ(get_oneshot_mods(), MOD_LSFT); VERIFY_AND_CLEAR(driver); - - /* OSM are added when an actual report is send */ - EXPECT_REPORT(driver, (osm_key.report_code)); - send_keyboard_report(); - VERIFY_AND_CLEAR(driver); - - /* Make unit-test pass */ - clear_oneshot_mods(); + clear_oneshot_mods(); // reset state } #if defined(ONESHOT_TIMEOUT) @@ -277,6 +275,47 @@ TEST_F(OneShot, OSMHoldNotLockingOSMs) { VERIFY_AND_CLEAR(driver); } +TEST_F(OneShot, OSMTapThenHoldNotLockingOSMs) { + TestDriver driver; + InSequence s; + KeymapKey osm_key = KeymapKey{0, 0, 0, OSM(MOD_LSFT), KC_LSFT}; + KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A}; + + set_keymap({osm_key, regular_key}); + + /* Press and release OSM */ + EXPECT_NO_REPORT(driver); + tap_key(osm_key); + VERIFY_AND_CLEAR(driver); + + /* Press and hold OSM */ + EXPECT_REPORT(driver, (osm_key.report_code)).Times(1); + osm_key.press(); + run_one_scan_loop(); + idle_for(TAPPING_TERM); + // EXPECT_EQ(get_oneshot_mods(), b02); // one shot mods should be disabled + VERIFY_AND_CLEAR(driver); + + /* Release OSM1 */ + EXPECT_EMPTY_REPORT(driver); + osm_key.release(); + run_one_scan_loop(); + // EXPECT_EQ(get_oneshot_mods(), 0); // one shot mods should be disabled + VERIFY_AND_CLEAR(driver); + + /* Press regular key */ + EXPECT_REPORT(driver, (regular_key.report_code)).Times(1); // no mod + regular_key.press(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Release regular key */ + EXPECT_EMPTY_REPORT(driver); + regular_key.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); +} + TEST_F(OneShot, OSLWithAdditionalKeypress) { TestDriver driver; InSequence s; @@ -686,4 +725,4 @@ TEST_F(OneShot, OSLWithLongModTapKeyAndRegularKey) { regular_key.release(); run_one_scan_loop(); VERIFY_AND_CLEAR(driver); -} \ No newline at end of file +}