8 static gboolean missing_locale = FALSE;
13 const gchar **file_sorted;
22 clear_line (Line *line)
28 compare_collate (const void *a, const void *b)
30 const Line *line_a = a;
31 const Line *line_b = b;
33 return g_utf8_collate (line_a->str, line_b->str);
37 compare_key (const void *a, const void *b)
39 const Line *line_a = a;
40 const Line *line_b = b;
42 return strcmp (line_a->key, line_b->key);
46 do_collate (gboolean for_file, gboolean use_key, const CollateTest *test)
54 g_test_skip ("no en_US locale");
58 line_array = g_array_new (FALSE, FALSE, sizeof(Line));
59 g_array_set_clear_func (line_array, (GDestroyNotify)clear_line);
61 for (i = 0; test->input[i]; i++)
63 line.str = test->input[i];
65 line.key = g_utf8_collate_key_for_filename (line.str, -1);
67 line.key = g_utf8_collate_key (line.str, -1);
69 g_array_append_val (line_array, line);
72 qsort (line_array->data, line_array->len, sizeof (Line), use_key ? compare_key : compare_collate);
74 for (i = 0; test->input[i]; i++)
77 str = g_array_index (line_array, Line, i).str;
79 g_assert_cmpstr (str, ==, test->file_sorted[i]);
81 g_assert_cmpstr (str, ==, test->sorted[i]);
84 g_array_free (line_array, TRUE);
88 test_collate (gconstpointer d)
90 const CollateTest *test = d;
91 do_collate (FALSE, FALSE, test);
95 test_collate_key (gconstpointer d)
97 const CollateTest *test = d;
98 do_collate (FALSE, TRUE, test);
102 test_collate_file (gconstpointer d)
104 const CollateTest *test = d;
105 do_collate (TRUE, TRUE, test);
108 const gchar *input0[] = {
122 const gchar *sorted0[] = {
136 const gchar *file_sorted0[] = {
150 const gchar *input1[] = {
167 const gchar *sorted1[] = {
184 const gchar *file_sorted1[] = {
201 const gchar *input2[] = {
218 const gchar *sorted2[] = {
235 const gchar *file_sorted2[] = {
236 /* Filename collation in OS X follows Finder style which gives
237 * a slightly different order from usual Linux locales. */
271 main (int argc, char *argv[])
278 g_test_init (&argc, &argv, NULL);
280 g_setenv ("LC_ALL", "en_US", TRUE);
281 locale = setlocale (LC_ALL, "");
282 if (locale == NULL || strcmp (locale, "en_US") != 0)
284 g_test_message ("No suitable locale, skipping tests");
285 missing_locale = TRUE;
286 /* let the tests run to completion so they show up as SKIP'd in TAP
290 test[0].input = input0;
291 test[0].sorted = sorted0;
292 test[0].file_sorted = file_sorted0;
293 test[1].input = input1;
294 test[1].sorted = sorted1;
295 test[1].file_sorted = file_sorted1;
296 test[2].input = input2;
297 test[2].sorted = sorted2;
298 test[2].file_sorted = file_sorted2;
300 for (i = 0; i < G_N_ELEMENTS (test); i++)
302 path = g_strdup_printf ("/unicode/collate/%d", i);
303 g_test_add_data_func (path, &test[i], test_collate);
305 path = g_strdup_printf ("/unicode/collate-key/%d", i);
306 g_test_add_data_func (path, &test[i], test_collate_key);
308 path = g_strdup_printf ("/unicode/collate-filename/%d", i);
309 g_test_add_data_func (path, &test[i], test_collate_file);
313 return g_test_run ();