Update contrib.
1 /* Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.*/
2 #undef G_DISABLE_ASSERT
11 #include <glib_global.h>
12 #include "mrt2_glib2_test.h"
13 #endif /*__SYMBIAN32__*/
15 gboolean success = TRUE;
18 decode (const gchar *input)
22 GString *result = g_string_new (NULL);
26 if (sscanf (input + offset, "%x", &ch) != 1)
28 fprintf (stderr, "Error parsing character string %s\n", input);
29 g_assert(FALSE && "unicode-normalize failed");
31 testResultXml("unicode-normalize");
36 g_string_append_unichar (result, ch);
38 while (input[offset] && input[offset] != ' ')
40 while (input[offset] && input[offset] == ' ')
43 while (input[offset]);
45 return g_string_free (result, FALSE);
48 const char *names[4] = {
56 encode (const gchar *input)
58 GString *result = g_string_new(NULL);
60 const gchar *p = input;
63 gunichar c = g_utf8_get_char (p);
64 g_string_append_printf (result, "%04X ", c);
65 p = g_utf8_next_char(p);
68 return g_string_free (result, FALSE);
81 gboolean mode_is_compat = (mode == G_NORMALIZE_NFKC ||
82 mode == G_NORMALIZE_NFKD);
84 if (mode_is_compat || !do_compat)
86 for (i = 0; i < 3; i++)
88 char *result = g_utf8_normalize (c[i], -1, mode);
89 if (strcmp (result, c[expected]) != 0)
91 char *result_raw = encode(result);
92 fprintf (stderr, "\nFailure: %d/%d: %s\n", line, i + 1, raw[5]);
93 fprintf (stderr, " g_utf8_normalize (%s, %s) != %s but %s\n",
94 raw[i], names[mode], raw[expected], result_raw);
102 if (mode_is_compat || do_compat)
104 for (i = 3; i < 5; i++)
106 char *result = g_utf8_normalize (c[i], -1, mode);
107 if (strcmp (result, c[expected]) != 0)
109 char *result_raw = encode(result);
110 fprintf (stderr, "\nFailure: %d/%d: %s\n", line, i, raw[5]);
111 fprintf (stderr, " g_utf8_normalize (%s, %s) != %s but %s\n",
112 raw[i], names[mode], raw[expected], result_raw);
123 process_one (int line, gchar **columns)
127 gboolean skip = FALSE;
129 for (i=0; i < 5; i++)
131 c[i] = decode(columns[i]);
138 test_form (line, G_NORMALIZE_NFD, FALSE, 2, c, columns);
139 test_form (line, G_NORMALIZE_NFD, TRUE, 4, c, columns);
140 test_form (line, G_NORMALIZE_NFC, FALSE, 1, c, columns);
141 test_form (line, G_NORMALIZE_NFC, TRUE, 3, c, columns);
142 test_form (line, G_NORMALIZE_NFKD, TRUE, 4, c, columns);
143 test_form (line, G_NORMALIZE_NFKC, TRUE, 3, c, columns);
146 for (i=0; i < 5; i++)
152 int main (int argc, char **argv)
155 GError *error = NULL;
156 GString *buffer = g_string_new (NULL);
161 g_log_set_handler (NULL, G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
162 g_set_print_handler(mrtPrintHandler);
163 #endif /*__SYMBIAN32__*/
164 if (argc != 2 && argc != 3)
166 fprintf (stderr, "Usage: unicode-normalize NormalizationTest.txt LINE\n");
171 line_to_do = atoi(argv[2]);
173 in = g_io_channel_new_file (argv[1], "r", &error);
176 fprintf (stderr, "Cannot open %s: %s\n", argv[1], error->message);
177 g_assert(FALSE && "unicode-normalize failed");
180 testResultXml("unicode-normalize");
181 #endif /* EMULATOR */
191 if (g_io_channel_read_line_string (in, buffer, &term_pos, &error) != G_IO_STATUS_NORMAL)
194 if (line_to_do && line != line_to_do)
197 buffer->str[term_pos] = '\0';
199 if (buffer->str[0] == '#') /* Comment */
201 if (buffer->str[0] == '@') /* Part */
203 fprintf (stderr, "\nProcessing %s\n", buffer->str + 1);
207 columns = g_strsplit (buffer->str, ";", -1);
211 if (!process_one (line, columns))
213 g_strfreev (columns);
216 g_string_truncate (buffer, 0);
222 fprintf (stderr, "Error reading test file, %s\n", error->message);
223 g_assert(FALSE && "unicode-normalize failed");
225 testResultXml("unicode-normalize");
226 #endif /* EMULATOR */
230 g_io_channel_unref (in);
231 g_string_free (buffer, TRUE);
234 assert_failed = !success;
235 testResultXml("unicode-normalize");
236 #endif /* EMULATOR */