From 5ed3b5301ed8a9cde7130f0bcee0790b8271c3e4 Mon Sep 17 00:00:00 2001 From: Mr-Asmodaeus Date: Sat, 16 Nov 2024 15:00:57 +0000 Subject: [PATCH] Added tests --- .../config.h | 9 ++++ .../test.mk | 7 +++ ...leader_no_initial_timeout_several_keys.cpp | 53 +++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 tests/leader/leader_no_initial_timeout_several_keys/config.h create mode 100644 tests/leader/leader_no_initial_timeout_several_keys/test.mk create mode 100644 tests/leader/leader_no_initial_timeout_several_keys/test_leader_no_initial_timeout_several_keys.cpp diff --git a/tests/leader/leader_no_initial_timeout_several_keys/config.h b/tests/leader/leader_no_initial_timeout_several_keys/config.h new file mode 100644 index 00000000000..3abf7aa3810 --- /dev/null +++ b/tests/leader/leader_no_initial_timeout_several_keys/config.h @@ -0,0 +1,9 @@ +// Copyright 2023 QMK +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "test_common.h" + +#define LEADER_NO_TIMEOUT +#define LEADER_NO_TIMEOUT_FOR_N_KEYSTOKES 2 diff --git a/tests/leader/leader_no_initial_timeout_several_keys/test.mk b/tests/leader/leader_no_initial_timeout_several_keys/test.mk new file mode 100644 index 00000000000..635c04ee92c --- /dev/null +++ b/tests/leader/leader_no_initial_timeout_several_keys/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_several_keys/test_leader_no_initial_timeout_several_keys.cpp b/tests/leader/leader_no_initial_timeout_several_keys/test_leader_no_initial_timeout_several_keys.cpp new file mode 100644 index 00000000000..83fddc9fa80 --- /dev/null +++ b/tests/leader/leader_no_initial_timeout_several_keys/test_leader_no_initial_timeout_several_keys.cpp @@ -0,0 +1,53 @@ +// 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_numkeypress_keys_pressed) { + 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); + + idle_for(1000); + + EXPECT_EQ(leader_sequence_active(), true); + EXPECT_EQ(leader_sequence_timed_out(), false); + + EXPECT_REPORT(driver, (KC_2)); + EXPECT_EMPTY_REPORT(driver); + tap_key(key_a); + + idle_for(1000); + + EXPECT_EQ(leader_sequence_active(), true); + EXPECT_EQ(leader_sequence_timed_out(), false); + + tap_key(key_b); + + 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); +}