aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/basic/keymap.c1
-rw-r--r--tests/basic/test_keypress.cpp208
-rw-r--r--tmk_core/common/action.c4
-rw-r--r--tmk_core/common/report.c30
-rw-r--r--tmk_core/common/report.h2
5 files changed, 122 insertions, 123 deletions
diff --git a/tests/basic/keymap.c b/tests/basic/keymap.c
index 951ce8e0c..2b5747abb 100644
--- a/tests/basic/keymap.c
+++ b/tests/basic/keymap.c
@@ -43,4 +43,3 @@ 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 551458a0d..ecd6e98e4 100644
--- a/tests/basic/test_keypress.cpp
+++ b/tests/basic/test_keypress.cpp
@@ -17,8 +17,8 @@
17#include "test_common.hpp" 17#include "test_common.hpp"
18 18
19using testing::_; 19using testing::_;
20using testing::Return;
21using testing::InSequence; 20using testing::InSequence;
21using testing::Return;
22 22
23class KeyPress : public TestFixture {}; 23class KeyPress : public TestFixture {};
24 24
@@ -125,116 +125,116 @@ TEST_F(KeyPress, RightShiftLeftControlAndCharWithTheSameKey) {
125} 125}
126 126
127TEST_F(KeyPress, PressPlusEqualReleaseBeforePress) { 127TEST_F(KeyPress, PressPlusEqualReleaseBeforePress) {
128 TestDriver driver; 128 TestDriver driver;
129 InSequence s; 129 InSequence s;
130 130
131 press_key(1, 1); // KC_PLUS 131 press_key(1, 1); // KC_PLUS
132 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); 132 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
133 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL))); 133 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL)));
134 run_one_scan_loop(); 134 run_one_scan_loop();
135 testing::Mock::VerifyAndClearExpectations(&driver); 135 testing::Mock::VerifyAndClearExpectations(&driver);
136 136
137 release_key(1, 1); // KC_PLUS 137 release_key(1, 1); // KC_PLUS
138 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); 138 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
139 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); 139 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
140 run_one_scan_loop(); 140 run_one_scan_loop();
141 testing::Mock::VerifyAndClearExpectations(&driver); 141 testing::Mock::VerifyAndClearExpectations(&driver);
142 142
143 press_key(0, 1); // KC_EQL 143 press_key(0, 1); // KC_EQL
144 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQL))); 144 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQL)));
145 run_one_scan_loop(); 145 run_one_scan_loop();
146 testing::Mock::VerifyAndClearExpectations(&driver); 146 testing::Mock::VerifyAndClearExpectations(&driver);
147 147
148 release_key(0, 1); // KC_EQL 148 release_key(0, 1); // KC_EQL
149 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); 149 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
150 run_one_scan_loop(); 150 run_one_scan_loop();
151 testing::Mock::VerifyAndClearExpectations(&driver); 151 testing::Mock::VerifyAndClearExpectations(&driver);
152} 152}
153 153
154TEST_F(KeyPress, PressPlusEqualDontReleaseBeforePress) { 154TEST_F(KeyPress, PressPlusEqualDontReleaseBeforePress) {
155 TestDriver driver; 155 TestDriver driver;
156 InSequence s; 156 InSequence s;
157 157
158 press_key(1, 1); // KC_PLUS 158 press_key(1, 1); // KC_PLUS
159 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); 159 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
160 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL))); 160 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL)));
161 run_one_scan_loop(); 161 run_one_scan_loop();
162 testing::Mock::VerifyAndClearExpectations(&driver); 162 testing::Mock::VerifyAndClearExpectations(&driver);
163 163
164 press_key(0, 1); // KC_EQL 164 press_key(0, 1); // KC_EQL
165 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); 165 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
166 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQL))); 166 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQL)));
167 run_one_scan_loop(); 167 run_one_scan_loop();
168 testing::Mock::VerifyAndClearExpectations(&driver); 168 testing::Mock::VerifyAndClearExpectations(&driver);
169 169
170 release_key(1, 1); //KC_PLS 170 release_key(1, 1); // KC_PLS
171 // BUG: Should really still return KC_EQL, but this is fine too 171 // BUG: Should really still return KC_EQL, but this is fine too
172 // It's also called twice for some reason 172 // It's also called twice for some reason
173 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(2); 173 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(2);
174 run_one_scan_loop(); 174 run_one_scan_loop();
175 testing::Mock::VerifyAndClearExpectations(&driver); 175 testing::Mock::VerifyAndClearExpectations(&driver);
176 176
177 release_key(0, 1); // KC_EQL 177 release_key(0, 1); // KC_EQL
178 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); 178 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
179 run_one_scan_loop(); 179 run_one_scan_loop();
180 testing::Mock::VerifyAndClearExpectations(&driver); 180 testing::Mock::VerifyAndClearExpectations(&driver);
181} 181}
182 182
183TEST_F(KeyPress, PressEqualPlusReleaseBeforePress) { 183TEST_F(KeyPress, PressEqualPlusReleaseBeforePress) {
184 TestDriver driver; 184 TestDriver driver;
185 InSequence s; 185 InSequence s;
186 186
187 press_key(0, 1); // KC_EQL 187 press_key(0, 1); // KC_EQL
188 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQL))); 188 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQL)));
189 run_one_scan_loop(); 189 run_one_scan_loop();
190 testing::Mock::VerifyAndClearExpectations(&driver); 190 testing::Mock::VerifyAndClearExpectations(&driver);
191 191
192 release_key(0, 1); // KQ_EQL 192 release_key(0, 1); // KQ_EQL
193 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); 193 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
194 run_one_scan_loop(); 194 run_one_scan_loop();
195 testing::Mock::VerifyAndClearExpectations(&driver); 195 testing::Mock::VerifyAndClearExpectations(&driver);
196 196
197 press_key(1, 1); // KC_PLUS 197 press_key(1, 1); // KC_PLUS
198 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); 198 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
199 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL))); 199 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL)));
200 run_one_scan_loop(); 200 run_one_scan_loop();
201 testing::Mock::VerifyAndClearExpectations(&driver); 201 testing::Mock::VerifyAndClearExpectations(&driver);
202 202
203 release_key(1, 1); // KC_PLUS 203 release_key(1, 1); // KC_PLUS
204 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); 204 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
205 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); 205 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
206 run_one_scan_loop(); 206 run_one_scan_loop();
207 testing::Mock::VerifyAndClearExpectations(&driver); 207 testing::Mock::VerifyAndClearExpectations(&driver);
208} 208}
209 209
210TEST_F(KeyPress, PressEqualPlusDontReleaseBeforePress) { 210TEST_F(KeyPress, PressEqualPlusDontReleaseBeforePress) {
211 TestDriver driver; 211 TestDriver driver;
212 InSequence s; 212 InSequence s;
213 213
214 press_key(0, 1); // KC_EQL 214 press_key(0, 1); // KC_EQL
215 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQL))); 215 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQL)));
216 run_one_scan_loop(); 216 run_one_scan_loop();
217 testing::Mock::VerifyAndClearExpectations(&driver); 217 testing::Mock::VerifyAndClearExpectations(&driver);
218 218
219 press_key(1, 1); // KC_PLUS 219 press_key(1, 1); // KC_PLUS
220 // BUG: The sequence is a bit strange, but it works, the end result is that 220 // BUG: The sequence is a bit strange, but it works, the end result is that
221 // KC_PLUS is sent 221 // KC_PLUS is sent
222 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL))); 222 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL)));
223 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); 223 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
224 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL))); 224 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL)));
225 run_one_scan_loop(); 225 run_one_scan_loop();
226 testing::Mock::VerifyAndClearExpectations(&driver); 226 testing::Mock::VerifyAndClearExpectations(&driver);
227 227
228 release_key(0, 1); //KC_EQL 228 release_key(0, 1); // KC_EQL
229 // I guess it's fine to still report shift here 229 // I guess it's fine to still report shift here
230 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); 230 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
231 run_one_scan_loop(); 231 run_one_scan_loop();
232 testing::Mock::VerifyAndClearExpectations(&driver); 232 testing::Mock::VerifyAndClearExpectations(&driver);
233 233
234 release_key(1, 1); // KC_PLUS 234 release_key(1, 1); // KC_PLUS
235 // This report is not needed 235 // This report is not needed
236 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); 236 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
237 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); 237 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
238 run_one_scan_loop(); 238 run_one_scan_loop();
239 testing::Mock::VerifyAndClearExpectations(&driver); 239 testing::Mock::VerifyAndClearExpectations(&driver);
240} 240}
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index 2deafd465..555a71ebc 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -758,8 +758,8 @@ void register_code(uint8_t code) {
758 // without this, keys with the same keycode, but different 758 // without this, keys with the same keycode, but different
759 // modifiers will be reported incorrectly, see issue #1708 759 // modifiers will be reported incorrectly, see issue #1708
760 if (is_key_pressed(keyboard_report, code)) { 760 if (is_key_pressed(keyboard_report, code)) {
761 del_key(code); 761 del_key(code);
762 send_keyboard_report(); 762 send_keyboard_report();
763 } 763 }
764 add_key(code); 764 add_key(code);
765 send_keyboard_report(); 765 send_keyboard_report();
diff --git a/tmk_core/common/report.c b/tmk_core/common/report.c
index f4cdca728..1bcb6f2ad 100644
--- a/tmk_core/common/report.c
+++ b/tmk_core/common/report.c
@@ -74,24 +74,24 @@ uint8_t get_first_key(report_keyboard_t* keyboard_report) {
74 * Note: The function doesn't support modifers currently, and it returns false for KC_NO 74 * Note: The function doesn't support modifers currently, and it returns false for KC_NO
75 */ 75 */
76bool is_key_pressed(report_keyboard_t* keyboard_report, uint8_t key) { 76bool is_key_pressed(report_keyboard_t* keyboard_report, uint8_t key) {
77 if (key == KC_NO) { 77 if (key == KC_NO) {
78 return false; 78 return false;
79 } 79 }
80#ifdef NKRO_ENABLE 80#ifdef NKRO_ENABLE
81 if (keyboard_protocol && keymap_config.nkro) { 81 if (keyboard_protocol && keymap_config.nkro) {
82 if ((key>>3) < KEYBOARD_REPORT_BITS) { 82 if ((key >> 3) < KEYBOARD_REPORT_BITS) {
83 return keyboard_report->nkro.bits[key>>3] & 1<<(key&7); 83 return keyboard_report->nkro.bits[key >> 3] & 1 << (key & 7);
84 } else { 84 } else {
85 return false; 85 return false;
86 }
86 } 87 }
87 }
88#endif 88#endif
89 for (int i=0; i < KEYBOARD_REPORT_KEYS; i++) { 89 for (int i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
90 if (keyboard_report->keys[i] == key) { 90 if (keyboard_report->keys[i] == key) {
91 return true; 91 return true;
92 } 92 }
93 } 93 }
94 return false; 94 return false;
95} 95}
96 96
97/** \brief add key byte 97/** \brief add key byte
diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h
index 645e01612..b7d104a45 100644
--- a/tmk_core/common/report.h
+++ b/tmk_core/common/report.h
@@ -237,7 +237,7 @@ static inline uint16_t KEYCODE2CONSUMER(uint8_t key) {
237 237
238uint8_t has_anykey(report_keyboard_t* keyboard_report); 238uint8_t has_anykey(report_keyboard_t* keyboard_report);
239uint8_t get_first_key(report_keyboard_t* keyboard_report); 239uint8_t get_first_key(report_keyboard_t* keyboard_report);
240bool is_key_pressed(report_keyboard_t* keyboard_report, uint8_t key); 240bool is_key_pressed(report_keyboard_t* keyboard_report, uint8_t key);
241 241
242void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code); 242void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code);
243void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code); 243void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code);