From 8b865a9d6445e3bce6c991224f373d71c67e87e5 Mon Sep 17 00:00:00 2001 From: Stefan Kerkmann Date: Tue, 14 Dec 2021 19:40:18 +0100 Subject: [Core] Don't send keyboard reports that propagate no changes to the host (#14065) --- tests/auto_shift/test_auto_shift.cpp | 3 -- tests/basic/test_action_layer.cpp | 33 +++++-------- tests/basic/test_keypress.cpp | 55 ++++++++++------------ tests/basic/test_one_shot_keys.cpp | 8 ++-- .../permissive_hold/test_tap_hold.cpp | 3 +- .../test_tap_hold.cpp | 3 +- .../tapping_force_hold/test_action_layer.cpp | 3 +- .../tapping_force_hold/test_tap_hold.cpp | 2 - tests/test_common/test_fixture.cpp | 3 -- 9 files changed, 43 insertions(+), 70 deletions(-) (limited to 'tests') diff --git a/tests/auto_shift/test_auto_shift.cpp b/tests/auto_shift/test_auto_shift.cpp index 9c5ed9a832..a19b5dfa82 100644 --- a/tests/auto_shift/test_auto_shift.cpp +++ b/tests/auto_shift/test_auto_shift.cpp @@ -42,7 +42,6 @@ TEST_F(AutoShift, key_release_before_timeout) { /* Release regular key */ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); regular_key.release(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); @@ -65,8 +64,6 @@ TEST_F(AutoShift, key_release_after_timeout) { EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_A))); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); regular_key.release(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); diff --git a/tests/basic/test_action_layer.cpp b/tests/basic/test_action_layer.cpp index 1b12d13642..fe5c729f7c 100644 --- a/tests/basic/test_action_layer.cpp +++ b/tests/basic/test_action_layer.cpp @@ -131,14 +131,12 @@ TEST_F(ActionLayer, MomentaryLayerDoesNothing) { set_keymap({layer_key}); /* Press and release MO, nothing should happen. */ - /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); layer_key.press(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); - /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); layer_key.release(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); @@ -153,8 +151,7 @@ TEST_F(ActionLayer, MomentaryLayerWithKeypress) { set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}}); /* Press MO. */ - /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); layer_key.press(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); @@ -175,8 +172,7 @@ TEST_F(ActionLayer, MomentaryLayerWithKeypress) { testing::Mock::VerifyAndClearExpectations(&driver); /* Release MO */ - /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); layer_key.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(0)); @@ -199,8 +195,7 @@ TEST_F(ActionLayer, ToggleLayerDoesNothing) { testing::Mock::VerifyAndClearExpectations(&driver); /* Release TG. */ - /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); layer_key.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); @@ -223,8 +218,7 @@ TEST_F(ActionLayer, ToggleLayerUpAndDown) { EXPECT_TRUE(layer_state_is(1)); testing::Mock::VerifyAndClearExpectations(&driver); - /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); toggle_layer_1_on_layer_0.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); @@ -237,8 +231,7 @@ TEST_F(ActionLayer, ToggleLayerUpAndDown) { EXPECT_TRUE(layer_state_is(0)); testing::Mock::VerifyAndClearExpectations(&driver); - /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); toggle_layer_0_on_layer_1.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(0)); @@ -254,14 +247,13 @@ TEST_F(ActionLayer, LayerTapToggleDoesNothing) { set_keymap({layer_key}); /* Press and release TT. */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(0); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); layer_key.press(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); testing::Mock::VerifyAndClearExpectations(&driver); - /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(2); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); layer_key.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(0)); @@ -279,7 +271,6 @@ TEST_F(ActionLayer, LayerTapToggleWithKeypress) { set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}}); /* Press TT. */ - /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(0); layer_key.press(); run_one_scan_loop(); @@ -298,8 +289,7 @@ TEST_F(ActionLayer, LayerTapToggleWithKeypress) { EXPECT_TRUE(layer_state_is(1)); testing::Mock::VerifyAndClearExpectations(&driver); - /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); layer_key.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(0)); @@ -317,8 +307,7 @@ TEST_F(ActionLayer, LayerTapToggleWithToggleWithKeypress) { set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}}); /* Tap TT five times . */ - /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(9); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); layer_key.press(); run_one_scan_loop(); diff --git a/tests/basic/test_keypress.cpp b/tests/basic/test_keypress.cpp index 1c175c9d56..044fc29378 100644 --- a/tests/basic/test_keypress.cpp +++ b/tests/basic/test_keypress.cpp @@ -85,7 +85,7 @@ TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { TEST_F(KeyPress, LeftShiftIsReportedCorrectly) { TestDriver driver; auto key_a = KeymapKey(0, 0, 0, KC_A); - auto key_lsft = KeymapKey(0, 3, 0, KC_LSFT); + auto key_lsft = KeymapKey(0, 3, 0, KC_LEFT_SHIFT); set_keymap({key_a, key_lsft}); @@ -110,8 +110,8 @@ TEST_F(KeyPress, LeftShiftIsReportedCorrectly) { TEST_F(KeyPress, PressLeftShiftAndControl) { TestDriver driver; - auto key_lsft = KeymapKey(0, 3, 0, KC_LSFT); - auto key_lctrl = KeymapKey(0, 5, 0, KC_LCTRL); + auto key_lsft = KeymapKey(0, 3, 0, KC_LEFT_SHIFT); + auto key_lctrl = KeymapKey(0, 5, 0, KC_LEFT_CTRL); set_keymap({key_lctrl, key_lsft}); @@ -138,8 +138,8 @@ TEST_F(KeyPress, PressLeftShiftAndControl) { TEST_F(KeyPress, LeftAndRightShiftCanBePressedAtTheSameTime) { TestDriver driver; - auto key_lsft = KeymapKey(0, 3, 0, KC_LSFT); - auto key_rsft = KeymapKey(0, 4, 0, KC_RSFT); + auto key_lsft = KeymapKey(0, 3, 0, KC_LEFT_SHIFT); + auto key_rsft = KeymapKey(0, 4, 0, KC_RIGHT_SHIFT); set_keymap({key_rsft, key_lsft}); @@ -175,12 +175,12 @@ TEST_F(KeyPress, RightShiftLeftControlAndCharWithTheSameKey) { // The underlying cause is that we use only one bit to represent the right hand // modifiers. combo_key.press(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL))); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL, KC_O))); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RIGHT_SHIFT, KC_RIGHT_CTRL))); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RIGHT_SHIFT, KC_RIGHT_CTRL, KC_O))); keyboard_task(); combo_key.release(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL))); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RIGHT_SHIFT, KC_RIGHT_CTRL))); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); keyboard_task(); } @@ -189,18 +189,18 @@ TEST_F(KeyPress, PressPlusEqualReleaseBeforePress) { TestDriver driver; InSequence s; auto key_plus = KeymapKey(0, 1, 1, KC_PLUS); - auto key_eql = KeymapKey(0, 0, 1, KC_EQL); + auto key_eql = KeymapKey(0, 0, 1, KC_EQUAL); set_keymap({key_plus, key_eql}); key_plus.press(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL))); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_EQUAL))); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); key_plus.release(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); @@ -220,13 +220,13 @@ TEST_F(KeyPress, PressPlusEqualDontReleaseBeforePress) { TestDriver driver; InSequence s; auto key_plus = KeymapKey(0, 1, 1, KC_PLUS); - auto key_eql = KeymapKey(0, 0, 1, KC_EQL); + auto key_eql = KeymapKey(0, 0, 1, KC_EQUAL); set_keymap({key_plus, key_eql}); key_plus.press(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL))); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_EQUAL))); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); @@ -237,14 +237,13 @@ TEST_F(KeyPress, PressPlusEqualDontReleaseBeforePress) { testing::Mock::VerifyAndClearExpectations(&driver); key_plus.release(); - // BUG: Should really still return KC_EQL, but this is fine too - // It's also called twice for some reason - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(2); + // BUG: Should really still return KC_EQUAL, but this is fine too + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); key_eql.release(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); } @@ -253,12 +252,12 @@ TEST_F(KeyPress, PressEqualPlusReleaseBeforePress) { TestDriver driver; InSequence s; auto key_plus = KeymapKey(0, 1, 1, KC_PLUS); - auto key_eql = KeymapKey(0, 0, 1, KC_EQL); + auto key_eql = KeymapKey(0, 0, 1, KC_EQUAL); set_keymap({key_plus, key_eql}); key_eql.press(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQL))); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQUAL))); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); @@ -268,13 +267,13 @@ TEST_F(KeyPress, PressEqualPlusReleaseBeforePress) { testing::Mock::VerifyAndClearExpectations(&driver); key_plus.press(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL))); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_EQUAL))); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); key_plus.release(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); @@ -284,12 +283,12 @@ TEST_F(KeyPress, PressEqualPlusDontReleaseBeforePress) { TestDriver driver; InSequence s; auto key_plus = KeymapKey(0, 1, 1, KC_PLUS); - auto key_eql = KeymapKey(0, 0, 1, KC_EQL); + auto key_eql = KeymapKey(0, 0, 1, KC_EQUAL); set_keymap({key_plus, key_eql}); key_eql.press(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQL))); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQUAL))); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); @@ -309,9 +308,7 @@ TEST_F(KeyPress, PressEqualPlusDontReleaseBeforePress) { testing::Mock::VerifyAndClearExpectations(&driver); key_plus.release(); - // This report is not needed - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); -} \ No newline at end of file +} diff --git a/tests/basic/test_one_shot_keys.cpp b/tests/basic/test_one_shot_keys.cpp index 98178912e4..43fc3e1ba3 100644 --- a/tests/basic/test_one_shot_keys.cpp +++ b/tests/basic/test_one_shot_keys.cpp @@ -175,22 +175,20 @@ TEST_F(OneShot, OSLWithAdditionalKeypress) { testing::Mock::VerifyAndClearExpectations(&driver); /* Release OSL key */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(2); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); osl_key.release(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); /* Press regular key */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(regular_key.report_code))).Times(2); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(regular_key.report_code))).Times(1); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); regular_key.press(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); /* Release regular key */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); regular_key.release(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); diff --git a/tests/tap_hold_configurations/permissive_hold/test_tap_hold.cpp b/tests/tap_hold_configurations/permissive_hold/test_tap_hold.cpp index ab9dd1518b..00c2b33cb7 100644 --- a/tests/tap_hold_configurations/permissive_hold/test_tap_hold.cpp +++ b/tests/tap_hold_configurations/permissive_hold/test_tap_hold.cpp @@ -117,7 +117,6 @@ TEST_F(PermissiveHold, tap_regular_key_while_layer_tap_key_is_held) { testing::Mock::VerifyAndClearExpectations(&driver); /* Release regular key */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(layer_key.report_code))); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); regular_key.release(); @@ -125,7 +124,7 @@ TEST_F(PermissiveHold, tap_regular_key_while_layer_tap_key_is_held) { testing::Mock::VerifyAndClearExpectations(&driver); /* Release layer-tap-hold key */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); layer_tap_hold_key.release(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); diff --git a/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/test_tap_hold.cpp b/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/test_tap_hold.cpp index 67f394653f..67706f80dc 100644 --- a/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/test_tap_hold.cpp +++ b/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/test_tap_hold.cpp @@ -119,7 +119,6 @@ TEST_F(PermissiveHold_IgnoreModTapInterrupt, tap_regular_key_while_layer_tap_key testing::Mock::VerifyAndClearExpectations(&driver); /* Release regular key */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); regular_key.release(); @@ -127,7 +126,7 @@ TEST_F(PermissiveHold_IgnoreModTapInterrupt, tap_regular_key_while_layer_tap_key testing::Mock::VerifyAndClearExpectations(&driver); /* Release layer-tap-hold key */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); layer_tap_hold_key.release(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); diff --git a/tests/tap_hold_configurations/tapping_force_hold/test_action_layer.cpp b/tests/tap_hold_configurations/tapping_force_hold/test_action_layer.cpp index 02416eed73..54e7daa22c 100644 --- a/tests/tap_hold_configurations/tapping_force_hold/test_action_layer.cpp +++ b/tests/tap_hold_configurations/tapping_force_hold/test_action_layer.cpp @@ -31,9 +31,8 @@ TEST_F(ActionLayer, LayerTapToggleWithToggleWithKeypress) { set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}}); /* Tap TT five times . */ - /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ /* TODO: Tapping Force Hold breaks TT */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(10); + EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); layer_key.press(); run_one_scan_loop(); diff --git a/tests/tap_hold_configurations/tapping_force_hold/test_tap_hold.cpp b/tests/tap_hold_configurations/tapping_force_hold/test_tap_hold.cpp index cb68429617..3ae7c4ccfd 100644 --- a/tests/tap_hold_configurations/tapping_force_hold/test_tap_hold.cpp +++ b/tests/tap_hold_configurations/tapping_force_hold/test_tap_hold.cpp @@ -60,7 +60,6 @@ TEST_F(TappingForceHold, tap_regular_key_while_mod_tap_key_is_held) { testing::Mock::VerifyAndClearExpectations(&driver); /* Idle for tapping term of mod tap hold key. */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_A))); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); @@ -101,7 +100,6 @@ TEST_F(TappingForceHold, tap_mod_tap_key_while_mod_tap_key_is_held) { testing::Mock::VerifyAndClearExpectations(&driver); /* Idle for tapping term of first mod tap hold key. */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_A))); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp index 0601b17191..91bf3e779e 100644 --- a/tests/test_common/test_fixture.cpp +++ b/tests/test_common/test_fixture.cpp @@ -48,7 +48,6 @@ void TestFixture::SetUpTestCase() { eeconfig_update_debug(debug_config.raw); TestDriver driver; - EXPECT_CALL(driver, send_keyboard_mock(_)); keyboard_init(); test_logger.info() << "TestFixture setup-up end." << std::endl; @@ -62,8 +61,6 @@ TestFixture::~TestFixture() { test_logger.info() << "TestFixture clean-up start." << std::endl; TestDriver driver; - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(2); - /* Reset keyboard state. */ clear_all_keys(); -- cgit v1.2.3 From 1d11ae3087f583c4f4756169802b33adea71ed94 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 25 Jan 2022 08:22:20 +1100 Subject: Rip out old macro and action_function system (#16025) * Rip out old macro and action_function system * Update quantum/action_util.c Co-authored-by: Joel Challis --- tests/basic/test_macro.cpp | 88 ---------------------------------------------- 1 file changed, 88 deletions(-) delete mode 100644 tests/basic/test_macro.cpp (limited to 'tests') diff --git a/tests/basic/test_macro.cpp b/tests/basic/test_macro.cpp deleted file mode 100644 index ae2f3b32e3..0000000000 --- a/tests/basic/test_macro.cpp +++ /dev/null @@ -1,88 +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.hpp" -#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); })) - -extern "C" 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; -}; - -TEST_F(Macro, PlayASimpleMacro) { - TestDriver driver; - InSequence s; - auto key_macro = KeymapKey(0, 8, 0, M(0)); - - set_keymap({key_macro}); - - key_macro.press(); - - uint32_t current_time = timer_read32(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).AT_TIME(0); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_H))).AT_TIME(0); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).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_LEFT_SHIFT))).AT_TIME(100); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_W))).AT_TIME(100); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).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 - // 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); - 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_LEFT_SHIFT))).AT_TIME(190); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_1))).AT_TIME(200); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).AT_TIME(210); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(220); - run_one_scan_loop(); - - key_macro.release(); -} -- cgit v1.2.3 From 63646e8906e062d1c1de3925cba70c4e3426a855 Mon Sep 17 00:00:00 2001 From: QMK Bot Date: Sat, 12 Feb 2022 10:29:31 -0800 Subject: Format code according to conventions (#16322) --- tests/test_common/keyboard_report_util.cpp | 14 ++++++++++---- tests/test_common/matrix.c | 16 ++++++++++++---- tests/test_common/test_driver.cpp | 20 +++++++++++++++----- tests/test_common/test_fixture.cpp | 4 +++- tests/test_common/test_logger.cpp | 8 ++++++-- 5 files changed, 46 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/tests/test_common/keyboard_report_util.cpp b/tests/test_common/keyboard_report_util.cpp index e148c76beb..7908e64f7f 100644 --- a/tests/test_common/keyboard_report_util.cpp +++ b/tests/test_common/keyboard_report_util.cpp @@ -36,7 +36,7 @@ std::vector get_keys(const report_keyboard_t& report) { std::sort(result.begin(), result.end()); return result; } -} // namespace +} // namespace bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) { auto lhskeys = get_keys(lhs); @@ -72,8 +72,14 @@ KeyboardReportMatcher::KeyboardReportMatcher(const std::vector& keys) { } } -bool KeyboardReportMatcher::MatchAndExplain(report_keyboard_t& report, MatchResultListener* listener) const { return m_report == report; } +bool KeyboardReportMatcher::MatchAndExplain(report_keyboard_t& report, MatchResultListener* listener) const { + return m_report == report; +} -void KeyboardReportMatcher::DescribeTo(::std::ostream* os) const { *os << "is equal to " << m_report; } +void KeyboardReportMatcher::DescribeTo(::std::ostream* os) const { + *os << "is equal to " << m_report; +} -void KeyboardReportMatcher::DescribeNegationTo(::std::ostream* os) const { *os << "is not equal to " << m_report; } +void KeyboardReportMatcher::DescribeNegationTo(::std::ostream* os) const { + *os << "is not equal to " << m_report; +} diff --git a/tests/test_common/matrix.c b/tests/test_common/matrix.c index 9a92a801c7..7b24d560e3 100644 --- a/tests/test_common/matrix.c +++ b/tests/test_common/matrix.c @@ -30,7 +30,9 @@ uint8_t matrix_scan(void) { return 1; } -matrix_row_t matrix_get_row(uint8_t row) { return matrix[row]; } +matrix_row_t matrix_get_row(uint8_t row) { + return matrix[row]; +} void matrix_print(void) {} @@ -38,10 +40,16 @@ void matrix_init_kb(void) {} void matrix_scan_kb(void) {} -void press_key(uint8_t col, uint8_t row) { matrix[row] |= 1 << col; } +void press_key(uint8_t col, uint8_t row) { + matrix[row] |= 1 << col; +} -void release_key(uint8_t col, uint8_t row) { matrix[row] &= ~(1 << col); } +void release_key(uint8_t col, uint8_t row) { + matrix[row] &= ~(1 << col); +} -void clear_all_keys(void) { memset(matrix, 0, sizeof(matrix)); } +void clear_all_keys(void) { + memset(matrix, 0, sizeof(matrix)); +} void led_set(uint8_t usb_led) {} diff --git a/tests/test_common/test_driver.cpp b/tests/test_common/test_driver.cpp index 2fa2b6a2e7..68f1dfd17d 100644 --- a/tests/test_common/test_driver.cpp +++ b/tests/test_common/test_driver.cpp @@ -23,17 +23,27 @@ TestDriver::TestDriver() : m_driver{&TestDriver::keyboard_leds, &TestDriver::sen m_this = this; } -TestDriver::~TestDriver() { m_this = nullptr; } +TestDriver::~TestDriver() { + m_this = nullptr; +} -uint8_t TestDriver::keyboard_leds(void) { return m_this->m_leds; } +uint8_t TestDriver::keyboard_leds(void) { + return m_this->m_leds; +} void TestDriver::send_keyboard(report_keyboard_t* report) { test_logger.trace() << *report; m_this->send_keyboard_mock(*report); } -void TestDriver::send_mouse(report_mouse_t* report) { m_this->send_mouse_mock(*report); } +void TestDriver::send_mouse(report_mouse_t* report) { + m_this->send_mouse_mock(*report); +} -void TestDriver::send_system(uint16_t data) { m_this->send_system_mock(data); } +void TestDriver::send_system(uint16_t data) { + m_this->send_system_mock(data); +} -void TestDriver::send_consumer(uint16_t data) { m_this->send_consumer(data); } +void TestDriver::send_consumer(uint16_t data) { + m_this->send_consumer(data); +} diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp index 91bf3e779e..c98a679554 100644 --- a/tests/test_common/test_fixture.cpp +++ b/tests/test_common/test_fixture.cpp @@ -55,7 +55,9 @@ void TestFixture::SetUpTestCase() { void TestFixture::TearDownTestCase() {} -TestFixture::TestFixture() { m_this = this; } +TestFixture::TestFixture() { + m_this = this; +} TestFixture::~TestFixture() { test_logger.info() << "TestFixture clean-up start." << std::endl; diff --git a/tests/test_common/test_logger.cpp b/tests/test_common/test_logger.cpp index 959fdde5ec..efc7719d13 100644 --- a/tests/test_common/test_logger.cpp +++ b/tests/test_common/test_logger.cpp @@ -34,6 +34,10 @@ TestLogger& TestLogger::error() { return *this; } -void TestLogger::reset() { this->m_log.str(""); }; +void TestLogger::reset() { + this->m_log.str(""); +}; -void TestLogger::print_log() { std::cerr << this->m_log.str(); } +void TestLogger::print_log() { + std::cerr << this->m_log.str(); +} -- cgit v1.2.3