Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some tests for swap hands feature #24420

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions quantum/action.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check failure on line 1 in quantum/action.c

View workflow job for this annotation

GitHub Actions / lint

Requires Formatting
Copyright 2012,2013 Jun Wako <[email protected]>

This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -253,7 +253,7 @@
break;
case OP_SH_TAP_TOGGLE:
default:
swap_hands = !swap_hands;
swap_hands_toggle();
swap_held = true;
}
break;
Expand Down Expand Up @@ -735,7 +735,7 @@
switch (action.swap.code) {
case OP_SH_TOGGLE:
if (event.pressed) {
swap_hands = !swap_hands;
swap_hands_toggle();
}
break;
case OP_SH_ON_OFF:
Expand All @@ -746,12 +746,12 @@
break;
case OP_SH_ON:
if (!event.pressed) {
swap_hands = true;
swap_hands_on();
}
break;
case OP_SH_OFF:
if (!event.pressed) {
swap_hands = false;
swap_hands_off();
}
break;
# ifndef NO_ACTION_ONESHOT
Expand All @@ -772,19 +772,19 @@
if (swap_held) {
swap_held = false;
} else {
swap_hands = !swap_hands;
swap_hands_toggle();
}
} else {
if (tap_count < TAPPING_TOGGLE) {
swap_hands = !swap_hands;
swap_hands_toggle();
}
}
break;
default:
/* tap key */
if (tap_count > 0) {
if (swap_held) {
swap_hands = !swap_hands; // undo hold set up in _tap_hint
swap_hands_toggle(); // undo hold set up in _tap_hint
swap_held = false;
}
if (event.pressed) {
Expand All @@ -796,7 +796,7 @@
}
} else {
if (swap_held && !event.pressed) {
swap_hands = !swap_hands; // undo hold set up in _tap_hint
swap_hands_toggle(); // undo hold set up in _tap_hint
swap_held = false;
}
}
Expand Down
20 changes: 20 additions & 0 deletions tests/swap_hands_hold/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "test_common.h"

#define ACTION_DEBUG
#define HOLD_ON_OTHER_KEY_PRESS
85 changes: 85 additions & 0 deletions tests/swap_hands_hold/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "action_util.h"

Check failure on line 1 in tests/swap_hands_hold/test.cpp

View workflow job for this annotation

GitHub Actions / lint

Requires Formatting
#include "keyboard_report_util.hpp"
#include "test_common.hpp"

using testing::_;
using testing::InSequence;

class SwapHands : public TestFixture {};

// XXX hand_swap_config[row][column] -> column, row
const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = {
{{0, 0}, {2, 0}, {1, 0}, {3, 0}}
};

TEST_F(SwapHands, LongHoldSwaps) {
TestDriver driver;
auto key_sh_t = KeymapKey(0, 0, 0, SH_T(KC_SPACE));
auto key_a = KeymapKey(0, 1, 0, KC_A);
auto key_b = KeymapKey(0, 2, 0, KC_B);

set_keymap({key_sh_t, key_a, key_b});

key_sh_t.press();
idle_for(211);
key_a.press();
EXPECT_REPORT(driver, (key_b.report_code));
idle_for(1);
key_sh_t.release();
idle_for(1);
key_a.release();

EXPECT_EMPTY_REPORT(driver);
keyboard_task();
}

TEST_F(SwapHands, ShortHoldSwaps) {
TestDriver driver;
auto key_sh_t = KeymapKey(0, 0, 0, SH_T(KC_SPACE));
auto key_a = KeymapKey(0, 1, 0, KC_A);
auto key_b = KeymapKey(0, 2, 0, KC_B);

set_keymap({key_sh_t, key_a, key_b});

key_sh_t.press();
idle_for(1);
key_a.press();
EXPECT_REPORT(driver, (key_b.report_code));
idle_for(1);
key_sh_t.release();
idle_for(1);
key_a.release();

EXPECT_EMPTY_REPORT(driver);
keyboard_task();
}

TEST_F(SwapHands, HoldAfterOSM_Swaps) {
TestDriver driver;
auto key_sh_t = KeymapKey(0, 0, 0, SH_T(KC_SPACE));
auto key_a = KeymapKey(0, 1, 0, KC_A);
auto key_b = KeymapKey(0, 2, 0, KC_B);
auto key_m = KeymapKey(0, 3, 0, OSM(MOD_LSFT));

set_keymap({key_sh_t, key_a, key_b, key_m});

debug_enable = true;
debug_keyboard = true;

key_m.press();
idle_for(1);
key_m.release();
idle_for(1);
key_sh_t.press();
idle_for(1);
key_a.press();
EXPECT_REPORT(driver, (key_b.report_code, KC_LEFT_SHIFT));
idle_for(1);
key_sh_t.release();
idle_for(1);
key_a.release();

EXPECT_EMPTY_REPORT(driver);
keyboard_task();
}

2 changes: 2 additions & 0 deletions tests/swap_hands_hold/test.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SWAP_HANDS_ENABLE = yes
CONSOLE_ENABLE = yes
20 changes: 20 additions & 0 deletions tests/swap_hands_permissive/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "test_common.h"

#define ACTION_DEBUG
#define PERMISSIVE_HOLD
106 changes: 106 additions & 0 deletions tests/swap_hands_permissive/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include "action_util.h"

Check failure on line 1 in tests/swap_hands_permissive/test.cpp

View workflow job for this annotation

GitHub Actions / lint

Requires Formatting
#include "keyboard_report_util.hpp"
#include "test_common.hpp"

using testing::_;
using testing::InSequence;

class SwapHands : public TestFixture {};

// XXX hand_swap_config[row][column] -> column, row
const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = {
{{0, 0}, {2, 0}, {1, 0}, {3, 0}}
};

TEST_F(SwapHands, LongHoldSwaps) {
TestDriver driver;
auto key_sh_t = KeymapKey(0, 0, 0, SH_T(KC_SPACE));
auto key_a = KeymapKey(0, 1, 0, KC_A);
auto key_b = KeymapKey(0, 2, 0, KC_B);

set_keymap({key_sh_t, key_a, key_b});

key_sh_t.press();
idle_for(211);
key_a.press();
EXPECT_REPORT(driver, (key_b.report_code));
idle_for(1);
key_sh_t.release();
idle_for(1);
key_a.release();

EXPECT_EMPTY_REPORT(driver);
keyboard_task();
}

TEST_F(SwapHands, ShortRollingHoldTaps) {
TestDriver driver;
auto key_sh_t = KeymapKey(0, 0, 0, SH_T(KC_SPACE));
auto key_a = KeymapKey(0, 1, 0, KC_A);
auto key_b = KeymapKey(0, 2, 0, KC_B);

set_keymap({key_sh_t, key_a, key_b});

key_sh_t.press();
idle_for(1);
key_a.press();
EXPECT_REPORT(driver, (key_a.report_code));
idle_for(1);
key_sh_t.release();
idle_for(1);
key_a.release();

EXPECT_EMPTY_REPORT(driver);
keyboard_task();
}

TEST_F(SwapHands, ShortHoldSwaps) {
TestDriver driver;
auto key_sh_t = KeymapKey(0, 0, 0, SH_T(KC_SPACE));
auto key_a = KeymapKey(0, 1, 0, KC_A);
auto key_b = KeymapKey(0, 2, 0, KC_B);

set_keymap({key_sh_t, key_a, key_b});

key_sh_t.press();
idle_for(1);
key_a.press();
idle_for(1);
key_a.release();
EXPECT_REPORT(driver, (key_b.report_code));
EXPECT_EMPTY_REPORT(driver);
idle_for(1);
key_sh_t.release();

keyboard_task();
}

TEST_F(SwapHands, HoldAfterOSM_Swaps) {
TestDriver driver;
auto key_sh_t = KeymapKey(0, 0, 0, SH_T(KC_SPACE));
auto key_a = KeymapKey(0, 1, 0, KC_A);
auto key_b = KeymapKey(0, 2, 0, KC_B);
auto key_m = KeymapKey(0, 3, 0, OSM(MOD_LSFT));

set_keymap({key_sh_t, key_a, key_b, key_m});

debug_enable = true;
debug_keyboard = true;

key_m.press();
idle_for(1);
key_m.release();
idle_for(1);
key_sh_t.press();
idle_for(1);
key_a.press();
idle_for(1);
key_a.release();
EXPECT_REPORT(driver, (key_b.report_code, KC_LEFT_SHIFT));
EXPECT_EMPTY_REPORT(driver);
idle_for(1);
key_sh_t.release();

keyboard_task();
}

2 changes: 2 additions & 0 deletions tests/swap_hands_permissive/test.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SWAP_HANDS_ENABLE = yes
CONSOLE_ENABLE = yes
Loading