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 Hangul syllables */
27 if (ch >= 0xac00 && ch <= 0xd7ff) /* Hangul syllables */
29 g_string_free (result, TRUE);
33 g_string_append_unichar (result, ch);
35 while (input[offset] && input[offset] != ' ')
37 while (input[offset] && input[offset] == ' ')
40 while (input[offset]);
42 return g_string_free (result, FALSE);
45 const char *names[4] = {
62 gboolean mode_is_compat = (mode == G_NORMALIZE_NFKC ||
63 mode == G_NORMALIZE_NFKD);
65 if (mode_is_compat || !do_compat)
67 for (i = 0; i < 3; i++)
69 char *result = g_utf8_normalize (c[i], -1, mode);
70 if (strcmp (result, c[expected]) != 0)
72 fprintf (stderr, "\nFailure: %d/%d: %s\n", line, i + 1, raw[5]);
73 fprintf (stderr, " g_utf8_normalize (%s, %s) != %s\n",
74 raw[i], names[mode], raw[expected]);
81 if (mode_is_compat || do_compat)
83 for (i = 3; i < 5; i++)
85 char *result = g_utf8_normalize (c[i], -1, mode);
86 if (strcmp (result, c[expected]) != 0)
88 fprintf (stderr, "\nFailure: %d/%d: %s\n", line, i, raw[5]);
89 fprintf (stderr, " g_utf8_normalize (%s, %s) != %s\n",
90 raw[i], names[mode], raw[expected]);
100 process_one (int line, gchar **columns)
104 gboolean skip = FALSE;
106 for (i=0; i < 5; i++)
108 c[i] = decode(columns[i]);
115 test_form (line, G_NORMALIZE_NFD, FALSE, 2, c, columns);
116 test_form (line, G_NORMALIZE_NFD, TRUE, 4, c, columns);
117 test_form (line, G_NORMALIZE_NFC, FALSE, 1, c, columns);
118 test_form (line, G_NORMALIZE_NFC, TRUE, 3, c, columns);
119 test_form (line, G_NORMALIZE_NFKD, TRUE, 4, c, columns);
120 test_form (line, G_NORMALIZE_NFKC, TRUE, 3, c, columns);
123 for (i=0; i < 5; i++)
129 int main (int argc, char **argv)
132 GError *error = NULL;
133 GString *buffer = g_string_new (NULL);
137 if (argc != 2 && argc != 3)
139 fprintf (stderr, "Usage: unicode-normalize NormalizationTest.txt LINE\n");
144 line_to_do = atoi(argv[2]);
146 in = g_io_channel_new_file (argv[1], "r", &error);
149 fprintf (stderr, "Cannot open %s: %s\n", argv[1], error->message);
158 if (g_io_channel_read_line_string (in, buffer, &term_pos, &error) != G_IO_STATUS_NORMAL)
161 if (line_to_do && line != line_to_do)
164 buffer->str[term_pos] = '\0';
166 if (buffer->str[0] == '#') /* Comment */
168 if (buffer->str[0] == '@') /* Part */
170 fprintf (stderr, "\nProcessing %s\n", buffer->str + 1);
174 columns = g_strsplit (buffer->str, ";", -1);
178 if (!process_one (line, columns))
180 g_strfreev (columns);
183 g_string_truncate (buffer, 0);
189 fprintf (stderr, "Error reading test file, %s\n", error->message);
193 g_io_channel_unref (in);
194 g_string_free (buffer, TRUE);