Tests for module 'setlocale'.
authorBruno Haible <bruno@clisp.org>
Sat, 12 Feb 2011 15:46:11 +0000 (16:46 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 12 Feb 2011 16:06:20 +0000 (17:06 +0100)
* modules/setlocale-tests: New file.
* tests/test-setlocale1.sh: New file.
* tests/test-setlocale1.c: New file.

ChangeLog
modules/setlocale-tests [new file with mode: 0644]
tests/test-setlocale1.c [new file with mode: 0644]
tests/test-setlocale1.sh [new file with mode: 0755]

index 2752af1..b57fbdd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2011-02-11  Bruno Haible  <bruno@clisp.org>
 
+       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 (file)
index 0000000..e326fdc
--- /dev/null
@@ -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 (file)
index 0000000..ea7945c
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <locale.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (setlocale, char *, (int, const char *));
+
+#include <stdlib.h>
+#include <string.h>
+
+#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 (executable)
index 0000000..add4e92
--- /dev/null
@@ -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