From 11a5f14838519ffd46707b750afbfffebcb3ab44 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 10 Mar 2007 00:24:51 +0000 Subject: [PATCH] Test for internationalization of module 'vasnprintf-posix'. --- ChangeLog | 6 +++ modules/vasnprintf-posix-tests | 12 ++++-- tests/test-vasnprintf-posix2.c | 70 +++++++++++++++++++++++++++++++++ tests/test-vasnprintf-posix2.sh | 22 +++++++++++ 4 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 tests/test-vasnprintf-posix2.c create mode 100755 tests/test-vasnprintf-posix2.sh diff --git a/ChangeLog b/ChangeLog index c305aa5cc4..2e783d6b90 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2007-03-09 Bruno Haible + * 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 '.'. diff --git a/modules/vasnprintf-posix-tests b/modules/vasnprintf-posix-tests index b54296bd77..4ca9e228ab 100644 --- a/modules/vasnprintf-posix-tests +++ b/modules/vasnprintf-posix-tests @@ -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 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 , 2007. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vasnprintf.h" + +#include +#include +#include + +#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} -- 2.30.2