diff options
Diffstat (limited to 'tests/pke-test.cpp')
| -rw-r--r-- | tests/pke-test.cpp | 77 |
1 files changed, 4 insertions, 73 deletions
diff --git a/tests/pke-test.cpp b/tests/pke-test.cpp index 7a314b5..b7a45aa 100644 --- a/tests/pke-test.cpp +++ b/tests/pke-test.cpp @@ -11,37 +11,16 @@ #include "./pke-test-stubs.h" #include "pk.h" -#include "unistd.h" -#include <stdio.h> -#define CLR_WHITE "\033[0m" -#define CLR_GREEN "\033[92m" -#define CLR_RED "\033[31m" - -// https://stackoverflow.com/questions/64190847/how-to-catch-a-call-to-exit-for-unit-testing -struct pke_test_long_jump lj; -void exit(int code) { - if (lj.expected_exit) { - lj.caught = 1; - longjmp(lj.jump_env, 1); - } - _exit(code); -} +#include <unistd.h> int main(int argc, char *argv[]) { (void)argc; (void)argv; - int i = 0; - int result; - uint32_t k, pass_count, test_group_count, test_group_pass_count; - double elapsed_ms; - double group_ms; - double total_ms; - pk_tmr func_tmr; - pk_tmr total_tmr; - pke_test_get_group *group_fns[] = { + const unsigned long test_group_count = 6; + pk_test_group_get *group_fns[test_group_count] = { pke_test_dummy_get_group, pke_test_static_ui_get_group, pke_test_serialization_get_group, @@ -49,57 +28,9 @@ int main(int argc, char *argv[]) pke_test_load_unload_get_group, pke_test_font_get_group, // pke_test_audio_get_group, - NULL, }; - total_ms = 0; - test_group_count = 0; - test_group_pass_count = 0; - pk_tmr_start(total_tmr); - fprintf(stdout, "\r\n"); - pke_test_get_group *fn = group_fns[i]; - while (fn != NULL) { - test_group_count += 1; - pass_count = 0; - group_ms = 0; - struct pke_test_group *group = (fn)(); - fprintf(stdout, "[pke-test]:[%s] Begin.\n", group->title); - if (group->group_setup != NULL) (group->group_setup)(); - for (k = 0; k < group->n_tests; ++k) { - pke_test_stub_init_vulkan(); - if (group->test_setup != NULL) (group->test_setup)(); - lj.expected_exit = 0; - lj.caught = 0; - pk_tmr_start(func_tmr); - result = (group->tests[k].func)(); - pk_tmr_stop(func_tmr); - elapsed_ms = pk_tmr_duration_dbl_mili(func_tmr); - group_ms += elapsed_ms; - total_ms += elapsed_ms; - if (result == group->tests[k].expected_result){ - pass_count += 1; - fprintf(stdout, "[pke-test]:[%s]:[%s] %sPassed.%s\n", group->title, group->tests[k].title, CLR_GREEN, CLR_WHITE); - fprintf(stdout, "[pke-test]:[%s]:[%s] Elapsed ms: '%f'.\n", group->title, group->tests[k].title, elapsed_ms); - } else { - fprintf(stdout, "[pke-test]:[%s]:[%s] %sFailed.%s Expected: '%i' Got: '%i'.\n", group->title, group->tests[k].title, CLR_RED, CLR_WHITE, group->tests[k].expected_result, result); - } - if (group->test_teardown != NULL) (group->test_teardown)(); - pke_test_stub_teardown_vulkan(); - } - if (group->group_teardown != NULL) (group->group_teardown)(); - fprintf(stdout, "[pke-test]:[%s] End. ( %s%03d%s / %03d ) Tests Completed.\n", group->title, pass_count == group->n_tests ? CLR_GREEN : CLR_RED, pass_count, CLR_WHITE, group->n_tests); - fprintf(stdout, "[pke-test]:[%s] End. Elapsed ms: '%f'.\n\n", group->title, group_ms); - if (pass_count == group->n_tests) { - test_group_pass_count += 1; - } - i += 1; - fn = group_fns[i]; - } - pk_tmr_stop(total_tmr); - - fprintf(stdout, "[pke-test] End. ( %s%03d%s / %03d ) Test Groups Completed.\n", test_group_count == test_group_pass_count ? CLR_GREEN : CLR_RED, test_group_pass_count, CLR_WHITE, test_group_count); - fprintf(stdout, "[pke-test] End. Elapsed ms: '%f' (test fn sum).\n", total_ms); - fprintf(stdout, "[pke-test] End. Elapsed ms: '%f' (actual).\n\n", pk_tmr_duration_dbl_mili(total_tmr)); + pk_test_run_test_groups(group_fns, test_group_count); return 0; } |
