1
0
Fork 0

Introduce VERIFY_AND_CLEAR shorthand (#19370)

Which is just a syntactic sugar for
testing::Mock::VerifyAndClearExpectations to reduce the visual clutter
in unit-tests.
This commit is contained in:
Stefan Kerkmann 2022-12-18 21:55:14 +01:00 committed by GitHub
parent 7aa2d791f6
commit c2b13bd77b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 257 additions and 251 deletions

View file

@ -28,7 +28,7 @@ TEST_F(ActionLayer, LayerStateDBG) {
layer_state_set(0);
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
}
TEST_F(ActionLayer, LayerStateSet) {
@ -39,7 +39,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 +56,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 +76,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 +85,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 +96,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 +108,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 +121,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 +134,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 +155,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 +192,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 +216,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 +251,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 +275,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 +344,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 +373,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 +382,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 +397,5 @@ 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);
}

View file

@ -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);
key_eql.release();
EXPECT_EMPTY_REPORT(driver);
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
}
TEST_F(KeyPress, PressPlusEqualDontReleaseBeforePress) {
@ -206,24 +206,24 @@ TEST_F(KeyPress, PressPlusEqualDontReleaseBeforePress) {
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_eql.press();
EXPECT_EMPTY_REPORT(driver);
EXPECT_REPORT(driver, (KC_EQUAL));
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
key_plus.release();
// BUG: Should really still return KC_EQUAL, but this is fine too
EXPECT_EMPTY_REPORT(driver);
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
key_eql.release();
EXPECT_NO_REPORT(driver);
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
}
TEST_F(KeyPress, PressEqualPlusReleaseBeforePress) {
@ -237,24 +237,24 @@ TEST_F(KeyPress, PressEqualPlusReleaseBeforePress) {
key_eql.press();
EXPECT_REPORT(driver, (KC_EQUAL));
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
key_eql.release();
EXPECT_EMPTY_REPORT(driver);
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
key_plus.press();
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);
}
TEST_F(KeyPress, PressEqualPlusDontReleaseBeforePress) {
@ -268,7 +268,7 @@ TEST_F(KeyPress, PressEqualPlusDontReleaseBeforePress) {
key_eql.press();
EXPECT_REPORT(driver, (KC_EQUAL));
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
key_plus.press();
// BUG: The sequence is a bit strange, but it works, the end result is that
@ -277,16 +277,16 @@ TEST_F(KeyPress, PressEqualPlusDontReleaseBeforePress) {
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_eql.release();
// I guess it's fine to still report shift here
EXPECT_REPORT(driver, (KC_LEFT_SHIFT));
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
key_plus.release();
EXPECT_EMPTY_REPORT(driver);
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
}

View file

@ -36,12 +36,12 @@ TEST_F(OneShot, OSMWithoutAdditionalKeypressDoesNothing) {
run_one_scan_loop();
osm_key.release();
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
/* OSM are added when an actual report is send */
EXPECT_REPORT(driver, (osm_key.report_code));
send_keyboard_report();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
/* Make unit-test pass */
clear_oneshot_mods();
@ -62,19 +62,19 @@ TEST_P(OneShotParametrizedTestFixture, OSMExpiredDoesNothing) {
run_one_scan_loop();
osm_key.release();
idle_for(ONESHOT_TIMEOUT);
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
/* Press regular key */
EXPECT_REPORT(driver, (regular_key.report_code)).Times(1);
regular_key.press();
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
/* Release regular key */
EXPECT_EMPTY_REPORT(driver);
regular_key.release();
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
}
#endif
@ -92,19 +92,19 @@ TEST_P(OneShotParametrizedTestFixture, OSMWithAdditionalKeypress) {
run_one_scan_loop();
osm_key.release();
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
/* Press regular key */
EXPECT_REPORT(driver, (osm_key.report_code, regular_key.report_code)).Times(1);
regular_key.press();
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
/* Release regular key */
EXPECT_EMPTY_REPORT(driver);
regular_key.release();
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
}
TEST_P(OneShotParametrizedTestFixture, OSMAsRegularModifierWithAdditionalKeypress) {
@ -120,26 +120,26 @@ TEST_P(OneShotParametrizedTestFixture, OSMAsRegularModifierWithAdditionalKeypres
EXPECT_NO_REPORT(driver);
osm_key.press();
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
/* Press regular key */
EXPECT_NO_REPORT(driver);
regular_key.press();
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
/* Release regular key */
EXPECT_NO_REPORT(driver);
regular_key.release();
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
/* Release OSM */
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);
VERIFY_AND_CLEAR(driver);
}
// clang-format off
@ -172,24 +172,24 @@ TEST_F(OneShot, OSLWithAdditionalKeypress) {
EXPECT_NO_REPORT(driver);
osl_key.press();
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
/* Release OSL key */
EXPECT_NO_REPORT(driver);
osl_key.release();
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
/* Press regular key */
EXPECT_REPORT(driver, (regular_key.report_code)).Times(1);
EXPECT_EMPTY_REPORT(driver);
regular_key.press();
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
/* Release regular key */
EXPECT_NO_REPORT(driver);
regular_key.release();
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
}

View file

@ -134,7 +134,7 @@ TEST_F(Tapping, TapA_CTL_T_KeyWhileReleasingShift) {
// Shift is reported
EXPECT_REPORT(driver, (KC_LSFT));
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
mod_tap_hold_key.press();
// Tapping keys does nothing on press
@ -145,7 +145,7 @@ TEST_F(Tapping, TapA_CTL_T_KeyWhileReleasingShift) {
// Releasing shift is delayed while tapping is in progress
EXPECT_NO_REPORT(driver);
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
mod_tap_hold_key.release();
// Releasing mod-tap key reports the tap and releases shift
@ -153,7 +153,7 @@ TEST_F(Tapping, TapA_CTL_T_KeyWhileReleasingShift) {
EXPECT_REPORT(driver, (KC_P));
EXPECT_EMPTY_REPORT(driver);
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
}
TEST_F(Tapping, TapA_CTL_T_KeyWhileReleasingLayer) {
@ -180,7 +180,7 @@ TEST_F(Tapping, TapA_CTL_T_KeyWhileReleasingLayer) {
// Releasing layer is delayed while tapping is in progress
EXPECT_NO_REPORT(driver);
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
mod_tap_hold_key1.release();
// Releasing mod-tap key reports the tap of the layer 1 key
@ -188,5 +188,5 @@ TEST_F(Tapping, TapA_CTL_T_KeyWhileReleasingLayer) {
EXPECT_REPORT(driver, (KC_Q));
EXPECT_EMPTY_REPORT(driver);
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
}