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/test-c-xvasprintf.c | |
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/test-c-xvasprintf.c')
-rw-r--r-- | tests/test-c-xvasprintf.c | 78 |
1 files changed, 78 insertions, 0 deletions
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; +} |