diff options
| author | fredizzimo <fsundvik@gmail.com> | 2020-03-13 20:09:38 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-13 14:09:38 -0400 |
| commit | 9e8767917d628afd3dc43759d1d50151c61944a1 (patch) | |
| tree | 0060b8968d5e9df38c37b375e4eb2d6a0d65ac0c /tests | |
| parent | f89439ae09c06d0e85f59af2bc5e020d141f23d6 (diff) | |
| download | qmk_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')
| -rw-r--r-- | tests/basic/keymap.c | 3 | ||||
| -rw-r--r-- | tests/basic/test_keypress.cpp | 118 | ||||
| -rw-r--r-- | tests/test_common/test_fixture.cpp | 7 |
3 files changed, 123 insertions, 5 deletions
diff --git a/tests/basic/keymap.c b/tests/basic/keymap.c index 02b3cc961..951ce8e0c 100644 --- a/tests/basic/keymap.c +++ b/tests/basic/keymap.c | |||
| @@ -28,7 +28,7 @@ const uint16_t PROGMEM | |||
| 28 | { | 28 | { |
| 29 | // 0 1 2 3 4 5 6 7 8 9 | 29 | // 0 1 2 3 4 5 6 7 8 9 |
| 30 | {KC_A, KC_B, KC_NO, KC_LSFT, KC_RSFT, KC_LCTL, COMBO1, SFT_T(KC_P), M(0), KC_NO}, | 30 | {KC_A, KC_B, KC_NO, KC_LSFT, KC_RSFT, KC_LCTL, COMBO1, SFT_T(KC_P), M(0), KC_NO}, |
| 31 | {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, | 31 | {KC_EQL, KC_PLUS, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, |
| 32 | {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, | 32 | {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, |
| 33 | {KC_C, KC_D, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, | 33 | {KC_C, KC_D, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, |
| 34 | }, | 34 | }, |
| @@ -43,3 +43,4 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { | |||
| 43 | } | 43 | } |
| 44 | return MACRO_NONE; | 44 | return MACRO_NONE; |
| 45 | }; | 45 | }; |
| 46 | |||
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 | ||
| 19 | using testing::_; | 19 | using testing::_; |
| 20 | using testing::Return; | 20 | using testing::Return; |
| 21 | using testing::InSequence; | ||
| 21 | 22 | ||
| 22 | class KeyPress : public TestFixture {}; | 23 | class 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 | |||
| 127 | TEST_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 | |||
| 154 | TEST_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 | |||
| 183 | TEST_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 | |||
| 210 | TEST_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 | } | ||
diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp index 8caf1fca4..20ed838eb 100644 --- a/tests/test_common/test_fixture.cpp +++ b/tests/test_common/test_fixture.cpp | |||
| @@ -32,14 +32,15 @@ TestFixture::TestFixture() {} | |||
| 32 | 32 | ||
| 33 | TestFixture::~TestFixture() { | 33 | TestFixture::~TestFixture() { |
| 34 | TestDriver driver; | 34 | TestDriver driver; |
| 35 | layer_clear(); | ||
| 36 | clear_all_keys(); | ||
| 37 | // Run for a while to make sure all keys are completely released | 35 | // Run for a while to make sure all keys are completely released |
| 38 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(AnyNumber()); | 36 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(AnyNumber()); |
| 37 | layer_clear(); | ||
| 38 | clear_all_keys(); | ||
| 39 | idle_for(TAPPING_TERM + 10); | 39 | idle_for(TAPPING_TERM + 10); |
| 40 | testing::Mock::VerifyAndClearExpectations(&driver); | 40 | testing::Mock::VerifyAndClearExpectations(&driver); |
| 41 | // Verify that the matrix really is cleared | 41 | // Verify that the matrix really is cleared |
| 42 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(Between(0, 1)); | 42 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(0); |
| 43 | idle_for(TAPPING_TERM + 10); | ||
| 43 | } | 44 | } |
| 44 | 45 | ||
| 45 | void TestFixture::run_one_scan_loop() { | 46 | void TestFixture::run_one_scan_loop() { |
