From 935cd72bddda77b5c09b9b72d5a478b9d7817aa6 Mon Sep 17 00:00:00 2001 From: Paolo Borelli Date: Sat, 4 Mar 2017 19:59:37 +0100 Subject: [PATCH] utf8: add unit test for g_utf8_make_valid --- glib/tests/utf8-misc.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/glib/tests/utf8-misc.c b/glib/tests/utf8-misc.c index 764cd3d0e..a2d22df3f 100644 --- a/glib/tests/utf8-misc.c +++ b/glib/tests/utf8-misc.c @@ -130,6 +130,27 @@ test_utf8_substring (void) g_free (r); } +static void +test_utf8_make_valid (void) +{ + gchar *r; + + /* valid UTF8 */ + r = g_utf8_make_valid ("\xe2\x82\xa0gh\xe2\x82\xa4jl", -1); + g_assert_cmpstr (r, ==, "\xe2\x82\xa0gh\xe2\x82\xa4jl"); + g_free (r); + + /* invalid UTF8 */ + r = g_utf8_make_valid ("\xe2\x82\xa0gh\xe2\xffjl", -1); + g_assert_cmpstr (r, ==, "\xe2\x82\xa0gh\xef\xbf\xbd\xef\xbf\xbdjl"); + g_free (r); + + /* invalid UTF8 with embedded nul */ + r = g_utf8_make_valid ("\xe2\x82\xa0gh\xe2\x00jl", 9); + g_assert_cmpstr (r, ==, "\xe2\x82\xa0gh\xef\xbf\xbd\xef\xbf\xbdjl"); + g_free (r); +} + int main (int argc, char *argv[]) @@ -141,6 +162,7 @@ main (int argc, g_test_add_func ("/utf8/strrchr", test_utf8_strrchr); g_test_add_func ("/utf8/reverse", test_utf8_reverse); g_test_add_func ("/utf8/substring", test_utf8_substring); + g_test_add_func ("/utf8/make-valid", test_utf8_make_valid); return g_test_run(); } -- 2.11.4.GIT