Skip to content

Commit

Permalink
Correct failing unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlK90 committed Jan 23, 2022
1 parent 49d6323 commit 386033b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
30 changes: 16 additions & 14 deletions tests/basic/test_tapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ TEST_F(Tapping, TapA_SHFT_T_KeyReportsKey) {
key_shift_hold_p_tap.press();
EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);

// First we get the key press
key_shift_hold_p_tap.release();
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));

// Then the release
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
}

TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) {
Expand All @@ -54,17 +53,15 @@ TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) {
set_keymap({mod_tap_hold_key});

mod_tap_hold_key.press();

// Tapping keys does nothing on press
EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
idle_for(TAPPING_TERM);

EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);

EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
mod_tap_hold_key.release();
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
}

TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) {
Expand All @@ -80,44 +77,49 @@ TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) {
EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
run_one_scan_loop();
key_shift_hold_p_tap.release();
testing::Mock::VerifyAndClearExpectations(&driver);

// First we get the key press
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
// Then the release
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);

// 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)));
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);

key_shift_hold_p_tap.release();
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
idle_for(TAPPING_TERM + 1);
testing::Mock::VerifyAndClearExpectations(&driver);

// 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);
run_one_scan_loop();
key_shift_hold_p_tap.release();
testing::Mock::VerifyAndClearExpectations(&driver);

// First we get the key press
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
// Then the release
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
idle_for(TAPPING_TERM + 1);
idle_for(TAPPING_TERM);
testing::Mock::VerifyAndClearExpectations(&driver);

// Now we are geting into strange territory, as the hold registers too early here
// But the stranges part is:
// 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_CALL(driver, send_keyboard_mock(_)).Times(0);
idle_for(TAPPING_TERM);
testing::Mock::VerifyAndClearExpectations(&driver);

EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).Times(1);
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
key_shift_hold_p_tap.release();
run_one_scan_loop();
}
testing::Mock::VerifyAndClearExpectations(&driver);
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ TEST_F(DefaultTapHold, tap_regular_key_while_mod_tap_key_is_held) {
testing::Mock::VerifyAndClearExpectations(&driver);

/* Idle for tapping term of mod tap hold key. */
idle_for(TAPPING_TERM - 3);
idle_for(TAPPING_TERM);
testing::Mock::VerifyAndClearExpectations(&driver);
}

Expand Down Expand Up @@ -227,4 +227,4 @@ TEST_F(DefaultTapHold, tap_and_hold_mod_tap_hold_key) {
mod_tap_hold_key.release();
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ TEST_F(RetroTapping, tap_and_hold_mod_tap_hold_key) {
testing::Mock::VerifyAndClearExpectations(&driver);

/* Release mod-tap-hold key. */
/* TODO: Why is LSHIFT send at all? */
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT)));
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
mod_tap_hold_key.release();
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
}
}
5 changes: 1 addition & 4 deletions tests/tap_hold_configurations/retro_tapping/test_tapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) {
testing::Mock::VerifyAndClearExpectations(&driver);

EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT)));
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);

EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P)));
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
Expand Down Expand Up @@ -109,4 +106,4 @@ TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) {
key_shift_hold_p_tap.release();
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ TEST_F(TappingForceHold, tap_regular_key_while_mod_tap_key_is_held) {
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()));
idle_for(TAPPING_TERM - 3);
idle_for(TAPPING_TERM);
testing::Mock::VerifyAndClearExpectations(&driver);
}

Expand Down Expand Up @@ -103,7 +103,7 @@ TEST_F(TappingForceHold, tap_mod_tap_key_while_mod_tap_key_is_held) {
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()));
idle_for(TAPPING_TERM - 3);
idle_for(TAPPING_TERM);
testing::Mock::VerifyAndClearExpectations(&driver);
}

Expand Down

0 comments on commit 386033b

Please sign in to comment.