From c18f87ad13da518af5ff245dbce2a9e608097ea1 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 17 Nov 2021 03:15:16 +0100 Subject: 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 --- tests/main.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests') 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 #include #include +#include #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; -- cgit v1.2.3