diff options
| author | Stefan Kerkmann <karlk90@pm.me> | 2021-11-22 22:15:04 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-23 08:15:04 +1100 |
| commit | b6054c0206609f3755f71d819643644d250288b0 (patch) | |
| tree | 4f6f33040bb5184d47144090058eb089d2782b6c /tests/tap_hold_configurations | |
| parent | f4966a19d69a7f3bbefeea0537071d7d7c2abbdd (diff) | |
| download | qmk_firmware-b6054c0206609f3755f71d819643644d250288b0.tar.gz qmk_firmware-b6054c0206609f3755f71d819643644d250288b0.zip | |
[Tests] Increase QMK test coverage (#13789)
* Add per-test keymaps
* Add better trace and info logs for failed unit-tests
* Add layer state assertion with tracing message
* Use individual test binaries configuration options
* Add basic qmk functionality tests
* Add tap hold configurations tests
* Add auto shift tests
* `qmk format-c
* Fix tests
Co-authored-by: Nick Brassel <nick@tzarc.org>
Diffstat (limited to 'tests/tap_hold_configurations')
21 files changed, 1403 insertions, 0 deletions
diff --git a/tests/tap_hold_configurations/default_mod_tap/config.h b/tests/tap_hold_configurations/default_mod_tap/config.h new file mode 100644 index 000000000..5955b8600 --- /dev/null +++ b/tests/tap_hold_configurations/default_mod_tap/config.h | |||
| @@ -0,0 +1,21 @@ | |||
| 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 | #pragma once | ||
| 18 | |||
| 19 | #include "test_common.h" | ||
| 20 | |||
| 21 | #define IGNORE_MOD_TAP_INTERRUPT \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/default_mod_tap/test.mk b/tests/tap_hold_configurations/default_mod_tap/test.mk new file mode 100644 index 000000000..cfab996e0 --- /dev/null +++ b/tests/tap_hold_configurations/default_mod_tap/test.mk | |||
| @@ -0,0 +1,18 @@ | |||
| 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 | # Keep this file, even if it is empty, as a marker that this folder contains tests | ||
| 18 | # -------------------------------------------------------------------------------- \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/default_mod_tap/test_tap_hold.cpp b/tests/tap_hold_configurations/default_mod_tap/test_tap_hold.cpp new file mode 100644 index 000000000..90befcdff --- /dev/null +++ b/tests/tap_hold_configurations/default_mod_tap/test_tap_hold.cpp | |||
| @@ -0,0 +1,230 @@ | |||
| 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 | |||
| 27 | class DefaultTapHold : public TestFixture {}; | ||
| 28 | |||
| 29 | TEST_F(DefaultTapHold, tap_regular_key_while_mod_tap_key_is_held) { | ||
| 30 | TestDriver driver; | ||
| 31 | InSequence s; | ||
| 32 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
| 33 | auto regular_key = KeymapKey(0, 2, 0, KC_A); | ||
| 34 | |||
| 35 | set_keymap({mod_tap_hold_key, regular_key}); | ||
| 36 | |||
| 37 | /* Press mod-tap-hold key. */ | ||
| 38 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 39 | mod_tap_hold_key.press(); | ||
| 40 | run_one_scan_loop(); | ||
| 41 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 42 | |||
| 43 | /* Press regular key. */ | ||
| 44 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 45 | regular_key.press(); | ||
| 46 | run_one_scan_loop(); | ||
| 47 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 48 | |||
| 49 | /* Release regular key. */ | ||
| 50 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 51 | regular_key.release(); | ||
| 52 | run_one_scan_loop(); | ||
| 53 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 54 | |||
| 55 | /* Release mod-tap-hold key. */ | ||
| 56 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 57 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P, KC_A))); | ||
| 58 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 59 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 60 | mod_tap_hold_key.release(); | ||
| 61 | run_one_scan_loop(); | ||
| 62 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 63 | |||
| 64 | /* Idle for tapping term of mod tap hold key. */ | ||
| 65 | idle_for(TAPPING_TERM - 3); | ||
| 66 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 67 | } | ||
| 68 | |||
| 69 | TEST_F(DefaultTapHold, tap_mod_tap_key_while_mod_tap_key_is_held) { | ||
| 70 | TestDriver driver; | ||
| 71 | InSequence s; | ||
| 72 | auto first_mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
| 73 | auto second_mod_tap_hold_key = KeymapKey(0, 2, 0, RSFT_T(KC_A)); | ||
| 74 | |||
| 75 | set_keymap({first_mod_tap_hold_key, second_mod_tap_hold_key}); | ||
| 76 | |||
| 77 | /* Press first mod-tap-hold key */ | ||
| 78 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 79 | first_mod_tap_hold_key.press(); | ||
| 80 | run_one_scan_loop(); | ||
| 81 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 82 | |||
| 83 | /* Press second tap-hold key */ | ||
| 84 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 85 | second_mod_tap_hold_key.press(); | ||
| 86 | run_one_scan_loop(); | ||
| 87 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 88 | |||
| 89 | /* Release second tap-hold key */ | ||
| 90 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 91 | second_mod_tap_hold_key.release(); | ||
| 92 | run_one_scan_loop(); | ||
| 93 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 94 | |||
| 95 | /* Release first mod-tap-hold key */ | ||
| 96 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 97 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P, KC_A))); | ||
| 98 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 99 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 100 | first_mod_tap_hold_key.release(); | ||
| 101 | run_one_scan_loop(); | ||
| 102 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 103 | } | ||
| 104 | |||
| 105 | TEST_F(DefaultTapHold, tap_regular_key_while_layer_tap_key_is_held) { | ||
| 106 | TestDriver driver; | ||
| 107 | InSequence s; | ||
| 108 | auto layer_tap_hold_key = KeymapKey(0, 1, 0, LT(1, KC_P)); | ||
| 109 | auto regular_key = KeymapKey(0, 2, 0, KC_A); | ||
| 110 | auto layer_key = KeymapKey(1, 2, 0, KC_B); | ||
| 111 | |||
| 112 | set_keymap({layer_tap_hold_key, regular_key, layer_key}); | ||
| 113 | |||
| 114 | /* Press layer-tap-hold key */ | ||
| 115 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 116 | layer_tap_hold_key.press(); | ||
| 117 | run_one_scan_loop(); | ||
| 118 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 119 | |||
| 120 | /* Press regular key */ | ||
| 121 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 122 | regular_key.press(); | ||
| 123 | run_one_scan_loop(); | ||
| 124 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 125 | |||
| 126 | /* Release regular key */ | ||
| 127 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 128 | regular_key.release(); | ||
| 129 | run_one_scan_loop(); | ||
| 130 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 131 | |||
| 132 | /* Release layer-tap-hold key */ | ||
| 133 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 134 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A, KC_P))); | ||
| 135 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 136 | EXPECT_CALL(driver, send_keyboard_mock(_)); | ||
| 137 | layer_tap_hold_key.release(); | ||
| 138 | run_one_scan_loop(); | ||
| 139 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 140 | } | ||
| 141 | |||
| 142 | TEST_F(DefaultTapHold, tap_mod_tap_hold_key_two_times) { | ||
| 143 | GTEST_SKIP() << "TODO:Holding a modtap key results in out of bounds access to the keymap, this is a bug in QMK."; | ||
| 144 | |||
| 145 | TestDriver driver; | ||
| 146 | InSequence s; | ||
| 147 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
| 148 | |||
| 149 | set_keymap({mod_tap_hold_key}); | ||
| 150 | |||
| 151 | /* Press mod-tap-hold key. */ | ||
| 152 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 153 | mod_tap_hold_key.press(); | ||
| 154 | run_one_scan_loop(); | ||
| 155 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 156 | |||
| 157 | /* Release mod-tap-hold key. */ | ||
| 158 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 159 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 160 | mod_tap_hold_key.release(); | ||
| 161 | run_one_scan_loop(); | ||
| 162 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 163 | |||
| 164 | /* Press mod-tap-hold key again. */ | ||
| 165 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 166 | mod_tap_hold_key.press(); | ||
| 167 | idle_for(TAPPING_TERM); | ||
| 168 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 169 | |||
| 170 | /* Release mod-tap-hold key. */ | ||
| 171 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 172 | mod_tap_hold_key.release(); | ||
| 173 | run_one_scan_loop(); | ||
| 174 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 175 | } | ||
| 176 | |||
| 177 | TEST_F(DefaultTapHold, tap_mod_tap_hold_key_twice_and_hold_on_second_time) { | ||
| 178 | GTEST_SKIP() << "TODO:Holding a modtap key results in out of bounds access to the keymap, this is a bug in QMK."; | ||
| 179 | |||
| 180 | TestDriver driver; | ||
| 181 | InSequence s; | ||
| 182 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
| 183 | |||
| 184 | set_keymap({mod_tap_hold_key}); | ||
| 185 | |||
| 186 | /* Press mod-tap-hold key. */ | ||
| 187 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 188 | mod_tap_hold_key.press(); | ||
| 189 | run_one_scan_loop(); | ||
| 190 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 191 | |||
| 192 | /* Release mod-tap-hold key. */ | ||
| 193 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 194 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 195 | mod_tap_hold_key.release(); | ||
| 196 | run_one_scan_loop(); | ||
| 197 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 198 | |||
| 199 | /* Press mod-tap-hold key again. */ | ||
| 200 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 201 | mod_tap_hold_key.press(); | ||
| 202 | idle_for(TAPPING_TERM); | ||
| 203 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 204 | |||
| 205 | /* Release mod-tap-hold key. */ | ||
| 206 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 207 | mod_tap_hold_key.release(); | ||
| 208 | run_one_scan_loop(); | ||
| 209 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 210 | } | ||
| 211 | |||
| 212 | TEST_F(DefaultTapHold, tap_and_hold_mod_tap_hold_key) { | ||
| 213 | TestDriver driver; | ||
| 214 | InSequence s; | ||
| 215 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
| 216 | |||
| 217 | set_keymap({mod_tap_hold_key}); | ||
| 218 | |||
| 219 | /* Press mod-tap-hold key. */ | ||
| 220 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT))); | ||
| 221 | mod_tap_hold_key.press(); | ||
| 222 | idle_for(TAPPING_TERM + 1); | ||
| 223 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 224 | |||
| 225 | /* Release mod-tap-hold key. */ | ||
| 226 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 227 | mod_tap_hold_key.release(); | ||
| 228 | run_one_scan_loop(); | ||
| 229 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 230 | } \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/ignore_mod_tap_interrupt/config.h b/tests/tap_hold_configurations/ignore_mod_tap_interrupt/config.h new file mode 100644 index 000000000..5955b8600 --- /dev/null +++ b/tests/tap_hold_configurations/ignore_mod_tap_interrupt/config.h | |||
| @@ -0,0 +1,21 @@ | |||
| 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 | #pragma once | ||
| 18 | |||
| 19 | #include "test_common.h" | ||
| 20 | |||
| 21 | #define IGNORE_MOD_TAP_INTERRUPT \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/ignore_mod_tap_interrupt/test.mk b/tests/tap_hold_configurations/ignore_mod_tap_interrupt/test.mk new file mode 100644 index 000000000..efecca2c2 --- /dev/null +++ b/tests/tap_hold_configurations/ignore_mod_tap_interrupt/test.mk | |||
| @@ -0,0 +1,18 @@ | |||
| 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 | # Keep this file, even if it is empty, as a marker that this folder contains tests | ||
| 18 | # -------------------------------------------------------------------------------- | ||
diff --git a/tests/tap_hold_configurations/ignore_mod_tap_interrupt/test_tap_hold.cpp b/tests/tap_hold_configurations/ignore_mod_tap_interrupt/test_tap_hold.cpp new file mode 100644 index 000000000..1702d604d --- /dev/null +++ b/tests/tap_hold_configurations/ignore_mod_tap_interrupt/test_tap_hold.cpp | |||
| @@ -0,0 +1,136 @@ | |||
| 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 | |||
| 27 | class IgnoreModTapInterrupt : public TestFixture {}; | ||
| 28 | |||
| 29 | TEST_F(IgnoreModTapInterrupt, tap_regular_key_while_mod_tap_key_is_held) { | ||
| 30 | TestDriver driver; | ||
| 31 | InSequence s; | ||
| 32 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
| 33 | auto regular_key = KeymapKey(0, 2, 0, KC_A); | ||
| 34 | |||
| 35 | set_keymap({mod_tap_hold_key, regular_key}); | ||
| 36 | |||
| 37 | /* Press mod-tap-hold key */ | ||
| 38 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 39 | mod_tap_hold_key.press(); | ||
| 40 | run_one_scan_loop(); | ||
| 41 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 42 | |||
| 43 | /* Press regular key */ | ||
| 44 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 45 | regular_key.press(); | ||
| 46 | run_one_scan_loop(); | ||
| 47 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 48 | |||
| 49 | /* Release regular key */ | ||
| 50 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 51 | regular_key.release(); | ||
| 52 | run_one_scan_loop(); | ||
| 53 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 54 | |||
| 55 | /* Release mod-tap-hold key */ | ||
| 56 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 57 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A, KC_P))); | ||
| 58 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 59 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 60 | mod_tap_hold_key.release(); | ||
| 61 | run_one_scan_loop(); | ||
| 62 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 63 | } | ||
| 64 | |||
| 65 | TEST_F(IgnoreModTapInterrupt, tap_mod_tap_key_while_mod_tap_key_is_held) { | ||
| 66 | TestDriver driver; | ||
| 67 | InSequence s; | ||
| 68 | auto first_mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
| 69 | auto second_mod_tap_hold_key = KeymapKey(0, 2, 0, RSFT_T(KC_A)); | ||
| 70 | |||
| 71 | set_keymap({first_mod_tap_hold_key, second_mod_tap_hold_key}); | ||
| 72 | |||
| 73 | /* Press first mod-tap-hold key */ | ||
| 74 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 75 | first_mod_tap_hold_key.press(); | ||
| 76 | run_one_scan_loop(); | ||
| 77 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 78 | |||
| 79 | /* Press second tap-hold key */ | ||
| 80 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 81 | second_mod_tap_hold_key.press(); | ||
| 82 | run_one_scan_loop(); | ||
| 83 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 84 | |||
| 85 | /* Release second tap-hold key */ | ||
| 86 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 87 | second_mod_tap_hold_key.release(); | ||
| 88 | run_one_scan_loop(); | ||
| 89 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 90 | |||
| 91 | /* Release first mod-tap-hold key */ | ||
| 92 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 93 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A, KC_P))); | ||
| 94 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 95 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 96 | first_mod_tap_hold_key.release(); | ||
| 97 | run_one_scan_loop(); | ||
| 98 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 99 | } | ||
| 100 | |||
| 101 | TEST_F(IgnoreModTapInterrupt, tap_regular_key_while_layer_tap_key_is_held) { | ||
| 102 | TestDriver driver; | ||
| 103 | InSequence s; | ||
| 104 | auto layer_tap_hold_key = KeymapKey(0, 1, 0, LT(1, KC_P)); | ||
| 105 | auto regular_key = KeymapKey(0, 2, 0, KC_A); | ||
| 106 | auto layer_key = KeymapKey(1, 2, 0, KC_B); | ||
| 107 | |||
| 108 | set_keymap({layer_tap_hold_key, regular_key, layer_key}); | ||
| 109 | |||
| 110 | /* Press layer-tap-hold key */ | ||
| 111 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 112 | layer_tap_hold_key.press(); | ||
| 113 | run_one_scan_loop(); | ||
| 114 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 115 | |||
| 116 | /* Press regular key */ | ||
| 117 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 118 | regular_key.press(); | ||
| 119 | run_one_scan_loop(); | ||
| 120 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 121 | |||
| 122 | /* Release regular key */ | ||
| 123 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 124 | regular_key.release(); | ||
| 125 | run_one_scan_loop(); | ||
| 126 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 127 | |||
| 128 | /* Release layer-tap-hold key */ | ||
| 129 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 130 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P, regular_key.report_code))); | ||
| 131 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 132 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 133 | layer_tap_hold_key.release(); | ||
| 134 | run_one_scan_loop(); | ||
| 135 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 136 | } | ||
diff --git a/tests/tap_hold_configurations/permissive_hold/config.h b/tests/tap_hold_configurations/permissive_hold/config.h new file mode 100644 index 000000000..2d5a9849e --- /dev/null +++ b/tests/tap_hold_configurations/permissive_hold/config.h | |||
| @@ -0,0 +1,21 @@ | |||
| 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 | #pragma once | ||
| 18 | |||
| 19 | #include "test_common.h" | ||
| 20 | |||
| 21 | #define PERMISSIVE_HOLD \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/permissive_hold/test.mk b/tests/tap_hold_configurations/permissive_hold/test.mk new file mode 100644 index 000000000..efecca2c2 --- /dev/null +++ b/tests/tap_hold_configurations/permissive_hold/test.mk | |||
| @@ -0,0 +1,18 @@ | |||
| 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 | # Keep this file, even if it is empty, as a marker that this folder contains tests | ||
| 18 | # -------------------------------------------------------------------------------- | ||
diff --git a/tests/tap_hold_configurations/permissive_hold/test_one_shot_keys.cpp b/tests/tap_hold_configurations/permissive_hold/test_one_shot_keys.cpp new file mode 100644 index 000000000..aa71ec397 --- /dev/null +++ b/tests/tap_hold_configurations/permissive_hold/test_one_shot_keys.cpp | |||
| @@ -0,0 +1,76 @@ | |||
| 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_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 36 | osm_key.press(); | ||
| 37 | run_one_scan_loop(); | ||
| 38 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 39 | |||
| 40 | /* Press regular key */ | ||
| 41 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 42 | regular_key.press(); | ||
| 43 | run_one_scan_loop(); | ||
| 44 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 45 | |||
| 46 | /* Release regular key */ | ||
| 47 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(osm_key.report_code))).Times(2); | ||
| 48 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(regular_key.report_code, osm_key.report_code))).Times(1); | ||
| 49 | regular_key.release(); | ||
| 50 | run_one_scan_loop(); | ||
| 51 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 52 | |||
| 53 | /* Release OSM */ | ||
| 54 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
| 55 | osm_key.release(); | ||
| 56 | run_one_scan_loop(); | ||
| 57 | testing::Mock::VerifyAndClearExpectations(&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 \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/permissive_hold/test_tap_hold.cpp b/tests/tap_hold_configurations/permissive_hold/test_tap_hold.cpp new file mode 100644 index 000000000..ab9dd1518 --- /dev/null +++ b/tests/tap_hold_configurations/permissive_hold/test_tap_hold.cpp | |||
| @@ -0,0 +1,132 @@ | |||
| 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_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 38 | mod_tap_hold_key.press(); | ||
| 39 | run_one_scan_loop(); | ||
| 40 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 41 | |||
| 42 | /* Press regular key */ | ||
| 43 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 44 | regular_key.press(); | ||
| 45 | run_one_scan_loop(); | ||
| 46 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 47 | |||
| 48 | /* Release regular key */ | ||
| 49 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT))); | ||
| 50 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT, regular_key.report_code))); | ||
| 51 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT))); | ||
| 52 | regular_key.release(); | ||
| 53 | run_one_scan_loop(); | ||
| 54 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 55 | |||
| 56 | /* Release mod-tap-hold key */ | ||
| 57 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 58 | mod_tap_hold_key.release(); | ||
| 59 | run_one_scan_loop(); | ||
| 60 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 61 | } | ||
| 62 | |||
| 63 | TEST_F(PermissiveHold, tap_mod_tap_key_while_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_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 73 | first_mod_tap_hold_key.press(); | ||
| 74 | run_one_scan_loop(); | ||
| 75 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 76 | |||
| 77 | /* Press second mod-tap-hold key */ | ||
| 78 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 79 | second_mod_tap_hold_key.press(); | ||
| 80 | run_one_scan_loop(); | ||
| 81 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 82 | |||
| 83 | /* Release second mod-tap-hold key */ | ||
| 84 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT))); | ||
| 85 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT, second_mod_tap_hold_key.report_code))); | ||
| 86 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT))); | ||
| 87 | second_mod_tap_hold_key.release(); | ||
| 88 | run_one_scan_loop(); | ||
| 89 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 90 | |||
| 91 | /* Release first mod-tap-hold key */ | ||
| 92 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 93 | first_mod_tap_hold_key.release(); | ||
| 94 | run_one_scan_loop(); | ||
| 95 | testing::Mock::VerifyAndClearExpectations(&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_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 109 | layer_tap_hold_key.press(); | ||
| 110 | run_one_scan_loop(); | ||
| 111 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 112 | |||
| 113 | /* Press regular key */ | ||
| 114 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 115 | regular_key.press(); | ||
| 116 | run_one_scan_loop(); | ||
| 117 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 118 | |||
| 119 | /* Release regular key */ | ||
| 120 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 121 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(layer_key.report_code))); | ||
| 122 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 123 | regular_key.release(); | ||
| 124 | run_one_scan_loop(); | ||
| 125 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 126 | |||
| 127 | /* Release layer-tap-hold key */ | ||
| 128 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 129 | layer_tap_hold_key.release(); | ||
| 130 | run_one_scan_loop(); | ||
| 131 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 132 | } \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/config.h b/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/config.h new file mode 100644 index 000000000..a6abd50bb --- /dev/null +++ b/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/config.h | |||
| @@ -0,0 +1,22 @@ | |||
| 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 | #pragma once | ||
| 18 | |||
| 19 | #include "test_common.h" | ||
| 20 | |||
| 21 | #define IGNORE_MOD_TAP_INTERRUPT | ||
| 22 | #define PERMISSIVE_HOLD \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/test.mk b/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/test.mk new file mode 100644 index 000000000..efecca2c2 --- /dev/null +++ b/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/test.mk | |||
| @@ -0,0 +1,18 @@ | |||
| 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 | # Keep this file, even if it is empty, as a marker that this folder contains tests | ||
| 18 | # -------------------------------------------------------------------------------- | ||
diff --git a/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/test_tap_hold.cpp b/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/test_tap_hold.cpp new file mode 100644 index 000000000..67f394653 --- /dev/null +++ b/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/test_tap_hold.cpp | |||
| @@ -0,0 +1,134 @@ | |||
| 1 | |||
| 2 | /* Copyright 2021 Stefan Kerkmann | ||
| 3 | * | ||
| 4 | * This program is free software: you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License as published by | ||
| 6 | * the Free Software Foundation, either version 2 of the License, or | ||
| 7 | * (at your option) any later version. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include "keyboard_report_util.hpp" | ||
| 19 | #include "keycode.h" | ||
| 20 | #include "test_common.hpp" | ||
| 21 | #include "action_tapping.h" | ||
| 22 | #include "test_fixture.hpp" | ||
| 23 | #include "test_keymap_key.hpp" | ||
| 24 | |||
| 25 | using testing::_; | ||
| 26 | using testing::InSequence; | ||
| 27 | |||
| 28 | class PermissiveHold_IgnoreModTapInterrupt : public TestFixture {}; | ||
| 29 | |||
| 30 | TEST_F(PermissiveHold_IgnoreModTapInterrupt, tap_regular_key_while_mod_tap_key_is_held) { | ||
| 31 | TestDriver driver; | ||
| 32 | InSequence s; | ||
| 33 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
| 34 | auto regular_key = KeymapKey(0, 2, 0, KC_A); | ||
| 35 | |||
| 36 | set_keymap({mod_tap_hold_key, regular_key}); | ||
| 37 | |||
| 38 | /* Press mod-tap-hold key */ | ||
| 39 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 40 | mod_tap_hold_key.press(); | ||
| 41 | run_one_scan_loop(); | ||
| 42 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 43 | |||
| 44 | /* Press regular key */ | ||
| 45 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 46 | regular_key.press(); | ||
| 47 | run_one_scan_loop(); | ||
| 48 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 49 | |||
| 50 | /* Release regular key */ | ||
| 51 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
| 52 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_A))); | ||
| 53 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
| 54 | regular_key.release(); | ||
| 55 | run_one_scan_loop(); | ||
| 56 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 57 | |||
| 58 | /* Release mod-tap-hold key */ | ||
| 59 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 60 | mod_tap_hold_key.release(); | ||
| 61 | run_one_scan_loop(); | ||
| 62 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 63 | } | ||
| 64 | |||
| 65 | TEST_F(PermissiveHold_IgnoreModTapInterrupt, tap_mod_tap_key_while_mod_tap_key_is_held) { | ||
| 66 | TestDriver driver; | ||
| 67 | InSequence s; | ||
| 68 | auto first_mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
| 69 | auto second_mod_tap_hold_key = KeymapKey(0, 2, 0, RSFT_T(KC_A)); | ||
| 70 | |||
| 71 | set_keymap({first_mod_tap_hold_key, second_mod_tap_hold_key}); | ||
| 72 | |||
| 73 | /* Press first mod-tap-hold key */ | ||
| 74 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 75 | first_mod_tap_hold_key.press(); | ||
| 76 | run_one_scan_loop(); | ||
| 77 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 78 | |||
| 79 | /* Press second tap-hold key */ | ||
| 80 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 81 | second_mod_tap_hold_key.press(); | ||
| 82 | run_one_scan_loop(); | ||
| 83 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 84 | |||
| 85 | /* Release second tap-hold key */ | ||
| 86 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
| 87 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_A))); | ||
| 88 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
| 89 | second_mod_tap_hold_key.release(); | ||
| 90 | run_one_scan_loop(); | ||
| 91 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 92 | |||
| 93 | /* Release first mod-tap-hold key */ | ||
| 94 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 95 | first_mod_tap_hold_key.release(); | ||
| 96 | run_one_scan_loop(); | ||
| 97 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 98 | } | ||
| 99 | |||
| 100 | TEST_F(PermissiveHold_IgnoreModTapInterrupt, tap_regular_key_while_layer_tap_key_is_held) { | ||
| 101 | TestDriver driver; | ||
| 102 | InSequence s; | ||
| 103 | auto layer_tap_hold_key = KeymapKey(0, 1, 0, LT(1, KC_P)); | ||
| 104 | auto regular_key = KeymapKey(0, 2, 0, KC_A); | ||
| 105 | auto layer_key = KeymapKey(1, 2, 0, KC_B); | ||
| 106 | |||
| 107 | set_keymap({layer_tap_hold_key, regular_key, layer_key}); | ||
| 108 | |||
| 109 | /* Press layer-tap-hold key */ | ||
| 110 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 111 | layer_tap_hold_key.press(); | ||
| 112 | run_one_scan_loop(); | ||
| 113 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 114 | |||
| 115 | /* Press regular key */ | ||
| 116 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 117 | regular_key.press(); | ||
| 118 | run_one_scan_loop(); | ||
| 119 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 120 | |||
| 121 | /* Release regular key */ | ||
| 122 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 123 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))); | ||
| 124 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 125 | regular_key.release(); | ||
| 126 | run_one_scan_loop(); | ||
| 127 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 128 | |||
| 129 | /* Release layer-tap-hold key */ | ||
| 130 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 131 | layer_tap_hold_key.release(); | ||
| 132 | run_one_scan_loop(); | ||
| 133 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 134 | } \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/retro_tapping/config.h b/tests/tap_hold_configurations/retro_tapping/config.h new file mode 100644 index 000000000..4b38f2644 --- /dev/null +++ b/tests/tap_hold_configurations/retro_tapping/config.h | |||
| @@ -0,0 +1,21 @@ | |||
| 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 | #pragma once | ||
| 18 | |||
| 19 | #include "test_common.h" | ||
| 20 | |||
| 21 | #define RETRO_TAPPING \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/retro_tapping/test.mk b/tests/tap_hold_configurations/retro_tapping/test.mk new file mode 100644 index 000000000..efecca2c2 --- /dev/null +++ b/tests/tap_hold_configurations/retro_tapping/test.mk | |||
| @@ -0,0 +1,18 @@ | |||
| 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 | # Keep this file, even if it is empty, as a marker that this folder contains tests | ||
| 18 | # -------------------------------------------------------------------------------- | ||
diff --git a/tests/tap_hold_configurations/retro_tapping/test_tap_hold.cpp b/tests/tap_hold_configurations/retro_tapping/test_tap_hold.cpp new file mode 100644 index 000000000..59ae77f78 --- /dev/null +++ b/tests/tap_hold_configurations/retro_tapping/test_tap_hold.cpp | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | |||
| 2 | /* Copyright 2021 Stefan Kerkmann | ||
| 3 | * | ||
| 4 | * This program is free software: you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License as published by | ||
| 6 | * the Free Software Foundation, either version 2 of the License, or | ||
| 7 | * (at your option) any later version. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include "keyboard_report_util.hpp" | ||
| 19 | #include "keycode.h" | ||
| 20 | #include "test_common.hpp" | ||
| 21 | #include "action_tapping.h" | ||
| 22 | #include "test_fixture.hpp" | ||
| 23 | #include "test_keymap_key.hpp" | ||
| 24 | |||
| 25 | using testing::_; | ||
| 26 | using testing::InSequence; | ||
| 27 | |||
| 28 | class RetroTapping : public TestFixture {}; | ||
| 29 | |||
| 30 | TEST_F(RetroTapping, tap_and_hold_mod_tap_hold_key) { | ||
| 31 | TestDriver driver; | ||
| 32 | InSequence s; | ||
| 33 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
| 34 | |||
| 35 | set_keymap({mod_tap_hold_key}); | ||
| 36 | |||
| 37 | /* Press mod-tap-hold key. */ | ||
| 38 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 39 | mod_tap_hold_key.press(); | ||
| 40 | idle_for(TAPPING_TERM); | ||
| 41 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 42 | |||
| 43 | /* Release mod-tap-hold key. */ | ||
| 44 | /* TODO: Why is LSHIFT send at all? */ | ||
| 45 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT))); | ||
| 46 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 47 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 48 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 49 | mod_tap_hold_key.release(); | ||
| 50 | run_one_scan_loop(); | ||
| 51 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 52 | } \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/retro_tapping/test_tapping.cpp b/tests/tap_hold_configurations/retro_tapping/test_tapping.cpp new file mode 100644 index 000000000..cf23df831 --- /dev/null +++ b/tests/tap_hold_configurations/retro_tapping/test_tapping.cpp | |||
| @@ -0,0 +1,112 @@ | |||
| 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_keymap_key.hpp" | ||
| 22 | |||
| 23 | using testing::_; | ||
| 24 | using testing::InSequence; | ||
| 25 | |||
| 26 | class Tapping : public TestFixture {}; | ||
| 27 | |||
| 28 | TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) { | ||
| 29 | TestDriver driver; | ||
| 30 | InSequence s; | ||
| 31 | auto mod_tap_hold_key = KeymapKey(0, 7, 0, SFT_T(KC_P)); | ||
| 32 | |||
| 33 | set_keymap({mod_tap_hold_key}); | ||
| 34 | |||
| 35 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 36 | mod_tap_hold_key.press(); | ||
| 37 | idle_for(TAPPING_TERM); | ||
| 38 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 39 | |||
| 40 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
| 41 | run_one_scan_loop(); | ||
| 42 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 43 | |||
| 44 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 45 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 46 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 47 | mod_tap_hold_key.release(); | ||
| 48 | run_one_scan_loop(); | ||
| 49 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 50 | } | ||
| 51 | |||
| 52 | TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) { | ||
| 53 | TestDriver driver; | ||
| 54 | InSequence s; | ||
| 55 | auto key_shift_hold_p_tap = KeymapKey(0, 7, 0, SFT_T(KC_P)); | ||
| 56 | |||
| 57 | set_keymap({key_shift_hold_p_tap}); | ||
| 58 | |||
| 59 | /* Press mod_tap_hold key */ | ||
| 60 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 61 | key_shift_hold_p_tap.press(); | ||
| 62 | run_one_scan_loop(); | ||
| 63 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 64 | |||
| 65 | /* Release mod_tap_hold key */ | ||
| 66 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 67 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 68 | key_shift_hold_p_tap.release(); | ||
| 69 | run_one_scan_loop(); | ||
| 70 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 71 | |||
| 72 | /* Press mod_tap_hold key again */ | ||
| 73 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 74 | key_shift_hold_p_tap.press(); | ||
| 75 | run_one_scan_loop(); | ||
| 76 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 77 | |||
| 78 | /* Release mod_tap_hold key again */ | ||
| 79 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 80 | key_shift_hold_p_tap.release(); | ||
| 81 | idle_for(TAPPING_TERM + 1); | ||
| 82 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 83 | |||
| 84 | /* Press mod_tap_hold key again */ | ||
| 85 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 86 | key_shift_hold_p_tap.press(); | ||
| 87 | run_one_scan_loop(); | ||
| 88 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 89 | |||
| 90 | /* Release mod_tap_hold key again */ | ||
| 91 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 92 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 93 | key_shift_hold_p_tap.release(); | ||
| 94 | idle_for(TAPPING_TERM + 1); | ||
| 95 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 96 | |||
| 97 | /* Press mod_tap_hold key again */ | ||
| 98 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 99 | key_shift_hold_p_tap.press(); | ||
| 100 | idle_for(TAPPING_TERM); | ||
| 101 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 102 | |||
| 103 | /* Release mod_tap_hold key again */ | ||
| 104 | /* TODO: Why is KC_LSFT send? */ | ||
| 105 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
| 106 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 107 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 108 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 109 | key_shift_hold_p_tap.release(); | ||
| 110 | run_one_scan_loop(); | ||
| 111 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 112 | } \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/tapping_force_hold/config.h b/tests/tap_hold_configurations/tapping_force_hold/config.h new file mode 100644 index 000000000..3b4646338 --- /dev/null +++ b/tests/tap_hold_configurations/tapping_force_hold/config.h | |||
| @@ -0,0 +1,21 @@ | |||
| 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 | #pragma once | ||
| 18 | |||
| 19 | #include "test_common.h" | ||
| 20 | |||
| 21 | #define TAPPING_FORCE_HOLD \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/tapping_force_hold/test.mk b/tests/tap_hold_configurations/tapping_force_hold/test.mk new file mode 100644 index 000000000..efecca2c2 --- /dev/null +++ b/tests/tap_hold_configurations/tapping_force_hold/test.mk | |||
| @@ -0,0 +1,18 @@ | |||
| 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 | # Keep this file, even if it is empty, as a marker that this folder contains tests | ||
| 18 | # -------------------------------------------------------------------------------- | ||
diff --git a/tests/tap_hold_configurations/tapping_force_hold/test_action_layer.cpp b/tests/tap_hold_configurations/tapping_force_hold/test_action_layer.cpp new file mode 100644 index 000000000..02416eed7 --- /dev/null +++ b/tests/tap_hold_configurations/tapping_force_hold/test_action_layer.cpp | |||
| @@ -0,0 +1,81 @@ | |||
| 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 "test_common.hpp" | ||
| 19 | |||
| 20 | using testing::_; | ||
| 21 | using testing::InSequence; | ||
| 22 | |||
| 23 | class ActionLayer : public TestFixture {}; | ||
| 24 | |||
| 25 | TEST_F(ActionLayer, LayerTapToggleWithToggleWithKeypress) { | ||
| 26 | TestDriver driver; | ||
| 27 | KeymapKey layer_key = KeymapKey{0, 0, 0, TT(1)}; | ||
| 28 | |||
| 29 | /* These keys must have the same position in the matrix, only the layer is different. */ | ||
| 30 | KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A}; | ||
| 31 | set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}}); | ||
| 32 | |||
| 33 | /* Tap TT five times . */ | ||
| 34 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
| 35 | /* TODO: Tapping Force Hold breaks TT */ | ||
| 36 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(10); | ||
| 37 | |||
| 38 | layer_key.press(); | ||
| 39 | run_one_scan_loop(); | ||
| 40 | layer_key.release(); | ||
| 41 | run_one_scan_loop(); | ||
| 42 | expect_layer_state(0); | ||
| 43 | |||
| 44 | layer_key.press(); | ||
| 45 | run_one_scan_loop(); | ||
| 46 | layer_key.release(); | ||
| 47 | run_one_scan_loop(); | ||
| 48 | expect_layer_state(0); | ||
| 49 | |||
| 50 | layer_key.press(); | ||
| 51 | run_one_scan_loop(); | ||
| 52 | layer_key.release(); | ||
| 53 | run_one_scan_loop(); | ||
| 54 | expect_layer_state(0); | ||
| 55 | |||
| 56 | layer_key.press(); | ||
| 57 | run_one_scan_loop(); | ||
| 58 | layer_key.release(); | ||
| 59 | run_one_scan_loop(); | ||
| 60 | expect_layer_state(0); | ||
| 61 | |||
| 62 | layer_key.press(); | ||
| 63 | run_one_scan_loop(); | ||
| 64 | layer_key.release(); | ||
| 65 | run_one_scan_loop(); | ||
| 66 | expect_layer_state(0); | ||
| 67 | |||
| 68 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 69 | |||
| 70 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))).Times(1); | ||
| 71 | regular_key.press(); | ||
| 72 | run_one_scan_loop(); | ||
| 73 | expect_layer_state(0); | ||
| 74 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 75 | |||
| 76 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
| 77 | regular_key.release(); | ||
| 78 | run_one_scan_loop(); | ||
| 79 | expect_layer_state(0); | ||
| 80 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 81 | } \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/tapping_force_hold/test_tap_hold.cpp b/tests/tap_hold_configurations/tapping_force_hold/test_tap_hold.cpp new file mode 100644 index 000000000..cb6842961 --- /dev/null +++ b/tests/tap_hold_configurations/tapping_force_hold/test_tap_hold.cpp | |||
| @@ -0,0 +1,215 @@ | |||
| 1 | |||
| 2 | /* Copyright 2021 Stefan Kerkmann | ||
| 3 | * | ||
| 4 | * This program is free software: you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License as published by | ||
| 6 | * the Free Software Foundation, either version 2 of the License, or | ||
| 7 | * (at your option) any later version. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include "keyboard_report_util.hpp" | ||
| 19 | #include "keycode.h" | ||
| 20 | #include "test_common.hpp" | ||
| 21 | #include "action_tapping.h" | ||
| 22 | #include "test_fixture.hpp" | ||
| 23 | #include "test_keymap_key.hpp" | ||
| 24 | |||
| 25 | using testing::_; | ||
| 26 | using testing::InSequence; | ||
| 27 | |||
| 28 | class TappingForceHold : public TestFixture {}; | ||
| 29 | |||
| 30 | TEST_F(TappingForceHold, tap_regular_key_while_mod_tap_key_is_held) { | ||
| 31 | TestDriver driver; | ||
| 32 | InSequence s; | ||
| 33 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
| 34 | auto regular_key = KeymapKey(0, 2, 0, KC_A); | ||
| 35 | |||
| 36 | set_keymap({mod_tap_hold_key, regular_key}); | ||
| 37 | |||
| 38 | /* Press mod-tap-hold key. */ | ||
| 39 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 40 | mod_tap_hold_key.press(); | ||
| 41 | run_one_scan_loop(); | ||
| 42 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 43 | |||
| 44 | /* Press regular key. */ | ||
| 45 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 46 | regular_key.press(); | ||
| 47 | run_one_scan_loop(); | ||
| 48 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 49 | |||
| 50 | /* Release regular key. */ | ||
| 51 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 52 | regular_key.release(); | ||
| 53 | run_one_scan_loop(); | ||
| 54 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 55 | |||
| 56 | /* Release mod-tap-hold key. */ | ||
| 57 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
| 58 | mod_tap_hold_key.release(); | ||
| 59 | run_one_scan_loop(); | ||
| 60 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 61 | |||
| 62 | /* Idle for tapping term of mod tap hold key. */ | ||
| 63 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
| 64 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_A))); | ||
| 65 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
| 66 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 67 | idle_for(TAPPING_TERM - 3); | ||
| 68 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 69 | } | ||
| 70 | |||
| 71 | TEST_F(TappingForceHold, tap_mod_tap_key_while_mod_tap_key_is_held) { | ||
| 72 | TestDriver driver; | ||
| 73 | InSequence s; | ||
| 74 | auto first_mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
| 75 | auto second_mod_tap_hold_key = KeymapKey(0, 2, 0, RSFT_T(KC_A)); | ||
| 76 | |||
| 77 | set_keymap({first_mod_tap_hold_key, second_mod_tap_hold_key}); | ||
| 78 | |||
| 79 | /* Press first mod-tap-hold key */ | ||
| 80 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 81 | first_mod_tap_hold_key.press(); | ||
| 82 | run_one_scan_loop(); | ||
| 83 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 84 | |||
| 85 | /* Press second tap-hold key */ | ||
| 86 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 87 | second_mod_tap_hold_key.press(); | ||
| 88 | run_one_scan_loop(); | ||
| 89 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 90 | |||
| 91 | /* Release second tap-hold key */ | ||
| 92 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 93 | second_mod_tap_hold_key.release(); | ||
| 94 | run_one_scan_loop(); | ||
| 95 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 96 | |||
| 97 | /* Release first mod-tap-hold key */ | ||
| 98 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
| 99 | first_mod_tap_hold_key.release(); | ||
| 100 | run_one_scan_loop(); | ||
| 101 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 102 | |||
| 103 | /* Idle for tapping term of first mod tap hold key. */ | ||
| 104 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
| 105 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_A))); | ||
| 106 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
| 107 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 108 | idle_for(TAPPING_TERM - 3); | ||
| 109 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 110 | } | ||
| 111 | |||
| 112 | TEST_F(TappingForceHold, tap_regular_key_while_layer_tap_key_is_held) { | ||
| 113 | TestDriver driver; | ||
| 114 | InSequence s; | ||
| 115 | auto layer_tap_hold_key = KeymapKey(0, 1, 0, LT(1, KC_P)); | ||
| 116 | auto regular_key = KeymapKey(0, 2, 0, KC_A); | ||
| 117 | auto layer_key = KeymapKey(1, 2, 0, KC_B); | ||
| 118 | |||
| 119 | set_keymap({layer_tap_hold_key, regular_key, layer_key}); | ||
| 120 | |||
| 121 | /* Press layer-tap-hold key */ | ||
| 122 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 123 | layer_tap_hold_key.press(); | ||
| 124 | run_one_scan_loop(); | ||
| 125 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 126 | |||
| 127 | /* Press regular key */ | ||
| 128 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 129 | regular_key.press(); | ||
| 130 | run_one_scan_loop(); | ||
| 131 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 132 | |||
| 133 | /* Release regular key */ | ||
| 134 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 135 | regular_key.release(); | ||
| 136 | run_one_scan_loop(); | ||
| 137 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 138 | |||
| 139 | /* Release layer-tap-hold key */ | ||
| 140 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 141 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A, KC_P))); | ||
| 142 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 143 | EXPECT_CALL(driver, send_keyboard_mock(_)); | ||
| 144 | layer_tap_hold_key.release(); | ||
| 145 | run_one_scan_loop(); | ||
| 146 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 147 | } | ||
| 148 | |||
| 149 | TEST_F(TappingForceHold, tap_mod_tap_hold_key_two_times) { | ||
| 150 | TestDriver driver; | ||
| 151 | InSequence s; | ||
| 152 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
| 153 | |||
| 154 | set_keymap({mod_tap_hold_key}); | ||
| 155 | |||
| 156 | /* Press mod-tap-hold key. */ | ||
| 157 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 158 | mod_tap_hold_key.press(); | ||
| 159 | run_one_scan_loop(); | ||
| 160 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 161 | |||
| 162 | /* Release mod-tap-hold key. */ | ||
| 163 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 164 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 165 | mod_tap_hold_key.release(); | ||
| 166 | run_one_scan_loop(); | ||
| 167 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 168 | |||
| 169 | /* Press mod-tap-hold key again. */ | ||
| 170 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 171 | mod_tap_hold_key.press(); | ||
| 172 | run_one_scan_loop(); | ||
| 173 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 174 | |||
| 175 | /* Release mod-tap-hold key. */ | ||
| 176 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 177 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 178 | mod_tap_hold_key.release(); | ||
| 179 | run_one_scan_loop(); | ||
| 180 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 181 | } | ||
| 182 | |||
| 183 | TEST_F(TappingForceHold, tap_mod_tap_hold_key_twice_and_hold_on_second_time) { | ||
| 184 | TestDriver driver; | ||
| 185 | InSequence s; | ||
| 186 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
| 187 | |||
| 188 | set_keymap({mod_tap_hold_key}); | ||
| 189 | |||
| 190 | /* Press mod-tap-hold key. */ | ||
| 191 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 192 | mod_tap_hold_key.press(); | ||
| 193 | run_one_scan_loop(); | ||
| 194 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 195 | |||
| 196 | /* Release mod-tap-hold key. */ | ||
| 197 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
| 198 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 199 | mod_tap_hold_key.release(); | ||
| 200 | run_one_scan_loop(); | ||
| 201 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 202 | |||
| 203 | /* Press mod-tap-hold key again. */ | ||
| 204 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
| 205 | mod_tap_hold_key.press(); | ||
| 206 | idle_for(TAPPING_TERM); | ||
| 207 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 208 | |||
| 209 | /* Release mod-tap-hold key. */ | ||
| 210 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT))); | ||
| 211 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
| 212 | mod_tap_hold_key.release(); | ||
| 213 | run_one_scan_loop(); | ||
| 214 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
| 215 | } | ||
