Skip to content

Commit

Permalink
Merge pull request #1374 from justincmoy/cycle-tests
Browse files Browse the repository at this point in the history
Add tests for the Cycle plugin
  • Loading branch information
obra authored Dec 19, 2023
2 parents e6a0d44 + 826c347 commit 5b8fe2f
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/plugins/Cycle/basic/basic.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* -*- mode: c++ -*-
* Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
*/

#include <Kaleidoscope.h>
#include <Kaleidoscope-Cycle.h>

#include "./common.h"

// *INDENT-OFF*
KEYMAPS(
[0] = KEYMAP_STACKED
(
Key_A, Key_B, Key_C, Key_D, Key_Cycle, ___, ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___,
___,

___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___,
___
),
)
// *INDENT-ON*


void cycleAction(Key previous_key, uint8_t cycle_count) {
if (previous_key == Key_A) {
Cycle.replace(Key_1);
} else if (previous_key == Key_B) {
cycleThrough(Key_B, Key_1, Key_2);
}
}

KALEIDOSCOPE_INIT_PLUGINS(Cycle);

void setup() {
Kaleidoscope.setup();
}

void loop() {
Kaleidoscope.loop();
}
27 changes: 27 additions & 0 deletions tests/plugins/Cycle/basic/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// -*- mode: c++ -*-

/* Kaleidoscope - Firmware for computer input devices
* Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <cstdint>

namespace kaleidoscope {
namespace testing {

} // namespace testing
} // namespace kaleidoscope
6 changes: 6 additions & 0 deletions tests/plugins/Cycle/basic/sketch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cpu": {
"fqbn": "keyboardio:virtual:model01",
"port": ""
}
}
1 change: 1 addition & 0 deletions tests/plugins/Cycle/basic/sketch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_fqbn: keyboardio:virtual:model01
72 changes: 72 additions & 0 deletions tests/plugins/Cycle/basic/test.ktest
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
VERSION 1

KEYSWITCH A 0 0
KEYSWITCH B 0 1
KEYSWITCH C 0 2
KEYSWITCH D 0 3
KEYSWITCH CYCLE 0 4

# ==============================================================================
NAME Cycle simple_replace
RUN 5 ms
PRESS A
RUN 1 cycle
EXPECT keyboard-report Key_A # Report should contain A
RELEASE A
RUN 1 cycle
PRESS CYCLE
EXPECT keyboard-report empty # Report should be empty
RUN 1 cycle
RELEASE CYCLE
RUN 1 cycle
EXPECT keyboard-report Key_Backspace # Report should contain Backspace
EXPECT keyboard-report empty # Report should be empty after Backspace
EXPECT keyboard-report Key_1 # Report should contain 1
EXPECT keyboard-report empty # Report should be empty after 1

NAME Cycle cycleThrough_with_loop
RUN 5 ms
PRESS B
RUN 1 cycle
EXPECT keyboard-report Key_B # Report should contain B
RELEASE B
RUN 1 cycle
PRESS CYCLE
EXPECT keyboard-report empty # Report should be empty
RUN 1 cycle
RELEASE CYCLE
RUN 1 cycle
EXPECT keyboard-report Key_Backspace # Report should contain Backspace for first key
EXPECT keyboard-report empty # Report should be empty after Backspace for first key
EXPECT keyboard-report Key_1 # Report should contain 1
EXPECT keyboard-report empty # Report should be empty after 1
RUN 1 cycle
PRESS CYCLE
RUN 1 cycle
RELEASE CYCLE
RUN 1 cycle
EXPECT keyboard-report Key_Backspace # Report should contain Backspace for second key
EXPECT keyboard-report empty # Report should be empty after Backspace for second key
EXPECT keyboard-report Key_2 # Report should contain 2
EXPECT keyboard-report empty # Report should be empty after 2
RUN 1 cycle
PRESS CYCLE
RUN 1 cycle
RELEASE CYCLE
RUN 1 cycle
EXPECT keyboard-report Key_Backspace # Report should contain Backspace for zeroth key
EXPECT keyboard-report empty # Report should be empty after Backspace for zeroth key
EXPECT keyboard-report Key_B # Report should contain B again
EXPECT keyboard-report empty # Report should be empty after B again

NAME Cycle does_not_activate
RUN 5 ms
PRESS C
RUN 1 cycle
EXPECT keyboard-report Key_C # Report should contain C
RELEASE C
RUN 1 cycle
PRESS CYCLE
EXPECT keyboard-report empty # Report should be empty
RUN 1 cycle
RELEASE CYCLE

0 comments on commit 5b8fe2f

Please sign in to comment.