diff options
Diffstat (limited to 'tests')
61 files changed, 2483 insertions, 830 deletions
diff --git a/tests/auto_shift/test_auto_shift.cpp b/tests/auto_shift/test_auto_shift.cpp index a83f436c33..1d80634b2f 100644 --- a/tests/auto_shift/test_auto_shift.cpp +++ b/tests/auto_shift/test_auto_shift.cpp @@ -37,14 +37,14 @@ TEST_F(AutoShift, key_release_before_timeout) { EXPECT_NO_REPORT(driver); regular_key.press(); run_one_scan_loop(); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); /* Release regular key */ EXPECT_REPORT(driver, (KC_A)); EXPECT_EMPTY_REPORT(driver); regular_key.release(); run_one_scan_loop(); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } TEST_F(AutoShift, key_release_after_timeout) { @@ -58,7 +58,7 @@ TEST_F(AutoShift, key_release_after_timeout) { EXPECT_NO_REPORT(driver); regular_key.press(); idle_for(AUTO_SHIFT_TIMEOUT); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); /* Release regular key */ EXPECT_REPORT(driver, (KC_LSFT, KC_A)); @@ -66,5 +66,5 @@ TEST_F(AutoShift, key_release_after_timeout) { EXPECT_EMPTY_REPORT(driver); regular_key.release(); run_one_scan_loop(); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } diff --git a/tests/autocorrect/test_autocorrect.cpp b/tests/autocorrect/test_autocorrect.cpp index 509c1c9ea4..9b8db3d68d 100644 --- a/tests/autocorrect/test_autocorrect.cpp +++ b/tests/autocorrect/test_autocorrect.cpp @@ -51,7 +51,7 @@ TEST_F(AutoCorrect, OnOffToggle) { autocorrect_toggle(); EXPECT_EQ(autocorrect_is_enabled(), true); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // Test that typing "fales" autocorrects to "false" @@ -80,7 +80,7 @@ TEST_F(AutoCorrect, fales_to_false_autocorrection) { TapKeys(key_f, key_a, key_l, key_e, key_s); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // Test that typing "fales" doesn't autocorrect if disabled @@ -109,7 +109,7 @@ TEST_F(AutoCorrect, fales_disabled_autocorrect) { TapKeys(key_f, key_a, key_l, key_e, key_s); autocorrect_enable(); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // Test that typing "falsify" doesn't autocorrect if disabled @@ -139,7 +139,7 @@ TEST_F(AutoCorrect, falsify_should_not_autocorrect) { TapKeys(key_f, key_a, key_l, key_s, key_i, key_f, key_y); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // Test that typing "ture" autocorrect to "true" @@ -169,7 +169,7 @@ TEST_F(AutoCorrect, ture_to_true_autocorrect) { TapKeys(key_space, key_t_code, key_u, key_r, key_e); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // Test that typing "overture" does not autocorrect @@ -200,5 +200,5 @@ TEST_F(AutoCorrect, overture_should_not_autocorrect) { TapKeys(key_o, key_v, key_e, key_r, key_t_code, key_u, key_r, key_e); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } diff --git a/tests/basic/test_action_layer.cpp b/tests/basic/test_action_layer.cpp index d0a28d42c0..b7ecfa52ef 100644 --- a/tests/basic/test_action_layer.cpp +++ b/tests/basic/test_action_layer.cpp @@ -19,6 +19,7 @@ #include "test_common.hpp" using testing::_; +using testing::AnyNumber; using testing::InSequence; class ActionLayer : public TestFixture {}; @@ -28,7 +29,7 @@ TEST_F(ActionLayer, LayerStateDBG) { layer_state_set(0); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } TEST_F(ActionLayer, LayerStateSet) { @@ -39,7 +40,7 @@ TEST_F(ActionLayer, LayerStateSet) { layer_state_set(0b001100); EXPECT_EQ(layer_state, 0b001100); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } TEST_F(ActionLayer, LayerStateIs) { @@ -56,7 +57,7 @@ TEST_F(ActionLayer, LayerStateIs) { EXPECT_EQ(layer_state_is(1), true); EXPECT_EQ(layer_state_is(2), false); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } TEST_F(ActionLayer, LayerStateCmp) { @@ -76,7 +77,7 @@ TEST_F(ActionLayer, LayerStateCmp) { EXPECT_EQ(layer_state_cmp(prev_layer, 1), true); EXPECT_EQ(layer_state_cmp(prev_layer, 2), false); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } TEST_F(ActionLayer, LayerClear) { @@ -85,7 +86,7 @@ TEST_F(ActionLayer, LayerClear) { layer_clear(); EXPECT_EQ(layer_state, 0); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } TEST_F(ActionLayer, LayerMove) { @@ -96,7 +97,7 @@ TEST_F(ActionLayer, LayerMove) { layer_move(3); EXPECT_EQ(layer_state, 0b1000); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } TEST_F(ActionLayer, LayerOn) { @@ -108,7 +109,7 @@ TEST_F(ActionLayer, LayerOn) { layer_on(3); EXPECT_EQ(layer_state, 0b1010); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } TEST_F(ActionLayer, LayerOff) { @@ -121,7 +122,7 @@ TEST_F(ActionLayer, LayerOff) { layer_off(2); EXPECT_EQ(layer_state, 0b0010); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } TEST_F(ActionLayer, MomentaryLayerDoesNothing) { @@ -134,12 +135,12 @@ TEST_F(ActionLayer, MomentaryLayerDoesNothing) { EXPECT_NO_REPORT(driver); layer_key.press(); run_one_scan_loop(); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); EXPECT_NO_REPORT(driver); layer_key.release(); run_one_scan_loop(); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } TEST_F(ActionLayer, MomentaryLayerWithKeypress) { @@ -155,28 +156,28 @@ TEST_F(ActionLayer, MomentaryLayerWithKeypress) { layer_key.press(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); /* Press key on layer 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); + VERIFY_AND_CLEAR(driver); /* Release key on layer 1 */ EXPECT_EMPTY_REPORT(driver); regular_key.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); /* Release MO */ EXPECT_NO_REPORT(driver); layer_key.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(0)); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } TEST_F(ActionLayer, ToggleLayerDoesNothing) { @@ -192,14 +193,14 @@ TEST_F(ActionLayer, ToggleLayerDoesNothing) { layer_key.press(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); /* Release TG. */ EXPECT_NO_REPORT(driver); layer_key.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } TEST_F(ActionLayer, ToggleLayerUpAndDown) { @@ -216,26 +217,26 @@ TEST_F(ActionLayer, ToggleLayerUpAndDown) { toggle_layer_1_on_layer_0.press(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); 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); + VERIFY_AND_CLEAR(driver); /* Toggle Layer 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); + VERIFY_AND_CLEAR(driver); EXPECT_NO_REPORT(driver); toggle_layer_0_on_layer_1.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(0)); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } TEST_F(ActionLayer, LayerTapToggleDoesNothing) { @@ -251,13 +252,13 @@ TEST_F(ActionLayer, LayerTapToggleDoesNothing) { layer_key.press(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); EXPECT_NO_REPORT(driver); layer_key.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(0)); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } TEST_F(ActionLayer, LayerTapToggleWithKeypress) { @@ -275,25 +276,25 @@ TEST_F(ActionLayer, LayerTapToggleWithKeypress) { layer_key.press(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); EXPECT_REPORT(driver, (KC_B)).Times(1); regular_key.press(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); EXPECT_EMPTY_REPORT(driver); regular_key.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); EXPECT_NO_REPORT(driver); layer_key.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(0)); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } TEST_F(ActionLayer, LayerTapToggleWithToggleWithKeypress) { @@ -344,19 +345,19 @@ TEST_F(ActionLayer, LayerTapToggleWithToggleWithKeypress) { run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); EXPECT_REPORT(driver, (KC_B)).Times(1); regular_key.press(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); EXPECT_EMPTY_REPORT(driver); regular_key.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } TEST_F(ActionLayer, LayerTapReleasedBeforeKeypressReleaseWithModifiers) { @@ -373,7 +374,7 @@ TEST_F(ActionLayer, LayerTapReleasedBeforeKeypressReleaseWithModifiers) { layer_0_key_0.press(); idle_for(TAPPING_TERM); EXPECT_TRUE(layer_state_is(0)); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); /* Press key with layer 1 mapping, result basically expected * altough more reports are send then necessary. */ @@ -382,14 +383,14 @@ TEST_F(ActionLayer, LayerTapReleasedBeforeKeypressReleaseWithModifiers) { layer_1_key_1.press(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(1)); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); /* Release layer tap key, no report is send because key is still held. */ EXPECT_NO_REPORT(driver); layer_0_key_0.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(0)); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); /* Unregister keycode and modifier. */ EXPECT_REPORT(driver, (KC_RALT)).Times(1); @@ -397,5 +398,67 @@ TEST_F(ActionLayer, LayerTapReleasedBeforeKeypressReleaseWithModifiers) { layer_1_key_1.release(); run_one_scan_loop(); EXPECT_TRUE(layer_state_is(0)); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); +} + +TEST_F(ActionLayer, LayerModWithKeypress) { + TestDriver driver; + KeymapKey layer_key = KeymapKey{0, 0, 0, LM(1, MOD_RALT)}; + KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A}; + set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}}); + + // Allow any number of reports with no keys or only KC_RALT. + // clang-format off + EXPECT_CALL(driver, send_keyboard_mock(AnyOf( + KeyboardReport(), + KeyboardReport(KC_RALT)))) + .Times(AnyNumber()); + // clang-format on + EXPECT_REPORT(driver, (KC_RALT, KC_B)).Times(1); + + layer_key.press(); + run_one_scan_loop(); + EXPECT_TRUE(layer_state_is(1)); + EXPECT_EQ(get_mods(), MOD_BIT(KC_RALT)); + + tap_key(regular_key); + + layer_key.release(); + run_one_scan_loop(); + EXPECT_TRUE(layer_state_is(0)); + EXPECT_EQ(get_mods(), 0); + + VERIFY_AND_CLEAR(driver); +} + +TEST_F(ActionLayer, LayerModHonorsModConfig) { + TestDriver driver; + KeymapKey layer_key = KeymapKey{0, 0, 0, LM(1, MOD_RALT)}; + KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A}; + set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}}); + + // Allow any number of reports with no keys or only KC_RALT. + // clang-format off + EXPECT_CALL(driver, send_keyboard_mock(AnyOf( + KeyboardReport(), + KeyboardReport(KC_RGUI)))) + .Times(AnyNumber()); + // clang-format on + EXPECT_REPORT(driver, (KC_RGUI, KC_B)).Times(1); + + keymap_config.swap_ralt_rgui = true; + + layer_key.press(); + run_one_scan_loop(); + EXPECT_TRUE(layer_state_is(1)); + EXPECT_EQ(get_mods(), MOD_BIT(KC_RGUI)); + + tap_key(regular_key); + + layer_key.release(); + run_one_scan_loop(); + EXPECT_TRUE(layer_state_is(0)); + EXPECT_EQ(get_mods(), 0); + + VERIFY_AND_CLEAR(driver); } diff --git a/tests/basic/test_keycode_util.cpp b/tests/basic/test_keycode_util.cpp new file mode 100644 index 0000000000..693334676e --- /dev/null +++ b/tests/basic/test_keycode_util.cpp @@ -0,0 +1,52 @@ +// Copyright 2022 Stefan Kerkmann +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "test_common.hpp" + +class KeycodeToIdentifierSuite : public ::testing::TestWithParam<std::pair<std::uint16_t, std::string>> {}; + +TEST_P(KeycodeToIdentifierSuite, ConversionTests) { + ASSERT_EQ(get_keycode_identifier_or_default(GetParam().first), GetParam().second); +} + +INSTANTIATE_TEST_CASE_P(ConversionTestsP, KeycodeToIdentifierSuite, + // clang-format off +::testing::Values( + // Goto layer + std::make_pair(TO(0), "TO(0)"), + std::make_pair(TO(0x1F), "TO(31)"), + // Momentary switch layer + std::make_pair(MO(0), "MO(0)"), + std::make_pair(MO(0x1F), "MO(31)"), + // Set default layer + std::make_pair(DF(0), "DF(0)"), + std::make_pair(DF(0x1F), "DF(31)"), + // Toggle layer + std::make_pair(TG(0), "TG(0)"), + std::make_pair(TG(0x1F), "TG(31)"), + // One-shot layer + std::make_pair(OSL(0), "OSL(0)"), + std::make_pair(OSL(0x1F), "OSL(31)"), + // One-shot mod + std::make_pair(OSM(MOD_LSFT), "OSM(MOD_LSFT)"), + std::make_pair(OSM(MOD_LSFT | MOD_LCTL), "OSM(MOD_LCTL | MOD_LSFT)"), + // Layer Mod + std::make_pair(LM(0, MOD_LSFT), "LM(0, MOD_LSFT)"), + std::make_pair(LM(0xF, MOD_LSFT), "LM(15, MOD_LSFT)"), + std::make_pair(LM(0xF, MOD_LSFT | MOD_LCTL), "LM(15, MOD_LCTL | MOD_LSFT)"), + // Layer tap toggle + std::make_pair(TT(0), "TT(0)"), + std::make_pair(TT(0x1F), "TT(31)"), + // Layer tap + std::make_pair(LT(0, KC_A), "LT(0, KC_A)"), + std::make_pair(LT(0xF, KC_SPACE), "LT(15, KC_SPACE)"), + std::make_pair(LT(1, KC_SPC), "LT(1, KC_SPACE)"), + // Mod tap + std::make_pair(MT(MOD_LCTL, KC_A), "MT(MOD_LCTL, KC_A)"), + std::make_pair(MT(MOD_LCTL | MOD_LSFT, KC_A), "MT(MOD_LCTL | MOD_LSFT, KC_A)"), + std::make_pair(ALT_T(KC_TAB), "MT(MOD_LALT, KC_TAB)"), + // Mods + std::make_pair(LCTL(KC_A), "QK_MODS(KC_A, QK_LCTL)"), + std::make_pair(HYPR(KC_SPACE), "QK_MODS(KC_SPACE, QK_LCTL | QK_LSFT | QK_LALT | QK_LGUI)") +)); +// clang-format on diff --git a/tests/basic/test_keypress.cpp b/tests/basic/test_keypress.cpp index 6d5b502a00..34682654b0 100644 --- a/tests/basic/test_keypress.cpp +++ b/tests/basic/test_keypress.cpp @@ -175,23 +175,23 @@ TEST_F(KeyPress, PressPlusEqualReleaseBeforePress) { EXPECT_REPORT(driver, (KC_LEFT_SHIFT)); EXPECT_REPORT(driver, (KC_LEFT_SHIFT, KC_EQUAL)); run_one_scan_loop(); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); key_plus.release(); EXPECT_REPORT(driver, (KC_LEFT_SHIFT)); EXPECT_EMPTY_REPORT(driver); run_one_scan_loop(); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); key_eql.press(); EXPECT_REPORT(driver, (key_eql.report_code)); run_one_scan_loop(); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); |