[glib] utf8: add unit test for g_utf8_make_valid
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] utf8: add unit test for g_utf8_make_valid
- Date: Sat, 4 Mar 2017 19:20:13 +0000 (UTC)
commit 935cd72bddda77b5c09b9b72d5a478b9d7817aa6
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Mar 4 19:59:37 2017 +0100
utf8: add unit test for g_utf8_make_valid
glib/tests/utf8-misc.c | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/glib/tests/utf8-misc.c b/glib/tests/utf8-misc.c
index 764cd3d..a2d22df 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();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]