From fe02abc47921428fe6eb59ca817bfd082f0de4bf Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Sat, 11 Feb 2023 15:23:07 -0800 Subject: [Core] Tri Layer Keys (#19795) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: wilba Co-authored-by: Pablo Martínez <58857054+elpekenin@users.noreply.github.com> Co-authored-by: Joel Challis Co-authored-by: Nick Brassel --- tests/tri_layer/config.h | 6 +++ tests/tri_layer/test.mk | 8 +++ tests/tri_layer/test_tri_layer.cpp | 103 +++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 tests/tri_layer/config.h create mode 100644 tests/tri_layer/test.mk create mode 100644 tests/tri_layer/test_tri_layer.cpp (limited to 'tests/tri_layer') diff --git a/tests/tri_layer/config.h b/tests/tri_layer/config.h new file mode 100644 index 0000000000..b68bf0c2d5 --- /dev/null +++ b/tests/tri_layer/config.h @@ -0,0 +1,6 @@ +// Copyright 2021 Christopher Courtney, aka Drashna Jael're (@drashna) +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "test_common.h" diff --git a/tests/tri_layer/test.mk b/tests/tri_layer/test.mk new file mode 100644 index 0000000000..50548c3e1c --- /dev/null +++ b/tests/tri_layer/test.mk @@ -0,0 +1,8 @@ +# Copyright 2021 Christopher Courtney, aka Drashna Jael're (@drashna) +# SPDX-License-Identifier: GPL-2.0-or-later + +# -------------------------------------------------------------------------------- +# Keep this file, even if it is empty, as a marker that this folder contains tests +# -------------------------------------------------------------------------------- + +TRI_LAYER_ENABLE = yes diff --git a/tests/tri_layer/test_tri_layer.cpp b/tests/tri_layer/test_tri_layer.cpp new file mode 100644 index 0000000000..fffc124f4c --- /dev/null +++ b/tests/tri_layer/test_tri_layer.cpp @@ -0,0 +1,103 @@ +// Copyright 2021 Christopher Courtney, aka Drashna Jael're (@drashna) +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "test_common.hpp" + +using testing::_; +using testing::InSequence; + +class TriLayer : public TestFixture {}; + +TEST_F(TriLayer, TriLayerLowerTest) { + TestDriver driver; + KeymapKey lower_layer_key = KeymapKey{0, 0, 0, QK_TRI_LAYER_LOWER}; + + set_keymap({lower_layer_key, KeymapKey{1, 0, 0, KC_TRNS}}); + + /* Press Lower. */ + EXPECT_NO_REPORT(driver); + lower_layer_key.press(); + run_one_scan_loop(); + EXPECT_TRUE(layer_state_is(get_tri_layer_lower_layer())); + EXPECT_FALSE(layer_state_is(get_tri_layer_upper_layer())); + EXPECT_FALSE(layer_state_is(get_tri_layer_adjust_layer())); + VERIFY_AND_CLEAR(driver); + + /* Release Lower. */ + EXPECT_NO_REPORT(driver); + lower_layer_key.release(); + run_one_scan_loop(); + EXPECT_FALSE(layer_state_is(get_tri_layer_lower_layer())); + EXPECT_FALSE(layer_state_is(get_tri_layer_upper_layer())); + EXPECT_FALSE(layer_state_is(get_tri_layer_adjust_layer())); + VERIFY_AND_CLEAR(driver); +} + +TEST_F(TriLayer, TriLayerUpperTest) { + TestDriver driver; + KeymapKey upper_layer_key = KeymapKey{0, 0, 0, QK_TRI_LAYER_UPPER}; + + set_keymap({upper_layer_key, KeymapKey{2, 0, 0, KC_TRNS}}); + + /* Press Raise. */ + EXPECT_NO_REPORT(driver); + upper_layer_key.press(); + run_one_scan_loop(); + EXPECT_FALSE(layer_state_is(get_tri_layer_lower_layer())); + EXPECT_TRUE(layer_state_is(get_tri_layer_upper_layer())); + EXPECT_FALSE(layer_state_is(get_tri_layer_adjust_layer())); + VERIFY_AND_CLEAR(driver); + + /* Release Raise. */ + EXPECT_NO_REPORT(driver); + upper_layer_key.release(); + run_one_scan_loop(); + EXPECT_FALSE(layer_state_is(get_tri_layer_lower_layer())); + EXPECT_FALSE(layer_state_is(get_tri_layer_upper_layer())); + EXPECT_FALSE(layer_state_is(get_tri_layer_adjust_layer())); + VERIFY_AND_CLEAR(driver); +} + +TEST_F(TriLayer, TriLayerAdjustTest) { + TestDriver driver; + KeymapKey lower_layer_key = KeymapKey{0, 0, 0, QK_TRI_LAYER_LOWER}; + KeymapKey upper_layer_key = KeymapKey{0, 1, 0, QK_TRI_LAYER_UPPER}; + + set_keymap({ + upper_layer_key, + lower_layer_key, + KeymapKey{1, 0, 0, KC_TRNS}, + KeymapKey{1, 1, 0, KC_TRNS}, + KeymapKey{2, 0, 0, KC_TRNS}, + KeymapKey{2, 1, 0, KC_TRNS}, + KeymapKey{3, 0, 0, KC_TRNS}, + KeymapKey{3, 1, 0, KC_TRNS}, + }); + + /* Press Lower, then upper, and release upper and then lower. */ + EXPECT_NO_REPORT(driver); + lower_layer_key.press(); + run_one_scan_loop(); + EXPECT_TRUE(layer_state_is(get_tri_layer_lower_layer())); + EXPECT_FALSE(layer_state_is(get_tri_layer_upper_layer())); + EXPECT_FALSE(layer_state_is(get_tri_layer_adjust_layer())); + + upper_layer_key.press(); + run_one_scan_loop(); + EXPECT_TRUE(layer_state_is(get_tri_layer_lower_layer())); + EXPECT_TRUE(layer_state_is(get_tri_layer_upper_layer())); + EXPECT_TRUE(layer_state_is(get_tri_layer_adjust_layer())); + + lower_layer_key.release(); + run_one_scan_loop(); + EXPECT_FALSE(layer_state_is(get_tri_layer_lower_layer())); + EXPECT_TRUE(layer_state_is(get_tri_layer_upper_layer())); + EXPECT_FALSE(layer_state_is(get_tri_layer_adjust_layer())); + + upper_layer_key.release(); + run_one_scan_loop(); + EXPECT_FALSE(layer_state_is(get_tri_layer_lower_layer())); + EXPECT_FALSE(layer_state_is(get_tri_layer_upper_layer())); + EXPECT_FALSE(layer_state_is(get_tri_layer_adjust_layer())); + VERIFY_AND_CLEAR(driver); +} -- cgit v1.2.3