qmk_firmware

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

test_one_shot_keys.cpp (2872B)


      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 "action_util.h"
     18 #include "keyboard_report_util.hpp"
     19 #include "test_common.hpp"
     20 
     21 using testing::_;
     22 using testing::InSequence;
     23 
     24 class OneShot : public TestFixture {};
     25 class OneShotParametrizedTestFixture : public ::testing::WithParamInterface<std::pair<KeymapKey, KeymapKey>>, public OneShot {};
     26 
     27 TEST_P(OneShotParametrizedTestFixture, OSMAsRegularModifierWithAdditionalKeypress) {
     28     TestDriver driver;
     29     KeymapKey  osm_key     = GetParam().first;
     30     KeymapKey  regular_key = GetParam().second;
     31 
     32     set_keymap({osm_key, regular_key});
     33 
     34     /* Press OSM */
     35     EXPECT_NO_REPORT(driver);
     36     osm_key.press();
     37     run_one_scan_loop();
     38     VERIFY_AND_CLEAR(driver);
     39 
     40     /* Press regular key */
     41     EXPECT_NO_REPORT(driver);
     42     regular_key.press();
     43     run_one_scan_loop();
     44     VERIFY_AND_CLEAR(driver);
     45 
     46     /* Release regular key */
     47     EXPECT_REPORT(driver, (osm_key.report_code)).Times(2);
     48     EXPECT_REPORT(driver, (regular_key.report_code, osm_key.report_code)).Times(1);
     49     regular_key.release();
     50     run_one_scan_loop();
     51     VERIFY_AND_CLEAR(driver);
     52 
     53     /* Release OSM */
     54     EXPECT_EMPTY_REPORT(driver).Times(1);
     55     osm_key.release();
     56     run_one_scan_loop();
     57     VERIFY_AND_CLEAR(driver);
     58 }
     59 
     60 // clang-format off
     61 
     62 INSTANTIATE_TEST_CASE_P(
     63     OneShotModifierTests,
     64     OneShotParametrizedTestFixture,
     65     ::testing::Values(
     66         /* first is osm key, second is regular key. */
     67         std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_LSFT), KC_LSFT}, KeymapKey{0, 1, 1, KC_A}),
     68         std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_LCTL), KC_LCTL}, KeymapKey{0, 1, 1, KC_A}),
     69         std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_LALT), KC_LALT}, KeymapKey{0, 1, 1, KC_A}),
     70         std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_LGUI), KC_LGUI}, KeymapKey{0, 1, 1, KC_A}),
     71         std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_RCTL), KC_RCTL}, KeymapKey{0, 1, 1, KC_A}),
     72         std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_RSFT), KC_RSFT}, KeymapKey{0, 1, 1, KC_A}),
     73         std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_RALT), KC_RALT}, KeymapKey{0, 1, 1, KC_A}),
     74         std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_RGUI), KC_RGUI}, KeymapKey{0, 1, 1, KC_A})
     75         ));
     76 // clang-format on