From 46844347c4f4b5f8b50ea22dd06c7555a86fc94b Mon Sep 17 00:00:00 2001 From: Kasimir Pihlasviita Date: Mon, 3 Apr 2023 08:38:44 +0300 Subject: Fix OSMs getting stuck (#20034) --- tests/basic/test_one_shot_keys.cpp | 144 +++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) (limited to 'tests/basic') diff --git a/tests/basic/test_one_shot_keys.cpp b/tests/basic/test_one_shot_keys.cpp index 2401c2c837..2a3434bf16 100644 --- a/tests/basic/test_one_shot_keys.cpp +++ b/tests/basic/test_one_shot_keys.cpp @@ -160,6 +160,150 @@ INSTANTIATE_TEST_CASE_P( )); // clang-format on +TEST_F(OneShot, OSMChainingTwoOSMs) { + TestDriver driver; + InSequence s; + KeymapKey osm_key1 = KeymapKey{0, 0, 0, OSM(MOD_LSFT), KC_LSFT}; + KeymapKey osm_key2 = KeymapKey{0, 0, 1, OSM(MOD_LCTL), KC_LCTL}; + KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A}; + + set_keymap({osm_key1, osm_key2, regular_key}); + + /* Press and release OSM1 */ + EXPECT_NO_REPORT(driver); + osm_key1.press(); + run_one_scan_loop(); + osm_key1.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Press and relesea OSM2 */ + EXPECT_NO_REPORT(driver); + osm_key2.press(); + run_one_scan_loop(); + osm_key2.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Press regular key */ + EXPECT_REPORT(driver, (osm_key1.report_code, osm_key2.report_code, regular_key.report_code)).Times(1); + 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, OSMDoubleTapNotLockingOSMs) { + TestDriver driver; + InSequence s; + KeymapKey osm_key1 = KeymapKey{0, 0, 0, OSM(MOD_LSFT), KC_LSFT}; + KeymapKey osm_key2 = KeymapKey{0, 0, 1, OSM(MOD_LCTL), KC_LCTL}; + KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A}; + + set_keymap({osm_key1, osm_key2, regular_key}); + + /* Press and release OSM1 */ + EXPECT_NO_REPORT(driver); + osm_key1.press(); + run_one_scan_loop(); + osm_key1.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Press and release OSM2 twice */ + EXPECT_NO_REPORT(driver); + osm_key2.press(); + run_one_scan_loop(); + osm_key2.release(); + run_one_scan_loop(); + osm_key2.press(); + run_one_scan_loop(); + osm_key2.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Press regular key */ + EXPECT_REPORT(driver, (osm_key1.report_code, osm_key2.report_code, regular_key.report_code)).Times(1); + 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); + + /* Press regular key */ + EXPECT_REPORT(driver, (regular_key.report_code)).Times(1); + 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, OSMHoldNotLockingOSMs) { + TestDriver driver; + InSequence s; + KeymapKey osm_key1 = KeymapKey{0, 0, 0, OSM(MOD_LSFT), KC_LSFT}; + KeymapKey osm_key2 = KeymapKey{0, 0, 1, OSM(MOD_LCTL), KC_LCTL}; + KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A}; + + set_keymap({osm_key1, osm_key2, regular_key}); + + /* Press and release OSM1 */ + EXPECT_NO_REPORT(driver); + osm_key1.press(); + run_one_scan_loop(); + osm_key1.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Press and hold OSM2 */ + EXPECT_REPORT(driver, (osm_key1.report_code, osm_key2.report_code)).Times(1); + osm_key2.press(); + run_one_scan_loop(); + idle_for(TAPPING_TERM); + VERIFY_AND_CLEAR(driver); + + /* Press and release regular key */ + EXPECT_REPORT(driver, (osm_key1.report_code, osm_key2.report_code, regular_key.report_code)).Times(1); + EXPECT_REPORT(driver, (osm_key2.report_code)).Times(1); + regular_key.press(); + run_one_scan_loop(); + regular_key.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Release OSM2 */ + EXPECT_EMPTY_REPORT(driver); + osm_key2.release(); + run_one_scan_loop(); + VERIFY_AND_CLEAR(driver); + + /* Press regular key */ + EXPECT_REPORT(driver, (regular_key.report_code)).Times(1); + 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; -- cgit v1.2.3