diff options
Diffstat (limited to 'glib/tests/unicode.c')
-rw-r--r-- | glib/tests/unicode.c | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/glib/tests/unicode.c b/glib/tests/unicode.c index 693214097..5d66977c2 100644 --- a/glib/tests/unicode.c +++ b/glib/tests/unicode.c @@ -2,6 +2,8 @@ * Copyright (C) 2010 Red Hat, Inc. * Copyright (C) 2011 Google, Inc. * + * SPDX-License-Identifier: LicenseRef-old-glib-tests + * * This work is provided "as is"; redistribution and modification * in whole or in part, in any medium, physical or electronic is * permitted without restriction. @@ -354,7 +356,9 @@ test_unichar_script (void) { G_UNICODE_SCRIPT_OLD_UYGHUR, 0x10F70 }, { G_UNICODE_SCRIPT_TANGSA, 0x16A70 }, { G_UNICODE_SCRIPT_TOTO, 0x1E290 }, - { G_UNICODE_SCRIPT_VITHKUQI, 0x10570 } + { G_UNICODE_SCRIPT_VITHKUQI, 0x10570 }, + { G_UNICODE_SCRIPT_KAWI, 0x11F00 }, + { G_UNICODE_SCRIPT_NAG_MUNDARI, 0x1E4D0 }, }; for (i = 0; i < G_N_ELEMENTS (examples); i++) g_assert_cmpint (g_unichar_get_script (examples[i].c), ==, examples[i].script); @@ -455,6 +459,10 @@ test_strup (void) /* Tricky, comparing two unicode strings with an ASCII function */ g_assert_cmpstr (str_up, ==, "AAZZ09X;\003E\357\274\241\357\274\241"); g_free (str_up); + + str_up = g_utf8_strup ("", 0); + g_assert_cmpstr (str_up, ==, ""); + g_free (str_up); } /* Test that g_utf8_strdown() returns the correct value for various @@ -480,6 +488,10 @@ test_strdown (void) /* Tricky, comparing two unicode strings with an ASCII function */ g_assert_cmpstr (str_down, ==, "aazz09x;\003\007\357\275\201\357\275\201"); g_free (str_down); + + str_down = g_utf8_strdown ("", 0); + g_assert_cmpstr (str_down, ==, ""); + g_free (str_down); } /* Test that g_utf8_strup() and g_utf8_strdown() return the correct @@ -572,6 +584,10 @@ test_casefold (void) /* Tricky, comparing two unicode strings with an ASCII function */ g_assert_cmpstr (str_casefold, ==, "aazz09x;\357\275\201\357\275\201"); g_free (str_casefold); + + str_casefold = g_utf8_casefold ("", 0); + g_assert_cmpstr (str_casefold, ==, ""); + g_free (str_casefold); } static void @@ -1848,7 +1864,11 @@ test_iso15924 (void) { G_UNICODE_SCRIPT_OLD_UYGHUR, "Ougr" }, { G_UNICODE_SCRIPT_TANGSA, "Tnsa" }, { G_UNICODE_SCRIPT_TOTO, "Toto" }, - { G_UNICODE_SCRIPT_VITHKUQI, "Vith" } + { G_UNICODE_SCRIPT_VITHKUQI, "Vith" }, + + /* Unicode 15.0 additions */ + { G_UNICODE_SCRIPT_KAWI, "Kawi" }, + { G_UNICODE_SCRIPT_NAG_MUNDARI, "Nagm" }, }; guint i; @@ -1873,6 +1893,7 @@ test_iso15924 (void) data[i].four_letter_code[2], data[i].four_letter_code[3]); + g_test_message ("Testing script %s (code %u)", data[i].four_letter_code, code); g_assert_cmphex (g_unicode_script_to_iso15924 (data[i].script), ==, code); g_assert_cmpint (g_unicode_script_from_iso15924 (code), ==, data[i].script); } @@ -1880,6 +1901,45 @@ test_iso15924 (void) #undef PACK } +static void +test_normalize (void) +{ + guint i; + typedef struct + { + const gchar *str; + const gchar *nfd; + const gchar *nfc; + const gchar *nfkd; + const gchar *nfkc; + } Test; + Test tests[] = { + { "Äffin", "A\u0308ffin", "Äffin", "A\u0308ffin", "Äffin" }, + { "Ä\uFB03n", "A\u0308\uFB03n", "Ä\uFB03n", "A\u0308ffin", "Äffin" }, + { "Henry IV", "Henry IV", "Henry IV", "Henry IV", "Henry IV" }, + { "Henry \u2163", "Henry \u2163", "Henry \u2163", "Henry IV", "Henry IV" }, + { "non-utf\x88", NULL, NULL, NULL, NULL }, + { "", "", "", "", "" }, + }; + +#define TEST(str, mode, expected) \ + { \ + gchar *normalized = g_utf8_normalize (str, -1, mode); \ + g_assert_cmpstr (normalized, ==, expected); \ + g_free (normalized); \ + } + + for (i = 0; i < G_N_ELEMENTS (tests); i++) + { + TEST (tests[i].str, G_NORMALIZE_NFD, tests[i].nfd); + TEST (tests[i].str, G_NORMALIZE_NFC, tests[i].nfc); + TEST (tests[i].str, G_NORMALIZE_NFKD, tests[i].nfkd); + TEST (tests[i].str, G_NORMALIZE_NFKC, tests[i].nfkc); + } + +#undef TEST +} + int main (int argc, char *argv[]) @@ -1924,6 +1984,7 @@ main (int argc, g_test_add_func ("/unicode/xdigit", test_xdigit); g_test_add_func ("/unicode/xdigit-value", test_xdigit_value); g_test_add_func ("/unicode/zero-width", test_zerowidth); + g_test_add_func ("/unicode/normalize", test_normalize); return g_test_run(); } |