test_tapping.cpp (3245B)
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 17 #include "keyboard_report_util.hpp" 18 #include "keycode.h" 19 #include "test_common.hpp" 20 #include "action_tapping.h" 21 #include "test_keymap_key.hpp" 22 23 using testing::_; 24 using testing::InSequence; 25 26 class Tapping : public TestFixture {}; 27 28 TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) { 29 TestDriver driver; 30 InSequence s; 31 auto mod_tap_hold_key = KeymapKey(0, 7, 0, SFT_T(KC_P)); 32 33 set_keymap({mod_tap_hold_key}); 34 35 EXPECT_NO_REPORT(driver); 36 mod_tap_hold_key.press(); 37 idle_for(TAPPING_TERM); 38 VERIFY_AND_CLEAR(driver); 39 40 EXPECT_REPORT(driver, (KC_LSFT)); 41 run_one_scan_loop(); 42 VERIFY_AND_CLEAR(driver); 43 44 EXPECT_EMPTY_REPORT(driver); 45 EXPECT_REPORT(driver, (KC_P)); 46 EXPECT_EMPTY_REPORT(driver); 47 mod_tap_hold_key.release(); 48 run_one_scan_loop(); 49 VERIFY_AND_CLEAR(driver); 50 } 51 52 TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) { 53 TestDriver driver; 54 InSequence s; 55 auto key_shift_hold_p_tap = KeymapKey(0, 7, 0, SFT_T(KC_P)); 56 57 set_keymap({key_shift_hold_p_tap}); 58 59 /* Press mod_tap_hold key */ 60 EXPECT_NO_REPORT(driver); 61 key_shift_hold_p_tap.press(); 62 run_one_scan_loop(); 63 VERIFY_AND_CLEAR(driver); 64 65 /* Release mod_tap_hold key */ 66 EXPECT_REPORT(driver, (KC_P)); 67 EXPECT_EMPTY_REPORT(driver); 68 key_shift_hold_p_tap.release(); 69 run_one_scan_loop(); 70 VERIFY_AND_CLEAR(driver); 71 72 /* Press mod_tap_hold key again */ 73 EXPECT_REPORT(driver, (KC_P)); 74 key_shift_hold_p_tap.press(); 75 run_one_scan_loop(); 76 VERIFY_AND_CLEAR(driver); 77 78 /* Release mod_tap_hold key again */ 79 EXPECT_EMPTY_REPORT(driver); 80 key_shift_hold_p_tap.release(); 81 idle_for(TAPPING_TERM + 1); 82 VERIFY_AND_CLEAR(driver); 83 84 /* Press mod_tap_hold key again */ 85 EXPECT_NO_REPORT(driver); 86 key_shift_hold_p_tap.press(); 87 run_one_scan_loop(); 88 VERIFY_AND_CLEAR(driver); 89 90 /* Release mod_tap_hold key again */ 91 EXPECT_REPORT(driver, (KC_P)); 92 EXPECT_EMPTY_REPORT(driver); 93 key_shift_hold_p_tap.release(); 94 idle_for(TAPPING_TERM + 1); 95 VERIFY_AND_CLEAR(driver); 96 97 /* Press mod_tap_hold key again */ 98 EXPECT_NO_REPORT(driver); 99 key_shift_hold_p_tap.press(); 100 idle_for(TAPPING_TERM); 101 VERIFY_AND_CLEAR(driver); 102 103 /* Release mod_tap_hold key again */ 104 /* TODO: Why is KC_LSFT send? */ 105 EXPECT_REPORT(driver, (KC_LSFT)); 106 EXPECT_EMPTY_REPORT(driver); 107 EXPECT_REPORT(driver, (KC_P)); 108 EXPECT_EMPTY_REPORT(driver); 109 key_shift_hold_p_tap.release(); 110 run_one_scan_loop(); 111 VERIFY_AND_CLEAR(driver); 112 }