summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-09-16 16:58:02 -0400
committerJonathan Bradley <jcb@pikum.xyz>2025-09-16 17:00:08 -0400
commit73c5e170260638cc566cba2689ea570caee39251 (patch)
tree256b36398d33650054a885e572437909f88485cb /tests
parente52ef2e49ae660833370befc34ba79d412cb4604 (diff)
pke: major object lifetime overhaul.
Added pke-test-load-unload to ensure objects are managed as expected.
Diffstat (limited to 'tests')
-rw-r--r--tests/pke-test-asset-manager.cpp7
-rw-r--r--tests/pke-test-dummy.cpp9
-rw-r--r--tests/pke-test-load-unload.cpp303
-rw-r--r--tests/pke-test-load-unload.h16
-rw-r--r--tests/pke-test-serialization.cpp51
-rw-r--r--tests/pke-test-static-ui.cpp9
-rw-r--r--tests/pke-test.cpp10
7 files changed, 362 insertions, 43 deletions
diff --git a/tests/pke-test-asset-manager.cpp b/tests/pke-test-asset-manager.cpp
index 180d134..55a368f 100644
--- a/tests/pke-test-asset-manager.cpp
+++ b/tests/pke-test-asset-manager.cpp
@@ -6,7 +6,11 @@
#include "font.hpp"
#include "thread-pool.hpp"
+static pk_membucket *bkt;
+
void pke_test_asset_manager_spinup() {
+ bkt = pk_mem_bucket_create("pke_test_asset_manager", PK_MEM_DEFAULT_BUCKET_SIZE, PK_MEMBUCKET_FLAG_NONE);
+ pk_mem_bucket_set_client_mem_bucket(bkt);
pk_ev_init(nullptr);
PkeThreads_Init();
AM_Init();
@@ -20,6 +24,9 @@ void pke_test_asset_manager_teardown() {
AM_Teardown();
PkeThreads_Teardown();
pk_ev_teardown();
+ pk_mem_bucket_destroy(bkt);
+ pk_mem_bucket_set_client_mem_bucket(nullptr);
+ bkt = nullptr;
};
int pke_test_asset_manager_001() {
diff --git a/tests/pke-test-dummy.cpp b/tests/pke-test-dummy.cpp
index e8c34ba..914f3cf 100644
--- a/tests/pke-test-dummy.cpp
+++ b/tests/pke-test-dummy.cpp
@@ -11,8 +11,12 @@
#include "static-ui.hpp"
#include "thread-pool.hpp"
+static pk_membucket *bkt;
+
int pke_test_dummy_001() {
- pk_ev_init(nullptr);
+ bkt = pk_mem_bucket_create("pke_test_dummy", PK_MEM_DEFAULT_BUCKET_SIZE, PK_MEMBUCKET_FLAG_NONE);
+ pk_mem_bucket_set_client_mem_bucket(bkt);
+ pk_ev_init(bkt);
Physics_Init();
PkeThreads_Init();
AM_Init();
@@ -40,6 +44,9 @@ int pke_test_dummy_001() {
PkeThreads_Teardown();
Physics_Teardown();
pk_ev_teardown();
+ pk_mem_bucket_destroy(bkt);
+ pk_mem_bucket_set_client_mem_bucket(nullptr);
+ bkt = nullptr;
return 0;
}
diff --git a/tests/pke-test-load-unload.cpp b/tests/pke-test-load-unload.cpp
new file mode 100644
index 0000000..f714538
--- /dev/null
+++ b/tests/pke-test-load-unload.cpp
@@ -0,0 +1,303 @@
+
+#include "pke-test-load-unload.h"
+
+#include "asset-manager.hpp"
+#include "audio.hpp"
+#include "camera.hpp"
+#include "ecs.hpp"
+#include "entities.hpp"
+#include "game-settings.hpp"
+#include "game.hpp"
+#include "level.hpp"
+#include "physics.hpp"
+#include "pk.h"
+#include "player-input.hpp"
+#include "scene.hpp"
+#include "static-ui.hpp"
+#include "thread-pool.hpp"
+
+#include "pk.h"
+
+extern pk_arr_t<Entity_Base*> entitiesMarkedForRemoval;
+extern pk_arr_t<EntityHandle> entitiesYetToBeRemoved;
+
+static pk_membucket *bkt;
+static pke_level *level_01;
+
+void print_entities_marked_for_removal() {
+ bool b;
+ pk_iter_t<Entity_Base*> iter{};
+ fprintf(stdout, "marked for removal BEGIN\n");
+ b = pk_arr_iter_begin(&entitiesMarkedForRemoval, &iter);
+ while (b == true) {
+ fprintf(stdout, "0x%.2X 0x%.2X\n", (*iter)->handle.b, (*iter)->handle.i);
+ b = pk_arr_iter_increment(&entitiesMarkedForRemoval, &iter);
+ }
+ fprintf(stdout, "marked for removal END\n\n");
+}
+
+void print_entities_yet_to_be_removed() {
+ bool b;
+ pk_iter_t<EntityHandle> iter{};
+ fprintf(stdout, "yet to be removed BEGIN\n");
+ b = pk_arr_iter_begin(&entitiesYetToBeRemoved, &iter);
+ while (b == true) {
+ fprintf(stdout, "0x%.2X 0x%.2X\n", iter->b, iter->i);
+ b = pk_arr_iter_increment(&entitiesYetToBeRemoved, &iter);
+ }
+ fprintf(stdout, "yet to be removed END\n\n");
+}
+
+int pke_test_load_unload_do_thing_001(int iteration) {
+ uint64_t err_index = iteration << 16;
+
+ // fprintf(stdout, "begin\n");
+
+ pkeSettings.rt.activeLevel = pke_level_create("load_unload_faux", pk_uuid_zed, pk_uuid_zed);
+ assert(pkeSettings.rt.activeLevel->isMarkedForRemoval == false);
+
+ PKE_TEST_ASSERT(pkeSettings.rt.activeLevel != NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.nextLevel == NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.previousLevel == NULL, err_index);
+ PKE_TEST_ASSERT(entitiesMarkedForRemoval.next == 0, err_index);
+ PKE_TEST_ASSERT(entitiesYetToBeRemoved.next == 0, err_index);
+ // print_entities_marked_for_removal();
+ // print_entities_yet_to_be_removed();
+ // fprintf(stdout, "tick 1\n");
+ Game_Tick(double(1.0 / 120.0));
+ // print_entities_marked_for_removal();
+ // print_entities_yet_to_be_removed();
+ PKE_TEST_ASSERT(pkeSettings.rt.activeLevel != NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.nextLevel == NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.previousLevel == NULL, err_index);
+ PKE_TEST_ASSERT(entitiesMarkedForRemoval.next == 0, err_index);
+ PKE_TEST_ASSERT(entitiesYetToBeRemoved.next == 0, err_index);
+
+ level_01 = pke_level_create("load_unload_01", pk_uuid_zed, pk_uuid_zed);
+ assert(level_01->isMarkedForRemoval == false);
+ pkeSettings.rt.nextLevel = level_01;
+
+ /* JCB
+ * Double tick so that the level can get flushed out.
+ * We need to do this so the first few asserts get a clean starting point.
+ * This *IS* expected behavior
+ */
+ PKE_TEST_ASSERT(pkeSettings.rt.activeLevel != NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.nextLevel != NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.previousLevel == NULL, err_index);
+ PKE_TEST_ASSERT(entitiesMarkedForRemoval.next == 0, err_index);
+ PKE_TEST_ASSERT(entitiesYetToBeRemoved.next == 0, err_index);
+ // print_entities_marked_for_removal();
+ // print_entities_yet_to_be_removed();
+ // fprintf(stdout, "tick 2\n");
+ Game_Tick(double(1.0 / 120.0));
+ // print_entities_marked_for_removal();
+ // print_entities_yet_to_be_removed();
+ PKE_TEST_ASSERT(pkeSettings.rt.activeLevel != NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.nextLevel == NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.previousLevel == NULL, err_index);
+ PKE_TEST_ASSERT(entitiesMarkedForRemoval.next == 0, err_index);
+ PKE_TEST_ASSERT(entitiesYetToBeRemoved.next == 1, err_index);
+ // fprintf(stdout, "tick 3\n");
+ Game_Tick(double(1.0 / 120.0));
+ // print_entities_marked_for_removal();
+ // print_entities_yet_to_be_removed();
+ PKE_TEST_ASSERT(pkeSettings.rt.activeLevel != NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.nextLevel == NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.previousLevel == NULL, err_index);
+ PKE_TEST_ASSERT(entitiesMarkedForRemoval.next == 0, err_index);
+ PKE_TEST_ASSERT(entitiesYetToBeRemoved.next == 0, err_index);
+
+ return 0;
+}
+
+int pke_test_load_unload_do_thing_002(int iteration) {
+ uint64_t err_index = iteration << 16;
+
+ // fprintf(stdout, "begin\n");
+
+ pkeSettings.rt.activeLevel = pke_level_create("load_unload_faux", pk_uuid_zed, pk_uuid_zed);
+ assert(pkeSettings.rt.activeLevel->isMarkedForRemoval == false);
+
+ // 1
+ PKE_TEST_ASSERT(pkeSettings.rt.activeLevel != NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.nextLevel == NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.previousLevel == NULL, err_index);
+ PKE_TEST_ASSERT(entitiesMarkedForRemoval.next == 0, err_index);
+ PKE_TEST_ASSERT(entitiesYetToBeRemoved.next == 0, err_index);
+ // print_entities_marked_for_removal();
+ // print_entities_yet_to_be_removed();
+ // fprintf(stdout, "tick 1\n");
+ Game_Tick(double(1.0 / 120.0));
+ // print_entities_marked_for_removal();
+ // print_entities_yet_to_be_removed();
+ PKE_TEST_ASSERT(pkeSettings.rt.activeLevel != NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.nextLevel == NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.previousLevel == NULL, err_index);
+ PKE_TEST_ASSERT(entitiesMarkedForRemoval.next == 0, err_index);
+ PKE_TEST_ASSERT(entitiesYetToBeRemoved.next == 0, err_index);
+
+ level_01 = pke_level_create("load_unload_01", pk_uuid_zed, pk_uuid_zed);
+ assert(level_01->isMarkedForRemoval == false);
+ pkeSettings.rt.nextLevel = level_01;
+ pke_ui_box *bx = pke_ui_box_new_root(PKE_UI_BOX_TYPE_TEXT);
+ FontRenderSettings frs_01{};
+ bx->type_data->text.font_render_handle = FontType_AddStringRender(FontTypeIndex{0}, std::move(cstring_to_pk_cstr("one")), &frs_01, bx);
+ bx->flags |= PKE_UI_BOX_FLAG_POSITION_TYPE_STATIC;
+ pke_level_register_root_ui_box(level_01, bx);
+
+ // 11
+ PKE_TEST_ASSERT(pkeSettings.rt.activeLevel != NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.nextLevel != NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.previousLevel == NULL, err_index);
+ PKE_TEST_ASSERT(entitiesMarkedForRemoval.next == 0, err_index);
+ PKE_TEST_ASSERT(entitiesYetToBeRemoved.next == 0, err_index);
+ // print_entities_marked_for_removal();
+ // print_entities_yet_to_be_removed();
+ // fprintf(stdout, "tick 2\n");
+ Game_Tick(double(1.0 / 120.0));
+ // print_entities_marked_for_removal();
+ // print_entities_yet_to_be_removed();
+ PKE_TEST_ASSERT(pkeSettings.rt.activeLevel != NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.nextLevel == NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.previousLevel == NULL, err_index);
+ PKE_TEST_ASSERT(entitiesMarkedForRemoval.next == 0, err_index);
+ PKE_TEST_ASSERT(entitiesYetToBeRemoved.next == 1, err_index);
+ // fprintf(stdout, "tick 3\n");
+ Game_Tick(double(1.0 / 120.0));
+ // print_entities_marked_for_removal();
+ // print_entities_yet_to_be_removed();
+ PKE_TEST_ASSERT(pkeSettings.rt.activeLevel != NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.nextLevel == NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.previousLevel == NULL, err_index);
+ PKE_TEST_ASSERT(entitiesMarkedForRemoval.next == 0, err_index);
+ PKE_TEST_ASSERT(entitiesYetToBeRemoved.next == 0, err_index);
+
+ pkeSettings.rt.nextLevel = pke_level_create("load_unload_faux", pk_uuid_zed, pk_uuid_zed);
+
+ // 26
+ // print_entities_marked_for_removal();
+ // print_entities_yet_to_be_removed();
+ // fprintf(stdout, "tick 4\n");
+ Game_Tick(double(1.0 / 120.0));
+ // print_entities_marked_for_removal();
+ // print_entities_yet_to_be_removed();
+ PKE_TEST_ASSERT(pkeSettings.rt.activeLevel != NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.nextLevel == NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.previousLevel == NULL, err_index);
+ PKE_TEST_ASSERT(entitiesMarkedForRemoval.next == 0, err_index);
+ PKE_TEST_ASSERT(entitiesYetToBeRemoved.next == 3, err_index);
+ // fprintf(stdout, "tick 5\n");
+ Game_Tick(double(1.0 / 120.0));
+ // print_entities_marked_for_removal();
+ // print_entities_yet_to_be_removed();
+ PKE_TEST_ASSERT(pkeSettings.rt.activeLevel != NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.nextLevel == NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.previousLevel == NULL, err_index);
+ PKE_TEST_ASSERT(entitiesMarkedForRemoval.next == 0, err_index);
+ PKE_TEST_ASSERT(entitiesYetToBeRemoved.next == 0, err_index);
+ // fprintf(stdout, "tick 6\n");
+ Game_Tick(double(1.0 / 120.0));
+ // print_entities_marked_for_removal();
+ // print_entities_yet_to_be_removed();
+ PKE_TEST_ASSERT(pkeSettings.rt.activeLevel != NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.nextLevel == NULL, err_index);
+ PKE_TEST_ASSERT(pkeSettings.rt.previousLevel == NULL, err_index);
+ PKE_TEST_ASSERT(entitiesMarkedForRemoval.next == 0, err_index);
+ PKE_TEST_ASSERT(entitiesYetToBeRemoved.next == 0, err_index);
+
+ return 0;
+}
+
+void pke_test_load_unload_init() {
+ bkt = pk_mem_bucket_create("pke_test_load_unload", PK_MEM_DEFAULT_BUCKET_SIZE, PK_MEMBUCKET_FLAG_NONE);
+ pk_mem_bucket_set_client_mem_bucket(bkt);
+ pkeSettings.mem_bkt.game = bkt;
+ pkeSettings.mem_bkt.game_transient = pk_mem_bucket_create("pke_test_load_unload_transient", PK_MEM_DEFAULT_BUCKET_SIZE, PK_MEMBUCKET_FLAG_TRANSIENT);
+ pk_ev_init(bkt);
+ Physics_Init();
+ PkeThreads_Init();
+ AM_Init();
+ ECS_Init();
+ pke_audio_init();
+ pke_input_init();
+ pke_ui_init();
+ PkeCamera_Init();
+ FontType_Init();
+ pke_scene_master_init();
+ pke_level_init();
+ EntityType_Init();
+}
+
+void pke_test_load_unload_teardown() {
+ EntityType_Teardown();
+ pke_level_teardown();
+ pke_scene_master_teardown();
+ FontType_Teardown();
+ PkeCamera_Teardown();
+ pke_ui_teardown();
+ pke_input_teardown();
+ pke_audio_teardown();
+ ECS_Teardown();
+ AM_Teardown();
+ PkeThreads_Teardown();
+ Physics_Teardown();
+ pk_ev_teardown();
+ pk_mem_bucket_destroy(pkeSettings.mem_bkt.game_transient);
+ pk_mem_bucket_destroy(bkt);
+ pk_mem_bucket_set_client_mem_bucket(nullptr);
+ bkt = nullptr;
+ pkeSettings.mem_bkt.game = nullptr;
+ pkeSettings.mem_bkt.game_transient = nullptr;
+ pkeSettings.rt.activeLevel = nullptr;
+ pkeSettings.rt.nextLevel = nullptr;
+ pkeSettings.rt.previousLevel = nullptr;
+}
+
+int pke_test_load_unload_001() {
+ int i, k;
+ for (i = 0; i < 255; ++i) {
+ if (k = pke_test_load_unload_do_thing_001(i), k != 0){
+ return k;
+ }
+ }
+ return 0;
+}
+
+int pke_test_load_unload_002() {
+ int i, k;
+ for (i = 0; i < 255; ++i) {
+ if (k = pke_test_load_unload_do_thing_002(i), k != 0){
+ return k;
+ }
+ }
+ return 0;
+}
+
+struct pke_test_group *
+pke_test_load_unload_get_group()
+{
+ static const uint64_t test_count = 2;
+ static struct pke_test tests[test_count] = {
+ {
+ .title = "test 001",
+ .func = pke_test_load_unload_001,
+ .expected_result = 0,
+ },
+ {
+ .title = "test 002",
+ .func = pke_test_load_unload_002,
+ .expected_result = 0,
+ },
+ };
+ static struct pke_test_group group{};
+ group.title = "load-unload";
+ group.group_setup = nullptr;
+ group.group_teardown = nullptr;
+ group.test_setup = pke_test_load_unload_init;
+ group.test_teardown = pke_test_load_unload_teardown;
+ group.n_tests = test_count;
+ group.tests = &tests[0];
+ return &group;
+}
+
diff --git a/tests/pke-test-load-unload.h b/tests/pke-test-load-unload.h
new file mode 100644
index 0000000..be28f0f
--- /dev/null
+++ b/tests/pke-test-load-unload.h
@@ -0,0 +1,16 @@
+#ifndef PKE_PKE_TEST_LOAD_UNLOAD_H
+#define PKE_PKE_TEST_LOAD_UNLOAD_H
+
+#include "pke-test-types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct pke_test_group *pke_test_load_unload_get_group();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PKE_PKE_TEST_LOAD_UNLOAD_H */
diff --git a/tests/pke-test-serialization.cpp b/tests/pke-test-serialization.cpp
index 374d77e..de483f7 100644
--- a/tests/pke-test-serialization.cpp
+++ b/tests/pke-test-serialization.cpp
@@ -18,7 +18,7 @@
#include <cstring>
#include <sstream>
-pk_membucket *bkt = nullptr;
+static pk_membucket *bkt = nullptr;
const char *test_level_name = "srlztn_test_level";
pke_level *test_level = nullptr;
FontType *ft;
@@ -48,6 +48,8 @@ const pk_uuid uuid_n[] = {
void pke_test_serialization_spinup() {
// pk_funcinstr_init();
+ bkt = pk_mem_bucket_create("pke_test_serialization", PK_MEM_DEFAULT_BUCKET_SIZE, PK_MEMBUCKET_FLAG_NONE);
+ pk_mem_bucket_set_client_mem_bucket(bkt);
pkeSettings.isSimulationPaused = true;
pk_ev_init(nullptr);
PkeThreads_Init();
@@ -58,8 +60,8 @@ void pke_test_serialization_spinup() {
PkeCamera_Init();
pke_scene_master_init();
pke_input_init();
- pke_ui_init();
FontType_Init();
+ pke_ui_init();
test_level = pke_level_create(test_level_name, pk_uuid_zed, pk_uuid_zed);
// pk_funcinstr_teardown();
};
@@ -68,8 +70,8 @@ void pke_test_serialization_teardown() {
// pk_funcinstr_init();
pke_level_teardown(test_level);
test_level = nullptr;
- FontType_Teardown();
pke_ui_teardown();
+ FontType_Teardown();
pke_input_teardown();
pke_scene_master_teardown();
PkeCamera_Teardown();
@@ -79,6 +81,8 @@ void pke_test_serialization_teardown() {
AM_Teardown();
PkeThreads_Teardown();
pk_ev_teardown();
+ pk_mem_bucket_destroy(bkt);
+ pk_mem_bucket_set_client_mem_bucket(nullptr);
bkt = nullptr;
// pk_funcinstr_teardown();
};
@@ -142,7 +146,6 @@ int pke_test_serialization_001() {
srlztn_serialize_helper *h;
std::stringstream ss;
try {
- bkt = pk_mem_bucket_create("pke_test_serialization", PK_MEM_DEFAULT_BUCKET_SIZE, PK_MEMBUCKET_FLAG_NONE);
h = pke_serialize_init(bkt);
glm::vec3 pos = glm::vec3(0,1,2);
@@ -171,10 +174,8 @@ int pke_test_serialization_001() {
pke_serialize_teardown(h);
} catch (const std::exception &ex) {
- pk_mem_bucket_destroy(bkt);
throw;
}
- pk_mem_bucket_destroy(bkt);
pk_funcinstr_teardown();
return 0;
}
@@ -184,7 +185,6 @@ int pke_test_deserialization_101() {
srlztn_deserialize_helper *h;
std::stringstream ss(test_001_str);
try {
- bkt = pk_mem_bucket_create("pke_test_serialization", PK_MEM_DEFAULT_BUCKET_SIZE, PK_MEMBUCKET_FLAG_NONE);
h = pke_deserialize_init(test_level, bkt);
pke_deserialize_scene_from_stream(ss, h);
@@ -214,10 +214,8 @@ int pke_test_deserialization_101() {
pke_deserialize_teardown(h);
} catch (const std::exception &ex) {
- pk_mem_bucket_destroy(bkt);
throw;
}
- pk_mem_bucket_destroy(bkt);
return 0;
}
@@ -255,7 +253,6 @@ int pke_test_serialization_002() {
pke_kve *kve = nullptr;
std::stringstream ss;
try {
- bkt = pk_mem_bucket_create("pke_test_serialization", PK_MEM_DEFAULT_BUCKET_SIZE, PK_MEMBUCKET_FLAG_NONE);
h = pke_serialize_init(bkt);
// reminder that 'targeting' moves and rotates the camera, so we shouldn't see these values in the output
@@ -313,10 +310,8 @@ int pke_test_serialization_002() {
pke_serialize_teardown(h);
} catch (const std::exception &ex) {
- pk_mem_bucket_destroy(bkt);
throw;
}
- pk_mem_bucket_destroy(bkt);
return 0;
}
@@ -327,7 +322,6 @@ int pke_test_deserialization_102() {
srlztn_deserialize_helper *h;
std::stringstream ss(test_002_str);
try {
- bkt = pk_mem_bucket_create("pke_test_serialization", PK_MEM_DEFAULT_BUCKET_SIZE, PK_MEMBUCKET_FLAG_NONE);
h = pke_deserialize_init(test_level, bkt);
pke_deserialize_scene_from_stream(ss, h);
@@ -385,10 +379,8 @@ int pke_test_deserialization_102() {
pke_deserialize_teardown(h);
} catch (const std::exception &ex) {
- pk_mem_bucket_destroy(bkt);
throw;
}
- pk_mem_bucket_destroy(bkt);
return 0;
}
@@ -433,10 +425,9 @@ int pke_test_serialization_003() {
pke_kve *kve = nullptr;
std::stringstream ss;
try {
- bkt = pk_mem_bucket_create("pke_test_serialization", PK_MEM_DEFAULT_BUCKET_SIZE, PK_MEMBUCKET_FLAG_NONE);
h = pke_serialize_init(bkt);
- FontTypeIndex fti;
+ uint64_t idx_unused;
FontRenderSettings frs;
frs.char_scale = 1.0;
frs.char_spacing_scale = 1.0;
@@ -444,7 +435,7 @@ int pke_test_serialization_003() {
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]);
+ FontRenderHandle fr_handle = FontType_AddStringRender(FontType_GetFonts(idx_unused)[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;
@@ -491,10 +482,8 @@ int pke_test_serialization_003() {
pke_serialize_teardown(h);
} catch (const std::exception &ex) {
- pk_mem_bucket_destroy(bkt);
throw;
}
- pk_mem_bucket_destroy(bkt);
return 0;
}
@@ -505,7 +494,6 @@ int pke_test_deserialization_103() {
srlztn_deserialize_helper *h;
std::stringstream ss(test_003_str);
try {
- bkt = pk_mem_bucket_create("pke_test_serialization", PK_MEM_DEFAULT_BUCKET_SIZE, PK_MEMBUCKET_FLAG_NONE);
h = pke_deserialize_init(test_level, bkt);
pke_deserialize_scene_from_stream(ss, h);
@@ -539,16 +527,15 @@ int pke_test_deserialization_103() {
pke_deserialize_scene(h);
- FontTypeIndex fti = FontTypeIndex{0};
- FontType *fonts = FontType_GetFonts(fti);
+ uint64_t idx_unused;
+ FontType *fonts = FontType_GetFonts(idx_unused);
// 66
- 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(idx_unused != 0xFFFFFFFFFFFFFFFF, err_index);
PKE_TEST_ASSERT(fonts->n_render > FontRenderIndex{0}, err_index);
FontRender *fr = &fonts[0].renders[0];
- // 70
+ // 69
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);
@@ -560,7 +547,7 @@ int pke_test_deserialization_103() {
PKE_TEST_ASSERT(fr->settings.color_foreground == glm::vec4(0.4, 0.9, 0.5, 0.8), err_index);
PKE_TEST_ASSERT(fr->settings.color_background == glm::vec4(0.0, 0.0, 0.0, 0.0), err_index);
- // 78
+ // 77
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);
@@ -569,7 +556,7 @@ int pke_test_deserialization_103() {
PKE_TEST_ASSERT(fr->text.val[3] == 'f', err_index);
PKE_TEST_ASSERT(fr->text.val[4] == '\0', err_index);
- // 85
+ // 84
pke_ui_box_count_T count;
pke_ui_box **boxes = pke_ui_get_root_boxes(&count);
pke_ui_box *box = boxes[0];
@@ -582,10 +569,8 @@ int pke_test_deserialization_103() {
pke_deserialize_teardown(h);
} catch (const std::exception &ex) {
- pk_mem_bucket_destroy(bkt);
throw;
}
- pk_mem_bucket_destroy(bkt);
return 0;
}
@@ -622,7 +607,6 @@ int pke_test_serialization_004() {
pke_kve *kve = nullptr;
std::stringstream ss;
try {
- bkt = pk_mem_bucket_create("pke_test_serialization", PK_MEM_DEFAULT_BUCKET_SIZE, PK_MEMBUCKET_FLAG_NONE);
h = pke_serialize_init(bkt);
pke_ui_box *ui_box_p = pke_ui_box_new_root(PKE_UI_BOX_TYPE_STANDARD, uuid_n[2]);
@@ -670,10 +654,8 @@ int pke_test_serialization_004() {
pke_serialize_teardown(h);
} catch (const std::exception &ex) {
- pk_mem_bucket_destroy(bkt);
throw;
}
- pk_mem_bucket_destroy(bkt);
return 0;
}
@@ -684,7 +666,6 @@ int pke_test_deserialization_104() {
pke_kve *kve = nullptr;
std::stringstream ss(test_004_str);
try {
- bkt = pk_mem_bucket_create("pke_test_serialization", PK_MEM_DEFAULT_BUCKET_SIZE, PK_MEMBUCKET_FLAG_NONE);
h = pke_deserialize_init(test_level, bkt);
pke_deserialize_scene_from_stream(ss, h);
@@ -750,10 +731,8 @@ int pke_test_deserialization_104() {
pke_deserialize_teardown(h);
} catch (const std::exception &ex) {
- pk_mem_bucket_destroy(bkt);
throw;
}
- pk_mem_bucket_destroy(bkt);
return 0;
}
diff --git a/tests/pke-test-static-ui.cpp b/tests/pke-test-static-ui.cpp
index ca696fc..c102aba 100644
--- a/tests/pke-test-static-ui.cpp
+++ b/tests/pke-test-static-ui.cpp
@@ -8,6 +8,7 @@
#include "window.hpp"
#include "vendor-glm-include.hpp"
#include <limits>
+
struct pke_ui_box_instance_buffer_item {
glm::mat4 pos_scale;
glm::vec2 px_scale;
@@ -18,10 +19,15 @@ struct pke_ui_flex_params {
float px_per_unit;
float unit_total;
};
+
#define PKE_TEST_EXPOSE
#include "static-ui.hpp"
+static pk_membucket *bkt;
+
void pke_test_static_ui_setup() {
+ bkt = pk_mem_bucket_create("pke_test_static_ui", PK_MEM_DEFAULT_BUCKET_SIZE, PK_MEMBUCKET_FLAG_NONE);
+ pk_mem_bucket_set_client_mem_bucket(bkt);
Extent.width = 1920;
Extent.height = 1080;
pk_ev_init(nullptr);
@@ -35,6 +41,9 @@ void pke_test_static_ui_teardown() {
ECS_Teardown();
pk_ev_teardown();
pke_input_teardown();
+ pk_mem_bucket_destroy(bkt);
+ pk_mem_bucket_set_client_mem_bucket(nullptr);
+ bkt = nullptr;
}
// test static
diff --git a/tests/pke-test.cpp b/tests/pke-test.cpp
index 97694b2..4c6f560 100644
--- a/tests/pke-test.cpp
+++ b/tests/pke-test.cpp
@@ -1,12 +1,13 @@
#include "./pke-test-types.h"
-#include "./pke-test-stubs.h"
-#include "./pke-test-audio.h"
#include "./pke-test-asset-manager.h"
+#include "./pke-test-audio.h"
#include "./pke-test-dummy.h"
+#include "./pke-test-load-unload.h"
#include "./pke-test-serialization.h"
#include "./pke-test-static-ui.h"
+#include "./pke-test-stubs.h"
#include "pk.h"
#include "unistd.h"
@@ -42,6 +43,7 @@ int main(int argc, char *argv[])
pke_test_static_ui_get_group,
pke_test_serialization_get_group,
pke_test_asset_manager_get_group,
+ pke_test_load_unload_get_group,
// pke_test_audio_get_group,
NULL,
};
@@ -55,9 +57,6 @@ int main(int argc, char *argv[])
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) {
- struct pk_membucket *bkt = pk_mem_bucket_create("pke-test-bucket", PK_MEM_DEFAULT_BUCKET_SIZE, PK_MEMBUCKET_FLAG_NONE);
- pk_mem_bucket_set_client_mem_bucket(bkt);
- fprintf(stdout, "[pke-test]:[%s]:[%s] Begin.\n", group->title, group->tests[k].title);
pke_test_stub_init_vulkan();
if (group->test_setup != NULL) (group->test_setup)();
lj.expected_exit = 0;
@@ -76,7 +75,6 @@ int main(int argc, char *argv[])
}
if (group->test_teardown != NULL) (group->test_teardown)();
pke_test_stub_teardown_vulkan();
- pk_mem_bucket_destroy(bkt);
}
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);