annotate tests/test-vsnprintf.c @ 14350:4cf3b58aaf12

Don't interfere with a program's definition of __attribute__. * lib/argp.h (__attribute__): Remove definition. (_GL_ATTRIBUTE_FORMAT): New macro. (argp_error, __argp_error, argp_failure, __argp_failure): Use it. * lib/argp-fmtstream.h (__attribute__): Remove definition. (_GL_ATTRIBUTE_FORMAT): New macro. (__argp_fmtstream_printf, argp_fmtstream_printf): Use it. * lib/argp-help.c (hol_entry_long_iterate): Use __attribute__ only for GCC 3 or newer. * lib/error.h (__attribute__): Remove definition. (_GL_ATTRIBUTE_FORMAT): New macro. (error, error_at_line): Use it. * lib/hash.h (__attribute__): Remove definition. (ATTRIBUTE_WUR): Update definition. Define always. * lib/openat.h (__attribute__): Remove definition. (ATTRIBUTE_NORETURN): Update definition. Define always. * lib/sigpipe-die.h (__attribute__): Remove definition. (ATTRIBUTE_NORETURN): Update definition. Define always. * lib/vasnprintf.h (__attribute__): Remove definition. (_GL_ATTRIBUTE_FORMAT): New macro. (asnprintf, vasnprintf): Use it. * lib/xalloc.h (__attribute__): Remove definition. (ATTRIBUTE_NORETURN): Update definition. Define always. (ATTRIBUTE_MALLOC, ATTRIBUTE_ALLOC_SIZE): Define always. * lib/xmemdup0.h (__attribute__): Remove definition. (ATTRIBUTE_NORETURN): Update definition. Define always. * lib/xprintf.h (__attribute__): Remove definition. (_GL_ATTRIBUTE_FORMAT): New macro. (xprintf, xvprintf, xfprintf, xvfprintf): Use it. * lib/xstrtol.h (__attribute__): Remove definition. (ATTRIBUTE_NORETURN): Update definition. Define always. * lib/xvasprintf.h (__attribute__): Remove definition. (_GL_ATTRIBUTE_FORMAT): New macro. (xasprintf, xvasprintf): Use it. * tests/test-argmatch.c (__attribute__): Remove definition. (ATTRIBUTE_NORETURN): Update definition. Define always. * tests/test-exclude.c (__attribute__): Remove definition. (ATTRIBUTE_NORETURN): Update definition. Define always. Reported by Paul Eggert.
author Bruno Haible <bruno@clisp.org>
date Sun, 13 Feb 2011 23:21:20 +0100
parents 97fc9a21a8fb
children 03a50862ef09
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8328
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of vsnprintf() function.
14079
97fc9a21a8fb maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents: 14003
diff changeset
2 Copyright (C) 2007-2011 Free Software Foundation, Inc.
8328
2773a5eebd49 Tests for module 'vsnprintf'.
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
8328
2773a5eebd49 Tests for module 'vsnprintf'.
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.
8328
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
2773a5eebd49 Tests for module 'vsnprintf'.
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/>. */
8328
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
8891
633babea5f62 Unconditionally include <config.h> in unit tests.
Eric Blake <ebb9@byu.net>
parents: 8763
diff changeset
19 #include <config.h>
8328
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <stdio.h>
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
12489
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
23 #include "signature.h"
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
24 SIGNATURE_CHECK (vsnprintf, int, (char *, size_t, char const *, va_list));
33ab12a7cea2 tests: add signature checks
Eric Blake <ebb9@byu.net>
parents: 12421
diff changeset
25
8328
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <stdarg.h>
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include <string.h>
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
12496
a48d3d749ca5 Refactor common macros used in tests.
Bruno Haible <bruno@clisp.org>
parents: 12489
diff changeset
29 #include "macros.h"
8328
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 static int
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 my_snprintf (char *buf, int size, const char *format, ...)
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 {
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 va_list args;
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 int ret;
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 va_start (args, format);
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 ret = vsnprintf (buf, size, format, args);
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 va_end (args);
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 return ret;
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 }
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 int
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 main (int argc, char *argv[])
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 {
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 char buf[8];
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 int size;
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 int retval;
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49
14003
f82a977dcf0b vsnprintf: make more consistent with snprintf; doc fixes
Paul Eggert <eggert@cs.ucla.edu>
parents: 12559
diff changeset
50 retval = my_snprintf (NULL, 0, "%d", 12345);
f82a977dcf0b vsnprintf: make more consistent with snprintf; doc fixes
Paul Eggert <eggert@cs.ucla.edu>
parents: 12559
diff changeset
51 ASSERT (retval == 5);
f82a977dcf0b vsnprintf: make more consistent with snprintf; doc fixes
Paul Eggert <eggert@cs.ucla.edu>
parents: 12559
diff changeset
52
8328
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 for (size = 0; size <= 8; size++)
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 {
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 memcpy (buf, "DEADBEEF", 8);
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 retval = my_snprintf (buf, size, "%d", 12345);
14003
f82a977dcf0b vsnprintf: make more consistent with snprintf; doc fixes
Paul Eggert <eggert@cs.ucla.edu>
parents: 12559
diff changeset
57 ASSERT (retval == 5);
8328
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 if (size < 6)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
59 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
60 if (size > 0)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
61 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
62 ASSERT (memcmp (buf, "12345", size - 1) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
63 ASSERT (buf[size - 1] == '\0' || buf[size - 1] == '0' + size);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
64 }
8763
39bb5430fc0e Guard against vsnprintf implementations that mishandle a size=0 argument.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
65 #if !CHECK_VSNPRINTF_POSIX
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
66 if (size > 0)
8763
39bb5430fc0e Guard against vsnprintf implementations that mishandle a size=0 argument.
Bruno Haible <bruno@clisp.org>
parents: 8754
diff changeset
67 #endif
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
68 ASSERT (memcmp (buf + size, "DEADBEEF" + size, 8 - size) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
69 }
8328
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
71 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
72 ASSERT (memcmp (buf, "12345\0EF", 8) == 0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9889
diff changeset
73 }
8328
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 }
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 return 0;
2773a5eebd49 Tests for module 'vsnprintf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 }