keyboard stuff
1/* Copyright 2022 Isaac Elenbaas
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 "keyboard_report_util.hpp"
18#include "keycode.h"
19#include "test_common.hpp"
20#include "action_tapping.h"
21#include "test_fixture.hpp"
22#include "test_keymap_key.hpp"
23
24using testing::_;
25using testing::AnyNumber;
26using testing::InSequence;
27
28class AutoShiftRepeat : public TestFixture {};
29
30TEST_F(AutoShiftRepeat, tap_regular_key_cancelling_another_key_hold) {
31 TestDriver driver;
32 InSequence s;
33 auto repeat_key = KeymapKey(0, 1, 0, KC_P);
34 auto regular_key = KeymapKey(0, 2, 0, KC_A);
35
36 set_keymap({repeat_key, regular_key});
37
38 /* Press repeat key. */
39 EXPECT_NO_REPORT(driver);
40 repeat_key.press();
41 run_one_scan_loop();
42 testing::Mock::VerifyAndClearExpectations(&driver);
43
44 /* Press regular key. */
45 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(testing::AnyNumber());
46 EXPECT_REPORT(driver, (KC_P));
47 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(testing::AnyNumber());
48 regular_key.press();
49 run_one_scan_loop();
50 testing::Mock::VerifyAndClearExpectations(&driver);
51
52 /* Release regular key. */
53 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(testing::AnyNumber());
54 EXPECT_REPORT(driver, (KC_A));
55 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(testing::AnyNumber());
56 regular_key.release();
57 run_one_scan_loop();
58 testing::Mock::VerifyAndClearExpectations(&driver);
59
60 /* Release repeat key. */
61 EXPECT_NO_REPORT(driver);
62 repeat_key.release();
63 run_one_scan_loop();
64 testing::Mock::VerifyAndClearExpectations(&driver);
65}
66
67TEST_F(AutoShiftRepeat, tap_regular_key_while_another_key_is_held) {
68 TestDriver driver;
69 InSequence s;
70 auto repeat_key = KeymapKey(0, 1, 0, KC_P);
71 auto regular_key = KeymapKey(0, 2, 0, KC_A);
72
73 set_keymap({repeat_key, regular_key});
74
75 /* Press repeat key. */
76 EXPECT_NO_REPORT(driver);
77 repeat_key.press();
78 run_one_scan_loop();
79 testing::Mock::VerifyAndClearExpectations(&driver);
80
81 /* Idle for auto-repeat to kick in. */
82 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).Times(AnyNumber());
83 EXPECT_REPORT(driver, (KC_LSFT, KC_P));
84 idle_for(AUTO_SHIFT_TIMEOUT);
85 run_one_scan_loop();
86 testing::Mock::VerifyAndClearExpectations(&driver);
87
88 /* Press regular key. */
89 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).Times(AnyNumber());
90 EXPECT_NO_REPORT(driver);
91 regular_key.press();
92 run_one_scan_loop();
93 testing::Mock::VerifyAndClearExpectations(&driver);
94
95 /* Release regular key. */
96 EXPECT_REPORT(driver, (KC_P, KC_A));
97 EXPECT_REPORT(driver, (KC_P));
98 regular_key.release();
99 run_one_scan_loop();
100 testing::Mock::VerifyAndClearExpectations(&driver);
101
102 /* Release repeat key. */
103 EXPECT_EMPTY_REPORT(driver);
104 repeat_key.release();
105 run_one_scan_loop();
106 testing::Mock::VerifyAndClearExpectations(&driver);
107}