9 const gchar **file_sorted;
18 clear_line (Line *line)
24 compare_collate (const void *a, const void *b)
26 const Line *line_a = a;
27 const Line *line_b = b;
29 return g_utf8_collate (line_a->str, line_b->str);
33 compare_key (const void *a, const void *b)
35 const Line *line_a = a;
36 const Line *line_b = b;
38 return strcmp (line_a->key, line_b->key);
42 do_collate (gboolean for_file, gboolean use_key, const CollateTest *test)
48 line_array = g_array_new (FALSE, FALSE, sizeof(Line));
49 g_array_set_clear_func (line_array, (GDestroyNotify)clear_line);
51 for (i = 0; test->input[i]; i++)
53 line.str = test->input[i];
55 line.key = g_utf8_collate_key_for_filename (line.str, -1);
57 line.key = g_utf8_collate_key (line.str, -1);
59 g_array_append_val (line_array, line);
62 qsort (line_array->data, line_array->len, sizeof (Line), use_key ? compare_key : compare_collate);
64 for (i = 0; test->input[i]; i++)
67 str = g_array_index (line_array, Line, i).str;
69 g_assert_cmpstr (str, ==, test->file_sorted[i]);
71 g_assert_cmpstr (str, ==, test->sorted[i]);
74 g_array_free (line_array, TRUE);
78 test_collate (gconstpointer d)
80 const CollateTest *test = d;
81 do_collate (FALSE, FALSE, test);
85 test_collate_key (gconstpointer d)
87 const CollateTest *test = d;
88 do_collate (FALSE, TRUE, test);
92 test_collate_file (gconstpointer d)
94 const CollateTest *test = d;
95 do_collate (TRUE, TRUE, test);
98 const gchar *input0[] = {
112 const gchar *sorted0[] = {
126 const gchar *file_sorted0[] = {
140 const gchar *input1[] = {
157 const gchar *sorted1[] = {
174 const gchar *file_sorted1[] = {
192 main (int argc, char *argv[])
199 g_test_init (&argc, &argv, NULL);
201 g_setenv ("LC_ALL", "en_US", TRUE);
202 locale = setlocale (LC_ALL, "");
203 if (locale == NULL || strcmp (locale, "en_US") != 0)
205 g_test_message ("No suitable locale, skipping test");
209 test[0].input = input0;
210 test[0].sorted = sorted0;
211 test[0].file_sorted = file_sorted0;
212 test[1].input = input1;
213 test[1].sorted = sorted1;
214 test[1].file_sorted = file_sorted1;
216 for (i = 0; i < G_N_ELEMENTS (test); i++)
218 path = g_strdup_printf ("/unicode/collate/%d", i);
219 g_test_add_data_func (path, &test[i], test_collate);
221 path = g_strdup_printf ("/unicode/collate-key/%d", i);
222 g_test_add_data_func (path, test, test_collate_key);
224 path = g_strdup_printf ("/unicode/collate-filename/%d", i);
225 g_test_add_data_func (path, test, test_collate_file);
229 return g_test_run ();