[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCHv2] tests: add program to detect locales
From: |
Paolo Bonzini |
Subject: |
[PATCHv2] tests: add program to detect locales |
Date: |
Mon, 29 Mar 2010 10:24:56 +0200 |
* tests/Makefile.am (check_PROGRAMS): Add get-mb-cur-max.
* tests/get-mb-cur-max.c: New.
* tests/euc-mb: Use it. Fail if the former detection test fails.
* tests/sjis-mb: Use it. Fail if the former detection test fails.
---
tests/Makefile.am | 3 +++
tests/euc-mb | 25 +++++++++++++++++--------
tests/get-mb-cur-max.c | 36 ++++++++++++++++++++++++++++++++++++
tests/sjis-mb | 15 +++++++++------
4 files changed, 65 insertions(+), 14 deletions(-)
create mode 100644 tests/get-mb-cur-max.c
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6920d21..81a10b5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -14,6 +14,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+check_PROGRAMS = get-mb-cur-max
+LDADD = ../lib/libgreputils.a $(LIBINTL) ../lib/libgreputils.a
+
TESTS = \
backref.sh \
backref-word \
diff --git a/tests/euc-mb b/tests/euc-mb
index becb032..590bd91 100644
--- a/tests/euc-mb
+++ b/tests/euc-mb
@@ -3,7 +3,9 @@
# too greedily.
# Derived from https://savannah.gnu.org/bugs/?23814
: ${srcdir=.}
-. "$srcdir/init.sh"; path_prepend_ ../src
+. "$srcdir/init.sh"; path_prepend_ . ../src
+
+locale=ja_JP.EUC-JP
make_input () {
echo "$1" | tr AB '\244\263'
@@ -11,14 +13,21 @@ make_input () {
euc_grep () {
pat=`make_input "$1"`
- LC_ALL=ja_JP.EUC-JP grep "$pat"
+ LC_ALL=$locale grep "$pat"
}
-if make_input BABA |euc_grep AB ; then
- skip_ 'EUC-JP locale seems not to work'
-fi
-make_input BABAAB |euc_grep AB || \
- fail_ 'whole line rejected after matching in the middle of a multibyte char'
+case `get-mb-cur-max $locale` in
+ 2|3) ;;
+ *) skip_ 'EUC-JP locale not found' ;;
+esac
+
+fail=0
+
+# Does EUC-JP work at all?
+make_input BABA |euc_grep AB && fail=1
+
+# Whole line rejected after matching in the middle of a multibyte char?
+make_input BABAAB |euc_grep AB || fail=1
-Exit 0
+Exit $fail
diff --git a/tests/get-mb-cur-max.c b/tests/get-mb-cur-max.c
new file mode 100644
index 0000000..f7384d5
--- /dev/null
+++ b/tests/get-mb-cur-max.c
@@ -0,0 +1,36 @@
+/* Auxiliary program to detect support for a locale.
+ Copyright 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, 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, write to the Free Software
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+ 02110-1301, USA. */
+
+#include <config.h>
+#include <locale.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+main(int argc, char **argv)
+{
+ set_program_name (argv[0]);
+ if (setlocale (LC_ALL, argv[1]))
+ {
+ printf ("%d\n", MB_CUR_MAX);
+ exit (EXIT_SUCCESS);
+ }
+
+ exit (EXIT_FAILURE);
+}
diff --git a/tests/sjis-mb b/tests/sjis-mb
index 4454ea1..82bc307 100644
--- a/tests/sjis-mb
+++ b/tests/sjis-mb
@@ -4,11 +4,13 @@
# character, and a suffix of a valid double-byte character
: ${srcdir=.}
-. "$srcdir/init.sh"; path_prepend_ ../src
+. "$srcdir/init.sh"; path_prepend_ . ../src
require_timeout_
-# % becomes a half-width katakana in SJIS, and an invalid sequence
+locale=ja_JP.SHIFT_JIS
+
+# % becomes an half-width katakana in SJIS, and an invalid sequence
# in UTF-8. Use this to try skipping implementations that do not
# support SJIS.
encode() { echo "$1" | tr @% '\203\301'; }
@@ -17,7 +19,7 @@ k=0
test_grep_reject() {
k=$(expr $k + 1)
encode "$2" | \
- LC_ALL=ja_JP.SHIFT_JIS \
+ LC_ALL=$locale \
timeout 10s grep $1 $(encode "$3") > out$k 2>&1
test $? = 1
}
@@ -25,13 +27,12 @@ test_grep_reject() {
test_grep() {
k=$(expr $k + 1)
encode "$2" > exp$k
- LC_ALL=ja_JP.SHIFT_JIS \
+ LC_ALL=$locale \
timeout 10s grep $1 $(encode "$3") exp$k > out$k 2>&1
test $? = 0 && compare out$k exp$k
}
-test_grep_reject -F @@ @ || skip_ 'system does not seem to know about SJIS'
-test_grep -F %%AA A || skip_ 'system seems to treat SJIS the same as UTF-8'
+test "$(get-mb-cur-max $locale)" = 2 || skip_ 'SJIS locale not found'
address@hidden
successful_tests='%%AA @AA @A@@A'
@@ -42,6 +43,8 @@ for i in $successful_tests; do
test_grep -E $i A || fail=1
done
+test_grep_reject -F @@ @
+test_grep_reject -E @@ @
for i in $failure_tests; do
test_grep_reject -F $i A || fail=1
test_grep_reject -E $i A || fail=1
--
1.6.6.1