]> git.donarmstrong.com Git - qmk_firmware.git/blob - tests/basic/test_keypress.cpp
Extended the hint of the programmer to link to the relevant README part instead of...
[qmk_firmware.git] / tests / basic / test_keypress.cpp
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.hpp"
18
19 using testing::_;
20 using testing::Return;
21
22 class KeyPress : public TestFixture {};
23
24 TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) {
25     TestDriver driver;
26     EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
27     keyboard_task();
28 }
29
30 TEST_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
40 TEST_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     //See issue #1476 for more information
46     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B)));
47     keyboard_task();
48     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C)));
49     keyboard_task();
50     release_key(1, 0);
51     release_key(0, 3);
52     //Note that the first key released is the first one in the matrix order
53     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_C)));
54     keyboard_task();
55     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
56     keyboard_task();
57 }
58
59 TEST_F(KeyPress, ANonMappedKeyDoesNothing) {
60     TestDriver driver;
61     press_key(2, 0);
62     EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
63     keyboard_task();
64     keyboard_task();
65 }
66
67 TEST_F(KeyPress, LeftShiftIsReportedCorrectly) {
68     TestDriver driver;
69     press_key(3, 0);
70     press_key(0, 0);
71     // Unfortunately modifiers are also processed in the wrong order
72     // See issue #1476 for more information
73     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A)));
74     keyboard_task();
75     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A, KC_LSFT)));
76     keyboard_task();
77     release_key(0, 0);
78     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
79     keyboard_task();
80     release_key(3, 0);
81     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
82     keyboard_task();
83 }
84
85 TEST_F(KeyPress, PressLeftShiftAndControl) {
86     TestDriver driver;
87     press_key(3, 0);
88     press_key(5, 0);
89     // Unfortunately modifiers are also processed in the wrong order
90     // See issue #1476 for more information
91     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
92     keyboard_task();
93     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_LCTRL)));
94     keyboard_task();
95 }
96
97 TEST_F(KeyPress, LeftAndRightShiftCanBePressedAtTheSameTime) {
98     TestDriver driver;
99     press_key(3, 0);
100     press_key(4, 0);
101     // Unfortunately modifiers are also processed in the wrong order
102     // See issue #1476 for more information
103     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
104     keyboard_task();
105     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_RSFT)));
106     keyboard_task();
107 }
108
109 TEST_F(KeyPress, RightShiftLeftControlAndCharWithTheSameKey) {
110     TestDriver driver;
111     press_key(6, 0);
112     // BUG: The press is split into two reports
113     // BUG: It reports RSFT instead of LSFT
114     // See issue #524 for more information
115     // The underlying cause is that we use only one bit to represent the right hand
116     // modifiers.
117     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL)));
118     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL, KC_O)));
119     keyboard_task();
120     release_key(6, 0);
121     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL)));
122     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
123     keyboard_task();
124 }