Tests for module 'vfprintf-posix'.
[gnulib.git] / tests / test-fprintf-posix.h
1 /* Test of POSIX compatible vsprintf() and sprintf() functions.
2    Copyright (C) 2007 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2, or (at your option)
7    any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software Foundation,
16    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
17
18 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
19
20 static void
21 test_function (int (*my_fprintf) (FILE *, const char *, ...))
22 {
23   /* Here we don't test output that may be platform dependent.
24      The bulk of the tests is done as part of the 'vasnprintf-posix' module.  */
25
26   /* Test support of size specifiers as in C99.  */
27
28   my_fprintf (stdout, "%ju %d\n", (uintmax_t) 12345671, 33, 44, 55);
29
30   my_fprintf (stdout, "%zu %d\n", (size_t) 12345672, 33, 44, 55);
31
32   my_fprintf (stdout, "%tu %d\n", (ptrdiff_t) 12345673, 33, 44, 55);
33
34   /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
35      output of floating-point numbers.  */
36
37   /* Positive zero.  */
38   my_fprintf (stdout, "%a %d\n", 0.0, 33, 44, 55);
39
40   /* Negative zero.  */
41   my_fprintf (stdout, "%a %d\n", -0.0, 33, 44, 55);
42
43   /* Positive infinity.  */
44   my_fprintf (stdout, "%a %d\n", 1.0 / 0.0, 33, 44, 55);
45
46   /* Negative infinity.  */
47   my_fprintf (stdout, "%a %d\n", -1.0 / 0.0, 33, 44, 55);
48
49   /* NaN.  */
50   my_fprintf (stdout, "%a %d\n", 0.0 / 0.0, 33, 44, 55);
51
52   /* FLAG_ZERO with infinite number.  */
53   my_fprintf (stdout, "%010a %d\n", 1.0 / 0.0, 33, 44, 55);
54
55   /* FLAG_ZERO with NaN.  */
56   my_fprintf (stdout, "%010a %d\n", 0.0 / 0.0, 33, 44, 55);
57
58   /* Test the support of the POSIX/XSI format strings with positions.  */
59
60   my_fprintf (stdout, "%2$d %1$d\n", 33, 55);
61 }