From 95d20e6d8bb1ffaf3024af793daf789ee0b75727 Mon Sep 17 00:00:00 2001 From: Pascal Getreuer <50221757+getreuer@users.noreply.github.com> Date: Sun, 5 Jun 2022 00:14:02 -0700 Subject: Fix and add unit tests for Caps Word to work with Unicode Map, Auto Shift, Retro Shift. (#17284) * Fix Caps Word and Unicode Map * Tests for Caps Word + Auto Shift and Unicode Map. * Fix formatting * Add additional keyboard report expectation macros This commit defines five test utilities, EXPECT_REPORT, EXPECT_UNICODE, EXPECT_EMPTY_REPORT, EXPECT_ANY_REPORT and EXPECT_NO_REPORT for use with TestDriver. EXPECT_REPORT sets a gmock expectation that a given keyboard report will be sent. For instance, EXPECT_REPORT(driver, (KC_LSFT, KC_A)); is shorthand for EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_A))); EXPECT_UNICODE sets a gmock expectation that a given Unicode code point will be sent using UC_LNX input mode. For instance for U+2013, EXPECT_UNICODE(driver, 0x2013); expects the sequence of keys: "Ctrl+Shift+U, 2, 0, 1, 3, space". EXPECT_EMPTY_REPORT sets a gmock expectation that a given keyboard report will be sent. For instance EXPECT_EMPTY_REPORT(driver); expects a single report without keypresses or modifiers. EXPECT_ANY_REPORT sets a gmock expectation that a arbitrary keyboard report will be sent, without matching its contents. For instance EXPECT_ANY_REPORT(driver).Times(1); expects a single arbitrary keyboard report will be sent. EXPECT_NO_REPORT sets a gmock expectation that no keyboard report will be sent at all. * Add tap_key() and tap_keys() to TestFixture. This commit adds a `tap_key(key)` method to TestFixture that taps a given KeymapKey, optionally with a specified delay between press and release. Similarly, the method `tap_keys(key_a, key_b, key_c)` taps a sequence of KeymapKeys. * Use EXPECT_REPORT, tap_keys, etc. in most tests. This commit uses EXPECT_REPORT, EXPECT_UNICODE, EXPECT_EMPTY_REPORT, EXPECT_NO_REPORT, tap_key() and tap_keys() test utilities from the previous two commits in most tests. Particularly the EXPECT_REPORT macro is frequently useful and makes a nice reduction in boilerplate needed to express many tests. Co-authored-by: David Kosorin --- tests/basic/test_action_layer.cpp | 54 ++++++++++----------- tests/basic/test_keypress.cpp | 96 +++++++++++++++++++------------------- tests/basic/test_one_shot_keys.cpp | 36 +++++++------- tests/basic/test_tapping.cpp | 34 +++++++------- 4 files changed, 110 insertions(+), 110 deletions(-) (limited to 'tests/basic') diff --git a/tests/basic/test_action_layer.cpp b/tests/basic/test_action_layer.cpp index fe5c729f7c..fa339a3375 100644 --- a/tests/basic/test_action_layer.cpp +++ b/tests/basic/test_action_layer.cpp @@ -131,12 +131,12 @@ TEST_F(ActionLayer, MomentaryLayerDoesNothing) { set_keymap({layer_key}); /* Press and release MO, nothing should happen. */ - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); layer_key.press(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); layer_key.release(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); @@ -151,28 +151,28 @@ TEST_F(ActionLayer, MomentaryLayerWithKeypress) { set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}}); /* Press MO. */ - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); layer_key.press(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); testing::Mock::VerifyAndClearExpectations(&driver); /* Press key on layer 1 */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))).Times(1); + EXPECT_REPORT(driver, (KC_B)).Times(1); regular_key.press(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); testing::Mock::VerifyAndClearExpectations(&driver); /* Release key on layer 1 */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); + EXPECT_EMPTY_REPORT(driver); regular_key.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); testing::Mock::VerifyAndClearExpectations(&driver); /* Release MO */ - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); layer_key.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(0)); @@ -188,14 +188,14 @@ TEST_F(ActionLayer, ToggleLayerDoesNothing) { set_keymap({layer_key}); /* Press TG. Layer state should not change as it's applied on release. */ - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); layer_key.press(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); testing::Mock::VerifyAndClearExpectations(&driver); /* Release TG. */ - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); layer_key.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); @@ -212,26 +212,26 @@ TEST_F(ActionLayer, ToggleLayerUpAndDown) { set_keymap({toggle_layer_1_on_layer_0, toggle_layer_0_on_layer_1}); /* Toggle Layer 1. */ - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); toggle_layer_1_on_layer_0.press(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); testing::Mock::VerifyAndClearExpectations(&driver); - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); toggle_layer_1_on_layer_0.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); testing::Mock::VerifyAndClearExpectations(&driver); /* Toggle Layer 0. */ - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); toggle_layer_0_on_layer_1.press(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(0)); testing::Mock::VerifyAndClearExpectations(&driver); - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); toggle_layer_0_on_layer_1.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(0)); @@ -247,13 +247,13 @@ TEST_F(ActionLayer, LayerTapToggleDoesNothing) { set_keymap({layer_key}); /* Press and release TT. */ - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); layer_key.press(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); testing::Mock::VerifyAndClearExpectations(&driver); - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); layer_key.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(0)); @@ -271,25 +271,25 @@ TEST_F(ActionLayer, LayerTapToggleWithKeypress) { set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}}); /* Press TT. */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(0); + EXPECT_NO_REPORT(driver); layer_key.press(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); testing::Mock::VerifyAndClearExpectations(&driver); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))).Times(1); + EXPECT_REPORT(driver, (KC_B)).Times(1); regular_key.press(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); testing::Mock::VerifyAndClearExpectations(&driver); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); + EXPECT_EMPTY_REPORT(driver); regular_key.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); testing::Mock::VerifyAndClearExpectations(&driver); - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); layer_key.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(0)); @@ -307,7 +307,7 @@ TEST_F(ActionLayer, LayerTapToggleWithToggleWithKeypress) { set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}}); /* Tap TT five times . */ - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); layer_key.press(); run_one_scan_loop(); @@ -346,13 +346,13 @@ TEST_F(ActionLayer, LayerTapToggleWithToggleWithKeypress) { testing::Mock::VerifyAndClearExpectations(&driver); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))).Times(1); + EXPECT_REPORT(driver, (KC_B)).Times(1); regular_key.press(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); testing::Mock::VerifyAndClearExpectations(&driver); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); + EXPECT_EMPTY_REPORT(driver); regular_key.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); @@ -370,7 +370,7 @@ TEST_F(ActionLayer, LayerTapReleasedBeforeKeypressReleaseWithModifiers) { set_keymap({layer_0_key_0, layer_1_key_1}); /* Press layer tap and wait for tapping term to switch to layer 1 */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(0); + EXPECT_NO_REPORT(driver); layer_0_key_0.press(); idle_for(TAPPING_TERM); EXPECT_TRUE(layer_state_is(0)); @@ -378,23 +378,23 @@ TEST_F(ActionLayer, LayerTapReleasedBeforeKeypressReleaseWithModifiers) { /* Press key with layer 1 mapping, result basically expected * altough more reports are send then necessary. */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RALT))).Times(1); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RALT, KC_9))).Times(1); + EXPECT_REPORT(driver, (KC_RALT)).Times(1); + EXPECT_REPORT(driver, (KC_RALT, KC_9)).Times(1); layer_1_key_1.press(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); testing::Mock::VerifyAndClearExpectations(&driver); /* Release layer tap key, no report is send because key is still held. */ - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); layer_0_key_0.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(0)); testing::Mock::VerifyAndClearExpectations(&driver); /* Unregister keycode and modifier. */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RALT))).Times(1); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); + EXPECT_REPORT(driver, (KC_RALT)).Times(1); + EXPECT_EMPTY_REPORT(driver); layer_1_key_1.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(0)); diff --git a/tests/basic/test_keypress.cpp b/tests/basic/test_keypress.cpp index 044fc29378..bb68ced557 100644 --- a/tests/basic/test_keypress.cpp +++ b/tests/basic/test_keypress.cpp @@ -24,7 +24,7 @@ class KeyPress : public TestFixture {}; TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { TestDriver driver; - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); keyboard_task(); } @@ -35,11 +35,11 @@ TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) { set_keymap({key}); key.press(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key.report_code))); + EXPECT_REPORT(driver, (key.report_code)); keyboard_task(); key.release(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_EMPTY_REPORT(driver); keyboard_task(); } @@ -50,7 +50,7 @@ TEST_F(KeyPress, ANonMappedKeyDoesNothing) { set_keymap({key}); key.press(); - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); keyboard_task(); keyboard_task(); } @@ -66,19 +66,19 @@ TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { key_c.press(); // Note that QMK only processes one key at a time // See issue #1476 for more information - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_b.report_code))); + EXPECT_REPORT(driver, (key_b.report_code)); keyboard_task(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_b.report_code, key_c.report_code))); + EXPECT_REPORT(driver, (key_b.report_code, key_c.report_code)); keyboard_task(); key_b.release(); key_c.release(); // Note that the first key released is the first one in the matrix order - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_c.report_code))); + EXPECT_REPORT(driver, (key_c.report_code)); keyboard_task(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_EMPTY_REPORT(driver); keyboard_task(); } @@ -94,17 +94,17 @@ TEST_F(KeyPress, LeftShiftIsReportedCorrectly) { // Unfortunately modifiers are also processed in the wrong order // See issue #1476 for more information - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_a.report_code))); + EXPECT_REPORT(driver, (key_a.report_code)); keyboard_task(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_a.report_code, key_lsft.report_code))); + EXPECT_REPORT(driver, (key_a.report_code, key_lsft.report_code)); keyboard_task(); key_a.release(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_lsft.report_code))); + EXPECT_REPORT(driver, (key_lsft.report_code)); keyboard_task(); key_lsft.release(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_EMPTY_REPORT(driver); keyboard_task(); } @@ -120,19 +120,19 @@ TEST_F(KeyPress, PressLeftShiftAndControl) { // Unfortunately modifiers are also processed in the wrong order // See issue #1476 for more information - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_lsft.report_code))); + EXPECT_REPORT(driver, (key_lsft.report_code)); keyboard_task(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_lsft.report_code, key_lctrl.report_code))); + EXPECT_REPORT(driver, (key_lsft.report_code, key_lctrl.report_code)); keyboard_task(); key_lsft.release(); key_lctrl.release(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_lctrl.report_code))); + EXPECT_REPORT(driver, (key_lctrl.report_code)); keyboard_task(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_EMPTY_REPORT(driver); keyboard_task(); } @@ -147,19 +147,19 @@ TEST_F(KeyPress, LeftAndRightShiftCanBePressedAtTheSameTime) { key_rsft.press(); // Unfortunately modifiers are also processed in the wrong order // See issue #1476 for more information - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_lsft.report_code))); + EXPECT_REPORT(driver, (key_lsft.report_code)); keyboard_task(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_lsft.report_code, key_rsft.report_code))); + EXPECT_REPORT(driver, (key_lsft.report_code, key_rsft.report_code)); keyboard_task(); key_lsft.release(); key_rsft.release(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_rsft.report_code))); + EXPECT_REPORT(driver, (key_rsft.report_code)); keyboard_task(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_EMPTY_REPORT(driver); keyboard_task(); } @@ -175,13 +175,13 @@ 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_RIGHT_SHIFT, KC_RIGHT_CTRL))); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RIGHT_SHIFT, KC_RIGHT_CTRL, KC_O))); + EXPECT_REPORT(driver, (KC_RIGHT_SHIFT, KC_RIGHT_CTRL)); + EXPECT_REPORT(driver, (KC_RIGHT_SHIFT, KC_RIGHT_CTRL, KC_O)); keyboard_task(); combo_key.release(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RIGHT_SHIFT, KC_RIGHT_CTRL))); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_REPORT(driver, (KC_RIGHT_SHIFT, KC_RIGHT_CTRL)); + EXPECT_EMPTY_REPORT(driver); keyboard_task(); } @@ -194,24 +194,24 @@ TEST_F(KeyPress, PressPlusEqualReleaseBeforePress) { set_keymap({key_plus, key_eql}); key_plus.press(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_EQUAL))); + EXPECT_REPORT(driver, (KC_LEFT_SHIFT)); + EXPECT_REPORT(driver, (KC_LEFT_SHIFT, KC_EQUAL)); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); key_plus.release(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_REPORT(driver, (KC_LEFT_SHIFT)); + EXPECT_EMPTY_REPORT(driver); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); key_eql.press(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_eql.report_code))); + EXPECT_REPORT(driver, (key_eql.report_code)); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); key_eql.release(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_EMPTY_REPORT(driver); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); } @@ -225,25 +225,25 @@ TEST_F(KeyPress, PressPlusEqualDontReleaseBeforePress) { set_keymap({key_plus, key_eql}); key_plus.press(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_EQUAL))); + EXPECT_REPORT(driver, (KC_LEFT_SHIFT)); + EXPECT_REPORT(driver, (KC_LEFT_SHIFT, KC_EQUAL)); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); key_eql.press(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQUAL))); + EXPECT_EMPTY_REPORT(driver); + EXPECT_REPORT(driver, (KC_EQUAL)); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); key_plus.release(); // BUG: Should really still return KC_EQUAL, but this is fine too - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); + EXPECT_EMPTY_REPORT(driver); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); key_eql.release(); - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); } @@ -257,24 +257,24 @@ TEST_F(KeyPress, PressEqualPlusReleaseBeforePress) { set_keymap({key_plus, key_eql}); key_eql.press(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQUAL))); + EXPECT_REPORT(driver, (KC_EQUAL)); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); key_eql.release(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_EMPTY_REPORT(driver); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); key_plus.press(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_EQUAL))); + EXPECT_REPORT(driver, (KC_LEFT_SHIFT)); + EXPECT_REPORT(driver, (KC_LEFT_SHIFT, KC_EQUAL)); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); key_plus.release(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_REPORT(driver, (KC_LEFT_SHIFT)); + EXPECT_EMPTY_REPORT(driver); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); } @@ -288,27 +288,27 @@ TEST_F(KeyPress, PressEqualPlusDontReleaseBeforePress) { set_keymap({key_plus, key_eql}); key_eql.press(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQUAL))); + EXPECT_REPORT(driver, (KC_EQUAL)); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); key_plus.press(); // BUG: The sequence is a bit strange, but it works, the end result is that // KC_PLUS is sent - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_EQUAL))); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_EQUAL))); + EXPECT_REPORT(driver, (KC_LEFT_SHIFT, KC_EQUAL)); + EXPECT_REPORT(driver, (KC_LEFT_SHIFT)); + EXPECT_REPORT(driver, (KC_LEFT_SHIFT, KC_EQUAL)); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); key_eql.release(); // I guess it's fine to still report shift here - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); + EXPECT_REPORT(driver, (KC_LEFT_SHIFT)); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); key_plus.release(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_EMPTY_REPORT(driver); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); } diff --git a/tests/basic/test_one_shot_keys.cpp b/tests/basic/test_one_shot_keys.cpp index 43fc3e1ba3..bb14221140 100644 --- a/tests/basic/test_one_shot_keys.cpp +++ b/tests/basic/test_one_shot_keys.cpp @@ -31,7 +31,7 @@ TEST_F(OneShot, OSMWithoutAdditionalKeypressDoesNothing) { set_keymap({osm_key}); /* Press and release OSM key*/ - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); osm_key.press(); run_one_scan_loop(); osm_key.release(); @@ -39,7 +39,7 @@ TEST_F(OneShot, OSMWithoutAdditionalKeypressDoesNothing) { testing::Mock::VerifyAndClearExpectations(&driver); /* OSM are added when an actual report is send */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(osm_key.report_code))); + EXPECT_REPORT(driver, (osm_key.report_code)); send_keyboard_report(); testing::Mock::VerifyAndClearExpectations(&driver); @@ -57,7 +57,7 @@ TEST_P(OneShotParametrizedTestFixture, OSMExpiredDoesNothing) { set_keymap({osm_key, regular_key}); /* Press and release OSM */ - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); osm_key.press(); run_one_scan_loop(); osm_key.release(); @@ -65,13 +65,13 @@ TEST_P(OneShotParametrizedTestFixture, OSMExpiredDoesNothing) { testing::Mock::VerifyAndClearExpectations(&driver); /* Press regular key */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(regular_key.report_code))).Times(1); + EXPECT_REPORT(driver, (regular_key.report_code)).Times(1); regular_key.press(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); /* Release regular key */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_EMPTY_REPORT(driver); regular_key.release(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); @@ -87,7 +87,7 @@ TEST_P(OneShotParametrizedTestFixture, OSMWithAdditionalKeypress) { set_keymap({osm_key, regular_key}); /* Press and release OSM */ - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); osm_key.press(); run_one_scan_loop(); osm_key.release(); @@ -95,13 +95,13 @@ TEST_P(OneShotParametrizedTestFixture, OSMWithAdditionalKeypress) { testing::Mock::VerifyAndClearExpectations(&driver); /* Press regular key */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(osm_key.report_code, regular_key.report_code))).Times(1); + EXPECT_REPORT(driver, (osm_key.report_code, regular_key.report_code)).Times(1); regular_key.press(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); /* Release regular key */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_EMPTY_REPORT(driver); regular_key.release(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); @@ -117,26 +117,26 @@ TEST_P(OneShotParametrizedTestFixture, OSMAsRegularModifierWithAdditionalKeypres set_keymap({osm_key, regular_key}); /* Press OSM */ - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); osm_key.press(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); /* Press regular key */ - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); regular_key.press(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); /* Release regular key */ - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); regular_key.release(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); /* Release OSM */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(regular_key.report_code, osm_key.report_code))).Times(1); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); + EXPECT_REPORT(driver, (regular_key.report_code, osm_key.report_code)).Times(1); + EXPECT_EMPTY_REPORT(driver); osm_key.release(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); @@ -169,26 +169,26 @@ TEST_F(OneShot, OSLWithAdditionalKeypress) { set_keymap({osl_key, regular_key}); /* Press OSL key */ - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); osl_key.press(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); /* Release OSL key */ - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); osl_key.release(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); /* Press regular key */ - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(regular_key.report_code))).Times(1); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_REPORT(driver, (regular_key.report_code)).Times(1); + EXPECT_EMPTY_REPORT(driver); regular_key.press(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); /* Release regular key */ - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); regular_key.release(); run_one_scan_loop(); testing::Mock::VerifyAndClearExpectations(&driver); diff --git a/tests/basic/test_tapping.cpp b/tests/basic/test_tapping.cpp index e4a7e4a9f3..6ff9cfe22b 100644 --- a/tests/basic/test_tapping.cpp +++ b/tests/basic/test_tapping.cpp @@ -34,15 +34,15 @@ TEST_F(Tapping, TapA_SHFT_T_KeyReportsKey) { // Tapping keys does nothing on press key_shift_hold_p_tap.press(); - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); run_one_scan_loop(); // First we get the key press key_shift_hold_p_tap.release(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); + EXPECT_REPORT(driver, (KC_P)); // Then the release - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_EMPTY_REPORT(driver); run_one_scan_loop(); } @@ -56,13 +56,13 @@ TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) { mod_tap_hold_key.press(); // Tapping keys does nothing on press - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); idle_for(TAPPING_TERM); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); + EXPECT_REPORT(driver, (KC_LSFT)); run_one_scan_loop(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_EMPTY_REPORT(driver); mod_tap_hold_key.release(); run_one_scan_loop(); } @@ -77,36 +77,36 @@ TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) { // Tapping keys does nothing on press key_shift_hold_p_tap.press(); - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); run_one_scan_loop(); key_shift_hold_p_tap.release(); // First we get the key press - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); + EXPECT_REPORT(driver, (KC_P)); // Then the release - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_EMPTY_REPORT(driver); run_one_scan_loop(); // This sends KC_P, even if it should do nothing key_shift_hold_p_tap.press(); // This test should not succed if everything works correctly - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); + EXPECT_REPORT(driver, (KC_P)); run_one_scan_loop(); key_shift_hold_p_tap.release(); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_EMPTY_REPORT(driver); idle_for(TAPPING_TERM + 1); // On the other hand, nothing is sent if we are outside the tapping term key_shift_hold_p_tap.press(); - EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); + EXPECT_NO_REPORT(driver); run_one_scan_loop(); key_shift_hold_p_tap.release(); // First we get the key press - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); + EXPECT_REPORT(driver, (KC_P)); // Then the release - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_EMPTY_REPORT(driver); idle_for(TAPPING_TERM + 1); // Now we are geting into strange territory, as the hold registers too early here @@ -114,10 +114,10 @@ TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) { // If TAPPING_TERM + 1 above is changed to TAPPING_TERM or TAPPING_TERM + 2 it doesn't key_shift_hold_p_tap.press(); // Shouldn't be called here really - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).Times(1); + EXPECT_REPORT(driver, (KC_LEFT_SHIFT)).Times(1); idle_for(TAPPING_TERM); - EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); + EXPECT_EMPTY_REPORT(driver); key_shift_hold_p_tap.release(); run_one_scan_loop(); -} \ No newline at end of file +} -- cgit v1.2.3