qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

test_tap_hold.cpp (4108B)


      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_fixture.hpp"
     22 #include "test_keymap_key.hpp"
     23 
     24 using testing::_;
     25 using testing::InSequence;
     26 class PermissiveHold : public TestFixture {};
     27 
     28 TEST_F(PermissiveHold, tap_regular_key_while_mod_tap_key_is_held) {
     29     TestDriver driver;
     30     InSequence s;
     31     auto       mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P));
     32     auto       regular_key      = KeymapKey(0, 2, 0, KC_A);
     33 
     34     set_keymap({mod_tap_hold_key, regular_key});
     35 
     36     /* Press mod-tap-hold key */
     37     EXPECT_NO_REPORT(driver);
     38     mod_tap_hold_key.press();
     39     run_one_scan_loop();
     40     VERIFY_AND_CLEAR(driver);
     41 
     42     /* Press regular key */
     43     EXPECT_NO_REPORT(driver);
     44     regular_key.press();
     45     run_one_scan_loop();
     46     VERIFY_AND_CLEAR(driver);
     47 
     48     /* Release regular key */
     49     EXPECT_REPORT(driver, (KC_LEFT_SHIFT));
     50     EXPECT_REPORT(driver, (KC_LEFT_SHIFT, regular_key.report_code));
     51     EXPECT_REPORT(driver, (KC_LEFT_SHIFT));
     52     regular_key.release();
     53     run_one_scan_loop();
     54     VERIFY_AND_CLEAR(driver);
     55 
     56     /* Release mod-tap-hold key */
     57     EXPECT_EMPTY_REPORT(driver);
     58     mod_tap_hold_key.release();
     59     run_one_scan_loop();
     60     VERIFY_AND_CLEAR(driver);
     61 }
     62 
     63 TEST_F(PermissiveHold, tap_a_mod_tap_key_while_another_mod_tap_key_is_held) {
     64     TestDriver driver;
     65     InSequence s;
     66     auto       first_mod_tap_hold_key  = KeymapKey(0, 1, 0, SFT_T(KC_P));
     67     auto       second_mod_tap_hold_key = KeymapKey(0, 2, 0, RSFT_T(KC_A));
     68 
     69     set_keymap({first_mod_tap_hold_key, second_mod_tap_hold_key});
     70 
     71     /* Press first mod-tap-hold key */
     72     EXPECT_NO_REPORT(driver);
     73     first_mod_tap_hold_key.press();
     74     run_one_scan_loop();
     75     VERIFY_AND_CLEAR(driver);
     76 
     77     /* Press second mod-tap-hold key */
     78     EXPECT_NO_REPORT(driver);
     79     second_mod_tap_hold_key.press();
     80     run_one_scan_loop();
     81     VERIFY_AND_CLEAR(driver);
     82 
     83     /* Release second mod-tap-hold key */
     84     EXPECT_REPORT(driver, (KC_LEFT_SHIFT));
     85     EXPECT_REPORT(driver, (KC_LEFT_SHIFT, second_mod_tap_hold_key.report_code));
     86     EXPECT_REPORT(driver, (KC_LEFT_SHIFT));
     87     second_mod_tap_hold_key.release();
     88     run_one_scan_loop();
     89     VERIFY_AND_CLEAR(driver);
     90 
     91     /* Release first mod-tap-hold key */
     92     EXPECT_EMPTY_REPORT(driver);
     93     first_mod_tap_hold_key.release();
     94     run_one_scan_loop();
     95     VERIFY_AND_CLEAR(driver);
     96 }
     97 
     98 TEST_F(PermissiveHold, tap_regular_key_while_layer_tap_key_is_held) {
     99     TestDriver driver;
    100     InSequence s;
    101     auto       layer_tap_hold_key = KeymapKey(0, 1, 0, LT(1, KC_P));
    102     auto       regular_key        = KeymapKey(0, 2, 0, KC_A);
    103     auto       layer_key          = KeymapKey(1, 2, 0, KC_B);
    104 
    105     set_keymap({layer_tap_hold_key, regular_key, layer_key});
    106 
    107     /* Press layer-tap-hold key */
    108     EXPECT_NO_REPORT(driver);
    109     layer_tap_hold_key.press();
    110     run_one_scan_loop();
    111     VERIFY_AND_CLEAR(driver);
    112 
    113     /* Press regular key */
    114     EXPECT_NO_REPORT(driver);
    115     regular_key.press();
    116     run_one_scan_loop();
    117     VERIFY_AND_CLEAR(driver);
    118 
    119     /* Release regular key */
    120     EXPECT_REPORT(driver, (layer_key.report_code));
    121     EXPECT_EMPTY_REPORT(driver);
    122     regular_key.release();
    123     run_one_scan_loop();
    124     VERIFY_AND_CLEAR(driver);
    125 
    126     /* Release layer-tap-hold key */
    127     EXPECT_NO_REPORT(driver);
    128     layer_tap_hold_key.release();
    129     run_one_scan_loop();
    130     VERIFY_AND_CLEAR(driver);
    131 }