diff options
Diffstat (limited to 'users/dennytom/chording_engine/tests')
-rw-r--r-- | users/dennytom/chording_engine/tests/minunit.h | 288 | ||||
-rw-r--r-- | users/dennytom/chording_engine/tests/test.c | 1259 | ||||
-rw-r--r-- | users/dennytom/chording_engine/tests/test_full.sh | 11 | ||||
-rw-r--r-- | users/dennytom/chording_engine/tests/test_keymap_def.json | 145 | ||||
-rw-r--r-- | users/dennytom/chording_engine/tests/test_quick.sh | 6 |
5 files changed, 1709 insertions, 0 deletions
diff --git a/users/dennytom/chording_engine/tests/minunit.h b/users/dennytom/chording_engine/tests/minunit.h new file mode 100644 index 0000000000..ed71b62533 --- /dev/null +++ b/users/dennytom/chording_engine/tests/minunit.h @@ -0,0 +1,288 @@ +#define mu_assert(message, test) \ + do { \ + if (!(test)) { \ + return message; \ + } \ + } while (0) + +#define RED "\033[0;31m" +#define GREEN "\033[0;32m" +#define NC "\033[0m" + +enum ASSERT_TYPES { + UINT, + INT +}; + +#define BUFF_SIZE 1024 +char buffer[BUFF_SIZE]; + +#define ASSERT_EQ(type, actual, expected) \ + do { \ + if (actual != expected) { \ + switch (type) { \ + case UINT: \ + snprintf(buffer, BUFF_SIZE, "\nline %d\nvar %s\nactual = %u\nexpected = %u\n", __LINE__, #actual, actual, expected); \ + break; \ + case INT: \ + snprintf(buffer, BUFF_SIZE, "\nline %d\nvar %s\nactual = %d\nexpected = %d\n", __LINE__, #actual, actual, expected); \ + break; \ + default: \ + snprintf(buffer, BUFF_SIZE, "\nline %d\nunsupported ASSERT_EQ type\n", __LINE__); \ + break; \ + } \ + printf("%s\n", buffer); \ + passed = false; \ + all_passed = false; \ + } \ + } while (0) + +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <string.h> + +#define MATRIX_ROWS 2 +#define MATRIX_COLS 10 +#define LAYOUT_test( \ + k09, k08, k07, k06, k05, k04, k03, k02, k01, k00, \ + k19, k18, k17, k16, k15, k14, k13, k12, k11, k10 \ +) { \ + { k00, k01, k02, k03, k04, k05, k06, k07, k08, k09}, \ + { k10, k11, k12, k13, k14, k15, k16, k17, k18, k19}, \ +} + +#define PROGMEM +#define memcpy_P memcpy +const struct Chord* pgm_read_word(const struct Chord* const* chord) {return *chord;} + +typedef struct { + uint8_t col; + uint8_t row; +} keypos_t; + +typedef struct { + keypos_t key; + bool pressed; + uint16_t time; +} keyevent_t; + +typedef struct { + bool interrupted :1; + bool reserved2 :1; + bool reserved1 :1; + bool reserved0 :1; + uint8_t count :4; +} tap_t; + +typedef struct { + keyevent_t event; + tap_t tap; +} keyrecord_t; + +keyrecord_t pressed = {{{0,0},true,0}, {0,0,0,0,0}}; +keyrecord_t depressed = {{{0,0},false,0}, {0,0,0,0,0}}; + +enum keycodes { + KC_NO, + KC_TILDE, + KC_GRAVE, + KC_EXCLAIM, + KC_1, + KC_AT, + KC_2, + KC_HASH, + KC_3, + KC_DOLLAR, + KC_4, + KC_PERCENT, + KC_5, + KC_CIRCUMFLEX, + KC_6, + KC_AMPERSAND, + KC_7, + KC_ASTERISK, + KC_8, + KC_LEFT_PAREN, + KC_9, + KC_RIGHT_PAREN, + KC_0, + KC_UNDERSCORE, + KC_MINUS, + KC_PLUS, + KC_EQUAL, + KC_LEFT_CURLY_BRACE, + KC_LBRACKET, + KC_RIGHT_CURLY_BRACE, + KC_RBRACKET, + KC_PIPE, + KC_BSLASH, + KC_COLON, + KC_SCOLON, + KC_DOUBLE_QUOTE, + KC_QUOTE, + KC_LEFT_ANGLE_BRACKET, + KC_COMMA, + KC_RIGHT_ANGLE_BRACKET, + KC_DOT, + KC_QUESTION, + KC_SLASH, + KC_Q, + KC_W, + KC_E, + KC_R, + KC_T, + KC_Y, + KC_U, + KC_I, + KC_O, + KC_P, + KC_A, + KC_S, + KC_D, + KC_F, + KC_G, + KC_H, + KC_J, + KC_K, + KC_L, + KC_Z, + KC_X, + KC_C, + KC_V, + KC_B, + KC_N, + KC_M, + KC_ESC, + KC_LSFT, + KC_LCTL, + KC_LGUI, + KC_LALT, + KC_RALT, + KC_RCTL, + KC_RGUI, + KC_RSFT, + KC_TAB, + KC_DEL, + KC_INS, + KC_BSPC, + KC_ENTER, + KC_SPACE, + KC_F1, + KC_F2, + KC_F3, + KC_F4, + KC_F5, + KC_F6, + KC_F7, + KC_F8, + KC_F9, + KC_F10, + KC_F11, + KC_F12, + KC_LEFT, + KC_DOWN, + KC_UP, + KC_RIGHT, + + SAFE_RANGE +}; + +#define HISTORY 20 + +int16_t current_time; +uint8_t keyboard_history[HISTORY][SAFE_RANGE-1]; +int16_t time_history[HISTORY]; +uint8_t history_index; + +void register_code(int16_t keycode) { + history_index++; + for (int j = 0; j < SAFE_RANGE-1; j++) { + keyboard_history[history_index][j] = keyboard_history[history_index-1][j]; + } + keyboard_history[history_index][keycode] = 1; + time_history[history_index] = current_time; +}; +void unregister_code(int16_t keycode) { + history_index++; + for (int j = 0; j < SAFE_RANGE-1; j++) { + keyboard_history[history_index][j] = keyboard_history[history_index-1][j]; + } + keyboard_history[history_index][keycode] = 0; + time_history[history_index] = current_time; +}; +void send_keyboard_report(void) { /*still don't know what this does*/ }; +void matrix_scan_user (void); +void wait_ms(uint16_t ms) { + current_time += ms; +}; +uint16_t timer_read(void) { + uint16_t result = current_time; + return result; +}; +uint16_t timer_elapsed(uint16_t timer) { + uint16_t result = current_time - timer; + return result; +}; +void layer_move(int16_t layer) { /*ignoring for now*/ }; +void clear_keyboard(void) { + history_index++; + for (int j = 0; j < SAFE_RANGE-1; j++) { + keyboard_history[history_index][j] = 0; + } + time_history[history_index] = current_time; +}; +void reset_keyboard(void) { /*ignoring for now*/ }; + +void pause_ms(uint16_t ms) { + for (int i = 0; i < ms; i++) { + current_time++; + matrix_scan_user(); + } +}; + +#define TEST(name) \ + do { \ + printf("%s\n", name); \ + passed = true; \ + do { \ + uint8_t clear_state = ACTIVATED; \ + struct Chord clear_chord PROGMEM = {0, QWERTY, &clear_state, NULL, 0, 0, clear}; \ + clear_chord.function(&clear_chord); \ + } while (0); \ + current_time = 0; \ + history_index = 0; \ + for (int j = 0; j < SAFE_RANGE-1; j++) { \ + keyboard_history[0][j] = 0; \ + } \ + time_history[0] = 0; \ + for (int i = 1; i < HISTORY; i++) { \ + for (int j = 0; j < SAFE_RANGE-1; j++) { \ + keyboard_history[i][j] = -1; \ + } \ + time_history[i] = -1; \ + } + +#define END_TEST \ + if (passed) { \ + printf(GREEN"PASSED"NC"\n"); \ + } else { \ + printf(RED"FAILED"NC"\n"); \ + } \ + } while(0); + +#define MAIN \ +int main(int argc, char **argv) { \ + bool passed = true; \ + bool all_passed = true; + +#define END \ + printf("\n"); \ + if (all_passed) { \ + printf(GREEN"ALL TESTS PASSED"NC"\n"); \ + } else { \ + printf(RED"TESTS FAILED"NC"\n"); \ + } \ + return 1 - all_passed; \ +}
\ No newline at end of file diff --git a/users/dennytom/chording_engine/tests/test.c b/users/dennytom/chording_engine/tests/test.c new file mode 100644 index 0000000000..0cc172f0a8 --- /dev/null +++ b/users/dennytom/chording_engine/tests/test.c @@ -0,0 +1,1259 @@ +#include "minunit.h" +#include "test_keymap.c" + +MAIN + +// CLEAR_KB +TEST("clear") + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + struct Chord* chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + struct Chord chord_storage; + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + struct Chord* chord = &chord_storage; + + *chord->state = READY; + + if (chord->counter) { + *chord->counter = 1; + } + } + + history_index++; + for (int j = 0; j < SAFE_RANGE-1; j++) { + keyboard_history[history_index][j] = 1; + } + + current_pseudolayer = 5; + lock_next = true; + autoshift_mode = false; + command_mode = 1; + in_leader_mode = true; + dynamic_macro_mode = true; + a_key_went_through = true; + + for (int i = 0; i < DYNAMIC_MACRO_MAX_LENGTH; i++) { + dynamic_macro_buffer[i] = 1; + } + + uint8_t clear_state = ACTIVATED; + struct Chord clear_chord PROGMEM = {0, QWERTY, &clear_state, NULL, 0, 0, clear}; + clear_chord.function(&clear_chord); + + for (int i = 0; i < NUMBER_OF_CHORDS; i++) { + struct Chord* chord_ptr = (struct Chord*) pgm_read_word (&list_of_chords[i]); + struct Chord chord_storage; + memcpy_P(&chord_storage, chord_ptr, sizeof(struct Chord)); + struct Chord* chord = &chord_storage; + + ASSERT_EQ(UINT, *chord->state, IDLE); + + if (chord->counter) { + ASSERT_EQ(UINT, *chord->counter, 0); + } + } + + for (int j = 0; j < SAFE_RANGE-1; j++) { + ASSERT_EQ(UINT, keyboard_history[history_index][j], 0); + } + + ASSERT_EQ(UINT, current_pseudolayer, 1); + ASSERT_EQ(UINT, lock_next, false); + ASSERT_EQ(UINT, autoshift_mode, true); + ASSERT_EQ(UINT, command_mode, 0); + ASSERT_EQ(UINT, in_leader_mode, false); + ASSERT_EQ(UINT, leader_ind, 0); + ASSERT_EQ(UINT, dynamic_macro_mode, false); + ASSERT_EQ(UINT, a_key_went_through, false); + + for (int i = 0; i < DYNAMIC_MACRO_MAX_LENGTH; i++) { + ASSERT_EQ(UINT, dynamic_macro_buffer[i], 0); + } +END_TEST + +TEST("pause_ms") + pause_ms(500); + ASSERT_EQ(UINT, current_time, 500); +END_TEST + +// KC +TEST("single_dance_held_states") + ASSERT_EQ(UINT, state_1, IDLE); + process_record_user(TOP1, &pressed); + pause_ms(CHORD_TIMEOUT); + ASSERT_EQ(UINT, state_1, IDLE); + pause_ms(1); + ASSERT_EQ(UINT, state_1, ACTIVATED); + pause_ms(DANCE_TIMEOUT); + ASSERT_EQ(UINT, state_1, ACTIVATED); + pause_ms(1); + ASSERT_EQ(UINT, state_1, PRESS_FROM_ACTIVE); + pause_ms(DANCE_TIMEOUT); + ASSERT_EQ(UINT, state_1, PRESS_FROM_ACTIVE); + pause_ms(1); + ASSERT_EQ(UINT, state_1, FINISHED_FROM_ACTIVE); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, state_1, IDLE); +END_TEST + +TEST("single_dance_held_codes") + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 0); + process_record_user(TOP1, &pressed); + pause_ms(CHORD_TIMEOUT); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 0); + pause_ms(1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 1); + pause_ms(DANCE_TIMEOUT); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 1); + pause_ms(1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 1); + pause_ms(DANCE_TIMEOUT); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 1); + pause_ms(1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 1); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 0); +END_TEST + +TEST("single_dance_tapped_states") + ASSERT_EQ(UINT, state_1, IDLE); + process_record_user(TOP1, &pressed); + pause_ms(CHORD_TIMEOUT); + ASSERT_EQ(UINT, state_1, IDLE); + pause_ms(1); + ASSERT_EQ(UINT, state_1, ACTIVATED); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, state_1, IDLE); +END_TEST + +TEST("single_dance_tapped_codes") + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 0); + process_record_user(TOP1, &pressed); + pause_ms(CHORD_TIMEOUT); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 0); + pause_ms(1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 1); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 0); +END_TEST + +// I can not actually track the states if the tap is faster than chord timeout + +TEST("single_dance_tapped_fast_codes") + ASSERT_EQ(UINT, state_0, IDLE); + process_record_user(TOP1, &pressed); + pause_ms(1); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, keyboard_history[0][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_Q], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_Q], 0); +END_TEST + +TEST("subchords_are_ignored") + ASSERT_EQ(UINT, state_0, IDLE); + process_record_user(TOP1, &pressed); + pause_ms(1); + process_record_user(TOP2, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_W], 0); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_ESC], 1); +END_TEST + +TEST("multiple_chords_at_once") + ASSERT_EQ(UINT, state_0, IDLE); + process_record_user(TOP1, &pressed); + pause_ms(1); + process_record_user(TOP3, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_E], 1); +END_TEST + +// MO +TEST("momentary_layer") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT7, &pressed); + pause_ms(1); + process_record_user(BOT8, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + process_record_user(BOT7, &depressed); + pause_ms(1); + process_record_user(BOT8, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); +END_TEST + +TEST("momentary_layer_reset") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT7, &pressed); + pause_ms(1); + process_record_user(BOT8, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + pause_ms(DANCE_TIMEOUT + 1); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + process_record_user(BOT7, &depressed); + pause_ms(1); + process_record_user(BOT8, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); +END_TEST + +TEST("momentary_layer_alt") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + + process_record_user(TOP8, &pressed); + pause_ms(1); + process_record_user(TOP9, &pressed); + pause_ms(1); + process_record_user(TOP0, &pressed); + pause_ms(1); + process_record_user(BOT8, &pressed); + pause_ms(1); + process_record_user(BOT9, &pressed); + pause_ms(1); + process_record_user(BOT0, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + + ASSERT_EQ(UINT, current_pseudolayer, NUM); + + process_record_user(TOP8, &depressed); + pause_ms(1); + process_record_user(TOP9, &depressed); + pause_ms(1); + process_record_user(TOP0, &depressed); + pause_ms(1); + process_record_user(BOT8, &depressed); + pause_ms(1); + process_record_user(BOT9, &depressed); + pause_ms(1); + process_record_user(BOT0, &depressed); + + ASSERT_EQ(UINT, current_pseudolayer, FNC); +END_TEST + +// DF +TEST("permanent_layer") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT9, &pressed); + pause_ms(1); + process_record_user(BOT0, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + process_record_user(BOT9, &depressed); + pause_ms(1); + process_record_user(BOT0, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + pause_ms(1000); + ASSERT_EQ(UINT, current_pseudolayer, NUM); +END_TEST + +// AT +TEST("autoshift_toggle") + ASSERT_EQ(UINT, autoshift_mode, 1); + uint8_t state = ACTIVATED; + struct Chord chord PROGMEM = {0, QWERTY, &state, NULL, 0, 0, autoshift_toggle}; + chord.function(&chord); + ASSERT_EQ(UINT, autoshift_mode, 0); + state = ACTIVATED; + chord.function(&chord); + ASSERT_EQ(UINT, autoshift_mode, 1); +END_TEST + +// AS +TEST("autoshift_tap") + process_record_user(BOT1, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + process_record_user(BOT1, &depressed); + + ASSERT_EQ(UINT, keyboard_history[0][KC_Z], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[1][KC_Z], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[2][KC_Z], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_LSFT], 0); +END_TEST + +TEST("autoshift_hold") + process_record_user(BOT1, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + pause_ms(LONG_PRESS_MULTIPLIER * (DANCE_TIMEOUT + 1)); + process_record_user(BOT1, &depressed); + + ASSERT_EQ(UINT, keyboard_history[0][KC_Z], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[1][KC_Z], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_LSFT], 1); + + ASSERT_EQ(UINT, keyboard_history[2][KC_Z], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_LSFT], 1); + + ASSERT_EQ(UINT, keyboard_history[3][KC_Z], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_LSFT], 1); + + ASSERT_EQ(UINT, keyboard_history[4][KC_Z], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_LSFT], 0); +END_TEST + +TEST("autoshift_hold_off") + autoshift_mode = 0; + process_record_user(BOT1, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + pause_ms(LONG_PRESS_MULTIPLIER * (DANCE_TIMEOUT + 1)); + process_record_user(BOT1, &depressed); + + ASSERT_EQ(UINT, keyboard_history[0][KC_Z], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[1][KC_Z], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[2][KC_Z], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_LSFT], 0); +END_TEST + +// LOCK +TEST("lock") + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); + process_record_user(BOT1, &pressed); + process_record_user(BOT2, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 1); + process_record_user(BOT1, &depressed); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); + pause_ms(1); + process_record_user(BOT2, &depressed); + pause_ms(1); + process_record_user(TOP1, &pressed); + process_record_user(TOP2, &pressed); + process_record_user(BOT1, &pressed); + process_record_user(BOT2, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + process_record_user(TOP1, &depressed); + pause_ms(1); + process_record_user(TOP2, &depressed); + process_record_user(BOT1, &depressed); + process_record_user(BOT2, &depressed); + pause_ms(1); + process_record_user(BOT1, &pressed); + process_record_user(BOT2, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 1); + process_record_user(BOT1, &depressed); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 1); + pause_ms(1); + process_record_user(BOT2, &depressed); + pause_ms(1000); + process_record_user(BOT1, &pressed); + process_record_user(BOT2, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); + process_record_user(BOT1, &depressed); + pause_ms(1); + process_record_user(BOT2, &depressed); + pause_ms(1000); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); +END_TEST + +// OSK +TEST("one_shot_key_tap") + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); + process_record_user(BOT2, &pressed); + process_record_user(BOT3, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); + process_record_user(BOT2, &depressed); + pause_ms(1); + process_record_user(BOT3, &depressed); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 1); + pause_ms(1000); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 1); + + process_record_user(TOP1, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); +END_TEST + +TEST("one_shot_key_hold") + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); + process_record_user(BOT2, &pressed); + process_record_user(BOT3, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + pause_ms(DANCE_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 1); + + process_record_user(TOP1, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 1); + + process_record_user(BOT2, &depressed); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); +END_TEST + +TEST("one_shot_key_retrotapping") + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); + process_record_user(BOT2, &pressed); + process_record_user(BOT3, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + pause_ms(DANCE_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 1); + + pause_ms(1000); + + process_record_user(BOT2, &depressed); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 1); +END_TEST + +// OSL +TEST("one_shot_layer_tap") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT6, &pressed); + process_record_user(BOT7, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT6, &depressed); + pause_ms(1); + process_record_user(BOT7, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + pause_ms(1000); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + + process_record_user(TOP1, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); +END_TEST + +TEST("one_shot_layer_hold") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT6, &pressed); + process_record_user(BOT7, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + pause_ms(DANCE_TIMEOUT + 1); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + + process_record_user(TOP1, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + + process_record_user(BOT6, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); +END_TEST + +TEST("one_shot_layer_retrotapping") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT6, &pressed); + process_record_user(BOT7, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + pause_ms(DANCE_TIMEOUT + 1); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + + pause_ms(1000); + + process_record_user(BOT6, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, NUM); +END_TEST + +// CMD +TEST("command_mode") + // start recording + process_record_user(TOP5, &pressed); + process_record_user(TOP6, &pressed); + process_record_user(BOT5, &pressed); + process_record_user(BOT6, &pressed); + pause_ms(1); + process_record_user(TOP5, &depressed); + process_record_user(TOP6, &depressed); + process_record_user(BOT5, &depressed); + process_record_user(BOT6, &depressed); + + ASSERT_EQ(UINT, command_mode, 1); + + // record shift+q + process_record_user(BOT1, &pressed); + process_record_user(BOT2, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); + process_record_user(BOT1, &depressed); + process_record_user(BOT2, &depressed); + pause_ms(1000); + + process_record_user(TOP1, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); + process_record_user(TOP1, &depressed); + pause_ms(1000); + + + ASSERT_EQ(UINT, keyboard_history[history_index][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[history_index][KC_LSFT], 0); + // execute + process_record_user(TOP5, &pressed); + process_record_user(TOP6, &pressed); + process_record_user(BOT5, &pressed); + process_record_user(BOT6, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + + ASSERT_EQ(UINT, command_mode, 0); + + // test history + ASSERT_EQ(UINT, keyboard_history[0][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[1][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_LSFT], 1); + + ASSERT_EQ(UINT, keyboard_history[2][KC_Q], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_LSFT], 1); + + ASSERT_EQ(UINT, keyboard_history[3][KC_Q], 1); + ASSERT_EQ(UINT, keyboard_history[3][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[4][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[5][KC_Q], 255); + ASSERT_EQ(UINT, keyboard_history[5][KC_LSFT], 255); +END_TEST + +// KK +TEST("key_key_dance_tap") + process_record_user(BOT2, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + process_record_user(BOT2, &depressed); + + ASSERT_EQ(UINT, keyboard_history[0][KC_X], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_LCTL], 0); + + ASSERT_EQ(UINT, keyboard_history[1][KC_X], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_LCTL], 0); + + ASSERT_EQ(UINT, keyboard_history[2][KC_X], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_LCTL], 0); +END_TEST + +TEST("key_key_dance_hold") + process_record_user(BOT2, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + pause_ms(DANCE_TIMEOUT + 1); + process_record_user(BOT2, &depressed); + + ASSERT_EQ(UINT, keyboard_history[0][KC_X], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_LCTL], 0); + + ASSERT_EQ(UINT, keyboard_history[1][KC_X], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_LCTL], 1); + + ASSERT_EQ(UINT, keyboard_history[2][KC_X], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_LCTL], 0); +END_TEST + +// KL +TEST("key_layer_tap") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT3, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + process_record_user(BOT3, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + pause_ms(1000); + + ASSERT_EQ(UINT, keyboard_history[0][KC_C], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_C], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_C], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_C], 255); +END_TEST + +TEST("key_layer_retrotapping") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT3, &pressed); + pause_ms(1000); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + process_record_user(BOT3, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + pause_ms(1000); + + ASSERT_EQ(UINT, keyboard_history[0][KC_C], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_C], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_C], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_C], 255); +END_TEST + +TEST("key_layer_hold_quick_typist") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT3, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + + pause_ms(1); + process_record_user(TOP1, &pressed); + pause_ms(1); + process_record_user(TOP1, &depressed); + pause_ms(1); + process_record_user(TOP1, &pressed); + pause_ms(1); + process_record_user(TOP1, &depressed); + pause_ms(1); + process_record_user(TOP1, &pressed); + pause_ms(1); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + pause_ms(1); + + process_record_user(BOT3, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + + ASSERT_EQ(UINT, keyboard_history[0][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[6][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[7][KC_1], 255); +END_TEST + +TEST("key_layer_hold_slow_typist") + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + process_record_user(BOT3, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + + pause_ms(1000); + process_record_user(TOP1, &pressed); + pause_ms(1000); + process_record_user(TOP1, &depressed); + pause_ms(1000); + process_record_user(TOP1, &pressed); + pause_ms(1000); + process_record_user(TOP1, &depressed); + pause_ms(1000); + process_record_user(TOP1, &pressed); + pause_ms(1000); + process_record_user(TOP1, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, NUM); + pause_ms(1); + + process_record_user(BOT3, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + + ASSERT_EQ(UINT, keyboard_history[0][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[6][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[7][KC_1], 255); +END_TEST + +// KM +TEST("key_mod_tap") + ASSERT_EQ(UINT, keyboard_history[0][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_V], 0); + process_record_user(BOT4, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_V], 0); + process_record_user(BOT4, &depressed); + ASSERT_EQ(UINT, keyboard_history[2][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_V], 0); + pause_ms(1000); + + ASSERT_EQ(UINT, keyboard_history[3][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_V], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_LALT], 255); + ASSERT_EQ(UINT, keyboard_history[5][KC_V], 255); +END_TEST + +TEST("key_mod_retrotapping") + ASSERT_EQ(UINT, keyboard_history[0][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_V], 0); + process_record_user(BOT4, &pressed); + pause_ms(1000); + ASSERT_EQ(UINT, keyboard_history[1][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_V], 0); + process_record_user(BOT4, &depressed); + ASSERT_EQ(UINT, keyboard_history[2][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_V], 0); + pause_ms(1000); + + ASSERT_EQ(UINT, keyboard_history[3][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_V], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_LALT], 255); + ASSERT_EQ(UINT, keyboard_history[5][KC_V], 255); +END_TEST + +TEST("key_mod_hold_quick_typist") + process_record_user(BOT4, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + + pause_ms(1); + process_record_user(TOP1, &pressed); + pause_ms(1); + process_record_user(TOP1, &depressed); + pause_ms(1); + process_record_user(TOP1, &pressed); + pause_ms(1); + process_record_user(TOP1, &depressed); + pause_ms(1); + process_record_user(TOP1, &pressed); + pause_ms(1); + process_record_user(TOP1, &depressed); + pause_ms(1); + + process_record_user(BOT4, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + + ASSERT_EQ(UINT, keyboard_history[0][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[3][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[5][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[6][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[6][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[7][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[7][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[8][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[8][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[9][KC_LALT], 255); + ASSERT_EQ(UINT, keyboard_history[9][KC_V], 255); +END_TEST + +TEST("key_mod_hold_slow_typist") + process_record_user(BOT4, &pressed); + pause_ms(CHORD_TIMEOUT + 1); + + pause_ms(1000); + process_record_user(TOP1, &pressed); + pause_ms(1000); + process_record_user(TOP1, &depressed); + pause_ms(1000); + process_record_user(TOP1, &pressed); + pause_ms(1000); + process_record_user(TOP1, &depressed); + pause_ms(1000); + process_record_user(TOP1, &pressed); + pause_ms(1000); + process_record_user(TOP1, &depressed); + pause_ms(1000); + + process_record_user(BOT4, &depressed); + ASSERT_EQ(UINT, current_pseudolayer, QWERTY); + + ASSERT_EQ(UINT, keyboard_history[0][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[0][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_Q], 1); + ASSERT_EQ(UINT, keyboard_history[3][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[3][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_Q], 1); + ASSERT_EQ(UINT, keyboard_history[5][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[5][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[6][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[6][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[6][KC_Q], 1); + ASSERT_EQ(UINT, keyboard_history[7][KC_LALT], 1); + ASSERT_EQ(UINT, keyboard_history[7][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[7][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[8][KC_LALT], 0); + ASSERT_EQ(UINT, keyboard_history[8][KC_V], 0); + ASSERT_EQ(UINT, keyboard_history[8][KC_Q], 0); + ASSERT_EQ(UINT, keyboard_history[9][KC_LALT], 255); + ASSERT_EQ(UINT, keyboard_history[9][KC_V], 255); + ASSERT_EQ(UINT, keyboard_history[9][KC_Q], 255); +END_TEST + +// LEADER +TEST("leader_triggers_global") + uint8_t state = ACTIVATED; + struct Chord chord PROGMEM = {0, QWERTY, &state, NULL, 0, 0, leader}; + chord.function(&chord); + + ASSERT_EQ(UINT, in_leader_mode, 1); +END_TEST + +TEST("leader_no_follow") + uint8_t state = ACTIVATED; + struct Chord chord PROGMEM = {0, QWERTY, &state, NULL, 0, 0, leader}; + chord.function(&chord); + + ASSERT_EQ(UINT, in_leader_mode, 1); + + pause_ms(1000); + + ASSERT_EQ(UINT, in_leader_mode, 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_O], 255); +END_TEST + +TEST("leader_wrong_follow") + process_record_user(TOP2, &pressed); + process_record_user(TOP3, &pressed); + process_record_user(BOT2, &pressed); + process_record_user(BOT3, &pressed); + pause_ms(1); + process_record_user(TOP2, &depressed); + process_record_user(TOP3, &depressed); + process_record_user(BOT2, &depressed); + process_record_user(BOT3, &depressed); + + ASSERT_EQ(UINT, in_leader_mode, 1); + + pause_ms(1); + process_record_user(TOP1, &pressed); + pause_ms(1); + process_record_user(TOP1, &depressed); + pause_ms(1); + process_record_user(TOP2, &pressed); + pause_ms(1); + process_record_user(TOP2, &depressed); + + pause_ms(LEADER_TIMEOUT); + pause_ms(1); + + ASSERT_EQ(UINT, in_leader_mode, 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_Q], 255); +END_TEST + +TEST("leader_correct_follow") + process_record_user(TOP2, &pressed); + process_record_user(TOP3, &pressed); + process_record_user(BOT2, &pressed); + process_record_user(BOT3, &pressed); + pause_ms(1); + process_record_user(TOP2, &depressed); + process_record_user(TOP3, &depressed); + process_record_user(BOT2, &depressed); + process_record_user(BOT3, &depressed); + + ASSERT_EQ(UINT, in_leader_mode, 1); + + pause_ms(1); + process_record_user(TOP0, &pressed); + pause_ms(1); + process_record_user(TOP0, &depressed); + pause_ms(1); + process_record_user(TOP9, &pressed); + pause_ms(1); + process_record_user(TOP9, &depressed); + + pause_ms(LEADER_TIMEOUT); + ASSERT_EQ(UINT, in_leader_mode, 1); + + pause_ms(1); + ASSERT_EQ(UINT, in_leader_mode, 0); + + ASSERT_EQ(UINT, keyboard_history[1][KC_O], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_P], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_A], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_S], 1); + + ASSERT_EQ(UINT, keyboard_history[2][KC_O], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_P], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_A], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_S], 0); + + ASSERT_EQ(UINT, keyboard_history[3][KC_O], 255); + ASSERT_EQ(UINT, keyboard_history[3][KC_P], 255); + ASSERT_EQ(UINT, keyboard_history[3][KC_A], 255); + ASSERT_EQ(UINT, keyboard_history[3][KC_S], 255); + + ASSERT_EQ(UINT, keyboard_history[4][KC_O], 255); + ASSERT_EQ(UINT, keyboard_history[4][KC_P], 255); + ASSERT_EQ(UINT, keyboard_history[4][KC_A], 255); + ASSERT_EQ(UINT, keyboard_history[4][KC_S], 255); + + ASSERT_EQ(UINT, keyboard_history[5][KC_Q], 255); +END_TEST + +// DYNAMIC MACRO +TEST("dynamic_macro_record_mode") + current_pseudolayer = NUM; + + // record + ASSERT_EQ(UINT, dynamic_macro_mode, 0); + process_record_user(BOT7, &pressed); + process_record_user(BOT7, &depressed); + ASSERT_EQ(UINT, dynamic_macro_mode, 1); + pause_ms(1000); + ASSERT_EQ(UINT, dynamic_macro_mode, 1); +END_TEST + +TEST("dynamic_macro_record_mode_off") + current_pseudolayer = NUM; + + process_record_user(BOT7, &pressed); + process_record_user(BOT7, &depressed); + ASSERT_EQ(UINT, dynamic_macro_mode, 1); + + process_record_user(BOT9, &pressed); + process_record_user(BOT9, &depressed); + ASSERT_EQ(UINT, dynamic_macro_mode, 0); +END_TEST + +TEST("dynamic_macro_record_one") + current_pseudolayer = NUM; + + process_record_user(BOT7, &pressed); + process_record_user(BOT7, &depressed); + ASSERT_EQ(UINT, dynamic_macro_mode, 1); + + process_record_user(TOP1, &pressed); + process_record_user(TOP1, &depressed); + + ASSERT_EQ(UINT, keyboard_history[1][KC_1], 255); + + process_record_user(BOT9, &pressed); + process_record_user(BOT9, &depressed); + + pause_ms(1000); + + process_record_user(BOT0, &pressed); + process_record_user(BOT0, &depressed); + + ASSERT_EQ(UINT, keyboard_history[1][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_1], 255); + + pause_ms(1000); + + process_record_user(BOT0, &pressed); + process_record_user(BOT0, &depressed); + + ASSERT_EQ(UINT, keyboard_history[3][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_1], 255); +END_TEST + +TEST("dynamic_macro_record_two") + current_pseudolayer = NUM; + + process_record_user(BOT7, &pressed); + process_record_user(BOT7, &depressed); + ASSERT_EQ(UINT, dynamic_macro_mode, 1); + + process_record_user(TOP1, &pressed); + process_record_user(TOP1, &depressed); + + process_record_user(TOP2, &pressed); + process_record_user(TOP2, &depressed); + + ASSERT_EQ(UINT, keyboard_history[1][KC_1], 255); + + process_record_user(BOT9, &pressed); + process_record_user(BOT9, &depressed); + + pause_ms(1000); + + process_record_user(BOT0, &pressed); + process_record_user(BOT0, &depressed); + + ASSERT_EQ(UINT, keyboard_history[1][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_2], 1); + ASSERT_EQ(UINT, keyboard_history[3][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_2], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_1], 255); +END_TEST + +TEST("dynamic_macro_record_two_parts") + current_pseudolayer = NUM; + + process_record_user(BOT7, &pressed); + process_record_user(BOT7, &depressed); + ASSERT_EQ(UINT, dynamic_macro_mode, 1); + + process_record_user(TOP1, &pressed); + process_record_user(TOP1, &depressed); + + process_record_user(TOP2, &pressed); + process_record_user(TOP2, &depressed); + + ASSERT_EQ(UINT, keyboard_history[1][KC_1], 255); + + process_record_user(BOT8, &pressed); + process_record_user(BOT8, &depressed); + + process_record_user(TOP3, &pressed); + process_record_user(TOP3, &depressed); + + process_record_user(BOT9, &pressed); + process_record_user(BOT9, &depressed); + + pause_ms(1000); + + process_record_user(BOT0, &pressed); + process_record_user(BOT0, &depressed); + + ASSERT_EQ(UINT, keyboard_history[1][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_2], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_3], 0); + + ASSERT_EQ(UINT, keyboard_history[2][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_2], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_3], 0); + + ASSERT_EQ(UINT, keyboard_history[3][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_2], 1); + ASSERT_EQ(UINT, keyboard_history[3][KC_3], 0); + + ASSERT_EQ(UINT, keyboard_history[4][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_2], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_3], 0); + + ASSERT_EQ(UINT, keyboard_history[5][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_2], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_3], 1); + + ASSERT_EQ(UINT, keyboard_history[6][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[6][KC_2], 0); + ASSERT_EQ(UINT, keyboard_history[6][KC_3], 0); + + ASSERT_EQ(UINT, keyboard_history[7][KC_1], 255); +END_TEST + +// dance + M() + +TEST("dance_tap") + process_record_user(BOT0, &pressed); + process_record_user(BOT0, &depressed); + + pause_ms(1000); + + ASSERT_EQ(UINT, keyboard_history[1][KC_9], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_0], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_9], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_0], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_9], 255); +END_TEST + +TEST("dance_hold") + process_record_user(BOT0, &pressed); + pause_ms(1000); + + ASSERT_EQ(UINT, keyboard_history[1][KC_9], 1); + + process_record_user(BOT0, &depressed); + ASSERT_EQ(UINT, keyboard_history[2][KC_9], 0); +END_TEST + +TEST("dance_tap_tap") + process_record_user(BOT0, &pressed); + process_record_user(BOT0, &depressed); + process_record_user(BOT0, &pressed); + process_record_user(BOT0, &depressed); + + pause_ms(1000); + + ASSERT_EQ(UINT, keyboard_history[1][KC_9], 0); + ASSERT_EQ(UINT, keyboard_history[1][KC_0], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_9], 0); + ASSERT_EQ(UINT, keyboard_history[2][KC_0], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_9], 255); +END_TEST + +TEST("dance_tap_hold") + process_record_user(BOT0, &pressed); + process_record_user(BOT0, &depressed); + pause_ms(1); + process_record_user(BOT0, &pressed); + pause_ms(1000); + + ASSERT_EQ(UINT, keyboard_history[1][KC_0], 1); + + process_record_user(BOT0, &depressed); + ASSERT_EQ(UINT, keyboard_history[2][KC_0], 0); +END_TEST + +// MK +TEST("multiple_keys") + current_pseudolayer = NUM; + + process_record_user(BOT1, &pressed); + process_record_user(BOT1, &depressed); + + ASSERT_EQ(UINT, keyboard_history[1][KC_LCTL], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[2][KC_LCTL], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_LSFT], 1); + + ASSERT_EQ(UINT, keyboard_history[3][KC_LCTL], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_LSFT], 1); + + ASSERT_EQ(UINT, keyboard_history[4][KC_LCTL], 0); + ASSERT_EQ(UINT, keyboard_history[4][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[5][KC_LCTL], 255); +END_TEST + +TEST("multiple_keys_interleaved") + current_pseudolayer = NUM; + + process_record_user(BOT1, &pressed); + pause_ms(CHORD_TIMEOUT+1); + + process_record_user(TOP1, &pressed); + process_record_user(TOP1, &depressed); + process_record_user(TOP1, &pressed); + process_record_user(TOP1, &depressed); + process_record_user(TOP1, &pressed); + process_record_user(TOP1, &depressed); + + process_record_user(BOT1, &depressed); + + ASSERT_EQ(UINT, keyboard_history[1][KC_LCTL], 1); + ASSERT_EQ(UINT, keyboard_history[1][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[2][KC_LCTL], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_LSFT], 1); + + ASSERT_EQ(UINT, keyboard_history[3][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[6][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[7][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[8][KC_1], 0); + + ASSERT_EQ(UINT, keyboard_history[9][KC_LCTL], 0); + ASSERT_EQ(UINT, keyboard_history[9][KC_LSFT], 1); + + ASSERT_EQ(UINT, keyboard_history[10][KC_LCTL], 0); + ASSERT_EQ(UINT, keyboard_history[10][KC_LSFT], 0); + + ASSERT_EQ(UINT, keyboard_history[11][KC_LCTL], 255); +END_TEST + +// D +TEST("dance_one") + current_pseudolayer = NUM; + + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + + pause_ms(CHORD_TIMEOUT+DANCE_TIMEOUT+2); + + ASSERT_EQ(UINT, keyboard_history[1][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_1], 255); + + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + + pause_ms(CHORD_TIMEOUT+DANCE_TIMEOUT+2); + + ASSERT_EQ(UINT, keyboard_history[1][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_1], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_1], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_1], 255); +END_TEST + +TEST("dance_two") + current_pseudolayer = NUM; + + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + + pause_ms(CHORD_TIMEOUT+DANCE_TIMEOUT+2); + + ASSERT_EQ(UINT, keyboard_history[1][KC_2], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_2], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_2], 255); + + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + + pause_ms(CHORD_TIMEOUT+DANCE_TIMEOUT+2); + + ASSERT_EQ(UINT, keyboard_history[1][KC_2], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_2], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_2], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_2], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_2], 255); +END_TEST + +TEST("dance_three") + current_pseudolayer = NUM; + + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + + pause_ms(CHORD_TIMEOUT+DANCE_TIMEOUT+2); + + ASSERT_EQ(UINT, keyboard_history[1][KC_3], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_3], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_3], 255); + + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + + pause_ms(CHORD_TIMEOUT+DANCE_TIMEOUT+2); + + ASSERT_EQ(UINT, keyboard_history[1][KC_3], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_3], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_3], 1); + ASSERT_EQ(UINT, keyboard_history[4][KC_3], 0); + ASSERT_EQ(UINT, keyboard_history[5][KC_3], 255); +END_TEST + +TEST("dance_two_held") + current_pseudolayer = NUM; + + process_record_user(BOT3, &pressed); + process_record_user(BOT3, &depressed); + process_record_user(BOT3, &pressed); + + pause_ms(CHORD_TIMEOUT+DANCE_TIMEOUT+2); + + ASSERT_EQ(UINT, keyboard_history[1][KC_2], 1); + ASSERT_EQ(UINT, keyboard_history[2][KC_2], 255); + + process_record_user(BOT3, &depressed); + ASSERT_EQ(UINT, keyboard_history[2][KC_2], 0); + ASSERT_EQ(UINT, keyboard_history[3][KC_2], 255); +END_TEST + +// These two are leaving the chording engine, they kinda have to be tested manually +// TO +// RESET + +END diff --git a/users/dennytom/chording_engine/tests/test_full.sh b/users/dennytom/chording_engine/tests/test_full.sh new file mode 100644 index 0000000000..ea93aec8f9 --- /dev/null +++ b/users/dennytom/chording_engine/tests/test_full.sh @@ -0,0 +1,11 @@ +#!/bin/sh +cd .. +python3 parser.py tests/test_keymap_def.json tests/test_keymap.c && \ +gcc -g tests/test.c -o tests/test && \ +tests/test && \ +python3 parser.py ../../../keyboards/butterstick/keymaps/tomas/keymap_def.json ../../../keyboards/butterstick/keymaps/tomas/keymap.c && \ +python3 parser.py ../../../keyboards/georgi/keymaps/tomas/keymap_def.json ../../../keyboards/georgi/keymaps/tomas/keymap.c && \ +python3 parser.py ../../../keyboards/georgi/keymaps/buttery/keymap_def.json ../../../keyboards/georgi/keymaps/buttery/keymap.c && \ +cd ../../../ && \ +make butterstick && \ +make georgi
\ No newline at end of file diff --git a/users/dennytom/chording_engine/tests/test_keymap_def.json b/users/dennytom/chording_engine/tests/test_keymap_def.json new file mode 100644 index 0000000000..eae2ed37cf --- /dev/null +++ b/users/dennytom/chording_engine/tests/test_keymap_def.json @@ -0,0 +1,145 @@ +{ + "keys": [ + "TOP1", "TOP2", "TOP3", "TOP4", "TOP5", "TOP6", "TOP7", "TOP8", "TOP9", "TOP0", + "BOT1", "BOT2", "BOT3", "BOT4", "BOT5", "BOT6", "BOT7", "BOT8", "BOT9", "BOT0" + ], + "parameters": { + "do_not_include_QMK": true, + "layout_function_name": "LAYOUT_test", + "chord_timeout": 100, + "dance_timeout": 200, + "leader_timeout": 750, + "tap_timeout": 50, + "command_max_length": 5, + "leader_max_length": 5, + "dynamic_macro_max_length": 20, + "string_max_length": 16, + "long_press_multiplier": 3, + "default_pseudolayer": "QWERTY" + }, + "layers": [ + { + "type": "auto" + }, + { + "type": "manual", + "keycodes": ["KC_1", "KC_2", "KC_3", "KC_4", "KC_5", "KC_6", "KC_7", "KC_8", "KC_9", "KC_0", + "KC_Q", "KC_W", "KC_E", "KC_R", "KC_T", "KC_Y", "KC_U", "KC_I", "KC_O", "KC_P" + ] + } + ], + "chord_sets": [ + { + "name": "rows", + "chords": [ + ["TOP1"], ["TOP2"], ["TOP3"], ["TOP4"], ["TOP5"], ["TOP6"], ["TOP7"], ["TOP8"], ["TOP9"], ["TOP0"], + ["TOP1", "BOT1"], ["TOP2", "BOT2"], ["TOP3", "BOT3"], ["TOP4", "BOT4"], ["TOP5", "BOT5"], ["TOP6", "BOT6"], ["TOP7", "BOT7"], ["TOP8", "BOT8"], ["TOP9", "BOT9"], ["TOP0", "BOT0"], + ["BOT1"], ["BOT2"], ["BOT3"], ["BOT4"], ["BOT5"], ["BOT6"], ["BOT7"], ["BOT8"], ["BOT9"], ["BOT0"] + ] + }, + { + "name": "cols", + "chords": [ + ["TOP1", "TOP2"], ["TOP2", "TOP3"], ["TOP3", "TOP4"], ["TOP4", "TOP5"], ["TOP5", "TOP6"], ["TOP6", "TOP7"], ["TOP7", "TOP8"], ["TOP8", "TOP9"], ["TOP9", "TOP0"], + ["TOP1", "TOP2", "BOT1", "BOT2"], ["TOP2", "TOP3", "BOT2", "BOT3"], ["TOP3", "TOP4", "BOT3", "BOT4"], ["TOP4", "TOP5", "BOT4", "BOT5"], ["TOP5", "TOP6", "BOT5", "BOT6"], ["TOP6", "TOP7", "BOT6", "BOT7"], ["TOP7", "TOP8", "BOT7", "BOT8"], ["TOP8", "TOP9", "BOT8", "BOT9"], ["TOP9", "TOP0", "BOT9", "BOT0"], + ["BOT1", "BOT2"], ["BOT2", "BOT3"], ["BOT3", "BOT4"], ["BOT4", "BOT5"], ["BOT5", "BOT6"], ["BOT6", "BOT7"], ["BOT7", "BOT8"], ["BOT8", "BOT9"], ["BOT9", "BOT0"] + ] + }, + { + "name": "asetniop", + "chords": [ + ["TOP1"], ["TOP2"], ["TOP3"], ["TOP4"], ["TOP7"], ["TOP8"], ["TOP9"], ["TOP0"], + ["TOP1", "TOP2"], ["TOP2", "TOP3"], ["TOP3", "TOP4"], ["TOP4", "TOP7"], ["TOP7", "TOP8"], ["TOP8", "TOP9"], ["TOP9", "TOP0"], + ["TOP1", "TOP3"], ["TOP2", "TOP4"], ["TOP3", "TOP7"], ["TOP4", "TOP8"], ["TOP7", "TOP9"], ["TOP8", "TOP0"], + ["TOP1", "TOP4"], ["TOP2", "TOP7"], ["TOP3", "TOP8"], ["TOP4", "TOP9"], ["TOP7", "TOP0"], + ["TOP1", "TOP7"], ["TOP2", "TOP8"], ["TOP3", "TOP9"], ["TOP4", "TOP0"], + ["TOP1", "TOP8"], ["TOP2", "TOP9"], ["TOP3", "TOP0"], + ["TOP1", "TOP9"], ["TOP2", "TOP0"], + ["TOP1", "TOP0"] + ] + } + ], + "pseudolayers": [ + { + "name": "ALWAYS_ON", + "chords": [ + { + "type": "visual", + "chord": [ + " ", " ", " ", " ", " ", " ", " ", "X", "X", "X", + " ", " ", " ", " ", " ", " ", " ", "X", "X", "X" + ], + "keycode": "MO(FNC, NUM)" + } + ] + }, + { + "name": "QWERTY", + "chords": [ + { + "type": "chord_set", + "set": "rows", + "keycodes": [ + "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", + "A", "S", "D", "F", "G", "H", "J", "K", "L", ";", + "AS(Z)", "KK(X, LCTL)", "KL(C, NUM)", "KM(V, LALT)", "B", "N", "M", "COMMA", ".", "M(double_dance, KC_9, KC_0)" + ] + }, + { + "type": "chord_set", + "set": "cols", + "keycodes": [ + "ESC", "", "", "", "", "", "", "", "", + "", "LEAD", "", "", "CMD", "", "", "", "", + "LSFT", "O(LSFT)", "", "", "", "O(NUM)", "MO(NUM)", "", "DF(NUM)" + ] + }, + { + "type": "visual", + "chord": [ + "X", "X", " ", " ", " ", " ", " ", " ", " ", " ", + "X", "X", " ", " ", " ", " ", " ", " ", " ", " " + ], + "keycode": "LOCK" + } + ] + }, + { + "name": "NUM", + "chords": [ + { + "type": "chord_set", + "set": "rows", + "keycodes": [ + "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", + "", "", "", "", "", "", "", "", "", "", + "", "KC_LEFT", "D(KC_1, KC_2, KC_3)", "", "", "", "DM_RECORD", "DM_NEXT", "DM_END", "DM_PLAY" + ] + }, + { + "type": "simple", + "chord": ["BOT1"], + "keycode": "MK(KC_LCTL, KC_LSFT)" + } + ] + }, + { + "name": "FNC", + "chords": [] + } + ], + "leader_sequences": [ + { + "name": "fnc_L1", + "function": "void fnc_L1(void) { key_in(KC_A); clear_keyboard(); }", + "sequence": ["KC_O", "KC_P"] + }, + { + "name": "fnc_L2", + "function": "void fnc_L2(void) { key_in(KC_S); clear_keyboard(); }", + "sequence": ["KC_P", "KC_O"] + } + ], + "extra_code": "void double_dance(const struct Chord* self) {\n switch (*self->state) {\n case ACTIVATED:\n *self->counter = (*self->counter + 1) % 2;\n break;\n case PRESS_FROM_ACTIVE:\n if (*self->counter == 1) {\n key_in(self->value1);\n } else {\n key_in(self->value2);\n }\n *self->state = FINISHED_FROM_ACTIVE;\n break;\n case FINISHED:\n if (*self->counter == 1) {\n tap_key(self->value1);\n } else {\n tap_key(self->value2);\n }\n *self->counter = 0;\n *self->state = IDLE;\n break;\n case RESTART:\n if (*self->counter == 1) {\n key_out(self->value1);\n } else {\n key_out(self->value2);\n }\n *self->counter = 0;\n break;\n default:\n break;\n }\n}\n", + "extra_dependencies": [] +}
\ No newline at end of file diff --git a/users/dennytom/chording_engine/tests/test_quick.sh b/users/dennytom/chording_engine/tests/test_quick.sh new file mode 100644 index 0000000000..3740122e27 --- /dev/null +++ b/users/dennytom/chording_engine/tests/test_quick.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +cd .. +python3 parser.py tests/test_keymap_def.json tests/test_keymap.c && \ +gcc -g tests/test.c -o tests/test && \ +tests/test
\ No newline at end of file |