summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2005-10-05 17:37:46 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2005-10-05 17:37:46 +0000
commitd433419b14cb71cbdb0f23d375af9ec596e21d5c (patch)
tree1e6e93412bb7ed0aaf9f477cd6e0b39bf5c0384a /tests
parent12e2c276b53538532398a4f53f60a317979123c5 (diff)
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().
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am9
-rw-r--r--tests/collate/collate-1.file9
-rw-r--r--tests/collate/collate-1.in9
-rw-r--r--tests/collate/collate-1.unicode9
-rw-r--r--tests/collate/collate-2.file13
-rw-r--r--tests/collate/collate-2.in13
-rw-r--r--tests/collate/collate-2.unicode13
-rwxr-xr-xtests/run-collate-tests.sh38
-rw-r--r--tests/unicode-collate.c43
9 files changed, 139 insertions, 17 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 61f62e403..a5336e458 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -105,9 +105,9 @@ test_programs = \
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)
@@ -159,6 +159,7 @@ tree_test_LDADD = $(progs_ldadd)
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)
@@ -185,6 +186,10 @@ dist-hook: $(BUILT_EXTRA_DIST)
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 \
diff --git a/tests/collate/collate-1.file b/tests/collate/collate-1.file
new file mode 100644
index 000000000..c8e41e991
--- /dev/null
+++ b/tests/collate/collate-1.file
@@ -0,0 +1,9 @@
+223
+bar
+baz
+c
+eer34
+er1
+foo
+GTK+
+z
diff --git a/tests/collate/collate-1.in b/tests/collate/collate-1.in
new file mode 100644
index 000000000..1fc897788
--- /dev/null
+++ b/tests/collate/collate-1.in
@@ -0,0 +1,9 @@
+z
+c
+eer34
+223
+er1
+foo
+bar
+baz
+GTK+
diff --git a/tests/collate/collate-1.unicode b/tests/collate/collate-1.unicode
new file mode 100644
index 000000000..c8e41e991
--- /dev/null
+++ b/tests/collate/collate-1.unicode
@@ -0,0 +1,9 @@
+223
+bar
+baz
+c
+eer34
+er1
+foo
+GTK+
+z
diff --git a/tests/collate/collate-2.file b/tests/collate/collate-2.file
new file mode 100644
index 000000000..2a5a4daff
--- /dev/null
+++ b/tests/collate/collate-2.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
diff --git a/tests/collate/collate-2.in b/tests/collate/collate-2.in
new file mode 100644
index 000000000..be294ca34
--- /dev/null
+++ b/tests/collate/collate-2.in
@@ -0,0 +1,13 @@
+file.txt
+file2.bla
+file.c
+file3.xx
+bla001
+bla02
+bla03
+bla4
+bla10
+bla100
+event.c
+eventgenerator.c
+event.h
diff --git a/tests/collate/collate-2.unicode b/tests/collate/collate-2.unicode
new file mode 100644
index 000000000..354685311
--- /dev/null
+++ b/tests/collate/collate-2.unicode
@@ -0,0 +1,13 @@
+bla001
+bla02
+bla03
+bla10
+bla100
+bla4
+event.c
+eventgenerator.c
+event.h
+file2.bla
+file3.xx
+file.c
+file.txt
diff --git a/tests/run-collate-tests.sh b/tests/run-collate-tests.sh
new file mode 100755
index 000000000..7f578286d
--- /dev/null
+++ b/tests/run-collate-tests.sh
@@ -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."
diff --git a/tests/unicode-collate.c b/tests/unicode-collate.c
index 33b055143..009b00fa0 100644
--- a/tests/unicode-collate.c
+++ b/tests/unicode-collate.c
@@ -36,19 +36,37 @@ int main (int argc, char **argv)
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;
}
}
@@ -68,7 +86,10 @@ int main (int argc, char **argv)
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);
@@ -80,15 +101,7 @@ int main (int argc, char **argv)
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);