Test for internationalization of module 'vasnprintf-posix'.
authorBruno Haible <bruno@clisp.org>
Sat, 10 Mar 2007 00:24:51 +0000 (00:24 +0000)
committerBruno Haible <bruno@clisp.org>
Sat, 10 Mar 2007 00:24:51 +0000 (00:24 +0000)
ChangeLog
modules/vasnprintf-posix-tests
tests/test-vasnprintf-posix2.c [new file with mode: 0644]
tests/test-vasnprintf-posix2.sh [new file with mode: 0755]

index c305aa5cc431ae11b0ad2e9f35707957d2f1add2..2e783d6b90b1c1a837aabcd879003b3f24929bb1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2007-03-09  Bruno Haible  <bruno@clisp.org>
 
+       * tests/test-vasnprintf-posix2.sh: New file.
+       * tests/test-vasnprintf-posix2.c: New file.
+       * modules/vasnprintf-posix-tests (Files): Add them and m4/locale-fr.m4.
+       (configure.ac): Invoke gt_LOCALE_FR and gt_LOCALE_FR_UTF8.
+       (Makefile.am): Activate test-vasnprintf-posix2.sh.
+
        * lib/vasnprintf.c (VASNPRINTF): For the 'a' and 'A' directives, use
        a locale dependent decimal point, rather than always '.'.
 
index b54296bd77f64415ef123e719e2e7106656d4957..4ca9e228aba9db2e42db7c7eb04a09ae18a0f43b 100644 (file)
@@ -1,14 +1,20 @@
 Files:
 tests/test-vasnprintf-posix.c
+tests/test-vasnprintf-posix2.sh
+tests/test-vasnprintf-posix2.c
 m4/longdouble.m4
+m4/locale-fr.m4
 
 Depends-on:
 stdint
 
 configure.ac:
 AC_REQUIRE([gt_TYPE_LONGDOUBLE])
+gt_LOCALE_FR
+gt_LOCALE_FR_UTF8
 
 Makefile.am:
-TESTS += test-vasnprintf-posix
-check_PROGRAMS += test-vasnprintf-posix
-
+TESTS += test-vasnprintf-posix test-vasnprintf-posix2.sh
+TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' LOCALE_FR='@LOCALE_FR@' LOCALE_FR_UTF8='@LOCALE_FR_UTF8@'
+check_PROGRAMS += test-vasnprintf-posix test-vasnprintf-posix2
+EXTRA_DIST += test-vasnprintf-posix2.sh
diff --git a/tests/test-vasnprintf-posix2.c b/tests/test-vasnprintf-posix2.c
new file mode 100644 (file)
index 0000000..da66492
--- /dev/null
@@ -0,0 +1,70 @@
+/* Test of POSIX compatible vasnprintf() and asnprintf() functions.
+   Copyright (C) 2007 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 2, 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.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "vasnprintf.h"
+
+#include <locale.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define ASSERT(expr) if (!(expr)) abort ();
+
+int
+main (int argc, char *argv[])
+{
+  /* configure should already have checked that the locale is supported.  */
+  if (setlocale (LC_ALL, "") == NULL)
+    return 1;
+
+  /* Test that a locale dependent decimal point is used.  */
+  {
+    size_t length;
+    char *result = asnprintf (NULL, &length, "%.1a", 1.0);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "0x1,0p+0") == 0
+           || strcmp (result, "0x2,0p-1") == 0
+           || strcmp (result, "0x4,0p-2") == 0
+           || strcmp (result, "0x8,0p-3") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
+#if HAVE_LONG_DOUBLE
+
+  /* Test that a locale dependent decimal point is used.  */
+  {
+    size_t length;
+    char *result = asnprintf (NULL, &length, "%.1La", 1.0L);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "0x1,0p+0") == 0
+           || strcmp (result, "0x2,0p-1") == 0
+           || strcmp (result, "0x4,0p-2") == 0
+           || strcmp (result, "0x8,0p-3") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
+#endif
+
+  return 0;
+}
diff --git a/tests/test-vasnprintf-posix2.sh b/tests/test-vasnprintf-posix2.sh
new file mode 100755 (executable)
index 0000000..5ee5b47
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+# Test whether a french locale is installed.
+: ${LOCALE_FR=fr_FR}
+: ${LOCALE_FR_UTF8=fr_FR.UTF-8}
+if test $LOCALE_FR != none; then
+  testlocale=$LOCALE_FR
+else
+  if test $LOCALE_FR_UTF8 != none; then
+    testlocale=$LOCALE_FR_UTF8
+  else
+    if test -f /usr/bin/localedef; then
+      echo "Skipping test: no french locale is installed"
+    else
+      echo "Skipping test: no french locale is supported"
+    fi
+    exit 77
+  fi
+fi
+
+LC_ALL=$testlocale \
+./test-vasnprintf-posix2${EXEEXT}