diff options
Diffstat (limited to 'tests/tap_hold_configurations/permissive_hold/test_tap_hold.cpp')
-rw-r--r-- | tests/tap_hold_configurations/permissive_hold/test_tap_hold.cpp | 132 |
1 files changed, 132 insertions, 0 deletions
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 | ||