diff options
author | Ben Pfaff <blp@cs.stanford.edu> | 2012-12-18 21:06:17 -0800 |
---|---|---|
committer | Ben Pfaff <blp@cs.stanford.edu> | 2012-12-18 21:06:17 -0800 |
commit | f022473fdaf724d84817c4003120b9a38fbf884b (patch) | |
tree | ce0393a3f1d55164c03f313da53a211d677195d1 /tests | |
parent | 37e3ad9a8077636cea173c1494c744e383962255 (diff) | |
download | gnulib-f022473fdaf724d84817c4003120b9a38fbf884b.tar.gz |
New 'c-*printf' modules for formatted output in C locale.
New module 'c-vasnprintf'.
* modules/c-vasnprintf: New file.
* lib/c-vasnprintf.c: New file.
* lib/c-vasnprintf.h: New file.
New module 'c-snprintf'.
* modules/c-snprintf: New file.
* modules/c-snprintf-tests: New file.
* lib/c-snprintf.c: New file.
* lib/c-snprintf.h: New file.
* tests/test-c-snprintf.c: New file.
* tests/test-c-snprintf.sh: New file.
New module 'c-vsnprintf'.
* modules/c-vsnprintf: New file.
* modules/c-vsnprintf-tests: New file.
* lib/c-vsnprintf.c: New file.
* lib/c-vsnprintf.h: New file.
* tests/test-c-vsnprintf.c: New file.
* tests/test-c-vsnprintf.sh: New file.
New module 'c-vasprintf'.
* modules/c-vasprintf: New file.
* modules/c-vasprintf-tests: New file.
* lib/c-asprintf.c: New file.
* lib/c-vasprintf.c: New file.
* lib/c-vasprintf.h: New file.
* tests/test-c-vasprintf.c +: New file.
* tests/test-c-vasprintf.sh: New file.
New module 'c-xvasprintf'.
* modules/c-xvasprintf: New file.
* modules/c-xvasprintf-tests: New file.
* lib/c-xasprintf.c: New file.
* lib/c-xvasprintf.c: New file.
* lib/c-xvasprintf.h: New file.
* tests/test-c-xvasprintf.c: New file.
* tests/test-c-xvasprintf.sh: New file.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-c-snprintf.c | 58 | ||||
-rwxr-xr-x | tests/test-c-snprintf.sh | 15 | ||||
-rw-r--r-- | tests/test-c-vasprintf.c | 80 | ||||
-rwxr-xr-x | tests/test-c-vasprintf.sh | 15 | ||||
-rw-r--r-- | tests/test-c-vsnprintf.c | 73 | ||||
-rwxr-xr-x | tests/test-c-vsnprintf.sh | 15 | ||||
-rw-r--r-- | tests/test-c-xvasprintf.c | 78 | ||||
-rwxr-xr-x | tests/test-c-xvasprintf.sh | 15 |
8 files changed, 349 insertions, 0 deletions
diff --git a/tests/test-c-snprintf.c b/tests/test-c-snprintf.c new file mode 100644 index 0000000000..d178b3f01b --- /dev/null +++ b/tests/test-c-snprintf.c @@ -0,0 +1,58 @@ +/* Test of c_snprintf() function. + Copyright (C) 2011-2012 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 "c-snprintf.h" + +#include <locale.h> +#include <stdio.h> +#include <string.h> + +#include "macros.h" + +int +main (int argc, char *argv[]) +{ + /* configure should already have checked that the locale is supported. */ + if (setlocale (LC_ALL, "") == NULL) + return 1; + + /* Test behaviour of snprintf() as a "control group". + (We should be running in a locale where ',' is the decimal point.) */ + { + char s[16]; + + snprintf (s, sizeof s, "%#.0f", 1.0); + if (!strcmp (s, "1.")) + { + /* Skip the test, since we're not in a useful locale for testing. */ + return 77; + } + ASSERT (!strcmp (s, "1,")); + } + + /* Test behaviour of c_snprintf(). + It should always use '.' as the decimal point. */ + { + char s[16]; + + c_snprintf (s, sizeof s, "%#.0f", 1.0); + ASSERT (!strcmp (s, "1.")); + } + + return 0; +} diff --git a/tests/test-c-snprintf.sh b/tests/test-c-snprintf.sh new file mode 100755 index 0000000000..83051fc5d0 --- /dev/null +++ b/tests/test-c-snprintf.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# Test in an ISO-8859-1 or ISO-8859-15 locale. +: ${LOCALE_FR=fr_FR} +if test $LOCALE_FR = none; then + if test -f /usr/bin/localedef; then + echo "Skipping test: no traditional french locale is installed" + else + echo "Skipping test: no traditional french locale is supported" + fi + exit 77 +fi + +LC_ALL=$LOCALE_FR \ +./test-c-snprintf${EXEEXT} 1 diff --git a/tests/test-c-vasprintf.c b/tests/test-c-vasprintf.c new file mode 100644 index 0000000000..00e7df42b7 --- /dev/null +++ b/tests/test-c-vasprintf.c @@ -0,0 +1,80 @@ +/* Test of c_asprintf() and c_vasprintf() functions. + Copyright (C) 2011-2012 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 "c-vasprintf.h" + +#include <locale.h> +#include <stdio.h> +#include <string.h> + +#include "macros.h" + +static int +my_c_asprintf (char **result, const char *format, ...) +{ + va_list args; + int ret; + + va_start (args, format); + ret = c_vasprintf (result, format, args); + va_end (args); + return ret; +} + +int +main (int argc, char *argv[]) +{ + /* configure should already have checked that the locale is supported. */ + if (setlocale (LC_ALL, "") == NULL) + return 1; + + /* Test behaviour of snprintf() as a "control group". + (We should be running in a locale where ',' is the decimal point.) */ + { + char s[16]; + + snprintf (s, sizeof s, "%#.0f", 1.0); + if (!strcmp (s, "1.")) + { + /* Skip the test, since we're not in a useful locale for testing. */ + return 77; + } + ASSERT (!strcmp (s, "1,")); + } + + /* Test behaviour of c_asprintf() and c_vasprintf(). + They should always use '.' as the decimal point. */ + { + int retval; + char *s; + + retval = c_asprintf (&s, "%#.0f", 1.0); + ASSERT (s != NULL); + ASSERT (!strcmp (s, "1.")); + ASSERT (retval == 2); + free (s); + + retval = my_c_asprintf (&s, "%#.0f", 1.0); + ASSERT (s != NULL); + ASSERT (!strcmp (s, "1.")); + ASSERT (retval == 2); + free (s); + } + + return 0; +} diff --git a/tests/test-c-vasprintf.sh b/tests/test-c-vasprintf.sh new file mode 100755 index 0000000000..525c0ef538 --- /dev/null +++ b/tests/test-c-vasprintf.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# Test in an ISO-8859-1 or ISO-8859-15 locale. +: ${LOCALE_FR=fr_FR} +if test $LOCALE_FR = none; then + if test -f /usr/bin/localedef; then + echo "Skipping test: no traditional french locale is installed" + else + echo "Skipping test: no traditional french locale is supported" + fi + exit 77 +fi + +LC_ALL=$LOCALE_FR \ +./test-c-vasprintf${EXEEXT} 1 diff --git a/tests/test-c-vsnprintf.c b/tests/test-c-vsnprintf.c new file mode 100644 index 0000000000..d504c2e2a0 --- /dev/null +++ b/tests/test-c-vsnprintf.c @@ -0,0 +1,73 @@ +/* Test of c_vsnprintf() function. + Copyright (C) 2011-2012 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 "c-vsnprintf.h" + +#include <locale.h> +#include <stdarg.h> +#include <stdio.h> +#include <string.h> + +#include "macros.h" + +#include <string.h> + +static int +my_c_snprintf (char *buf, int size, const char *format, ...) +{ + va_list args; + int ret; + + va_start (args, format); + ret = c_vsnprintf (buf, size, format, args); + va_end (args); + return ret; +} + +int +main (int argc, char *argv[]) +{ + /* configure should already have checked that the locale is supported. */ + if (setlocale (LC_ALL, "") == NULL) + return 1; + + /* Test behaviour of snprintf() as a "control group". + (We should be running in a locale where ',' is the decimal point.) */ + { + char s[16]; + + snprintf (s, sizeof s, "%#.0f", 1.0); + if (!strcmp (s, "1.")) + { + /* Skip the test, since we're not in a useful locale for testing. */ + return 77; + } + ASSERT (!strcmp (s, "1,")); + } + + /* Test behaviour of c_vsnprintf(). + It should always use '.' as the decimal point. */ + { + char s[16]; + + my_c_snprintf (s, sizeof s, "%#.0f", 1.0); + ASSERT (!strcmp (s, "1.")); + } + + return 0; +} diff --git a/tests/test-c-vsnprintf.sh b/tests/test-c-vsnprintf.sh new file mode 100755 index 0000000000..b173a382a7 --- /dev/null +++ b/tests/test-c-vsnprintf.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# Test in an ISO-8859-1 or ISO-8859-15 locale. +: ${LOCALE_FR=fr_FR} +if test $LOCALE_FR = none; then + if test -f /usr/bin/localedef; then + echo "Skipping test: no traditional french locale is installed" + else + echo "Skipping test: no traditional french locale is supported" + fi + exit 77 +fi + +LC_ALL=$LOCALE_FR \ +./test-c-vsnprintf${EXEEXT} 1 diff --git a/tests/test-c-xvasprintf.c b/tests/test-c-xvasprintf.c new file mode 100644 index 0000000000..a5c5268161 --- /dev/null +++ b/tests/test-c-xvasprintf.c @@ -0,0 +1,78 @@ +/* Test of c_xasprintf() and c_xvasprintf() functions. + Copyright (C) 2011-2012 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 "c-xvasprintf.h" + +#include <locale.h> +#include <stdio.h> +#include <string.h> + +#include "macros.h" + +static char * +my_c_xasprintf (const char *format, ...) +{ + va_list args; + char *s; + + va_start (args, format); + s = c_xvasprintf (format, args); + va_end (args); + + return s; +} + +int +main (int argc, char *argv[]) +{ + /* configure should already have checked that the locale is supported. */ + if (setlocale (LC_ALL, "") == NULL) + return 1; + + /* Test behaviour of snprintf() as a "control group". + (We should be running in a locale where ',' is the decimal point.) */ + { + char s[16]; + + snprintf (s, sizeof s, "%#.0f", 1.0); + if (!strcmp (s, "1.")) + { + /* Skip the test, since we're not in a useful locale for testing. */ + return 77; + } + ASSERT (!strcmp (s, "1,")); + } + + /* Test behaviour of c_xasprintf() and c_xvasprintf(). + They should always use '.' as the decimal point. */ + { + char *s; + + s = c_xasprintf ("%#.0f", 1.0); + ASSERT (s != NULL); + ASSERT (!strcmp (s, "1.")); + free (s); + + s = my_c_xasprintf ("%#.0f", 1.0); + ASSERT (s != NULL); + ASSERT (!strcmp (s, "1.")); + free (s); + } + + return 0; +} diff --git a/tests/test-c-xvasprintf.sh b/tests/test-c-xvasprintf.sh new file mode 100755 index 0000000000..1ec5e35cd9 --- /dev/null +++ b/tests/test-c-xvasprintf.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# Test in an ISO-8859-1 or ISO-8859-15 locale. +: ${LOCALE_FR=fr_FR} +if test $LOCALE_FR = none; then + if test -f /usr/bin/localedef; then + echo "Skipping test: no traditional french locale is installed" + else + echo "Skipping test: no traditional french locale is supported" + fi + exit 77 +fi + +LC_ALL=$LOCALE_FR \ +./test-c-xvasprintf${EXEEXT} 1 |