Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/eglib
diff options
context:
space:
mode:
authorAndrew Wilson <andrew.wilson@linn.co.uk>2012-09-04 00:13:28 +0400
committerRodrigo Kumpera <kumpera@gmail.com>2012-10-11 00:28:55 +0400
commitbaf2ec58aacfaee0a95dc6b6a659f6012a76f025 (patch)
tree4dc1892f5aed31b20bbbc50ebb1b27e771304b6b /eglib
parentfa49af24984b38402028f259d2c14bdc5b67362d (diff)
Add test for g_utf8_to_utf16_with_nuls.
Diffstat (limited to 'eglib')
-rw-r--r--eglib/test/Makefile.am2
-rw-r--r--eglib/test/utf8.c71
2 files changed, 65 insertions, 8 deletions
diff --git a/eglib/test/Makefile.am b/eglib/test/Makefile.am
index dfa708025a3..3f914fd510d 100644
--- a/eglib/test/Makefile.am
+++ b/eglib/test/Makefile.am
@@ -31,7 +31,7 @@ SOURCES = \
test_eglib_SOURCES = $(SOURCES)
-test_eglib_CFLAGS = -Wall -D_FORTIFY_SOURCE=2 -I$(srcdir)/../src -I../src -DDRIVER_NAME=\"EGlib\"
+test_eglib_CFLAGS = -Wall -DEGLIB_TESTS=1 -D_FORTIFY_SOURCE=2 -I$(srcdir)/../src -I../src -DDRIVER_NAME=\"EGlib\"
test_eglib_LDADD = ../src/libeglib.la $(LIBICONV)
run-eglib: all
diff --git a/eglib/test/utf8.c b/eglib/test/utf8.c
index bae5ba0240b..153a4bbc60f 100644
--- a/eglib/test/utf8.c
+++ b/eglib/test/utf8.c
@@ -136,11 +136,15 @@ compare_strings_utf16_RESULT (const gunichar2 *expected, const gunichar2 *actual
ret = compare_strings_utf16_pos (expected, actual, size);
if (ret < 0)
return OK;
- return FAILED ("Incorrect output: expected '%s' but was '%s'\n", expected, actual);
+ return FAILED ("Incorrect output: expected '%s' but was '%s', differ at %d ('%c' x '%c')\n", expected, actual, ret, expected [ret], actual [ret]);
}
+#if !defined(EGLIB_TESTS)
+#define g_utf8_to_utf16_with_nuls g_utf8_to_utf16
+#endif
+
RESULT
-compare_utf8_to_utf16_explicit (const gunichar2 *expected, const gchar *utf8, glong len_in, glong len_out, glong size_spec)
+compare_utf8_to_utf16_explicit (const gunichar2 *expected, const gchar *utf8, glong len_in, glong len_out, glong size_spec, gboolean include_nuls)
{
GError *error;
gunichar2* ret;
@@ -150,7 +154,11 @@ compare_utf8_to_utf16_explicit (const gunichar2 *expected, const gchar *utf8, gl
result = NULL;
error = NULL;
- ret = g_utf8_to_utf16 (utf8, size_spec, &in_read, &out_read, &error);
+ if (include_nuls)
+ ret = g_utf8_to_utf16_with_nuls (utf8, size_spec, &in_read, &out_read, &error);
+ else
+ ret = g_utf8_to_utf16 (utf8, size_spec, &in_read, &out_read, &error);
+
if (error) {
result = FAILED ("The error is %d %s\n", (error)->code, (error)->message);
g_error_free (error);
@@ -172,19 +180,31 @@ compare_utf8_to_utf16_explicit (const gunichar2 *expected, const gchar *utf8, gl
return OK;
}
-
RESULT
-compare_utf8_to_utf16 (const gunichar2 *expected, const gchar *utf8, glong len_in, glong len_out)
+compare_utf8_to_utf16_general (const gunichar2 *expected, const gchar *utf8, glong len_in, glong len_out, gboolean include_nuls)
{
RESULT result;
- result = compare_utf8_to_utf16_explicit (expected, utf8, len_in, len_out, -1);
+ result = compare_utf8_to_utf16_explicit (expected, utf8, len_in, len_out, -1, include_nuls);
if (result != OK)
return result;
- return compare_utf8_to_utf16_explicit (expected, utf8, len_in, len_out, len_in);
+ return compare_utf8_to_utf16_explicit (expected, utf8, len_in, len_out, len_in, include_nuls);
+}
+
+RESULT
+compare_utf8_to_utf16 (const gunichar2 *expected, const gchar *utf8, glong len_in, glong len_out)
+{
+ return compare_utf8_to_utf16_general (expected, utf8, len_in, len_out, FALSE);
}
RESULT
+compare_utf8_to_utf16_with_nuls (const gunichar2 *expected, const gchar *utf8, glong len_in, glong len_out)
+{
+ return compare_utf8_to_utf16_explicit (expected, utf8, len_in, len_out, len_in, TRUE);
+}
+
+
+RESULT
test_utf8_seq ()
{
const gchar *src = "\xE5\xB9\xB4\x27";
@@ -240,6 +260,42 @@ test_utf8_to_utf16 ()
return OK;
}
+RESULT
+test_utf8_to_utf16_with_nuls ()
+{
+ const gchar *src0 = "", *src1 = "AB\0DE", *src2 = "\xE5\xB9\xB4\x27", *src3 = "\xEF\xBC\xA1", *src4 = "\xEF\xBD\x81";
+ gunichar2 str0 [] = {0}, str1 [] = {'A', 'B', 0, 'D', 'E', 0}, str2 [] = {0x5E74, 39, 0}, str3 [] = {0xFF21, 0}, str4 [] = {0xFF41, 0};
+ RESULT result;
+
+#if !defined(EGLIB_TESTS)
+ return OK;
+#endif
+
+ /* implicit length is forbidden */
+ if (g_utf8_to_utf16_with_nuls (src1, -1, NULL, NULL, NULL) != NULL)
+ return FAILED ("explicit nulls must fail with -1 length\n");
+
+ /* empty string */
+ result = compare_utf8_to_utf16_with_nuls (str0, src0, 0, 0);
+ if (result != OK)
+ return result;
+
+ result = compare_utf8_to_utf16_with_nuls (str1, src1, 5, 5);
+ if (result != OK)
+ return result;
+ result = compare_utf8_to_utf16_with_nuls (str2, src2, 4, 2);
+ if (result != OK)
+ return result;
+ result = compare_utf8_to_utf16_with_nuls (str3, src3, 3, 1);
+ if (result != OK)
+ return result;
+ result = compare_utf8_to_utf16_with_nuls (str4, src4, 3, 1);
+ if (result != OK)
+ return result;
+
+ return OK;
+}
+
typedef struct {
char *content;
size_t length;
@@ -859,6 +915,7 @@ test_utf8_strdown ()
static Test utf8_tests [] = {
{"g_utf16_to_utf8", test_utf16_to_utf8},
{"g_utf8_to_utf16", test_utf8_to_utf16},
+ {"g_utf8_to_utf16_with_nuls", test_utf8_to_utf16_with_nuls},
{"g_utf8_seq", test_utf8_seq},
{"g_convert", test_convert },
{"g_unichar_xdigit_value", test_xdigit },