From 097885d0981547e184259079a820b9f66c7f6924 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 12 Feb 2011 16:46:11 +0100 Subject: [PATCH] Tests for module 'setlocale'. * modules/setlocale-tests: New file. * tests/test-setlocale1.sh: New file. * tests/test-setlocale1.c: New file. --- ChangeLog | 5 ++++ modules/setlocale-tests | 27 ++++++++++++++++++++++ tests/test-setlocale1.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/test-setlocale1.sh | 34 ++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 modules/setlocale-tests create mode 100644 tests/test-setlocale1.c create mode 100755 tests/test-setlocale1.sh diff --git a/ChangeLog b/ChangeLog index 2752af1e6..b57fbddc3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2011-02-11 Bruno Haible + Tests for module 'setlocale'. + * modules/setlocale-tests: New file. + * tests/test-setlocale1.sh: New file. + * tests/test-setlocale1.c: New file. + New module 'setlocale'. * lib/locale.in.h (setlocale): New declaration. * lib/setlocale.c: New file, based on diff --git a/modules/setlocale-tests b/modules/setlocale-tests new file mode 100644 index 000000000..e326fdcc5 --- /dev/null +++ b/modules/setlocale-tests @@ -0,0 +1,27 @@ +Files: +tests/test-setlocale1.sh +tests/test-setlocale1.c +tests/signature.h +tests/macros.h +m4/locale-fr.m4 +m4/locale-ja.m4 +m4/locale-zh.m4 +m4/codeset.m4 + +Depends-on: +strdup + +configure.ac: +gt_LOCALE_FR +gt_LOCALE_FR_UTF8 +gt_LOCALE_JA +gt_LOCALE_ZH_CN + +Makefile.am: +TESTS += test-setlocale1.sh +TESTS_ENVIRONMENT += \ + LOCALE_FR='@LOCALE_FR@' \ + LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' \ + LOCALE_JA='@LOCALE_JA@' \ + LOCALE_ZH_CN='@LOCALE_ZH_CN@' +check_PROGRAMS += test-setlocale1 diff --git a/tests/test-setlocale1.c b/tests/test-setlocale1.c new file mode 100644 index 000000000..ea7945c77 --- /dev/null +++ b/tests/test-setlocale1.c @@ -0,0 +1,59 @@ +/* Test of setting the current locale. + Copyright (C) 2011 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 . */ + +#include + +#include + +#include "signature.h" +SIGNATURE_CHECK (setlocale, char *, (int, const char *)); + +#include +#include + +#include "macros.h" + +int +main (int argc, char *argv[]) +{ + char *name1; + char *name2; + + /* Try to set the locale by implicitly looking at the LC_ALL environment + variable. + configure should already have checked that the locale is supported. */ + if (setlocale (LC_ALL, "") == NULL) + return 1; + + name1 = strdup (setlocale (LC_ALL, NULL)); + + /* Reset the locale. */ + if (setlocale (LC_ALL, "C") == NULL) + return 1; + + /* Try to set the locale by explicitly looking at the LC_ALL environment + variable. + configure should already have checked that the locale is supported. */ + if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL) + return 1; + + name2 = strdup (setlocale (LC_ALL, NULL)); + + /* Test that the two results are the same. */ + ASSERT (strcmp (name1, name2) == 0); + + return 0; +} diff --git a/tests/test-setlocale1.sh b/tests/test-setlocale1.sh new file mode 100755 index 000000000..add4e922b --- /dev/null +++ b/tests/test-setlocale1.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +: ${LOCALE_FR=fr_FR} +: ${LOCALE_FR_UTF8=fr_FR.UTF-8} +: ${LOCALE_JA=ja_JP} +: ${LOCALE_ZH_CN=zh_CN.GB18030} + +if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none \ + && test $LOCALE_JA = none && test $LOCALE_ZH_CN = none; then + if test -f /usr/bin/localedef; then + echo "Skipping test: no locale for testing is installed" + else + echo "Skipping test: no locale for testing is supported" + fi + exit 77 +fi + +if test $LOCALE_FR != none; then + LC_ALL=$LOCALE_FR ./test-setlocale1${EXEEXT} 1 || exit 1 +fi + +if test $LOCALE_FR_UTF8 != none; then + LC_ALL=$LOCALE_FR_UTF8 ./test-setlocale1${EXEEXT} 1 || exit 1 +fi + +if test $LOCALE_JA != none; then + LC_ALL=$LOCALE_JA ./test-setlocale1${EXEEXT} 1 || exit 1 +fi + +if test $LOCALE_ZH_CN != none; then + LC_ALL=$LOCALE_ZH_CN ./test-setlocale1${EXEEXT} 1 || exit 1 +fi + +exit 0 -- 2.11.0