pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/2] i18n: Add simple tests.


From: John Darrington
Subject: Re: [PATCH 1/2] i18n: Add simple tests.
Date: Thu, 23 Sep 2010 13:06:44 +0000
User-agent: Mutt/1.5.18 (2008-05-17)

Looks like a good start to me.

On Tue, Sep 21, 2010 at 10:19:38PM -0700, Ben Pfaff wrote:
     ---
      src/libpspp/i18n.c        |   36 ++++++++++++++++------------------
      tests/atlocal.in          |    1 +
      tests/automake.mk         |    7 +++++-
      tests/libpspp/i18n-test.c |   46 
+++++++++++++++++++++++++++++++++++++++++++++
      tests/libpspp/i18n.at     |   44 
+++++++++++++++++++++++++++++++++++++++++++
      5 files changed, 114 insertions(+), 20 deletions(-)
      create mode 100644 tests/libpspp/i18n-test.c
      create mode 100644 tests/libpspp/i18n.at
     
     diff --git a/src/libpspp/i18n.c b/src/libpspp/i18n.c
     index 60dc693..6cb721a 100644
     --- a/src/libpspp/i18n.c
     +++ b/src/libpspp/i18n.c
     @@ -15,31 +15,29 @@
         along with this program.  If not, see <http://www.gnu.org/licenses/>. 
*/
      
      #include <config.h>
     -#include <xalloc.h>
     +
     +#include "libpspp/i18n.h"
     +
      #include <assert.h>
     +#include <errno.h>
     +#include <iconv.h>
     +#include <langinfo.h>
     +#include <libintl.h>
      #include <locale.h>
     -#include <stdlib.h>
      #include <stdio.h>
     +#include <stdlib.h>
      #include <string.h>
     -#include <libintl.h>
     -#include <iconv.h>
     -#include <errno.h>
     -#include <relocatable.h>
     -#include "assertion.h"
     -#include "hmapx.h"
     -#include "hash-functions.h"
     -#include "pool.h"
     -
     -#include "i18n.h"
      
     -#include "version.h"
     +#include "libpspp/assertion.h"
     +#include "libpspp/hmapx.h"
     +#include "libpspp/hash-functions.h"
     +#include "libpspp/pool.h"
     +#include "libpspp/version.h"
      
     -#include <localcharset.h>
     -#include "xstrndup.h"
     -
     -#if HAVE_NL_LANGINFO
     -#include <langinfo.h>
     -#endif
     +#include "gl/localcharset.h"
     +#include "gl/xalloc.h"
     +#include "gl/relocatable.h"
     +#include "gl/xstrndup.h"
      
      struct converter
       {
     diff --git a/tests/atlocal.in b/tests/atlocal.in
     index ecfd2d7..cd61f44 100644
     --- a/tests/atlocal.in
     +++ b/tests/atlocal.in
     @@ -3,3 +3,4 @@ PERL='@PERL@'
      CHARSETALIASDIR="$abs_top_builddir/gl"
      export CHARSETALIASDIR
      WITH_PERL_MODULE='@WITH_PERL_MODULE@'
     +host='@host@'
     diff --git a/tests/automake.mk b/tests/automake.mk
     index f64a669..a27e4d3 100644
     --- a/tests/automake.mk
     +++ b/tests/automake.mk
     @@ -169,6 +169,7 @@ check_PROGRAMS += \
        $(nodist_TESTS) \
        tests/data/datasheet-test \
        tests/formats/inexactify \
     +  tests/libpspp/i18n-test \
        tests/libpspp/sparse-xarray-test \
        tests/output/render-test
      
     @@ -219,6 +220,9 @@ tests_libpspp_hmapx_test_SOURCES = \
      tests_libpspp_hmapx_test_LDADD = gl/libgl.la $(LIBINTL)
      tests_libpspp_hmapx_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10
      
     +tests_libpspp_i18n_test_SOURCES = tests/libpspp/i18n-test.c
     +tests_libpspp_i18n_test_LDADD = src/libpspp/libpspp.la gl/libgl.la 
$(LIBINTL) 
     +
      tests_libpspp_abt_test_SOURCES = \
        src/libpspp/abt.c \
        src/libpspp/abt.h \
     @@ -434,6 +438,7 @@ TESTSUITE_AT = \
        tests/language/xforms/compute.at \
        tests/language/xforms/count.at \
        tests/language/xforms/recode.at \
     +  tests/libpspp/i18n.at \
        tests/math/moments.at \
        tests/output/render.at \
        tests/output/charts.at \
     @@ -451,7 +456,7 @@ $(srcdir)/tests/testsuite.at: tests/testsuite.in 
Makefile
      
      CHECK_LOCAL += tests_check
      tests_check: tests/atconfig tests/atlocal $(TESTSUITE)
     -  $(SHELL) '$(TESTSUITE)' -C tests 
AUTOTEST_PATH=tests/output:src/ui/terminal $(TESTSUITEFLAGS)
     +  $(SHELL) '$(TESTSUITE)' -C tests 
AUTOTEST_PATH=tests/libpspp:tests/output:src/ui/terminal $(TESTSUITEFLAGS)
      
      CLEAN_LOCAL += tests_clean
      tests_clean:
     diff --git a/tests/libpspp/i18n-test.c b/tests/libpspp/i18n-test.c
     new file mode 100644
     index 0000000..f2bead9
     --- /dev/null
     +++ b/tests/libpspp/i18n-test.c
     @@ -0,0 +1,46 @@
     +/* PSPP - a program for statistical analysis.
     +   Copyright (C) 2010 Free Software Foundation, Inc.
     +
     +   This program is free software: you can redistribute it and/or modify
     +   it under the terms of the GNU General Public License as published by
     +   the Free Software Foundation, either version 3 of the License, or
     +   (at your option) any later version.
     +
     +   This program is distributed in the hope that it will be useful,
     +   but WITHOUT ANY WARRANTY; without even the implied warranty of
     +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     +   GNU General Public License for more details.
     +
     +   You should have received a copy of the GNU General Public License
     +   along with this program.  If not, see <http://www.gnu.org/licenses/>. 
*/
     +
     +#include <config.h>
     +
     +#include <stdio.h>
     +#include <stdlib.h>
     +
     +#include "libpspp/i18n.h"
     +
     +int
     +main (int argc, char *argv[])
     +{
     +  char *s;
     +
     +  if (argc != 4)
     +    {
     +      fprintf (stderr,
     +               "usage: %s FROM TO STRING\n"
     +               "where FROM is the source encoding,\n"
     +               "      TO is the target encoding,\n"
     +               "      and STRING is the text to recode.\n",
     +               argv[0]);
     +      return EXIT_FAILURE;
     +    }
     +
     +  i18n_init ();
     +  s = recode_string (argv[2], argv[1], argv[3], -1);
     +  puts (s);
     +  free (s);
     +
     +  return 0;
     +}
     diff --git a/tests/libpspp/i18n.at b/tests/libpspp/i18n.at
     new file mode 100644
     index 0000000..c845519
     --- /dev/null
     +++ b/tests/libpspp/i18n.at
     @@ -0,0 +1,44 @@
     +AT_BANNER([i18n routines])
     +
     +# CHECK_I18N([TITLE], [FROM-CODING], [TO-CODING], [FROM-TEXT], [TO-TEXT])
     +#
     +# Converts FROM-TEXT from FROM-CODING to TO-CODING and checks that the 
result
     +# is TO-TEXT.  The "printf" program is applied to both FROM-TEXT and 
TO-TEXT
     +# to allow for backslash-escapes.  (Be aware that hex escapes are not 
portable;
     +# use octal escapes instead.)
     +m4_define([CHECK_I18N],
     +  [AT_SETUP([convert $1])
     +   AT_KEYWORDS([i18n])
     +
     +   dnl Skip the test if this host doesn't know the source and target 
encodings.
     +   AT_CHECK(
     +     [case "$host" in
     +        *-*-linux* | *-*-*-gnu*)
     +          dnl GNU/Linux always has the encodings we want.  We can't ask
     +    dnl config.charset about them because it has a special case here
     +    dnl too and won't tell us.
     +    ;;
     +  *)
     +          $SHELL $top_srcdir/gl/config.charset "$host" | grep '$2' || 
exit 77
     +          $SHELL $top_srcdir/gl/config.charset "$host" | grep '$3' || 
exit 77
     +          ;;
     +      esac
     +     ], [0], [ignore])
     +   AT_CHECK_UNQUOTED([i18n-test '$2' '$3' `printf '$4'`], [0], [`printf 
'$5'`
     +])
     +   AT_CLEANUP])
     +     
     +CHECK_I18N([reflexively], [ASCII], [ASCII], [abc], [abc])
     +CHECK_I18N([without any change], [ASCII], [UTF-8], [abc], [abc])
     +
     +CHECK_I18N([from ISO-8859-1 to UTF-8], [ISO-8859-1], [UTF-8],
     +           [\242], [\302\242])
     +CHECK_I18N([from UTF-8 to ISO-8859-1], [UTF-8], [ISO-8859-1],
     +           [\302\242], [\242])
     +
     +# 0xc0 == 0300 is invalid in UTF-8
     +CHECK_I18N([invalid UTF-8 to ISO-8859-1], [UTF-8], [ISO-8859-1],
     +           [xy\300z], [xy?z])
     +# 0xc2 == 0302 is the first byte of a 2-byte UTF-8 sequence
     +CHECK_I18N([truncated UTF-8 to ISO-8559-1], [UTF-8], [ISO-8859-1],
     +           [xy\302], [xy?])
     -- 
     1.7.1
     
     
     _______________________________________________
     pspp-dev mailing list
     address@hidden
     http://lists.gnu.org/mailman/listinfo/pspp-dev

-- 
PGP Public key ID: 1024D/2DE827B3 
fingerprint = 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3
See http://pgp.mit.edu or any PGP keyserver for public key.


Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]