diff options
author | Akshay <[email protected]> | 2022-04-10 12:13:40 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2022-04-10 12:13:40 +0100 |
commit | dc90387ce7d8ba7b607d9c48540bf6d8b560f14d (patch) | |
tree | 4ccb8fa5886b66fa9d480edef74236c27f035e16 /tests/basic |
Diffstat (limited to 'tests/basic')
-rw-r--r-- | tests/basic/config.h | 19 | ||||
-rw-r--r-- | tests/basic/test.mk | 18 | ||||
-rw-r--r-- | tests/basic/test_action_layer.cpp | 413 | ||||
-rw-r--r-- | tests/basic/test_keypress.cpp | 317 | ||||
-rw-r--r-- | tests/basic/test_macro.cpp | 88 | ||||
-rw-r--r-- | tests/basic/test_one_shot_keys.cpp | 197 | ||||
-rw-r--r-- | tests/basic/test_tapping.cpp | 123 |
7 files changed, 1175 insertions, 0 deletions
diff --git a/tests/basic/config.h b/tests/basic/config.h new file mode 100644 index 000000000..85fa9d691 --- /dev/null +++ b/tests/basic/config.h | |||
@@ -0,0 +1,19 @@ | |||
1 | /* Copyright 2017 Fred Sundvik | ||
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" \ No newline at end of file | ||
diff --git a/tests/basic/test.mk b/tests/basic/test.mk new file mode 100644 index 000000000..29690d1ad --- /dev/null +++ b/tests/basic/test.mk | |||
@@ -0,0 +1,18 @@ | |||
1 | # Copyright 2017 Fred Sundvik | ||
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/basic/test_action_layer.cpp b/tests/basic/test_action_layer.cpp new file mode 100644 index 000000000..1b12d1364 --- /dev/null +++ b/tests/basic/test_action_layer.cpp | |||
@@ -0,0 +1,413 @@ | |||
1 | /* Copyright 2017 Colin T.A. Gray | ||
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 "gtest/gtest.h" | ||
18 | #include "keyboard_report_util.hpp" | ||
19 | #include "test_common.hpp" | ||
20 | |||
21 | using testing::_; | ||
22 | using testing::InSequence; | ||
23 | |||
24 | class ActionLayer : public TestFixture {}; | ||
25 | |||
26 | TEST_F(ActionLayer, LayerStateDBG) { | ||
27 | TestDriver driver; | ||
28 | |||
29 | layer_state_set(0); | ||
30 | |||
31 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
32 | } | ||
33 | |||
34 | TEST_F(ActionLayer, LayerStateSet) { | ||
35 | TestDriver driver; | ||
36 | |||
37 | layer_state_set(0); | ||
38 | EXPECT_EQ(layer_state, 0); | ||
39 | layer_state_set(0b001100); | ||
40 | EXPECT_EQ(layer_state, 0b001100); | ||
41 | |||
42 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
43 | } | ||
44 | |||
45 | TEST_F(ActionLayer, LayerStateIs) { | ||
46 | TestDriver driver; | ||
47 | |||
48 | layer_state_set(0); | ||
49 | EXPECT_EQ(layer_state_is(0), true); | ||
50 | EXPECT_EQ(layer_state_is(1), false); | ||
51 | layer_state_set(1); | ||
52 | EXPECT_EQ(layer_state_is(0), true); | ||
53 | EXPECT_EQ(layer_state_is(1), false); | ||
54 | layer_state_set(2); | ||
55 | EXPECT_EQ(layer_state_is(0), false); | ||
56 | EXPECT_EQ(layer_state_is(1), true); | ||
57 | EXPECT_EQ(layer_state_is(2), false); | ||
58 | |||
59 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
60 | } | ||
61 | |||
62 | TEST_F(ActionLayer, LayerStateCmp) { | ||
63 | TestDriver driver; | ||
64 | uint32_t prev_layer; | ||
65 | |||
66 | prev_layer = 0; | ||
67 | EXPECT_EQ(layer_state_cmp(prev_layer, 0), true); | ||
68 | EXPECT_EQ(layer_state_cmp(prev_layer, 1), false); | ||
69 | |||
70 | prev_layer = 1; | ||
71 | EXPECT_EQ(layer_state_cmp(prev_layer, 0), true); | ||
72 | EXPECT_EQ(layer_state_cmp(prev_layer, 1), false); | ||
73 | |||
74 | prev_layer = 2; | ||
75 | EXPECT_EQ(layer_state_cmp(prev_layer, 0), false); | ||
76 | EXPECT_EQ(layer_state_cmp(prev_layer, 1), true); | ||
77 | EXPECT_EQ(layer_state_cmp(prev_layer, 2), false); | ||
78 | |||
79 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
80 | } | ||
81 | |||
82 | TEST_F(ActionLayer, LayerClear) { | ||
83 | TestDriver driver; | ||
84 | |||
85 | layer_clear(); | ||
86 | EXPECT_EQ(layer_state, 0); | ||
87 | |||
88 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
89 | } | ||
90 | |||
91 | TEST_F(ActionLayer, LayerMove) { | ||
92 | TestDriver driver; | ||
93 | |||
94 | layer_move(0); | ||
95 | EXPECT_EQ(layer_state, 1); | ||
96 | layer_move(3); | ||
97 | EXPECT_EQ(layer_state, 0b1000); | ||
98 | |||
99 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
100 | } | ||
101 | |||
102 | TEST_F(ActionLayer, LayerOn) { | ||
103 | TestDriver driver; | ||
104 | |||
105 | layer_clear(); | ||
106 | layer_on(1); | ||
107 | layer_on(3); | ||
108 | layer_on(3); | ||
109 | EXPECT_EQ(layer_state, 0b1010); | ||
110 | |||
111 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
112 | } | ||
113 | |||
114 | TEST_F(ActionLayer, LayerOff) { | ||
115 | TestDriver driver; | ||
116 | |||
117 | layer_clear(); | ||
118 | layer_on(1); | ||
119 | layer_on(3); | ||
120 | layer_off(3); | ||
121 | layer_off(2); | ||
122 | EXPECT_EQ(layer_state, 0b0010); | ||
123 | |||
124 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
125 | } | ||
126 | |||
127 | TEST_F(ActionLayer, MomentaryLayerDoesNothing) { | ||
128 | TestDriver driver; | ||
129 | KeymapKey layer_key = KeymapKey{0, 0, 0, MO(1)}; | ||
130 | |||
131 | set_keymap({layer_key}); | ||
132 | |||
133 | /* Press and release MO, nothing should happen. */ | ||
134 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
135 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
136 | layer_key.press(); | ||
137 | run_one_scan_loop(); | ||
138 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
139 | |||
140 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
141 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
142 | layer_key.release(); | ||
143 | run_one_scan_loop(); | ||
144 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
145 | } | ||
146 | |||
147 | TEST_F(ActionLayer, MomentaryLayerWithKeypress) { | ||
148 | TestDriver driver; | ||
149 | KeymapKey layer_key = KeymapKey{0, 0, 0, MO(1)}; | ||
150 | |||
151 | /* These keys must have the same position in the matrix, only the layer is different. */ | ||
152 | KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A}; | ||
153 | set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}}); | ||
154 | |||
155 | /* Press MO. */ | ||
156 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
157 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
158 | layer_key.press(); | ||
159 | run_one_scan_loop(); | ||
160 | EXPECT_TRUE(layer_state_is(1)); | ||
161 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
162 | |||
163 | /* Press key on layer 1 */ | ||
164 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))).Times(1); | ||
165 | regular_key.press(); | ||
166 | run_one_scan_loop(); | ||
167 | EXPECT_TRUE(layer_state_is(1)); | ||
168 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
169 | |||
170 | /* Release key on layer 1 */ | ||
171 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
172 | regular_key.release(); | ||
173 | run_one_scan_loop(); | ||
174 | EXPECT_TRUE(layer_state_is(1)); | ||
175 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
176 | |||
177 | /* Release MO */ | ||
178 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
179 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
180 | layer_key.release(); | ||
181 | run_one_scan_loop(); | ||
182 | EXPECT_TRUE(layer_state_is(0)); | ||
183 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
184 | } | ||
185 | |||
186 | TEST_F(ActionLayer, ToggleLayerDoesNothing) { | ||
187 | GTEST_SKIP() << "TODO: Toggle layer does not activate the expected layer on key press but on release."; | ||
188 | |||
189 | TestDriver driver; | ||
190 | KeymapKey layer_key = KeymapKey{0, 0, 0, TG(1)}; | ||
191 | |||
192 | set_keymap({layer_key}); | ||
193 | |||
194 | /* Press TG. Layer state should not change as it's applied on release. */ | ||
195 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
196 | layer_key.press(); | ||
197 | run_one_scan_loop(); | ||
198 | EXPECT_TRUE(layer_state_is(1)); | ||
199 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
200 | |||
201 | /* Release TG. */ | ||
202 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
203 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
204 | layer_key.release(); | ||
205 | run_one_scan_loop(); | ||
206 | EXPECT_TRUE(layer_state_is(1)); | ||
207 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
208 | } | ||
209 | |||
210 | TEST_F(ActionLayer, ToggleLayerUpAndDown) { | ||
211 | GTEST_SKIP() << "TODO: Toggle layer does not activate the expected layer on key press but on release."; | ||
212 | |||
213 | TestDriver driver; | ||
214 | KeymapKey toggle_layer_1_on_layer_0 = KeymapKey{0, 0, 0, TG(1)}; | ||
215 | KeymapKey toggle_layer_0_on_layer_1 = KeymapKey{1, 1, 0, TG(0)}; | ||
216 | |||
217 | set_keymap({toggle_layer_1_on_layer_0, toggle_layer_0_on_layer_1}); | ||
218 | |||
219 | /* Toggle Layer 1. */ | ||
220 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
221 | toggle_layer_1_on_layer_0.press(); | ||
222 | run_one_scan_loop(); | ||
223 | EXPECT_TRUE(layer_state_is(1)); | ||
224 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
225 | |||
226 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
227 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
228 | toggle_layer_1_on_layer_0.release(); | ||
229 | run_one_scan_loop(); | ||
230 | EXPECT_TRUE(layer_state_is(1)); | ||
231 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
232 | |||
233 | /* Toggle Layer 0. */ | ||
234 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
235 | toggle_layer_0_on_layer_1.press(); | ||
236 | run_one_scan_loop(); | ||
237 | EXPECT_TRUE(layer_state_is(0)); | ||
238 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
239 | |||
240 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
241 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
242 | toggle_layer_0_on_layer_1.release(); | ||
243 | run_one_scan_loop(); | ||
244 | EXPECT_TRUE(layer_state_is(0)); | ||
245 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
246 | } | ||
247 | |||
248 | TEST_F(ActionLayer, LayerTapToggleDoesNothing) { | ||
249 | GTEST_SKIP() << "TODO: Tap toggle layer does not activate the expected layer on key press."; | ||
250 | |||
251 | TestDriver driver; | ||
252 | KeymapKey layer_key = KeymapKey{0, 0, 0, TT(1)}; | ||
253 | |||
254 | set_keymap({layer_key}); | ||
255 | |||
256 | /* Press and release TT. */ | ||
257 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(0); | ||
258 | layer_key.press(); | ||
259 | run_one_scan_loop(); | ||
260 | EXPECT_TRUE(layer_state_is(1)); | ||
261 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
262 | |||
263 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
264 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(2); | ||
265 | layer_key.release(); | ||
266 | run_one_scan_loop(); | ||
267 | EXPECT_TRUE(layer_state_is(0)); | ||
268 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
269 | } | ||
270 | |||
271 | TEST_F(ActionLayer, LayerTapToggleWithKeypress) { | ||
272 | GTEST_SKIP() << "TODO: Tap toggle layer does not activate the expected layer on key press."; | ||
273 | |||
274 | TestDriver driver; | ||
275 | KeymapKey layer_key = KeymapKey{0, 0, 0, TT(1)}; | ||
276 | |||
277 | /* These keys must have the same position in the matrix, only the layer is different. */ | ||
278 | KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A}; | ||
279 | set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}}); | ||
280 | |||
281 | /* Press TT. */ | ||
282 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
283 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(0); | ||
284 | layer_key.press(); | ||
285 | run_one_scan_loop(); | ||
286 | EXPECT_TRUE(layer_state_is(1)); | ||
287 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
288 | |||
289 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))).Times(1); | ||
290 | regular_key.press(); | ||
291 | run_one_scan_loop(); | ||
292 | EXPECT_TRUE(layer_state_is(1)); | ||
293 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
294 | |||
295 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
296 | regular_key.release(); | ||
297 | run_one_scan_loop(); | ||
298 | EXPECT_TRUE(layer_state_is(1)); | ||
299 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
300 | |||
301 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
302 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
303 | layer_key.release(); | ||
304 | run_one_scan_loop(); | ||
305 | EXPECT_TRUE(layer_state_is(0)); | ||
306 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
307 | } | ||
308 | |||
309 | TEST_F(ActionLayer, LayerTapToggleWithToggleWithKeypress) { | ||
310 | GTEST_SKIP() << "TODO: Tap toggle layer does not activate the expected layer on key press."; | ||
311 | |||
312 | TestDriver driver; | ||
313 | KeymapKey layer_key = KeymapKey{0, 0, 0, TT(1)}; | ||
314 | |||
315 | /* These keys must have the same position in the matrix, only the layer is different. */ | ||
316 | KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A}; | ||
317 | set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}}); | ||
318 | |||
319 | /* Tap TT five times . */ | ||
320 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
321 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(9); | ||
322 | |||
323 | layer_key.press(); | ||
324 | run_one_scan_loop(); | ||
325 | EXPECT_TRUE(layer_state_is(1)); | ||
326 | layer_key.release(); | ||
327 | run_one_scan_loop(); | ||
328 | EXPECT_TRUE(layer_state_is(0)); | ||
329 | |||
330 | layer_key.press(); | ||
331 | run_one_scan_loop(); | ||
332 | EXPECT_TRUE(layer_state_is(1)); | ||
333 | layer_key.release(); | ||
334 | run_one_scan_loop(); | ||
335 | EXPECT_TRUE(layer_state_is(0)); | ||
336 | |||
337 | layer_key.press(); | ||
338 | run_one_scan_loop(); | ||
339 | EXPECT_TRUE(layer_state_is(1)); | ||
340 | layer_key.release(); | ||
341 | run_one_scan_loop(); | ||
342 | EXPECT_TRUE(layer_state_is(0)); | ||
343 | |||
344 | layer_key.press(); | ||
345 | run_one_scan_loop(); | ||
346 | EXPECT_TRUE(layer_state_is(1)); | ||
347 | layer_key.release(); | ||
348 | run_one_scan_loop(); | ||
349 | EXPECT_TRUE(layer_state_is(0)); | ||
350 | |||
351 | layer_key.press(); | ||
352 | run_one_scan_loop(); | ||
353 | EXPECT_TRUE(layer_state_is(1)); | ||
354 | layer_key.release(); | ||
355 | run_one_scan_loop(); | ||
356 | EXPECT_TRUE(layer_state_is(1)); | ||
357 | |||
358 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
359 | |||
360 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))).Times(1); | ||
361 | regular_key.press(); | ||
362 | run_one_scan_loop(); | ||
363 | EXPECT_TRUE(layer_state_is(1)); | ||
364 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
365 | |||
366 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
367 | regular_key.release(); | ||
368 | run_one_scan_loop(); | ||
369 | EXPECT_TRUE(layer_state_is(1)); | ||
370 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
371 | } | ||
372 | |||
373 | TEST_F(ActionLayer, LayerTapReleasedBeforeKeypressReleaseWithModifiers) { | ||
374 | GTEST_SKIP() << "TODO: Modifiers are erroneously discarded on layer changes, although a key that introduced the modifier is still held."; | ||
375 | TestDriver driver; | ||
376 | InSequence s; | ||
377 | |||
378 | KeymapKey layer_0_key_0 = KeymapKey{0, 0, 0, LT(1, KC_T)}; | ||
379 | KeymapKey layer_1_key_1 = KeymapKey{1, 1, 0, RALT(KC_9)}; | ||
380 | |||
381 | set_keymap({layer_0_key_0, layer_1_key_1}); | ||
382 | |||
383 | /* Press layer tap and wait for tapping term to switch to layer 1 */ | ||
384 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(0); | ||
385 | layer_0_key_0.press(); | ||
386 | idle_for(TAPPING_TERM); | ||
387 | EXPECT_TRUE(layer_state_is(0)); | ||
388 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
389 | |||
390 | /* Press key with layer 1 mapping, result basically expected | ||
391 | * altough more reports are send then necessary. */ | ||
392 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RALT))).Times(1); | ||
393 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RALT, KC_9))).Times(1); | ||
394 | layer_1_key_1.press(); | ||
395 | run_one_scan_loop(); | ||
396 | EXPECT_TRUE(layer_state_is(1)); | ||
397 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
398 | |||
399 | /* Release layer tap key, no report is send because key is still held. */ | ||
400 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
401 | layer_0_key_0.release(); | ||
402 | run_one_scan_loop(); | ||
403 | EXPECT_TRUE(layer_state_is(0)); | ||
404 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
405 | |||
406 | /* Unregister keycode and modifier. */ | ||
407 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RALT))).Times(1); | ||
408 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
409 | layer_1_key_1.release(); | ||
410 | run_one_scan_loop(); | ||
411 | EXPECT_TRUE(layer_state_is(0)); | ||
412 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
413 | } | ||
diff --git a/tests/basic/test_keypress.cpp b/tests/basic/test_keypress.cpp new file mode 100644 index 000000000..1c175c9d5 --- /dev/null +++ b/tests/basic/test_keypress.cpp | |||
@@ -0,0 +1,317 @@ | |||
1 | /* Copyright 2017 Fred Sundvik | ||
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 "keycode.h" | ||
18 | #include "test_common.hpp" | ||
19 | |||
20 | using testing::_; | ||
21 | using testing::InSequence; | ||
22 | |||
23 | class KeyPress : public TestFixture {}; | ||
24 | |||
25 | TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { | ||
26 | TestDriver driver; | ||
27 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
28 | keyboard_task(); | ||
29 | } | ||
30 | |||
31 | TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) { | ||
32 | TestDriver driver; | ||
33 | auto key = KeymapKey(0, 0, 0, KC_A); | ||
34 | |||
35 | set_keymap({key}); | ||
36 | |||
37 | key.press(); | ||
38 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key.report_code))); | ||
39 | keyboard_task(); | ||
40 | |||
41 | key.release(); | ||
42 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
43 | keyboard_task(); | ||
44 | } | ||
45 | |||
46 | TEST_F(KeyPress, ANonMappedKeyDoesNothing) { | ||
47 | TestDriver driver; | ||
48 | auto key = KeymapKey(0, 0, 0, KC_NO); | ||
49 | |||
50 | set_keymap({key}); | ||
51 | |||
52 | key.press(); | ||
53 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
54 | keyboard_task(); | ||
55 | keyboard_task(); | ||
56 | } | ||
57 | |||
58 | TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { | ||
59 | TestDriver driver; | ||
60 | auto key_b = KeymapKey(0, 0, 0, KC_B); | ||
61 | auto key_c = KeymapKey(0, 1, 1, KC_C); | ||
62 | |||
63 | set_keymap({key_b, key_c}); | ||
64 | |||
65 | key_b.press(); | ||
66 | key_c.press(); | ||
67 | // Note that QMK only processes one key at a time | ||
68 | // See issue #1476 for more information | ||
69 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_b.report_code))); | ||
70 | keyboard_task(); | ||
71 | |||
72 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_b.report_code, key_c.report_code))); | ||
73 | keyboard_task(); | ||
74 | |||
75 | key_b.release(); | ||
76 | key_c.release(); | ||
77 | // Note that the first key released is the first one in the matrix order | ||
78 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_c.report_code))); | ||
79 | keyboard_task(); | ||
80 | |||
81 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
82 | keyboard_task(); | ||
83 | } | ||
84 | |||
85 | TEST_F(KeyPress, LeftShiftIsReportedCorrectly) { | ||
86 | TestDriver driver; | ||
87 | auto key_a = KeymapKey(0, 0, 0, KC_A); | ||
88 | auto key_lsft = KeymapKey(0, 3, 0, KC_LSFT); | ||
89 | |||
90 | set_keymap({key_a, key_lsft}); | ||
91 | |||
92 | key_lsft.press(); | ||
93 | key_a.press(); | ||
94 | |||
95 | // Unfortunately modifiers are also processed in the wrong order | ||
96 | // See issue #1476 for more information | ||
97 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_a.report_code))); | ||
98 | keyboard_task(); | ||
99 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_a.report_code, key_lsft.report_code))); | ||
100 | keyboard_task(); | ||
101 | |||
102 | key_a.release(); | ||
103 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_lsft.report_code))); | ||
104 | keyboard_task(); | ||
105 | |||
106 | key_lsft.release(); | ||
107 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
108 | keyboard_task(); | ||
109 | } | ||
110 | |||
111 | TEST_F(KeyPress, PressLeftShiftAndControl) { | ||
112 | TestDriver driver; | ||
113 | auto key_lsft = KeymapKey(0, 3, 0, KC_LSFT); | ||
114 | auto key_lctrl = KeymapKey(0, 5, 0, KC_LCTRL); | ||
115 | |||
116 | set_keymap({key_lctrl, key_lsft}); | ||
117 | |||
118 | key_lsft.press(); | ||
119 | key_lctrl.press(); | ||
120 | |||
121 | // Unfortunately modifiers are also processed in the wrong order | ||
122 | // See issue #1476 for more information | ||
123 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_lsft.report_code))); | ||
124 | keyboard_task(); | ||
125 | |||
126 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_lsft.report_code, key_lctrl.report_code))); | ||
127 | keyboard_task(); | ||
128 | |||
129 | key_lsft.release(); | ||
130 | key_lctrl.release(); | ||
131 | |||
132 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_lctrl.report_code))); | ||
133 | keyboard_task(); | ||
134 | |||
135 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
136 | keyboard_task(); | ||
137 | } | ||
138 | |||
139 | TEST_F(KeyPress, LeftAndRightShiftCanBePressedAtTheSameTime) { | ||
140 | TestDriver driver; | ||
141 | auto key_lsft = KeymapKey(0, 3, 0, KC_LSFT); | ||
142 | auto key_rsft = KeymapKey(0, 4, 0, KC_RSFT); | ||
143 | |||
144 | set_keymap({key_rsft, key_lsft}); | ||
145 | |||
146 | key_lsft.press(); | ||
147 | key_rsft.press(); | ||
148 | // Unfortunately modifiers are also processed in the wrong order | ||
149 | // See issue #1476 for more information | ||
150 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_lsft.report_code))); | ||
151 | keyboard_task(); | ||
152 | |||
153 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_lsft.report_code, key_rsft.report_code))); | ||
154 | keyboard_task(); | ||
155 | |||
156 | key_lsft.release(); | ||
157 | key_rsft.release(); | ||
158 | |||
159 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_rsft.report_code))); | ||
160 | keyboard_task(); | ||
161 | |||
162 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
163 | keyboard_task(); | ||
164 | } | ||
165 | |||
166 | TEST_F(KeyPress, RightShiftLeftControlAndCharWithTheSameKey) { | ||
167 | TestDriver driver; | ||
168 | auto combo_key = KeymapKey(0, 0, 0, RSFT(LCTL(KC_O))); | ||
169 | |||
170 | set_keymap({combo_key}); | ||
171 | |||
172 | // BUG: The press is split into two reports | ||
173 | // BUG: It reports RSFT instead of LSFT | ||
174 | // See issue #524 for more information | ||
175 | // The underlying cause is that we use only one bit to represent the right hand | ||
176 | // modifiers. | ||
177 | combo_key.press(); | ||
178 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL))); | ||
179 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL, KC_O))); | ||
180 | keyboard_task(); | ||
181 | |||
182 | combo_key.release(); | ||
183 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL))); | ||
184 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
185 | keyboard_task(); | ||
186 | } | ||
187 | |||
188 | TEST_F(KeyPress, PressPlusEqualReleaseBeforePress) { | ||
189 | TestDriver driver; | ||
190 | InSequence s; | ||
191 | auto key_plus = KeymapKey(0, 1, 1, KC_PLUS); | ||
192 | auto key_eql = KeymapKey(0, 0, 1, KC_EQL); | ||
193 | |||
194 | set_keymap({key_plus, key_eql}); | ||
195 | |||
196 | key_plus.press(); | ||
197 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
198 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL))); | ||
199 | run_one_scan_loop(); | ||
200 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
201 | |||
202 | key_plus.release(); | ||
203 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
204 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
205 | run_one_scan_loop(); | ||
206 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
207 | |||
208 | key_eql.press(); | ||
209 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_eql.report_code))); | ||
210 | run_one_scan_loop(); | ||
211 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
212 | |||
213 | key_eql.release(); | ||
214 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
215 | run_one_scan_loop(); | ||
216 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
217 | } | ||
218 | |||
219 | TEST_F(KeyPress, PressPlusEqualDontReleaseBeforePress) { | ||
220 | TestDriver driver; | ||
221 | InSequence s; | ||
222 | auto key_plus = KeymapKey(0, 1, 1, KC_PLUS); | ||
223 | auto key_eql = KeymapKey(0, 0, 1, KC_EQL); | ||
224 | |||
225 | set_keymap({key_plus, key_eql}); | ||
226 | |||
227 | key_plus.press(); | ||
228 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
229 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL))); | ||
230 | run_one_scan_loop(); | ||
231 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
232 | |||
233 | key_eql.press(); | ||
234 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
235 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQUAL))); | ||
236 | run_one_scan_loop(); | ||
237 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
238 | |||
239 | key_plus.release(); | ||
240 | // BUG: Should really still return KC_EQL, but this is fine too | ||
241 | // It's also called twice for some reason | ||
242 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(2); | ||
243 | run_one_scan_loop(); | ||
244 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
245 | |||
246 | key_eql.release(); | ||
247 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
248 | run_one_scan_loop(); | ||
249 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
250 | } | ||
251 | |||
252 | TEST_F(KeyPress, PressEqualPlusReleaseBeforePress) { | ||
253 | TestDriver driver; | ||
254 | InSequence s; | ||
255 | auto key_plus = KeymapKey(0, 1, 1, KC_PLUS); | ||
256 | auto key_eql = KeymapKey(0, 0, 1, KC_EQL); | ||
257 | |||
258 | set_keymap({key_plus, key_eql}); | ||
259 | |||
260 | key_eql.press(); | ||
261 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQL))); | ||
262 | run_one_scan_loop(); | ||
263 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
264 | |||
265 | key_eql.release(); | ||
266 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
267 | run_one_scan_loop(); | ||
268 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
269 | |||
270 | key_plus.press(); | ||
271 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
272 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL))); | ||
273 | run_one_scan_loop(); | ||
274 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
275 | |||
276 | key_plus.release(); | ||
277 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
278 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
279 | run_one_scan_loop(); | ||
280 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
281 | } | ||
282 | |||
283 | TEST_F(KeyPress, PressEqualPlusDontReleaseBeforePress) { | ||
284 | TestDriver driver; | ||
285 | InSequence s; | ||
286 | auto key_plus = KeymapKey(0, 1, 1, KC_PLUS); | ||
287 | auto key_eql = KeymapKey(0, 0, 1, KC_EQL); | ||
288 | |||
289 | set_keymap({key_plus, key_eql}); | ||
290 | |||
291 | key_eql.press(); | ||
292 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQL))); | ||
293 | run_one_scan_loop(); | ||
294 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
295 | |||
296 | key_plus.press(); | ||
297 | // BUG: The sequence is a bit strange, but it works, the end result is that | ||
298 | // KC_PLUS is sent | ||
299 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_EQUAL))); | ||
300 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); | ||
301 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_EQUAL))); | ||
302 | run_one_scan_loop(); | ||
303 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
304 | |||
305 | key_eql.release(); | ||
306 | // I guess it's fine to still report shift here | ||
307 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); | ||
308 | run_one_scan_loop(); | ||
309 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
310 | |||
311 | key_plus.release(); | ||
312 | // This report is not needed | ||
313 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); | ||
314 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
315 | run_one_scan_loop(); | ||
316 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
317 | } \ No newline at end of file | ||
diff --git a/tests/basic/test_macro.cpp b/tests/basic/test_macro.cpp new file mode 100644 index 000000000..ae2f3b32e --- /dev/null +++ b/tests/basic/test_macro.cpp | |||
@@ -0,0 +1,88 @@ | |||
1 | /* Copyright 2017 Fred Sundvik | ||
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 "test_common.hpp" | ||
18 | #include "time.h" | ||
19 | |||
20 | using testing::InSequence; | ||
21 | using testing::InvokeWithoutArgs; | ||
22 | |||
23 | class Macro : public TestFixture {}; | ||
24 | |||
25 | #define AT_TIME(t) WillOnce(InvokeWithoutArgs([current_time]() { EXPECT_EQ(timer_elapsed32(current_time), t); })) | ||
26 | |||
27 | extern "C" const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { | ||
28 | if (record->event.pressed) { | ||
29 | switch (id) { | ||
30 | case 0: | ||
31 | return MACRO(D(LSFT), T(H), U(LSFT), T(E), T(L), T(L), T(O), T(SPACE), W(100), D(LSFT), T(W), U(LSFT), I(10), T(O), T(R), T(L), T(D), D(LSFT), T(1), U(LSFT), END); | ||
32 | } | ||
33 | } | ||
34 | return MACRO_NONE; | ||
35 | }; | ||
36 | |||
37 | TEST_F(Macro, PlayASimpleMacro) { | ||
38 | TestDriver driver; | ||
39 | InSequence s; | ||
40 | auto key_macro = KeymapKey(0, 8, 0, M(0)); | ||
41 | |||
42 | set_keymap({key_macro}); | ||
43 | |||
44 | key_macro.press(); | ||
45 | |||
46 | uint32_t current_time = timer_read32(); | ||
47 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).AT_TIME(0); | ||
48 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_H))).AT_TIME(0); | ||
49 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).AT_TIME(0); | ||
50 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0); | ||
51 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_E))).AT_TIME(0); | ||
52 | // The macro system could actually skip these empty keyboard reports | ||
53 | // it should be enough to just send a report with the next key down | ||
54 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0); | ||
55 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L))).AT_TIME(0); | ||
56 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0); | ||
57 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L))).AT_TIME(0); | ||
58 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0); | ||
59 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_O))).AT_TIME(0); | ||
60 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0); | ||
61 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_SPACE))).AT_TIME(0); | ||
62 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0); | ||
63 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).AT_TIME(100); | ||
64 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_W))).AT_TIME(100); | ||
65 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).AT_TIME(100); | ||
66 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(100); | ||
67 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_O))) | ||
68 | // BUG: The timer should not really have advanced 10 ms here | ||
69 | // See issue #1477 | ||
70 | .AT_TIME(110); | ||
71 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())) | ||
72 | // BUG: The timer should not advance on both keydown and key-up | ||
73 | // See issue #1477 | ||
74 | .AT_TIME(120); | ||
75 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_R))).AT_TIME(130); | ||
76 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(140); | ||
77 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L))).AT_TIME(150); | ||
78 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(160); | ||
79 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_D))).AT_TIME(170); | ||
80 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(180); | ||
81 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).AT_TIME(190); | ||
82 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_1))).AT_TIME(200); | ||
83 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).AT_TIME(210); | ||
84 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(220); | ||
85 | run_one_scan_loop(); | ||
86 | |||
87 | key_macro.release(); | ||
88 | } | ||
diff --git a/tests/basic/test_one_shot_keys.cpp b/tests/basic/test_one_shot_keys.cpp new file mode 100644 index 000000000..98178912e --- /dev/null +++ b/tests/basic/test_one_shot_keys.cpp | |||
@@ -0,0 +1,197 @@ | |||
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_F(OneShot, OSMWithoutAdditionalKeypressDoesNothing) { | ||
28 | TestDriver driver; | ||
29 | auto osm_key = KeymapKey(0, 0, 0, OSM(MOD_LSFT), KC_LSFT); | ||
30 | |||
31 | set_keymap({osm_key}); | ||
32 | |||
33 | /* Press and release OSM key*/ | ||
34 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
35 | osm_key.press(); | ||
36 | run_one_scan_loop(); | ||
37 | osm_key.release(); | ||
38 | run_one_scan_loop(); | ||
39 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
40 | |||
41 | /* OSM are added when an actual report is send */ | ||
42 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(osm_key.report_code))); | ||
43 | send_keyboard_report(); | ||
44 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
45 | |||
46 | /* Make unit-test pass */ | ||
47 | clear_oneshot_mods(); | ||
48 | } | ||
49 | |||
50 | #if defined(ONESHOT_TIMEOUT) | ||
51 | |||
52 | TEST_P(OneShotParametrizedTestFixture, OSMExpiredDoesNothing) { | ||
53 | TestDriver driver; | ||
54 | KeymapKey osm_key = GetParam().first; | ||
55 | KeymapKey regular_key = GetParam().second; | ||
56 | |||
57 | set_keymap({osm_key, regular_key}); | ||
58 | |||
59 | /* Press and release OSM */ | ||
60 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
61 | osm_key.press(); | ||
62 | run_one_scan_loop(); | ||
63 | osm_key.release(); | ||
64 | idle_for(ONESHOT_TIMEOUT); | ||
65 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
66 | |||
67 | /* Press regular key */ | ||
68 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(regular_key.report_code))).Times(1); | ||
69 | regular_key.press(); | ||
70 | run_one_scan_loop(); | ||
71 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
72 | |||
73 | /* Release regular key */ | ||
74 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
75 | regular_key.release(); | ||
76 | run_one_scan_loop(); | ||
77 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
78 | } | ||
79 | |||
80 | #endif | ||
81 | |||
82 | TEST_P(OneShotParametrizedTestFixture, OSMWithAdditionalKeypress) { | ||
83 | TestDriver driver; | ||
84 | KeymapKey osm_key = GetParam().first; | ||
85 | KeymapKey regular_key = GetParam().second; | ||
86 | |||
87 | set_keymap({osm_key, regular_key}); | ||
88 | |||
89 | /* Press and release OSM */ | ||
90 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
91 | osm_key.press(); | ||
92 | run_one_scan_loop(); | ||
93 | osm_key.release(); | ||
94 | run_one_scan_loop(); | ||
95 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
96 | |||
97 | /* Press regular key */ | ||
98 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(osm_key.report_code, regular_key.report_code))).Times(1); | ||
99 | regular_key.press(); | ||
100 | run_one_scan_loop(); | ||
101 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
102 | |||
103 | /* Release regular key */ | ||
104 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
105 | regular_key.release(); | ||
106 | run_one_scan_loop(); | ||
107 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
108 | } | ||
109 | |||
110 | TEST_P(OneShotParametrizedTestFixture, OSMAsRegularModifierWithAdditionalKeypress) { | ||
111 | TestDriver driver; | ||
112 | testing::InSequence s; | ||
113 | |||
114 | KeymapKey osm_key = GetParam().first; | ||
115 | KeymapKey regular_key = GetParam().second; | ||
116 | |||
117 | set_keymap({osm_key, regular_key}); | ||
118 | |||
119 | /* Press OSM */ | ||
120 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
121 | osm_key.press(); | ||
122 | run_one_scan_loop(); | ||
123 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
124 | |||
125 | /* Press regular key */ | ||
126 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
127 | regular_key.press(); | ||
128 | run_one_scan_loop(); | ||
129 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
130 | |||
131 | /* Release regular key */ | ||
132 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
133 | regular_key.release(); | ||
134 | run_one_scan_loop(); | ||
135 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
136 | |||
137 | /* Release OSM */ | ||
138 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(regular_key.report_code, osm_key.report_code))).Times(1); | ||
139 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
140 | osm_key.release(); | ||
141 | run_one_scan_loop(); | ||
142 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
143 | } | ||
144 | |||
145 | // clang-format off | ||
146 | |||
147 | INSTANTIATE_TEST_CASE_P( | ||
148 | OneShotModifierTests, | ||
149 | OneShotParametrizedTestFixture, | ||
150 | ::testing::Values( | ||
151 | /* first is osm key, second is regular key. */ | ||
152 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_LSFT), KC_LSFT}, KeymapKey{0, 1, 1, KC_A}), | ||
153 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_LCTL), KC_LCTL}, KeymapKey{0, 1, 1, KC_A}), | ||
154 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_LALT), KC_LALT}, KeymapKey{0, 1, 1, KC_A}), | ||
155 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_LGUI), KC_LGUI}, KeymapKey{0, 1, 1, KC_A}), | ||
156 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_RCTL), KC_RCTL}, KeymapKey{0, 1, 1, KC_A}), | ||
157 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_RSFT), KC_RSFT}, KeymapKey{0, 1, 1, KC_A}), | ||
158 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_RALT), KC_RALT}, KeymapKey{0, 1, 1, KC_A}), | ||
159 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_RGUI), KC_RGUI}, KeymapKey{0, 1, 1, KC_A}) | ||
160 | )); | ||
161 | // clang-format on | ||
162 | |||
163 | TEST_F(OneShot, OSLWithAdditionalKeypress) { | ||
164 | TestDriver driver; | ||
165 | InSequence s; | ||
166 | KeymapKey osl_key = KeymapKey{0, 0, 0, OSL(1)}; | ||
167 | KeymapKey regular_key = KeymapKey{1, 1, 0, KC_A}; | ||
168 | |||
169 | set_keymap({osl_key, regular_key}); | ||
170 | |||
171 | /* Press OSL key */ | ||
172 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
173 | osl_key.press(); | ||
174 | run_one_scan_loop(); | ||
175 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
176 | |||
177 | /* Release OSL key */ | ||
178 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(2); | ||
179 | osl_key.release(); | ||
180 | run_one_scan_loop(); | ||
181 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
182 | |||
183 | /* Press regular key */ | ||
184 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
185 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(regular_key.report_code))).Times(2); | ||
186 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
187 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
188 | regular_key.press(); | ||
189 | run_one_scan_loop(); | ||
190 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
191 | |||
192 | /* Release regular key */ | ||
193 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
194 | regular_key.release(); | ||
195 | run_one_scan_loop(); | ||
196 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
197 | } | ||
diff --git a/tests/basic/test_tapping.cpp b/tests/basic/test_tapping.cpp new file mode 100644 index 000000000..e4a7e4a9f --- /dev/null +++ b/tests/basic/test_tapping.cpp | |||
@@ -0,0 +1,123 @@ | |||
1 | /* Copyright 2017 Fred Sundvik | ||
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, TapA_SHFT_T_KeyReportsKey) { | ||
29 | TestDriver driver; | ||
30 | InSequence s; | ||
31 | auto key_shift_hold_p_tap = KeymapKey(0, 7, 0, SFT_T(KC_P)); | ||
32 | |||
33 | set_keymap({key_shift_hold_p_tap}); | ||
34 | |||
35 | // Tapping keys does nothing on press | ||
36 | key_shift_hold_p_tap.press(); | ||
37 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
38 | run_one_scan_loop(); | ||
39 | |||
40 | // First we get the key press | ||
41 | key_shift_hold_p_tap.release(); | ||
42 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
43 | |||
44 | // Then the release | ||
45 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
46 | run_one_scan_loop(); | ||
47 | } | ||
48 | |||
49 | TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) { | ||
50 | TestDriver driver; | ||
51 | InSequence s; | ||
52 | auto mod_tap_hold_key = KeymapKey(0, 7, 0, SFT_T(KC_P)); | ||
53 | |||
54 | set_keymap({mod_tap_hold_key}); | ||
55 | |||
56 | mod_tap_hold_key.press(); | ||
57 | |||
58 | // Tapping keys does nothing on press | ||
59 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
60 | idle_for(TAPPING_TERM); | ||
61 | |||
62 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
63 | run_one_scan_loop(); | ||
64 | |||
65 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
66 | mod_tap_hold_key.release(); | ||
67 | run_one_scan_loop(); | ||
68 | } | ||
69 | |||
70 | TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) { | ||
71 | // See issue #1478 for more information | ||
72 | TestDriver driver; | ||
73 | InSequence s; | ||
74 | auto key_shift_hold_p_tap = KeymapKey(0, 7, 0, SFT_T(KC_P)); | ||
75 | |||
76 | set_keymap({key_shift_hold_p_tap}); | ||
77 | |||
78 | // Tapping keys does nothing on press | ||
79 | key_shift_hold_p_tap.press(); | ||
80 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
81 | run_one_scan_loop(); | ||
82 | key_shift_hold_p_tap.release(); | ||
83 | |||
84 | // First we get the key press | ||
85 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
86 | // Then the release | ||
87 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
88 | run_one_scan_loop(); | ||
89 | |||
90 | // This sends KC_P, even if it should do nothing | ||
91 | key_shift_hold_p_tap.press(); | ||
92 | // This test should not succed if everything works correctly | ||
93 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
94 | run_one_scan_loop(); | ||
95 | |||
96 | key_shift_hold_p_tap.release(); | ||
97 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
98 | idle_for(TAPPING_TERM + 1); | ||
99 | |||
100 | // On the other hand, nothing is sent if we are outside the tapping term | ||
101 | key_shift_hold_p_tap.press(); | ||
102 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
103 | run_one_scan_loop(); | ||
104 | key_shift_hold_p_tap.release(); | ||
105 | |||
106 | // First we get the key press | ||
107 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
108 | // Then the release | ||
109 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
110 | idle_for(TAPPING_TERM + 1); | ||
111 | |||
112 | // Now we are geting into strange territory, as the hold registers too early here | ||
113 | // But the stranges part is: | ||
114 | // If TAPPING_TERM + 1 above is changed to TAPPING_TERM or TAPPING_TERM + 2 it doesn't | ||
115 | key_shift_hold_p_tap.press(); | ||
116 | // Shouldn't be called here really | ||
117 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).Times(1); | ||
118 | idle_for(TAPPING_TERM); | ||
119 | |||
120 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
121 | key_shift_hold_p_tap.release(); | ||
122 | run_one_scan_loop(); | ||
123 | } \ No newline at end of file | ||