summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-05-06 13:12:24 -0400
committerJonathan Bradley <jcb@pikum.xyz>2025-05-06 13:12:24 -0400
commit32968050f0b34fdabfcc2a4fb5601d4be361bbd2 (patch)
treeacef384a2156a16d4d506c37f13f79d454a4a6e9 /tests
parentef37d054dfe5812efa9eefb4b9b18621fdabac25 (diff)
pke: major serialization refactor, first-pass
Diffstat (limited to 'tests')
-rw-r--r--tests/pke-test-serialization.cpp126
-rw-r--r--tests/pke-test-serialization.h16
-rw-r--r--tests/pke-test-static-ui.cpp3
-rw-r--r--tests/pke-test.cpp2
4 files changed, 147 insertions, 0 deletions
diff --git a/tests/pke-test-serialization.cpp b/tests/pke-test-serialization.cpp
new file mode 100644
index 0000000..64523d8
--- /dev/null
+++ b/tests/pke-test-serialization.cpp
@@ -0,0 +1,126 @@
+
+#include "./pke-test-serialization.h"
+
+#include "pk.h"
+#include "serialization-component.hpp"
+#include "serialization.hpp"
+
+#include <cstring>
+#include <sstream>
+
+pk_membucket *bkt;
+
+const char *const test_001_str = R"VOGON(:PKFB:
+:0:
+
+InstPos:00000000!00000000
+Position:0.000000;1.000000;2.000000
+Rotation:7.000000;8.000000;9.000000;6.000000
+Scale:5.000000;4.000000;3.000000
+
+:PKFE:
+)VOGON";
+int pke_test_serialization_001() {
+ int64_t err_index = 0, i;
+ srlztn_serialize_helper *h;
+ std::stringstream ss;
+ try {
+ bkt = pk_bucket_create("pke_test_serialization", PK_DEFAULT_BUCKET_SIZE, false);
+ h = pke_serialize_init(bkt);
+
+ glm::vec3 pos = glm::vec3(0,1,2);
+ glm::quat rot = glm::quat(6,7,8,9);
+ glm::vec3 scale = glm::vec3(5,4,3);
+ pke_serialize_inst_pos(h, pos, rot, scale);
+
+ pke_serialize_scene_to_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 == 1, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers[0].child_handles.next == 0, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers[0].arr.next == 3, err_index);
+ for (i = 0; i < 3; ++i) {
+ // 6,9,12
+ PKE_TEST_ASSERT(h->kvp_containers[0].arr[i].key != nullptr, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers[0].arr[i].val != nullptr, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers[0].arr[i].end != nullptr, err_index);
+ }
+
+ std::string s = ss.str();
+ // 15
+ PKE_TEST_ASSERT(strstr(test_001_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_101() {
+ int64_t err_index = 0, i;
+ srlztn_deserialize_helper *h;
+ std::stringstream ss(test_001_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 == 1, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers[0].child_handles.next == 0, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers[0].arr.next == 3, err_index);
+ for (i = 0; i < 3; ++i) {
+ // 6,9,12
+ PKE_TEST_ASSERT(h->kvp_containers[0].arr[i].key != nullptr, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers[0].arr[i].val != nullptr, err_index);
+ PKE_TEST_ASSERT(h->kvp_containers[0].arr[i].end != nullptr, err_index);
+ }
+
+ glm::vec3 pos;
+ glm::quat rot;
+ glm::vec3 scale;
+ pke_deserialize_inst_pos(h, &h->kvp_containers[0], pos, rot, scale);
+
+ // 15
+ PKE_TEST_ASSERT(pos == glm::vec3(0,1,2), err_index);
+ PKE_TEST_ASSERT(rot == glm::quat(6,7,8,9), err_index);
+ PKE_TEST_ASSERT(scale == glm::vec3(5,4,3), 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 = 2;
+ static struct pke_test tests[test_count] = {
+ {
+ .title = "test 001",
+ .func = pke_test_serialization_001,
+ .expected_result = 0,
+ },
+ {
+ .title = "test 101",
+ .func = pke_test_deserialization_101,
+ .expected_result = 0,
+ },
+ };
+ static struct pke_test_group group = {};
+ group.title = "de/serialization";
+ group.n_tests = test_count;
+ group.tests = &tests[0];
+
+ return &group;
+}
diff --git a/tests/pke-test-serialization.h b/tests/pke-test-serialization.h
new file mode 100644
index 0000000..0d4aa2b
--- /dev/null
+++ b/tests/pke-test-serialization.h
@@ -0,0 +1,16 @@
+#ifndef PKE_PKE_TEST_SERIALIZATION_H
+#define PKE_PKE_TEST_SERIALIZATION_H
+
+#include "pke-test-types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct pke_test_group *pke_test_serialization_get_group();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PKE_PKE_TEST_SERIALIZATION_H */
diff --git a/tests/pke-test-static-ui.cpp b/tests/pke-test-static-ui.cpp
index 410f290..1e11d97 100644
--- a/tests/pke-test-static-ui.cpp
+++ b/tests/pke-test-static-ui.cpp
@@ -3,6 +3,7 @@
#include "./pke-test-types.h"
+#include "ecs.hpp"
#include "window.hpp"
#include "dynamic-array.hpp"
#include "vendor-glm-include.hpp"
@@ -23,11 +24,13 @@ struct pke_ui_flex_params {
void pke_test_static_ui_setup() {
Extent.width = 1920;
Extent.height = 1080;
+ ECS_Init();
pke_ui_init();
}
void pke_test_static_ui_teardown() {
pke_ui_teardown();
+ ECS_Teardown();
}
// test static
diff --git a/tests/pke-test.cpp b/tests/pke-test.cpp
index 1849014..78ad662 100644
--- a/tests/pke-test.cpp
+++ b/tests/pke-test.cpp
@@ -3,6 +3,7 @@
#include "./pke-test-dummy.h"
#include "./pke-test-static-ui.h"
+#include "./pke-test-serialization.h"
#include "pk.h"
#include "unistd.h"
@@ -36,6 +37,7 @@ int main(int argc, char *argv[])
pke_test_get_group *group_fns[] = {
pke_test_dummy_get_group,
pke_test_static_ui_get_group,
+ pke_test_serialization_get_group,
NULL,
};