diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-09-23 09:37:01 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-09-23 09:37:01 -0400 |
| commit | ed6b1a537939b37a7a66bfa6b10eb594a4c597e6 (patch) | |
| tree | dbd2f44a3ac45a76839429d4111eeb0f3c70012b | |
| parent | ccf107a65e566b1372907ae95e099f3dfa0a076e (diff) | |
pke: FontType_AddStringRender increment index
| -rw-r--r-- | Makefile | 1 | ||||
| -rw-r--r-- | src/font.cpp | 9 | ||||
| -rw-r--r-- | tests/pke-test-font.cpp | 89 | ||||
| -rw-r--r-- | tests/pke-test-font.hpp | 8 | ||||
| -rw-r--r-- | tests/pke-test.cpp | 2 |
5 files changed, 105 insertions, 4 deletions
@@ -252,6 +252,7 @@ $(DIR_OBJ)/libpke-test.$(LIB_EXT): $(DIR_OBJ)/pke-test-static-ui.$(OBJ_EXT) $(DIR_OBJ)/libpke-test.$(LIB_EXT): $(DIR_OBJ)/pke-test-serialization.$(OBJ_EXT) $(DIR_OBJ)/libpke-test.$(LIB_EXT): $(DIR_OBJ)/pke-test-load-unload.$(OBJ_EXT) $(DIR_OBJ)/libpke-test.$(LIB_EXT): $(DIR_OBJ)/pke-test-asset-manager.$(OBJ_EXT) +$(DIR_OBJ)/libpke-test.$(LIB_EXT): $(DIR_OBJ)/pke-test-font.$(OBJ_EXT) ar rcs $@ $(filter %.$(OBJ_EXT),$^) $(DIR_OBJ)/libpke-runtime.$(LIB_EXT): $(DIR_OBJ)/libpke.$(LIB_EXT) diff --git a/src/font.cpp b/src/font.cpp index 58d5f50..3dba635 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -888,13 +888,14 @@ FontRenderHandle FontType_AddStringRender(FontTypeIndex idx_ft, const pk_cstr && assert(settings != nullptr); FontType *ft = &ftd.arr_ft[(FontTypeIndex_T)idx_ft]; FontRender *fr; + FontRenderIndex_T fri; uint32_t i, count; FontRenderIndex idx_fr = FontRenderIndex{0}; - for (i = 0; i < (FontRenderIndex_T)ft->n_render; ++i) { - if ((ft->unused_frs & (1llu << i)) != 0) { - ft->unused_frs &= ~(1llu << i); - idx_fr = FontRenderIndex{0}; + for (fri = 0; fri < (FontRenderIndex_T)ft->n_render; ++fri) { + if ((ft->unused_frs & (1llu << fri)) != 0) { + ft->unused_frs &= ~(1llu << fri); + idx_fr = FontRenderIndex{fri}; break; } } diff --git a/tests/pke-test-font.cpp b/tests/pke-test-font.cpp new file mode 100644 index 0000000..856dbdb --- /dev/null +++ b/tests/pke-test-font.cpp @@ -0,0 +1,89 @@ + +#include "pke-test-font.hpp" + +#include "asset-manager.hpp" +#include "ecs.hpp" +#include "font.hpp" +#include "pk.h" +#include "thread-pool.hpp" + +static pk_membucket *bkt; + +void pke_test_font_setup() { + bkt = pk_mem_bucket_create("pke_test_font", PK_MEM_DEFAULT_BUCKET_SIZE, PK_MEMBUCKET_FLAG_NONE); + pk_mem_bucket_set_client_mem_bucket(bkt); + pk_ev_init(bkt); + PkeThreads_Init(); + AM_Init(); + ECS_Init(); + FontType_Init(); +} + +void pke_test_font_teardown() { + FontType_Teardown(); + ECS_Teardown(); + AM_Teardown(); + PkeThreads_Teardown(); + pk_ev_teardown(); + pk_mem_bucket_destroy(bkt); + pk_mem_bucket_set_client_mem_bucket(nullptr); + bkt = nullptr; +} + +/* Ensure the font exists + */ +int pke_test_font_001() { + int err_index = 0; + + FontType *ft = FontType_Get(FontTypeIndex{0}); + PKE_TEST_ASSERT(ft != nullptr, err_index); + PKE_TEST_ASSERT(ft->index_ft == FontTypeIndex{0}, err_index); + + return 0; +} + +/* Ensure we can have more than one FontRender + */ +int pke_test_font_002() { + int err_index = 0; + FontTypeIndex fti{0}; + FontRenderHandle handle_001{}; + FontRenderHandle handle_002{}; + FontRenderSettings frs{}; + + handle_001 = FontType_AddStringRender(fti, std::move(cstring_to_pk_cstr("string one")), &frs); + + PKE_TEST_ASSERT(handle_001.index_ft == FontTypeIndex{0}, err_index); + PKE_TEST_ASSERT(handle_001.index_fr == FontRenderIndex{0}, err_index); + + handle_002 = FontType_AddStringRender(fti, std::move(cstring_to_pk_cstr("string two")), &frs); + + PKE_TEST_ASSERT(handle_002.index_ft == FontTypeIndex{0}, err_index); + PKE_TEST_ASSERT(handle_002.index_fr == FontRenderIndex{1}, err_index); + + return 0; +} + +struct pke_test_group *pke_test_font_get_group() { + static const uint64_t test_count = 2; + static struct pke_test tests[test_count] = { + { + .title = "test 001", + .func = pke_test_font_001, + .expected_result = 0, + }, + { + .title = "test 002", + .func = pke_test_font_002, + .expected_result = 0, + }, + }; + static struct pke_test_group group = {}; + group.title = "font test"; + group.test_setup = pke_test_font_setup; + group.test_teardown = pke_test_font_teardown; + group.n_tests = test_count; + group.tests = &tests[0]; + + return &group; +} diff --git a/tests/pke-test-font.hpp b/tests/pke-test-font.hpp new file mode 100644 index 0000000..19b2ddd --- /dev/null +++ b/tests/pke-test-font.hpp @@ -0,0 +1,8 @@ +#ifndef PKE_PKE_TEST_FONT_HPP +#define PKE_PKE_TEST_FONT_HPP + +#include "pke-test-types.h" + +struct pke_test_group *pke_test_font_get_group(); + +#endif /* PKE_PKE_TEST_FONT_HPP */ diff --git a/tests/pke-test.cpp b/tests/pke-test.cpp index 4c6f560..5508394 100644 --- a/tests/pke-test.cpp +++ b/tests/pke-test.cpp @@ -4,6 +4,7 @@ #include "./pke-test-asset-manager.h" #include "./pke-test-audio.h" #include "./pke-test-dummy.h" +#include "./pke-test-font.hpp" #include "./pke-test-load-unload.h" #include "./pke-test-serialization.h" #include "./pke-test-static-ui.h" @@ -44,6 +45,7 @@ int main(int argc, char *argv[]) pke_test_serialization_get_group, pke_test_asset_manager_get_group, pke_test_load_unload_get_group, + pke_test_font_get_group, // pke_test_audio_get_group, NULL, }; |
