diff options
author | Stefan Kerkmann <karlk90@pm.me> | 2021-11-23 03:31:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-23 13:31:01 +1100 |
commit | a24bdccee0580d1263733bc7e66e4e4f97713f19 (patch) | |
tree | 868cb12a436a87b39c936292f442bcc266ae0224 | |
parent | e20bc76a1e05d02c15a452e51fa76d9ec39b0369 (diff) | |
download | qmk_firmware-a24bdccee0580d1263733bc7e66e4e4f97713f19.tar.gz qmk_firmware-a24bdccee0580d1263733bc7e66e4e4f97713f19.zip |
[Tests] Increase QMK test coverage take 2 (#15269)
* Add per-test keymaps
* Add better trace and info logs for failed unit-tests
* Add layer state assertion with tracing message
* Use individual test binaries configuration options
* Add basic qmk functionality tests
* Add tap hold configurations tests
* Add auto shift tests
Co-authored-by: Nick Brassel <nick@tzarc.org>
48 files changed, 2703 insertions, 246 deletions
@@ -378,11 +378,12 @@ define PARSE_ALL_KEYMAPS | |||
378 | endef | 378 | endef |
379 | 379 | ||
380 | define BUILD_TEST | 380 | define BUILD_TEST |
381 | TEST_NAME := $1 | 381 | TEST_PATH := $1 |
382 | TEST_NAME := $$(notdir $$(TEST_PATH)) | ||
382 | MAKE_TARGET := $2 | 383 | MAKE_TARGET := $2 |
383 | COMMAND := $1 | 384 | COMMAND := $1 |
384 | MAKE_CMD := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_test.mk $$(MAKE_TARGET) | 385 | MAKE_CMD := $$(MAKE) -r -R -C $(ROOT_DIR) -f build_test.mk $$(MAKE_TARGET) |
385 | MAKE_VARS := TEST=$$(TEST_NAME) FULL_TESTS="$$(FULL_TESTS)" | 386 | MAKE_VARS := TEST=$$(TEST_NAME) TEST_PATH=$$(TEST_PATH) FULL_TESTS="$$(FULL_TESTS)" |
386 | MAKE_MSG := $$(MSG_MAKE_TEST) | 387 | MAKE_MSG := $$(MSG_MAKE_TEST) |
387 | $$(eval $$(call BUILD)) | 388 | $$(eval $$(call BUILD)) |
388 | ifneq ($$(MAKE_TARGET),clean) | 389 | ifneq ($$(MAKE_TARGET),clean) |
@@ -406,7 +407,7 @@ define PARSE_TEST | |||
406 | ifeq ($$(TEST_NAME),all) | 407 | ifeq ($$(TEST_NAME),all) |
407 | MATCHED_TESTS := $$(TEST_LIST) | 408 | MATCHED_TESTS := $$(TEST_LIST) |
408 | else | 409 | else |
409 | MATCHED_TESTS := $$(foreach TEST,$$(TEST_LIST),$$(if $$(findstring $$(TEST_NAME),$$(TEST)),$$(TEST),)) | 410 | MATCHED_TESTS := $$(foreach TEST, $$(TEST_LIST),$$(if $$(findstring $$(TEST_NAME), $$(notdir $$(TEST))), $$(TEST),)) |
410 | endif | 411 | endif |
411 | $$(foreach TEST,$$(MATCHED_TESTS),$$(eval $$(call BUILD_TEST,$$(TEST),$$(TEST_TARGET)))) | 412 | $$(foreach TEST,$$(MATCHED_TESTS),$$(eval $$(call BUILD_TEST,$$(TEST),$$(TEST_TARGET)))) |
412 | endef | 413 | endef |
diff --git a/build_full_test.mk b/build_full_test.mk index f8030cb06..4cd1ac61b 100644 --- a/build_full_test.mk +++ b/build_full_test.mk | |||
@@ -13,21 +13,24 @@ | |||
13 | # You should have received a copy of the GNU General Public License | 13 | # You should have received a copy of the GNU General Public License |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | 15 | ||
16 | #include $(TMK_PATH)/protocol.mk | 16 | $(TEST)_INC := \ |
17 | tests\test_common\common_config.h | ||
17 | 18 | ||
18 | TEST_PATH=tests/$(TEST) | 19 | $(TEST)_SRC := \ |
19 | |||
20 | $(TEST)_SRC= \ | ||
21 | $(TEST_PATH)/keymap.c \ | ||
22 | $(TMK_COMMON_SRC) \ | 20 | $(TMK_COMMON_SRC) \ |
23 | $(QUANTUM_SRC) \ | 21 | $(QUANTUM_SRC) \ |
24 | $(SRC) \ | 22 | $(SRC) \ |
23 | tests/test_common/keymap.c \ | ||
25 | tests/test_common/matrix.c \ | 24 | tests/test_common/matrix.c \ |
26 | tests/test_common/test_driver.cpp \ | 25 | tests/test_common/test_driver.cpp \ |
27 | tests/test_common/keyboard_report_util.cpp \ | 26 | tests/test_common/keyboard_report_util.cpp \ |
28 | tests/test_common/test_fixture.cpp | 27 | tests/test_common/test_fixture.cpp \ |
29 | $(TEST)_SRC += $(patsubst $(ROOTDIR)/%,%,$(wildcard $(TEST_PATH)/*.cpp)) | 28 | tests/test_common/test_keymap_key.cpp \ |
29 | tests/test_common/test_logger.cpp \ | ||
30 | $(patsubst $(ROOTDIR)/%,%,$(wildcard $(TEST_PATH)/*.cpp)) | ||
31 | |||
32 | $(TEST)_DEFS := $(TMK_COMMON_DEFS) $(OPT_DEFS) | ||
33 | |||
34 | $(TEST)_CONFIG := $(TEST_PATH)/config.h | ||
30 | 35 | ||
31 | $(TEST)_DEFS=$(TMK_COMMON_DEFS) $(OPT_DEFS) | 36 | VPATH += $(TOP_DIR)/tests/test_common \ No newline at end of file |
32 | $(TEST)_CONFIG=$(TEST_PATH)/config.h | ||
33 | VPATH+=$(TOP_DIR)/tests/test_common | ||
diff --git a/build_test.mk b/build_test.mk index 36cb7936e..136a0455f 100644 --- a/build_test.mk +++ b/build_test.mk | |||
@@ -16,14 +16,14 @@ TEST_OBJ = $(BUILD_DIR)/test_obj | |||
16 | OUTPUTS := $(TEST_OBJ)/$(TEST) $(GTEST_OUTPUT) | 16 | OUTPUTS := $(TEST_OBJ)/$(TEST) $(GTEST_OUTPUT) |
17 | 17 | ||
18 | GTEST_INC := \ | 18 | GTEST_INC := \ |
19 | $(LIB_PATH)/googletest/googletest/include\ | 19 | $(LIB_PATH)/googletest/googletest/include \ |
20 | $(LIB_PATH)/googletest/googlemock/include\ | 20 | $(LIB_PATH)/googletest/googlemock/include |
21 | 21 | ||
22 | GTEST_INTERNAL_INC :=\ | 22 | GTEST_INTERNAL_INC := \ |
23 | $(LIB_PATH)/googletest/googletest\ | 23 | $(LIB_PATH)/googletest/googletest \ |
24 | $(LIB_PATH)/googletest/googlemock | 24 | $(LIB_PATH)/googletest/googlemock |
25 | 25 | ||
26 | $(GTEST_OUTPUT)_SRC :=\ | 26 | $(GTEST_OUTPUT)_SRC := \ |
27 | googletest/src/gtest-all.cc\ | 27 | googletest/src/gtest-all.cc\ |
28 | googlemock/src/gmock-all.cc | 28 | googlemock/src/gmock-all.cc |
29 | 29 | ||
@@ -33,9 +33,9 @@ $(GTEST_OUTPUT)_INC := $(GTEST_INC) $(GTEST_INTERNAL_INC) | |||
33 | LDFLAGS += -lstdc++ -lpthread -shared-libgcc | 33 | LDFLAGS += -lstdc++ -lpthread -shared-libgcc |
34 | CREATE_MAP := no | 34 | CREATE_MAP := no |
35 | 35 | ||
36 | VPATH +=\ | 36 | VPATH += \ |
37 | $(LIB_PATH)/googletest\ | 37 | $(LIB_PATH)/googletest \ |
38 | $(LIB_PATH)/googlemock\ | 38 | $(LIB_PATH)/googlemock \ |
39 | $(LIB_PATH)/printf | 39 | $(LIB_PATH)/printf |
40 | 40 | ||
41 | all: elf | 41 | all: elf |
@@ -49,7 +49,8 @@ CONSOLE_ENABLE = yes | |||
49 | endif | 49 | endif |
50 | 50 | ||
51 | ifneq ($(filter $(FULL_TESTS),$(TEST)),) | 51 | ifneq ($(filter $(FULL_TESTS),$(TEST)),) |
52 | include tests/$(TEST)/rules.mk | 52 | include tests/test_common/build.mk |
53 | include $(TEST_PATH)/test.mk | ||
53 | endif | 54 | endif |
54 | 55 | ||
55 | include common_features.mk | 56 | include common_features.mk |
diff --git a/testlist.mk b/testlist.mk index cff784dad..d2bb571be 100644 --- a/testlist.mk +++ b/testlist.mk | |||
@@ -1,5 +1,5 @@ | |||
1 | TEST_LIST = $(notdir $(patsubst %/rules.mk,%,$(wildcard $(ROOT_DIR)/tests/*/rules.mk))) | 1 | TEST_LIST = $(sort $(patsubst %/test.mk,%, $(shell find $(ROOT_DIR)tests -type f -name test.mk))) |
2 | FULL_TESTS := $(TEST_LIST) | 2 | FULL_TESTS := $(notdir $(TEST_LIST)) |
3 | 3 | ||
4 | include $(QUANTUM_PATH)/debounce/tests/testlist.mk | 4 | include $(QUANTUM_PATH)/debounce/tests/testlist.mk |
5 | include $(QUANTUM_PATH)/encoder/tests/testlist.mk | 5 | include $(QUANTUM_PATH)/encoder/tests/testlist.mk |
diff --git a/tests/auto_shift/config.h b/tests/auto_shift/config.h new file mode 100644 index 000000000..4f343b452 --- /dev/null +++ b/tests/auto_shift/config.h | |||
@@ -0,0 +1,19 @@ | |||
1 | /* Copyright 2021 Stefan Kerkmann | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #pragma once | ||
18 | |||
19 | #include "test_common.h" \ No newline at end of file | ||
diff --git a/tests/auto_shift/test.mk b/tests/auto_shift/test.mk new file mode 100644 index 000000000..4259c606e --- /dev/null +++ b/tests/auto_shift/test.mk | |||
@@ -0,0 +1,20 @@ | |||
1 | # Copyright 2021 Stefan Kerkmann | ||
2 | # | ||
3 | # This program is free software: you can redistribute it and/or modify | ||
4 | # it under the terms of the GNU General Public License as published by | ||
5 | # the Free Software Foundation, either version 2 of the License, or | ||
6 | # (at your option) any later version. | ||
7 | # | ||
8 | # This program is distributed in the hope that it will be useful, | ||
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | # GNU General Public License for more details. | ||
12 | # | ||
13 | # You should have received a copy of the GNU General Public License | ||
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | |||
16 | # -------------------------------------------------------------------------------- | ||
17 | # Keep this file, even if it is empty, as a marker that this folder contains tests | ||
18 | # -------------------------------------------------------------------------------- | ||
19 | |||
20 | AUTO_SHIFT_ENABLE = yes \ No newline at end of file | ||
diff --git a/tests/auto_shift/test_auto_shift.cpp b/tests/auto_shift/test_auto_shift.cpp new file mode 100644 index 000000000..9c5ed9a83 --- /dev/null +++ b/tests/auto_shift/test_auto_shift.cpp | |||
@@ -0,0 +1,73 @@ | |||
1 | /* Copyright 2021 Stefan Kerkmann | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include "keyboard_report_util.hpp" | ||
18 | #include "keycode.h" | ||
19 | #include "test_common.hpp" | ||
20 | #include "action_tapping.h" | ||
21 | #include "test_fixture.hpp" | ||
22 | #include "test_keymap_key.hpp" | ||
23 | |||
24 | using testing::_; | ||
25 | using testing::InSequence; | ||
26 | |||
27 | class AutoShift : public TestFixture {}; | ||
28 | |||
29 | TEST_F(AutoShift, key_release_before_timeout) { | ||
30 | TestDriver driver; | ||
31 | InSequence s; | ||
32 | auto regular_key = KeymapKey(0, 2, 0, KC_A); | ||
33 | |||
34 | set_keymap({regular_key}); | ||
35 | |||
36 | /* Press regular key */ | ||
37 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
38 | regular_key.press(); | ||
39 | run_one_scan_loop(); | ||
40 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
41 | |||
42 | /* Release regular key */ | ||
43 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); | ||
44 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
45 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
46 | regular_key.release(); | ||
47 | run_one_scan_loop(); | ||
48 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
49 | } | ||
50 | |||
51 | TEST_F(AutoShift, key_release_after_timeout) { | ||
52 | TestDriver driver; | ||
53 | InSequence s; | ||
54 | auto regular_key = KeymapKey(0, 2, 0, KC_A); | ||
55 | |||
56 | set_keymap({regular_key}); | ||
57 | |||
58 | /* Press regular key */ | ||
59 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
60 | regular_key.press(); | ||
61 | idle_for(AUTO_SHIFT_TIMEOUT); | ||
62 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
63 | |||
64 | /* Release regular key */ | ||
65 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_A))); | ||
66 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
67 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
68 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
69 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
70 | regular_key.release(); | ||
71 | run_one_scan_loop(); | ||
72 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
73 | } \ No newline at end of file | ||
diff --git a/tests/basic/config.h b/tests/basic/config.h index 99bd62d99..85fa9d691 100644 --- a/tests/basic/config.h +++ b/tests/basic/config.h | |||
@@ -16,5 +16,4 @@ | |||
16 | 16 | ||
17 | #pragma once | 17 | #pragma once |
18 | 18 | ||
19 | #define MATRIX_ROWS 4 | 19 | #include "test_common.h" \ No newline at end of file |
20 | #define MATRIX_COLS 10 | ||
diff --git a/tests/basic/keymap.c b/tests/basic/keymap.c deleted file mode 100644 index 2b5747abb..000000000 --- a/tests/basic/keymap.c +++ /dev/null | |||
@@ -1,45 +0,0 @@ | |||
1 | /* Copyright 2017 Fred Sundvik | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include "quantum.h" | ||
18 | |||
19 | // Don't rearrange keys as existing tests might rely on the order | ||
20 | // Col2, Row 0 has to be KC_NO, because tests rely on it | ||
21 | |||
22 | #define COMBO1 RSFT(LCTL(KC_O)) | ||
23 | |||
24 | const uint16_t PROGMEM | ||
25 | keymaps[][MATRIX_ROWS][MATRIX_COLS] = | ||
26 | { | ||
27 | [0] = | ||
28 | { | ||
29 | // 0 1 2 3 4 5 6 7 8 9 | ||
30 | {KC_A, KC_B, KC_NO, KC_LSFT, KC_RSFT, KC_LCTL, COMBO1, SFT_T(KC_P), M(0), KC_NO}, | ||
31 | {KC_EQL, KC_PLUS, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, | ||
32 | {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, | ||
33 | {KC_C, KC_D, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, | ||
34 | }, | ||
35 | }; | ||
36 | |||
37 | const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { | ||
38 | if (record->event.pressed) { | ||
39 | switch (id) { | ||
40 | case 0: | ||
41 | return MACRO(D(LSFT), T(H), U(LSFT), T(E), T(L), T(L), T(O), T(SPACE), W(100), D(LSFT), T(W), U(LSFT), I(10), T(O), T(R), T(L), T(D), D(LSFT), T(1), U(LSFT), END); | ||
42 | } | ||
43 | } | ||
44 | return MACRO_NONE; | ||
45 | }; | ||
diff --git a/tests/basic/test.mk b/tests/basic/test.mk new file mode 100644 index 000000000..29690d1ad --- /dev/null +++ b/tests/basic/test.mk | |||
@@ -0,0 +1,18 @@ | |||
1 | # Copyright 2017 Fred Sundvik | ||
2 | # | ||
3 | # This program is free software: you can redistribute it and/or modify | ||
4 | # it under the terms of the GNU General Public License as published by | ||
5 | # the Free Software Foundation, either version 2 of the License, or | ||
6 | # (at your option) any later version. | ||
7 | # | ||
8 | # This program is distributed in the hope that it will be useful, | ||
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | # GNU General Public License for more details. | ||
12 | # | ||
13 | # You should have received a copy of the GNU General Public License | ||
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | |||
16 | # -------------------------------------------------------------------------------- | ||
17 | # Keep this file, even if it is empty, as a marker that this folder contains tests | ||
18 | # -------------------------------------------------------------------------------- \ No newline at end of file | ||
diff --git a/tests/basic/test_action_layer.cpp b/tests/basic/test_action_layer.cpp index d00a0859b..1b12d1364 100644 --- a/tests/basic/test_action_layer.cpp +++ b/tests/basic/test_action_layer.cpp | |||
@@ -14,39 +14,54 @@ | |||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include "gtest/gtest.h" | ||
18 | #include "keyboard_report_util.hpp" | ||
17 | #include "test_common.hpp" | 19 | #include "test_common.hpp" |
18 | 20 | ||
19 | using testing::_; | 21 | using testing::_; |
20 | using testing::Return; | 22 | using testing::InSequence; |
21 | 23 | ||
22 | class ActionLayer : public TestFixture {}; | 24 | class ActionLayer : public TestFixture {}; |
23 | 25 | ||
24 | // TEST_F(ActionLayer, LayerStateDBG) { | 26 | TEST_F(ActionLayer, LayerStateDBG) { |
25 | // layer_state_set(0); | 27 | TestDriver driver; |
26 | // } | 28 | |
27 | 29 | layer_state_set(0); | |
28 | // TEST_F(ActionLayer, LayerStateSet) { | 30 | |
29 | // layer_state_set(0); | 31 | testing::Mock::VerifyAndClearExpectations(&driver); |
30 | // EXPECT_EQ(layer_state, 0); | 32 | } |
31 | // layer_state_set(0b001100); | 33 | |
32 | // EXPECT_EQ(layer_state, 0b001100); | 34 | TEST_F(ActionLayer, LayerStateSet) { |
33 | // } | 35 | TestDriver driver; |
34 | 36 | ||
35 | // TEST_F(ActionLayer, LayerStateIs) { | 37 | layer_state_set(0); |
36 | // layer_state_set(0); | 38 | EXPECT_EQ(layer_state, 0); |
37 | // EXPECT_EQ(layer_state_is(0), true); | 39 | layer_state_set(0b001100); |
38 | // EXPECT_EQ(layer_state_is(1), true); | 40 | EXPECT_EQ(layer_state, 0b001100); |
39 | // layer_state_set(1); | 41 | |
40 | // EXPECT_EQ(layer_state_is(0), true); | 42 | testing::Mock::VerifyAndClearExpectations(&driver); |
41 | // EXPECT_EQ(layer_state_is(1), true); | 43 | } |
42 | // layer_state_set(2); | 44 | |
43 | // EXPECT_EQ(layer_state_is(0), false); | 45 | TEST_F(ActionLayer, LayerStateIs) { |
44 | // EXPECT_EQ(layer_state_is(1), false); | 46 | TestDriver driver; |
45 | // EXPECT_EQ(layer_state_is(2), true); | 47 | |
46 | // } | 48 | layer_state_set(0); |
49 | EXPECT_EQ(layer_state_is(0), true); | ||
50 | EXPECT_EQ(layer_state_is(1), false); | ||
51 | layer_state_set(1); | ||
52 | EXPECT_EQ(layer_state_is(0), true); | ||
53 | EXPECT_EQ(layer_state_is(1), false); | ||
54 | layer_state_set(2); | ||
55 | EXPECT_EQ(layer_state_is(0), false); | ||
56 | EXPECT_EQ(layer_state_is(1), true); | ||
57 | EXPECT_EQ(layer_state_is(2), false); | ||
58 | |||
59 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
60 | } | ||
47 | 61 | ||
48 | TEST_F(ActionLayer, LayerStateCmp) { | 62 | TEST_F(ActionLayer, LayerStateCmp) { |
49 | uint32_t prev_layer; | 63 | TestDriver driver; |
64 | uint32_t prev_layer; | ||
50 | 65 | ||
51 | prev_layer = 0; | 66 | prev_layer = 0; |
52 | EXPECT_EQ(layer_state_cmp(prev_layer, 0), true); | 67 | EXPECT_EQ(layer_state_cmp(prev_layer, 0), true); |
@@ -60,33 +75,339 @@ TEST_F(ActionLayer, LayerStateCmp) { | |||
60 | EXPECT_EQ(layer_state_cmp(prev_layer, 0), false); | 75 | EXPECT_EQ(layer_state_cmp(prev_layer, 0), false); |
61 | EXPECT_EQ(layer_state_cmp(prev_layer, 1), true); | 76 | EXPECT_EQ(layer_state_cmp(prev_layer, 1), true); |
62 | EXPECT_EQ(layer_state_cmp(prev_layer, 2), false); | 77 | EXPECT_EQ(layer_state_cmp(prev_layer, 2), false); |
78 | |||
79 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
80 | } | ||
81 | |||
82 | TEST_F(ActionLayer, LayerClear) { | ||
83 | TestDriver driver; | ||
84 | |||
85 | layer_clear(); | ||
86 | EXPECT_EQ(layer_state, 0); | ||
87 | |||
88 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
89 | } | ||
90 | |||
91 | TEST_F(ActionLayer, LayerMove) { | ||
92 | TestDriver driver; | ||
93 | |||
94 | layer_move(0); | ||
95 | EXPECT_EQ(layer_state, 1); | ||
96 | layer_move(3); | ||
97 | EXPECT_EQ(layer_state, 0b1000); | ||
98 | |||
99 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
100 | } | ||
101 | |||
102 | TEST_F(ActionLayer, LayerOn) { | ||
103 | TestDriver driver; | ||
104 | |||
105 | layer_clear(); | ||
106 | layer_on(1); | ||
107 | layer_on(3); | ||
108 | layer_on(3); | ||
109 | EXPECT_EQ(layer_state, 0b1010); | ||
110 | |||
111 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
112 | } | ||
113 | |||
114 | TEST_F(ActionLayer, LayerOff) { | ||
115 | TestDriver driver; | ||
116 | |||
117 | layer_clear(); | ||
118 | layer_on(1); | ||
119 | layer_on(3); | ||
120 | layer_off(3); | ||
121 | layer_off(2); | ||
122 | EXPECT_EQ(layer_state, 0b0010); | ||
123 | |||
124 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
125 | } | ||
126 | |||
127 | TEST_F(ActionLayer, MomentaryLayerDoesNothing) { | ||
128 | TestDriver driver; | ||
129 | KeymapKey layer_key = KeymapKey{0, 0, 0, MO(1)}; | ||
130 | |||
131 | set_keymap({layer_key}); | ||
132 | |||
133 | /* Press and release MO, nothing should happen. */ | ||
134 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
135 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
136 | layer_key.press(); | ||
137 | run_one_scan_loop(); | ||
138 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
139 | |||
140 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
141 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
142 | layer_key.release(); | ||
143 | run_one_scan_loop(); | ||
144 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
145 | } | ||
146 | |||
147 | TEST_F(ActionLayer, MomentaryLayerWithKeypress) { | ||
148 | TestDriver driver; | ||
149 | KeymapKey layer_key = KeymapKey{0, 0, 0, MO(1)}; | ||
150 | |||
151 | /* These keys must have the same position in the matrix, only the layer is different. */ | ||
152 | KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A}; | ||
153 | set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}}); | ||
154 | |||
155 | /* Press MO. */ | ||
156 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
157 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
158 | layer_key.press(); | ||
159 | run_one_scan_loop(); | ||
160 | EXPECT_TRUE(layer_state_is(1)); | ||
161 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
162 | |||
163 | /* Press key on layer 1 */ | ||
164 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))).Times(1); | ||
165 | regular_key.press(); | ||
166 | run_one_scan_loop(); | ||
167 | EXPECT_TRUE(layer_state_is(1)); | ||
168 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
169 | |||
170 | /* Release key on layer 1 */ | ||
171 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
172 | regular_key.release(); | ||
173 | run_one_scan_loop(); | ||
174 | EXPECT_TRUE(layer_state_is(1)); | ||
175 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
176 | |||
177 | /* Release MO */ | ||
178 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
179 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
180 | layer_key.release(); | ||
181 | run_one_scan_loop(); | ||
182 | EXPECT_TRUE(layer_state_is(0)); | ||
183 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
184 | } | ||
185 | |||
186 | TEST_F(ActionLayer, ToggleLayerDoesNothing) { | ||
187 | GTEST_SKIP() << "TODO: Toggle layer does not activate the expected layer on key press but on release."; | ||
188 | |||
189 | TestDriver driver; | ||
190 | KeymapKey layer_key = KeymapKey{0, 0, 0, TG(1)}; | ||
191 | |||
192 | set_keymap({layer_key}); | ||
193 | |||
194 | /* Press TG. Layer state should not change as it's applied on release. */ | ||
195 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
196 | layer_key.press(); | ||
197 | run_one_scan_loop(); | ||
198 | EXPECT_TRUE(layer_state_is(1)); | ||
199 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
200 | |||
201 | /* Release TG. */ | ||
202 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
203 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
204 | layer_key.release(); | ||
205 | run_one_scan_loop(); | ||
206 | EXPECT_TRUE(layer_state_is(1)); | ||
207 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
208 | } | ||
209 | |||
210 | TEST_F(ActionLayer, ToggleLayerUpAndDown) { | ||
211 | GTEST_SKIP() << "TODO: Toggle layer does not activate the expected layer on key press but on release."; | ||
212 | |||
213 | TestDriver driver; | ||
214 | KeymapKey toggle_layer_1_on_layer_0 = KeymapKey{0, 0, 0, TG(1)}; | ||
215 | KeymapKey toggle_layer_0_on_layer_1 = KeymapKey{1, 1, 0, TG(0)}; | ||
216 | |||
217 | set_keymap({toggle_layer_1_on_layer_0, toggle_layer_0_on_layer_1}); | ||
218 | |||
219 | /* Toggle Layer 1. */ | ||
220 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
221 | toggle_layer_1_on_layer_0.press(); | ||
222 | run_one_scan_loop(); | ||
223 | EXPECT_TRUE(layer_state_is(1)); | ||
224 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
225 | |||
226 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
227 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
228 | toggle_layer_1_on_layer_0.release(); | ||
229 | run_one_scan_loop(); | ||
230 | EXPECT_TRUE(layer_state_is(1)); | ||
231 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
232 | |||
233 | /* Toggle Layer 0. */ | ||
234 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
235 | toggle_layer_0_on_layer_1.press(); | ||
236 | run_one_scan_loop(); | ||
237 | EXPECT_TRUE(layer_state_is(0)); | ||
238 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
239 | |||
240 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
241 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
242 | toggle_layer_0_on_layer_1.release(); | ||
243 | run_one_scan_loop(); | ||
244 | EXPECT_TRUE(layer_state_is(0)); | ||
245 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
246 | } | ||
247 | |||
248 | TEST_F(ActionLayer, LayerTapToggleDoesNothing) { | ||
249 | GTEST_SKIP() << "TODO: Tap toggle layer does not activate the expected layer on key press."; | ||
250 | |||
251 | TestDriver driver; | ||
252 | KeymapKey layer_key = KeymapKey{0, 0, 0, TT(1)}; | ||
253 | |||
254 | set_keymap({layer_key}); | ||
255 | |||
256 | /* Press and release TT. */ | ||
257 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(0); | ||
258 | layer_key.press(); | ||
259 | run_one_scan_loop(); | ||
260 | EXPECT_TRUE(layer_state_is(1)); | ||
261 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
262 | |||
263 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
264 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(2); | ||
265 | layer_key.release(); | ||
266 | run_one_scan_loop(); | ||
267 | EXPECT_TRUE(layer_state_is(0)); | ||
268 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
269 | } | ||
270 | |||
271 | TEST_F(ActionLayer, LayerTapToggleWithKeypress) { | ||
272 | GTEST_SKIP() << "TODO: Tap toggle layer does not activate the expected layer on key press."; | ||
273 | |||
274 | TestDriver driver; | ||
275 | KeymapKey layer_key = KeymapKey{0, 0, 0, TT(1)}; | ||
276 | |||
277 | /* These keys must have the same position in the matrix, only the layer is different. */ | ||
278 | KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A}; | ||
279 | set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}}); | ||
280 | |||
281 | /* Press TT. */ | ||
282 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
283 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(0); | ||
284 | layer_key.press(); | ||
285 | run_one_scan_loop(); | ||
286 | EXPECT_TRUE(layer_state_is(1)); | ||
287 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
288 | |||
289 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))).Times(1); | ||
290 | regular_key.press(); | ||
291 | run_one_scan_loop(); | ||
292 | EXPECT_TRUE(layer_state_is(1)); | ||
293 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
294 | |||
295 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
296 | regular_key.release(); | ||
297 | run_one_scan_loop(); | ||
298 | EXPECT_TRUE(layer_state_is(1)); | ||
299 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
300 | |||
301 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
302 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
303 | layer_key.release(); | ||
304 | run_one_scan_loop(); | ||
305 | EXPECT_TRUE(layer_state_is(0)); | ||
306 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
307 | } | ||
308 | |||
309 | TEST_F(ActionLayer, LayerTapToggleWithToggleWithKeypress) { | ||
310 | GTEST_SKIP() << "TODO: Tap toggle layer does not activate the expected layer on key press."; | ||
311 | |||
312 | TestDriver driver; | ||
313 | KeymapKey layer_key = KeymapKey{0, 0, 0, TT(1)}; | ||
314 | |||
315 | /* These keys must have the same position in the matrix, only the layer is different. */ | ||
316 | KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A}; | ||
317 | set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}}); | ||
318 | |||
319 | /* Tap TT five times . */ | ||
320 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
321 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(9); | ||
322 | |||
323 | layer_key.press(); | ||
324 | run_one_scan_loop(); | ||
325 | EXPECT_TRUE(layer_state_is(1)); | ||
326 | layer_key.release(); | ||
327 | run_one_scan_loop(); | ||
328 | EXPECT_TRUE(layer_state_is(0)); | ||
329 | |||
330 | layer_key.press(); | ||
331 | run_one_scan_loop(); | ||
332 | EXPECT_TRUE(layer_state_is(1)); | ||
333 | layer_key.release(); | ||
334 | run_one_scan_loop(); | ||
335 | EXPECT_TRUE(layer_state_is(0)); | ||
336 | |||
337 | layer_key.press(); | ||
338 | run_one_scan_loop(); | ||
339 | EXPECT_TRUE(layer_state_is(1)); | ||
340 | layer_key.release(); | ||
341 | run_one_scan_loop(); | ||
342 | EXPECT_TRUE(layer_state_is(0)); | ||
343 | |||
344 | layer_key.press(); | ||
345 | run_one_scan_loop(); | ||
346 | EXPECT_TRUE(layer_state_is(1)); | ||
347 | layer_key.release(); | ||
348 | run_one_scan_loop(); | ||
349 | EXPECT_TRUE(layer_state_is(0)); | ||
350 | |||
351 | layer_key.press(); | ||
352 | run_one_scan_loop(); | ||
353 | EXPECT_TRUE(layer_state_is(1)); | ||
354 | layer_key.release(); | ||
355 | run_one_scan_loop(); | ||
356 | EXPECT_TRUE(layer_state_is(1)); | ||
357 | |||
358 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
359 | |||
360 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))).Times(1); | ||
361 | regular_key.press(); | ||
362 | run_one_scan_loop(); | ||
363 | EXPECT_TRUE(layer_state_is(1)); | ||
364 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
365 | |||
366 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
367 | regular_key.release(); | ||
368 | run_one_scan_loop(); | ||
369 | EXPECT_TRUE(layer_state_is(1)); | ||
370 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
63 | } | 371 | } |
64 | 372 | ||
65 | // TEST_F(ActionLayer, LayerClear) { | 373 | TEST_F(ActionLayer, LayerTapReleasedBeforeKeypressReleaseWithModifiers) { |
66 | // layer_clear(); | 374 | GTEST_SKIP() << "TODO: Modifiers are erroneously discarded on layer changes, although a key that introduced the modifier is still held."; |
67 | // EXPECT_EQ(layer_state, 0); | 375 | TestDriver driver; |
68 | // } | 376 | InSequence s; |
69 | 377 | ||
70 | // TEST_F(ActionLayer, LayerMove) { | 378 | KeymapKey layer_0_key_0 = KeymapKey{0, 0, 0, LT(1, KC_T)}; |
71 | // layer_move(0); | 379 | KeymapKey layer_1_key_1 = KeymapKey{1, 1, 0, RALT(KC_9)}; |
72 | // EXPECT_EQ(layer_state, 1); | 380 | |
73 | // layer_move(3); | 381 | set_keymap({layer_0_key_0, layer_1_key_1}); |
74 | // EXPECT_EQ(layer_state, 0b1000); | 382 | |
75 | // } | 383 | /* Press layer tap and wait for tapping term to switch to layer 1 */ |
76 | 384 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(0); | |
77 | // TEST_F(ActionLayer, LayerOn) { | 385 | layer_0_key_0.press(); |
78 | // layer_clear(); | 386 | idle_for(TAPPING_TERM); |
79 | // layer_on(1); | 387 | EXPECT_TRUE(layer_state_is(0)); |
80 | // layer_on(3); | 388 | testing::Mock::VerifyAndClearExpectations(&driver); |
81 | // layer_on(3); | 389 | |
82 | // EXPECT_EQ(layer_state, 0b1010); | 390 | /* Press key with layer 1 mapping, result basically expected |
83 | // } | 391 | * altough more reports are send then necessary. */ |
84 | 392 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RALT))).Times(1); | |
85 | // TEST_F(ActionLayer, LayerOff) { | 393 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RALT, KC_9))).Times(1); |
86 | // layer_clear(); | 394 | layer_1_key_1.press(); |
87 | // layer_on(1); | 395 | run_one_scan_loop(); |
88 | // layer_on(3); | 396 | EXPECT_TRUE(layer_state_is(1)); |
89 | // layer_off(3); | 397 | testing::Mock::VerifyAndClearExpectations(&driver); |
90 | // layer_off(2); | 398 | |
91 | // EXPECT_EQ(layer_state, 0b1000); | 399 | /* Release layer tap key, no report is send because key is still held. */ |
92 | // } | 400 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); |
401 | layer_0_key_0.release(); | ||
402 | run_one_scan_loop(); | ||
403 | EXPECT_TRUE(layer_state_is(0)); | ||
404 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
405 | |||
406 | /* Unregister keycode and modifier. */ | ||
407 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RALT))).Times(1); | ||
408 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
409 | layer_1_key_1.release(); | ||
410 | run_one_scan_loop(); | ||
411 | EXPECT_TRUE(layer_state_is(0)); | ||
412 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
413 | } | ||
diff --git a/tests/basic/test_keypress.cpp b/tests/basic/test_keypress.cpp index cf839f8c1..1c175c9d5 100644 --- a/tests/basic/test_keypress.cpp +++ b/tests/basic/test_keypress.cpp | |||
@@ -14,11 +14,11 @@ | |||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include "keycode.h" | ||
17 | #include "test_common.hpp" | 18 | #include "test_common.hpp" |
18 | 19 | ||
19 | using testing::_; | 20 | using testing::_; |
20 | using testing::InSequence; | 21 | using testing::InSequence; |
21 | using testing::Return; | ||
22 | 22 | ||
23 | class KeyPress : public TestFixture {}; | 23 | class KeyPress : public TestFixture {}; |
24 | 24 | ||
@@ -30,96 +30,157 @@ TEST_F(KeyPress, SendKeyboardIsNotCalledWhenNoKeyIsPressed) { | |||
30 | 30 | ||
31 | TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) { | 31 | TEST_F(KeyPress, CorrectKeyIsReportedWhenPressed) { |
32 | TestDriver driver; | 32 | TestDriver driver; |
33 | press_key(0, 0); | 33 | auto key = KeymapKey(0, 0, 0, KC_A); |
34 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); | 34 | |
35 | set_keymap({key}); | ||
36 | |||
37 | key.press(); | ||
38 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key.report_code))); | ||
35 | keyboard_task(); | 39 | keyboard_task(); |
36 | release_key(0, 0); | 40 | |
41 | key.release(); | ||
37 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | 42 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); |
38 | keyboard_task(); | 43 | keyboard_task(); |
39 | } | 44 | } |
40 | 45 | ||
46 | TEST_F(KeyPress, ANonMappedKeyDoesNothing) { | ||
47 | TestDriver driver; | ||
48 | auto key = KeymapKey(0, 0, 0, KC_NO); | ||
49 | |||
50 | set_keymap({key}); | ||
51 | |||
52 | key.press(); | ||
53 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
54 | keyboard_task(); | ||
55 | keyboard_task(); | ||
56 | } | ||
57 | |||
41 | TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { | 58 | TEST_F(KeyPress, CorrectKeysAreReportedWhenTwoKeysArePressed) { |
42 | TestDriver driver; | 59 | TestDriver driver; |
43 | press_key(1, 0); | 60 | auto key_b = KeymapKey(0, 0, 0, KC_B); |
44 | press_key(0, 3); | 61 | auto key_c = KeymapKey(0, 1, 1, KC_C); |
62 | |||
63 | set_keymap({key_b, key_c}); | ||
64 | |||
65 | key_b.press(); | ||
66 | key_c.press(); | ||
45 | // Note that QMK only processes one key at a time | 67 | // Note that QMK only processes one key at a time |
46 | // See issue #1476 for more information | 68 | // See issue #1476 for more information |
47 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))); | 69 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_b.report_code))); |
48 | keyboard_task(); | 70 | keyboard_task(); |
49 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B, KC_C))); | 71 | |
72 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_b.report_code, key_c.report_code))); | ||
50 | keyboard_task(); | 73 | keyboard_task(); |
51 | release_key(1, 0); | 74 | |
52 | release_key(0, 3); | 75 | key_b.release(); |
76 | key_c.release(); | ||
53 | // Note that the first key released is the first one in the matrix order | 77 | // Note that the first key released is the first one in the matrix order |
54 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_C))); | 78 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_c.report_code))); |
55 | keyboard_task(); | ||
56 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
57 | keyboard_task(); | 79 | keyboard_task(); |
58 | } | ||
59 | 80 | ||
60 | TEST_F(KeyPress, ANonMappedKeyDoesNothing) { | 81 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); |
61 | TestDriver driver; | ||
62 | press_key(2, 0); | ||
63 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
64 | keyboard_task(); | ||
65 | keyboard_task(); | 82 | keyboard_task(); |
66 | } | 83 | } |
67 | 84 | ||
68 | TEST_F(KeyPress, LeftShiftIsReportedCorrectly) { | 85 | TEST_F(KeyPress, LeftShiftIsReportedCorrectly) { |
69 | TestDriver driver; | 86 | TestDriver driver; |
70 | press_key(3, 0); | 87 | auto key_a = KeymapKey(0, 0, 0, KC_A); |
71 | press_key(0, 0); | 88 | auto key_lsft = KeymapKey(0, 3, 0, KC_LSFT); |
89 | |||
90 | set_keymap({key_a, key_lsft}); | ||
91 | |||
92 | key_lsft.press(); | ||
93 | key_a.press(); | ||
94 | |||
72 | // Unfortunately modifiers are also processed in the wrong order | 95 | // Unfortunately modifiers are also processed in the wrong order |
73 | // See issue #1476 for more information | 96 | // See issue #1476 for more information |
74 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))); | 97 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_a.report_code))); |
75 | keyboard_task(); | 98 | keyboard_task(); |
76 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A, KC_LEFT_SHIFT))); | 99 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_a.report_code, key_lsft.report_code))); |
77 | keyboard_task(); | 100 | keyboard_task(); |
78 | release_key(0, 0); | 101 | |
79 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); | 102 | key_a.release(); |
103 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_lsft.report_code))); | ||
80 | keyboard_task(); | 104 | keyboard_task(); |
81 | release_key(3, 0); | 105 | |
106 | key_lsft.release(); | ||
82 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | 107 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); |
83 | keyboard_task(); | 108 | keyboard_task(); |
84 | } | 109 | } |
85 | 110 | ||
86 | TEST_F(KeyPress, PressLeftShiftAndControl) { | 111 | TEST_F(KeyPress, PressLeftShiftAndControl) { |
87 | TestDriver driver; | 112 | TestDriver driver; |
88 | press_key(3, 0); | 113 | auto key_lsft = KeymapKey(0, 3, 0, KC_LSFT); |
89 | press_key(5, 0); | 114 | auto key_lctrl = KeymapKey(0, 5, 0, KC_LCTRL); |
115 | |||
116 | set_keymap({key_lctrl, key_lsft}); | ||
117 | |||
118 | key_lsft.press(); | ||
119 | key_lctrl.press(); | ||
120 | |||
90 | // Unfortunately modifiers are also processed in the wrong order | 121 | // Unfortunately modifiers are also processed in the wrong order |
91 | // See issue #1476 for more information | 122 | // See issue #1476 for more information |
92 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); | 123 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_lsft.report_code))); |
124 | keyboard_task(); | ||
125 | |||
126 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_lsft.report_code, key_lctrl.report_code))); | ||
93 | keyboard_task(); | 127 | keyboard_task(); |
94 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_LEFT_CTRL))); | 128 | |
129 | key_lsft.release(); | ||
130 | key_lctrl.release(); | ||
131 | |||
132 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_lctrl.report_code))); | ||
133 | keyboard_task(); | ||
134 | |||
135 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
95 | keyboard_task(); | 136 | keyboard_task(); |
96 | } | 137 | } |
97 | 138 | ||
98 | TEST_F(KeyPress, LeftAndRightShiftCanBePressedAtTheSameTime) { | 139 | TEST_F(KeyPress, LeftAndRightShiftCanBePressedAtTheSameTime) { |
99 | TestDriver driver; | 140 | TestDriver driver; |
100 | press_key(3, 0); | 141 | auto key_lsft = KeymapKey(0, 3, 0, KC_LSFT); |
101 | press_key(4, 0); | 142 | auto key_rsft = KeymapKey(0, 4, 0, KC_RSFT); |
143 | |||
144 | set_keymap({key_rsft, key_lsft}); | ||
145 | |||
146 | key_lsft.press(); | ||
147 | key_rsft.press(); | ||
102 | // Unfortunately modifiers are also processed in the wrong order | 148 | // Unfortunately modifiers are also processed in the wrong order |
103 | // See issue #1476 for more information | 149 | // See issue #1476 for more information |
104 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); | 150 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_lsft.report_code))); |
105 | keyboard_task(); | 151 | keyboard_task(); |
106 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_RIGHT_SHIFT))); | 152 | |
153 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_lsft.report_code, key_rsft.report_code))); | ||
154 | keyboard_task(); | ||
155 | |||
156 | key_lsft.release(); | ||
157 | key_rsft.release(); | ||
158 | |||
159 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_rsft.report_code))); | ||
160 | keyboard_task(); | ||
161 | |||
162 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
107 | keyboard_task(); | 163 | keyboard_task(); |
108 | } | 164 | } |
109 | 165 | ||
110 | TEST_F(KeyPress, RightShiftLeftControlAndCharWithTheSameKey) { | 166 | TEST_F(KeyPress, RightShiftLeftControlAndCharWithTheSameKey) { |
111 | TestDriver driver; | 167 | TestDriver driver; |
112 | press_key(6, 0); | 168 | auto combo_key = KeymapKey(0, 0, 0, RSFT(LCTL(KC_O))); |
169 | |||
170 | set_keymap({combo_key}); | ||
171 | |||
113 | // BUG: The press is split into two reports | 172 | // BUG: The press is split into two reports |
114 | // BUG: It reports RSFT instead of LSFT | 173 | // BUG: It reports RSFT instead of LSFT |
115 | // See issue #524 for more information | 174 | // See issue #524 for more information |
116 | // The underlying cause is that we use only one bit to represent the right hand | 175 | // The underlying cause is that we use only one bit to represent the right hand |
117 | // modifiers. | 176 | // modifiers. |
118 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RIGHT_SHIFT, KC_RIGHT_CTRL))); | 177 | combo_key.press(); |
119 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RIGHT_SHIFT, KC_RIGHT_CTRL, KC_O))); | 178 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL))); |
179 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL, KC_O))); | ||
120 | keyboard_task(); | 180 | keyboard_task(); |
121 | release_key(6, 0); | 181 | |
122 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RIGHT_SHIFT, KC_RIGHT_CTRL))); | 182 | combo_key.release(); |
183 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_RSFT, KC_RCTRL))); | ||
123 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | 184 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); |
124 | keyboard_task(); | 185 | keyboard_task(); |
125 | } | 186 | } |
@@ -127,25 +188,29 @@ TEST_F(KeyPress, RightShiftLeftControlAndCharWithTheSameKey) { | |||
127 | TEST_F(KeyPress, PressPlusEqualReleaseBeforePress) { | 188 | TEST_F(KeyPress, PressPlusEqualReleaseBeforePress) { |
128 | TestDriver driver; | 189 | TestDriver driver; |
129 | InSequence s; | 190 | InSequence s; |
191 | auto key_plus = KeymapKey(0, 1, 1, KC_PLUS); | ||
192 | auto key_eql = KeymapKey(0, 0, 1, KC_EQL); | ||
130 | 193 | ||
131 | press_key(1, 1); // KC_PLUS | 194 | set_keymap({key_plus, key_eql}); |
132 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); | 195 | |
133 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_EQUAL))); | 196 | key_plus.press(); |
197 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
198 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL))); | ||
134 | run_one_scan_loop(); | 199 | run_one_scan_loop(); |
135 | testing::Mock::VerifyAndClearExpectations(&driver); | 200 | testing::Mock::VerifyAndClearExpectations(&driver); |
136 | 201 | ||
137 | release_key(1, 1); // KC_PLUS | 202 | key_plus.release(); |
138 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); | 203 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); |
139 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | 204 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); |
140 | run_one_scan_loop(); | 205 | run_one_scan_loop(); |
141 | testing::Mock::VerifyAndClearExpectations(&driver); | 206 | testing::Mock::VerifyAndClearExpectations(&driver); |
142 | 207 | ||
143 | press_key(0, 1); // KC_EQUAL | 208 | key_eql.press(); |
144 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQUAL))); | 209 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(key_eql.report_code))); |
145 | run_one_scan_loop(); | 210 | run_one_scan_loop(); |
146 | testing::Mock::VerifyAndClearExpectations(&driver); | 211 | testing::Mock::VerifyAndClearExpectations(&driver); |
147 | 212 | ||
148 | release_key(0, 1); // KC_EQUAL | 213 | key_eql.release(); |
149 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | 214 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); |
150 | run_one_scan_loop(); | 215 | run_one_scan_loop(); |
151 | testing::Mock::VerifyAndClearExpectations(&driver); | 216 | testing::Mock::VerifyAndClearExpectations(&driver); |
@@ -154,27 +219,31 @@ TEST_F(KeyPress, PressPlusEqualReleaseBeforePress) { | |||
154 | TEST_F(KeyPress, PressPlusEqualDontReleaseBeforePress) { | 219 | TEST_F(KeyPress, PressPlusEqualDontReleaseBeforePress) { |
155 | TestDriver driver; | 220 | TestDriver driver; |
156 | InSequence s; | 221 | InSequence s; |
222 | auto key_plus = KeymapKey(0, 1, 1, KC_PLUS); | ||
223 | auto key_eql = KeymapKey(0, 0, 1, KC_EQL); | ||
157 | 224 | ||
158 | press_key(1, 1); // KC_PLUS | 225 | set_keymap({key_plus, key_eql}); |
159 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); | 226 | |
160 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_EQUAL))); | 227 | key_plus.press(); |
228 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
229 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL))); | ||
161 | run_one_scan_loop(); | 230 | run_one_scan_loop(); |
162 | testing::Mock::VerifyAndClearExpectations(&driver); | 231 | testing::Mock::VerifyAndClearExpectations(&driver); |
163 | 232 | ||
164 | press_key(0, 1); // KC_EQUAL | 233 | key_eql.press(); |
165 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | 234 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); |
166 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQUAL))); | 235 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQUAL))); |
167 | run_one_scan_loop(); | 236 | run_one_scan_loop(); |
168 | testing::Mock::VerifyAndClearExpectations(&driver); | 237 | testing::Mock::VerifyAndClearExpectations(&driver); |
169 | 238 | ||
170 | release_key(1, 1); // KC_PLUS | 239 | key_plus.release(); |
171 | // BUG: Should really still return KC_EQUAL, but this is fine too | 240 | // BUG: Should really still return KC_EQL, but this is fine too |
172 | // It's also called twice for some reason | 241 | // It's also called twice for some reason |
173 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(2); | 242 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(2); |
174 | run_one_scan_loop(); | 243 | run_one_scan_loop(); |
175 | testing::Mock::VerifyAndClearExpectations(&driver); | 244 | testing::Mock::VerifyAndClearExpectations(&driver); |
176 | 245 | ||
177 | release_key(0, 1); // KC_EQUAL | 246 | key_eql.release(); |
178 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | 247 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); |
179 | run_one_scan_loop(); | 248 | run_one_scan_loop(); |
180 | testing::Mock::VerifyAndClearExpectations(&driver); | 249 | testing::Mock::VerifyAndClearExpectations(&driver); |
@@ -183,25 +252,29 @@ TEST_F(KeyPress, PressPlusEqualDontReleaseBeforePress) { | |||
183 | TEST_F(KeyPress, PressEqualPlusReleaseBeforePress) { | 252 | TEST_F(KeyPress, PressEqualPlusReleaseBeforePress) { |
184 | TestDriver driver; | 253 | TestDriver driver; |
185 | InSequence s; | 254 | InSequence s; |
255 | auto key_plus = KeymapKey(0, 1, 1, KC_PLUS); | ||
256 | auto key_eql = KeymapKey(0, 0, 1, KC_EQL); | ||
186 | 257 | ||
187 | press_key(0, 1); // KC_EQUAL | 258 | set_keymap({key_plus, key_eql}); |
188 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQUAL))); | 259 | |
260 | key_eql.press(); | ||
261 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQL))); | ||
189 | run_one_scan_loop(); | 262 | run_one_scan_loop(); |
190 | testing::Mock::VerifyAndClearExpectations(&driver); | 263 | testing::Mock::VerifyAndClearExpectations(&driver); |
191 | 264 | ||
192 | release_key(0, 1); // KC_EQUAL | 265 | key_eql.release(); |
193 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | 266 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); |
194 | run_one_scan_loop(); | 267 | run_one_scan_loop(); |
195 | testing::Mock::VerifyAndClearExpectations(&driver); | 268 | testing::Mock::VerifyAndClearExpectations(&driver); |
196 | 269 | ||
197 | press_key(1, 1); // KC_PLUS | 270 | key_plus.press(); |
198 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); | 271 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); |
199 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_EQUAL))); | 272 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_EQL))); |
200 | run_one_scan_loop(); | 273 | run_one_scan_loop(); |
201 | testing::Mock::VerifyAndClearExpectations(&driver); | 274 | testing::Mock::VerifyAndClearExpectations(&driver); |
202 | 275 | ||
203 | release_key(1, 1); // KC_PLUS | 276 | key_plus.release(); |
204 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); | 277 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); |
205 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | 278 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); |
206 | run_one_scan_loop(); | 279 | run_one_scan_loop(); |
207 | testing::Mock::VerifyAndClearExpectations(&driver); | 280 | testing::Mock::VerifyAndClearExpectations(&driver); |
@@ -210,13 +283,17 @@ TEST_F(KeyPress, PressEqualPlusReleaseBeforePress) { | |||
210 | TEST_F(KeyPress, PressEqualPlusDontReleaseBeforePress) { | 283 | TEST_F(KeyPress, PressEqualPlusDontReleaseBeforePress) { |
211 | TestDriver driver; | 284 | TestDriver driver; |
212 | InSequence s; | 285 | InSequence s; |
286 | auto key_plus = KeymapKey(0, 1, 1, KC_PLUS); | ||
287 | auto key_eql = KeymapKey(0, 0, 1, KC_EQL); | ||
213 | 288 | ||
214 | press_key(0, 1); // KC_EQUAL | 289 | set_keymap({key_plus, key_eql}); |
215 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQUAL))); | 290 | |
291 | key_eql.press(); | ||
292 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_EQL))); | ||
216 | run_one_scan_loop(); | 293 | run_one_scan_loop(); |
217 | testing::Mock::VerifyAndClearExpectations(&driver); | 294 | testing::Mock::VerifyAndClearExpectations(&driver); |
218 | 295 | ||
219 | press_key(1, 1); // KC_PLUS | 296 | key_plus.press(); |
220 | // BUG: The sequence is a bit strange, but it works, the end result is that | 297 | // BUG: The sequence is a bit strange, but it works, the end result is that |
221 | // KC_PLUS is sent | 298 | // KC_PLUS is sent |
222 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_EQUAL))); | 299 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_EQUAL))); |
@@ -225,16 +302,16 @@ TEST_F(KeyPress, PressEqualPlusDontReleaseBeforePress) { | |||
225 | run_one_scan_loop(); | 302 | run_one_scan_loop(); |
226 | testing::Mock::VerifyAndClearExpectations(&driver); | 303 | testing::Mock::VerifyAndClearExpectations(&driver); |
227 | 304 | ||
228 | release_key(0, 1); // KC_EQUAL | 305 | key_eql.release(); |
229 | // I guess it's fine to still report shift here | 306 | // I guess it's fine to still report shift here |
230 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); | 307 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); |
231 | run_one_scan_loop(); | 308 | run_one_scan_loop(); |
232 | testing::Mock::VerifyAndClearExpectations(&driver); | 309 | testing::Mock::VerifyAndClearExpectations(&driver); |
233 | 310 | ||
234 | release_key(1, 1); // KC_PLUS | 311 | key_plus.release(); |
235 | // This report is not needed | 312 | // This report is not needed |
236 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); | 313 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); |
237 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | 314 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); |
238 | run_one_scan_loop(); | 315 | run_one_scan_loop(); |
239 | testing::Mock::VerifyAndClearExpectations(&driver); | 316 | testing::Mock::VerifyAndClearExpectations(&driver); |
240 | } | 317 | } \ No newline at end of file |
diff --git a/tests/basic/test_macro.cpp b/tests/basic/test_macro.cpp index 1ac6f473f..ae2f3b32e 100644 --- a/tests/basic/test_macro.cpp +++ b/tests/basic/test_macro.cpp | |||
@@ -24,10 +24,25 @@ class Macro : public TestFixture {}; | |||
24 | 24 | ||
25 | #define AT_TIME(t) WillOnce(InvokeWithoutArgs([current_time]() { EXPECT_EQ(timer_elapsed32(current_time), t); })) | 25 | #define AT_TIME(t) WillOnce(InvokeWithoutArgs([current_time]() { EXPECT_EQ(timer_elapsed32(current_time), t); })) |
26 | 26 | ||
27 | extern "C" const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { | ||
28 | if (record->event.pressed) { | ||
29 | switch (id) { | ||
30 | case 0: | ||
31 | return MACRO(D(LSFT), T(H), U(LSFT), T(E), T(L), T(L), T(O), T(SPACE), W(100), D(LSFT), T(W), U(LSFT), I(10), T(O), T(R), T(L), T(D), D(LSFT), T(1), U(LSFT), END); | ||
32 | } | ||
33 | } | ||
34 | return MACRO_NONE; | ||
35 | }; | ||
36 | |||
27 | TEST_F(Macro, PlayASimpleMacro) { | 37 | TEST_F(Macro, PlayASimpleMacro) { |
28 | TestDriver driver; | 38 | TestDriver driver; |
29 | InSequence s; | 39 | InSequence s; |
30 | press_key(8, 0); | 40 | auto key_macro = KeymapKey(0, 8, 0, M(0)); |
41 | |||
42 | set_keymap({key_macro}); | ||
43 | |||
44 | key_macro.press(); | ||
45 | |||
31 | uint32_t current_time = timer_read32(); | 46 | uint32_t current_time = timer_read32(); |
32 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).AT_TIME(0); | 47 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).AT_TIME(0); |
33 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_H))).AT_TIME(0); | 48 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT, KC_H))).AT_TIME(0); |
@@ -68,4 +83,6 @@ TEST_F(Macro, PlayASimpleMacro) { | |||
68 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).AT_TIME(210); | 83 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).AT_TIME(210); |
69 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(220); | 84 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).AT_TIME(220); |
70 | run_one_scan_loop(); | 85 | run_one_scan_loop(); |
86 | |||
87 | key_macro.release(); | ||
71 | } | 88 | } |
diff --git a/tests/basic/test_one_shot_keys.cpp b/tests/basic/test_one_shot_keys.cpp new file mode 100644 index 000000000..98178912e --- /dev/null +++ b/tests/basic/test_one_shot_keys.cpp | |||
@@ -0,0 +1,197 @@ | |||
1 | /* Copyright 2021 Stefan Kerkmann | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include "action_util.h" | ||
18 | #include "keyboard_report_util.hpp" | ||
19 | #include "test_common.hpp" | ||
20 | |||
21 | using testing::_; | ||
22 | using testing::InSequence; | ||
23 | |||
24 | class OneShot : public TestFixture {}; | ||
25 | class OneShotParametrizedTestFixture : public ::testing::WithParamInterface<std::pair<KeymapKey, KeymapKey>>, public OneShot {}; | ||
26 | |||
27 | TEST_F(OneShot, OSMWithoutAdditionalKeypressDoesNothing) { | ||
28 | TestDriver driver; | ||
29 | auto osm_key = KeymapKey(0, 0, 0, OSM(MOD_LSFT), KC_LSFT); | ||
30 | |||
31 | set_keymap({osm_key}); | ||
32 | |||
33 | /* Press and release OSM key*/ | ||
34 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
35 | osm_key.press(); | ||
36 | run_one_scan_loop(); | ||
37 | osm_key.release(); | ||
38 | run_one_scan_loop(); | ||
39 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
40 | |||
41 | /* OSM are added when an actual report is send */ | ||
42 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(osm_key.report_code))); | ||
43 | send_keyboard_report(); | ||
44 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
45 | |||
46 | /* Make unit-test pass */ | ||
47 | clear_oneshot_mods(); | ||
48 | } | ||
49 | |||
50 | #if defined(ONESHOT_TIMEOUT) | ||
51 | |||
52 | TEST_P(OneShotParametrizedTestFixture, OSMExpiredDoesNothing) { | ||
53 | TestDriver driver; | ||
54 | KeymapKey osm_key = GetParam().first; | ||
55 | KeymapKey regular_key = GetParam().second; | ||
56 | |||
57 | set_keymap({osm_key, regular_key}); | ||
58 | |||
59 | /* Press and release OSM */ | ||
60 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
61 | osm_key.press(); | ||
62 | run_one_scan_loop(); | ||
63 | osm_key.release(); | ||
64 | idle_for(ONESHOT_TIMEOUT); | ||
65 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
66 | |||
67 | /* Press regular key */ | ||
68 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(regular_key.report_code))).Times(1); | ||
69 | regular_key.press(); | ||
70 | run_one_scan_loop(); | ||
71 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
72 | |||
73 | /* Release regular key */ | ||
74 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
75 | regular_key.release(); | ||
76 | run_one_scan_loop(); | ||
77 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
78 | } | ||
79 | |||
80 | #endif | ||
81 | |||
82 | TEST_P(OneShotParametrizedTestFixture, OSMWithAdditionalKeypress) { | ||
83 | TestDriver driver; | ||
84 | KeymapKey osm_key = GetParam().first; | ||
85 | KeymapKey regular_key = GetParam().second; | ||
86 | |||
87 | set_keymap({osm_key, regular_key}); | ||
88 | |||
89 | /* Press and release OSM */ | ||
90 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
91 | osm_key.press(); | ||
92 | run_one_scan_loop(); | ||
93 | osm_key.release(); | ||
94 | run_one_scan_loop(); | ||
95 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
96 | |||
97 | /* Press regular key */ | ||
98 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(osm_key.report_code, regular_key.report_code))).Times(1); | ||
99 | regular_key.press(); | ||
100 | run_one_scan_loop(); | ||
101 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
102 | |||
103 | /* Release regular key */ | ||
104 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
105 | regular_key.release(); | ||
106 | run_one_scan_loop(); | ||
107 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
108 | } | ||
109 | |||
110 | TEST_P(OneShotParametrizedTestFixture, OSMAsRegularModifierWithAdditionalKeypress) { | ||
111 | TestDriver driver; | ||
112 | testing::InSequence s; | ||
113 | |||
114 | KeymapKey osm_key = GetParam().first; | ||
115 | KeymapKey regular_key = GetParam().second; | ||
116 | |||
117 | set_keymap({osm_key, regular_key}); | ||
118 | |||
119 | /* Press OSM */ | ||
120 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
121 | osm_key.press(); | ||
122 | run_one_scan_loop(); | ||
123 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
124 | |||
125 | /* Press regular key */ | ||
126 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
127 | regular_key.press(); | ||
128 | run_one_scan_loop(); | ||
129 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
130 | |||
131 | /* Release regular key */ | ||
132 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
133 | regular_key.release(); | ||
134 | run_one_scan_loop(); | ||
135 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
136 | |||
137 | /* Release OSM */ | ||
138 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(regular_key.report_code, osm_key.report_code))).Times(1); | ||
139 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
140 | osm_key.release(); | ||
141 | run_one_scan_loop(); | ||
142 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
143 | } | ||
144 | |||
145 | // clang-format off | ||
146 | |||
147 | INSTANTIATE_TEST_CASE_P( | ||
148 | OneShotModifierTests, | ||
149 | OneShotParametrizedTestFixture, | ||
150 | ::testing::Values( | ||
151 | /* first is osm key, second is regular key. */ | ||
152 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_LSFT), KC_LSFT}, KeymapKey{0, 1, 1, KC_A}), | ||
153 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_LCTL), KC_LCTL}, KeymapKey{0, 1, 1, KC_A}), | ||
154 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_LALT), KC_LALT}, KeymapKey{0, 1, 1, KC_A}), | ||
155 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_LGUI), KC_LGUI}, KeymapKey{0, 1, 1, KC_A}), | ||
156 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_RCTL), KC_RCTL}, KeymapKey{0, 1, 1, KC_A}), | ||
157 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_RSFT), KC_RSFT}, KeymapKey{0, 1, 1, KC_A}), | ||
158 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_RALT), KC_RALT}, KeymapKey{0, 1, 1, KC_A}), | ||
159 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_RGUI), KC_RGUI}, KeymapKey{0, 1, 1, KC_A}) | ||
160 | )); | ||
161 | // clang-format on | ||
162 | |||
163 | TEST_F(OneShot, OSLWithAdditionalKeypress) { | ||
164 | TestDriver driver; | ||
165 | InSequence s; | ||
166 | KeymapKey osl_key = KeymapKey{0, 0, 0, OSL(1)}; | ||
167 | KeymapKey regular_key = KeymapKey{1, 1, 0, KC_A}; | ||
168 | |||
169 | set_keymap({osl_key, regular_key}); | ||
170 | |||
171 | /* Press OSL key */ | ||
172 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
173 | osl_key.press(); | ||
174 | run_one_scan_loop(); | ||
175 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
176 | |||
177 | /* Release OSL key */ | ||
178 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(2); | ||
179 | osl_key.release(); | ||
180 | run_one_scan_loop(); | ||
181 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
182 | |||
183 | /* Press regular key */ | ||
184 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
185 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(regular_key.report_code))).Times(2); | ||
186 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
187 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
188 | regular_key.press(); | ||
189 | run_one_scan_loop(); | ||
190 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
191 | |||
192 | /* Release regular key */ | ||
193 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
194 | regular_key.release(); | ||
195 | run_one_scan_loop(); | ||
196 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
197 | } | ||
diff --git a/tests/basic/test_tapping.cpp b/tests/basic/test_tapping.cpp index 88ab97eb6..e4a7e4a9f 100644 --- a/tests/basic/test_tapping.cpp +++ b/tests/basic/test_tapping.cpp | |||
@@ -14,8 +14,11 @@ | |||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include "keyboard_report_util.hpp" | ||
18 | #include "keycode.h" | ||
17 | #include "test_common.hpp" | 19 | #include "test_common.hpp" |
18 | #include "action_tapping.h" | 20 | #include "action_tapping.h" |
21 | #include "test_keymap_key.hpp" | ||
19 | 22 | ||
20 | using testing::_; | 23 | using testing::_; |
21 | using testing::InSequence; | 24 | using testing::InSequence; |
@@ -25,14 +28,19 @@ class Tapping : public TestFixture {}; | |||
25 | TEST_F(Tapping, TapA_SHFT_T_KeyReportsKey) { | 28 | TEST_F(Tapping, TapA_SHFT_T_KeyReportsKey) { |
26 | TestDriver driver; | 29 | TestDriver driver; |
27 | InSequence s; | 30 | InSequence s; |
31 | auto key_shift_hold_p_tap = KeymapKey(0, 7, 0, SFT_T(KC_P)); | ||
32 | |||
33 | set_keymap({key_shift_hold_p_tap}); | ||
28 | 34 | ||
29 | press_key(7, 0); | ||
30 | // Tapping keys does nothing on press | 35 | // Tapping keys does nothing on press |
36 | key_shift_hold_p_tap.press(); | ||
31 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | 37 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); |
32 | run_one_scan_loop(); | 38 | run_one_scan_loop(); |
33 | release_key(7, 0); | 39 | |
34 | // First we get the key press | 40 | // First we get the key press |
41 | key_shift_hold_p_tap.release(); | ||
35 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | 42 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); |
43 | |||
36 | // Then the release | 44 | // Then the release |
37 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | 45 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); |
38 | run_one_scan_loop(); | 46 | run_one_scan_loop(); |
@@ -41,12 +49,21 @@ TEST_F(Tapping, TapA_SHFT_T_KeyReportsKey) { | |||
41 | TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) { | 49 | TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) { |
42 | TestDriver driver; | 50 | TestDriver driver; |
43 | InSequence s; | 51 | InSequence s; |
52 | auto mod_tap_hold_key = KeymapKey(0, 7, 0, SFT_T(KC_P)); | ||
53 | |||
54 | set_keymap({mod_tap_hold_key}); | ||
55 | |||
56 | mod_tap_hold_key.press(); | ||
44 | 57 | ||
45 | press_key(7, 0); | ||
46 | // Tapping keys does nothing on press | 58 | // Tapping keys does nothing on press |
47 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | 59 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); |
48 | idle_for(TAPPING_TERM); | 60 | idle_for(TAPPING_TERM); |
49 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))); | 61 | |
62 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
63 | run_one_scan_loop(); | ||
64 | |||
65 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
66 | mod_tap_hold_key.release(); | ||
50 | run_one_scan_loop(); | 67 | run_one_scan_loop(); |
51 | } | 68 | } |
52 | 69 | ||
@@ -54,12 +71,16 @@ TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) { | |||
54 | // See issue #1478 for more information | 71 | // See issue #1478 for more information |
55 | TestDriver driver; | 72 | TestDriver driver; |
56 | InSequence s; | 73 | InSequence s; |
74 | auto key_shift_hold_p_tap = KeymapKey(0, 7, 0, SFT_T(KC_P)); | ||
75 | |||
76 | set_keymap({key_shift_hold_p_tap}); | ||
57 | 77 | ||
58 | press_key(7, 0); | ||
59 | // Tapping keys does nothing on press | 78 | // Tapping keys does nothing on press |
79 | key_shift_hold_p_tap.press(); | ||
60 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | 80 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); |
61 | run_one_scan_loop(); | 81 | run_one_scan_loop(); |
62 | release_key(7, 0); | 82 | key_shift_hold_p_tap.release(); |
83 | |||
63 | // First we get the key press | 84 | // First we get the key press |
64 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | 85 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); |
65 | // Then the release | 86 | // Then the release |
@@ -67,19 +88,20 @@ TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) { | |||
67 | run_one_scan_loop(); | 88 | run_one_scan_loop(); |
68 | 89 | ||
69 | // This sends KC_P, even if it should do nothing | 90 | // This sends KC_P, even if it should do nothing |
70 | press_key(7, 0); | 91 | key_shift_hold_p_tap.press(); |
71 | // This test should not succed if everything works correctly | 92 | // This test should not succed if everything works correctly |
72 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | 93 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); |
73 | run_one_scan_loop(); | 94 | run_one_scan_loop(); |
74 | release_key(7, 0); | 95 | |
96 | key_shift_hold_p_tap.release(); | ||
75 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | 97 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); |
76 | idle_for(TAPPING_TERM + 1); | 98 | idle_for(TAPPING_TERM + 1); |
77 | 99 | ||
78 | // On the other hand, nothing is sent if we are outside the tapping term | 100 | // On the other hand, nothing is sent if we are outside the tapping term |
79 | press_key(7, 0); | 101 | key_shift_hold_p_tap.press(); |
80 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | 102 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); |
81 | run_one_scan_loop(); | 103 | run_one_scan_loop(); |
82 | release_key(7, 0); | 104 | key_shift_hold_p_tap.release(); |
83 | 105 | ||
84 | // First we get the key press | 106 | // First we get the key press |
85 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | 107 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); |
@@ -90,8 +112,12 @@ TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) { | |||
90 | // Now we are geting into strange territory, as the hold registers too early here | 112 | // Now we are geting into strange territory, as the hold registers too early here |
91 | // But the stranges part is: | 113 | // But the stranges part is: |
92 | // If TAPPING_TERM + 1 above is changed to TAPPING_TERM or TAPPING_TERM + 2 it doesn't | 114 | // If TAPPING_TERM + 1 above is changed to TAPPING_TERM or TAPPING_TERM + 2 it doesn't |
93 | press_key(7, 0); | 115 | key_shift_hold_p_tap.press(); |
94 | // Shouldn't be called here really | 116 | // Shouldn't be called here really |
95 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).Times(1); | 117 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LEFT_SHIFT))).Times(1); |
96 | idle_for(TAPPING_TERM); | 118 | idle_for(TAPPING_TERM); |
97 | } | 119 | |
120 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
121 | key_shift_hold_p_tap.release(); | ||
122 | run_one_scan_loop(); | ||
123 | } \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/default_mod_tap/config.h b/tests/tap_hold_configurations/default_mod_tap/config.h new file mode 100644 index 000000000..5955b8600 --- /dev/null +++ b/tests/tap_hold_configurations/default_mod_tap/config.h | |||
@@ -0,0 +1,21 @@ | |||
1 | /* Copyright 2021 Stefan Kerkmann | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #pragma once | ||
18 | |||
19 | #include "test_common.h" | ||
20 | |||
21 | #define IGNORE_MOD_TAP_INTERRUPT \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/default_mod_tap/test.mk b/tests/tap_hold_configurations/default_mod_tap/test.mk new file mode 100644 index 000000000..cfab996e0 --- /dev/null +++ b/tests/tap_hold_configurations/default_mod_tap/test.mk | |||
@@ -0,0 +1,18 @@ | |||
1 | # Copyright 2021 Stefan Kerkmann | ||
2 | # | ||
3 | # This program is free software: you can redistribute it and/or modify | ||
4 | # it under the terms of the GNU General Public License as published by | ||
5 | # the Free Software Foundation, either version 2 of the License, or | ||
6 | # (at your option) any later version. | ||
7 | # | ||
8 | # This program is distributed in the hope that it will be useful, | ||
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | # GNU General Public License for more details. | ||
12 | # | ||
13 | # You should have received a copy of the GNU General Public License | ||
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | |||
16 | # -------------------------------------------------------------------------------- | ||
17 | # Keep this file, even if it is empty, as a marker that this folder contains tests | ||
18 | # -------------------------------------------------------------------------------- \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/default_mod_tap/test_tap_hold.cpp b/tests/tap_hold_configurations/default_mod_tap/test_tap_hold.cpp new file mode 100644 index 000000000..90befcdff --- /dev/null +++ b/tests/tap_hold_configurations/default_mod_tap/test_tap_hold.cpp | |||
@@ -0,0 +1,230 @@ | |||
1 | /* Copyright 2021 Stefan Kerkmann | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include "keyboard_report_util.hpp" | ||
18 | #include "keycode.h" | ||
19 | #include "test_common.hpp" | ||
20 | #include "action_tapping.h" | ||
21 | #include "test_fixture.hpp" | ||
22 | #include "test_keymap_key.hpp" | ||
23 | |||
24 | using testing::_; | ||
25 | using testing::InSequence; | ||
26 | |||
27 | class DefaultTapHold : public TestFixture {}; | ||
28 | |||
29 | TEST_F(DefaultTapHold, tap_regular_key_while_mod_tap_key_is_held) { | ||
30 | TestDriver driver; | ||
31 | InSequence s; | ||
32 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
33 | auto regular_key = KeymapKey(0, 2, 0, KC_A); | ||
34 | |||
35 | set_keymap({mod_tap_hold_key, regular_key}); | ||
36 | |||
37 | /* Press mod-tap-hold key. */ | ||
38 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
39 | mod_tap_hold_key.press(); | ||
40 | run_one_scan_loop(); | ||
41 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
42 | |||
43 | /* Press regular key. */ | ||
44 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
45 | regular_key.press(); | ||
46 | run_one_scan_loop(); | ||
47 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
48 | |||
49 | /* Release regular key. */ | ||
50 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
51 | regular_key.release(); | ||
52 | run_one_scan_loop(); | ||
53 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
54 | |||
55 | /* Release mod-tap-hold key. */ | ||
56 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
57 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P, KC_A))); | ||
58 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
59 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
60 | mod_tap_hold_key.release(); | ||
61 | run_one_scan_loop(); | ||
62 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
63 | |||
64 | /* Idle for tapping term of mod tap hold key. */ | ||
65 | idle_for(TAPPING_TERM - 3); | ||
66 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
67 | } | ||
68 | |||
69 | TEST_F(DefaultTapHold, tap_mod_tap_key_while_mod_tap_key_is_held) { | ||
70 | TestDriver driver; | ||
71 | InSequence s; | ||
72 | auto first_mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
73 | auto second_mod_tap_hold_key = KeymapKey(0, 2, 0, RSFT_T(KC_A)); | ||
74 | |||
75 | set_keymap({first_mod_tap_hold_key, second_mod_tap_hold_key}); | ||
76 | |||
77 | /* Press first mod-tap-hold key */ | ||
78 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
79 | first_mod_tap_hold_key.press(); | ||
80 | run_one_scan_loop(); | ||
81 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
82 | |||
83 | /* Press second tap-hold key */ | ||
84 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
85 | second_mod_tap_hold_key.press(); | ||
86 | run_one_scan_loop(); | ||
87 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
88 | |||
89 | /* Release second tap-hold key */ | ||
90 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
91 | second_mod_tap_hold_key.release(); | ||
92 | run_one_scan_loop(); | ||
93 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
94 | |||
95 | /* Release first mod-tap-hold key */ | ||
96 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
97 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P, KC_A))); | ||
98 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
99 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
100 | first_mod_tap_hold_key.release(); | ||
101 | run_one_scan_loop(); | ||
102 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
103 | } | ||
104 | |||
105 | TEST_F(DefaultTapHold, tap_regular_key_while_layer_tap_key_is_held) { | ||
106 | TestDriver driver; | ||
107 | InSequence s; | ||
108 | auto layer_tap_hold_key = KeymapKey(0, 1, 0, LT(1, KC_P)); | ||
109 | auto regular_key = KeymapKey(0, 2, 0, KC_A); | ||
110 | auto layer_key = KeymapKey(1, 2, 0, KC_B); | ||
111 | |||
112 | set_keymap({layer_tap_hold_key, regular_key, layer_key}); | ||
113 | |||
114 | /* Press layer-tap-hold key */ | ||
115 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
116 | layer_tap_hold_key.press(); | ||
117 | run_one_scan_loop(); | ||
118 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
119 | |||
120 | /* Press regular key */ | ||
121 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
122 | regular_key.press(); | ||
123 | run_one_scan_loop(); | ||
124 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
125 | |||
126 | /* Release regular key */ | ||
127 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
128 | regular_key.release(); | ||
129 | run_one_scan_loop(); | ||
130 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
131 | |||
132 | /* Release layer-tap-hold key */ | ||
133 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
134 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A, KC_P))); | ||
135 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
136 | EXPECT_CALL(driver, send_keyboard_mock(_)); | ||
137 | layer_tap_hold_key.release(); | ||
138 | run_one_scan_loop(); | ||
139 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
140 | } | ||
141 | |||
142 | TEST_F(DefaultTapHold, tap_mod_tap_hold_key_two_times) { | ||
143 | GTEST_SKIP() << "TODO:Holding a modtap key results in out of bounds access to the keymap, this is a bug in QMK."; | ||
144 | |||
145 | TestDriver driver; | ||
146 | InSequence s; | ||
147 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
148 | |||
149 | set_keymap({mod_tap_hold_key}); | ||
150 | |||
151 | /* Press mod-tap-hold key. */ | ||
152 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
153 | mod_tap_hold_key.press(); | ||
154 | run_one_scan_loop(); | ||
155 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
156 | |||
157 | /* Release mod-tap-hold key. */ | ||
158 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
159 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
160 | mod_tap_hold_key.release(); | ||
161 | run_one_scan_loop(); | ||
162 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
163 | |||
164 | /* Press mod-tap-hold key again. */ | ||
165 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
166 | mod_tap_hold_key.press(); | ||
167 | idle_for(TAPPING_TERM); | ||
168 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
169 | |||
170 | /* Release mod-tap-hold key. */ | ||
171 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
172 | mod_tap_hold_key.release(); | ||
173 | run_one_scan_loop(); | ||
174 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
175 | } | ||
176 | |||
177 | TEST_F(DefaultTapHold, tap_mod_tap_hold_key_twice_and_hold_on_second_time) { | ||
178 | GTEST_SKIP() << "TODO:Holding a modtap key results in out of bounds access to the keymap, this is a bug in QMK."; | ||
179 | |||
180 | TestDriver driver; | ||
181 | InSequence s; | ||
182 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
183 | |||
184 | set_keymap({mod_tap_hold_key}); | ||
185 | |||
186 | /* Press mod-tap-hold key. */ | ||
187 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
188 | mod_tap_hold_key.press(); | ||
189 | run_one_scan_loop(); | ||
190 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
191 | |||
192 | /* Release mod-tap-hold key. */ | ||
193 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
194 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
195 | mod_tap_hold_key.release(); | ||
196 | run_one_scan_loop(); | ||
197 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
198 | |||
199 | /* Press mod-tap-hold key again. */ | ||
200 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
201 | mod_tap_hold_key.press(); | ||
202 | idle_for(TAPPING_TERM); | ||
203 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
204 | |||
205 | /* Release mod-tap-hold key. */ | ||
206 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
207 | mod_tap_hold_key.release(); | ||
208 | run_one_scan_loop(); | ||
209 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
210 | } | ||
211 | |||
212 | TEST_F(DefaultTapHold, tap_and_hold_mod_tap_hold_key) { | ||
213 | TestDriver driver; | ||
214 | InSequence s; | ||
215 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
216 | |||
217 | set_keymap({mod_tap_hold_key}); | ||
218 | |||
219 | /* Press mod-tap-hold key. */ | ||
220 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT))); | ||
221 | mod_tap_hold_key.press(); | ||
222 | idle_for(TAPPING_TERM + 1); | ||
223 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
224 | |||
225 | /* Release mod-tap-hold key. */ | ||
226 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
227 | mod_tap_hold_key.release(); | ||
228 | run_one_scan_loop(); | ||
229 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
230 | } \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/ignore_mod_tap_interrupt/config.h b/tests/tap_hold_configurations/ignore_mod_tap_interrupt/config.h new file mode 100644 index 000000000..5955b8600 --- /dev/null +++ b/tests/tap_hold_configurations/ignore_mod_tap_interrupt/config.h | |||
@@ -0,0 +1,21 @@ | |||
1 | /* Copyright 2021 Stefan Kerkmann | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #pragma once | ||
18 | |||
19 | #include "test_common.h" | ||
20 | |||
21 | #define IGNORE_MOD_TAP_INTERRUPT \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/ignore_mod_tap_interrupt/test.mk b/tests/tap_hold_configurations/ignore_mod_tap_interrupt/test.mk new file mode 100644 index 000000000..efecca2c2 --- /dev/null +++ b/tests/tap_hold_configurations/ignore_mod_tap_interrupt/test.mk | |||
@@ -0,0 +1,18 @@ | |||
1 | # Copyright 2021 Stefan Kerkmann | ||
2 | # | ||
3 | # This program is free software: you can redistribute it and/or modify | ||
4 | # it under the terms of the GNU General Public License as published by | ||
5 | # the Free Software Foundation, either version 2 of the License, or | ||
6 | # (at your option) any later version. | ||
7 | # | ||
8 | # This program is distributed in the hope that it will be useful, | ||
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | # GNU General Public License for more details. | ||
12 | # | ||
13 | # You should have received a copy of the GNU General Public License | ||
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | |||
16 | # -------------------------------------------------------------------------------- | ||
17 | # Keep this file, even if it is empty, as a marker that this folder contains tests | ||
18 | # -------------------------------------------------------------------------------- | ||
diff --git a/tests/tap_hold_configurations/ignore_mod_tap_interrupt/test_tap_hold.cpp b/tests/tap_hold_configurations/ignore_mod_tap_interrupt/test_tap_hold.cpp new file mode 100644 index 000000000..1702d604d --- /dev/null +++ b/tests/tap_hold_configurations/ignore_mod_tap_interrupt/test_tap_hold.cpp | |||
@@ -0,0 +1,136 @@ | |||
1 | /* Copyright 2021 Stefan Kerkmann | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include "keyboard_report_util.hpp" | ||
18 | #include "keycode.h" | ||
19 | #include "test_common.hpp" | ||
20 | #include "action_tapping.h" | ||
21 | #include "test_fixture.hpp" | ||
22 | #include "test_keymap_key.hpp" | ||
23 | |||
24 | using testing::_; | ||
25 | using testing::InSequence; | ||
26 | |||
27 | class IgnoreModTapInterrupt : public TestFixture {}; | ||
28 | |||
29 | TEST_F(IgnoreModTapInterrupt, tap_regular_key_while_mod_tap_key_is_held) { | ||
30 | TestDriver driver; | ||
31 | InSequence s; | ||
32 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
33 | auto regular_key = KeymapKey(0, 2, 0, KC_A); | ||
34 | |||
35 | set_keymap({mod_tap_hold_key, regular_key}); | ||
36 | |||
37 | /* Press mod-tap-hold key */ | ||
38 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
39 | mod_tap_hold_key.press(); | ||
40 | run_one_scan_loop(); | ||
41 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
42 | |||
43 | /* Press regular key */ | ||
44 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
45 | regular_key.press(); | ||
46 | run_one_scan_loop(); | ||
47 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
48 | |||
49 | /* Release regular key */ | ||
50 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
51 | regular_key.release(); | ||
52 | run_one_scan_loop(); | ||
53 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
54 | |||
55 | /* Release mod-tap-hold key */ | ||
56 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
57 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A, KC_P))); | ||
58 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
59 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
60 | mod_tap_hold_key.release(); | ||
61 | run_one_scan_loop(); | ||
62 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
63 | } | ||
64 | |||
65 | TEST_F(IgnoreModTapInterrupt, tap_mod_tap_key_while_mod_tap_key_is_held) { | ||
66 | TestDriver driver; | ||
67 | InSequence s; | ||
68 | auto first_mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
69 | auto second_mod_tap_hold_key = KeymapKey(0, 2, 0, RSFT_T(KC_A)); | ||
70 | |||
71 | set_keymap({first_mod_tap_hold_key, second_mod_tap_hold_key}); | ||
72 | |||
73 | /* Press first mod-tap-hold key */ | ||
74 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
75 | first_mod_tap_hold_key.press(); | ||
76 | run_one_scan_loop(); | ||
77 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
78 | |||
79 | /* Press second tap-hold key */ | ||
80 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
81 | second_mod_tap_hold_key.press(); | ||
82 | run_one_scan_loop(); | ||
83 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
84 | |||
85 | /* Release second tap-hold key */ | ||
86 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
87 | second_mod_tap_hold_key.release(); | ||
88 | run_one_scan_loop(); | ||
89 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
90 | |||
91 | /* Release first mod-tap-hold key */ | ||
92 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
93 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A, KC_P))); | ||
94 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
95 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
96 | first_mod_tap_hold_key.release(); | ||
97 | run_one_scan_loop(); | ||
98 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
99 | } | ||
100 | |||
101 | TEST_F(IgnoreModTapInterrupt, tap_regular_key_while_layer_tap_key_is_held) { | ||
102 | TestDriver driver; | ||
103 | InSequence s; | ||
104 | auto layer_tap_hold_key = KeymapKey(0, 1, 0, LT(1, KC_P)); | ||
105 | auto regular_key = KeymapKey(0, 2, 0, KC_A); | ||
106 | auto layer_key = KeymapKey(1, 2, 0, KC_B); | ||
107 | |||
108 | set_keymap({layer_tap_hold_key, regular_key, layer_key}); | ||
109 | |||
110 | /* Press layer-tap-hold key */ | ||
111 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
112 | layer_tap_hold_key.press(); | ||
113 | run_one_scan_loop(); | ||
114 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
115 | |||
116 | /* Press regular key */ | ||
117 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
118 | regular_key.press(); | ||
119 | run_one_scan_loop(); | ||
120 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
121 | |||
122 | /* Release regular key */ | ||
123 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
124 | regular_key.release(); | ||
125 | run_one_scan_loop(); | ||
126 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
127 | |||
128 | /* Release layer-tap-hold key */ | ||
129 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
130 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P, regular_key.report_code))); | ||
131 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
132 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
133 | layer_tap_hold_key.release(); | ||
134 | run_one_scan_loop(); | ||
135 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
136 | } | ||
diff --git a/tests/tap_hold_configurations/permissive_hold/config.h b/tests/tap_hold_configurations/permissive_hold/config.h new file mode 100644 index 000000000..2d5a9849e --- /dev/null +++ b/tests/tap_hold_configurations/permissive_hold/config.h | |||
@@ -0,0 +1,21 @@ | |||
1 | /* Copyright 2021 Stefan Kerkmann | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #pragma once | ||
18 | |||
19 | #include "test_common.h" | ||
20 | |||
21 | #define PERMISSIVE_HOLD \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/permissive_hold/test.mk b/tests/tap_hold_configurations/permissive_hold/test.mk new file mode 100644 index 000000000..efecca2c2 --- /dev/null +++ b/tests/tap_hold_configurations/permissive_hold/test.mk | |||
@@ -0,0 +1,18 @@ | |||
1 | # Copyright 2021 Stefan Kerkmann | ||
2 | # | ||
3 | # This program is free software: you can redistribute it and/or modify | ||
4 | # it under the terms of the GNU General Public License as published by | ||
5 | # the Free Software Foundation, either version 2 of the License, or | ||
6 | # (at your option) any later version. | ||
7 | # | ||
8 | # This program is distributed in the hope that it will be useful, | ||
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | # GNU General Public License for more details. | ||
12 | # | ||
13 | # You should have received a copy of the GNU General Public License | ||
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | |||
16 | # -------------------------------------------------------------------------------- | ||
17 | # Keep this file, even if it is empty, as a marker that this folder contains tests | ||
18 | # -------------------------------------------------------------------------------- | ||
diff --git a/tests/tap_hold_configurations/permissive_hold/test_one_shot_keys.cpp b/tests/tap_hold_configurations/permissive_hold/test_one_shot_keys.cpp new file mode 100644 index 000000000..aa71ec397 --- /dev/null +++ b/tests/tap_hold_configurations/permissive_hold/test_one_shot_keys.cpp | |||
@@ -0,0 +1,76 @@ | |||
1 | /* Copyright 2021 Stefan Kerkmann | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include "action_util.h" | ||
18 | #include "keyboard_report_util.hpp" | ||
19 | #include "test_common.hpp" | ||
20 | |||
21 | using testing::_; | ||
22 | using testing::InSequence; | ||
23 | |||
24 | class OneShot : public TestFixture {}; | ||
25 | class OneShotParametrizedTestFixture : public ::testing::WithParamInterface<std::pair<KeymapKey, KeymapKey>>, public OneShot {}; | ||
26 | |||
27 | TEST_P(OneShotParametrizedTestFixture, OSMAsRegularModifierWithAdditionalKeypress) { | ||
28 | TestDriver driver; | ||
29 | KeymapKey osm_key = GetParam().first; | ||
30 | KeymapKey regular_key = GetParam().second; | ||
31 | |||
32 | set_keymap({osm_key, regular_key}); | ||
33 | |||
34 | /* Press OSM */ | ||
35 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
36 | osm_key.press(); | ||
37 | run_one_scan_loop(); | ||
38 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
39 | |||
40 | /* Press regular key */ | ||
41 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
42 | regular_key.press(); | ||
43 | run_one_scan_loop(); | ||
44 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
45 | |||
46 | /* Release regular key */ | ||
47 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(osm_key.report_code))).Times(2); | ||
48 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(regular_key.report_code, osm_key.report_code))).Times(1); | ||
49 | regular_key.release(); | ||
50 | run_one_scan_loop(); | ||
51 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
52 | |||
53 | /* Release OSM */ | ||
54 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
55 | osm_key.release(); | ||
56 | run_one_scan_loop(); | ||
57 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
58 | } | ||
59 | |||
60 | // clang-format off | ||
61 | |||
62 | INSTANTIATE_TEST_CASE_P( | ||
63 | OneShotModifierTests, | ||
64 | OneShotParametrizedTestFixture, | ||
65 | ::testing::Values( | ||
66 | /* first is osm key, second is regular key. */ | ||
67 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_LSFT), KC_LSFT}, KeymapKey{0, 1, 1, KC_A}), | ||
68 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_LCTL), KC_LCTL}, KeymapKey{0, 1, 1, KC_A}), | ||
69 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_LALT), KC_LALT}, KeymapKey{0, 1, 1, KC_A}), | ||
70 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_LGUI), KC_LGUI}, KeymapKey{0, 1, 1, KC_A}), | ||
71 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_RCTL), KC_RCTL}, KeymapKey{0, 1, 1, KC_A}), | ||
72 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_RSFT), KC_RSFT}, KeymapKey{0, 1, 1, KC_A}), | ||
73 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_RALT), KC_RALT}, KeymapKey{0, 1, 1, KC_A}), | ||
74 | std::make_pair(KeymapKey{0, 0, 0, OSM(MOD_RGUI), KC_RGUI}, KeymapKey{0, 1, 1, KC_A}) | ||
75 | )); | ||
76 | // clang-format on \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/permissive_hold/test_tap_hold.cpp b/tests/tap_hold_configurations/permissive_hold/test_tap_hold.cpp new file mode 100644 index 000000000..ab9dd1518 --- /dev/null +++ b/tests/tap_hold_configurations/permissive_hold/test_tap_hold.cpp | |||
@@ -0,0 +1,132 @@ | |||
1 | /* Copyright 2021 Stefan Kerkmann | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include "keyboard_report_util.hpp" | ||
18 | #include "keycode.h" | ||
19 | #include "test_common.hpp" | ||
20 | #include "action_tapping.h" | ||
21 | #include "test_fixture.hpp" | ||
22 | #include "test_keymap_key.hpp" | ||
23 | |||
24 | using testing::_; | ||
25 | using testing::InSequence; | ||
26 | class PermissiveHold : public TestFixture {}; | ||
27 | |||
28 | TEST_F(PermissiveHold, tap_regular_key_while_mod_tap_key_is_held) { | ||
29 | TestDriver driver; | ||
30 | InSequence s; | ||
31 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
32 | auto regular_key = KeymapKey(0, 2, 0, KC_A); | ||
33 | |||
34 | set_keymap({mod_tap_hold_key, regular_key}); | ||
35 | |||
36 | /* Press mod-tap-hold key */ | ||
37 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
38 | mod_tap_hold_key.press(); | ||
39 | run_one_scan_loop(); | ||
40 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
41 | |||
42 | /* Press regular key */ | ||
43 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
44 | regular_key.press(); | ||
45 | run_one_scan_loop(); | ||
46 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
47 | |||
48 | /* Release regular key */ | ||
49 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT))); | ||
50 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT, regular_key.report_code))); | ||
51 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT))); | ||
52 | regular_key.release(); | ||
53 | run_one_scan_loop(); | ||
54 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
55 | |||
56 | /* Release mod-tap-hold key */ | ||
57 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
58 | mod_tap_hold_key.release(); | ||
59 | run_one_scan_loop(); | ||
60 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
61 | } | ||
62 | |||
63 | TEST_F(PermissiveHold, tap_mod_tap_key_while_mod_tap_key_is_held) { | ||
64 | TestDriver driver; | ||
65 | InSequence s; | ||
66 | auto first_mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
67 | auto second_mod_tap_hold_key = KeymapKey(0, 2, 0, RSFT_T(KC_A)); | ||
68 | |||
69 | set_keymap({first_mod_tap_hold_key, second_mod_tap_hold_key}); | ||
70 | |||
71 | /* Press first mod-tap-hold key */ | ||
72 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
73 | first_mod_tap_hold_key.press(); | ||
74 | run_one_scan_loop(); | ||
75 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
76 | |||
77 | /* Press second mod-tap-hold key */ | ||
78 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
79 | second_mod_tap_hold_key.press(); | ||
80 | run_one_scan_loop(); | ||
81 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
82 | |||
83 | /* Release second mod-tap-hold key */ | ||
84 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT))); | ||
85 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT, second_mod_tap_hold_key.report_code))); | ||
86 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT))); | ||
87 | second_mod_tap_hold_key.release(); | ||
88 | run_one_scan_loop(); | ||
89 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
90 | |||
91 | /* Release first mod-tap-hold key */ | ||
92 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
93 | first_mod_tap_hold_key.release(); | ||
94 | run_one_scan_loop(); | ||
95 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
96 | } | ||
97 | |||
98 | TEST_F(PermissiveHold, tap_regular_key_while_layer_tap_key_is_held) { | ||
99 | TestDriver driver; | ||
100 | InSequence s; | ||
101 | auto layer_tap_hold_key = KeymapKey(0, 1, 0, LT(1, KC_P)); | ||
102 | auto regular_key = KeymapKey(0, 2, 0, KC_A); | ||
103 | auto layer_key = KeymapKey(1, 2, 0, KC_B); | ||
104 | |||
105 | set_keymap({layer_tap_hold_key, regular_key, layer_key}); | ||
106 | |||
107 | /* Press layer-tap-hold key */ | ||
108 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
109 | layer_tap_hold_key.press(); | ||
110 | run_one_scan_loop(); | ||
111 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
112 | |||
113 | /* Press regular key */ | ||
114 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
115 | regular_key.press(); | ||
116 | run_one_scan_loop(); | ||
117 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
118 | |||
119 | /* Release regular key */ | ||
120 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
121 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(layer_key.report_code))); | ||
122 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
123 | regular_key.release(); | ||
124 | run_one_scan_loop(); | ||
125 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
126 | |||
127 | /* Release layer-tap-hold key */ | ||
128 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
129 | layer_tap_hold_key.release(); | ||
130 | run_one_scan_loop(); | ||
131 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
132 | } \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/config.h b/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/config.h new file mode 100644 index 000000000..a6abd50bb --- /dev/null +++ b/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/config.h | |||
@@ -0,0 +1,22 @@ | |||
1 | /* Copyright 2021 Stefan Kerkmann | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #pragma once | ||
18 | |||
19 | #include "test_common.h" | ||
20 | |||
21 | #define IGNORE_MOD_TAP_INTERRUPT | ||
22 | #define PERMISSIVE_HOLD \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/test.mk b/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/test.mk new file mode 100644 index 000000000..efecca2c2 --- /dev/null +++ b/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/test.mk | |||
@@ -0,0 +1,18 @@ | |||
1 | # Copyright 2021 Stefan Kerkmann | ||
2 | # | ||
3 | # This program is free software: you can redistribute it and/or modify | ||
4 | # it under the terms of the GNU General Public License as published by | ||
5 | # the Free Software Foundation, either version 2 of the License, or | ||
6 | # (at your option) any later version. | ||
7 | # | ||
8 | # This program is distributed in the hope that it will be useful, | ||
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | # GNU General Public License for more details. | ||
12 | # | ||
13 | # You should have received a copy of the GNU General Public License | ||
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | |||
16 | # -------------------------------------------------------------------------------- | ||
17 | # Keep this file, even if it is empty, as a marker that this folder contains tests | ||
18 | # -------------------------------------------------------------------------------- | ||
diff --git a/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/test_tap_hold.cpp b/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/test_tap_hold.cpp new file mode 100644 index 000000000..67f394653 --- /dev/null +++ b/tests/tap_hold_configurations/permissive_hold_ignore_mod_tap_interrupt/test_tap_hold.cpp | |||
@@ -0,0 +1,134 @@ | |||
1 | |||
2 | /* Copyright 2021 Stefan Kerkmann | ||
3 | * | ||
4 | * This program is free software: you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation, either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include "keyboard_report_util.hpp" | ||
19 | #include "keycode.h" | ||
20 | #include "test_common.hpp" | ||
21 | #include "action_tapping.h" | ||
22 | #include "test_fixture.hpp" | ||
23 | #include "test_keymap_key.hpp" | ||
24 | |||
25 | using testing::_; | ||
26 | using testing::InSequence; | ||
27 | |||
28 | class PermissiveHold_IgnoreModTapInterrupt : public TestFixture {}; | ||
29 | |||
30 | TEST_F(PermissiveHold_IgnoreModTapInterrupt, tap_regular_key_while_mod_tap_key_is_held) { | ||
31 | TestDriver driver; | ||
32 | InSequence s; | ||
33 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
34 | auto regular_key = KeymapKey(0, 2, 0, KC_A); | ||
35 | |||
36 | set_keymap({mod_tap_hold_key, regular_key}); | ||
37 | |||
38 | /* Press mod-tap-hold key */ | ||
39 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
40 | mod_tap_hold_key.press(); | ||
41 | run_one_scan_loop(); | ||
42 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
43 | |||
44 | /* Press regular key */ | ||
45 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
46 | regular_key.press(); | ||
47 | run_one_scan_loop(); | ||
48 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
49 | |||
50 | /* Release regular key */ | ||
51 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
52 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_A))); | ||
53 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
54 | regular_key.release(); | ||
55 | run_one_scan_loop(); | ||
56 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
57 | |||
58 | /* Release mod-tap-hold key */ | ||
59 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
60 | mod_tap_hold_key.release(); | ||
61 | run_one_scan_loop(); | ||
62 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
63 | } | ||
64 | |||
65 | TEST_F(PermissiveHold_IgnoreModTapInterrupt, tap_mod_tap_key_while_mod_tap_key_is_held) { | ||
66 | TestDriver driver; | ||
67 | InSequence s; | ||
68 | auto first_mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
69 | auto second_mod_tap_hold_key = KeymapKey(0, 2, 0, RSFT_T(KC_A)); | ||
70 | |||
71 | set_keymap({first_mod_tap_hold_key, second_mod_tap_hold_key}); | ||
72 | |||
73 | /* Press first mod-tap-hold key */ | ||
74 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
75 | first_mod_tap_hold_key.press(); | ||
76 | run_one_scan_loop(); | ||
77 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
78 | |||
79 | /* Press second tap-hold key */ | ||
80 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
81 | second_mod_tap_hold_key.press(); | ||
82 | run_one_scan_loop(); | ||
83 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
84 | |||
85 | /* Release second tap-hold key */ | ||
86 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
87 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_A))); | ||
88 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
89 | second_mod_tap_hold_key.release(); | ||
90 | run_one_scan_loop(); | ||
91 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
92 | |||
93 | /* Release first mod-tap-hold key */ | ||
94 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
95 | first_mod_tap_hold_key.release(); | ||
96 | run_one_scan_loop(); | ||
97 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
98 | } | ||
99 | |||
100 | TEST_F(PermissiveHold_IgnoreModTapInterrupt, tap_regular_key_while_layer_tap_key_is_held) { | ||
101 | TestDriver driver; | ||
102 | InSequence s; | ||
103 | auto layer_tap_hold_key = KeymapKey(0, 1, 0, LT(1, KC_P)); | ||
104 | auto regular_key = KeymapKey(0, 2, 0, KC_A); | ||
105 | auto layer_key = KeymapKey(1, 2, 0, KC_B); | ||
106 | |||
107 | set_keymap({layer_tap_hold_key, regular_key, layer_key}); | ||
108 | |||
109 | /* Press layer-tap-hold key */ | ||
110 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
111 | layer_tap_hold_key.press(); | ||
112 | run_one_scan_loop(); | ||
113 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
114 | |||
115 | /* Press regular key */ | ||
116 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
117 | regular_key.press(); | ||
118 | run_one_scan_loop(); | ||
119 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
120 | |||
121 | /* Release regular key */ | ||
122 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
123 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_B))); | ||
124 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
125 | regular_key.release(); | ||
126 | run_one_scan_loop(); | ||
127 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
128 | |||
129 | /* Release layer-tap-hold key */ | ||
130 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
131 | layer_tap_hold_key.release(); | ||
132 | run_one_scan_loop(); | ||
133 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
134 | } \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/retro_tapping/config.h b/tests/tap_hold_configurations/retro_tapping/config.h new file mode 100644 index 000000000..4b38f2644 --- /dev/null +++ b/tests/tap_hold_configurations/retro_tapping/config.h | |||
@@ -0,0 +1,21 @@ | |||
1 | /* Copyright 2021 Stefan Kerkmann | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #pragma once | ||
18 | |||
19 | #include "test_common.h" | ||
20 | |||
21 | #define RETRO_TAPPING \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/retro_tapping/test.mk b/tests/tap_hold_configurations/retro_tapping/test.mk new file mode 100644 index 000000000..efecca2c2 --- /dev/null +++ b/tests/tap_hold_configurations/retro_tapping/test.mk | |||
@@ -0,0 +1,18 @@ | |||
1 | # Copyright 2021 Stefan Kerkmann | ||
2 | # | ||
3 | # This program is free software: you can redistribute it and/or modify | ||
4 | # it under the terms of the GNU General Public License as published by | ||
5 | # the Free Software Foundation, either version 2 of the License, or | ||
6 | # (at your option) any later version. | ||
7 | # | ||
8 | # This program is distributed in the hope that it will be useful, | ||
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | # GNU General Public License for more details. | ||
12 | # | ||
13 | # You should have received a copy of the GNU General Public License | ||
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | |||
16 | # -------------------------------------------------------------------------------- | ||
17 | # Keep this file, even if it is empty, as a marker that this folder contains tests | ||
18 | # -------------------------------------------------------------------------------- | ||
diff --git a/tests/tap_hold_configurations/retro_tapping/test_tap_hold.cpp b/tests/tap_hold_configurations/retro_tapping/test_tap_hold.cpp new file mode 100644 index 000000000..59ae77f78 --- /dev/null +++ b/tests/tap_hold_configurations/retro_tapping/test_tap_hold.cpp | |||
@@ -0,0 +1,52 @@ | |||
1 | |||
2 | /* Copyright 2021 Stefan Kerkmann | ||
3 | * | ||
4 | * This program is free software: you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation, either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include "keyboard_report_util.hpp" | ||
19 | #include "keycode.h" | ||
20 | #include "test_common.hpp" | ||
21 | #include "action_tapping.h" | ||
22 | #include "test_fixture.hpp" | ||
23 | #include "test_keymap_key.hpp" | ||
24 | |||
25 | using testing::_; | ||
26 | using testing::InSequence; | ||
27 | |||
28 | class RetroTapping : public TestFixture {}; | ||
29 | |||
30 | TEST_F(RetroTapping, tap_and_hold_mod_tap_hold_key) { | ||
31 | TestDriver driver; | ||
32 | InSequence s; | ||
33 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
34 | |||
35 | set_keymap({mod_tap_hold_key}); | ||
36 | |||
37 | /* Press mod-tap-hold key. */ | ||
38 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
39 | mod_tap_hold_key.press(); | ||
40 | idle_for(TAPPING_TERM); | ||
41 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
42 | |||
43 | /* Release mod-tap-hold key. */ | ||
44 | /* TODO: Why is LSHIFT send at all? */ | ||
45 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT))); | ||
46 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
47 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
48 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
49 | mod_tap_hold_key.release(); | ||
50 | run_one_scan_loop(); | ||
51 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
52 | } \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/retro_tapping/test_tapping.cpp b/tests/tap_hold_configurations/retro_tapping/test_tapping.cpp new file mode 100644 index 000000000..cf23df831 --- /dev/null +++ b/tests/tap_hold_configurations/retro_tapping/test_tapping.cpp | |||
@@ -0,0 +1,112 @@ | |||
1 | /* Copyright 2021 Stefan Kerkmann | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include "keyboard_report_util.hpp" | ||
18 | #include "keycode.h" | ||
19 | #include "test_common.hpp" | ||
20 | #include "action_tapping.h" | ||
21 | #include "test_keymap_key.hpp" | ||
22 | |||
23 | using testing::_; | ||
24 | using testing::InSequence; | ||
25 | |||
26 | class Tapping : public TestFixture {}; | ||
27 | |||
28 | TEST_F(Tapping, HoldA_SHFT_T_KeyReportsShift) { | ||
29 | TestDriver driver; | ||
30 | InSequence s; | ||
31 | auto mod_tap_hold_key = KeymapKey(0, 7, 0, SFT_T(KC_P)); | ||
32 | |||
33 | set_keymap({mod_tap_hold_key}); | ||
34 | |||
35 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
36 | mod_tap_hold_key.press(); | ||
37 | idle_for(TAPPING_TERM); | ||
38 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
39 | |||
40 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
41 | run_one_scan_loop(); | ||
42 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
43 | |||
44 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
45 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
46 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
47 | mod_tap_hold_key.release(); | ||
48 | run_one_scan_loop(); | ||
49 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
50 | } | ||
51 | |||
52 | TEST_F(Tapping, ANewTapWithinTappingTermIsBuggy) { | ||
53 | TestDriver driver; | ||
54 | InSequence s; | ||
55 | auto key_shift_hold_p_tap = KeymapKey(0, 7, 0, SFT_T(KC_P)); | ||
56 | |||
57 | set_keymap({key_shift_hold_p_tap}); | ||
58 | |||
59 | /* Press mod_tap_hold key */ | ||
60 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
61 | key_shift_hold_p_tap.press(); | ||
62 | run_one_scan_loop(); | ||
63 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
64 | |||
65 | /* Release mod_tap_hold key */ | ||
66 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
67 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
68 | key_shift_hold_p_tap.release(); | ||
69 | run_one_scan_loop(); | ||
70 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
71 | |||
72 | /* Press mod_tap_hold key again */ | ||
73 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
74 | key_shift_hold_p_tap.press(); | ||
75 | run_one_scan_loop(); | ||
76 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
77 | |||
78 | /* Release mod_tap_hold key again */ | ||
79 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
80 | key_shift_hold_p_tap.release(); | ||
81 | idle_for(TAPPING_TERM + 1); | ||
82 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
83 | |||
84 | /* Press mod_tap_hold key again */ | ||
85 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
86 | key_shift_hold_p_tap.press(); | ||
87 | run_one_scan_loop(); | ||
88 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
89 | |||
90 | /* Release mod_tap_hold key again */ | ||
91 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
92 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
93 | key_shift_hold_p_tap.release(); | ||
94 | idle_for(TAPPING_TERM + 1); | ||
95 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
96 | |||
97 | /* Press mod_tap_hold key again */ | ||
98 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
99 | key_shift_hold_p_tap.press(); | ||
100 | idle_for(TAPPING_TERM); | ||
101 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
102 | |||
103 | /* Release mod_tap_hold key again */ | ||
104 | /* TODO: Why is KC_LSFT send? */ | ||
105 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
106 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
107 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
108 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
109 | key_shift_hold_p_tap.release(); | ||
110 | run_one_scan_loop(); | ||
111 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
112 | } \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/tapping_force_hold/config.h b/tests/tap_hold_configurations/tapping_force_hold/config.h new file mode 100644 index 000000000..3b4646338 --- /dev/null +++ b/tests/tap_hold_configurations/tapping_force_hold/config.h | |||
@@ -0,0 +1,21 @@ | |||
1 | /* Copyright 2021 Stefan Kerkmann | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #pragma once | ||
18 | |||
19 | #include "test_common.h" | ||
20 | |||
21 | #define TAPPING_FORCE_HOLD \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/tapping_force_hold/test.mk b/tests/tap_hold_configurations/tapping_force_hold/test.mk new file mode 100644 index 000000000..efecca2c2 --- /dev/null +++ b/tests/tap_hold_configurations/tapping_force_hold/test.mk | |||
@@ -0,0 +1,18 @@ | |||
1 | # Copyright 2021 Stefan Kerkmann | ||
2 | # | ||
3 | # This program is free software: you can redistribute it and/or modify | ||
4 | # it under the terms of the GNU General Public License as published by | ||
5 | # the Free Software Foundation, either version 2 of the License, or | ||
6 | # (at your option) any later version. | ||
7 | # | ||
8 | # This program is distributed in the hope that it will be useful, | ||
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | # GNU General Public License for more details. | ||
12 | # | ||
13 | # You should have received a copy of the GNU General Public License | ||
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | |||
16 | # -------------------------------------------------------------------------------- | ||
17 | # Keep this file, even if it is empty, as a marker that this folder contains tests | ||
18 | # -------------------------------------------------------------------------------- | ||
diff --git a/tests/tap_hold_configurations/tapping_force_hold/test_action_layer.cpp b/tests/tap_hold_configurations/tapping_force_hold/test_action_layer.cpp new file mode 100644 index 000000000..02416eed7 --- /dev/null +++ b/tests/tap_hold_configurations/tapping_force_hold/test_action_layer.cpp | |||
@@ -0,0 +1,81 @@ | |||
1 | /* Copyright 2021 Stefan Kerkmann | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include "keyboard_report_util.hpp" | ||
18 | #include "test_common.hpp" | ||
19 | |||
20 | using testing::_; | ||
21 | using testing::InSequence; | ||
22 | |||
23 | class ActionLayer : public TestFixture {}; | ||
24 | |||
25 | TEST_F(ActionLayer, LayerTapToggleWithToggleWithKeypress) { | ||
26 | TestDriver driver; | ||
27 | KeymapKey layer_key = KeymapKey{0, 0, 0, TT(1)}; | ||
28 | |||
29 | /* These keys must have the same position in the matrix, only the layer is different. */ | ||
30 | KeymapKey regular_key = KeymapKey{0, 1, 0, KC_A}; | ||
31 | set_keymap({layer_key, regular_key, KeymapKey{1, 1, 0, KC_B}}); | ||
32 | |||
33 | /* Tap TT five times . */ | ||
34 | /* TODO: QMK currently sends an empty report even if nothing needs to be reported to the host! */ | ||
35 | /* TODO: Tapping Force Hold breaks TT */ | ||
36 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(10); | ||
37 | |||
38 | layer_key.press(); | ||
39 | run_one_scan_loop(); | ||
40 | layer_key.release(); | ||
41 | run_one_scan_loop(); | ||
42 | expect_layer_state(0); | ||
43 | |||
44 | layer_key.press(); | ||
45 | run_one_scan_loop(); | ||
46 | layer_key.release(); | ||
47 | run_one_scan_loop(); | ||
48 | expect_layer_state(0); | ||
49 | |||
50 | layer_key.press(); | ||
51 | run_one_scan_loop(); | ||
52 | layer_key.release(); | ||
53 | run_one_scan_loop(); | ||
54 | expect_layer_state(0); | ||
55 | |||
56 | layer_key.press(); | ||
57 | run_one_scan_loop(); | ||
58 | layer_key.release(); | ||
59 | run_one_scan_loop(); | ||
60 | expect_layer_state(0); | ||
61 | |||
62 | layer_key.press(); | ||
63 | run_one_scan_loop(); | ||
64 | layer_key.release(); | ||
65 | run_one_scan_loop(); | ||
66 | expect_layer_state(0); | ||
67 | |||
68 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
69 | |||
70 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A))).Times(1); | ||
71 | regular_key.press(); | ||
72 | run_one_scan_loop(); | ||
73 | expect_layer_state(0); | ||
74 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
75 | |||
76 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(1); | ||
77 | regular_key.release(); | ||
78 | run_one_scan_loop(); | ||
79 | expect_layer_state(0); | ||
80 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
81 | } \ No newline at end of file | ||
diff --git a/tests/tap_hold_configurations/tapping_force_hold/test_tap_hold.cpp b/tests/tap_hold_configurations/tapping_force_hold/test_tap_hold.cpp new file mode 100644 index 000000000..cb6842961 --- /dev/null +++ b/tests/tap_hold_configurations/tapping_force_hold/test_tap_hold.cpp | |||
@@ -0,0 +1,215 @@ | |||
1 | |||
2 | /* Copyright 2021 Stefan Kerkmann | ||
3 | * | ||
4 | * This program is free software: you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation, either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include "keyboard_report_util.hpp" | ||
19 | #include "keycode.h" | ||
20 | #include "test_common.hpp" | ||
21 | #include "action_tapping.h" | ||
22 | #include "test_fixture.hpp" | ||
23 | #include "test_keymap_key.hpp" | ||
24 | |||
25 | using testing::_; | ||
26 | using testing::InSequence; | ||
27 | |||
28 | class TappingForceHold : public TestFixture {}; | ||
29 | |||
30 | TEST_F(TappingForceHold, tap_regular_key_while_mod_tap_key_is_held) { | ||
31 | TestDriver driver; | ||
32 | InSequence s; | ||
33 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
34 | auto regular_key = KeymapKey(0, 2, 0, KC_A); | ||
35 | |||
36 | set_keymap({mod_tap_hold_key, regular_key}); | ||
37 | |||
38 | /* Press mod-tap-hold key. */ | ||
39 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
40 | mod_tap_hold_key.press(); | ||
41 | run_one_scan_loop(); | ||
42 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
43 | |||
44 | /* Press regular key. */ | ||
45 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
46 | regular_key.press(); | ||
47 | run_one_scan_loop(); | ||
48 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
49 | |||
50 | /* Release regular key. */ | ||
51 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
52 | regular_key.release(); | ||
53 | run_one_scan_loop(); | ||
54 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
55 | |||
56 | /* Release mod-tap-hold key. */ | ||
57 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
58 | mod_tap_hold_key.release(); | ||
59 | run_one_scan_loop(); | ||
60 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
61 | |||
62 | /* Idle for tapping term of mod tap hold key. */ | ||
63 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
64 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_A))); | ||
65 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
66 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
67 | idle_for(TAPPING_TERM - 3); | ||
68 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
69 | } | ||
70 | |||
71 | TEST_F(TappingForceHold, tap_mod_tap_key_while_mod_tap_key_is_held) { | ||
72 | TestDriver driver; | ||
73 | InSequence s; | ||
74 | auto first_mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
75 | auto second_mod_tap_hold_key = KeymapKey(0, 2, 0, RSFT_T(KC_A)); | ||
76 | |||
77 | set_keymap({first_mod_tap_hold_key, second_mod_tap_hold_key}); | ||
78 | |||
79 | /* Press first mod-tap-hold key */ | ||
80 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
81 | first_mod_tap_hold_key.press(); | ||
82 | run_one_scan_loop(); | ||
83 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
84 | |||
85 | /* Press second tap-hold key */ | ||
86 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
87 | second_mod_tap_hold_key.press(); | ||
88 | run_one_scan_loop(); | ||
89 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
90 | |||
91 | /* Release second tap-hold key */ | ||
92 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
93 | second_mod_tap_hold_key.release(); | ||
94 | run_one_scan_loop(); | ||
95 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
96 | |||
97 | /* Release first mod-tap-hold key */ | ||
98 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
99 | first_mod_tap_hold_key.release(); | ||
100 | run_one_scan_loop(); | ||
101 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
102 | |||
103 | /* Idle for tapping term of first mod tap hold key. */ | ||
104 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
105 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT, KC_A))); | ||
106 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSFT))); | ||
107 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
108 | idle_for(TAPPING_TERM - 3); | ||
109 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
110 | } | ||
111 | |||
112 | TEST_F(TappingForceHold, tap_regular_key_while_layer_tap_key_is_held) { | ||
113 | TestDriver driver; | ||
114 | InSequence s; | ||
115 | auto layer_tap_hold_key = KeymapKey(0, 1, 0, LT(1, KC_P)); | ||
116 | auto regular_key = KeymapKey(0, 2, 0, KC_A); | ||
117 | auto layer_key = KeymapKey(1, 2, 0, KC_B); | ||
118 | |||
119 | set_keymap({layer_tap_hold_key, regular_key, layer_key}); | ||
120 | |||
121 | /* Press layer-tap-hold key */ | ||
122 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
123 | layer_tap_hold_key.press(); | ||
124 | run_one_scan_loop(); | ||
125 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
126 | |||
127 | /* Press regular key */ | ||
128 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
129 | regular_key.press(); | ||
130 | run_one_scan_loop(); | ||
131 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
132 | |||
133 | /* Release regular key */ | ||
134 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
135 | regular_key.release(); | ||
136 | run_one_scan_loop(); | ||
137 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
138 | |||
139 | /* Release layer-tap-hold key */ | ||
140 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
141 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_A, KC_P))); | ||
142 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
143 | EXPECT_CALL(driver, send_keyboard_mock(_)); | ||
144 | layer_tap_hold_key.release(); | ||
145 | run_one_scan_loop(); | ||
146 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
147 | } | ||
148 | |||
149 | TEST_F(TappingForceHold, tap_mod_tap_hold_key_two_times) { | ||
150 | TestDriver driver; | ||
151 | InSequence s; | ||
152 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
153 | |||
154 | set_keymap({mod_tap_hold_key}); | ||
155 | |||
156 | /* Press mod-tap-hold key. */ | ||
157 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
158 | mod_tap_hold_key.press(); | ||
159 | run_one_scan_loop(); | ||
160 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
161 | |||
162 | /* Release mod-tap-hold key. */ | ||
163 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
164 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
165 | mod_tap_hold_key.release(); | ||
166 | run_one_scan_loop(); | ||
167 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
168 | |||
169 | /* Press mod-tap-hold key again. */ | ||
170 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
171 | mod_tap_hold_key.press(); | ||
172 | run_one_scan_loop(); | ||
173 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
174 | |||
175 | /* Release mod-tap-hold key. */ | ||
176 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
177 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
178 | mod_tap_hold_key.release(); | ||
179 | run_one_scan_loop(); | ||
180 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
181 | } | ||
182 | |||
183 | TEST_F(TappingForceHold, tap_mod_tap_hold_key_twice_and_hold_on_second_time) { | ||
184 | TestDriver driver; | ||
185 | InSequence s; | ||
186 | auto mod_tap_hold_key = KeymapKey(0, 1, 0, SFT_T(KC_P)); | ||
187 | |||
188 | set_keymap({mod_tap_hold_key}); | ||
189 | |||
190 | /* Press mod-tap-hold key. */ | ||
191 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
192 | mod_tap_hold_key.press(); | ||
193 | run_one_scan_loop(); | ||
194 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
195 | |||
196 | /* Release mod-tap-hold key. */ | ||
197 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_P))); | ||
198 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
199 | mod_tap_hold_key.release(); | ||
200 | run_one_scan_loop(); | ||
201 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
202 | |||
203 | /* Press mod-tap-hold key again. */ | ||
204 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
205 | mod_tap_hold_key.press(); | ||
206 | idle_for(TAPPING_TERM); | ||
207 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
208 | |||
209 | /* Release mod-tap-hold key. */ | ||
210 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport(KC_LSHIFT))); | ||
211 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())); | ||
212 | mod_tap_hold_key.release(); | ||
213 | run_one_scan_loop(); | ||
214 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
215 | } | ||
diff --git a/tests/basic/rules.mk b/tests/test_common/build.mk index 9fb5d4361..aeb305785 100644 --- a/tests/basic/rules.mk +++ b/tests/test_common/build.mk | |||
@@ -1,4 +1,4 @@ | |||
1 | # Copyright 2017 Fred Sundvik | 1 | # Copyright 2021 Stefan Kerkmann |
2 | # | 2 | # |
3 | # This program is free software: you can redistribute it and/or modify | 3 | # This program is free software: you can redistribute it and/or modify |
4 | # it under the terms of the GNU General Public License as published by | 4 | # it under the terms of the GNU General Public License as published by |
@@ -13,4 +13,4 @@ | |||
13 | # You should have received a copy of the GNU General Public License | 13 | # You should have received a copy of the GNU General Public License |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | 15 | ||
16 | CUSTOM_MATRIX=yes | 16 | CUSTOM_MATRIX=yes \ No newline at end of file |
diff --git a/tests/test_common/keyboard_report_util.cpp b/tests/test_common/keyboard_report_util.cpp index f73cf239e..e148c76be 100644 --- a/tests/test_common/keyboard_report_util.cpp +++ b/tests/test_common/keyboard_report_util.cpp | |||
@@ -44,16 +44,21 @@ bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) { | |||
44 | return lhs.mods == rhs.mods && lhskeys == rhskeys; | 44 | return lhs.mods == rhs.mods && lhskeys == rhskeys; |
45 | } | 45 | } |
46 | 46 | ||
47 | std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) { | 47 | std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& report) { |
48 | stream << "Keyboard report:" << std::endl; | 48 | auto keys = get_keys(report); |
49 | stream << "Mods: " << (uint32_t)value.mods << std::endl; | 49 | |
50 | stream << "Keys: "; | ||
51 | // TODO: This should probably print friendly names for the keys | 50 | // TODO: This should probably print friendly names for the keys |
52 | for (uint32_t k : get_keys(value)) { | 51 | stream << "Keyboard Report: Mods (" << (uint32_t)report.mods << ") Keys ("; |
53 | stream << k << " "; | 52 | |
53 | for (auto key = keys.cbegin(); key != keys.cend();) { | ||
54 | stream << +(*key); | ||
55 | key++; | ||
56 | if (key != keys.cend()) { | ||
57 | stream << ","; | ||
58 | } | ||
54 | } | 59 | } |
55 | stream << std::endl; | 60 | |
56 | return stream; | 61 | return stream << ")" << std::endl; |
57 | } | 62 | } |
58 | 63 | ||
59 | KeyboardReportMatcher::KeyboardReportMatcher(const std::vector<uint8_t>& keys) { | 64 | KeyboardReportMatcher::KeyboardReportMatcher(const std::vector<uint8_t>& keys) { |
diff --git a/tests/test_common/keymap.c b/tests/test_common/keymap.c new file mode 100644 index 000000000..fc3a56a00 --- /dev/null +++ b/tests/test_common/keymap.c | |||
@@ -0,0 +1,33 @@ | |||
1 | /* Copyright 2017 Fred Sundvik | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include "quantum.h" | ||
18 | |||
19 | // clang-format off | ||
20 | |||
21 | const uint16_t PROGMEM | ||
22 | keymaps[][MATRIX_ROWS][MATRIX_COLS] = | ||
23 | { | ||
24 | [0] = | ||
25 | { | ||
26 | {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, | ||
27 | {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, | ||
28 | {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, | ||
29 | {KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO}, | ||
30 | }, | ||
31 | }; | ||
32 | |||
33 | // clang-format on | ||
diff --git a/tests/test_common/test_common.h b/tests/test_common/test_common.h new file mode 100644 index 000000000..19ffcddce --- /dev/null +++ b/tests/test_common/test_common.h | |||
@@ -0,0 +1,4 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #define MATRIX_ROWS 4 | ||
4 | #define MATRIX_COLS 10 \ No newline at end of file | ||
diff --git a/tests/test_common/test_driver.cpp b/tests/test_common/test_driver.cpp index 84e249d83..2fa2b6a2e 100644 --- a/tests/test_common/test_driver.cpp +++ b/tests/test_common/test_driver.cpp | |||
@@ -27,7 +27,10 @@ TestDriver::~TestDriver() { m_this = nullptr; } | |||
27 | 27 | ||
28 | uint8_t TestDriver::keyboard_leds(void) { return m_this->m_leds; } | 28 | uint8_t TestDriver::keyboard_leds(void) { return m_this->m_leds; } |
29 | 29 | ||
30 | void TestDriver::send_keyboard(report_keyboard_t* report) { m_this->send_keyboard_mock(*report); } | 30 | void TestDriver::send_keyboard(report_keyboard_t* report) { |
31 | test_logger.trace() << *report; | ||
32 | m_this->send_keyboard_mock(*report); | ||
33 | } | ||
31 | 34 | ||
32 | void TestDriver::send_mouse(report_mouse_t* report) { m_this->send_mouse_mock(*report); } | 35 | void TestDriver::send_mouse(report_mouse_t* report) { m_this->send_mouse_mock(*report); } |
33 | 36 | ||
diff --git a/tests/test_common/test_driver.hpp b/tests/test_common/test_driver.hpp index f86308df9..f9197b363 100644 --- a/tests/test_common/test_driver.hpp +++ b/tests/test_common/test_driver.hpp | |||
@@ -20,25 +20,26 @@ | |||
20 | #include <stdint.h> | 20 | #include <stdint.h> |
21 | #include "host.h" | 21 | #include "host.h" |
22 | #include "keyboard_report_util.hpp" | 22 | #include "keyboard_report_util.hpp" |
23 | 23 | #include "test_logger.hpp" | |
24 | 24 | ||
25 | class TestDriver { | 25 | class TestDriver { |
26 | public: | 26 | public: |
27 | TestDriver(); | 27 | TestDriver(); |
28 | ~TestDriver(); | 28 | ~TestDriver(); |
29 | void set_leds(uint8_t leds) { m_leds = leds; } | 29 | void set_leds(uint8_t leds) { m_leds = leds; } |
30 | 30 | ||
31 | MOCK_METHOD1(send_keyboard_mock, void (report_keyboard_t&)); | 31 | MOCK_METHOD1(send_keyboard_mock, void(report_keyboard_t&)); |
32 | MOCK_METHOD1(send_mouse_mock, void (report_mouse_t&)); | 32 | MOCK_METHOD1(send_mouse_mock, void(report_mouse_t&)); |
33 | MOCK_METHOD1(send_system_mock, void (uint16_t)); | 33 | MOCK_METHOD1(send_system_mock, void(uint16_t)); |
34 | MOCK_METHOD1(send_consumer_mock, void (uint16_t)); | 34 | MOCK_METHOD1(send_consumer_mock, void(uint16_t)); |
35 | private: | 35 | |
36 | static uint8_t keyboard_leds(void); | 36 | private: |
37 | static void send_keyboard(report_keyboard_t *report); | 37 | static uint8_t keyboard_leds(void); |
38 | static void send_mouse(report_mouse_t* report); | 38 | static void send_keyboard(report_keyboard_t* report); |
39 | static void send_system(uint16_t data); | 39 | static void send_mouse(report_mouse_t* report); |
40 | static void send_consumer(uint16_t data); | 40 | static void send_system(uint16_t data); |
41 | host_driver_t m_driver; | 41 | static void send_consumer(uint16_t data); |
42 | uint8_t m_leds = 0; | 42 | host_driver_t m_driver; |
43 | uint8_t m_leds = 0; | ||
43 | static TestDriver* m_this; | 44 | static TestDriver* m_this; |
44 | }; | 45 | }; |
diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp index e041df712..0601b1719 100644 --- a/tests/test_common/test_fixture.cpp +++ b/tests/test_common/test_fixture.cpp | |||
@@ -1,26 +1,48 @@ | |||
1 | #include "test_fixture.hpp" | 1 | #include "test_fixture.hpp" |
2 | #include <algorithm> | ||
3 | #include <cstdint> | ||
4 | #include <cstdio> | ||
5 | #include <cstdlib> | ||
6 | #include "gmock/gmock-cardinalities.h" | ||
2 | #include "gmock/gmock.h" | 7 | #include "gmock/gmock.h" |
8 | #include "gtest/gtest.h" | ||
9 | #include "keyboard_report_util.hpp" | ||
10 | #include "keycode.h" | ||
3 | #include "test_driver.hpp" | 11 | #include "test_driver.hpp" |
12 | #include "test_logger.hpp" | ||
4 | #include "test_matrix.h" | 13 | #include "test_matrix.h" |
5 | #include "keyboard.h" | 14 | #include "test_keymap_key.hpp" |
6 | #include "action.h" | ||
7 | #include "action_tapping.h" | ||
8 | 15 | ||
9 | extern "C" { | 16 | extern "C" { |
17 | #include "action.h" | ||
18 | #include "action_tapping.h" | ||
19 | #include "action_util.h" | ||
20 | #include "action_layer.h" | ||
10 | #include "debug.h" | 21 | #include "debug.h" |
11 | #include "eeconfig.h" | 22 | #include "eeconfig.h" |
12 | #include "action_layer.h" | 23 | #include "keyboard.h" |
24 | #include "keymap.h" | ||
13 | 25 | ||
14 | void set_time(uint32_t t); | 26 | void set_time(uint32_t t); |
15 | void advance_time(uint32_t ms); | 27 | void advance_time(uint32_t ms); |
16 | } | 28 | } |
17 | 29 | ||
18 | using testing::_; | 30 | using testing::_; |
19 | using testing::AnyNumber; | 31 | |
20 | using testing::Between; | 32 | /* This is used for dynamic dispatching keymap_key_to_keycode calls to the current active test_fixture. */ |
21 | using testing::Return; | 33 | TestFixture* TestFixture::m_this = nullptr; |
34 | |||
35 | /* Override weak QMK function to allow the usage of isolated per-test keymaps in unit-tests. | ||
36 | * The actual call is dynamicaly dispatched to the current active test fixture, which in turn has it's own keymap. */ | ||
37 | extern "C" uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t position) { | ||
38 | uint16_t keycode; | ||
39 | TestFixture::m_this->get_keycode(layer, position, &keycode); | ||
40 | return keycode; | ||
41 | } | ||
22 | 42 | ||
23 | void TestFixture::SetUpTestCase() { | 43 | void TestFixture::SetUpTestCase() { |
44 | test_logger.info() << "TestFixture setup-up start." << std::endl; | ||
45 | |||
24 | // The following is enough to bootstrap the values set in main | 46 | // The following is enough to bootstrap the values set in main |
25 | eeconfig_init_quantum(); | 47 | eeconfig_init_quantum(); |
26 | eeconfig_update_debug(debug_config.raw); | 48 | eeconfig_update_debug(debug_config.raw); |
@@ -28,23 +50,99 @@ void TestFixture::SetUpTestCase() { | |||
28 | TestDriver driver; | 50 | TestDriver driver; |
29 | EXPECT_CALL(driver, send_keyboard_mock(_)); | 51 | EXPECT_CALL(driver, send_keyboard_mock(_)); |
30 | keyboard_init(); | 52 | keyboard_init(); |
53 | |||
54 | test_logger.info() << "TestFixture setup-up end." << std::endl; | ||
31 | } | 55 | } |
32 | 56 | ||
33 | void TestFixture::TearDownTestCase() {} | 57 | void TestFixture::TearDownTestCase() {} |
34 | 58 | ||
35 | TestFixture::TestFixture() {} | 59 | TestFixture::TestFixture() { m_this = this; } |
36 | 60 | ||
37 | TestFixture::~TestFixture() { | 61 | TestFixture::~TestFixture() { |
62 | test_logger.info() << "TestFixture clean-up start." << std::endl; | ||
38 | TestDriver driver; | 63 | TestDriver driver; |
39 | // Run for a while to make sure all keys are completely released | 64 | |
40 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(AnyNumber()); | 65 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(2); |
41 | layer_clear(); | 66 | |
67 | /* Reset keyboard state. */ | ||
42 | clear_all_keys(); | 68 | clear_all_keys(); |
43 | idle_for(TAPPING_TERM + 10); | 69 | |
70 | clear_keyboard(); | ||
71 | |||
72 | clear_oneshot_mods(); | ||
73 | clear_oneshot_locked_mods(); | ||
74 | reset_oneshot_layer(); | ||
75 | |||
76 | layer_clear(); | ||
77 | |||
78 | #if defined(SWAP_HANDS_ENABLE) | ||
79 | clear_oneshot_swaphands(); | ||
80 | #endif | ||
81 | |||
82 | idle_for(TAPPING_TERM * 10); | ||
83 | testing::Mock::VerifyAndClearExpectations(&driver); | ||
84 | |||
85 | /* Verify that the matrix really is cleared */ | ||
86 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(0); | ||
87 | idle_for(TAPPING_TERM * 10); | ||
44 | testing::Mock::VerifyAndClearExpectations(&driver); | 88 | testing::Mock::VerifyAndClearExpectations(&driver); |
45 | // Verify that the matrix really is cleared | 89 | |
46 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(0); | 90 | m_this = nullptr; |
47 | idle_for(TAPPING_TERM + 10); | 91 | |
92 | test_logger.info() << "TestFixture clean-up end." << std::endl; | ||
93 | |||
94 | print_test_log(); | ||
95 | } | ||
96 | |||
97 | void TestFixture::add_key(KeymapKey key) { | ||
98 | if (this->find_key(key.layer, key.position)) { | ||
99 | FAIL() << "Key is already mapped for layer " << +key.layer << " and (column,row) (" << +key.position.col << "," << +key.position.row << ")"; | ||
100 | } | ||
101 | |||
102 | this->keymap.push_back(key); | ||
103 | } | ||
104 | |||
105 | void TestFixture::set_keymap(std::initializer_list<KeymapKey> keys) { | ||
106 | this->keymap.clear(); | ||
107 | for (auto& key : keys) { | ||
108 | add_key(key); | ||
109 | } | ||
110 | } | ||
111 | |||
112 | const KeymapKey* TestFixture::find_key(layer_t layer, keypos_t position) const { | ||
113 | auto keymap_key_predicate = [&](KeymapKey candidate) { return candidate.layer == layer && candidate.position.col == position.col && candidate.position.row == position.row; }; | ||
114 | |||
115 | auto result = std::find_if(this->keymap.begin(), this->keymap.end(), keymap_key_predicate); | ||
116 | |||
117 | if (result != std::end(this->keymap)) { | ||
118 | return &(*result); | ||
119 | } | ||
120 | return nullptr; | ||
121 | } | ||
122 | |||
123 | void TestFixture::get_keycode(const layer_t layer, const keypos_t position, uint16_t* result) const { | ||
124 | bool key_is_out_of_bounds = position.col >= MATRIX_COLS && position.row >= MATRIX_ROWS; | ||
125 | |||
126 | if (key_is_out_of_bounds) { | ||
127 | /* See if this is done in hardware as well, because this is 100% out of bounds reads on all QMK keebs out there. */ | ||
128 | auto msg = [&]() { | ||
129 | std::stringstream msg; | ||
130 | msg << "Keycode for position (" << +position.col << "," << +position.row << ") requested! This is out of bounds." << std::endl; | ||
131 | return msg.str(); | ||
132 | }(); | ||
133 | |||
134 | *result = KC_NO; | ||
135 | test_logger.error() << msg; | ||
136 | EXPECT_FALSE(key_is_out_of_bounds) << msg; | ||
137 | return; | ||
138 | } | ||
139 | |||
140 | if (auto key = this->find_key(layer, position)) { | ||
141 | *result = key->code; | ||
142 | return; | ||
143 | } | ||
144 | |||
145 | FAIL() << "No key is mapped for layer " << +layer << " and (column,row) " << +position.col << "," << +position.row << ")"; | ||
48 | } | 146 | } |
49 | 147 | ||
50 | void TestFixture::run_one_scan_loop() { | 148 | void TestFixture::run_one_scan_loop() { |
@@ -57,3 +155,17 @@ void TestFixture::idle_for(unsigned time) { | |||
57 | run_one_scan_loop(); | 155 | run_one_scan_loop(); |
58 | } | 156 | } |
59 | } | 157 | } |
158 | |||
159 | void TestFixture::print_test_log() const { | ||
160 | const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info(); | ||
161 | if (HasFailure()) { | ||
162 | std::cerr << test_info->test_case_name() << "." << test_info->name() << " failed!" << std::endl; | ||
163 | test_logger.print_log(); | ||
164 | } | ||
165 | test_logger.reset(); | ||
166 | } | ||
167 | |||
168 | void TestFixture::expect_layer_state(layer_t layer_state) const { | ||
169 | test_logger.trace() << "Layer state: (" << +layer_state << ") Highest layer bit: (" << +get_highest_layer(layer_state) << ")" << std::endl; | ||
170 | EXPECT_TRUE(layer_state_is(layer_state)); | ||
171 | } | ||
diff --git a/tests/test_common/test_fixture.hpp b/tests/test_common/test_fixture.hpp index 340503665..73b5d8d3e 100644 --- a/tests/test_common/test_fixture.hpp +++ b/tests/test_common/test_fixture.hpp | |||
@@ -16,15 +16,34 @@ | |||
16 | 16 | ||
17 | #pragma once | 17 | #pragma once |
18 | 18 | ||
19 | #include <cstdint> | ||
20 | #include <unordered_map> | ||
21 | #include <optional> | ||
19 | #include "gtest/gtest.h" | 22 | #include "gtest/gtest.h" |
23 | #include "keyboard.h" | ||
24 | #include "test_keymap_key.hpp" | ||
20 | 25 | ||
21 | class TestFixture : public testing::Test { | 26 | class TestFixture : public testing::Test { |
22 | public: | 27 | public: |
28 | static TestFixture* m_this; | ||
29 | |||
23 | TestFixture(); | 30 | TestFixture(); |
24 | ~TestFixture(); | 31 | ~TestFixture(); |
25 | static void SetUpTestCase(); | 32 | static void SetUpTestCase(); |
26 | static void TearDownTestCase(); | 33 | static void TearDownTestCase(); |
27 | 34 | ||
35 | void set_keymap(std::initializer_list<KeymapKey> keycodes); | ||
36 | void add_key(const KeymapKey key); | ||
37 | |||
38 | const KeymapKey* find_key(const layer_t layer_t, const keypos_t position) const; | ||
39 | void get_keycode(const layer_t layer, const keypos_t position, uint16_t* result) const; | ||
40 | |||
28 | void run_one_scan_loop(); | 41 | void run_one_scan_loop(); |
29 | void idle_for(unsigned ms); | 42 | void idle_for(unsigned ms); |
43 | |||
44 | void expect_layer_state(layer_t layer) const; | ||
45 | |||
46 | protected: | ||
47 | void print_test_log() const; | ||
48 | std::vector<KeymapKey> keymap; | ||
30 | }; | 49 | }; |
diff --git a/tests/test_common/test_keymap_key.cpp b/tests/test_common/test_keymap_key.cpp new file mode 100644 index 000000000..878ae097b --- /dev/null +++ b/tests/test_common/test_keymap_key.cpp | |||
@@ -0,0 +1,30 @@ | |||
1 | /* Copyright 2021 Stefan Kerkmann | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include "test_keymap_key.hpp" | ||
18 | #include "test_logger.hpp" | ||
19 | #include "gtest/gtest-message.h" | ||
20 | #include "gtest/gtest.h" | ||
21 | |||
22 | void KeymapKey::press() { | ||
23 | test_logger.trace() << "Key pressed: (" << +this->position.col << "," << +this->position.row << ")" << std::endl; | ||
24 | press_key(this->position.col, this->position.row); | ||
25 | } | ||
26 | |||
27 | void KeymapKey::release() { | ||
28 | test_logger.trace() << "Key released: (" << +this->position.col << "," << +this->position.row << ")" << std::endl; | ||
29 | release_key(this->position.col, this->position.row); | ||
30 | } \ No newline at end of file | ||
diff --git a/tests/test_common/test_keymap_key.hpp b/tests/test_common/test_keymap_key.hpp new file mode 100644 index 000000000..7861cb4a3 --- /dev/null +++ b/tests/test_common/test_keymap_key.hpp | |||
@@ -0,0 +1,46 @@ | |||
1 | /* Copyright 2021 Stefan Kerkmann | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #pragma once | ||
18 | |||
19 | extern "C" { | ||
20 | #include "keyboard.h" | ||
21 | #include "test_matrix.h" | ||
22 | } | ||
23 | |||
24 | #include <cassert> | ||
25 | |||
26 | typedef uint8_t layer_t; | ||
27 | |||
28 | struct KeymapKey { | ||
29 | KeymapKey(layer_t layer, uint8_t col, uint8_t row, uint16_t keycode) : layer(layer), position({.col = col, .row = row}), code(keycode), report_code(keycode) { validate(); } | ||
30 | KeymapKey(layer_t layer, uint8_t col, uint8_t row, uint16_t keycode, uint16_t report_code) : layer(layer), position({.col = col, .row = row}), code(keycode), report_code(report_code) { validate(); } | ||
31 | |||
32 | void press(); | ||
33 | void release(); | ||
34 | |||
35 | const layer_t layer; | ||
36 | const keypos_t position; | ||
37 | const uint16_t code; | ||
38 | /* Sometimes the keycode does not match the code that is send in the usb report, so we provide it here. */ | ||
39 | const uint16_t report_code; | ||
40 | |||
41 | private: | ||
42 | void validate() { | ||
43 | assert(position.col <= MATRIX_COLS); | ||
44 | assert(position.row <= MATRIX_ROWS); | ||
45 | } | ||
46 | }; \ No newline at end of file | ||
diff --git a/tests/test_common/test_logger.cpp b/tests/test_common/test_logger.cpp new file mode 100644 index 000000000..959fdde5e --- /dev/null +++ b/tests/test_common/test_logger.cpp | |||
@@ -0,0 +1,39 @@ | |||
1 | /* Copyright 2021 Stefan Kerkmann | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include <iostream> | ||
18 | #include "test_logger.hpp" | ||
19 | |||
20 | TestLogger test_logger; | ||
21 | |||
22 | TestLogger& TestLogger::info() { | ||
23 | *this << "[ INFO ] "; | ||
24 | return *this; | ||
25 | } | ||
26 | |||
27 | TestLogger& TestLogger::trace() { | ||
28 | *this << "[ TRACE ] "; | ||
29 | return *this; | ||
30 | } | ||
31 | |||
32 | TestLogger& TestLogger::error() { | ||
33 | *this << "[ ERROR ] "; | ||
34 | return *this; | ||
35 | } | ||
36 | |||
37 | void TestLogger::reset() { this->m_log.str(""); }; | ||
38 | |||
39 | void TestLogger::print_log() { std::cerr << this->m_log.str(); } | ||
diff --git a/tests/test_common/test_logger.hpp b/tests/test_common/test_logger.hpp new file mode 100644 index 000000000..348af7fab --- /dev/null +++ b/tests/test_common/test_logger.hpp | |||
@@ -0,0 +1,35 @@ | |||
1 | /* Copyright 2021 Stefan Kerkmann | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #pragma once | ||
18 | |||
19 | #include <ostream> | ||
20 | #include <sstream> | ||
21 | |||
22 | class TestLogger : public std::ostream { | ||
23 | public: | ||
24 | TestLogger() : std::ostream(&m_log){}; | ||
25 | TestLogger& info(); | ||
26 | TestLogger& trace(); | ||
27 | TestLogger& error(); | ||
28 | void print_log(); | ||
29 | void reset(); | ||
30 | |||
31 | private: | ||
32 | std::stringbuf m_log; | ||
33 | }; | ||
34 | |||
35 | extern TestLogger test_logger; \ No newline at end of file | ||