+2005-10-05 Matthias Clasen <mclasen@redhat.com>
+
+ * Makefile.am: Add Collation tests.
+
+ * tests/collate/*: Inputs and expected outputs for collation tests.
+
+ * tests/run-collate-tests.sh: Script to run collation tests.
+
+ * tests/unicode-collate.c (main): Rework slightly to make
+ it usable in unit tests. Also test g_utf8_collate_key_for_filename().
+
2005-10-01 Behdad Esfahbod <behdad@gnome.org>
* docs/reference/glib/tmpl/unicode.sgml:
+2005-10-05 Matthias Clasen <mclasen@redhat.com>
+
+ * Makefile.am: Add Collation tests.
+
+ * tests/collate/*: Inputs and expected outputs for collation tests.
+
+ * tests/run-collate-tests.sh: Script to run collation tests.
+
+ * tests/unicode-collate.c (main): Rework slightly to make
+ it usable in unit tests. Also test g_utf8_collate_key_for_filename().
+
2005-10-01 Behdad Esfahbod <behdad@gnome.org>
* docs/reference/glib/tmpl/unicode.sgml:
+2005-10-05 Matthias Clasen <mclasen@redhat.com>
+
+ * Makefile.am: Add Collation tests.
+
+ * tests/collate/*: Inputs and expected outputs for collation tests.
+
+ * tests/run-collate-tests.sh: Script to run collation tests.
+
+ * tests/unicode-collate.c (main): Rework slightly to make
+ it usable in unit tests. Also test g_utf8_collate_key_for_filename().
+
2005-10-01 Behdad Esfahbod <behdad@gnome.org>
* docs/reference/glib/tmpl/unicode.sgml:
utf8-validate \
uri-test
-test_scripts = run-markup-tests.sh
+test_scripts = run-markup-tests.sh run-collate-tests.sh
-test_script_support_programs = markup-test
+test_script_support_programs = markup-test unicode-collate
check_PROGRAMS = $(test_programs) $(test_script_support_programs)
type_test_LDADD = $(progs_ldadd)
unicode_encoding_LDADD = $(progs_ldadd)
unicode_caseconv_LDADD = $(progs_ldadd)
+unicode_collate_LDADD = $(progs_ldadd)
utf8_validate_LDADD = $(progs_ldadd)
uri_test_LDADD = $(progs_ldadd)
for f in $(srcdir)/markups/* ; do \
cp $$f $(distdir)/markups; \
done
+ mkdir $(distdir)/collate; \
+ for f in $(srcdir)/collate/* ; do \
+ cp $$f $(distdir)/collate; \
+ done
DISTCLEANFILES = iochannel-test-outfile \
file-test-get-contents \
--- /dev/null
+223
+bar
+baz
+c
+eer34
+er1
+foo
+GTK+
+z
--- /dev/null
+z
+c
+eer34
+223
+er1
+foo
+bar
+baz
+GTK+
--- /dev/null
+223
+bar
+baz
+c
+eer34
+er1
+foo
+GTK+
+z
--- /dev/null
+bla001
+bla02
+bla03
+bla4
+bla10
+bla100
+event.c
+event.h
+eventgenerator.c
+file.c
+file.txt
+file2.bla
+file3.xx
--- /dev/null
+file.txt
+file2.bla
+file.c
+file3.xx
+bla001
+bla02
+bla03
+bla4
+bla10
+bla100
+event.c
+eventgenerator.c
+event.h
--- /dev/null
+bla001
+bla02
+bla03
+bla10
+bla100
+bla4
+event.c
+eventgenerator.c
+event.h
+file2.bla
+file3.xx
+file.c
+file.txt
--- /dev/null
+#! /bin/sh
+
+fail ()
+{
+ echo "Test failed: $*"
+ exit 1
+}
+
+echo_v ()
+{
+ if [ "$verbose" = "1" ]; then
+ echo "$*"
+ fi
+}
+
+error_out=/dev/null
+if [ "$1" = "-v" ]; then
+ verbose=1
+ error_out=/dev/stderr
+fi
+for I in ${srcdir:-.}/collate/*.in; do
+ echo_v "Sorting $I"
+ name=`basename $I .in`
+ ./unicode-collate $I > collate.out
+ if ! diff collate.out ${srcdir:-.}/collate/$name.unicode; then
+ fail "unexpected error when using g_utf8_collate() on $I"
+ fi
+ ./unicode-collate --key $I > collate.out
+ if ! diff collate.out ${srcdir:-.}/collate/$name.unicode; then
+ fail "unexpected error when using g_utf8_collate_key() on $I"
+ fi
+ ./unicode-collate --file $I > collate.out
+ if ! diff collate.out ${srcdir:-.}/collate/$name.file; then
+ fail "unexpected error when using g_utf8_collate_key_for_filename() on $I"
+ fi
+done
+
+echo_v "All tests passed."
GError *error = NULL;
GArray *line_array = g_array_new (FALSE, FALSE, sizeof(Line));
guint i;
+ gboolean do_key = FALSE;
+ gboolean do_file = FALSE;
- if (argc != 1 && argc != 2)
+ if (argc != 1 && argc != 2 && argc != 3)
{
- fprintf (stderr, "Usage: unicode-collate [FILE]\n");
+ fprintf (stderr, "Usage: unicode-collate [--key|--file] [FILE]\n");
return 1;
}
- if (argc == 2)
+ i = 1;
+ if (argc > 1)
{
- in = g_io_channel_new_file (argv[1], "r", &error);
+ if (strcmp (argv[1], "--key") == 0)
+ {
+ do_key = TRUE;
+ i = 2;
+ }
+ else if (strcmp (argv[1], "--file") == 0)
+ {
+ do_key = TRUE;
+ do_file = TRUE;
+ i = 2;
+ }
+ }
+
+ if (argc > i)
+ {
+ in = g_io_channel_new_file (argv[i], "r", &error);
if (!in)
{
- fprintf (stderr, "Cannot open %s: %s\n", argv[1], error->message);
+ fprintf (stderr, "Cannot open %s: %s\n", argv[i], error->message);
return 1;
}
}
str[term_pos] = '\0';
- line.key = g_utf8_collate_key (str, -1);
+ if (do_file)
+ line.key = g_utf8_collate_key_for_filename (str, -1);
+ else
+ line.key = g_utf8_collate_key (str, -1);
line.str = str;
g_array_append_val (line_array, line);
return 1;
}
- printf ("== g_utf8_collate ==\n");
-
- qsort (line_array->data, line_array->len, sizeof (Line), compare_collate);
- for (i = 0; i < line_array->len; i++)
- printf ("%s\n", g_array_index (line_array, Line, i).str);
-
- printf ("== g_utf8_collate_key ==\n");
-
- qsort (line_array->data, line_array->len, sizeof (Line), compare_key);
+ qsort (line_array->data, line_array->len, sizeof (Line), do_key ? compare_key : compare_collate);
for (i = 0; i < line_array->len; i++)
printf ("%s\n", g_array_index (line_array, Line, i).str);