aboutsummaryrefslogtreecommitdiff
path: root/tests/tap_hold_configurations/default_mod_tap
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tap_hold_configurations/default_mod_tap')
-rw-r--r--tests/tap_hold_configurations/default_mod_tap/config.h21
-rw-r--r--tests/tap_hold_configurations/default_mod_tap/test.mk18
-rw-r--r--tests/tap_hold_configurations/default_mod_tap/test_tap_hold.cpp230
3 files changed, 269 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
24using testing::_;
25using testing::InSequence;
26
27class DefaultTapHold : public TestFixture {};
28
29TEST_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
69TEST_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
105TEST_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
142TEST_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
177TEST_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
212TEST_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