Skip to content
Merged
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
2 changes: 2 additions & 0 deletions tests/expected/test_kb_cmd.expect
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ loop test starting
loop test completed
nesting test starting
nesting test completed
single iteration test starting
single iteration test completed
char table test starting
char table test completed
word test starting
Expand Down
9 changes: 5 additions & 4 deletions tests/src/kb_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#include "test_helper.h"

// Returns 0 if executed successfully, non-zero otherwise
typedef int (*CmdFunc)(void);
// Index is passed in for logging purposes
typedef int (*CmdFunc)(int);

struct LoopNode {
int idx;
Expand Down Expand Up @@ -143,7 +144,7 @@ static struct KbCmd keyPressCMD(enum KeyCode code, enum KeyState event,
}

static struct KbCmd keyPressCMDFromData(struct KeyData data) {
return (keyPressCMD(data.c, KeyPressed, data.mods));
return keyPressCMD(data.c, KeyPressed, data.mods);
}

static struct KbCmd typeWordCMD(char *word) {
Expand All @@ -167,8 +168,8 @@ static struct KbCmd endCMD() {
return (struct KbCmd){CMD_END, {}};
}

// Returns 0 when exiting normally, and anything else when things go wrong
typedef void (*KeyPressHandler)(struct PS2Buf_t);
// Returns 0 when exiting normally, and anything else when things go wrong
typedef int (*ExecFunc)(struct KbCmd, int *, KeyPressHandler);

// Commented out to avoid gcc complaining about it being unused
Expand Down Expand Up @@ -207,7 +208,7 @@ static int baseExec(struct KbCmd cmd, int *idx, KeyPressHandler kp) {
}
break;
case CMD_FUNC:
return cmd.data.func();
return cmd.data.func(*idx);
case CMD_END:
break;
default:
Expand Down
40 changes: 29 additions & 11 deletions tests/src/test_kb_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#include "string.h"

#define testStart(name, print) \
int name##Start() { \
int name##Start(int) { \
char text[] = print " starting\n"; \
serialWrite(COM1, (uint8_t *)(text), sizeof(text) - 1); \
return 0; \
}

#define testEnd(name, print) \
int name##End() { \
int name##End(int) { \
char text[] = print " completed\n"; \
serialWrite(COM1, (uint8_t *)(text), sizeof(text) - 1); \
return 0; \
Expand All @@ -18,7 +18,7 @@
char buff[64];
int buffIdx = 0;

int resetBuff() {
int resetBuff(int) {
memset(buff, 0, sizeof(buff));
buffIdx = 0;
return 0;
Expand All @@ -38,6 +38,10 @@ testEnd(loopTest, "loop test")
testStart(nestingTest, "nesting test")
testEnd(nestingTest, "nesting test")

// Single Iteration prints
testStart(singleIterationTest, "single iteration test")
testEnd(singleIterationTest, "single iteration test")

// Char table prints
testStart(charTableTest, "char table test")
testEnd(charTableTest, "char table test")
Expand All @@ -55,36 +59,41 @@ int v = 0;

// clang-format on

int vReset() {
int vReset(int) {
v = 0;
return 0;
}

int vInc() {
int vInc(int) {
v++;
return 0;
}

int testSingleLoop() {
int testSingleLoop(int) {
ASSERT_M(v == 4, "Expected to loop 4 times, looped %i time(s) instead", v);
return 0;
}

int testNestedLoop() {
int testNestedLoop(int) {
ASSERT_M(v == 6, "Expected to loop 6 times, looped %i time(s) instead", v);
return 0;
}

int testSingleIteration(int) {
ASSERT_M(v == 1, "Expected to loop 1 time, looped %i time(s) instead", v);
return 0;
}

// Char table testing
int capitalShiftTest() {
int capitalShiftTest(int) {
ASSERT(Key_a == charToPressCMD['a'].c);
ASSERT(0 == charToPressCMD['a'].mods);
ASSERT(Key_a == charToPressCMD['A'].c);
ASSERT(KEY_MOD_SHIFT == charToPressCMD['A'].mods)
return 0;
}

int shiftTest() {
int shiftTest(int) {
ASSERT(Key_grave == charToPressCMD['`'].c)
ASSERT(0 == charToPressCMD['`'].mods)
ASSERT(Key_grave == charToPressCMD['~'].c)
Expand All @@ -93,12 +102,12 @@ int shiftTest() {
}

// Word type testing
int wordTest() {
int wordTest(int) {
ASSERT(strncmp("test", buff, 5) == 0)
return 0;
}

int complexWordTest() {
int complexWordTest(int) {
ASSERT(strncmp("This is a very Loong word$%@^@\\", buff, 32) == 0)
return 0;
}
Expand All @@ -124,6 +133,15 @@ void test_main() {
funcCMD(testNestedLoop),
funcCMD(nestingTestEnd),

funcCMD(vReset),
// Single iteration test
funcCMD(singleIterationTestStart),
loopStartCMD(1),
funcCMD(vInc),
loopEndCMD(),
funcCMD(testSingleIteration),
funcCMD(singleIterationTestEnd),

// Char table values test
funcCMD(charTableTestStart),
funcCMD(capitalShiftTest),
Expand Down