summaryrefslogtreecommitdiff
path: root/tests/tri_layer/test_tri_layer.cpp
blob: fffc124f4c6aa2390d5531dc7794ac6b5f6d2e61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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);
}