Add Collation tests.

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().
This commit is contained in:
Matthias Clasen 2005-10-05 17:37:46 +00:00 committed by Matthias Clasen
parent 12e2c276b5
commit d433419b14
12 changed files with 172 additions and 17 deletions

View File

@ -1,3 +1,14 @@
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> 2005-10-01 Behdad Esfahbod <behdad@gnome.org>
* docs/reference/glib/tmpl/unicode.sgml: * docs/reference/glib/tmpl/unicode.sgml:

View File

@ -1,3 +1,14 @@
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> 2005-10-01 Behdad Esfahbod <behdad@gnome.org>
* docs/reference/glib/tmpl/unicode.sgml: * docs/reference/glib/tmpl/unicode.sgml:

View File

@ -1,3 +1,14 @@
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> 2005-10-01 Behdad Esfahbod <behdad@gnome.org>
* docs/reference/glib/tmpl/unicode.sgml: * docs/reference/glib/tmpl/unicode.sgml:

View File

@ -105,9 +105,9 @@ test_programs = \
utf8-validate \ utf8-validate \
uri-test 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) check_PROGRAMS = $(test_programs) $(test_script_support_programs)
@ -159,6 +159,7 @@ tree_test_LDADD = $(progs_ldadd)
type_test_LDADD = $(progs_ldadd) type_test_LDADD = $(progs_ldadd)
unicode_encoding_LDADD = $(progs_ldadd) unicode_encoding_LDADD = $(progs_ldadd)
unicode_caseconv_LDADD = $(progs_ldadd) unicode_caseconv_LDADD = $(progs_ldadd)
unicode_collate_LDADD = $(progs_ldadd)
utf8_validate_LDADD = $(progs_ldadd) utf8_validate_LDADD = $(progs_ldadd)
uri_test_LDADD = $(progs_ldadd) uri_test_LDADD = $(progs_ldadd)
@ -185,6 +186,10 @@ dist-hook: $(BUILT_EXTRA_DIST)
for f in $(srcdir)/markups/* ; do \ for f in $(srcdir)/markups/* ; do \
cp $$f $(distdir)/markups; \ cp $$f $(distdir)/markups; \
done done
mkdir $(distdir)/collate; \
for f in $(srcdir)/collate/* ; do \
cp $$f $(distdir)/collate; \
done
DISTCLEANFILES = iochannel-test-outfile \ DISTCLEANFILES = iochannel-test-outfile \
file-test-get-contents \ file-test-get-contents \

View File

@ -0,0 +1,9 @@
223
bar
baz
c
eer34
er1
foo
GTK+
z

View File

@ -0,0 +1,9 @@
z
c
eer34
223
er1
foo
bar
baz
GTK+

View File

@ -0,0 +1,9 @@
223
bar
baz
c
eer34
er1
foo
GTK+
z

View File

@ -0,0 +1,13 @@
bla001
bla02
bla03
bla4
bla10
bla100
event.c
event.h
eventgenerator.c
file.c
file.txt
file2.bla
file3.xx

View File

@ -0,0 +1,13 @@
file.txt
file2.bla
file.c
file3.xx
bla001
bla02
bla03
bla4
bla10
bla100
event.c
eventgenerator.c
event.h

View File

@ -0,0 +1,13 @@
bla001
bla02
bla03
bla10
bla100
bla4
event.c
eventgenerator.c
event.h
file2.bla
file3.xx
file.c
file.txt

38
tests/run-collate-tests.sh Executable file
View File

@ -0,0 +1,38 @@
#! /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."

View File

@ -36,19 +36,37 @@ int main (int argc, char **argv)
GError *error = NULL; GError *error = NULL;
GArray *line_array = g_array_new (FALSE, FALSE, sizeof(Line)); GArray *line_array = g_array_new (FALSE, FALSE, sizeof(Line));
guint i; 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; 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) 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; return 1;
} }
} }
@ -68,7 +86,10 @@ int main (int argc, char **argv)
str[term_pos] = '\0'; 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; line.str = str;
g_array_append_val (line_array, line); g_array_append_val (line_array, line);
@ -80,15 +101,7 @@ int main (int argc, char **argv)
return 1; return 1;
} }
printf ("== g_utf8_collate ==\n"); qsort (line_array->data, line_array->len, sizeof (Line), do_key ? compare_key : compare_collate);
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);
for (i = 0; i < line_array->len; i++) for (i = 0; i < line_array->len; i++)
printf ("%s\n", g_array_index (line_array, Line, i).str); printf ("%s\n", g_array_index (line_array, Line, i).str);