mirror of
git://sourceware.org/git/glibc.git
synced 2024-12-21 04:31:04 +08:00
e15f7de60c
Quite a few tests include libc-internal.h just for the DIAG_* macros. Split those macros to their own file, which can be included safely in _ISOMAC mode. I also moved ignore_value, since it seems logically related, even though I didn't notice any tests needing it. Also add -Wnonnull suppressions to two tests that _should_ have them, but the error is masked when compiling against internal headers. * include/libc-diag.h: New file. Define ignore_value, DIAG_PUSH_NEEDS_COMMENT, DIAG_POP_NEEDS_COMMENT, DIAG_IGNORE_NEEDS_COMMENT, and DIAG_IGNORE_Os_NEEDS_COMMENT here. * include/libc-internal.h: Definitions of above macros moved from here. Include libc-diag.h. Add copyright notice. * malloc/tst-malloc.c, malloc/tst-memcheck.c, malloc/tst-realloc.c * misc/tst-error1.c, posix/tst-dir.c, stdio-common/bug21.c * stdio-common/scanf14.c, stdio-common/scanf4.c, stdio-common/scanf7.c * stdio-common/test-vfprintf.c, stdio-common/tst-printf.c * stdio-common/tst-printfsz.c, stdio-common/tst-sprintf.c * stdio-common/tst-unlockedio.c, stdio-common/tstdiomisc.c * stdlib/bug-getcontext.c, string/tester.c, string/tst-endian.c * time/tst-strptime2.c, wcsmbs/tst-wcstof.c: Include libc-diag.h instead of libc-internal.h. * stdlib/tst-environ.c: Include libc-diag.h. Suppress -Wnonnull for call to unsetenv (NULL). * nptl/tst-mutex1.c: Include libc-diag.h. Suppress -Wnonnull for call to pthread_mutexattr_destroy (NULL).
82 lines
2.2 KiB
C
82 lines
2.2 KiB
C
/* Based on code by Larry McVoy <lm@neteng.engr.sgi.com>. */
|
|
#include <printf.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <libc-diag.h>
|
|
|
|
#define V 12345678.12345678
|
|
|
|
|
|
static int
|
|
do_test (void)
|
|
{
|
|
char buf[1024];
|
|
int result = 0;
|
|
|
|
/* Testing printf_size_info requires using the deprecated
|
|
register_printf_function, resulting in warnings
|
|
"'register_printf_function' is deprecated". */
|
|
DIAG_PUSH_NEEDS_COMMENT;
|
|
DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wdeprecated-declarations");
|
|
/* Register the printf handlers. */
|
|
register_printf_function ('b', printf_size, printf_size_info);
|
|
register_printf_function ('B', printf_size, printf_size_info);
|
|
DIAG_POP_NEEDS_COMMENT;
|
|
|
|
/* All of the formats here use the nonstandard extension specifier
|
|
just registered, so compiler checking will never grok them. */
|
|
DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat");
|
|
DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat-extra-args");
|
|
|
|
sprintf (buf, "%g %b %B %.0b %.0B %.1b %.1B %8.0b %08.0B",
|
|
V, 1025., V, V, V, V, V, V, V, V);
|
|
fputs (buf, stdout);
|
|
if (strcmp (buf, "\
|
|
1.23457e+07 1.001k 12.346M 12m 12M 11.8m 12.3M 12m 0000012M"))
|
|
{
|
|
result = 1;
|
|
fputs (" -> WRONG\n", stdout);
|
|
}
|
|
else
|
|
fputs (" -> OK\n", stdout);
|
|
|
|
sprintf (buf, "%b|%B|%-20.2b|%-10.0b|%-10.8b|%-10.2B|",
|
|
V, V, V, V, V, V, V, V, V, V, V);
|
|
fputs (buf, stdout);
|
|
if (strcmp (buf, "\
|
|
11.774m|12.346M|11.77m |12m |11.77375614m|12.35M |"))
|
|
{
|
|
result = 1;
|
|
fputs (" -> WRONG\n", stdout);
|
|
}
|
|
else
|
|
fputs (" -> OK\n", stdout);
|
|
|
|
sprintf (buf, "%#.0B %*.0b %10.*b %*.*B %10.2B",
|
|
V, 2, V, 2, V, 10, 2, V, V);
|
|
fputs (buf, stdout);
|
|
if (strcmp (buf, "12.M 12m 11.77m 12.35M 12.35M"))
|
|
{
|
|
result = 1;
|
|
fputs (" -> WRONG\n", stdout);
|
|
}
|
|
else
|
|
fputs (" -> OK\n", stdout);
|
|
|
|
sprintf (buf, "%6B %6.1B %b %B %b %B",
|
|
V, V, 1000.0, 1000.0, 1024.0, 1024.0);
|
|
fputs (buf, stdout);
|
|
if (strcmp (buf, "12.346M 12.3M 1000.000 1.000K 1.000k 1.024K"))
|
|
{
|
|
result = 1;
|
|
fputs (" -> WRONG\n", stdout);
|
|
}
|
|
else
|
|
fputs (" -> OK\n", stdout);
|
|
|
|
return result;
|
|
}
|
|
|
|
#define TEST_FUNCTION do_test ()
|
|
#include "../test-skeleton.c"
|