summaryrefslogtreecommitdiff
path: root/tests/pke-test-static-ui.cpp
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-03-12 17:26:48 -0400
committerJonathan Bradley <jcb@pikum.xyz>2025-03-12 17:26:48 -0400
commit85a2ba407b1ae285b4080e14f8a18ecf4ec7da2c (patch)
tree0abe7044b6af5820e9f3c143733047b254e78e15 /tests/pke-test-static-ui.cpp
parent68ef51ed3247dc4e7bd5970b9279a7d6a938ca52 (diff)
pke: more testing features + more ui flex work
Diffstat (limited to 'tests/pke-test-static-ui.cpp')
-rw-r--r--tests/pke-test-static-ui.cpp106
1 files changed, 106 insertions, 0 deletions
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;
+}