Skip to content

Commit

Permalink
WIP: unit-tests and action_(tapping) fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlK90 committed May 2, 2023
1 parent 45f17ac commit 79fa530
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 4 deletions.
4 changes: 4 additions & 0 deletions quantum/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ __attribute__((weak)) void post_process_record_quantum(keyrecord_t *record) {}
* FIXME: Needs documentation.
*/
void process_record_tap_hint(keyrecord_t *record) {
if (!IS_KEYEVENT(record->event)) {
return;
}

action_t action = layer_switch_get_action(record->event.key);

switch (action.kind.id) {
Expand Down
10 changes: 6 additions & 4 deletions quantum/action_tapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,24 @@ bool process_tapping(keyrecord_t *keyp) {

// state machine is in the "reset" state, no tapping key is to be
// processed
if (IS_NOEVENT(tapping_key.event) && IS_EVENT(event)) {
if (event.pressed && is_tap_record(keyp)) {
if (IS_NOEVENT(tapping_key.event)) {
if (!IS_EVENT(event)) {
// early return for tick events
} else if (event.pressed && is_tap_record(keyp)) {
// the currently pressed key is a tapping key, therefore transition
// into the "pressed" tapping key state
ac_dprintf("Tapping: Start(Press tap key).\n");
tapping_key = *keyp;
process_record_tap_hint(&tapping_key);
waiting_buffer_scan_tap();
debug_tapping_key();
return true;
} else {
// the current key is just a regular key, pass it on for regular
// processing
process_record(keyp);
return true;
}

return true;
}

TAP_DEFINE_KEYCODE;
Expand Down
8 changes: 8 additions & 0 deletions tests/combo/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright 2023 Stefan Kerkmann (@KarlK90)
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include "test_common.h"

#define TAPPING_TERM 200
4 changes: 4 additions & 0 deletions tests/combo/test.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2023 Stefan Kerkmann (@KarlK90)
# SPDX-License-Identifier: GPL-2.0-or-later

COMBO_ENABLE = yes
53 changes: 53 additions & 0 deletions tests/combo/test_combo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2023 Stefan Kerkmann (@KarlK90)
// Copyright 2023 @filterpaper
// SPDX-License-Identifier: GPL-2.0-or-later

#include "keyboard_report_util.hpp"
#include "quantum.h"
#include "keycode.h"
#include "test_common.h"
#include "test_driver.hpp"
#include "test_fixture.hpp"
#include "test_keymap_key.hpp"

extern "C" {
enum combos { modtest, COMBO_LENGTH };
uint16_t COMBO_LEN = COMBO_LENGTH;

uint16_t const modtest_combo[] PROGMEM = {KC_Y, KC_U, COMBO_END};

// clang-format off
combo_t key_combos[] = {
[modtest] = COMBO(modtest_combo, RSFT_T(KC_SPACE))
};
// clang-format on
}

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

class Combo : public TestFixture {};

TEST_F(Combo, combo_tapped) {
TestDriver driver;
KeymapKey key_y(0, 0, 1, KC_Y);
KeymapKey key_u(0, 0, 2, KC_U);
set_keymap({key_y, key_u});

EXPECT_REPORT(driver, (KC_SPACE));
EXPECT_EMPTY_REPORT(driver);
tap_combo({key_y, key_u});
VERIFY_AND_CLEAR(driver);
}

TEST_F(Combo, combo_held_longer_than_tapping_term) {
TestDriver driver;
KeymapKey key_y(0, 0, 1, KC_Y);
KeymapKey key_u(0, 0, 2, KC_U);
set_keymap({key_y, key_u});

EXPECT_REPORT(driver, (KC_RIGHT_SHIFT));
EXPECT_EMPTY_REPORT(driver);
tap_combo({key_y, key_u}, TAPPING_TERM + 1);
VERIFY_AND_CLEAR(driver);
}

0 comments on commit 79fa530

Please sign in to comment.