6 static gboolean missing_locale = FALSE;
11 const gchar **file_sorted;
20 clear_line (Line *line)
26 compare_collate (const void *a, const void *b)
28 const Line *line_a = a;
29 const Line *line_b = b;
31 return g_utf8_collate (line_a->str, line_b->str);
35 compare_key (const void *a, const void *b)
37 const Line *line_a = a;
38 const Line *line_b = b;
40 return strcmp (line_a->key, line_b->key);
44 do_collate (gboolean for_file, gboolean use_key, const CollateTest *test)
52 g_test_skip ("no en_US locale");
56 line_array = g_array_new (FALSE, FALSE, sizeof(Line));
57 g_array_set_clear_func (line_array, (GDestroyNotify)clear_line);
59 for (i = 0; test->input[i]; i++)
61 line.str = test->input[i];
63 line.key = g_utf8_collate_key_for_filename (line.str, -1);
65 line.key = g_utf8_collate_key (line.str, -1);
67 g_array_append_val (line_array, line);
70 qsort (line_array->data, line_array->len, sizeof (Line), use_key ? compare_key : compare_collate);
72 for (i = 0; test->input[i]; i++)
75 str = g_array_index (line_array, Line, i).str;
77 g_assert_cmpstr (str, ==, test->file_sorted[i]);
79 g_assert_cmpstr (str, ==, test->sorted[i]);
82 g_array_free (line_array, TRUE);
86 test_collate (gconstpointer d)
88 const CollateTest *test = d;
89 do_collate (FALSE, FALSE, test);
93 test_collate_key (gconstpointer d)
95 const CollateTest *test = d;
96 do_collate (FALSE, TRUE, test);
100 test_collate_file (gconstpointer d)
102 const CollateTest *test = d;
103 do_collate (TRUE, TRUE, test);
106 const gchar *input0[] = {
120 const gchar *sorted0[] = {
134 const gchar *file_sorted0[] = {
148 const gchar *input1[] = {
165 const gchar *sorted1[] = {
182 const gchar *file_sorted1[] = {
199 const gchar *input2[] = {
216 const gchar *sorted2[] = {
233 const gchar *file_sorted2[] = {
251 main (int argc, char *argv[])
258 g_test_init (&argc, &argv, NULL);
260 g_setenv ("LC_ALL", "en_US", TRUE);
261 locale = setlocale (LC_ALL, "");
262 if (locale == NULL || strcmp (locale, "en_US") != 0)
264 g_test_message ("No suitable locale, skipping tests");
265 missing_locale = TRUE;
266 /* let the tests run to completion so they show up as SKIP'd in TAP
270 test[0].input = input0;
271 test[0].sorted = sorted0;
272 test[0].file_sorted = file_sorted0;
273 test[1].input = input1;
274 test[1].sorted = sorted1;
275 test[1].file_sorted = file_sorted1;
276 test[2].input = input2;
277 test[2].sorted = sorted2;
278 test[2].file_sorted = file_sorted2;
280 for (i = 0; i < G_N_ELEMENTS (test); i++)
282 path = g_strdup_printf ("/unicode/collate/%d", i);
283 g_test_add_data_func (path, &test[i], test_collate);
285 path = g_strdup_printf ("/unicode/collate-key/%d", i);
286 g_test_add_data_func (path, &test[i], test_collate_key);
288 path = g_strdup_printf ("/unicode/collate-filename/%d", i);
289 g_test_add_data_func (path, &test[i], test_collate_file);
293 return g_test_run ();