Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
130 additions
and 3 deletions.
- +5 −1 tests/Makefile
- +36 −0 tests/main.c
- +2 −2 tests/parser_tests.h
- +79 −0 tests/process_tests.c
- +8 −0 tests/process_tests.h
| @@ -1,13 +1,49 @@ | ||
| #include <stdint.h> | ||
|
|
||
| #include "greatest/greatest.h" | ||
|
|
||
| #include "teletype.h" | ||
|
|
||
| #include "parser_tests.h" | ||
| #include "process_tests.h" | ||
|
|
||
| void tele_metro(int16_t m, int16_t m_act, uint8_t m_reset) {} | ||
| void tele_tr(uint8_t i, int16_t v) {} | ||
| void tele_cv(uint8_t i, int16_t v, uint8_t s) {} | ||
| void tele_cv_slew(uint8_t i, int16_t v) {} | ||
| void tele_delay(uint8_t i) {} | ||
| void tele_s(uint8_t i) {} | ||
| void tele_cv_off(uint8_t i, int16_t v) {} | ||
| void tele_ii(uint8_t i, int16_t d) {} | ||
| void tele_scene(uint8_t i) {} | ||
| void tele_pi() {} | ||
| void tele_script(uint8_t a) {} | ||
| void tele_kill() {} | ||
| void tele_mute(uint8_t i, uint8_t s) {} | ||
| void tele_input_state(uint8_t n) {} | ||
|
|
||
| GREATEST_MAIN_DEFS(); | ||
|
|
||
| int main(int argc, char **argv) { | ||
| update_metro = &tele_metro; | ||
| update_tr = &tele_tr; | ||
| update_cv = &tele_cv; | ||
| update_cv_slew = &tele_cv_slew; | ||
| update_delay = &tele_delay; | ||
| update_s = &tele_s; | ||
| update_cv_off = &tele_cv_off; | ||
| update_ii = &tele_ii; | ||
| update_scene = &tele_scene; | ||
| update_pi = &tele_pi; | ||
| run_script = &tele_script; | ||
| update_kill = &tele_kill; | ||
| update_mute = &tele_mute; | ||
| update_input = &tele_input_state; | ||
|
|
||
| GREATEST_MAIN_BEGIN(); | ||
|
|
||
| RUN_SUITE(parser_suite); | ||
| RUN_SUITE(process_suite); | ||
|
|
||
| GREATEST_MAIN_END(); | ||
| } |
| @@ -0,0 +1,79 @@ | ||
| #include "process_tests.h" | ||
|
|
||
| #include "greatest/greatest.h" | ||
|
|
||
| #include "teletype.h" | ||
|
|
||
| // runs multiple lines of commands and then asserts that the final answer is | ||
| // correct | ||
| TEST process_helper(size_t n, char* lines[], int16_t answer) { | ||
| process_result_t result = {.h = PR_EMPTY, .v = 0 }; | ||
| for (size_t i = 0; i < n; i++) { | ||
| tele_command_t cmd; | ||
| error_t error = parse(lines[i], &cmd); | ||
| if (error != E_OK) { FAIL(); } | ||
| if (validate(&cmd) != E_OK) { FAIL(); } | ||
| result = process(&cmd); | ||
| } | ||
| ASSERT_EQ(PR_VALUE, result.h); | ||
| ASSERT_EQ(answer, result.v); | ||
|
|
||
| PASS(); | ||
| } | ||
|
|
||
| TEST test_ADD() { | ||
| // beware of global state!!! | ||
| char* test1[1] = { "ADD 5 6" }; | ||
| CHECK_CALL(process_helper(1, test1, 11)); | ||
|
|
||
| char* test2[1] = { "ADD 2 -2" }; | ||
| CHECK_CALL(process_helper(1, test2, 0)); | ||
|
|
||
| PASS(); | ||
| } | ||
|
|
||
| TEST test_P() { | ||
| // beware of global state!!! | ||
| char* test1[2] = { "P 0 1", "P 0" }; | ||
| CHECK_CALL(process_helper(2, test1, 1)); | ||
|
|
||
| char* test2[2] = { "P 0 2", "P 0" }; | ||
| CHECK_CALL(process_helper(2, test2, 2)); | ||
|
|
||
| PASS(); | ||
| } | ||
|
|
||
| TEST test_PN() { | ||
| // beware of global state!!! | ||
| char* test1[2] = { "PN 0 0 1", "PN 0 0" }; | ||
| CHECK_CALL(process_helper(2, test1, 1)); | ||
|
|
||
| char* test2[2] = { "PN 0 0 2", "PN 0 0" }; | ||
| CHECK_CALL(process_helper(2, test2, 2)); | ||
|
|
||
| char* test3[3] = { "P.N 0", "P 0 3", "PN 0 0" }; | ||
| CHECK_CALL(process_helper(3, test3, 3)); | ||
|
|
||
| char* test4[3] = { "P.N 0", "PN 0 0 4", "P 0" }; | ||
| CHECK_CALL(process_helper(3, test4, 4)); | ||
|
|
||
| PASS(); | ||
| } | ||
|
|
||
| TEST test_X() { | ||
| // beware of global state!!! | ||
| char* test1[2] = { "X 0", "X" }; | ||
| CHECK_CALL(process_helper(2, test1, 0)); | ||
|
|
||
| char* test2[2] = { "X 10", "X" }; | ||
| CHECK_CALL(process_helper(2, test2, 10)); | ||
|
|
||
| PASS(); | ||
| } | ||
|
|
||
| SUITE(process_suite) { | ||
| RUN_TEST(test_ADD); | ||
| RUN_TEST(test_P); | ||
| RUN_TEST(test_PN); | ||
| RUN_TEST(test_X); | ||
| } |
| @@ -0,0 +1,8 @@ | ||
| #ifndef _PROCESS_TESTS_H_ | ||
| #define _PROCESS_TESTS_H_ | ||
|
|
||
| #include "greatest/greatest.h" | ||
|
|
||
| SUITE_EXTERN(process_suite); | ||
|
|
||
| #endif |