From 7d7996278571334d04e4a05445ffa4bf341806a2 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Mon, 26 Jun 2017 23:56:01 +0300 Subject: Move test keymap to keymap.c --- tests/basic/keymap.c | 24 ++++++++++++++++++++++++ tests/basic/test.cpp | 7 ------- 2 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 tests/basic/keymap.c (limited to 'tests') diff --git a/tests/basic/keymap.c b/tests/basic/keymap.c new file mode 100644 index 000000000..2afb4d6a9 --- /dev/null +++ b/tests/basic/keymap.c @@ -0,0 +1,24 @@ +/* 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 "quantum.h" + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = { + {KC_A, KC_B}, + {KC_C, KC_D} + }, +}; diff --git a/tests/basic/test.cpp b/tests/basic/test.cpp index 1bd5c2762..f574481f2 100644 --- a/tests/basic/test.cpp +++ b/tests/basic/test.cpp @@ -26,13 +26,6 @@ using testing::_; using testing::Return; -const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { - [0] = { - {KC_A, KC_B}, - {KC_C, KC_D} - }, -}; - class KeyPress : public TestFixture {}; TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { -- cgit v1.2.3 From 1e4cc36e14d711d2fc755354f9b6fd80c9728882 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Tue, 27 Jun 2017 00:01:58 +0300 Subject: Rename test.cpp to keypress.cpp --- tests/basic/keypress.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/basic/test.cpp | 53 ------------------------------------------------ 2 files changed, 53 insertions(+), 53 deletions(-) create mode 100644 tests/basic/keypress.cpp delete mode 100644 tests/basic/test.cpp (limited to 'tests') diff --git a/tests/basic/keypress.cpp b/tests/basic/keypress.cpp new file mode 100644 index 000000000..f574481f2 --- /dev/null +++ b/tests/basic/keypress.cpp @@ -0,0 +1,53 @@ +/* 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 "gtest/gtest.h" +#include "gmock/gmock.h" + +#include "quantum.h" +#include "test_driver.h" +#include "test_matrix.h" +#include "keyboard_report_util.h" +#include "test_fixture.h" + +using testing::_; +using testing::Return; + +class KeyPress : public TestFixture {}; + +TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { + TestDriver driver; + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + keyboard_task(); +} + +TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) { + TestDriver driver; + press_key(0, 0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); + keyboard_task(); +} + +TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { + TestDriver driver; + press_key(1, 0); + press_key(0, 1); + //Note that QMK only processes one key at a time + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))); + keyboard_task(); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C))); + keyboard_task(); +} diff --git a/tests/basic/test.cpp b/tests/basic/test.cpp deleted file mode 100644 index f574481f2..000000000 --- a/tests/basic/test.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* 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 "gtest/gtest.h" -#include "gmock/gmock.h" - -#include "quantum.h" -#include "test_driver.h" -#include "test_matrix.h" -#include "keyboard_report_util.h" -#include "test_fixture.h" - -using testing::_; -using testing::Return; - -class KeyPress : public TestFixture {}; - -TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { - TestDriver driver; - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); - keyboard_task(); -} - -TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) { - TestDriver driver; - press_key(0, 0); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); - keyboard_task(); -} - -TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { - TestDriver driver; - press_key(1, 0); - press_key(0, 1); - //Note that QMK only processes one key at a time - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))); - keyboard_task(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C))); - keyboard_task(); -} -- cgit v1.2.3 From 72c8df1f190d34d4eb48e9f06d13c9a4de566716 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Tue, 27 Jun 2017 00:13:21 +0300 Subject: A bigger test matrix, and test for unmapped keys --- tests/basic/config.h | 4 ++-- tests/basic/keymap.c | 8 ++++++-- tests/basic/keypress.cpp | 11 ++++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/basic/config.h b/tests/basic/config.h index 4da8d0425..a52d8a4fa 100644 --- a/tests/basic/config.h +++ b/tests/basic/config.h @@ -17,8 +17,8 @@ #ifndef TESTS_BASIC_CONFIG_H_ #define TESTS_BASIC_CONFIG_H_ -#define MATRIX_ROWS 2 -#define MATRIX_COLS 2 +#define MATRIX_ROWS 4 +#define MATRIX_COLS 10 #endif /* TESTS_BASIC_CONFIG_H_ */ diff --git a/tests/basic/keymap.c b/tests/basic/keymap.c index 2afb4d6a9..c0e0dfb49 100644 --- a/tests/basic/keymap.c +++ b/tests/basic/keymap.c @@ -16,9 +16,13 @@ #include "quantum.h" +// Don't rearrange keys as existing tests might rely on the order +// Col2, Row 0 has to be KC_NO, because tests rely on it const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = { - {KC_A, KC_B}, - {KC_C, KC_D} + {KC_A, KC_B, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, + {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, + {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, + {KC_C, KC_D, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, }, }; diff --git a/tests/basic/keypress.cpp b/tests/basic/keypress.cpp index f574481f2..2b8b96b22 100644 --- a/tests/basic/keypress.cpp +++ b/tests/basic/keypress.cpp @@ -44,10 +44,19 @@ TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) { TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { TestDriver driver; press_key(1, 0); - press_key(0, 1); + press_key(0, 3); //Note that QMK only processes one key at a time EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))); keyboard_task(); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C))); keyboard_task(); } + +TEST_F(KeyPress, ANonMappedKeyDoesNothing) { + TestDriver driver; + press_key(2, 0); + //Note that QMK only processes one key at a time + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + keyboard_task(); + keyboard_task(); +} \ No newline at end of file -- cgit v1.2.3 From 1985f43bad9fd51101467bea994e000c6c295f00 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 1 Jul 2017 01:25:30 +0300 Subject: Improve the tests a bit --- tests/basic/keypress.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/basic/keypress.cpp b/tests/basic/keypress.cpp index 2b8b96b22..e2cc7279f 100644 --- a/tests/basic/keypress.cpp +++ b/tests/basic/keypress.cpp @@ -39,6 +39,9 @@ TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) { press_key(0, 0); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); keyboard_task(); + release_key(0, 0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + keyboard_task(); } TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { @@ -50,12 +53,18 @@ TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { keyboard_task(); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C))); keyboard_task(); + release_key(1, 0); + release_key(0, 3); + //Note that the first key released is the first one in the matrix order + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_C))); + keyboard_task(); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + keyboard_task(); } TEST_F(KeyPress, ANonMappedKeyDoesNothing) { TestDriver driver; press_key(2, 0); - //Note that QMK only processes one key at a time EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); keyboard_task(); keyboard_task(); -- cgit v1.2.3 From cae7a9c3ec3834f08dfd56b0f094dc6afaf2ccaa Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 1 Jul 2017 02:00:30 +0300 Subject: Add simple modifier test --- tests/basic/keymap.c | 9 +++++---- tests/basic/keypress.cpp | 17 +++++++++++++++++ tests/test_common/keyboard_report_util.cpp | 14 ++++++++++---- 3 files changed, 32 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/basic/keymap.c b/tests/basic/keymap.c index c0e0dfb49..a3e1aaf66 100644 --- a/tests/basic/keymap.c +++ b/tests/basic/keymap.c @@ -20,9 +20,10 @@ // Col2, Row 0 has to be KC_NO, because tests rely on it const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = { - {KC_A, KC_B, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, - {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, - {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, - {KC_C, KC_D, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, + // 0 1 2 3 4 5 6 7 8 9 + {KC_A, KC_B, KC_NO, KC_LSFT, KC_RSFT, KC_LCTL, KC_NO, KC_NO, KC_NO, KC_NO}, + {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, + {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, + {KC_C, KC_D, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, }, }; diff --git a/tests/basic/keypress.cpp b/tests/basic/keypress.cpp index e2cc7279f..4424e8696 100644 --- a/tests/basic/keypress.cpp +++ b/tests/basic/keypress.cpp @@ -68,4 +68,21 @@ TEST_F(KeyPress, ANonMappedKeyDoesNothing) { EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); keyboard_task(); keyboard_task(); +} + +TEST_F(KeyPress, LeftShiftIsReportedCorrectly) { + TestDriver driver; + press_key(3, 0); + press_key(0, 0); + // Unfortunately modifiers are also processed in the wrong order + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); + keyboard_task(); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A, KC_LSFT))); + keyboard_task(); + release_key(0, 0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); + keyboard_task(); + release_key(3, 0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + keyboard_task(); } \ No newline at end of file diff --git a/tests/test_common/keyboard_report_util.cpp b/tests/test_common/keyboard_report_util.cpp index aca4433dd..aa096e416 100644 --- a/tests/test_common/keyboard_report_util.cpp +++ b/tests/test_common/keyboard_report_util.cpp @@ -47,19 +47,25 @@ bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) { std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) { stream << "Keyboard report:" << std::endl; - stream << "Mods: " << value.mods << std::endl; + stream << "Mods: " << (uint32_t)value.mods << std::endl; + stream << "Keys: "; // TODO: This should probably print friendly names for the keys for (uint32_t k: get_keys(value)) { - stream << k << std::endl; + stream << k << " "; } + stream << std::endl; return stream; } KeyboardReportMatcher::KeyboardReportMatcher(const std::vector& keys) { - // TODO: Support modifiers memset(m_report.raw, 0, sizeof(m_report.raw)); for (auto k: keys) { - add_key_to_report(&m_report, k); + if (IS_MOD(k)) { + m_report.mods |= MOD_BIT(k); + } + else { + add_key_to_report(&m_report, k); + } } } -- cgit v1.2.3 From a62f4496599d4a1880adc5f272f97f81be0586cb Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 1 Jul 2017 02:43:32 +0300 Subject: Add test for a combo key --- tests/basic/keymap.c | 13 ++++++++----- tests/basic/keypress.cpp | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/basic/keymap.c b/tests/basic/keymap.c index a3e1aaf66..e3a60ccc4 100644 --- a/tests/basic/keymap.c +++ b/tests/basic/keymap.c @@ -18,12 +18,15 @@ // Don't rearrange keys as existing tests might rely on the order // Col2, Row 0 has to be KC_NO, because tests rely on it + +#define COMBO1 RSFT(LCTL(KC_O)) + const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = { - // 0 1 2 3 4 5 6 7 8 9 - {KC_A, KC_B, KC_NO, KC_LSFT, KC_RSFT, KC_LCTL, KC_NO, KC_NO, KC_NO, KC_NO}, - {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, - {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, - {KC_C, KC_D, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, + // 0 1 2 3 4 5 6 7 8 9 + {KC_A, KC_B, KC_NO, KC_LSFT, KC_RSFT, KC_LCTL, COMBO1, KC_NO, KC_NO, KC_NO}, + {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, + {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, + {KC_C, KC_D, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, }, }; diff --git a/tests/basic/keypress.cpp b/tests/basic/keypress.cpp index 4424e8696..2bb029d88 100644 --- a/tests/basic/keypress.cpp +++ b/tests/basic/keypress.cpp @@ -85,4 +85,40 @@ TEST_F(KeyPress, LeftShiftIsReportedCorrectly) { release_key(3, 0); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); keyboard_task(); +} + +TEST_F(KeyPress, PressLeftShiftAndControl) { + TestDriver driver; + press_key(3, 0); + press_key(5, 0); + // Unfortunately modifiers are also processed in the wrong order + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); + keyboard_task(); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_LCTRL))); + keyboard_task(); +} + +TEST_F(KeyPress, LeftAndRightShiftCanBePressedAtTheSameTime) { + TestDriver driver; + press_key(3, 0); + press_key(4, 0); + // Unfortunately modifiers are also processed in the wrong order + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); + keyboard_task(); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_RSFT))); + keyboard_task(); +} + +TEST_F(KeyPress, RightShiftLeftControlAndCharWithTheSameKey) { + TestDriver driver; + press_key(6, 0); + // BUG: The press is split into two reports + // BUG: It reports RSFT instead of LSFT + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL))); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL, KC_O))); + keyboard_task(); + release_key(6, 0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL))); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + keyboard_task(); } \ No newline at end of file -- cgit v1.2.3 From 4e69a8bda6c4003c6b9e33de7db89fe073c970f5 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 1 Jul 2017 22:25:06 +0300 Subject: Add basic timing support, and SFT_T tests Also expose some bugs... --- tests/basic/config.h | 1 - tests/basic/keymap.c | 10 ++-- tests/basic/keypress.cpp | 9 +--- tests/basic/tapping.cpp | 96 ++++++++++++++++++++++++++++++++++++++ tests/test_common/test_common.h | 24 ++++++++++ tests/test_common/test_fixture.cpp | 23 +++++++-- tests/test_common/test_fixture.h | 2 + 7 files changed, 147 insertions(+), 18 deletions(-) create mode 100644 tests/basic/tapping.cpp create mode 100644 tests/test_common/test_common.h (limited to 'tests') diff --git a/tests/basic/config.h b/tests/basic/config.h index a52d8a4fa..e5d018a32 100644 --- a/tests/basic/config.h +++ b/tests/basic/config.h @@ -20,5 +20,4 @@ #define MATRIX_ROWS 4 #define MATRIX_COLS 10 - #endif /* TESTS_BASIC_CONFIG_H_ */ diff --git a/tests/basic/keymap.c b/tests/basic/keymap.c index e3a60ccc4..358cbdb59 100644 --- a/tests/basic/keymap.c +++ b/tests/basic/keymap.c @@ -23,10 +23,10 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = { - // 0 1 2 3 4 5 6 7 8 9 - {KC_A, KC_B, KC_NO, KC_LSFT, KC_RSFT, KC_LCTL, COMBO1, KC_NO, KC_NO, KC_NO}, - {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, - {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, - {KC_C, KC_D, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, + // 0 1 2 3 4 5 6 7 8 9 + {KC_A, KC_B, KC_NO, KC_LSFT, KC_RSFT, KC_LCTL, COMBO1, SFT_T(KC_P), KC_NO, KC_NO}, + {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, + {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, + {KC_C, KC_D, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, }, }; diff --git a/tests/basic/keypress.cpp b/tests/basic/keypress.cpp index 2bb029d88..2323b7cb4 100644 --- a/tests/basic/keypress.cpp +++ b/tests/basic/keypress.cpp @@ -14,14 +14,7 @@ * along with this program. If not, see . */ -#include "gtest/gtest.h" -#include "gmock/gmock.h" - -#include "quantum.h" -#include "test_driver.h" -#include "test_matrix.h" -#include "keyboard_report_util.h" -#include "test_fixture.h" +#include "test_common.h" using testing::_; using testing::Return; diff --git a/tests/basic/tapping.cpp b/tests/basic/tapping.cpp new file mode 100644 index 000000000..c158e1718 --- /dev/null +++ b/tests/basic/tapping.cpp @@ -0,0 +1,96 @@ +/* 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 "action_tapping.h" + +using testing::_; +using testing::InSequence; + +class Tapping : public TestFixture {}; + +TEST_F(Tapping, TapA_SHFT_T_KeyReportsKey) { + TestDriver driver; + InSequence s; + + press_key(7, 0); + // Tapping keys does nothing on press + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + run_one_scan_loop(); + release_key(7, 0); + // First we get the key press + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); + // Then the release + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + run_one_scan_loop(); +} + +TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) { + TestDriver driver; + InSequence s; + + press_key(7, 0); + // Tapping keys does nothing on press + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + idle_for(TAPPING_TERM); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); + run_one_scan_loop(); +} + +TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) { + TestDriver driver; + InSequence s; + + press_key(7, 0); + // Tapping keys does nothing on press + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + run_one_scan_loop(); + release_key(7, 0); + // First we get the key press + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); + // Then the release + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + run_one_scan_loop(); + + // This sends KC_P, even if it should do nothing + press_key(7, 0); + // This test should not succed if everything works correctly + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); + run_one_scan_loop(); + release_key(7, 0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + idle_for(TAPPING_TERM + 1); + + // On the other hand, nothing is sent if we are outside the tapping term + press_key(7, 0); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + run_one_scan_loop(); + release_key(7, 0); + + // First we get the key press + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); + // Then the release + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + idle_for(TAPPING_TERM + 1); + + // Now we are geting into strange territory, as the hold registers too early here + // But the stranges part is: + // If TAPPING_TERM + 1 above is changed to TAPPING_TERM or TAPPING_TERM + 2 it doesn't + press_key(7, 0); + // Shouldn't be called here really + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).Times(1); + idle_for(TAPPING_TERM); +} diff --git a/tests/test_common/test_common.h b/tests/test_common/test_common.h new file mode 100644 index 000000000..38eb0ed93 --- /dev/null +++ b/tests/test_common/test_common.h @@ -0,0 +1,24 @@ +/* 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 "gtest/gtest.h" +#include "gmock/gmock.h" + +#include "quantum.h" +#include "test_driver.h" +#include "test_matrix.h" +#include "keyboard_report_util.h" +#include "test_fixture.h" \ No newline at end of file diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp index eef9b854b..5ca5247db 100644 --- a/tests/test_common/test_fixture.cpp +++ b/tests/test_common/test_fixture.cpp @@ -3,6 +3,13 @@ #include "test_driver.h" #include "test_matrix.h" #include "keyboard.h" +#include "action.h" +#include "action_tapping.h" + +extern "C" { + void set_time(uint32_t t); + void advance_time(uint32_t ms); +} using testing::_; using testing::AnyNumber; @@ -25,12 +32,20 @@ TestFixture::~TestFixture() { TestDriver driver; clear_all_keys(); // Run for a while to make sure all keys are completely released - // Should probably wait until tapping term etc, has timed out EXPECT_CALL(driver, send_keyboard_mock(_)).Times(AnyNumber()); - for (int i=0; i<100; i++) { - keyboard_task(); - } + idle_for(TAPPING_TERM + 10); testing::Mock::VerifyAndClearExpectations(&driver); // Verify that the matrix really is cleared EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(Between(0, 1)); +} + +void TestFixture::run_one_scan_loop() { + keyboard_task(); + advance_time(1); +} + +void TestFixture::idle_for(uint time) { + for (uint i=0; i Date: Sat, 1 Jul 2017 22:46:21 +0300 Subject: Rename tests to start with test_ --- tests/basic/keypress.cpp | 117 ------------------------------------------ tests/basic/tapping.cpp | 96 ---------------------------------- tests/basic/test_keypress.cpp | 117 ++++++++++++++++++++++++++++++++++++++++++ tests/basic/test_tapping.cpp | 96 ++++++++++++++++++++++++++++++++++ 4 files changed, 213 insertions(+), 213 deletions(-) delete mode 100644 tests/basic/keypress.cpp delete mode 100644 tests/basic/tapping.cpp create mode 100644 tests/basic/test_keypress.cpp create mode 100644 tests/basic/test_tapping.cpp (limited to 'tests') diff --git a/tests/basic/keypress.cpp b/tests/basic/keypress.cpp deleted file mode 100644 index 2323b7cb4..000000000 --- a/tests/basic/keypress.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* 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" - -using testing::_; -using testing::Return; - -class KeyPress : public TestFixture {}; - -TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { - TestDriver driver; - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); - keyboard_task(); -} - -TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) { - TestDriver driver; - press_key(0, 0); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); - keyboard_task(); - release_key(0, 0); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); - keyboard_task(); -} - -TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { - TestDriver driver; - press_key(1, 0); - press_key(0, 3); - //Note that QMK only processes one key at a time - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))); - keyboard_task(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C))); - keyboard_task(); - release_key(1, 0); - release_key(0, 3); - //Note that the first key released is the first one in the matrix order - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_C))); - keyboard_task(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); - keyboard_task(); -} - -TEST_F(KeyPress, ANonMappedKeyDoesNothing) { - TestDriver driver; - press_key(2, 0); - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); - keyboard_task(); - keyboard_task(); -} - -TEST_F(KeyPress, LeftShiftIsReportedCorrectly) { - TestDriver driver; - press_key(3, 0); - press_key(0, 0); - // Unfortunately modifiers are also processed in the wrong order - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); - keyboard_task(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A, KC_LSFT))); - keyboard_task(); - release_key(0, 0); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); - keyboard_task(); - release_key(3, 0); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); - keyboard_task(); -} - -TEST_F(KeyPress, PressLeftShiftAndControl) { - TestDriver driver; - press_key(3, 0); - press_key(5, 0); - // Unfortunately modifiers are also processed in the wrong order - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); - keyboard_task(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_LCTRL))); - keyboard_task(); -} - -TEST_F(KeyPress, LeftAndRightShiftCanBePressedAtTheSameTime) { - TestDriver driver; - press_key(3, 0); - press_key(4, 0); - // Unfortunately modifiers are also processed in the wrong order - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); - keyboard_task(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_RSFT))); - keyboard_task(); -} - -TEST_F(KeyPress, RightShiftLeftControlAndCharWithTheSameKey) { - TestDriver driver; - press_key(6, 0); - // BUG: The press is split into two reports - // BUG: It reports RSFT instead of LSFT - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL))); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL, KC_O))); - keyboard_task(); - release_key(6, 0); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL))); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); - keyboard_task(); -} \ No newline at end of file diff --git a/tests/basic/tapping.cpp b/tests/basic/tapping.cpp deleted file mode 100644 index c158e1718..000000000 --- a/tests/basic/tapping.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* 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 "action_tapping.h" - -using testing::_; -using testing::InSequence; - -class Tapping : public TestFixture {}; - -TEST_F(Tapping, TapA_SHFT_T_KeyReportsKey) { - TestDriver driver; - InSequence s; - - press_key(7, 0); - // Tapping keys does nothing on press - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); - run_one_scan_loop(); - release_key(7, 0); - // First we get the key press - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); - // Then the release - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); - run_one_scan_loop(); -} - -TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) { - TestDriver driver; - InSequence s; - - press_key(7, 0); - // Tapping keys does nothing on press - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); - idle_for(TAPPING_TERM); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); - run_one_scan_loop(); -} - -TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) { - TestDriver driver; - InSequence s; - - press_key(7, 0); - // Tapping keys does nothing on press - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); - run_one_scan_loop(); - release_key(7, 0); - // First we get the key press - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); - // Then the release - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); - run_one_scan_loop(); - - // This sends KC_P, even if it should do nothing - press_key(7, 0); - // This test should not succed if everything works correctly - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); - run_one_scan_loop(); - release_key(7, 0); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); - idle_for(TAPPING_TERM + 1); - - // On the other hand, nothing is sent if we are outside the tapping term - press_key(7, 0); - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); - run_one_scan_loop(); - release_key(7, 0); - - // First we get the key press - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); - // Then the release - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); - idle_for(TAPPING_TERM + 1); - - // Now we are geting into strange territory, as the hold registers too early here - // But the stranges part is: - // If TAPPING_TERM + 1 above is changed to TAPPING_TERM or TAPPING_TERM + 2 it doesn't - press_key(7, 0); - // Shouldn't be called here really - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).Times(1); - idle_for(TAPPING_TERM); -} diff --git a/tests/basic/test_keypress.cpp b/tests/basic/test_keypress.cpp new file mode 100644 index 000000000..2323b7cb4 --- /dev/null +++ b/tests/basic/test_keypress.cpp @@ -0,0 +1,117 @@ +/* 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" + +using testing::_; +using testing::Return; + +class KeyPress : public TestFixture {}; + +TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { + TestDriver driver; + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + keyboard_task(); +} + +TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) { + TestDriver driver; + press_key(0, 0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); + keyboard_task(); + release_key(0, 0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + keyboard_task(); +} + +TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { + TestDriver driver; + press_key(1, 0); + press_key(0, 3); + //Note that QMK only processes one key at a time + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))); + keyboard_task(); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C))); + keyboard_task(); + release_key(1, 0); + release_key(0, 3); + //Note that the first key released is the first one in the matrix order + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_C))); + keyboard_task(); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + keyboard_task(); +} + +TEST_F(KeyPress, ANonMappedKeyDoesNothing) { + TestDriver driver; + press_key(2, 0); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + keyboard_task(); + keyboard_task(); +} + +TEST_F(KeyPress, LeftShiftIsReportedCorrectly) { + TestDriver driver; + press_key(3, 0); + press_key(0, 0); + // Unfortunately modifiers are also processed in the wrong order + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); + keyboard_task(); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A, KC_LSFT))); + keyboard_task(); + release_key(0, 0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); + keyboard_task(); + release_key(3, 0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + keyboard_task(); +} + +TEST_F(KeyPress, PressLeftShiftAndControl) { + TestDriver driver; + press_key(3, 0); + press_key(5, 0); + // Unfortunately modifiers are also processed in the wrong order + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); + keyboard_task(); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_LCTRL))); + keyboard_task(); +} + +TEST_F(KeyPress, LeftAndRightShiftCanBePressedAtTheSameTime) { + TestDriver driver; + press_key(3, 0); + press_key(4, 0); + // Unfortunately modifiers are also processed in the wrong order + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); + keyboard_task(); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_RSFT))); + keyboard_task(); +} + +TEST_F(KeyPress, RightShiftLeftControlAndCharWithTheSameKey) { + TestDriver driver; + press_key(6, 0); + // BUG: The press is split into two reports + // BUG: It reports RSFT instead of LSFT + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL))); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL, KC_O))); + keyboard_task(); + release_key(6, 0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL))); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + keyboard_task(); +} \ No newline at end of file diff --git a/tests/basic/test_tapping.cpp b/tests/basic/test_tapping.cpp new file mode 100644 index 000000000..c158e1718 --- /dev/null +++ b/tests/basic/test_tapping.cpp @@ -0,0 +1,96 @@ +/* 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 "action_tapping.h" + +using testing::_; +using testing::InSequence; + +class Tapping : public TestFixture {}; + +TEST_F(Tapping, TapA_SHFT_T_KeyReportsKey) { + TestDriver driver; + InSequence s; + + press_key(7, 0); + // Tapping keys does nothing on press + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + run_one_scan_loop(); + release_key(7, 0); + // First we get the key press + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); + // Then the release + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + run_one_scan_loop(); +} + +TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) { + TestDriver driver; + InSequence s; + + press_key(7, 0); + // Tapping keys does nothing on press + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + idle_for(TAPPING_TERM); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); + run_one_scan_loop(); +} + +TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) { + TestDriver driver; + InSequence s; + + press_key(7, 0); + // Tapping keys does nothing on press + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + run_one_scan_loop(); + release_key(7, 0); + // First we get the key press + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); + // Then the release + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + run_one_scan_loop(); + + // This sends KC_P, even if it should do nothing + press_key(7, 0); + // This test should not succed if everything works correctly + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); + run_one_scan_loop(); + release_key(7, 0); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + idle_for(TAPPING_TERM + 1); + + // On the other hand, nothing is sent if we are outside the tapping term + press_key(7, 0); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + run_one_scan_loop(); + release_key(7, 0); + + // First we get the key press + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); + // Then the release + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + idle_for(TAPPING_TERM + 1); + + // Now we are geting into strange territory, as the hold registers too early here + // But the stranges part is: + // If TAPPING_TERM + 1 above is changed to TAPPING_TERM or TAPPING_TERM + 2 it doesn't + press_key(7, 0); + // Shouldn't be called here really + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))).Times(1); + idle_for(TAPPING_TERM); +} -- cgit v1.2.3 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/keymap.c | 13 ++++++- tests/basic/test_macro.cpp | 97 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 tests/basic/test_macro.cpp (limited to 'tests') diff --git a/tests/basic/keymap.c b/tests/basic/keymap.c index 358cbdb59..adacb379c 100644 --- a/tests/basic/keymap.c +++ b/tests/basic/keymap.c @@ -24,9 +24,20 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = { // 0 1 2 3 4 5 6 7 8 9 - {KC_A, KC_B, KC_NO, KC_LSFT, KC_RSFT, KC_LCTL, COMBO1, SFT_T(KC_P), KC_NO, KC_NO}, + {KC_A, KC_B, KC_NO, KC_LSFT, KC_RSFT, KC_LCTL, COMBO1, SFT_T(KC_P), M(0), KC_NO}, {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, {KC_C, KC_D, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, }, }; + +const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { + if (record->event.pressed) { + switch(id) { + case 0: + 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); + } + } + return MACRO_NONE; +}; 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 631c09e97679c27d2f9d8bf3980cc6b2ca6181aa Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 2 Jul 2017 01:29:32 +0300 Subject: Fix keymap formatting --- tests/basic/keymap.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/basic/keymap.c b/tests/basic/keymap.c index adacb379c..3274f213f 100644 --- a/tests/basic/keymap.c +++ b/tests/basic/keymap.c @@ -22,22 +22,22 @@ #define COMBO1 RSFT(LCTL(KC_O)) const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { - [0] = { - // 0 1 2 3 4 5 6 7 8 9 - {KC_A, KC_B, KC_NO, KC_LSFT, KC_RSFT, KC_LCTL, COMBO1, SFT_T(KC_P), M(0), KC_NO}, - {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, - {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, - {KC_C, KC_D, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, - }, + [0] = { + // 0 1 2 3 4 5 6 7 8 9 + {KC_A, KC_B, KC_NO, KC_LSFT, KC_RSFT, KC_LCTL, COMBO1, SFT_T(KC_P), M(0), KC_NO}, + {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, + {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, + {KC_C, KC_D, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, + }, }; const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { if (record->event.pressed) { switch(id) { case 0: - 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); + 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); } } return MACRO_NONE; -}; +}; \ 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_keypress.cpp | 2 +- tests/basic/test_macro.cpp | 2 +- tests/basic/test_tapping.cpp | 2 +- tests/test_common/keyboard_report_util.cpp | 2 +- tests/test_common/keyboard_report_util.h | 39 ------------------------ tests/test_common/keyboard_report_util.hpp | 39 ++++++++++++++++++++++++ tests/test_common/test_common.h | 24 --------------- tests/test_common/test_common.hpp | 24 +++++++++++++++ tests/test_common/test_driver.cpp | 2 +- tests/test_common/test_driver.h | 48 ------------------------------ tests/test_common/test_driver.hpp | 48 ++++++++++++++++++++++++++++++ tests/test_common/test_fixture.cpp | 4 +-- tests/test_common/test_fixture.h | 30 ------------------- tests/test_common/test_fixture.hpp | 30 +++++++++++++++++++ 14 files changed, 148 insertions(+), 148 deletions(-) delete mode 100644 tests/test_common/keyboard_report_util.h create mode 100644 tests/test_common/keyboard_report_util.hpp delete mode 100644 tests/test_common/test_common.h create mode 100644 tests/test_common/test_common.hpp delete mode 100644 tests/test_common/test_driver.h create mode 100644 tests/test_common/test_driver.hpp delete mode 100644 tests/test_common/test_fixture.h create mode 100644 tests/test_common/test_fixture.hpp (limited to 'tests') diff --git a/tests/basic/test_keypress.cpp b/tests/basic/test_keypress.cpp index 2323b7cb4..460c38385 100644 --- a/tests/basic/test_keypress.cpp +++ b/tests/basic/test_keypress.cpp @@ -14,7 +14,7 @@ * along with this program. If not, see . */ -#include "test_common.h" +#include "test_common.hpp" using testing::_; using testing::Return; 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; diff --git a/tests/basic/test_tapping.cpp b/tests/basic/test_tapping.cpp index c158e1718..75a1bcafb 100644 --- a/tests/basic/test_tapping.cpp +++ b/tests/basic/test_tapping.cpp @@ -14,7 +14,7 @@ * along with this program. If not, see . */ -#include "test_common.h" +#include "test_common.hpp" #include "action_tapping.h" using testing::_; diff --git a/tests/test_common/keyboard_report_util.cpp b/tests/test_common/keyboard_report_util.cpp index aa096e416..bf728b9a2 100644 --- a/tests/test_common/keyboard_report_util.cpp +++ b/tests/test_common/keyboard_report_util.cpp @@ -14,7 +14,7 @@ * along with this program. If not, see . */ - #include "keyboard_report_util.h" + #include "keyboard_report_util.hpp" #include #include using namespace testing; diff --git a/tests/test_common/keyboard_report_util.h b/tests/test_common/keyboard_report_util.h deleted file mode 100644 index 48543c205..000000000 --- a/tests/test_common/keyboard_report_util.h +++ /dev/null @@ -1,39 +0,0 @@ -/* 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 . - */ - -#pragma once -#include "report.h" -#include -#include "gmock/gmock.h" - -bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs); -std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value); - -class KeyboardReportMatcher : public testing::MatcherInterface { - public: - KeyboardReportMatcher(const std::vector& keys); - virtual bool MatchAndExplain(report_keyboard_t& report, testing::MatchResultListener* listener) const override; - virtual void DescribeTo(::std::ostream* os) const override; - virtual void DescribeNegationTo(::std::ostream* os) const override; -private: - report_keyboard_t m_report; -}; - - -template -inline testing::Matcher KeyboardReport(Ts... keys) { - return testing::MakeMatcher(new KeyboardReportMatcher(std::vector({keys...}))); -} \ No newline at end of file diff --git a/tests/test_common/keyboard_report_util.hpp b/tests/test_common/keyboard_report_util.hpp new file mode 100644 index 000000000..48543c205 --- /dev/null +++ b/tests/test_common/keyboard_report_util.hpp @@ -0,0 +1,39 @@ +/* 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 . + */ + +#pragma once +#include "report.h" +#include +#include "gmock/gmock.h" + +bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs); +std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value); + +class KeyboardReportMatcher : public testing::MatcherInterface { + public: + KeyboardReportMatcher(const std::vector& keys); + virtual bool MatchAndExplain(report_keyboard_t& report, testing::MatchResultListener* listener) const override; + virtual void DescribeTo(::std::ostream* os) const override; + virtual void DescribeNegationTo(::std::ostream* os) const override; +private: + report_keyboard_t m_report; +}; + + +template +inline testing::Matcher KeyboardReport(Ts... keys) { + return testing::MakeMatcher(new KeyboardReportMatcher(std::vector({keys...}))); +} \ No newline at end of file diff --git a/tests/test_common/test_common.h b/tests/test_common/test_common.h deleted file mode 100644 index 38eb0ed93..000000000 --- a/tests/test_common/test_common.h +++ /dev/null @@ -1,24 +0,0 @@ -/* 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 "gtest/gtest.h" -#include "gmock/gmock.h" - -#include "quantum.h" -#include "test_driver.h" -#include "test_matrix.h" -#include "keyboard_report_util.h" -#include "test_fixture.h" \ No newline at end of file diff --git a/tests/test_common/test_common.hpp b/tests/test_common/test_common.hpp new file mode 100644 index 000000000..239844633 --- /dev/null +++ b/tests/test_common/test_common.hpp @@ -0,0 +1,24 @@ +/* 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 "gtest/gtest.h" +#include "gmock/gmock.h" + +#include "quantum.h" +#include "test_driver.hpp" +#include "test_matrix.h" +#include "keyboard_report_util.hpp" +#include "test_fixture.hpp" \ No newline at end of file diff --git a/tests/test_common/test_driver.cpp b/tests/test_common/test_driver.cpp index feb80563a..511309969 100644 --- a/tests/test_common/test_driver.cpp +++ b/tests/test_common/test_driver.cpp @@ -14,7 +14,7 @@ * along with this program. If not, see . */ -#include "test_driver.h" +#include "test_driver.hpp" TestDriver* TestDriver::m_this = nullptr; diff --git a/tests/test_common/test_driver.h b/tests/test_common/test_driver.h deleted file mode 100644 index 0123fd539..000000000 --- a/tests/test_common/test_driver.h +++ /dev/null @@ -1,48 +0,0 @@ -/* 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 . - */ - -#ifndef TESTS_TEST_COMMON_TEST_DRIVER_H_ -#define TESTS_TEST_COMMON_TEST_DRIVER_H_ - -#include "gmock/gmock.h" -#include -#include "host.h" -#include "keyboard_report_util.h" - - -class TestDriver { -public: - TestDriver(); - ~TestDriver(); - void set_leds(uint8_t leds) { m_leds = leds; } - - MOCK_METHOD1(send_keyboard_mock, void (report_keyboard_t&)); - MOCK_METHOD1(send_mouse_mock, void (report_mouse_t&)); - MOCK_METHOD1(send_system_mock, void (uint16_t)); - MOCK_METHOD1(send_consumer_mock, void (uint16_t)); -private: - static uint8_t keyboard_leds(void); - static void send_keyboard(report_keyboard_t *report); - static void send_mouse(report_mouse_t* report); - static void send_system(uint16_t data); - static void send_consumer(uint16_t data); - host_driver_t m_driver; - uint8_t m_leds = 0; - static TestDriver* m_this; -}; - - -#endif /* TESTS_TEST_COMMON_TEST_DRIVER_H_ */ diff --git a/tests/test_common/test_driver.hpp b/tests/test_common/test_driver.hpp new file mode 100644 index 000000000..c3ae17b1a --- /dev/null +++ b/tests/test_common/test_driver.hpp @@ -0,0 +1,48 @@ +/* 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 . + */ + +#ifndef TESTS_TEST_COMMON_TEST_DRIVER_H_ +#define TESTS_TEST_COMMON_TEST_DRIVER_H_ + +#include "gmock/gmock.h" +#include +#include "host.h" +#include "keyboard_report_util.hpp" + + +class TestDriver { +public: + TestDriver(); + ~TestDriver(); + void set_leds(uint8_t leds) { m_leds = leds; } + + MOCK_METHOD1(send_keyboard_mock, void (report_keyboard_t&)); + MOCK_METHOD1(send_mouse_mock, void (report_mouse_t&)); + MOCK_METHOD1(send_system_mock, void (uint16_t)); + MOCK_METHOD1(send_consumer_mock, void (uint16_t)); +private: + static uint8_t keyboard_leds(void); + static void send_keyboard(report_keyboard_t *report); + static void send_mouse(report_mouse_t* report); + static void send_system(uint16_t data); + static void send_consumer(uint16_t data); + host_driver_t m_driver; + uint8_t m_leds = 0; + static TestDriver* m_this; +}; + + +#endif /* TESTS_TEST_COMMON_TEST_DRIVER_H_ */ diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp index 5ca5247db..df57338df 100644 --- a/tests/test_common/test_fixture.cpp +++ b/tests/test_common/test_fixture.cpp @@ -1,6 +1,6 @@ -#include "test_fixture.h" +#include "test_fixture.hpp" #include "gmock/gmock.h" -#include "test_driver.h" +#include "test_driver.hpp" #include "test_matrix.h" #include "keyboard.h" #include "action.h" diff --git a/tests/test_common/test_fixture.h b/tests/test_common/test_fixture.h deleted file mode 100644 index 4146b682b..000000000 --- a/tests/test_common/test_fixture.h +++ /dev/null @@ -1,30 +0,0 @@ -/* 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 . - */ - - #pragma once - -#include "gtest/gtest.h" - -class TestFixture : public testing::Test { -public: - TestFixture(); - ~TestFixture(); - static void SetUpTestCase(); - static void TearDownTestCase(); - - void run_one_scan_loop(); - void idle_for(uint ms); -}; \ No newline at end of file diff --git a/tests/test_common/test_fixture.hpp b/tests/test_common/test_fixture.hpp new file mode 100644 index 000000000..4146b682b --- /dev/null +++ b/tests/test_common/test_fixture.hpp @@ -0,0 +1,30 @@ +/* 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 . + */ + + #pragma once + +#include "gtest/gtest.h" + +class TestFixture : public testing::Test { +public: + TestFixture(); + ~TestFixture(); + static void SetUpTestCase(); + static void TearDownTestCase(); + + void run_one_scan_loop(); + void idle_for(uint ms); +}; \ No newline at end of file -- cgit v1.2.3 From 60b1880a6248b8d94da0d8d0db638af130557416 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 8 Jul 2017 19:23:39 +0300 Subject: Reference issue #1476 from the unit tests --- tests/basic/test_keypress.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/basic/test_keypress.cpp b/tests/basic/test_keypress.cpp index 460c38385..d85cba446 100644 --- a/tests/basic/test_keypress.cpp +++ b/tests/basic/test_keypress.cpp @@ -42,6 +42,7 @@ TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { press_key(1, 0); press_key(0, 3); //Note that QMK only processes one key at a time + //See issue #1476 for more information EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))); keyboard_task(); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C))); @@ -68,6 +69,7 @@ TEST_F(KeyPress, LeftShiftIsReportedCorrectly) { press_key(3, 0); press_key(0, 0); // Unfortunately modifiers are also processed in the wrong order + // See issue #1476 for more information EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); keyboard_task(); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A, KC_LSFT))); @@ -85,6 +87,7 @@ TEST_F(KeyPress, PressLeftShiftAndControl) { press_key(3, 0); press_key(5, 0); // Unfortunately modifiers are also processed in the wrong order + // See issue #1476 for more information EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); keyboard_task(); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_LCTRL))); @@ -96,6 +99,7 @@ TEST_F(KeyPress, LeftAndRightShiftCanBePressedAtTheSameTime) { press_key(3, 0); press_key(4, 0); // Unfortunately modifiers are also processed in the wrong order + // See issue #1476 for more information EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); keyboard_task(); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_RSFT))); -- cgit v1.2.3 From 41efcd6d73ca08774e680daa39c42b0437133387 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 8 Jul 2017 19:26:47 +0300 Subject: Reference issue #524 from the unit tests --- tests/basic/test_keypress.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/basic/test_keypress.cpp b/tests/basic/test_keypress.cpp index d85cba446..194b1745b 100644 --- a/tests/basic/test_keypress.cpp +++ b/tests/basic/test_keypress.cpp @@ -111,6 +111,9 @@ TEST_F(KeyPress, RightShiftLeftControlAndCharWithTheSameKey) { press_key(6, 0); // BUG: The press is split into two reports // BUG: It reports RSFT instead of LSFT + // See issue #524 for more information + // The underlying cause is that we use only one bit to represent the right hand + // modifiers. EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL))); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL, KC_O))); keyboard_task(); -- 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') 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 From 9158673166aa270eb80892acb8bbcb51cf72f9b6 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sat, 8 Jul 2017 19:48:22 +0300 Subject: Reference issue #1478 from the unit tests --- tests/basic/test_tapping.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/basic/test_tapping.cpp b/tests/basic/test_tapping.cpp index 75a1bcafb..30d032e9f 100644 --- a/tests/basic/test_tapping.cpp +++ b/tests/basic/test_tapping.cpp @@ -51,6 +51,7 @@ TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) { } TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) { + // See issue #1478 for more information TestDriver driver; InSequence s; -- cgit v1.2.3 From 78545b95090816767bf3e17c4745bb0c3db01a5f Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Tue, 11 Jul 2017 19:41:04 +0300 Subject: Fix unreferenced errors with mingw compiler and unit tests --- tests/basic/keymap.c | 5 ++++- tests/test_common/matrix.c | 3 +++ tests/test_common/test_fixture.cpp | 4 ++-- tests/test_common/test_fixture.hpp | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/basic/keymap.c b/tests/basic/keymap.c index 3274f213f..3f97c0a0e 100644 --- a/tests/basic/keymap.c +++ b/tests/basic/keymap.c @@ -40,4 +40,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { } } return MACRO_NONE; -}; \ No newline at end of file +}; + +void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) { +} \ No newline at end of file diff --git a/tests/test_common/matrix.c b/tests/test_common/matrix.c index 0d9fa68b0..4b501039b 100644 --- a/tests/test_common/matrix.c +++ b/tests/test_common/matrix.c @@ -58,3 +58,6 @@ void release_key(uint8_t col, uint8_t row) { void clear_all_keys(void) { memset(matrix, 0, sizeof(matrix)); } + +void led_set(uint8_t usb_led) { +} diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp index df57338df..4084ee9c6 100644 --- a/tests/test_common/test_fixture.cpp +++ b/tests/test_common/test_fixture.cpp @@ -44,8 +44,8 @@ void TestFixture::run_one_scan_loop() { advance_time(1); } -void TestFixture::idle_for(uint time) { - for (uint i=0; i