1 /* Test of POSIX and GNU compatible dprintf() function.
2 Copyright (C) 2007-2024 Free Software Foundation, Inc.
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 3 of the License, or
7 (at your option) any later version.
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.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2023. */
29 test_function (int (*my_dprintf
) (int, const char *, ...))
31 /* Here we don't test output that may be platform dependent.
32 The bulk of the tests is done as part of the 'vasnprintf-posix' module. */
34 /* Test the support of the 'B' conversion specifier for binary output of
38 my_dprintf (fileno (stdout
), "%B %d\n", 0, 33, 44, 55);
40 /* A positive number. */
41 my_dprintf (fileno (stdout
), "%B %d\n", 12345, 33, 44, 55);
43 /* A large positive number. */
44 my_dprintf (fileno (stdout
), "%B %d\n", 0xFFFFFFFEU
, 33, 44, 55);
47 my_dprintf (fileno (stdout
), "%20B %d\n", 12345, 33, 44, 55);
49 /* Width given as argument. */
50 my_dprintf (fileno (stdout
), "%*B %d\n", 20, 12345, 33, 44, 55);
52 /* Negative width given as argument (cf. FLAG_LEFT below). */
53 my_dprintf (fileno (stdout
), "%*B %d\n", -20, 12345, 33, 44, 55);
56 my_dprintf (fileno (stdout
), "%.20B %d\n", 12345, 33, 44, 55);
58 /* Zero precision and a positive number. */
59 my_dprintf (fileno (stdout
), "%.0B %d\n", 12345, 33, 44, 55);
61 /* Zero precision and a zero number. */
62 my_dprintf (fileno (stdout
), "%.0B %d\n", 0, 33, 44, 55);
64 /* Width and precision. */
65 my_dprintf (fileno (stdout
), "%25.20B %d\n", 12345, 33, 44, 55);
68 my_dprintf (fileno (stdout
), "%-20B %d\n", 12345, 33, 44, 55);
70 /* FLAG_ALT with zero. */
71 my_dprintf (fileno (stdout
), "%#B %d\n", 0, 33, 44, 55);
73 /* FLAG_ALT with a positive number. */
74 my_dprintf (fileno (stdout
), "%#B %d\n", 12345, 33, 44, 55);
76 /* FLAG_ALT with a positive number and width. */
77 my_dprintf (fileno (stdout
), "%#20B %d\n", 12345, 33, 44, 55);
79 /* FLAG_ALT with a positive number and padding. */
80 my_dprintf (fileno (stdout
), "%0#20B %d\n", 12345, 33, 44, 55);
82 /* FLAG_ALT with a positive number and precision. */
83 my_dprintf (fileno (stdout
), "%0#.20B %d\n", 12345, 33, 44, 55);
85 /* FLAG_ALT with a positive number and width and precision. */
86 my_dprintf (fileno (stdout
), "%#25.20B %d\n", 12345, 33, 44, 55);
88 /* FLAG_ALT with a zero precision and a zero number. */
89 my_dprintf (fileno (stdout
), "%#.0B %d\n", 0, 33, 44, 55);
93 main (int argc
, char *argv
[])
95 test_function (dprintf
);
96 return test_exit_status
;