diff --git a/tests/expected/test_kb_cmd.expect b/tests/expected/test_kb_cmd.expect index 520f230..f917178 100644 --- a/tests/expected/test_kb_cmd.expect +++ b/tests/expected/test_kb_cmd.expect @@ -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 diff --git a/tests/src/kb_cmd.h b/tests/src/kb_cmd.h index ac9a6ac..b2ec161 100644 --- a/tests/src/kb_cmd.h +++ b/tests/src/kb_cmd.h @@ -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; @@ -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) { @@ -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 @@ -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: diff --git a/tests/src/test_kb_cmd.c b/tests/src/test_kb_cmd.c index a90ecf0..ad83de9 100644 --- a/tests/src/test_kb_cmd.c +++ b/tests/src/test_kb_cmd.c @@ -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; \ @@ -18,7 +18,7 @@ char buff[64]; int buffIdx = 0; -int resetBuff() { +int resetBuff(int) { memset(buff, 0, sizeof(buff)); buffIdx = 0; return 0; @@ -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") @@ -55,28 +59,33 @@ 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); @@ -84,7 +93,7 @@ int capitalShiftTest() { return 0; } -int shiftTest() { +int shiftTest(int) { ASSERT(Key_grave == charToPressCMD['`'].c) ASSERT(0 == charToPressCMD['`'].mods) ASSERT(Key_grave == charToPressCMD['~'].c) @@ -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; } @@ -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),