diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-11-17 03:15:16 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-11-17 03:15:16 +0100 |
commit | c18f87ad13da518af5ff245dbce2a9e608097ea1 (patch) | |
tree | 3ca8a22df68fc1ef7ecd7b9ec449a733b76de67a /tests | |
parent | ccd0e65a0ddccd9c52d4c075ec1cad41ae7edb40 (diff) |
Attempt to fix font glyph texture overlap by aligning texture size to
next character size
Add function to get the start of a utf8 codepoint (backwards), test utf8
functions
Diffstat (limited to 'tests')
-rw-r--r-- | tests/main.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/main.c b/tests/main.c index cee3ec7..b341bb3 100644 --- a/tests/main.c +++ b/tests/main.c @@ -13,6 +13,7 @@ #include <mgl/graphics/shader.h> #include <mgl/system/clock.h> #include <mgl/system/fileutils.h> +#include <mgl/system/utf8.h> #define require_equals(a, b) do { if((a) != (b)) { fprintf(stderr, "Assert failed on line %d: %s == %s\n", __LINE__, #a, #b); abort(); } } while(0) #define require_not_equals(a, b) do { if((a) == (b)) { fprintf(stderr, "Assert failed on line %d: %s != %s\n", __LINE__, #a, #b); abort(); } } while(0) @@ -189,8 +190,34 @@ static void test_hash_map() { mgl_font_char_map_deinit(&char_map); } +static void test_utf8() { + uint32_t codepoint = 0; + size_t codepoint_length = 0; + + require_equals(mgl_utf8_decode("a", 1, &codepoint, &codepoint_length), true); + require_equals(codepoint, 0x61); + require_equals(codepoint_length, 1); + + require_equals(mgl_utf8_decode("á", 2, &codepoint, &codepoint_length), true); + require_equals(codepoint, 0xE1); + require_equals(codepoint_length, 2); + + require_equals(mgl_utf8_decode("‡", 3, &codepoint, &codepoint_length), true); + require_equals(codepoint, 0x2021); + require_equals(codepoint_length, 3); + + require_equals(mgl_utf8_decode("𒀀", 4, &codepoint, &codepoint_length), true); + require_equals(codepoint, 0x12000); + require_equals(codepoint_length, 4); + + require_equals(mgl_utf8_get_start_of_codepoint("abc", 3, 0), 0); + require_equals(mgl_utf8_get_start_of_codepoint("abc", 3, 2), 2); + require_equals(mgl_utf8_get_start_of_codepoint("abö", 3, 4), 2); +} + int main(int argc, char **argv) { test_hash_map(); + test_utf8(); if(mgl_init() != 0) return 1; |