annotate tests/test-printf-posix.c @ 9889:0be6f1ab456d

Flush the standard error stream before aborting.
author Bruno Haible <bruno@clisp.org>
date Fri, 11 Apr 2008 16:31:39 +0200
parents bb2a238b2c3a
children 849e7305914c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9430
bb2a238b2c3a Typo in comment.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
1 /* Test of POSIX compatible printf() function.
9889
0be6f1ab456d Flush the standard error stream before aborting.
Bruno Haible <bruno@clisp.org>
parents: 9430
diff changeset
2 Copyright (C) 2007-2008 Free Software Foundation, Inc.
8403
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
4 This program is free software: you can redistribute it and/or modify
8403
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
7 (at your option) any later version.
8403
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8891
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8403
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
8891
633babea5f62 Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents: 8754
diff changeset
19 #include <config.h>
8403
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <stdio.h>
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <stddef.h>
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8403
diff changeset
24 #include <stdio.h>
8403
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <stdint.h>
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <stdlib.h>
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include <string.h>
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8403
diff changeset
29 #define ASSERT(expr) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8403
diff changeset
30 do \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8403
diff changeset
31 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8403
diff changeset
32 if (!(expr)) \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8403
diff changeset
33 { \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8403
diff changeset
34 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
9889
0be6f1ab456d Flush the standard error stream before aborting.
Bruno Haible <bruno@clisp.org>
parents: 9430
diff changeset
35 fflush (stderr); \
8754
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8403
diff changeset
36 abort (); \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8403
diff changeset
37 } \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8403
diff changeset
38 } \
1f57552cdb11 Better ASSERT macro.
Bruno Haible <bruno@clisp.org>
parents: 8403
diff changeset
39 while (0)
8403
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 #include "test-printf-posix.h"
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 int
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 main (int argc, char *argv[])
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 {
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 test_function (printf);
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 return 0;
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 }
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 /* Test whether __attribute__ (__format__ (...)) still works. */
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 #if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)) && !__STRICT_ANSI__
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 extern int func1 (char *, size_t, const char *, ...)
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 __attribute__ ((__format__ (__printf__, 3, 4)));
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 extern int func2 (char *, size_t, const char *, ...)
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 __attribute__ ((__format__ (printf, 3, 4)));
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 extern int func3 (char *, size_t, const char *, ...)
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 __attribute__ ((format (__printf__, 3, 4)));
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 extern int func4 (char *, size_t, const char *, ...)
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 __attribute__ ((format (printf, 3, 4)));
f05a09ae28b1 Tests for module 'printf-posix'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 #endif