diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/pke-test-dummy.cpp (renamed from tests/pke-test-dummy.c) | 7 | ||||
| -rw-r--r-- | tests/pke-test-dummy.h | 8 | ||||
| -rw-r--r-- | tests/pke-test-static-ui.cpp | 106 | ||||
| -rw-r--r-- | tests/pke-test-static-ui.h | 16 | ||||
| -rw-r--r-- | tests/pke-test-types.h | 11 | ||||
| -rw-r--r-- | tests/pke-test.cpp (renamed from tests/pke-test.c) | 26 |
6 files changed, 168 insertions, 6 deletions
diff --git a/tests/pke-test-dummy.c b/tests/pke-test-dummy.cpp index ea92c34..a7e2ddc 100644 --- a/tests/pke-test-dummy.c +++ b/tests/pke-test-dummy.cpp @@ -6,16 +6,17 @@ int pke_test_dummy_001() { } struct pke_test_group *pke_test_dummy_get_group() { - static struct pke_test tests[1] = { + static const uint64_t test_count = 1; + static struct pke_test tests[test_count] = { { .title = "test 001", .func = pke_test_dummy_001, .expected_result = 0, } }; - static struct pke_test_group group = {0}; + static struct pke_test_group group = {}; group.title = "dummy test"; - group.n_tests = 1; + group.n_tests = test_count; group.tests = &tests[0]; return &group; diff --git a/tests/pke-test-dummy.h b/tests/pke-test-dummy.h index b69609e..6abf8b7 100644 --- a/tests/pke-test-dummy.h +++ b/tests/pke-test-dummy.h @@ -3,6 +3,14 @@ #include "pke-test-types.h" +#ifdef __cplusplus +extern "C" { +#endif + struct pke_test_group *pke_test_dummy_get_group(); +#ifdef __cplusplus +} +#endif + #endif /* PKE_PKE_TEST_DUMMY_H */ diff --git a/tests/pke-test-static-ui.cpp b/tests/pke-test-static-ui.cpp new file mode 100644 index 0000000..6e6fb4b --- /dev/null +++ b/tests/pke-test-static-ui.cpp @@ -0,0 +1,106 @@ + +#include "./pke-test-static-ui.h" + +#include "window.hpp" +#include "dynamic-array.hpp" +#include "vendor-glm-include.hpp" +struct pke_ui_box_instance_buffer_item { + glm::mat4 pos_scale; + glm::vec2 px_scale; + float depth; + float padding[1]; +}; +struct pke_ui_flex_params { + float px_per_unit; + float unit_total; +}; +#define PKE_TEST_EXPOSE +#include "static-ui.hpp" + +void pke_test_static_ui_setup() { + Extent.width = 1920; + Extent.height = 1080; + pke_ui_init(); +} + +void pke_test_static_ui_teardown() { + pke_ui_teardown(); +} + +// test static +int pke_test_static_ui_000() { + DynArray<pke_ui_box_instance_buffer_item> arr{}; + float calculated_offset; + uint8_t err_index = 0; + + pke_ui_box *ui_box = pke_ui_box_new_root(); + ui_box->flags = PKE_UI_BOX_FLAG_POSITION_TYPE_STATIC; + ui_box->pos_top_left_x = 10; + ui_box->pos_top_left_y = 10; + ui_box->max_width = 500; + ui_box->max_height = 500; + + pke_ui_box *c_ui_box = pke_ui_box_new_child(ui_box); + c_ui_box->flags = PKE_UI_BOX_FLAG_POSITION_TYPE_STATIC; + c_ui_box->pos_top_left_x = 10; + c_ui_box->pos_top_left_y = 10; + c_ui_box->max_width = 100; + c_ui_box->max_height = 100; + + calculated_offset = ui_box->pos_top_left_x + c_ui_box->pos_top_left_x + built_in_offset; + + pke_ui_calc_px(arr, nullptr, ui_box); + pke_ui_recalc_sizes_recursive(arr, ui_box, 0); + + PKE_TEST_ASSERT(ui_box->internal.parent == nullptr, err_index); + PKE_TEST_ASSERT(c_ui_box->internal.parent != nullptr, err_index); + + PKE_TEST_ASSERT(ui_box->internal.px_corner_x == 10, err_index); + PKE_TEST_ASSERT(ui_box->internal.px_corner_y == 10, err_index); + PKE_TEST_ASSERT(c_ui_box->internal.px_corner_x == calculated_offset, err_index); + PKE_TEST_ASSERT(c_ui_box->internal.px_corner_y == calculated_offset, err_index); + + return 0; +} + +// test dynamic +int pke_test_static_ui_100() { + return 0; +} + + +// test flex +int pke_test_static_ui_200() { + return 0; +} + +pke_test_group *pke_test_static_ui_get_group() { + static const uint64_t test_count = 3; + static struct pke_test tests[test_count] = { + { + .title = "test 000", + .func = pke_test_static_ui_000, + .expected_result = 0, + }, + { + .title = "test 100", + .func = pke_test_static_ui_100, + .expected_result = 0, + }, + { + .title = "test 200", + .func = pke_test_static_ui_200, + .expected_result = 0, + }, + }; + static struct pke_test_group group = {}; + group.title = "static_ui"; + group.group_setup = NULL; + group.group_teardown = NULL; + group.test_setup = pke_test_static_ui_setup; + group.test_teardown = pke_test_static_ui_teardown; + group.tests = &tests[0]; + group.n_tests = test_count; + + return &group; +} diff --git a/tests/pke-test-static-ui.h b/tests/pke-test-static-ui.h new file mode 100644 index 0000000..673adf8 --- /dev/null +++ b/tests/pke-test-static-ui.h @@ -0,0 +1,16 @@ +#ifndef PKE_PKE_TEST_STATIC_UI_H +#define PKE_PKE_TEST_STATIC_UI_H + +#include "pke-test-types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct pke_test_group *pke_test_static_ui_get_group(); + +#ifdef __cplusplus +} +#endif + +#endif /* PKE_PKE_TEST_STATIC_UI_H */ diff --git a/tests/pke-test-types.h b/tests/pke-test-types.h index 5278eae..5a9ee24 100644 --- a/tests/pke-test-types.h +++ b/tests/pke-test-types.h @@ -15,6 +15,11 @@ typedef int (pke_test_func)(); struct pke_test_group; typedef struct pke_test_group *(pke_test_get_group)(); +typedef void (pke_test_group_setup()); +typedef void (pke_test_group_teardown()); +typedef void (pke_test_setup()); +typedef void (pke_test_teardown()); + struct pke_test { const char *title; pke_test_func *func; @@ -23,8 +28,14 @@ struct pke_test { struct pke_test_group { const char *title; + pke_test_group_setup *group_setup; + pke_test_group_teardown *group_teardown; + pke_test_setup *test_setup; + pke_test_teardown *test_teardown; struct pke_test *tests; uint32_t n_tests; }; +#define PKE_TEST_ASSERT(condition, index) if (!(condition)) { return ++index; } else { ++index; } + #endif /* PKE_PKE_TEST_TYPES_H */ diff --git a/tests/pke-test.c b/tests/pke-test.cpp index 4f88dbf..61b6fb8 100644 --- a/tests/pke-test.c +++ b/tests/pke-test.cpp @@ -2,7 +2,9 @@ #include "./pke-test-types.h" #include "./pke-test-dummy.h" +#include "./pke-test-static-ui.h" +#include "pk.h" #include "unistd.h" #include <stdio.h> @@ -25,30 +27,48 @@ int main(int argc, char *argv[]) (void)argc; (void)argv; int i = 0; + int result; uint32_t k, pass_count; + double nanoseconds; + double group_nanoseconds; + pk_tmr func_tmr; pke_test_get_group *group_fns[] = { pke_test_dummy_get_group, + pke_test_static_ui_get_group, NULL, }; + fprintf(stdout, "\r\n"); pke_test_get_group *fn = group_fns[i]; while (fn != NULL) { pass_count = 0; + group_nanoseconds = 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) { fprintf(stdout, "[pke-test]:[%s]:[%s] Begin.\n", group->title, group->tests[k].title); + if (group->test_setup != NULL) (group->test_setup)(); lj.expected_exit = 0; lj.caught = 0; - if (group->tests[k].expected_result == (group->tests[k].func)()){ + pk_tmr_start(func_tmr); + result = (group->tests[k].func)(); + pk_tmr_stop(func_tmr); + nanoseconds = pk_tmr_duration_double(func_tmr); + group_nanoseconds += nanoseconds; + 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, nanoseconds); } else { - fprintf(stdout, "[pke-test]:[%s]:[%s] %sFailed.%s\n", group->title, group->tests[k].title, CLR_RED, CLR_WHITE); + 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)(); } - fprintf(stdout, "[pke-test]:[%s] End. ( %s%03d%s / %03d ) Tests Completed.\n\n", group->title, pass_count == group->n_tests ? CLR_GREEN : CLR_RED, pass_count, CLR_WHITE, group->n_tests); + 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_nanoseconds); i += 1; fn = group_fns[i]; } |
