test_caps_word_autoshift.cpp (2175B)
1 // Copyright 2022 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::_; 23 using ::testing::AnyNumber; 24 using ::testing::AnyOf; 25 using ::testing::InSequence; 26 27 class CapsWord : public TestFixture { 28 public: 29 void SetUp() override { 30 caps_word_off(); 31 } 32 }; 33 34 // Tests that with Auto Shift, letter keys are shifted by Caps Word 35 // regardless of whether they are released before AUTO_SHIFT_TIMEOUT. 36 TEST_F(CapsWord, AutoShiftKeys) { 37 TestDriver driver; 38 KeymapKey key_a(0, 0, 0, KC_A); 39 KeymapKey key_spc(0, 1, 0, KC_SPC); 40 set_keymap({key_a, key_spc}); 41 42 // Allow any number of reports with no keys or only KC_LSFT. 43 // clang-format off 44 EXPECT_CALL(driver, send_keyboard_mock(AnyOf( 45 KeyboardReport(), 46 KeyboardReport(KC_LSFT)))) 47 .Times(AnyNumber()); 48 // clang-format on 49 { // Expect: "A, A, space, a". 50 InSequence s; 51 EXPECT_REPORT(driver, (KC_LSFT, KC_A)); 52 EXPECT_REPORT(driver, (KC_LSFT, KC_A)); 53 EXPECT_REPORT(driver, (KC_SPC)); 54 EXPECT_REPORT(driver, (KC_A)); 55 } 56 57 // Turn on Caps Word and type "A (quick tap), A (long press), space, A". 58 caps_word_on(); 59 60 tap_key(key_a); // Tap A quickly. 61 tap_key(key_a, AUTO_SHIFT_TIMEOUT + 1); // Long press A. 62 tap_key(key_spc); 63 tap_key(key_a); 64 65 testing::Mock::VerifyAndClearExpectations(&driver); 66 }