diff options
| author | Pascal Getreuer <50221757+getreuer@users.noreply.github.com> | 2023-04-03 16:11:26 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-04 09:11:26 +1000 |
| commit | ae63c0f509fae71270fb5885d504ee26cbad95ff (patch) | |
| tree | ddb9844e52d36bbcdb144e20ad349031fbdee034 /tests/caps_word | |
| parent | 368fee9655b8c0611808212b680674b5acd4349c (diff) | |
[Core] Caps Word "Invert on shift" option: pressing Shift inverts the shift state. (#20092)
Co-authored-by: Nick Brassel <nick@tzarc.org>
Diffstat (limited to 'tests/caps_word')
3 files changed, 253 insertions, 0 deletions
diff --git a/tests/caps_word/caps_word_invert_on_shift/config.h b/tests/caps_word/caps_word_invert_on_shift/config.h new file mode 100644 index 0000000000..7a3ec846f9 --- /dev/null +++ b/tests/caps_word/caps_word_invert_on_shift/config.h | |||
| @@ -0,0 +1,21 @@ | |||
| 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 | #pragma once | ||
| 17 | |||
| 18 | #include "test_common.h" | ||
| 19 | |||
| 20 | #define CAPS_WORD_INVERT_ON_SHIFT | ||
| 21 | #define PERMISSIVE_HOLD | ||
diff --git a/tests/caps_word/caps_word_invert_on_shift/test.mk b/tests/caps_word/caps_word_invert_on_shift/test.mk new file mode 100644 index 0000000000..319c04d67a --- /dev/null +++ b/tests/caps_word/caps_word_invert_on_shift/test.mk | |||
| @@ -0,0 +1,17 @@ | |||
| 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 | CAPS_WORD_ENABLE = yes | ||
| 17 | |||
diff --git a/tests/caps_word/caps_word_invert_on_shift/test_caps_word_invert_on_shift.cpp b/tests/caps_word/caps_word_invert_on_shift/test_caps_word_invert_on_shift.cpp new file mode 100644 index 0000000000..d322448181 --- /dev/null +++ b/tests/caps_word/caps_word_invert_on_shift/test_caps_word_invert_on_shift.cpp | |||
| @@ -0,0 +1,215 @@ | |||
| 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::_; | ||
| 23 | using ::testing::AnyNumber; | ||
| 24 | using ::testing::AnyOf; | ||
| 25 | using ::testing::InSequence; | ||
| 26 | using ::testing::TestParamInfo; | ||
| 27 | |||
| 28 | namespace { | ||
| 29 | |||
| 30 | struct ShiftKeyParams { | ||
| 31 | std::string name; | ||
| 32 | uint16_t keycode; | ||
| 33 | uint16_t report_shift_code; | ||
| 34 | |||
| 35 | static const std::string& GetName(const TestParamInfo<ShiftKeyParams>& info) { | ||
| 36 | return info.param.name; | ||
| 37 | } | ||
| 38 | }; | ||
| 39 | |||
| 40 | class CapsWordInvertOnShift : public ::testing::WithParamInterface<ShiftKeyParams>, public TestFixture { | ||
| 41 | void SetUp() override { | ||
| 42 | caps_word_off(); | ||
| 43 | } | ||
| 44 | }; | ||
| 45 | |||
| 46 | // With Caps Word on, type "A, 4, Shift(A, 4, A), A, Shift(A), 4". | ||
| 47 | TEST_P(CapsWordInvertOnShift, ShiftWithinWord) { | ||
| 48 | TestDriver driver; | ||
| 49 | KeymapKey key_shift(0, 0, 0, GetParam().keycode); | ||
| 50 | KeymapKey key_a(0, 1, 0, KC_A); | ||
| 51 | KeymapKey key_4(0, 2, 0, KC_4); | ||
| 52 | set_keymap({key_shift, key_a, key_4}); | ||
| 53 | |||
| 54 | // Allow any number of reports with no keys or only KC_LSFT. | ||
| 55 | // clang-format off | ||
| 56 | EXPECT_CALL(driver, send_keyboard_mock(AnyOf( | ||
| 57 | KeyboardReport(), | ||
| 58 | KeyboardReport(KC_LSFT)))) | ||
| 59 | .Times(AnyNumber()); | ||
| 60 | // clang-format on | ||
| 61 | |||
| 62 | { // Expect: "A4a$aAa4" | ||
| 63 | InSequence s; | ||
| 64 | EXPECT_REPORT(driver, (KC_LSFT, KC_A)); | ||
| 65 | EXPECT_REPORT(driver, (KC_4)); | ||
| 66 | EXPECT_REPORT(driver, (KC_A)); | ||
| 67 | EXPECT_REPORT(driver, (KC_LSFT, KC_4)); | ||
| 68 | EXPECT_REPORT(driver, (KC_A)); | ||
| 69 | EXPECT_REPORT(driver, (KC_LSFT, KC_A)); | ||
| 70 | EXPECT_REPORT(driver, (KC_A)); | ||
| 71 | EXPECT_REPORT(driver, (KC_4)); | ||
| 72 | } | ||
| 73 | |||
| 74 | caps_word_on(); | ||
| 75 | tap_keys(key_a, key_4); // Type "A, 4". | ||
| 76 | |||
| 77 | key_shift.press(); // Type "Shift(A, 4, A)". | ||
| 78 | run_one_scan_loop(); | ||
| 79 | tap_keys(key_a, key_4, key_a); | ||
| 80 | key_shift.release(); | ||
| 81 | run_one_scan_loop(); | ||
| 82 | |||
| 83 | tap_key(key_a); // Type "A". | ||
| 84 | |||
| 85 | key_shift.press(); // Type "Shift(A)". | ||
| 86 | run_one_scan_loop(); | ||
| 87 | tap_key(key_a); | ||
| 88 | key_shift.release(); | ||
| 89 | run_one_scan_loop(); | ||
| 90 | |||
| 91 | tap_key(key_4); // Type "4". | ||
| 92 | |||
| 93 | VERIFY_AND_CLEAR(driver); | ||
| 94 | } | ||
| 95 | |||
| 96 | TEST_P(CapsWordInvertOnShift, ShiftHeldAtWordEnd) { | ||
| 97 | TestDriver driver; | ||
| 98 | KeymapKey key_shift(0, 0, 0, GetParam().keycode); | ||
| 99 | KeymapKey key_a(0, 1, 0, KC_A); | ||
| 100 | KeymapKey key_slsh(0, 2, 0, KC_SLSH); | ||
| 101 | set_keymap({key_shift, key_a, key_slsh}); | ||
| 102 | |||
| 103 | // Allow any number of reports with no keys or only KC_LSFT. | ||
| 104 | // clang-format off | ||
| 105 | EXPECT_CALL(driver, send_keyboard_mock(AnyOf( | ||
| 106 | KeyboardReport(), | ||
| 107 | KeyboardReport(KC_LSFT), | ||
| 108 | KeyboardReport(KC_RSFT)))) | ||
| 109 | .Times(AnyNumber()); | ||
| 110 | // clang-format on | ||
| 111 | |||
| 112 | { // Expect: "Aa?A" | ||
| 113 | InSequence s; | ||
| 114 | EXPECT_REPORT(driver, (KC_LSFT, KC_A)); | ||
| 115 | EXPECT_REPORT(driver, (KC_A)); | ||
| 116 | EXPECT_REPORT(driver, (GetParam().report_shift_code, KC_SLSH)); | ||
| 117 | EXPECT_REPORT(driver, (GetParam().report_shift_code, KC_A)); | ||
| 118 | } | ||
| 119 | |||
| 120 | caps_word_on(); | ||
| 121 | tap_key(key_a); | ||
| 122 | |||
| 123 | key_shift.press(); // Press Shift. | ||
| 124 | run_one_scan_loop(); | ||
| 125 | |||
| 126 | EXPECT_EQ(get_mods(), 0); | ||
| 127 | |||
| 128 | tap_key(key_a); | ||
| 129 | tap_key(key_slsh); // Tap '/' key, which is word breaking, ending Caps Word. | ||
| 130 | |||
| 131 | EXPECT_FALSE(is_caps_word_on()); | ||
| 132 | EXPECT_EQ(get_mods(), MOD_BIT(GetParam().report_shift_code)); | ||
| 133 | |||
| 134 | tap_key(key_a); | ||
| 135 | key_shift.release(); // Release Shift. | ||
| 136 | run_one_scan_loop(); | ||
| 137 | |||
| 138 | EXPECT_EQ(get_mods(), 0); | ||
| 139 | VERIFY_AND_CLEAR(driver); | ||
| 140 | } | ||
| 141 | |||
| 142 | TEST_P(CapsWordInvertOnShift, TwoShiftsHeld) { | ||
| 143 | TestDriver driver; | ||
| 144 | KeymapKey key_shift1(0, 0, 0, GetParam().keycode); | ||
| 145 | KeymapKey key_shift2(0, 1, 0, GetParam().report_shift_code); | ||
| 146 | KeymapKey key_a(0, 2, 0, KC_A); | ||
| 147 | KeymapKey key_slsh(0, 3, 0, KC_SLSH); | ||
| 148 | set_keymap({key_shift1, key_shift2, key_a, key_slsh}); | ||
| 149 | |||
| 150 | // Allow any number of reports with no keys or only KC_LSFT. | ||
| 151 | // clang-format off | ||
| 152 | EXPECT_CALL(driver, send_keyboard_mock(AnyOf( | ||
| 153 | KeyboardReport(), | ||
| 154 | KeyboardReport(KC_LSFT), | ||
| 155 | KeyboardReport(KC_RSFT)))) | ||
| 156 | .Times(AnyNumber()); | ||
| 157 | // clang-format on | ||
| 158 | |||
| 159 | { // Expect: "Aa?a" | ||
| 160 | InSequence s; | ||
| 161 | EXPECT_REPORT(driver, (KC_LSFT, KC_A)); | ||
| 162 | EXPECT_REPORT(driver, (KC_A)); | ||
| 163 | EXPECT_REPORT(driver, (GetParam().report_shift_code, KC_SLSH)); | ||
| 164 | EXPECT_REPORT(driver, (KC_A)); | ||
| 165 | } | ||
| 166 | |||
| 167 | caps_word_on(); | ||
| 168 | tap_key(key_a); | ||
| 169 | |||
| 170 | key_shift1.press(); // Press shift1. | ||
| 171 | run_one_scan_loop(); | ||
| 172 | |||
| 173 | EXPECT_EQ(get_mods(), 0); | ||
| 174 | |||
| 175 | tap_key(key_a); | ||
| 176 | tap_key(key_slsh); // Tap '/' key, which is word breaking, ending Caps Word. | ||
| 177 | |||
| 178 | EXPECT_FALSE(is_caps_word_on()); | ||
| 179 | EXPECT_EQ(get_mods(), MOD_BIT(GetParam().report_shift_code)); | ||
| 180 | |||
| 181 | key_shift2.press(); // Press shift2. | ||
| 182 | run_one_scan_loop(); | ||
| 183 | |||
| 184 | EXPECT_EQ(get_mods(), MOD_BIT(GetParam().report_shift_code)); | ||
| 185 | |||
| 186 | key_shift1.release(); // Release shift1. | ||
| 187 | run_one_scan_loop(); | ||
| 188 | |||
| 189 | EXPECT_EQ(get_mods(), 0); | ||
| 190 | tap_key(key_a); | ||
| 191 | |||
| 192 | key_shift2.release(); // Release shift2. | ||
| 193 | run_one_scan_loop(); | ||
| 194 | |||
| 195 | EXPECT_EQ(get_mods(), 0); | ||
| 196 | VERIFY_AND_CLEAR(driver); | ||
| 197 | } | ||
| 198 | |||
| 199 | // clang-format off | ||
| 200 | INSTANTIATE_TEST_CASE_P( | ||
| 201 | Shifts, | ||
| 202 | CapsWordInvertOnShift, | ||
| 203 | ::testing::Values( | ||
| 204 | ShiftKeyParams{"KC_LSFT", KC_LSFT, KC_LSFT}, | ||
| 205 | ShiftKeyParams{"KC_RSFT", KC_RSFT, KC_RSFT}, | ||
| 206 | ShiftKeyParams{"LSFT_T", LSFT_T(KC_A), KC_LSFT}, | ||
| 207 | ShiftKeyParams{"RSFT_T", RSFT_T(KC_A), KC_RSFT}, | ||
| 208 | ShiftKeyParams{"OSM_LSFT", OSM(MOD_LSFT), KC_LSFT}, | ||
| 209 | ShiftKeyParams{"OSM_RSFT", OSM(MOD_RSFT), KC_RSFT} | ||
| 210 | ), | ||
| 211 | ShiftKeyParams::GetName | ||
| 212 | ); | ||
| 213 | // clang-format on | ||
| 214 | |||
| 215 | } // namespace | ||
