diff options
author | Drashna Jaelre <drashna@live.com> | 2023-02-11 15:23:07 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-12 10:23:07 +1100 |
commit | fe02abc47921428fe6eb59ca817bfd082f0de4bf (patch) | |
tree | 5bc3f68ec782969cfed93660c21704df4b530823 /tests | |
parent | 40028437971fbca33f49e1d0b683b3b6e2dc9a61 (diff) |
[Core] Tri Layer Keys (#19795)
Co-authored-by: wilba <wilba@wilba.tech>
Co-authored-by: Pablo MartÃnez <58857054+elpekenin@users.noreply.github.com>
Co-authored-by: Joel Challis <git@zvecr.com>
Co-authored-by: Nick Brassel <nick@tzarc.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_common/keycode_table.cpp | 2 | ||||
-rw-r--r-- | tests/tri_layer/config.h | 6 | ||||
-rw-r--r-- | tests/tri_layer/test.mk | 8 | ||||
-rw-r--r-- | tests/tri_layer/test_tri_layer.cpp | 103 |
4 files changed, 119 insertions, 0 deletions
diff --git a/tests/test_common/keycode_table.cpp b/tests/test_common/keycode_table.cpp index ab9c292e95..337bc8fb5f 100644 --- a/tests/test_common/keycode_table.cpp +++ b/tests/test_common/keycode_table.cpp @@ -659,5 +659,7 @@ std::map<uint16_t, std::string> KEYCODE_ID_TABLE = { {QK_AUTOCORRECT_ON, "QK_AUTOCORRECT_ON"}, {QK_AUTOCORRECT_OFF, "QK_AUTOCORRECT_OFF"}, {QK_AUTOCORRECT_TOGGLE, "QK_AUTOCORRECT_TOGGLE"}, + {QK_TRI_LAYER_LOWER, "QK_TRI_LAYER_LOWER"}, + {QK_TRI_LAYER_UPPER, "QK_TRI_LAYER_UPPER"}, {SAFE_RANGE, "SAFE_RANGE"}, }; 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) <drashna@live.com> +// 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) <drashna@live.com> +# 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) <drashna@live.com> +// 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); +} |