summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2007-03-10 00:24:51 +0000
committerBruno Haible <bruno@clisp.org>2007-03-10 00:24:51 +0000
commit11a5f14838519ffd46707b750afbfffebcb3ab44 (patch)
treecff0bcd59f8998ed6db68ead91a1b71dd7f7ad95 /tests
parent794283a4bb176e313b3a7a7fc5d320e37881a0be (diff)
downloadgnulib-11a5f14838519ffd46707b750afbfffebcb3ab44.tar.gz
Test for internationalization of module 'vasnprintf-posix'.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-vasnprintf-posix2.c70
-rwxr-xr-xtests/test-vasnprintf-posix2.sh22
2 files changed, 92 insertions, 0 deletions
diff --git a/tests/test-vasnprintf-posix2.c b/tests/test-vasnprintf-posix2.c
new file mode 100644
index 0000000000..da66492833
--- /dev/null
+++ b/tests/test-vasnprintf-posix2.c
@@ -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
index 0000000000..5ee5b4751c
--- /dev/null
+++ b/tests/test-vasnprintf-posix2.sh
@@ -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}