From 085dfff1c41d6ee305f00aa7177286ca8965efbc Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 11 Feb 2012 10:16:25 -0800 Subject: [PATCH] tests: Improve test for supported encodings. I misunderstood the purpose for the config.charset script. I had a notion that it was supposed to print all of the character sets that are supported by the operating system. It doesn't (it prints character set names that need translation for the operating system). This change switches to using the same code that will be used at PSPP runtime to determine whether an encoding is supported, for determining during the tests whether an encoding is supported. This should cause fewer tests to be skipped on Mac OS. Reported-by: Jeremy Lavergne --- tests/data/sys-file.at | 2 +- tests/language/data-io/data-reader.at | 6 +++--- tests/libpspp/encoding-guesser.at | 16 ++++++++-------- tests/libpspp/i18n-test.c | 22 ++++++++++++++++++++-- tests/libpspp/i18n.at | 22 ++-------------------- tests/libpspp/u8-istream.at | 16 ++++++++-------- 6 files changed, 42 insertions(+), 42 deletions(-) diff --git a/tests/data/sys-file.at b/tests/data/sys-file.at index 5975e0f3b7..85ccfd8b49 100644 --- a/tests/data/sys-file.at +++ b/tests/data/sys-file.at @@ -384,7 +384,7 @@ dnl This test writes non-ASCII characters to most of the string fields in dnl a .sav file and demonstrates that they are properly read back in. dnl XXX mrsets tests are missing. AT_SETUP([system file character encoding]) -AT_CHECK([supports_encodings windows-1252]) +AT_CHECK([i18n-test supports_encodings windows-1252]) AT_DATA([save.sps], [dnl SET LOCALE='windows-1252'. DATA LIST LIST NOTABLE /àéîöçxyzabc * roué (A9) croûton (A1000). diff --git a/tests/language/data-io/data-reader.at b/tests/language/data-io/data-reader.at index a6a5f360ae..b9e7607595 100644 --- a/tests/language/data-io/data-reader.at +++ b/tests/language/data-io/data-reader.at @@ -206,14 +206,14 @@ DATA_READER_BINARY([MODE=360 /RECFORM=FIXED /LRECL=32], length ($out) == 32 or die; print +a2e ($out); }], - [AT_CHECK([supports_encodings EBCDIC-US])]) + [AT_CHECK([i18n-test supports_encodings EBCDIC-US])]) DATA_READER_BINARY([MODE=360 /RECFORM=VARIABLE], [for $_ (@data) { push (@records, pack ("n xx", length ($_) + 4) . a2e ($_)); } dump_records ();], - [AT_CHECK([supports_encodings EBCDIC-US])]) + [AT_CHECK([i18n-test supports_encodings EBCDIC-US])]) DATA_READER_BINARY([MODE=360 /RECFORM=SPANNED], [[for my $line (@data) { @@ -233,4 +233,4 @@ DATA_READER_BINARY([MODE=360 /RECFORM=SPANNED], } } dump_records ();]], - [AT_CHECK([supports_encodings EBCDIC-US])]) + [AT_CHECK([i18n-test supports_encodings EBCDIC-US])]) diff --git a/tests/libpspp/encoding-guesser.at b/tests/libpspp/encoding-guesser.at index d63dc37e79..a2b0aabd9d 100644 --- a/tests/libpspp/encoding-guesser.at +++ b/tests/libpspp/encoding-guesser.at @@ -8,14 +8,14 @@ AT_CLEANUP AT_SETUP([UTF-8]) AT_KEYWORDS([encoding guesser]) -AT_CHECK([supports_encodings ISO-8859-1]) +AT_CHECK([i18n-test supports_encodings ISO-8859-1]) AT_CHECK([printf '\346\227\245\346\234\254\350\252\236\n' | encoding-guesser-test Auto,ISO-8859-1], [0], [UTF-8 ]) AT_CLEANUP AT_SETUP([UTF-8 starting with ASCII]) AT_KEYWORDS([encoding guesser]) -AT_CHECK([supports_encodings ISO-8859-1]) +AT_CHECK([i18n-test supports_encodings ISO-8859-1]) AT_CHECK([printf 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\346\227\245\346\234\254\350\252\236\n' | encoding-guesser-test Auto,ISO-8859-1 32], [0], [UTF-8 ]) AT_CLEANUP @@ -96,7 +96,7 @@ AT_CLEANUP AT_SETUP([ISO-8859-1]) AT_KEYWORDS([encoding guesser]) -AT_CHECK([supports_encodings ISO-8859-1]) +AT_CHECK([i18n-test supports_encodings ISO-8859-1]) AT_CHECK([printf 'entr\351e\n' | encoding-guesser-test Auto,ISO-8859-1], [0], [ISO-8859-1 ]) @@ -104,7 +104,7 @@ AT_CLEANUP AT_SETUP([GB-18030 with byte order mark]) AT_KEYWORDS([encoding guesser]) -AT_CHECK([supports_encodings ISO-8859-1]) +AT_CHECK([i18n-test supports_encodings ISO-8859-1]) AT_CHECK([printf '\204\061\225\063' | encoding-guesser-test Auto,ISO-8859-1], [0], [GB-18030 ]) @@ -112,7 +112,7 @@ AT_CLEANUP AT_SETUP([UTF-EBCDIC with byte order mark]) AT_KEYWORDS([encoding guesser]) -AT_CHECK([supports_encodings ISO-8859-1]) +AT_CHECK([i18n-test supports_encodings ISO-8859-1]) AT_CHECK([printf '\335\163\146\163' | encoding-guesser-test Auto,ISO-8859-1], [0], [UTF-EBCDIC ]) @@ -120,7 +120,7 @@ AT_CLEANUP AT_SETUP([EUC-JP as Auto,EUC-JP]) AT_KEYWORDS([encoding guesser]) -AT_CHECK([supports_encodings EUC-JP]) +AT_CHECK([i18n-test supports_encodings EUC-JP]) AT_CHECK([printf '\244\241 \244\242 \244\243 \244\244 \244\245 \244\246 \244\247 \244\250 \244\251 \244\252\n' | encoding-guesser-test Auto,EUC-JP], [0], [EUC-JP ]) @@ -128,7 +128,7 @@ AT_CLEANUP AT_SETUP([EUC-JP starting with ASCII as Auto,EUC-JP]) AT_KEYWORDS([encoding guesser]) -AT_CHECK([supports_encodings EUC-JP]) +AT_CHECK([i18n-test supports_encodings EUC-JP]) AT_CHECK([printf 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \244\241 \244\242 \244\243 \244\244 \244\245 \244\246 \244\247 \244\250 \244\251 \244\252\n' | encoding-guesser-test Auto,EUC-JP 32], [0], [EUC-JP ]) @@ -136,7 +136,7 @@ AT_CLEANUP AT_SETUP([UTF-8 with character split across input buffers]) AT_KEYWORDS([encoding guesser]) -AT_CHECK([supports_encodings ISO-8859-1]) +AT_CHECK([i18n-test supports_encodings ISO-8859-1]) AT_CHECK([printf '\343\201\201\343\201\202\343\201\203\343\201\204\343\201\205\343\201\206\343\201\207\343\201\210\343\201\211\343\201\212\343\201\201\343\201\202\343\201\203\343\201\204\343\201\205\343\201\206\343\201\207\343\201\210\343\201\211\343\201\212\n' | encoding-guesser-test Auto,ISO-8859-1 32], [0], [UTF-8 ]) diff --git a/tests/libpspp/i18n-test.c b/tests/libpspp/i18n-test.c index b433756b0d..b0d027090e 100644 --- a/tests/libpspp/i18n-test.c +++ b/tests/libpspp/i18n-test.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 2010, 2011, 2012 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 @@ -30,6 +30,20 @@ main (int argc, char *argv[]) { i18n_init (); + if (argc > 1 && !strcmp (argv[1], "supports_encodings")) + { + int status = 0; + int i; + + for (i = 2; i < argc; i++) + if (!is_encoding_supported (argv[i])) + { + printf ("encoding \"%s\" is NOT supported\n", argv[i]); + status = 77; + } + i18n_done (); + exit (status); + } if (argc == 5 && !strcmp (argv[1], "recode")) { const char *from = argv[2]; @@ -68,6 +82,10 @@ main (int argc, char *argv[]) else { fprintf (stderr, "\ +usage: %s supports_encodings ENCODING...\n\ +where ENCODING is the name of an encoding.\n\ +Exits with status 0 if all the encodings are supported, 77 otherwise.\n\ +\n\ usage: %s recode FROM TO STRING\n\ where FROM is the source encoding,\n\ TO is the target encoding,\n\ @@ -78,7 +96,7 @@ where HEAD is the first string to concatenate\n\ TAIL is the second string to concatenate\n\ ENCODING is the encoding in which to measure the result's length\n\ MAX_LEN is the maximum length of the result in ENCODING.\n", - argv[0], argv[0]); + argv[0], argv[0], argv[0]); return EXIT_FAILURE; } diff --git a/tests/libpspp/i18n.at b/tests/libpspp/i18n.at index 421241e5db..5f4bb65961 100644 --- a/tests/libpspp/i18n.at +++ b/tests/libpspp/i18n.at @@ -1,23 +1,5 @@ AT_BANNER([i18n recoding]) -m4_divert_push([PREPARE_TESTS]) -supports_encodings () { - 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. - return 0 - ;; - *) - for encoding in "$@"; do - $SHELL $top_srcdir/gl/config.charset "$host" | grep '$2' || return 77 - done - ;; - esac -} -m4_divert_pop([PREPARE_TESTS]) - # CHECK_I18N_RECODE([TITLE], [FROM-CODING], [TO-CODING], # [FROM-TEXT], [TO-TEXT]) # @@ -30,7 +12,7 @@ m4_define([CHECK_I18N_RECODE], AT_KEYWORDS([i18n]) dnl Skip the test if this host doesn't know the source and target encodings. - AT_CHECK([supports_encodings '$2' '$3']) + AT_CHECK([i18n-test supports_encodings '$2' '$3']) AT_CHECK_UNQUOTED([i18n-test recode '$2' '$3' `printf '$4'`], [0], [`printf '$5'` ]) AT_CLEANUP]) @@ -80,7 +62,7 @@ m4_define([CHECK_I18N_CONCAT], AT_KEYWORDS([i18n]) dnl Skip the test if this host doesn't know the encoding. - AT_CHECK([supports_encodings '$3']) + AT_CHECK([i18n-test supports_encodings '$3']) AT_CHECK_UNQUOTED( [i18n-test concat "`printf '$1'`" "`printf '$2'`" '$3' '$4'], [0], [`printf '$5'` diff --git a/tests/libpspp/u8-istream.at b/tests/libpspp/u8-istream.at index 2d8baa4745..985805d7ee 100644 --- a/tests/libpspp/u8-istream.at +++ b/tests/libpspp/u8-istream.at @@ -2,7 +2,7 @@ AT_BANNER([u8_istream]) AT_SETUP([read ASCII]) AT_KEYWORDS([u8_istream]) -AT_CHECK([supports_encodings ASCII]) +AT_CHECK([i18n-test supports_encodings ASCII]) AT_CHECK([echo string | u8-istream-test read - ASCII], [0], [string ]) AT_CLEANUP @@ -18,7 +18,7 @@ AT_CLEANUP AT_SETUP([read EUC-JP]) AT_KEYWORDS([u8_istream]) -AT_CHECK([supports_encodings EUC-JP]) +AT_CHECK([i18n-test supports_encodings EUC-JP]) AT_CHECK([printf '\244\241 \244\242 \244\243 \244\244 \244\245 \244\246 \244\247 \244\250 \244\251 \244\252\n' | u8-istream-test read - EUC-JP], [0], [ぁ あ ぃ い ぅ う ぇ え ぉ お @@ -58,7 +58,7 @@ AT_CLEANUP AT_SETUP([read EUC-JP with character split across input buffers]) AT_KEYWORDS([u8_istream]) -AT_CHECK([supports_encodings EUC-JP]) +AT_CHECK([i18n-test supports_encodings EUC-JP]) buffer_size=`u8-istream-test buffer-size` ($PERL -e "print 'x' x ($buffer_size - 16)" printf '\244\241 \244\242 \244\243 \244\244 \244\245 \244\246 \244\247 ' @@ -72,7 +72,7 @@ AT_CLEANUP AT_SETUP([read EUC-JP with character split across output buffers]) AT_KEYWORDS([u8_istream]) -AT_CHECK([supports_encodings EUC-JP]) +AT_CHECK([i18n-test supports_encodings EUC-JP]) AT_CHECK([printf '\244\241\244\242\244\243\244\244\244\245\244\246\244\247\244\250\244\251\244\252\n' | u8-istream-test read - EUC-JP 16], [0], [ぁあぃいぅうぇえぉお @@ -81,7 +81,7 @@ AT_CLEANUP AT_SETUP([read EUC-JP with character split across input and output buffers]) AT_KEYWORDS([u8_istream]) -AT_CHECK([supports_encodings EUC-JP]) +AT_CHECK([i18n-test supports_encodings EUC-JP]) buffer_size=`u8-istream-test buffer-size` ($PERL -e "print 'x' x ($buffer_size - 16)" printf 'xyz\244\241\244\242\244\243\244\244\244\245\244\246\244\247\244\250' @@ -113,7 +113,7 @@ AT_CLEANUP AT_SETUP([read ISO-8859-1 as Auto,ISO-8859-1]) AT_KEYWORDS([u8_istream]) -AT_CHECK([supports_encodings ISO-8859-1]) +AT_CHECK([i18n-test supports_encodings ISO-8859-1]) buffer_size=`u8-istream-test buffer-size` ($PERL -e "print 'x' x int($buffer_size * 2.5)"; printf 'entr\351e\n') > input (echo "Auto mode" @@ -125,7 +125,7 @@ AT_CLEANUP dnl UTF-16BE is not ASCII compatible so this doesn't start out in Auto mode. AT_SETUP([read UTF-16BE as Auto,UTF-16BE]) AT_KEYWORDS([u8_istream]) -AT_CHECK([supports_encodings UTF-16BE]) +AT_CHECK([i18n-test supports_encodings UTF-16BE]) AT_CHECK([printf '\0e\0n\0t\0r\0\351\0e\0\n' | u8-istream-test read - Auto,UTF-16BE], [0], [dnl entrée @@ -134,7 +134,7 @@ AT_CLEANUP AT_SETUP([read EUC-JP as Auto,EUC-JP]) AT_KEYWORDS([u8_istream]) -AT_CHECK([supports_encodings EUC-JP]) +AT_CHECK([i18n-test supports_encodings EUC-JP]) AT_CHECK([printf 'entr\217\253\261e\n' | u8-istream-test read - Auto,EUC-JP], [0], [entrée ]) -- 2.30.2