diff options
author | Matthias Clasen <mclasen@redhat.com> | 2015-09-07 14:59:22 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2015-09-07 15:01:16 -0400 |
commit | e773acfe9a0f8cf4d67799f6177997bd8a761ede (patch) | |
tree | 92706daed3d398d4a39ca425e261347bb505c483 | |
parent | db3ffe5bf139a664609ab1f7e3715a2da5019805 (diff) | |
download | glib-e773acfe9a0f8cf4d67799f6177997bd8a761ede.tar.gz |
tests: Don't test g_utf8_to_ucs4_fast too rigorously
The function is documented to assume valid input, and doesn't
guarantee behavior with invalid input. So don't test that.
https://bugzilla.gnome.org/show_bug.cgi?id=754636
-rw-r--r-- | tests/unicode-encoding.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/tests/unicode-encoding.c b/tests/unicode-encoding.c index b1dc885c8..8ac4f9522 100644 --- a/tests/unicode-encoding.c +++ b/tests/unicode-encoding.c @@ -78,6 +78,16 @@ utf16_count (gunichar2 *a) } static void +print_ucs4 (const gchar *prefix, gunichar *ucs4, gint ucs4_len) +{ + gint i; + g_print ("%s ", prefix); + for (i = 0; i < ucs4_len; i++) + g_print ("%x ", ucs4[i]); + g_print ("\n"); +} + +static void process (gint line, gchar *utf8, Status status, @@ -112,7 +122,7 @@ process (gint line, if (status == INCOMPLETE) { - gunichar *ucs4_result; + gunichar *ucs4_result; ucs4_result = g_utf8_to_ucs4 (utf8, -1, NULL, NULL, &error); @@ -137,31 +147,40 @@ process (gint line, if (status == VALID || status == NOTUNICODE) { gunichar *ucs4_result; - gchar *utf8_result; ucs4_result = g_utf8_to_ucs4 (utf8, -1, &items_read, &items_written, &error); if (!ucs4_result) { - fail ("line %d: conversion to ucs4 failed: %s\n", line, error->message); + fail ("line %d: conversion with status %d to ucs4 failed: %s\n", line, status, error->message); return; } - + if (!ucs4_equal (ucs4_result, ucs4) || items_read != strlen (utf8) || items_written != ucs4_len) { - fail ("line %d: results of conversion to ucs4 do not match expected.\n", line); + fail ("line %d: results of conversion with status %d to ucs4 do not match expected.\n", line, status); + print_ucs4 ("expected: ", ucs4, ucs4_len); + print_ucs4 ("received: ", ucs4_result, items_written); return; } g_free (ucs4_result); + } + + if (status == VALID) + { + gunichar *ucs4_result; + gchar *utf8_result; ucs4_result = g_utf8_to_ucs4_fast (utf8, -1, &items_written); - + if (!ucs4_equal (ucs4_result, ucs4) || items_written != ucs4_len) { - fail ("line %d: results of fast conversion to ucs4 do not match expected.\n", line); + fail ("line %d: results of fast conversion with status %d to ucs4 do not match expected.\n", line, status); + print_ucs4 ("expected: ", ucs4, ucs4_len); + print_ucs4 ("received: ", ucs4_result, items_written); return; } |