diff options
Diffstat (limited to 'tests/tri_layer')
-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 |
3 files changed, 117 insertions, 0 deletions
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); +} |