]> git.donarmstrong.com Git - qmk_firmware.git/blob - tests/basic/test_tapping.cpp
update layout macros for planck
[qmk_firmware.git] / tests / basic / test_tapping.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 #include "action_tapping.h"
19
20 using testing::_;
21 using testing::InSequence;
22
23 class Tapping : public TestFixture {};
24
25 TEST_F(Tapping, TapA_SHFT_T_KeyReportsKey) {
26     TestDriver driver;
27     InSequence s;
28
29     press_key(7, 0);
30     // Tapping keys does nothing on press
31     EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
32     run_one_scan_loop();
33     release_key(7, 0);
34     // First we get the key press
35     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
36     // Then the release
37     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
38     run_one_scan_loop();
39 }
40
41 TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) {
42     TestDriver driver;
43     InSequence s;
44
45     press_key(7, 0);
46     // Tapping keys does nothing on press
47     EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
48     idle_for(TAPPING_TERM);
49     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
50     run_one_scan_loop();
51 }
52
53 TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) {
54     // See issue #1478 for more information
55     TestDriver driver;
56     InSequence s;
57
58     press_key(7, 0);
59     // Tapping keys does nothing on press
60     EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
61     run_one_scan_loop();
62     release_key(7, 0);
63     // First we get the key press
64     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
65     // Then the release
66     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
67     run_one_scan_loop();
68
69     // This sends KC_P, even if it should do nothing
70     press_key(7, 0);
71     // This test should not succed if everything works correctly
72     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
73     run_one_scan_loop();
74     release_key(7, 0);
75     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
76     idle_for(TAPPING_TERM + 1);
77
78     // On the other hand, nothing is sent if we are outside the tapping term
79     press_key(7, 0);
80     EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
81     run_one_scan_loop();
82     release_key(7, 0);
83
84     // First we get the key press
85     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
86     // Then the release
87     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
88     idle_for(TAPPING_TERM + 1);
89
90     // Now we are geting into strange territory, as the hold registers too early here
91     // But the stranges part is:
92     // If TAPPING_TERM + 1 above is changed to TAPPING_TERM or TAPPING_TERM + 2 it doesn't
93     press_key(7, 0);
94     // Shouldn't be called here really
95     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).Times(1);
96     idle_for(TAPPING_TERM);
97 }