Add Collation tests.
authorMatthias Clasen <mclasen@redhat.com>
Wed, 5 Oct 2005 17:37:46 +0000 (17:37 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Wed, 5 Oct 2005 17:37:46 +0000 (17:37 +0000)
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().

12 files changed:
ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
tests/Makefile.am
tests/collate/collate-1.file [new file with mode: 0644]
tests/collate/collate-1.in [new file with mode: 0644]
tests/collate/collate-1.unicode [new file with mode: 0644]
tests/collate/collate-2.file [new file with mode: 0644]
tests/collate/collate-2.in [new file with mode: 0644]
tests/collate/collate-2.unicode [new file with mode: 0644]
tests/run-collate-tests.sh [new file with mode: 0755]
tests/unicode-collate.c

index b468626b95637db731d763e7464ed2ef964e46d5..f20033ed6349105497f87e05fa17527e85a30201 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
 
        * docs/reference/glib/tmpl/unicode.sgml:
index b468626b95637db731d763e7464ed2ef964e46d5..f20033ed6349105497f87e05fa17527e85a30201 100644 (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>
 
        * docs/reference/glib/tmpl/unicode.sgml:
index b468626b95637db731d763e7464ed2ef964e46d5..f20033ed6349105497f87e05fa17527e85a30201 100644 (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>
 
        * docs/reference/glib/tmpl/unicode.sgml:
index 61f62e40372cfaaece217f364e79664597aa4574..a5336e45878bc83b32d2e53cd48700a01ac1cea6 100644 (file)
@@ -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 (file)
index 0000000..c8e41e9
--- /dev/null
@@ -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 (file)
index 0000000..1fc8977
--- /dev/null
@@ -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 (file)
index 0000000..c8e41e9
--- /dev/null
@@ -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 (file)
index 0000000..2a5a4da
--- /dev/null
@@ -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 (file)
index 0000000..be294ca
--- /dev/null
@@ -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 (file)
index 0000000..3546853
--- /dev/null
@@ -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 (executable)
index 0000000..7f57828
--- /dev/null
@@ -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."
index 33b055143a4c586c145ced04bf8cbc8eb766fa3e..009b00fa0ee0ab07b6a623ff44ea23e728c69a3f 100644 (file)
@@ -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);