7 const gchar **file_sorted;
16 compare_collate (const void *a, const void *b)
18 const Line *line_a = a;
19 const Line *line_b = b;
21 return g_utf8_collate (line_a->str, line_b->str);
25 compare_key (const void *a, const void *b)
27 const Line *line_a = a;
28 const Line *line_b = b;
30 return strcmp (line_a->key, line_b->key);
34 do_collate (gboolean for_file, gboolean use_key, const CollateTest *test)
36 GArray *line_array = g_array_new (FALSE, FALSE, sizeof(Line));
40 for (i = 0; test->input[i]; i++)
42 line.str = test->input[i];
44 line.key = g_utf8_collate_key_for_filename (line.str, -1);
46 line.key = g_utf8_collate_key (line.str, -1);
48 g_array_append_val (line_array, line);
51 qsort (line_array->data, line_array->len, sizeof (Line), use_key ? compare_key : compare_collate);
53 for (i = 0; test->input[i]; i++)
56 str = g_array_index (line_array, Line, i).str;
58 g_assert_cmpstr (str, ==, test->file_sorted[i]);
60 g_assert_cmpstr (str, ==, test->sorted[i]);
65 test_collate (gconstpointer d)
67 const CollateTest *test = d;
68 do_collate (FALSE, FALSE, test);
72 test_collate_key (gconstpointer d)
74 const CollateTest *test = d;
75 do_collate (FALSE, TRUE, test);
79 test_collate_file (gconstpointer d)
81 const CollateTest *test = d;
82 do_collate (TRUE, TRUE, test);
85 const gchar *input0[] = {
98 const gchar *sorted0[] = {
111 const gchar *file_sorted0[] = {
124 const gchar *input1[] = {
141 const gchar *sorted1[] = {
158 const gchar *file_sorted1[] = {
176 main (int argc, char *argv[])
183 g_test_init (&argc, &argv, NULL);
185 g_setenv ("LC_ALL", "en_US", TRUE);
186 locale = setlocale (LC_ALL, "");
187 if (locale == NULL || strcmp (locale, "en_US") != 0)
189 g_test_message ("No suitable locale, skipping test");
193 test[0].input = input0;
194 test[0].sorted = sorted0;
195 test[0].file_sorted = file_sorted0;
196 test[1].input = input1;
197 test[1].sorted = sorted1;
198 test[1].file_sorted = file_sorted1;
200 for (i = 0; i < G_N_ELEMENTS (test); i++)
202 path = g_strdup_printf ("/unicode/collate/%d", i);
203 g_test_add_data_func (path, &test[i], test_collate);
205 path = g_strdup_printf ("/unicode/collate-key/%d", i);
206 g_test_add_data_func (path, test, test_collate_key);
208 path = g_strdup_printf ("/unicode/collate-filename/%d", i);
209 g_test_add_data_func (path, test, test_collate_file);
213 return g_test_run ();