qmk_firmware

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

test_repeat_key_combo.cpp (1883B)


      1 // Copyright 2023 Google LLC
      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 #include "keyboard_report_util.hpp"
     17 #include "keycode.h"
     18 #include "test_common.hpp"
     19 #include "test_fixture.hpp"
     20 #include "test_keymap_key.hpp"
     21 
     22 using ::testing::AnyNumber;
     23 using ::testing::InSequence;
     24 
     25 namespace {
     26 
     27 class RepeatKey : public TestFixture {};
     28 
     29 // Tests repeating a combo, KC_X + KC_Y = KC_Q, by typing
     30 // "X, Repeat, Repeat, {X Y}, Repeat, Repeat". This produces "xxxqqq".
     31 TEST_F(RepeatKey, Combo) {
     32     TestDriver driver;
     33     KeymapKey  key_x(0, 0, 0, KC_X);
     34     KeymapKey  key_y(0, 1, 0, KC_Y);
     35     KeymapKey  key_repeat(0, 2, 0, QK_REP);
     36     set_keymap({key_x, key_y, key_repeat});
     37 
     38     // Allow any number of empty reports.
     39     EXPECT_EMPTY_REPORT(driver).Times(AnyNumber());
     40     {
     41         InSequence seq;
     42         EXPECT_REPORT(driver, (KC_X));
     43         EXPECT_REPORT(driver, (KC_X));
     44         EXPECT_REPORT(driver, (KC_X));
     45         EXPECT_REPORT(driver, (KC_Q));
     46         EXPECT_REPORT(driver, (KC_Q));
     47         EXPECT_REPORT(driver, (KC_Q));
     48     }
     49 
     50     tap_keys(key_x, key_repeat, key_repeat);
     51     tap_combo({key_x, key_y});
     52 
     53     EXPECT_KEYCODE_EQ(get_last_keycode(), KC_Q);
     54 
     55     tap_keys(key_repeat, key_repeat);
     56 
     57     testing::Mock::VerifyAndClearExpectations(&driver);
     58 }
     59 
     60 } // namespace