summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-05-21 10:42:46 -0400
committerJonathan Bradley <jcb@pikum.xyz>2025-05-21 10:42:46 -0400
commitbaa0276594b5871d9e61ef4f454bc84074c44084 (patch)
tree1083cb62c57d5a4cd325fab2275b02ae66bb849b /tests
parent85cac31d06f5ef15b36aa6bc4edd31f85221a7b7 (diff)
pke: serialize nested ui-boxes
Diffstat (limited to 'tests')
-rw-r--r--tests/pke-test-serialization.cpp173
1 files changed, 171 insertions, 2 deletions
diff --git a/tests/pke-test-serialization.cpp b/tests/pke-test-serialization.cpp
index 840adfa..5663275 100644
--- a/tests/pke-test-serialization.cpp
+++ b/tests/pke-test-serialization.cpp
@@ -9,7 +9,6 @@
#include "physics.hpp"
#include "pk.h"
#include "scene.hpp"
-#include "serialization-camera.hpp"
#include "serialization-component.hpp"
#include "serialization.hpp"
#include "static-ui.hpp"
@@ -569,8 +568,168 @@ int pke_test_deserialization_103() {
return 0;
}
+const char *const test_004_str = R"VOGON(:PKFB:
+:0:
+
+UIBox:00000000!00000000
+ChildId:00000000!00000001
+UUID:02020202-0202-0202-0202-020202020202
+Flags:0x02
+PosTopLeft:1.000000;1.000000
+MaxSize:1278.000000;718.000000
+Type:0x00
+Layer:0x00
+
+UIBox:00000000!00000001
+UUID:01010101-0101-0101-0101-010101010101
+ParentUUID:02020202-0202-0202-0202-020202020202
+Flags:0x04
+PosTopLeft:0.100000;0.100000
+MaxSize:0.800000;0.800000
+Type:0x00
+Layer:0x00
+
+:PKFE:)VOGON";
+int pke_test_serialization_004() {
+ int64_t err_index = 0;
+ uint32_t i, k;
+ srlztn_serialize_helper *h = nullptr;
+ pke_kve *kve = nullptr;
+ std::stringstream ss;
+ try {
+ bkt = pk_bucket_create("pke_test_serialization", PK_DEFAULT_BUCKET_SIZE, false);
+ h = pke_serialize_init(bkt);
+
+ pke_ui_box *ui_box_p = pke_ui_box_new_root(PKE_UI_BOX_TYPE_STANDARD, uuid_n[2]);
+ ui_box_p->flags |= PKE_UI_BOX_FLAG_POSITION_TYPE_STATIC;
+ ui_box_p->pos_top_left.x = 1.f;
+ ui_box_p->pos_top_left.y = 1.f;
+ ui_box_p->max_size.x = 1278.f;
+ ui_box_p->max_size.y = 718.f;
+
+ pke_ui_box *ui_box_c = pke_ui_box_new_child(ui_box_p, PKE_UI_BOX_TYPE_STANDARD, uuid_n[1]);
+ ui_box_c->flags |= PKE_UI_BOX_FLAG_POSITION_TYPE_DYNAMIC;
+ ui_box_c->pos_top_left.x = 0.1;
+ ui_box_c->pos_top_left.y = 0.1;
+ ui_box_c->max_size.x = 0.8;
+ ui_box_c->max_size.y = 0.8;
+
+ pke_serialize_scene(h);
+ pke_serialize_scene_to_stream(ss, h);
+ std::string s = ss.str();
+
+ PKE_TEST_ASSERT(h->bkt == bkt, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers.bkt == bkt, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers.next == 2, err_index);
+ // ui box
+ PKE_TEST_ASSERT(h->kvp_containers[0].child_handles.next == 1, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers[0].arr.next == 6, err_index);
+ // ui box
+ PKE_TEST_ASSERT(h->kvp_containers[1].child_handles.next == 0, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers[1].arr.next == 7, err_index);
+
+ // 8
+ for (k = 0; k < h->kvp_containers.next; ++k) {
+ for (i = 0; i < h->kvp_containers[k].arr.next; ++i) {
+ // 8 + (3 * (7 + 6))
+ kve = &h->kvp_containers[k].arr[i];
+ PKE_TEST_ASSERT(kve->key != nullptr, err_index);
+ PKE_TEST_ASSERT(kve->val != nullptr, err_index);
+ PKE_TEST_ASSERT(kve->end != nullptr, err_index);
+ }
+ }
+
+ // 47
+ PKE_TEST_ASSERT(strstr(test_004_str, s.c_str()) != nullptr, err_index);
+
+ pke_serialize_teardown(h);
+
+ } catch (const std::exception &ex) {
+ pk_bucket_destroy(bkt);
+ throw;
+ }
+ pk_bucket_destroy(bkt);
+ return 0;
+}
+
+int pke_test_deserialization_104() {
+ int64_t err_index = 0;
+ uint32_t i, k;
+ srlztn_deserialize_helper *h = nullptr;
+ pke_kve *kve = nullptr;
+ std::stringstream ss(test_004_str);
+ try {
+ bkt = pk_bucket_create("pke_test_serialization", PK_DEFAULT_BUCKET_SIZE, false);
+ h = pke_deserialize_init(bkt);
+
+ pke_deserialize_scene_from_stream(ss, h);
+
+ PKE_TEST_ASSERT(h->bkt == bkt, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers.bkt == bkt, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers.next == 2, err_index);
+ // ui box
+ PKE_TEST_ASSERT(h->kvp_containers[0].child_handles.next == 1, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers[0].arr.next == 6, err_index);
+ // ui box
+ PKE_TEST_ASSERT(h->kvp_containers[1].child_handles.next == 0, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers[1].arr.next == 7, err_index);
+
+ // 8
+ for (k = 0; k < h->kvp_containers.next; ++k) {
+ for (i = 0; i < h->kvp_containers[k].arr.next; ++i) {
+ // 8 + (3 * (7 + 6))
+ kve = &h->kvp_containers[k].arr[i];
+ PKE_TEST_ASSERT(kve->key != nullptr, err_index);
+ PKE_TEST_ASSERT(kve->val != nullptr, err_index);
+ PKE_TEST_ASSERT(kve->end != nullptr, err_index);
+ }
+ }
+
+ pke_deserialize_scene(h);
+
+ pke_ui_box_count_T box_count;
+ pke_ui_box **root_boxes = pke_ui_get_root_boxes(&box_count);
+ // 47
+ PKE_TEST_ASSERT(root_boxes != nullptr, err_index);
+ PKE_TEST_ASSERT(box_count == 1, err_index);
+ PKE_TEST_ASSERT(root_boxes[0] != nullptr, err_index);
+
+ // 50
+ PKE_TEST_ASSERT(root_boxes[0]->uuid == uuid_n[2], err_index);
+ PKE_TEST_ASSERT(PK_HAS_FLAG(root_boxes[0]->flags, PKE_UI_BOX_FLAG_POSITION_TYPE_STATIC), err_index);
+ PKE_TEST_ASSERT(root_boxes[0]->pos_top_left == glm::vec2(1.f,1.f), err_index);
+ PKE_TEST_ASSERT(root_boxes[0]->max_size == glm::vec2(1278.f,718.f), err_index);
+ PKE_TEST_ASSERT(PK_HAS_FLAG(root_boxes[0]->type, PKE_UI_BOX_TYPE_STANDARD), err_index);
+ PKE_TEST_ASSERT(root_boxes[0]->layer == 0, err_index);
+ PKE_TEST_ASSERT(root_boxes[0]->internal.parent == nullptr, err_index);
+ PKE_TEST_ASSERT(root_boxes[0]->internal.h_children == 1, err_index);
+ PKE_TEST_ASSERT(root_boxes[0]->internal.children != nullptr, err_index);
+ PKE_TEST_ASSERT(root_boxes[0]->internal.children[0] != nullptr, err_index);
+
+ pke_ui_box *box_c = root_boxes[0]->internal.children[0];
+ // 60
+ PKE_TEST_ASSERT(box_c->uuid == uuid_n[1], err_index);
+ PKE_TEST_ASSERT(PK_HAS_FLAG(box_c->flags, PKE_UI_BOX_FLAG_POSITION_TYPE_DYNAMIC), err_index);
+ PKE_TEST_ASSERT(box_c->pos_top_left == glm::vec2(0.1,0.1), err_index);
+ PKE_TEST_ASSERT(box_c->max_size == glm::vec2(0.8,0.8), err_index);
+ PKE_TEST_ASSERT(PK_HAS_FLAG(box_c->type, PKE_UI_BOX_TYPE_STANDARD), err_index);
+ PKE_TEST_ASSERT(box_c->layer == 0, err_index);
+ PKE_TEST_ASSERT(box_c->internal.parent == root_boxes[0], err_index);
+ PKE_TEST_ASSERT(box_c->internal.h_children == 0, err_index);
+ PKE_TEST_ASSERT(box_c->internal.children == nullptr, err_index);
+
+ pke_deserialize_teardown(h);
+
+ } catch (const std::exception &ex) {
+ pk_bucket_destroy(bkt);
+ throw;
+ }
+ pk_bucket_destroy(bkt);
+ return 0;
+}
+
struct pke_test_group *pke_test_serialization_get_group() {
- static const uint64_t test_count = 7;
+ static const uint64_t test_count = 9;
static struct pke_test tests[test_count] = {
{
.title = "test 999",
@@ -607,6 +766,16 @@ struct pke_test_group *pke_test_serialization_get_group() {
.func = pke_test_deserialization_103,
.expected_result = 0,
},
+ {
+ .title = "test 004",
+ .func = pke_test_serialization_004,
+ .expected_result = 0,
+ },
+ {
+ .title = "test 104",
+ .func = pke_test_deserialization_104,
+ .expected_result = 0,
+ },
};
static struct pke_test_group group = {};
group.title = "de/serialization";