From 206d0681c820ecd6802ef8d6adfff2d724e1f568 Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Sun, 11 Apr 2021 11:06:30 -0500 Subject: [PATCH] Add testcases for Leader plugin Signed-off-by: Michael Richters --- tests/plugins/Leader/basic/basic.ino | 66 +++++++++++++++ tests/plugins/Leader/basic/sketch.json | 6 ++ tests/plugins/Leader/basic/test.ktest | 107 +++++++++++++++++++++++++ 3 files changed, 179 insertions(+) create mode 100644 tests/plugins/Leader/basic/basic.ino create mode 100644 tests/plugins/Leader/basic/sketch.json create mode 100644 tests/plugins/Leader/basic/test.ktest diff --git a/tests/plugins/Leader/basic/basic.ino b/tests/plugins/Leader/basic/basic.ino new file mode 100644 index 00000000..febdf47e --- /dev/null +++ b/tests/plugins/Leader/basic/basic.ino @@ -0,0 +1,66 @@ +/* -*- mode: c++ -*- + * Copyright (C) 2021 Keyboard.io, Inc. + * + * 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, version 3. + * + * 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 . + */ + +#include +#include +#include + +// *INDENT-OFF* +KEYMAPS( + [0] = KEYMAP_STACKED + ( + LEAD(0), ___, ___, ___, ___, ___, ___, + Key_A, Key_B, Key_C, Key_D, ___, ___, ___, + ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, + ___, + + ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, + ___ + ), +) +// *INDENT-ON* + +KALEIDOSCOPE_INIT_PLUGINS(Leader); + +static void leaderBC(uint8_t id) { + Macros.type(PSTR("x")); +} + +static void leaderAC(uint8_t id) { + Macros.type(PSTR("xyz")); +} + +// *INDENT-OFF* +static const kaleidoscope::plugin::Leader::dictionary_t leader_dictionary[] PROGMEM = + LEADER_DICT( {LEADER_SEQ(LEAD(0), Key_B, Key_C), leaderBC}, + {LEADER_SEQ(LEAD(0), Key_A, Key_C), leaderAC} ); +// *INDENT-ON* + +void setup() { + Kaleidoscope.setup(); + Leader.time_out = 20; + Leader.dictionary = leader_dictionary; +} + +void loop() { + Kaleidoscope.loop(); +} diff --git a/tests/plugins/Leader/basic/sketch.json b/tests/plugins/Leader/basic/sketch.json new file mode 100644 index 00000000..8cc86922 --- /dev/null +++ b/tests/plugins/Leader/basic/sketch.json @@ -0,0 +1,6 @@ +{ + "cpu": { + "fqbn": "keyboardio:virtual:model01", + "port": "" + } +} diff --git a/tests/plugins/Leader/basic/test.ktest b/tests/plugins/Leader/basic/test.ktest new file mode 100644 index 00000000..62cfa2f6 --- /dev/null +++ b/tests/plugins/Leader/basic/test.ktest @@ -0,0 +1,107 @@ +VERSION 1 + +KEYSWITCH LEAD_0 0 0 +KEYSWITCH A 1 0 +KEYSWITCH B 1 1 +KEYSWITCH C 1 2 +KEYSWITCH D 1 3 + +# ============================================================================== +NAME Leader sequence AC + +RUN 4 ms +PRESS LEAD_0 +RUN 1 cycle + +RUN 4 ms +RELEASE LEAD_0 +RUN 1 cycle + +RUN 4 ms +PRESS A +RUN 1 cycle + +RUN 4 ms +RELEASE A +RUN 1 cycle + +RUN 4 ms +PRESS C +RUN 1 cycle +EXPECT keyboard-report Key_X # report should contain `X` (0x1b) +EXPECT keyboard-report empty # report should be empty +EXPECT keyboard-report Key_Y # report should contain `Y` (0x1c) +EXPECT keyboard-report empty # report should be empty +EXPECT keyboard-report Key_Z # report should contain `Z` (0x1d) +EXPECT keyboard-report empty # report should be empty + +RUN 4 ms +RELEASE C +RUN 1 cycle + +RUN 5 ms +EXPECT no keyboard-report # expect no more reports + +# ============================================================================== +NAME Leader sequence BC + +RUN 4 ms +PRESS LEAD_0 +RUN 1 cycle + +RUN 4 ms +RELEASE LEAD_0 +RUN 1 cycle + +RUN 4 ms +PRESS B +RUN 1 cycle + +RUN 4 ms +RELEASE B +RUN 1 cycle + +RUN 4 ms +PRESS C +RUN 1 cycle +EXPECT keyboard-report Key_X # report should contain `X` (0x1b) +EXPECT keyboard-report empty # report should be empty + +RUN 4 ms +RELEASE C +RUN 1 cycle + +RUN 5 ms +EXPECT no keyboard-report # expect no more reports + +# ============================================================================== +NAME Leader sequence timeout + +RUN 4 ms +PRESS LEAD_0 +RUN 1 cycle + +RUN 4 ms +RELEASE LEAD_0 +RUN 1 cycle + +RUN 4 ms +PRESS B +RUN 1 cycle + +RUN 24 ms +RELEASE B +RUN 1 cycle + +RUN 4 ms +PRESS C +RUN 1 cycle +EXPECT keyboard-report Key_C # report should contain `C` (0x06) + +RUN 4 ms +RELEASE C +RUN 1 cycle +EXPECT keyboard-report empty # report should be empty + +RUN 5 ms +EXPECT no keyboard-report # expect no more reports