aboutsummaryrefslogtreecommitdiff
path: root/tests/basic/test_keypress.cpp
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2017-07-01 22:46:21 +0300
committerJack Humbert <jack.humb@gmail.com>2017-07-08 21:59:51 -0400
commitfc4bfbe580c520caed5b6682790019658133f74e (patch)
tree115266c40c06d828dcf0b4faa5e80a336949141d /tests/basic/test_keypress.cpp
parent4e69a8bda6c4003c6b9e33de7db89fe073c970f5 (diff)
downloadqmk_firmware-fc4bfbe580c520caed5b6682790019658133f74e.tar.gz
qmk_firmware-fc4bfbe580c520caed5b6682790019658133f74e.zip
Rename tests to start with test_
Diffstat (limited to 'tests/basic/test_keypress.cpp')
-rw-r--r--tests/basic/test_keypress.cpp117
1 files changed, 117 insertions, 0 deletions
diff --git a/tests/basic/test_keypress.cpp b/tests/basic/test_keypress.cpp
new file mode 100644
index 000000000..2323b7cb4
--- /dev/null
+++ b/tests/basic/test_keypress.cpp
@@ -0,0 +1,117 @@
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.h"
18
19using testing::_;
20using testing::Return;
21
22class KeyPress : public TestFixture {};
23
24TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) {
25 TestDriver driver;
26 EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
27 keyboard_task();
28}
29
30TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) {
31 TestDriver driver;
32 press_key(0, 0);
33 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
34 keyboard_task();
35 release_key(0, 0);
36 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
37 keyboard_task();
38}
39
40TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) {
41 TestDriver driver;
42 press_key(1, 0);
43 press_key(0, 3);
44 //Note that QMK only processes one key at a time
45 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B)));
46 keyboard_task();
47 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C)));
48 keyboard_task();
49 release_key(1, 0);
50 release_key(0, 3);
51 //Note that the first key released is the first one in the matrix order
52 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_C)));
53 keyboard_task();
54 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
55 keyboard_task();
56}
57
58TEST_F(KeyPress, ANonMappedKeyDoesNothing) {
59 TestDriver driver;
60 press_key(2, 0);
61 EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
62 keyboard_task();
63 keyboard_task();
64}
65
66TEST_F(KeyPress, LeftShiftIsReportedCorrectly) {
67 TestDriver driver;
68 press_key(3, 0);
69 press_key(0, 0);
70 // Unfortunately modifiers are also processed in the wrong order
71 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
72 keyboard_task();
73 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A, KC_LSFT)));
74 keyboard_task();
75 release_key(0, 0);
76 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
77 keyboard_task();
78 release_key(3, 0);
79 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
80 keyboard_task();
81}
82
83TEST_F(KeyPress, PressLeftShiftAndControl) {
84 TestDriver driver;
85 press_key(3, 0);
86 press_key(5, 0);
87 // Unfortunately modifiers are also processed in the wrong order
88 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
89 keyboard_task();
90 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_LCTRL)));
91 keyboard_task();
92}
93
94TEST_F(KeyPress, LeftAndRightShiftCanBePressedAtTheSameTime) {
95 TestDriver driver;
96 press_key(3, 0);
97 press_key(4, 0);
98 // Unfortunately modifiers are also processed in the wrong order
99 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
100 keyboard_task();
101 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_RSFT)));
102 keyboard_task();
103}
104
105TEST_F(KeyPress, RightShiftLeftControlAndCharWithTheSameKey) {
106 TestDriver driver;
107 press_key(6, 0);
108 // BUG: The press is split into two reports
109 // BUG: It reports RSFT instead of LSFT
110 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL)));
111 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL, KC_O)));
112 keyboard_task();
113 release_key(6, 0);
114 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL)));
115 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
116 keyboard_task();
117} \ No newline at end of file