aboutsummaryrefslogtreecommitdiff
path: root/tests/basic/test_macro.cpp
diff options
context:
space:
mode:
authorAkshay <[email protected]>2022-04-10 12:13:40 +0100
committerAkshay <[email protected]>2022-04-10 12:13:40 +0100
commitdc90387ce7d8ba7b607d9c48540bf6d8b560f14d (patch)
tree4ccb8fa5886b66fa9d480edef74236c27f035e16 /tests/basic/test_macro.cpp
Diffstat (limited to 'tests/basic/test_macro.cpp')
-rw-r--r--tests/basic/test_macro.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/basic/test_macro.cpp b/tests/basic/test_macro.cpp
new file mode 100644
index 000000000..ae2f3b32e
--- /dev/null
+++ b/tests/basic/test_macro.cpp
@@ -0,0 +1,88 @@
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 "time.h"
19
20using testing::InSequence;
21using testing::InvokeWithoutArgs;
22
23class Macro : public TestFixture {};
24
25#define AT_TIME(t) WillOnce(InvokeWithoutArgs([current_time]() { EXPECT_EQ(timer_elapsed32(current_time), t); }))
26
27extern "C" const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) {
28 if (record->event.pressed) {
29 switch (id) {
30 case 0:
31 return MACRO(D(LSFT), T(H), U(LSFT), T(E), T(L), T(L), T(O), T(SPACE), W(100), D(LSFT), T(W), U(LSFT), I(10), T(O), T(R), T(L), T(D), D(LSFT), T(1), U(LSFT), END);
32 }
33 }
34 return MACRO_NONE;
35};
36
37TEST_F(Macro, PlayASimpleMacro) {
38 TestDriver driver;
39 InSequence s;
40 auto key_macro = KeymapKey(0, 8, 0, M(0));
41
42 set_keymap({key_macro});
43
44 key_macro.press();
45
46 uint32_t current_time = timer_read32();
47 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).AT_TIME(0);
48 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_H))).AT_TIME(0);
49 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).AT_TIME(0);
50 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0);
51 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_E))).AT_TIME(0);
52 // The macro system could actually skip these empty keyboard reports
53 // it should be enough to just send a report with the next key down
54 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0);
55 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L))).AT_TIME(0);
56 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0);
57 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L))).AT_TIME(0);
58 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0);
59 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_O))).AT_TIME(0);
60 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0);
61 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_SPACE))).AT_TIME(0);
62 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(0);
63 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).AT_TIME(100);
64 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_W))).AT_TIME(100);
65 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).AT_TIME(100);
66 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(100);
67 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_O)))
68 // BUG: The timer should not really have advanced 10 ms here
69 // See issue #1477
70 .AT_TIME(110);
71 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()))
72 // BUG: The timer should not advance on both keydown and key-up
73 // See issue #1477
74 .AT_TIME(120);
75 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_R))).AT_TIME(130);
76 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(140);
77 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L))).AT_TIME(150);
78 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(160);
79 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_D))).AT_TIME(170);
80 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(180);
81 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).AT_TIME(190);
82 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_1))).AT_TIME(200);
83 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).AT_TIME(210);
84 EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(220);
85 run_one_scan_loop();
86
87 key_macro.release();
88}