diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/leader/config.h | 6 | ||||
-rw-r--r-- | tests/leader/leader_no_initial_timeout/config.h | 8 | ||||
-rw-r--r-- | tests/leader/leader_no_initial_timeout/test.mk | 7 | ||||
-rw-r--r-- | tests/leader/leader_no_initial_timeout/test_leader_no_initial_timeout.cpp | 48 | ||||
-rw-r--r-- | tests/leader/leader_per_key_timeout/config.h | 5 | ||||
-rw-r--r-- | tests/leader/leader_per_key_timeout/test.mk | 7 | ||||
-rw-r--r-- | tests/leader/leader_per_key_timeout/test_leader_per_key_timeout.cpp | 40 | ||||
-rw-r--r-- | tests/leader/leader_sequences.c | 26 | ||||
-rw-r--r-- | tests/leader/leader_strict_key_processing/config.h | 8 | ||||
-rw-r--r-- | tests/leader/leader_strict_key_processing/test.mk | 7 | ||||
-rw-r--r-- | tests/leader/leader_strict_key_processing/test_leader_strict_key_processing.cpp | 45 | ||||
-rw-r--r-- | tests/leader/test.mk | 7 | ||||
-rw-r--r-- | tests/leader/test_leader.cpp | 224 |
13 files changed, 438 insertions, 0 deletions
diff --git a/tests/leader/config.h b/tests/leader/config.h new file mode 100644 index 0000000000..e8005d4b6d --- /dev/null +++ b/tests/leader/config.h @@ -0,0 +1,6 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "test_common.h" diff --git a/tests/leader/leader_no_initial_timeout/config.h b/tests/leader/leader_no_initial_timeout/config.h new file mode 100644 index 0000000000..73b280bce9 --- /dev/null +++ b/tests/leader/leader_no_initial_timeout/config.h @@ -0,0 +1,8 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "test_common.h" + +#define LEADER_NO_TIMEOUT diff --git a/tests/leader/leader_no_initial_timeout/test.mk b/tests/leader/leader_no_initial_timeout/test.mk new file mode 100644 index 0000000000..635c04ee92 --- /dev/null +++ b/tests/leader/leader_no_initial_timeout/test.mk @@ -0,0 +1,7 @@ +# -------------------------------------------------------------------------------- +# Keep this file, even if it is empty, as a marker that this folder contains tests +# -------------------------------------------------------------------------------- + +LEADER_ENABLE = yes + +SRC += ../leader_sequences.c diff --git a/tests/leader/leader_no_initial_timeout/test_leader_no_initial_timeout.cpp b/tests/leader/leader_no_initial_timeout/test_leader_no_initial_timeout.cpp new file mode 100644 index 0000000000..c23af65344 --- /dev/null +++ b/tests/leader/leader_no_initial_timeout/test_leader_no_initial_timeout.cpp @@ -0,0 +1,48 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "keyboard_report_util.hpp" +#include "keycode.h" +#include "test_common.hpp" +#include "test_keymap_key.hpp" + +using testing::_; + +class Leader : public TestFixture {}; + +TEST_F(Leader, does_not_timeout_until_next_key_pressed) { + TestDriver driver; + + auto key_leader = KeymapKey(0, 0, 0, QK_LEADER); + auto key_a = KeymapKey(0, 1, 0, KC_A); + + set_keymap({key_leader, key_a}); + + EXPECT_EQ(leader_sequence_active(), false); + + EXPECT_NO_REPORT(driver); + tap_key(key_leader); + + EXPECT_EQ(leader_sequence_active(), true); + + idle_for(1000); + + EXPECT_EQ(leader_sequence_active(), true); + EXPECT_EQ(leader_sequence_timed_out(), false); + + EXPECT_REPORT(driver, (KC_1)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_a); + + EXPECT_EQ(leader_sequence_active(), true); + EXPECT_EQ(leader_sequence_timed_out(), false); + + idle_for(300); + + EXPECT_EQ(leader_sequence_active(), false); + EXPECT_EQ(leader_sequence_timed_out(), true); + + EXPECT_REPORT(driver, (KC_A)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_a); +} diff --git a/tests/leader/leader_per_key_timeout/config.h b/tests/leader/leader_per_key_timeout/config.h new file mode 100644 index 0000000000..045e7c1a57 --- /dev/null +++ b/tests/leader/leader_per_key_timeout/config.h @@ -0,0 +1,5 @@ +#pragma once + +#include "test_common.h" + +#define LEADER_PER_KEY_TIMING diff --git a/tests/leader/leader_per_key_timeout/test.mk b/tests/leader/leader_per_key_timeout/test.mk new file mode 100644 index 0000000000..635c04ee92 --- /dev/null +++ b/tests/leader/leader_per_key_timeout/test.mk @@ -0,0 +1,7 @@ +# -------------------------------------------------------------------------------- +# Keep this file, even if it is empty, as a marker that this folder contains tests +# -------------------------------------------------------------------------------- + +LEADER_ENABLE = yes + +SRC += ../leader_sequences.c diff --git a/tests/leader/leader_per_key_timeout/test_leader_per_key_timeout.cpp b/tests/leader/leader_per_key_timeout/test_leader_per_key_timeout.cpp new file mode 100644 index 0000000000..a1e9eb3c77 --- /dev/null +++ b/tests/leader/leader_per_key_timeout/test_leader_per_key_timeout.cpp @@ -0,0 +1,40 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "keyboard_report_util.hpp" +#include "keycode.h" +#include "test_common.hpp" +#include "test_keymap_key.hpp" + +using testing::_; + +class Leader : public TestFixture {}; + +TEST_F(Leader, does_not_timeout_during_sequence) { + TestDriver driver; + + auto key_leader = KeymapKey(0, 0, 0, QK_LEADER); + auto key_a = KeymapKey(0, 1, 0, KC_A); + auto key_b = KeymapKey(0, 2, 0, KC_B); + auto key_c = KeymapKey(0, 3, 0, KC_C); + + set_keymap({key_leader, key_a, key_b, key_c}); + + tap_key(key_leader); + + EXPECT_NO_REPORT(driver); + tap_key(key_a); + + idle_for(150); + + EXPECT_NO_REPORT(driver); + tap_key(key_b); + + idle_for(150); + + EXPECT_REPORT(driver, (KC_3)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_c); + + idle_for(300); +} diff --git a/tests/leader/leader_sequences.c b/tests/leader/leader_sequences.c new file mode 100644 index 0000000000..39e23623b3 --- /dev/null +++ b/tests/leader/leader_sequences.c @@ -0,0 +1,26 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "quantum.h" + +void leader_end_user(void) { + if (leader_sequence_one_key(KC_A)) { + tap_code(KC_1); + } + + if (leader_sequence_two_keys(KC_A, KC_B)) { + tap_code(KC_2); + } + + if (leader_sequence_three_keys(KC_A, KC_B, KC_C)) { + tap_code(KC_3); + } + + if (leader_sequence_four_keys(KC_A, KC_B, KC_C, KC_D)) { + tap_code(KC_4); + } + + if (leader_sequence_five_keys(KC_A, KC_B, KC_C, KC_D, KC_E)) { + tap_code(KC_5); + } +} diff --git a/tests/leader/leader_strict_key_processing/config.h b/tests/leader/leader_strict_key_processing/config.h new file mode 100644 index 0000000000..cca5ed0458 --- /dev/null +++ b/tests/leader/leader_strict_key_processing/config.h @@ -0,0 +1,8 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "test_common.h" + +#define LEADER_KEY_STRICT_KEY_PROCESSING diff --git a/tests/leader/leader_strict_key_processing/test.mk b/tests/leader/leader_strict_key_processing/test.mk new file mode 100644 index 0000000000..635c04ee92 --- /dev/null +++ b/tests/leader/leader_strict_key_processing/test.mk @@ -0,0 +1,7 @@ +# -------------------------------------------------------------------------------- +# Keep this file, even if it is empty, as a marker that this folder contains tests +# -------------------------------------------------------------------------------- + +LEADER_ENABLE = yes + +SRC += ../leader_sequences.c diff --git a/tests/leader/leader_strict_key_processing/test_leader_strict_key_processing.cpp b/tests/leader/leader_strict_key_processing/test_leader_strict_key_processing.cpp new file mode 100644 index 0000000000..de6bcf0fce --- /dev/null +++ b/tests/leader/leader_strict_key_processing/test_leader_strict_key_processing.cpp @@ -0,0 +1,45 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "keyboard_report_util.hpp" +#include "keycode.h" +#include "test_common.hpp" +#include "test_keymap_key.hpp" + +using testing::_; + +class Leader : public TestFixture {}; + +TEST_F(Leader, does_not_extract_mod_tap_keycode) { + TestDriver driver; + + auto key_leader = KeymapKey(0, 0, 0, QK_LEADER); + auto key_mt = KeymapKey(0, 1, 0, LSFT_T(KC_A)); + + set_keymap({key_leader, key_mt}); + + tap_key(key_leader); + + EXPECT_NO_REPORT(driver); + tap_key(key_mt); + + EXPECT_EQ(leader_sequence_one_key(KC_A), false); + EXPECT_EQ(leader_sequence_one_key(LSFT_T(KC_A)), true); +} + +TEST_F(Leader, does_not_extract_layer_tap_keycode) { + TestDriver driver; + + auto key_leader = KeymapKey(0, 0, 0, QK_LEADER); + auto key_lt = KeymapKey(0, 1, 0, LT(1, KC_A)); + + set_keymap({key_leader, key_lt}); + + tap_key(key_leader); + + EXPECT_NO_REPORT(driver); + tap_key(key_lt); + + EXPECT_EQ(leader_sequence_one_key(KC_A), false); + EXPECT_EQ(leader_sequence_one_key(LT(1, KC_A)), true); +} diff --git a/tests/leader/test.mk b/tests/leader/test.mk new file mode 100644 index 0000000000..bae8bfcc41 --- /dev/null +++ b/tests/leader/test.mk @@ -0,0 +1,7 @@ +# -------------------------------------------------------------------------------- +# Keep this file, even if it is empty, as a marker that this folder contains tests +# -------------------------------------------------------------------------------- + +LEADER_ENABLE = yes + +SRC += leader_sequences.c diff --git a/tests/leader/test_leader.cpp b/tests/leader/test_leader.cpp new file mode 100644 index 0000000000..7349d2f89f --- /dev/null +++ b/tests/leader/test_leader.cpp @@ -0,0 +1,224 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "keyboard_report_util.hpp" +#include "keycode.h" +#include "test_common.hpp" +#include "test_keymap_key.hpp" + +using testing::_; + +class Leader : public TestFixture {}; + +TEST_F(Leader, triggers_one_key_sequence) { + TestDriver driver; + + auto key_leader = KeymapKey(0, 0, 0, QK_LEADER); + auto key_a = KeymapKey(0, 1, 0, KC_A); + + set_keymap({key_leader, key_a}); + + EXPECT_EQ(leader_sequence_active(), false); + + EXPECT_NO_REPORT(driver); + tap_key(key_leader); + + EXPECT_EQ(leader_sequence_active(), true); + + EXPECT_REPORT(driver, (KC_1)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_a); + + EXPECT_EQ(leader_sequence_timed_out(), false); + + idle_for(300); + + EXPECT_EQ(leader_sequence_active(), false); + EXPECT_EQ(leader_sequence_timed_out(), true); + + EXPECT_REPORT(driver, (KC_A)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_a); +} + +TEST_F(Leader, triggers_two_key_sequence) { + TestDriver driver; + + auto key_leader = KeymapKey(0, 0, 0, QK_LEADER); + auto key_a = KeymapKey(0, 1, 0, KC_A); + auto key_b = KeymapKey(0, 2, 0, KC_B); + + set_keymap({key_leader, key_a, key_b}); + + EXPECT_EQ(leader_sequence_active(), false); + + EXPECT_NO_REPORT(driver); + tap_key(key_leader); + + EXPECT_EQ(leader_sequence_active(), true); + + EXPECT_REPORT(driver, (KC_2)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_a); + tap_key(key_b); + + EXPECT_EQ(leader_sequence_timed_out(), false); + + idle_for(300); + + EXPECT_EQ(leader_sequence_active(), false); + EXPECT_EQ(leader_sequence_timed_out(), true); + + EXPECT_REPORT(driver, (KC_A)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_a); +} + +TEST_F(Leader, triggers_three_key_sequence) { + TestDriver driver; + + auto key_leader = KeymapKey(0, 0, 0, QK_LEADER); + auto key_a = KeymapKey(0, 1, 0, KC_A); + auto key_b = KeymapKey(0, 2, 0, KC_B); + auto key_c = KeymapKey(0, 3, 0, KC_C); + + set_keymap({key_leader, key_a, key_b, key_c}); + + EXPECT_EQ(leader_sequence_active(), false); + + EXPECT_NO_REPORT(driver); + tap_key(key_leader); + + EXPECT_EQ(leader_sequence_active(), true); + + EXPECT_REPORT(driver, (KC_3)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_a); + tap_key(key_b); + tap_key(key_c); + + EXPECT_EQ(leader_sequence_timed_out(), false); + + idle_for(300); + + EXPECT_EQ(leader_sequence_active(), false); + EXPECT_EQ(leader_sequence_timed_out(), true); + + EXPECT_REPORT(driver, (KC_A)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_a); +} + +TEST_F(Leader, triggers_four_key_sequence) { + TestDriver driver; + + auto key_leader = KeymapKey(0, 0, 0, QK_LEADER); + auto key_a = KeymapKey(0, 1, 0, KC_A); + auto key_b = KeymapKey(0, 2, 0, KC_B); + auto key_c = KeymapKey(0, 3, 0, KC_C); + auto key_d = KeymapKey(0, 4, 0, KC_D); + + set_keymap({key_leader, key_a, key_b, key_c, key_d}); + + EXPECT_EQ(leader_sequence_active(), false); + + EXPECT_NO_REPORT(driver); + tap_key(key_leader); + + EXPECT_EQ(leader_sequence_active(), true); + + EXPECT_REPORT(driver, (KC_4)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_a); + tap_key(key_b); + tap_key(key_c); + tap_key(key_d); + + EXPECT_EQ(leader_sequence_timed_out(), false); + + idle_for(300); + + EXPECT_EQ(leader_sequence_active(), false); + EXPECT_EQ(leader_sequence_timed_out(), true); + + EXPECT_REPORT(driver, (KC_A)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_a); +} + +TEST_F(Leader, triggers_five_key_sequence) { + TestDriver driver; + + auto key_leader = KeymapKey(0, 0, 0, QK_LEADER); + auto key_a = KeymapKey(0, 1, 0, KC_A); + auto key_b = KeymapKey(0, 2, 0, KC_B); + auto key_c = KeymapKey(0, 3, 0, KC_C); + auto key_d = KeymapKey(0, 4, 0, KC_D); + auto key_e = KeymapKey(0, 5, 0, KC_E); + + set_keymap({key_leader, key_a, key_b, key_c, key_d, key_e}); + + EXPECT_EQ(leader_sequence_active(), false); + + EXPECT_NO_REPORT(driver); + tap_key(key_leader); + + EXPECT_EQ(leader_sequence_active(), true); + + EXPECT_REPORT(driver, (KC_5)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_a); + tap_key(key_b); + tap_key(key_c); + tap_key(key_d); + tap_key(key_e); + + EXPECT_EQ(leader_sequence_timed_out(), false); + + idle_for(300); + + EXPECT_EQ(leader_sequence_active(), false); + EXPECT_EQ(leader_sequence_timed_out(), true); + + EXPECT_REPORT(driver, (KC_A)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_a); +} + +TEST_F(Leader, extracts_mod_tap_keycode) { + TestDriver driver; + + auto key_leader = KeymapKey(0, 0, 0, QK_LEADER); + auto key_mt = KeymapKey(0, 1, 0, LSFT_T(KC_A)); + + set_keymap({key_leader, key_mt}); + + tap_key(key_leader); + + EXPECT_REPORT(driver, (KC_1)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_mt); + + EXPECT_EQ(leader_sequence_one_key(KC_A), true); + + idle_for(300); +} + +TEST_F(Leader, extracts_layer_tap_keycode) { + TestDriver driver; + + auto key_leader = KeymapKey(0, 0, 0, QK_LEADER); + auto key_lt = KeymapKey(0, 1, 0, LT(1, KC_A)); + + set_keymap({key_leader, key_lt}); + + tap_key(key_leader); + + EXPECT_REPORT(driver, (KC_1)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_lt); + + EXPECT_EQ(leader_sequence_one_key(KC_A), true); + + idle_for(300); +} |