Skip to content

Commit

Permalink
Report keycodes instead of matrix position in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlK90 committed May 8, 2022
1 parent 475a2c9 commit 7e4d888
Show file tree
Hide file tree
Showing 21 changed files with 394 additions and 133 deletions.
1 change: 1 addition & 0 deletions builddefs/build_full_test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ $(TEST)_SRC := \
tests/test_common/matrix.c \
tests/test_common/test_driver.cpp \
tests/test_common/keyboard_report_util.cpp \
tests/test_common/keycode_util.cpp \
tests/test_common/test_fixture.cpp \
tests/test_common/test_keymap_key.cpp \
tests/test_common/test_logger.cpp \
Expand Down
6 changes: 3 additions & 3 deletions tests/auto_shift/test_auto_shift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AutoShift : public TestFixture {};
TEST_F(AutoShift, key_release_before_timeout) {
TestDriver driver;
InSequence s;
auto regular_key = KeymapKey(0, 2, 0, KC_A);
auto regular_key = KEYMAP_KEY(0, 2, 0, KC_A);

set_keymap({regular_key});

Expand All @@ -50,7 +50,7 @@ TEST_F(AutoShift, key_release_before_timeout) {
TEST_F(AutoShift, key_release_after_timeout) {
TestDriver driver;
InSequence s;
auto regular_key = KeymapKey(0, 2, 0, KC_A);
auto regular_key = KEYMAP_KEY(0, 2, 0, KC_A);

set_keymap({regular_key});

Expand All @@ -67,4 +67,4 @@ TEST_F(AutoShift, key_release_after_timeout) {
regular_key.release();
run_one_scan_loop();
testing::Mock::VerifyAndClearExpectations(&driver);
}
}
32 changes: 16 additions & 16 deletions tests/basic/test_action_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ TEST_F(ActionLayer, LayerOff) {

TEST_F(ActionLayer, MomentaryLayerDoesNothing) {
TestDriver driver;
KeymapKey layer_key = KeymapKey{0, 0, 0, MO(1)};
auto layer_key = KEYMAP_KEY(0, 0, 0, MO(1));

set_keymap({layer_key});

Expand All @@ -144,11 +144,11 @@ TEST_F(ActionLayer, MomentaryLayerDoesNothing) {

TEST_F(ActionLayer, MomentaryLayerWithKeypress) {
TestDriver driver;
KeymapKey layer_key = KeymapKey{0, 0, 0, MO(1)};
auto layer_key = KEYMAP_KEY(0, 0, 0, MO(1));

/* These keys must have the same position in the matrix, only the layer is different. */
KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A};
set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}});
auto regular_key = KEYMAP_KEY(0, 1, 0, KC_A);
set_keymap({layer_key, regular_key, KEYMAP_KEY(1, 1, 0, KC_B)});

/* Press MO. */
EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
Expand Down Expand Up @@ -183,7 +183,7 @@ TEST_F(ActionLayer, ToggleLayerDoesNothing) {
GTEST_SKIP() << "TODO: Toggle layer does not activate the expected layer on key press but on release.";

TestDriver driver;
KeymapKey layer_key = KeymapKey{0, 0, 0, TG(1)};
auto layer_key = KEYMAP_KEY(0, 0, 0, TG(1));

set_keymap({layer_key});

Expand All @@ -206,8 +206,8 @@ TEST_F(ActionLayer, ToggleLayerUpAndDown) {
GTEST_SKIP() << "TODO: Toggle layer does not activate the expected layer on key press but on release.";

TestDriver driver;
KeymapKey toggle_layer_1_on_layer_0 = KeymapKey{0, 0, 0, TG(1)};
KeymapKey toggle_layer_0_on_layer_1 = KeymapKey{1, 1, 0, TG(0)};
auto toggle_layer_1_on_layer_0 = KEYMAP_KEY(0, 0, 0, TG(1));
auto toggle_layer_0_on_layer_1 = KEYMAP_KEY(1, 1, 0, TG(0));

set_keymap({toggle_layer_1_on_layer_0, toggle_layer_0_on_layer_1});

Expand Down Expand Up @@ -242,7 +242,7 @@ TEST_F(ActionLayer, LayerTapToggleDoesNothing) {
GTEST_SKIP() << "TODO: Tap toggle layer does not activate the expected layer on key press.";

TestDriver driver;
KeymapKey layer_key = KeymapKey{0, 0, 0, TT(1)};
auto layer_key = KEYMAP_KEY(0, 0, 0, TT(1));

set_keymap({layer_key});

Expand All @@ -264,11 +264,11 @@ TEST_F(ActionLayer, LayerTapToggleWithKeypress) {
GTEST_SKIP() << "TODO: Tap toggle layer does not activate the expected layer on key press.";

TestDriver driver;
KeymapKey layer_key = KeymapKey{0, 0, 0, TT(1)};
auto layer_key = KEYMAP_KEY(0, 0, 0, TT(1));

/* These keys must have the same position in the matrix, only the layer is different. */
KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A};
set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}});
auto regular_key = KEYMAP_KEY(0, 1, 0, KC_A);
set_keymap({layer_key, regular_key, KEYMAP_KEY(1, 1, 0, KC_B)});

/* Press TT. */
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(0);
Expand Down Expand Up @@ -300,11 +300,11 @@ TEST_F(ActionLayer, LayerTapToggleWithToggleWithKeypress) {
GTEST_SKIP() << "TODO: Tap toggle layer does not activate the expected layer on key press.";

TestDriver driver;
KeymapKey layer_key = KeymapKey{0, 0, 0, TT(1)};
auto layer_key = KEYMAP_KEY(0, 0, 0, TT(1));

/* These keys must have the same position in the matrix, only the layer is different. */
KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A};
set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}});
auto regular_key = KEYMAP_KEY(0, 1, 0, KC_A);
set_keymap({layer_key, regular_key, KEYMAP_KEY(1, 1, 0, KC_B)});

/* Tap TT five times . */
EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0);
Expand Down Expand Up @@ -364,8 +364,8 @@ TEST_F(ActionLayer, LayerTapReleasedBeforeKeypressReleaseWithModifiers) {
TestDriver driver;
InSequence s;

KeymapKey layer_0_key_0 = KeymapKey{0, 0, 0, LT(1, KC_T)};
KeymapKey layer_1_key_1 = KeymapKey{1, 1, 0, RALT(KC_9)};
auto layer_0_key_0 = KEYMAP_KEY(0, 0, 0, LT(1, KC_T));
auto layer_1_key_1 = KEYMAP_KEY(1, 1, 0, RALT(KC_9));

set_keymap({layer_0_key_0, layer_1_key_1});

Expand Down
38 changes: 19 additions & 19 deletions tests/basic/test_keypress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) {

TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) {
TestDriver driver;
auto key = KeymapKey(0, 0, 0, KC_A);
auto key = KEYMAP_KEY(0, 0, 0, KC_A);

set_keymap({key});

Expand All @@ -45,7 +45,7 @@ TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) {

TEST_F(KeyPress, ANonMappedKeyDoesNothing) {
TestDriver driver;
auto key = KeymapKey(0, 0, 0, KC_NO);
auto key = KEYMAP_KEY(0, 0, 0, KC_NO);

set_keymap({key});

Expand All @@ -57,8 +57,8 @@ TEST_F(KeyPress, ANonMappedKeyDoesNothing) {

TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) {
TestDriver driver;
auto key_b = KeymapKey(0, 0, 0, KC_B);
auto key_c = KeymapKey(0, 1, 1, KC_C);
auto key_b = KEYMAP_KEY(0, 0, 0, KC_B);
auto key_c = KEYMAP_KEY(0, 1, 1, KC_C);

set_keymap({key_b, key_c});

Expand All @@ -84,8 +84,8 @@ TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) {

TEST_F(KeyPress, LeftShiftIsReportedCorrectly) {
TestDriver driver;
auto key_a = KeymapKey(0, 0, 0, KC_A);
auto key_lsft = KeymapKey(0, 3, 0, KC_LEFT_SHIFT);
auto key_a = KEYMAP_KEY(0, 0, 0, KC_A);
auto key_lsft = KEYMAP_KEY(0, 3, 0, KC_LEFT_SHIFT);

set_keymap({key_a, key_lsft});

Expand All @@ -110,8 +110,8 @@ TEST_F(KeyPress, LeftShiftIsReportedCorrectly) {

TEST_F(KeyPress, PressLeftShiftAndControl) {
TestDriver driver;
auto key_lsft = KeymapKey(0, 3, 0, KC_LEFT_SHIFT);
auto key_lctrl = KeymapKey(0, 5, 0, KC_LEFT_CTRL);
auto key_lsft = KEYMAP_KEY(0, 3, 0, KC_LEFT_SHIFT);
auto key_lctrl = KEYMAP_KEY(0, 5, 0, KC_LEFT_CTRL);

set_keymap({key_lctrl, key_lsft});

Expand All @@ -138,8 +138,8 @@ TEST_F(KeyPress, PressLeftShiftAndControl) {

TEST_F(KeyPress, LeftAndRightShiftCanBePressedAtTheSameTime) {
TestDriver driver;
auto key_lsft = KeymapKey(0, 3, 0, KC_LEFT_SHIFT);
auto key_rsft = KeymapKey(0, 4, 0, KC_RIGHT_SHIFT);
auto key_lsft = KEYMAP_KEY(0, 3, 0, KC_LEFT_SHIFT);
auto key_rsft = KEYMAP_KEY(0, 4, 0, KC_RIGHT_SHIFT);

set_keymap({key_rsft, key_lsft});

Expand All @@ -165,7 +165,7 @@ TEST_F(KeyPress, LeftAndRightShiftCanBePressedAtTheSameTime) {

TEST_F(KeyPress, RightShiftLeftControlAndCharWithTheSameKey) {
TestDriver driver;
auto combo_key = KeymapKey(0, 0, 0, RSFT(LCTL(KC_O)));
auto combo_key = KEYMAP_KEY(0, 0, 0, RSFT(LCTL(KC_O)));

set_keymap({combo_key});

Expand All @@ -188,8 +188,8 @@ TEST_F(KeyPress, RightShiftLeftControlAndCharWithTheSameKey) {
TEST_F(KeyPress, PressPlusEqualReleaseBeforePress) {
TestDriver driver;
InSequence s;
auto key_plus = KeymapKey(0, 1, 1, KC_PLUS);
auto key_eql = KeymapKey(0, 0, 1, KC_EQUAL);
auto key_plus = KEYMAP_KEY(0, 1, 1, KC_PLUS);
auto key_eql = KEYMAP_KEY(0, 0, 1, KC_EQUAL);

set_keymap({key_plus, key_eql});

Expand Down Expand Up @@ -219,8 +219,8 @@ TEST_F(KeyPress, PressPlusEqualReleaseBeforePress) {
TEST_F(KeyPress, PressPlusEqualDontReleaseBeforePress) {
TestDriver driver;
InSequence s;
auto key_plus = KeymapKey(0, 1, 1, KC_PLUS);
auto key_eql = KeymapKey(0, 0, 1, KC_EQUAL);
auto key_plus = KEYMAP_KEY(0, 1, 1, KC_PLUS);
auto key_eql = KEYMAP_KEY(0, 0, 1, KC_EQUAL);

set_keymap({key_plus, key_eql});

Expand Down Expand Up @@ -251,8 +251,8 @@ TEST_F(KeyPress, PressPlusEqualDontReleaseBeforePress) {
TEST_F(KeyPress, PressEqualPlusReleaseBeforePress) {
TestDriver driver;
InSequence s;
auto key_plus = KeymapKey(0, 1, 1, KC_PLUS);
auto key_eql = KeymapKey(0, 0, 1, KC_EQUAL);
auto key_plus = KEYMAP_KEY(0, 1, 1, KC_PLUS);
auto key_eql = KEYMAP_KEY(0, 0, 1, KC_EQUAL);

set_keymap({key_plus, key_eql});

Expand Down Expand Up @@ -282,8 +282,8 @@ TEST_F(KeyPress, PressEqualPlusReleaseBeforePress) {
TEST_F(KeyPress, PressEqualPlusDontReleaseBeforePress) {
TestDriver driver;
InSequence s;
auto key_plus = KeymapKey(0, 1, 1, KC_PLUS);
auto key_eql = KeymapKey(0, 0, 1, KC_EQUAL);
auto key_plus = KEYMAP_KEY(0, 1, 1, KC_PLUS);
auto key_eql = KEYMAP_KEY(0, 0, 1, KC_EQUAL);

set_keymap({key_plus, key_eql});

Expand Down
34 changes: 17 additions & 17 deletions tests/basic/test_one_shot_keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class OneShotParametrizedTestFixture : public ::testing::WithParamInterface<std:

TEST_F(OneShot, OSMWithoutAdditionalKeypressDoesNothing) {
TestDriver driver;
auto osm_key = KeymapKey(0, 0, 0, OSM(MOD_LSFT), KC_LSFT);
auto osm_key = KEYMAP_KEY_EXPLICIT_REPORT_CODE(0, 0, 0, OSM(MOD_LSFT), KC_LSFT);

set_keymap({osm_key});

Expand All @@ -51,8 +51,8 @@ TEST_F(OneShot, OSMWithoutAdditionalKeypressDoesNothing) {

TEST_P(OneShotParametrizedTestFixture, OSMExpiredDoesNothing) {
TestDriver driver;
KeymapKey osm_key = GetParam().first;
KeymapKey regular_key = GetParam().second;
auto osm_key = GetParam().first;
auto regular_key = GetParam().second;

set_keymap({osm_key, regular_key});

Expand Down Expand Up @@ -81,8 +81,8 @@ TEST_P(OneShotParametrizedTestFixture, OSMExpiredDoesNothing) {

TEST_P(OneShotParametrizedTestFixture, OSMWithAdditionalKeypress) {
TestDriver driver;
KeymapKey osm_key = GetParam().first;
KeymapKey regular_key = GetParam().second;
auto osm_key = GetParam().first;
auto regular_key = GetParam().second;

set_keymap({osm_key, regular_key});

Expand Down Expand Up @@ -111,8 +111,8 @@ TEST_P(OneShotParametrizedTestFixture, OSMAsRegularModifierWithAdditionalKeypres
TestDriver driver;
testing::InSequence s;

KeymapKey osm_key = GetParam().first;
KeymapKey regular_key = GetParam().second;
auto osm_key = GetParam().first;
auto regular_key = GetParam().second;

set_keymap({osm_key, regular_key});

Expand Down Expand Up @@ -149,22 +149,22 @@ INSTANTIATE_TEST_CASE_P(
OneShotParametrizedTestFixture,
::testing::Values(
/* first is osm key, second is regular key. */
std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_LSFT), KC_LSFT}, KeymapKey{0, 1, 1, KC_A}),
std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_LCTL), KC_LCTL}, KeymapKey{0, 1, 1, KC_A}),
std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_LALT), KC_LALT}, KeymapKey{0, 1, 1, KC_A}),
std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_LGUI), KC_LGUI}, KeymapKey{0, 1, 1, KC_A}),
std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_RCTL), KC_RCTL}, KeymapKey{0, 1, 1, KC_A}),
std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_RSFT), KC_RSFT}, KeymapKey{0, 1, 1, KC_A}),
std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_RALT), KC_RALT}, KeymapKey{0, 1, 1, KC_A}),
std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_RGUI), KC_RGUI}, KeymapKey{0, 1, 1, KC_A})
std::make_pair(KEYMAP_KEY_EXPLICIT_REPORT_CODE(0, 0, 0, OSM(MOD_LSFT), KC_LSFT), KEYMAP_KEY(0, 1, 1, KC_A)),
std::make_pair(KEYMAP_KEY_EXPLICIT_REPORT_CODE(0, 0, 0, OSM(MOD_LCTL), KC_LCTL), KEYMAP_KEY(0, 1, 1, KC_A)),
std::make_pair(KEYMAP_KEY_EXPLICIT_REPORT_CODE(0, 0, 0, OSM(MOD_LALT), KC_LALT), KEYMAP_KEY(0, 1, 1, KC_A)),
std::make_pair(KEYMAP_KEY_EXPLICIT_REPORT_CODE(0, 0, 0, OSM(MOD_LGUI), KC_LGUI), KEYMAP_KEY(0, 1, 1, KC_A)),
std::make_pair(KEYMAP_KEY_EXPLICIT_REPORT_CODE(0, 0, 0, OSM(MOD_RCTL), KC_RCTL), KEYMAP_KEY(0, 1, 1, KC_A)),
std::make_pair(KEYMAP_KEY_EXPLICIT_REPORT_CODE(0, 0, 0, OSM(MOD_RSFT), KC_RSFT), KEYMAP_KEY(0, 1, 1, KC_A)),
std::make_pair(KEYMAP_KEY_EXPLICIT_REPORT_CODE(0, 0, 0, OSM(MOD_RALT), KC_RALT), KEYMAP_KEY(0, 1, 1, KC_A)),
std::make_pair(KEYMAP_KEY_EXPLICIT_REPORT_CODE(0, 0, 0, OSM(MOD_RGUI), KC_RGUI), KEYMAP_KEY(0, 1, 1, KC_A))
));
// clang-format on

TEST_F(OneShot, OSLWithAdditionalKeypress) {
TestDriver driver;
InSequence s;
KeymapKey osl_key = KeymapKey{0, 0, 0, OSL(1)};
KeymapKey regular_key = KeymapKey{1, 1, 0, KC_A};
auto osl_key = KEYMAP_KEY(0, 0, 0, OSL(1));
auto regular_key = KEYMAP_KEY(1, 1, 0, KC_A);

set_keymap({osl_key, regular_key});

Expand Down
8 changes: 4 additions & 4 deletions tests/basic/test_tapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Tapping : public TestFixture {};
TEST_F(Tapping, TapA_SHFT_T_KeyReportsKey) {
TestDriver driver;
InSequence s;
auto key_shift_hold_p_tap = KeymapKey(0, 7, 0, SFT_T(KC_P));
auto key_shift_hold_p_tap = KEYMAP_KEY(0, 7, 0, SFT_T(KC_P));

set_keymap({key_shift_hold_p_tap});

Expand All @@ -49,7 +49,7 @@ TEST_F(Tapping, TapA_SHFT_T_KeyReportsKey) {
TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) {
TestDriver driver;
InSequence s;
auto mod_tap_hold_key = KeymapKey(0, 7, 0, SFT_T(KC_P));
auto mod_tap_hold_key = KEYMAP_KEY(0, 7, 0, SFT_T(KC_P));

set_keymap({mod_tap_hold_key});

Expand All @@ -71,7 +71,7 @@ TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) {
// See issue #1478 for more information
TestDriver driver;
InSequence s;
auto key_shift_hold_p_tap = KeymapKey(0, 7, 0, SFT_T(KC_P));
auto key_shift_hold_p_tap = KEYMAP_KEY(0, 7, 0, SFT_T(KC_P));

set_keymap({key_shift_hold_p_tap});

Expand Down Expand Up @@ -120,4 +120,4 @@ TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) {
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport()));
key_shift_hold_p_tap.release();
run_one_scan_loop();
}
}
Loading

0 comments on commit 7e4d888

Please sign in to comment.