9 const gchar **file_sorted;
18 compare_collate (const void *a, const void *b)
20 const Line *line_a = a;
21 const Line *line_b = b;
23 return g_utf8_collate (line_a->str, line_b->str);
27 compare_key (const void *a, const void *b)
29 const Line *line_a = a;
30 const Line *line_b = b;
32 return strcmp (line_a->key, line_b->key);
36 do_collate (gboolean for_file, gboolean use_key, const CollateTest *test)
38 GArray *line_array = g_array_new (FALSE, FALSE, sizeof(Line));
42 for (i = 0; test->input[i]; i++)
44 line.str = test->input[i];
46 line.key = g_utf8_collate_key_for_filename (line.str, -1);
48 line.key = g_utf8_collate_key (line.str, -1);
50 g_array_append_val (line_array, line);
53 qsort (line_array->data, line_array->len, sizeof (Line), use_key ? compare_key : compare_collate);
55 for (i = 0; test->input[i]; i++)
58 str = g_array_index (line_array, Line, i).str;
60 g_assert_cmpstr (str, ==, test->file_sorted[i]);
62 g_assert_cmpstr (str, ==, test->sorted[i]);
67 test_collate (gconstpointer d)
69 const CollateTest *test = d;
70 do_collate (FALSE, FALSE, test);
74 test_collate_key (gconstpointer d)
76 const CollateTest *test = d;
77 do_collate (FALSE, TRUE, test);
81 test_collate_file (gconstpointer d)
83 const CollateTest *test = d;
84 do_collate (TRUE, TRUE, test);
87 const gchar *input0[] = {
100 const gchar *sorted0[] = {
113 const gchar *file_sorted0[] = {
126 const gchar *input1[] = {
143 const gchar *sorted1[] = {
160 const gchar *file_sorted1[] = {
178 main (int argc, char *argv[])
185 g_test_init (&argc, &argv, NULL);
187 g_setenv ("LC_ALL", "en_US", TRUE);
188 locale = setlocale (LC_ALL, "");
189 if (locale == NULL || strcmp (locale, "en_US") != 0)
191 g_test_message ("No suitable locale, skipping test");
195 test[0].input = input0;
196 test[0].sorted = sorted0;
197 test[0].file_sorted = file_sorted0;
198 test[1].input = input1;
199 test[1].sorted = sorted1;
200 test[1].file_sorted = file_sorted1;
202 for (i = 0; i < G_N_ELEMENTS (test); i++)
204 path = g_strdup_printf ("/unicode/collate/%d", i);
205 g_test_add_data_func (path, &test[i], test_collate);
207 path = g_strdup_printf ("/unicode/collate-key/%d", i);
208 g_test_add_data_func (path, test, test_collate_key);
210 path = g_strdup_printf ("/unicode/collate-filename/%d", i);
211 g_test_add_data_func (path, test, test_collate_file);
215 return g_test_run ();