aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/main.c27
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;