diff options
Diffstat (limited to 'tests/caps_word')
4 files changed, 83 insertions, 25 deletions
diff --git a/tests/caps_word/caps_word_autoshift/test_caps_word_autoshift.cpp b/tests/caps_word/caps_word_autoshift/test_caps_word_autoshift.cpp index ba21c527a6..01b1a78a5f 100644 --- a/tests/caps_word/caps_word_autoshift/test_caps_word_autoshift.cpp +++ b/tests/caps_word/caps_word_autoshift/test_caps_word_autoshift.cpp @@ -64,7 +64,7 @@ TEST_F(CapsWord, AutoShiftKeys) { tap_key(key_spc); tap_key(key_a); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // Test Caps Word + Auto Shift where keys A and B are rolled. @@ -104,7 +104,7 @@ TEST_F(CapsWord, AutoShiftRolledShiftedKeys) { run_one_scan_loop(); caps_word_off(); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // Tests that with tap-hold keys with Retro Shift, letter keys are shifted by @@ -133,5 +133,5 @@ TEST_F(CapsWord, RetroShiftKeys) { tap_key(key_modtap_a); // Tap A quickly. EXPECT_EQ(is_caps_word_on(), true); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } diff --git a/tests/caps_word/caps_word_combo/test_caps_word_combo.cpp b/tests/caps_word/caps_word_combo/test_caps_word_combo.cpp index 3a0530b854..0876cc91a3 100644 --- a/tests/caps_word/caps_word_combo/test_caps_word_combo.cpp +++ b/tests/caps_word/caps_word_combo/test_caps_word_combo.cpp @@ -102,7 +102,7 @@ TEST_P(CapsWord, SingleCombo) { EXPECT_TRUE(is_caps_word_on()); caps_word_off(); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // Test a longer 4-key combo. @@ -123,7 +123,7 @@ TEST_P(CapsWord, LongerCombo) { EXPECT_TRUE(is_caps_word_on()); caps_word_off(); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // Test with two overlapping combos on regular keys: @@ -161,7 +161,7 @@ TEST_P(CapsWord, ComboRegularKeys) { tap_key(key_a); EXPECT_FALSE(is_caps_word_on()); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // Test where combo chords involve tap-hold keys: @@ -194,7 +194,7 @@ TEST_P(CapsWord, ComboModTapKey) { EXPECT_TRUE(is_caps_word_on()); caps_word_off(); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // clang-format off diff --git a/tests/caps_word/caps_word_unicodemap/test_caps_word_unicodemap.cpp b/tests/caps_word/caps_word_unicodemap/test_caps_word_unicodemap.cpp index fb8f9333bb..01cdfd6408 100644 --- a/tests/caps_word/caps_word_unicodemap/test_caps_word_unicodemap.cpp +++ b/tests/caps_word/caps_word_unicodemap/test_caps_word_unicodemap.cpp @@ -93,7 +93,7 @@ TEST_F(CapsWord, ShiftedUnicodeMapKey) { tap_keys(key_delta, key_spc, key_delta); EXPECT_EQ(is_caps_word_on(), false); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // Tests typing U_ENDASH while Caps Word is on. @@ -117,5 +117,5 @@ TEST_F(CapsWord, UnshiftedUnicodeMapKey) { tap_key(key_dash); EXPECT_EQ(is_caps_word_on(), true); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } diff --git a/tests/caps_word/test_caps_word.cpp b/tests/caps_word/test_caps_word.cpp index 3d0735d8c2..6d38b383f3 100644 --- a/tests/caps_word/test_caps_word.cpp +++ b/tests/caps_word/test_caps_word.cpp @@ -90,7 +90,7 @@ TEST_F(CapsWord, OnOffToggleFuns) { caps_word_toggle(); EXPECT_EQ(is_caps_word_on(), false); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // Tests the default `caps_word_press_user()` function. @@ -133,7 +133,7 @@ TEST_F(CapsWord, CapswrdKey) { tap_key(key_capswrd); // Tap the QK_CAPS_WORD_TOGGLE key again. EXPECT_EQ(is_caps_word_on(), false); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // Tests that being idle for CAPS_WORD_IDLE_TIMEOUT turns off Caps Word. @@ -157,7 +157,7 @@ TEST_F(CapsWord, IdleTimeout) { caps_word_on(); tap_key(key_a); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); idle_for(CAPS_WORD_IDLE_TIMEOUT); run_one_scan_loop(); @@ -171,7 +171,7 @@ TEST_F(CapsWord, IdleTimeout) { EXPECT_REPORT(driver, (KC_A)); tap_key(key_a); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // Tests that typing "A, 4, A, 4" produces "Shift+A, 4, Shift+A, 4". @@ -201,7 +201,7 @@ TEST_F(CapsWord, ShiftsLettersButNotDigits) { caps_word_on(); tap_keys(key_a, key_4, key_a, key_4); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // Tests that typing "A, Space, A" produces "Shift+A, Space, A". @@ -230,7 +230,7 @@ TEST_F(CapsWord, SpaceTurnsOffCapsWord) { caps_word_on(); tap_keys(key_a, key_spc, key_a); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // Tests that typing "AltGr + A" produces "Shift + AltGr + A". @@ -260,7 +260,7 @@ TEST_F(CapsWord, ShiftsAltGrSymbols) { run_one_scan_loop(); key_altgr.release(); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // Tests typing "AltGr + A" using a mod-tap key. @@ -291,7 +291,7 @@ TEST_F(CapsWord, ShiftsModTapAltGrSymbols) { key_altgr_t.release(); EXPECT_TRUE(is_caps_word_on()); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } struct CapsWordPressUserParams { @@ -326,7 +326,7 @@ TEST_P(CapsWordPressUser, KeyCode) { EXPECT_EQ(passed_keycode, GetParam().expected_passed_keycode); EXPECT_EQ(is_caps_word_on(), GetParam().continues_caps_word); clear_oneshot_mods(); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } const uint16_t LT_1_KC_A = LT(1, KC_A); @@ -431,7 +431,7 @@ TEST_P(CapsWordBothShifts, PressLRLR) { EXPECT_EQ(is_caps_word_on(), true); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // Pressing shifts as "Left down, Right down, Right up, Left up". @@ -468,7 +468,7 @@ TEST_P(CapsWordBothShifts, PressLRRL) { EXPECT_EQ(is_caps_word_on(), true); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // clang-format off @@ -505,7 +505,8 @@ class CapsWordDoubleTapShift : public ::testing::WithParamInterface<CapsWordDoub TEST_P(CapsWordDoubleTapShift, Activation) { TestDriver driver; KeymapKey left_shift(0, 0, 0, GetParam().left_shift_keycode); - set_keymap({left_shift}); + KeymapKey esc(0, 0, 1, KC_ESCAPE); + set_keymap({left_shift, esc}); // clang-format off EXPECT_CALL(driver, send_keyboard_mock(AnyOf( @@ -523,7 +524,13 @@ TEST_P(CapsWordDoubleTapShift, Activation) { EXPECT_EQ(is_caps_word_on(), true); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); + + // We have to manually reset the internal state of the caps word state + // machine at this point. This due to imperfect test isolation which can't + // reset the caps word double shift timer on test case setup. + idle_for(CAPS_WORD_IDLE_TIMEOUT); + tap_key(esc); } // Double tap doesn't count if another key is pressed between the taps. @@ -555,7 +562,7 @@ TEST_P(CapsWordDoubleTapShift, Interrupted) { EXPECT_EQ(is_caps_word_on(), false); // Caps Word is still off. clear_oneshot_mods(); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // Double tap doesn't count if taps are more than tapping term apart. @@ -578,7 +585,7 @@ TEST_P(CapsWordDoubleTapShift, SlowTaps) { EXPECT_EQ(is_caps_word_on(), false); // Caps Word is still off. clear_oneshot_mods(); - testing::Mock::VerifyAndClearExpectations(&driver); + VERIFY_AND_CLEAR(driver); } // clang-format off @@ -591,6 +598,57 @@ INSTANTIATE_TEST_CASE_P( ), CapsWordDoubleTapShiftParams::GetName ); -// clang-format on +// Tests that holding a OSL keeps caps word active and shifts keys on the layer that need to be shifted. +TEST_F(CapsWord, IgnoresOSLHold) { + TestDriver driver; + KeymapKey key_a(0, 0, 0, KC_A); + KeymapKey key_osl(0, 1, 0, OSL(1)); + KeymapKey key_b(1, 0, 0, KC_B); + set_keymap({key_a, key_osl, key_b}); + + // Allow any number of reports with no keys or only modifiers. + // clang-format off + EXPECT_CALL(driver, send_keyboard_mock(AnyOf( + KeyboardReport(), + KeyboardReport(KC_LSFT)))) + .Times(AnyNumber()); + + EXPECT_REPORT(driver, (KC_LSFT, KC_B)); + caps_word_on(); + + key_osl.press(); + run_one_scan_loop(); + tap_key(key_b); + key_osl.release(); + run_one_scan_loop(); + + VERIFY_AND_CLEAR(driver); +} + +// Tests that tapping a OSL keeps caps word active and shifts keys on the layer that need to be shifted. +TEST_F(CapsWord, IgnoresOSLTap) { + TestDriver driver; + KeymapKey key_a(0, 0, 0, KC_A); + KeymapKey key_osl(0, 1, 0, OSL(1)); + KeymapKey key_b(1, 0, 0, KC_B); + set_keymap({key_a, key_osl, key_b}); + + // Allow any number of reports with no keys or only modifiers. + // clang-format off + EXPECT_CALL(driver, send_keyboard_mock(AnyOf( + KeyboardReport(), + KeyboardReport(KC_LSFT)))) + .Times(AnyNumber()); + + EXPECT_REPORT(driver, (KC_LSFT, KC_B)); + caps_word_on(); + + tap_key(key_osl); + tap_key(key_b); + run_one_scan_loop(); + + VERIFY_AND_CLEAR(driver); +} +// clang-format on } // namespace |