Skip to content

Commit

Permalink
Introduce VERIFY_AND_CLEAR shorthand (qmk#19370)
Browse files Browse the repository at this point in the history
Which is just a syntactic sugar for
testing::Mock::VerifyAndClearExpectations to reduce the visual clutter
in unit-tests.
  • Loading branch information
KarlK90 authored and omikronik committed Jan 22, 2023
1 parent 319b6df commit f069bf2
Show file tree
Hide file tree
Showing 21 changed files with 257 additions and 251 deletions.
8 changes: 4 additions & 4 deletions tests/auto_shift/test_auto_shift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -58,13 +58,13 @@ 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));
EXPECT_REPORT(driver, (KC_LSFT));
EXPECT_EMPTY_REPORT(driver);
regular_key.release();
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
}
12 changes: 6 additions & 6 deletions tests/autocorrect/test_autocorrect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
66 changes: 33 additions & 33 deletions tests/basic/test_action_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ TEST_F(ActionLayer, LayerStateDBG) {

layer_state_set(0);

testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
}

TEST_F(ActionLayer, LayerStateSet) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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. */
Expand All @@ -382,20 +382,20 @@ 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);
EXPECT_EMPTY_REPORT(driver);
layer_1_key_1.release();
run_one_scan_loop();
EXPECT_TRUE(layer_state_is(0));
testing::Mock::VerifyAndClearExpectations(&driver);
VERIFY_AND_CLEAR(driver);
}
Loading

0 comments on commit f069bf2

Please sign in to comment.