aboutsummaryrefslogtreecommitdiff
path: root/tests/basic/test_keypress.cpp
diff options
context:
space:
mode:
authorfredizzimo <fsundvik@gmail.com>2020-03-13 20:09:38 +0200
committerGitHub <noreply@github.com>2020-03-13 14:09:38 -0400
commit9e8767917d628afd3dc43759d1d50151c61944a1 (patch)
tree0060b8968d5e9df38c37b375e4eb2d6a0d65ac0c /tests/basic/test_keypress.cpp
parentf89439ae09c06d0e85f59af2bc5e020d141f23d6 (diff)
downloadqmk_firmware-9e8767917d628afd3dc43759d1d50151c61944a1.tar.gz
qmk_firmware-9e8767917d628afd3dc43759d1d50151c61944a1.zip
Fix pressing two keys with the same keycode but different modifiers (#2710)
* Fix extra keyboard report during test_fixture teardown * Add tests for pressing two keys with only different modifers * Fix #1708 When two keys that use the same keycode, but different modifiers were pressed at the same time, the second keypress wasn't registered. This is fixed by forcing a key release when we detect a new press for the same keycode. * Fix the NKRO version of is_key_pressed * Fix uninitalized loop variable Co-authored-by: Jack Humbert <jack.humb@gmail.com>
Diffstat (limited to 'tests/basic/test_keypress.cpp')
-rw-r--r--tests/basic/test_keypress.cpp118
1 files changed, 117 insertions, 1 deletions
diff --git a/tests/basic/test_keypress.cpp b/tests/basic/test_keypress.cpp
index e5247911c..551458a0d 100644
--- a/tests/basic/test_keypress.cpp
+++ b/tests/basic/test_keypress.cpp
@@ -18,6 +18,7 @@
18 18
19using testing::_; 19using testing::_;
20using testing::Return; 20using testing::Return;
21using testing::InSequence;
21 22
22class KeyPress : public TestFixture {}; 23class KeyPress : public TestFixture {};
23 24
@@ -121,4 +122,119 @@ TEST_F(KeyPress, RightShiftLeftControlAndCharWithTheSameKey) {
121 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL))); 122 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL)));
122 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); 123 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
123 keyboard_task(); 124 keyboard_task();
124} \ No newline at end of file 125}
126
127TEST_F(KeyPress, PressPlusEqualReleaseBeforePress) {
128 TestDriver driver;
129 InSequence s;
130
131 press_key(1, 1); // KC_PLUS
132 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
133 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL)));
134 run_one_scan_loop();
135 testing::Mock::VerifyAndClearExpectations(&driver);
136
137 release_key(1, 1); // KC_PLUS
138 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
139 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
140 run_one_scan_loop();
141 testing::Mock::VerifyAndClearExpectations(&driver);
142
143 press_key(0, 1); // KC_EQL
144 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQL)));
145 run_one_scan_loop();
146 testing::Mock::VerifyAndClearExpectations(&driver);
147
148 release_key(0, 1); // KC_EQL
149 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
150 run_one_scan_loop();
151 testing::Mock::VerifyAndClearExpectations(&driver);
152}
153
154TEST_F(KeyPress, PressPlusEqualDontReleaseBeforePress) {
155 TestDriver driver;
156 InSequence s;
157
158 press_key(1, 1); // KC_PLUS
159 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
160 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL)));
161 run_one_scan_loop();
162 testing::Mock::VerifyAndClearExpectations(&driver);
163
164 press_key(0, 1); // KC_EQL
165 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
166 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQL)));
167 run_one_scan_loop();
168 testing::Mock::VerifyAndClearExpectations(&driver);
169
170 release_key(1, 1); //KC_PLS
171 // BUG: Should really still return KC_EQL, but this is fine too
172 // It's also called twice for some reason
173 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(2);
174 run_one_scan_loop();
175 testing::Mock::VerifyAndClearExpectations(&driver);
176
177 release_key(0, 1); // KC_EQL
178 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
179 run_one_scan_loop();
180 testing::Mock::VerifyAndClearExpectations(&driver);
181}
182
183TEST_F(KeyPress, PressEqualPlusReleaseBeforePress) {
184 TestDriver driver;
185 InSequence s;
186
187 press_key(0, 1); // KC_EQL
188 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQL)));
189 run_one_scan_loop();
190 testing::Mock::VerifyAndClearExpectations(&driver);
191
192 release_key(0, 1); // KQ_EQL
193 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
194 run_one_scan_loop();
195 testing::Mock::VerifyAndClearExpectations(&driver);
196
197 press_key(1, 1); // KC_PLUS
198 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
199 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL)));
200 run_one_scan_loop();
201 testing::Mock::VerifyAndClearExpectations(&driver);
202
203 release_key(1, 1); // KC_PLUS
204 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
205 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
206 run_one_scan_loop();
207 testing::Mock::VerifyAndClearExpectations(&driver);
208}
209
210TEST_F(KeyPress, PressEqualPlusDontReleaseBeforePress) {
211 TestDriver driver;
212 InSequence s;
213
214 press_key(0, 1); // KC_EQL
215 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQL)));
216 run_one_scan_loop();
217 testing::Mock::VerifyAndClearExpectations(&driver);
218
219 press_key(1, 1); // KC_PLUS
220 // BUG: The sequence is a bit strange, but it works, the end result is that
221 // KC_PLUS is sent
222 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL)));
223 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
224 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL)));
225 run_one_scan_loop();
226 testing::Mock::VerifyAndClearExpectations(&driver);
227
228 release_key(0, 1); //KC_EQL
229 // I guess it's fine to still report shift here
230 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
231 run_one_scan_loop();
232 testing::Mock::VerifyAndClearExpectations(&driver);
233
234 release_key(1, 1); // KC_PLUS
235 // This report is not needed
236 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
237 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
238 run_one_scan_loop();
239 testing::Mock::VerifyAndClearExpectations(&driver);
240}