summaryrefslogtreecommitdiffstats
path: root/tests/caps_word/test_caps_word.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/caps_word/test_caps_word.cpp')
-rw-r--r--tests/caps_word/test_caps_word.cpp90
1 files changed, 74 insertions, 16 deletions
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