1 #undef G_DISABLE_ASSERT
9 gboolean success = TRUE;
12 decode (const gchar *input)
16 GString *result = g_string_new (NULL);
20 if (sscanf (input + offset, "%x", &ch) != 1)
22 fprintf (stderr, "Error parsing character string %s\n", input);
26 /* FIXME: We don't handle the > BMP or Hangul syllables */
27 if (ch > 0xffff || /* > BMP */
28 (ch >= 0xac00 && ch <= 0xd7ff)) /* Hangul syllables */
30 g_string_free (result, TRUE);
34 g_string_append_unichar (result, ch);
36 while (input[offset] && input[offset] != ' ')
38 while (input[offset] && input[offset] == ' ')
41 while (input[offset]);
43 return g_string_free (result, FALSE);
46 const char *names[4] = {
63 gboolean mode_is_compat = (mode == G_NORMALIZE_NFKC ||
64 mode == G_NORMALIZE_NFKD);
66 if (mode_is_compat || !do_compat)
68 for (i = 0; i < 3; i++)
70 char *result = g_utf8_normalize (c[i], -1, mode);
71 if (strcmp (result, c[expected]) != 0)
73 fprintf (stderr, "\nFailure: %d/%d: %s\n", line, i + 1, raw[5]);
74 fprintf (stderr, " g_utf8_normalize (%s, %s) != %s\n",
75 raw[i], names[mode], raw[expected]);
82 if (mode_is_compat || do_compat)
84 for (i = 3; i < 5; i++)
86 char *result = g_utf8_normalize (c[i], -1, mode);
87 if (strcmp (result, c[expected]) != 0)
89 fprintf (stderr, "\nFailure: %d/%d: %s\n", line, i, raw[5]);
90 fprintf (stderr, " g_utf8_normalize (%s, %s) != %s\n",
91 raw[i], names[mode], raw[expected]);
101 process_one (int line, gchar **columns)
105 gboolean skip = FALSE;
107 for (i=0; i < 5; i++)
109 c[i] = decode(columns[i]);
116 test_form (line, G_NORMALIZE_NFD, FALSE, 2, c, columns);
117 test_form (line, G_NORMALIZE_NFD, TRUE, 4, c, columns);
118 test_form (line, G_NORMALIZE_NFC, FALSE, 1, c, columns);
119 test_form (line, G_NORMALIZE_NFC, TRUE, 3, c, columns);
120 test_form (line, G_NORMALIZE_NFKD, TRUE, 4, c, columns);
121 test_form (line, G_NORMALIZE_NFKC, TRUE, 3, c, columns);
124 for (i=0; i < 5; i++)
130 int main (int argc, char **argv)
133 GError *error = NULL;
134 GString *buffer = g_string_new (NULL);
138 if (argc != 2 && argc != 3)
140 fprintf (stderr, "Usage: unicode-normalize NormalizationTest.txt LINE\n");
145 line_to_do = atoi(argv[2]);
147 in = g_io_channel_new_file (argv[1], "r", &error);
150 fprintf (stderr, "Cannot open %s: %s\n", argv[1], error->message);
159 if (g_io_channel_read_line_string (in, buffer, &term_pos, &error) != G_IO_STATUS_NORMAL)
162 if (line_to_do && line != line_to_do)
165 buffer->str[term_pos] = '\0';
167 if (buffer->str[0] == '#') /* Comment */
169 if (buffer->str[0] == '@') /* Part */
171 fprintf (stderr, "\nProcessing %s\n", buffer->str + 1);
175 columns = g_strsplit (buffer->str, ";", -1);
179 if (!process_one (line, columns))
181 g_strfreev (columns);
184 g_string_truncate (buffer, 0);
190 fprintf (stderr, "Error reading test file, %s\n", error->message);
194 g_io_channel_unref (in);
195 g_string_free (buffer, TRUE);