From e5780a6dc66bb21969594f1b446916e36cf69253 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 2 Jul 2017 01:06:59 +0300 Subject: Add tests for macros --- tests/basic/test_macro.cpp | 97 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 tests/basic/test_macro.cpp (limited to 'tests/basic/test_macro.cpp') diff --git a/tests/basic/test_macro.cpp b/tests/basic/test_macro.cpp new file mode 100644 index 000000000..f1990bf6f --- /dev/null +++ b/tests/basic/test_macro.cpp @@ -0,0 +1,97 @@ +/* Copyright 2017 Fred Sundvik + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test_common.h" +#include "time.h" + +using testing::InSequence; +using testing::InvokeWithoutArgs; + +class Macro : public TestFixture {}; + +#define AT_TIME(t) WillOnce(InvokeWithoutArgs([current_time]() {EXPECT_EQ(timer_elapsed32(current_time), t);})) + +TEST_F(Macro, PlayASimpleMacro) { + TestDriver driver; + InSequence s; + press_key(8, 0); + uint32_t current_time = timer_read32(); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))) + .AT_TIME(0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_H))) + .AT_TIME(0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))) + .AT_TIME(0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())) + .AT_TIME(0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_E))) + .AT_TIME(0); + // The macro system could actually skip these empty keyboard reports + // it should be enough to just send a report with the next key down + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())) + .AT_TIME(0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L))) + .AT_TIME(0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())) + .AT_TIME(0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L))) + .AT_TIME(0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())) + .AT_TIME(0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_O))) + .AT_TIME(0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())) + .AT_TIME(0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_SPACE))) + .AT_TIME(0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())) + .AT_TIME(0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))) + .AT_TIME(100); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_W))) + .AT_TIME(100); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))) + .AT_TIME(100); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())) + .AT_TIME(100); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_O))) + // BUG: The timer should not really have advanced 10 ms here + .AT_TIME(110); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())) + // BUG: The timer should not advance on both keydown and key-up + .AT_TIME(120); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_R))) + .AT_TIME(130); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())) + .AT_TIME(140); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_L))) + .AT_TIME(150); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())) + .AT_TIME(160); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_D))) + .AT_TIME(170); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())) + .AT_TIME(180); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))) + .AT_TIME(190); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_1))) + .AT_TIME(200); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))) + .AT_TIME(210); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())) + .AT_TIME(220); + run_one_scan_loop(); +} \ No newline at end of file -- cgit v1.2.3 From 67f722c9c8cb077b946dfb2b6a3b538e37f3aa8c Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 2 Jul 2017 21:46:35 +0300 Subject: Configure vscode file associations, use hpp instead of h --- tests/basic/test_macro.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/basic/test_macro.cpp') diff --git a/tests/basic/test_macro.cpp b/tests/basic/test_macro.cpp index f1990bf6f..56ee5ad3e 100644 --- a/tests/basic/test_macro.cpp +++ b/tests/basic/test_macro.cpp @@ -14,7 +14,7 @@ * along with this program. If not, see . */ -#include "test_common.h" +#include "test_common.hpp" #include "time.h" using testing::InSequence; -- cgit v1.2.3 From b3af79eaffcf272df7327d2e23cba8b60acea792 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 8 Jul 2017 19:34:51 +0300 Subject: Reference issue #1477 from the unit tests --- tests/basic/test_macro.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/basic/test_macro.cpp') diff --git a/tests/basic/test_macro.cpp b/tests/basic/test_macro.cpp index 56ee5ad3e..80676d515 100644 --- a/tests/basic/test_macro.cpp +++ b/tests/basic/test_macro.cpp @@ -69,9 +69,11 @@ TEST_F(Macro, PlayASimpleMacro) { .AT_TIME(100); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_O))) // BUG: The timer should not really have advanced 10 ms here + // See issue #1477 .AT_TIME(110); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())) // BUG: The timer should not advance on both keydown and key-up + // See issue #1477 .AT_TIME(120); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_R))) .AT_TIME(130); -- cgit v1.2.3