summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-05-20 21:08:19 -0400
committerJonathan Bradley <jcb@pikum.xyz>2025-05-20 21:08:19 -0400
commit40d69e7e40a18865a31af2f55efcde369d36dbbb (patch)
tree95a2cbbe40192183d13f846f3444b32d7e12b0e8 /tests
parentead9e484db969a880470d625b1884aced296e722 (diff)
pke: serialization overhaul + embedded assets
Diffstat (limited to 'tests')
-rw-r--r--tests/pke-test-serialization.cpp255
-rw-r--r--tests/pke-test-static-ui.cpp50
2 files changed, 267 insertions, 38 deletions
diff --git a/tests/pke-test-serialization.cpp b/tests/pke-test-serialization.cpp
index c514578..840adfa 100644
--- a/tests/pke-test-serialization.cpp
+++ b/tests/pke-test-serialization.cpp
@@ -1,8 +1,9 @@
#include "./pke-test-serialization.h"
+#include "asset-manager.hpp"
+#include "font.hpp"
#include "game-settings.hpp"
-#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
#include "camera.hpp"
#include "ecs.hpp"
#include "physics.hpp"
@@ -11,6 +12,8 @@
#include "serialization-camera.hpp"
#include "serialization-component.hpp"
#include "serialization.hpp"
+#include "static-ui.hpp"
+#include "thread-pool.hpp"
#include <cstring>
#include <sstream>
@@ -18,23 +21,61 @@
pk_membucket *bkt = nullptr;
const char *test_scene_name = "srlztn_test_scene";
pke_scene *test_scene = nullptr;
+FontType *ft;
+
+#define FAKE_UUID_GEN(oct) { .uuid = { oct,oct,oct,oct,oct,oct,oct,oct,oct,oct,oct,oct,oct,oct,oct,oct } }
+
+const pk_uuid uuid_n[] = {
+ FAKE_UUID_GEN(0x00),
+ FAKE_UUID_GEN(0x01),
+ FAKE_UUID_GEN(0x02),
+ FAKE_UUID_GEN(0x03),
+ FAKE_UUID_GEN(0x04),
+ FAKE_UUID_GEN(0x05),
+ FAKE_UUID_GEN(0x06),
+ FAKE_UUID_GEN(0x07),
+ FAKE_UUID_GEN(0x08),
+ FAKE_UUID_GEN(0x09),
+ FAKE_UUID_GEN(0x0a),
+ FAKE_UUID_GEN(0x0b),
+ FAKE_UUID_GEN(0x0c),
+ FAKE_UUID_GEN(0x0d),
+ FAKE_UUID_GEN(0x0e),
+ FAKE_UUID_GEN(0x0f),
+};
+const pk_uuid uuid_17 = FAKE_UUID_GEN(0x11);
+// const pk_uuid uuid_34 = FAKE_UUID_GEN(0x22);
void pke_test_serialization_spinup() {
pkeSettings.isSimulationPaused = true;
Physics_Init();
+ PkeThreads_Init();
+ AM_Init();
ECS_Init();
+ pke_ui_init();
PkeCamera_Init();
+ FontType_Init();
pke_scene_master_init();
test_scene = pke_scene_create(test_scene_name);
+ FontTypeIndex fti;
+ FontType *ft = FontType_GetFonts(fti);
+ assert(fti > FontTypeIndex{0});
+ ft->uuid = uuid_17;
};
void pke_test_serialization_teardown() {
// pke_scene_remove(test_scene->scene_handle); // TODO this doesn't work?
test_scene = nullptr;
pke_scene_master_teardown();
+ FontType_Teardown();
PkeCamera_Teardown();
+ pke_ui_teardown();
ECS_Teardown();
+ AM_Teardown();
+ PkeThreads_Teardown();
Physics_Teardown();
+ pk_memory_teardown_all();
+ bkt = nullptr;
};
int pke_test_serialization_999() {
@@ -181,7 +222,7 @@ Rotation:0.000000;0.000000;0.000000;1.000000
Instance:00000000!00000001
ChildId:00000000!00000000
-UUID:67eec271-ab64-78d2-a38e-1f2946e87ccd
+UUID:01010101-0101-0101-0101-010101010101
Mass:1.000000
CollisionLayer:0x0000000000000001
CollisionMask:0x0000000000000001
@@ -193,10 +234,10 @@ Scale:5.000000;4.000000;3.000000
Camera:00000000!00000003
ChildId:00000000!00000002
-UUID:67eec26e-56c4-7aeb-a43c-986966334873
+UUID:02020202-0202-0202-0202-020202020202
Type:0x01
Orientation:0x01
-TargetUUID:67eec271-ab64-78d2-a38e-1f2946e87ccd
+TargetUUID:01010101-0101-0101-0101-010101010101
IsPrimary:1
:PKFE:)VOGON";
@@ -209,8 +250,6 @@ int pke_test_serialization_002() {
try {
bkt = pk_bucket_create("pke_test_serialization", PK_DEFAULT_BUCKET_SIZE, false);
h = pke_serialize_init(bkt);
- const pk_uuid camera_uuid = { .uuid = { 0x67,0xEE,0xC2,0x6E,0x56,0xC4,0x7A,0xEB,0xA4,0x3C,0x98,0x69,0x66,0x33,0x48,0x73 } };
- const pk_uuid target_uuid = { .uuid = { 0x67,0xEE,0xC2,0x71,0xAB,0x64,0x78,0xD2,0xA3,0x8E,0x1F,0x29,0x46,0xE8,0x7C,0xCD } };
// reminder that 'targeting' moves and rotates the camera, so we shouldn't see these values in the output
InstPos cam_inst_pos{};
@@ -221,10 +260,10 @@ int pke_test_serialization_002() {
cam_inst_pos.mass = 1.f;
Entity_Base *target_ent = ECS_CreateGenericEntity();
- CompInstance *target_ent_comp_inst = ECS_CreateInstance(target_ent, target_uuid, nullptr, &cam_inst_pos);
+ CompInstance *target_ent_comp_inst = ECS_CreateInstance(target_ent, uuid_n[1], nullptr, &cam_inst_pos);
cam_inst_pos.scale = btVector3(5,4,3);
- PkeCamera &cam = PkeCamera_Register(camera_uuid, cam_inst_pos);
+ PkeCamera &cam = PkeCamera_Register(uuid_n[2], cam_inst_pos);
cam.type = PKE_CAMERA_TYPE_PERSPECTIVE;
cam.view = PKE_CAMERA_VIEW_TARGET;
PkeCamera_SetPrimary(cam.camHandle);
@@ -284,8 +323,6 @@ int pke_test_deserialization_102() {
bkt = pk_bucket_create("pke_test_serialization", PK_DEFAULT_BUCKET_SIZE, false);
h = pke_deserialize_init(bkt);
h->scene = test_scene;
- const pk_uuid camera_uuid = { .uuid = { 0x67,0xEE,0xC2,0x6E,0x56,0xC4,0x7A,0xEB,0xA4,0x3C,0x98,0x69,0x66,0x33,0x48,0x73 } };
- const pk_uuid target_uuid = { .uuid = { 0x67,0xEE,0xC2,0x71,0xAB,0x64,0x78,0xD2,0xA3,0x8E,0x1F,0x29,0x46,0xE8,0x7C,0xCD } };
pke_deserialize_scene_from_stream(ss, h);
@@ -334,10 +371,10 @@ int pke_test_deserialization_102() {
PkeCamera *des_cam = &PkeCamera_GetCameras(0, item_index)[0];
// 57
PKE_TEST_ASSERT(des_cam != nullptr, err_index);
- PKE_TEST_ASSERT(des_cam->uuid == camera_uuid, err_index);
+ PKE_TEST_ASSERT(des_cam->uuid == uuid_n[2], err_index);
PKE_TEST_ASSERT(des_cam->type == PKE_CAMERA_TYPE_PERSPECTIVE, err_index);
PKE_TEST_ASSERT(des_cam->view == PKE_CAMERA_VIEW_TARGET, err_index);
- PKE_TEST_ASSERT(des_cam->phys.target_inst_uuid == target_uuid, err_index);
+ PKE_TEST_ASSERT(des_cam->phys.target_inst_uuid == uuid_n[1], err_index);
PKE_TEST_ASSERT(des_cam->isPrimary == true, err_index);
pke_deserialize_teardown(h);
@@ -350,8 +387,190 @@ int pke_test_deserialization_102() {
return 0;
}
+const char *const test_003_str = R"VOGON(:PKFB:
+:0:
+
+FontRenderSettings:00000000!00000000
+CharScale:1.000000
+LineHeightScale:1.000000
+CharSpacingScale:1.000000
+SurfaceAreaSize:250;250
+SurfaceAreaPos:0;0
+SurfaceAreaFlags:0x03
+
+FontRender:00000000!00000001
+ChildId:00000000!00000000
+UUID:01010101-0101-0101-0101-010101010101
+FontTypeUUID:11111111-1111-1111-1111-111111111111
+TextBegin::
+asdf
+:MULTILINE_END:
+
+UIBoxTypeData:00000000!00000002
+FontRenderUUID:01010101-0101-0101-0101-010101010101
+
+UIBox:00000000!00000003
+ChildId:00000000!00000002
+UUID:02020202-0202-0202-0202-020202020202
+Flags:0x84
+PosTopLeft:0.100000;0.100000
+MaxSize:0.800000;0.800000
+Type:0x28
+Layer:0x00
+
+:PKFE:)VOGON";
+int pke_test_serialization_003() {
+ 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);
+
+ FontTypeIndex fti;
+ FontRenderSettings frs;
+ frs.char_scale = 1.0;
+ frs.char_spacing_scale = 1.0;
+ frs.line_height_scale = 1.0;
+ frs.surface_area_size = glm::ivec2(250, 250);
+ frs.surface_area_pos = glm::ivec2(0, 0);
+ frs.surface_area_type_flags = FONT_RENDER_SURFACE_AREA_TYPE_FLAGS_FLUID;
+ FontRenderHandle fr_handle = FontType_AddStringRender(FontType_GetFonts(fti)[0].index_ft, std::move(cstring_to_pk_cstr("asdf")), &frs, nullptr, uuid_n[1]);
+
+ pke_ui_box *ui_box = pke_ui_box_new_root(PKE_UI_BOX_TYPE_TEXT, uuid_n[2]);
+ ui_box->flags |= PKE_UI_BOX_FLAG_POSITION_TYPE_DYNAMIC;
+ ui_box->pos_top_left.x = 0.1;
+ ui_box->pos_top_left.y = 0.1;
+ ui_box->max_size.x = 0.8;
+ ui_box->max_size.y = 0.8;
+ ui_box->type_data->text.font_render_handle = fr_handle;
+
+ 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 == 4, err_index);
+ // FontRenderSettings
+ PKE_TEST_ASSERT(h->kvp_containers[0].child_handles.next == 0, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers[0].arr.next == 6, err_index);
+ // FontRender
+ PKE_TEST_ASSERT(h->kvp_containers[1].child_handles.next == 1, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers[1].arr.next == 3, err_index);
+ // ui box type text
+ PKE_TEST_ASSERT(h->kvp_containers[2].child_handles.next == 0, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers[2].arr.next == 1, err_index);
+ // ui box
+ PKE_TEST_ASSERT(h->kvp_containers[3].child_handles.next == 1, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers[3].arr.next == 6, err_index);
+
+ // 12
+ for (k = 0; k < h->kvp_containers.next; ++k) {
+ for (i = 0; i < h->kvp_containers[k].arr.next; ++i) {
+ // 12 + (3 * (6 + 3 + 1 + 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);
+ }
+ }
+
+ // 60
+ PKE_TEST_ASSERT(strstr(test_003_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_103() {
+ int64_t err_index = 0;
+ uint32_t i, k;
+ pke_kve *kve;
+ srlztn_deserialize_helper *h;
+ std::stringstream ss(test_003_str);
+ try {
+ bkt = pk_bucket_create("pke_test_serialization", PK_DEFAULT_BUCKET_SIZE, false);
+ h = pke_deserialize_init(bkt);
+ h->scene = test_scene;
+
+ 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 == 4, err_index);
+ // FontRenderSettings
+ PKE_TEST_ASSERT(h->kvp_containers[0].child_handles.next == 0, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers[0].arr.next == 6, err_index);
+ // FontRender
+ PKE_TEST_ASSERT(h->kvp_containers[1].child_handles.next == 1, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers[1].arr.next == 3, err_index);
+ // ui box type text
+ PKE_TEST_ASSERT(h->kvp_containers[2].child_handles.next == 0, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers[2].arr.next == 1, err_index);
+ // ui box
+ PKE_TEST_ASSERT(h->kvp_containers[3].child_handles.next == 1, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers[3].arr.next == 6, err_index);
+
+ // 12
+ for (k = 0; k < h->kvp_containers.next; ++k) {
+ for (i = 0; i < h->kvp_containers[k].arr.next; ++i) {
+ // 12 + (3 * (6 + 3 + 1 + 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);
+
+ FontTypeIndex fti = FontTypeIndex{0};
+ FontType *fonts = FontType_GetFonts(fti);
+ // 60
+ PKE_TEST_ASSERT(fti > FontTypeIndex{0}, err_index);
+ PKE_TEST_ASSERT(fonts != nullptr, err_index);
+ PKE_TEST_ASSERT(fonts->h_render > FontRenderIndex{0}, err_index);
+ PKE_TEST_ASSERT(fonts->n_render > FontRenderIndex{0}, err_index);
+ FontRender *fr = &fonts[0].renders[0];
+
+ // 64
+ PKE_TEST_ASSERT(fr->settings.char_scale == 1.f, err_index);
+ PKE_TEST_ASSERT(fr->settings.line_height_scale == 1.f, err_index);
+ PKE_TEST_ASSERT(fr->settings.char_spacing_scale == 1.f, err_index);
+ PKE_TEST_ASSERT(fr->settings.surface_area_size == glm::ivec2(250,250), err_index);
+ PKE_TEST_ASSERT(fr->settings.surface_area_pos == glm::ivec2(0,0), err_index);
+ PKE_TEST_ASSERT(fr->settings.surface_area_type_flags == FONT_RENDER_SURFACE_AREA_TYPE_FLAGS_FLUID, err_index);
+
+ // 70
+ PKE_TEST_ASSERT(fr->uuid == uuid_n[1], err_index);
+ PKE_TEST_ASSERT(fr->text.val != nullptr, err_index);
+ PKE_TEST_ASSERT(fr->text.val[0] == 'a', err_index);
+ PKE_TEST_ASSERT(fr->text.val[1] == 's', err_index);
+ PKE_TEST_ASSERT(fr->text.val[2] == 'd', err_index);
+ PKE_TEST_ASSERT(fr->text.val[3] == 'f', err_index);
+ PKE_TEST_ASSERT(fr->text.val[4] == '\0', 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 = 5;
+ static const uint64_t test_count = 7;
static struct pke_test tests[test_count] = {
{
.title = "test 999",
@@ -378,6 +597,16 @@ struct pke_test_group *pke_test_serialization_get_group() {
.func = pke_test_deserialization_102,
.expected_result = 0,
},
+ {
+ .title = "test 003",
+ .func = pke_test_serialization_003,
+ .expected_result = 0,
+ },
+ {
+ .title = "test 103",
+ .func = pke_test_deserialization_103,
+ .expected_result = 0,
+ },
};
static struct pke_test_group group = {};
group.title = "de/serialization";
diff --git a/tests/pke-test-static-ui.cpp b/tests/pke-test-static-ui.cpp
index 1e11d97..9a5fb71 100644
--- a/tests/pke-test-static-ui.cpp
+++ b/tests/pke-test-static-ui.cpp
@@ -41,19 +41,19 @@ int pke_test_static_ui_000() {
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;
+ ui_box->pos_top_left.x = 10;
+ ui_box->pos_top_left.y = 10;
+ ui_box->max_size.x = 500;
+ ui_box->max_size.y = 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;
+ c_ui_box->pos_top_left.x = 10;
+ c_ui_box->pos_top_left.y = 10;
+ c_ui_box->max_size.x = 100;
+ c_ui_box->max_size.y = 100;
- calculated_offset = ui_box->pos_top_left_x + c_ui_box->pos_top_left_x + built_in_offset;
+ 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);
@@ -87,17 +87,17 @@ int pke_test_static_ui_100() {
pke_ui_box *ui_box = pke_ui_box_new_root();
ui_box->flags = PKE_UI_BOX_FLAG_POSITION_TYPE_DYNAMIC;
- ui_box->pos_top_left_x = 0.1;
- ui_box->pos_top_left_y = 0.1;
- ui_box->max_width = 0.8;
- ui_box->max_height = 0.8;
+ ui_box->pos_top_left.x = 0.1;
+ ui_box->pos_top_left.y = 0.1;
+ ui_box->max_size.x = 0.8;
+ ui_box->max_size.y = 0.8;
pke_ui_box *c_ui_box = pke_ui_box_new_child(ui_box);
c_ui_box->flags = PKE_UI_BOX_FLAG_POSITION_TYPE_DYNAMIC;
- c_ui_box->pos_top_left_x = 0.1;
- c_ui_box->pos_top_left_y = 0.1;
- c_ui_box->max_width = 0.8;
- c_ui_box->max_height = 0.8;
+ c_ui_box->pos_top_left.x = 0.1;
+ c_ui_box->pos_top_left.y = 0.1;
+ c_ui_box->max_size.x = 0.8;
+ c_ui_box->max_size.y = 0.8;
unit = Extent.width * 0.1;
calculated_offset_x = (unit * 8) - (built_in_offset * 2); // padded parent
@@ -147,17 +147,17 @@ int pke_test_static_ui_200() {
pke_ui_box *ui_box = pke_ui_box_new_root();
ui_box->flags = PKE_UI_BOX_FLAG_POSITION_TYPE_DYNAMIC;
- ui_box->pos_top_left_x = 0.1;
- ui_box->pos_top_left_y = 0.1;
- ui_box->max_width = 0.8;
- ui_box->max_height = 0.8;
+ ui_box->pos_top_left.x = 0.1;
+ ui_box->pos_top_left.y = 0.1;
+ ui_box->max_size.x = 0.8;
+ ui_box->max_size.y = 0.8;
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 = 1;
- c_ui_box->pos_top_left_y = 1;
- c_ui_box->max_width = 300;
- c_ui_box->max_height = 300;
+ c_ui_box->pos_top_left.x = 1;
+ c_ui_box->pos_top_left.y = 1;
+ c_ui_box->max_size.x = 300;
+ c_ui_box->max_size.y = 300;
unit = Extent.width * 0.1;
calculated_offset_x = unit + 1 + built_in_offset;