Update contrib.
1 /* Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.*/
2 #undef G_DISABLE_ASSERT
11 #include "mrt2_glib2_test.h"
14 gboolean success = TRUE;
16 static char *decode (const gchar *input)
20 GString *result = g_string_new (NULL);
24 if (sscanf (input + offset, "%x", &ch) != 1)
26 g_print("Error parsing character string %s\n", input);
28 g_assert(FALSE && "unicode-normalize failed");
31 testResultXml("unicode-normalize");
37 g_string_append_unichar (result, ch);
39 while (input[offset] && input[offset] != ' ')
41 while (input[offset] && input[offset] == ' ')
44 while (input[offset]);
45 return g_string_free (result, FALSE);
48 const char *names[4] = {
65 gboolean mode_is_compat = (mode == G_NORMALIZE_NFKC ||
66 mode == G_NORMALIZE_NFKD);
68 if (mode_is_compat || !do_compat)
70 for (i = 0; i < 3; i++)
72 char *result = g_utf8_normalize (c[i], -1, mode);
73 if (strcmp (result, c[expected]) != 0)
75 g_print("\nFailure: %d/%d: %s\n", line, i + 1, raw[5]);
76 g_print(" g_utf8_normalize (%s, %s) != %s\n",
77 raw[i], names[mode], raw[expected]);
84 if (mode_is_compat || do_compat)
86 for (i = 3; i < 5; i++)
88 char *result = g_utf8_normalize (c[i], -1, mode);
89 if (strcmp (result, c[expected]) != 0)
91 g_print("\nFailure: %d/%d: %s\n", line, i, raw[5]);
92 g_print(" g_utf8_normalize (%s, %s) != %s\n",
93 raw[i], names[mode], raw[expected]);
103 process_one (int line, gchar **columns)
107 gboolean skip = FALSE;
109 for (i=0; i < 5; i++)
111 c[i] = decode(columns[i]);
118 test_form (line, G_NORMALIZE_NFD, FALSE, 2, c, columns);
119 test_form (line, G_NORMALIZE_NFD, TRUE, 4, c, columns);
120 test_form (line, G_NORMALIZE_NFC, FALSE, 1, c, columns);
121 test_form (line, G_NORMALIZE_NFC, TRUE, 3, c, columns);
122 test_form (line, G_NORMALIZE_NFKD, TRUE, 4, c, columns);
123 test_form (line, G_NORMALIZE_NFKC, TRUE, 3, c, columns);
126 for (i=0; i < 5; i++)
132 int main (int argc, char **argv)
135 GError *error = NULL;
139 gchar *srcdir = getenv ("srcdir");
143 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);
144 g_set_print_handler(mrtPrintHandler);
147 buffer = g_string_new (NULL);
149 /*if (argc != 2 && argc != 3)
151 g_print("Usage: unicode-normalize NormalizationTest.txt LINE\n");
156 line_to_do = atoi(argv[2]);
162 testfile = g_strconcat (srcdir, G_DIR_SEPARATOR_S "NormalizationTest.txt", NULL);
164 in = g_io_channel_new_file (testfile, "r", &error);
167 g_print("Cannot open %s: %s\n", testfile, error->message);
168 g_assert(FALSE && "unicode-normalize failed");
171 testResultXml("unicode-normalize");
172 #endif /* EMULATOR */
182 if (g_io_channel_read_line_string (in, buffer, &term_pos, &error) != G_IO_STATUS_NORMAL)
185 //if (line_to_do && line != line_to_do)
188 buffer->str[term_pos] = '\0';
190 if (buffer->str[0] == '#') /* Comment */
192 if (buffer->str[0] == '@') /* Part */
194 //g_print("\nProcessing %s\n",buffer->str + 1);
198 columns = g_strsplit (buffer->str, ";", -1);
202 if (!process_one (line, columns))
204 g_strfreev (columns);
207 g_string_truncate (buffer, 0);
213 g_print("Error reading test file, %s\n", error->message);
215 g_assert(FALSE && "unicode-normalize failed");
218 testResultXml("unicode-normalize");
219 #endif /* EMULATOR */
224 g_io_channel_unref (in);
225 g_string_free (buffer, TRUE);
228 assert_failed = !success;
229 testResultXml("unicode-normalize");
230 #endif /* EMULATOR */