glibc/libio/tst_swprintf.c
Roland McGrath 57b36a0a75 * catgets/open_catalog.c (__open_catalog): Don't use a value type
as the __builtin_expect expression, just the Boolean value.

	* sysdeps/generic/wordexp.c (parse_glob): int -> size_t for counter.
	* sysdeps/unix/sysv/linux/opensock.c (__opensock): Likewise.
	* resolv/res_hconf.c (arg_service_list, parse_line): Likewise.
	* iconvdata/tst-loading.c (main): Likewise.
	* catgets/tst-catgets.c (main): Likewise.
	* stdlib/tst-xpg-basename.c (main): Likewise.
	* stdlib/tst-bsearch.c (main): Likewise.
	* stdio-common/test-vfprintf.c (main): Likewise.
	* stdio-common/tst-rndseek.c (do_test): Likewise.
	* libio/tst_swprintf.c (main): Likewise.
	* libio/tst-fgetws.c (main): Likewise.
	* wcsmbs/tst-mbrtowc.c (check_ascii): Likewise.
	* time/tst-posixtz.c (main): Likewise.
	* time/tst-strptime.c (test_tm): Likewise.
	* time/tst-strptime.c (main): Likewise.
	* time/tst-getdate.c (main): Likewise.
	* posix/tst-mmap.c (main): Likewise.
	* posix/tst-getaddrinfo.c (do_test): Likewise.
	* io/tst-getcwd.c (do_test): Likewise.
	* resolv/tst-aton.c (main): Likewise.
	* inet/tst-network.c (main): Likewise.
	* libio/tst-fgetws.c (main): Likewise.
	* sysdeps/posix/sprofil.c (add_region): int -> unsigned int for I.
	* sysdeps/unix/sysv/linux/ptsname.c (__ptsname_r): int -> unsigned int
	for PTYNO.

	* stdlib/msort.c (qsort): Add a cast to silence warning.
	* stdio-common/vfprintf.c (process_string_arg): Likewise.
	* libio/oldfileops.c (_IO_old_do_write): Likewise.
	* sysdeps/unix/sysv/linux/getcwd.c (__getcwd): Likewise.
	* sysdeps/unix/sysv/linux/ttyname.c (ttyname): Likewise.
	* sysdeps/unix/sysv/linux/gethostid.c (gethostid): Likewise.
	* argp/argp-fmtstream.c (__argp_fmtstream_printf): Likewise.
	* nscd/nscd_getgr_r.c (nscd_getgr_r): Likewise.
	* sysdeps/unix/grantpt.c (grantpt): Likewise.
	* libio/tst-widetext.c (main): Likewise.
	* libio/tst-mmap2-eofsync.c (do_test): Likewise.
	* rt/tst-aio.c (test_file): Likewise.
	* rt/tst-aio64.c (test_file): Likewise.
	* resolv/tst-aton.c (main): Likewise.

	* catgets/catgetsinfo.h (CATGETS_MAGIC): Use U suffix on the constant.

	* ctype/ctype.c (__ctype_tolower, __ctype_toupper): Cast to int32_t
	instead of uint32_t in these macros.
2002-09-24 04:24:25 +00:00

93 lines
2.1 KiB
C

#include <stdio.h>
#include <wchar.h>
#include <sys/types.h>
static wchar_t buf[100];
#define nbuf (sizeof (buf) / sizeof (buf[0]))
static const struct
{
size_t n;
const char *str;
ssize_t exp;
} tests[] =
{
{ nbuf, "hello world", 11 },
{ 0, "hello world", -1 },
{ 0, "", -1 },
{ nbuf, "", 0 }
};
int
main (int argc, char *argv[])
{
size_t n;
int result = 0;
puts ("test 1");
n = swprintf (buf, nbuf, L"Hello %s", "world");
if (n != 11)
{
printf ("incorrect return value: %d instead of 11\n", n);
result = 1;
}
else if (wcscmp (buf, L"Hello world") != 0)
{
printf ("incorrect string: L\"%ls\" instead of L\"Hello world\"\n", buf);
result = 1;
}
puts ("test 2");
n = swprintf (buf, nbuf, L"Is this >%g< 3.1?", 3.1);
if (n != 18)
{
printf ("incorrect return value: %d instead of 18\n", n);
result = 1;
}
else if (wcscmp (buf, L"Is this >3.1< 3.1?") != 0)
{
printf ("incorrect string: L\"%ls\" instead of L\"Is this >3.1< 3.1?\"\n",
buf);
result = 1;
}
for (n = 0; n < sizeof (tests) / sizeof (tests[0]); ++n)
{
ssize_t res = swprintf (buf, tests[n].n, L"%s", tests[n].str);
if (tests[n].exp < 0 && res >= 0)
{
printf ("swprintf (buf, %Zu, L\"%%s\", \"%s\") expected to fail\n",
tests[n].n, tests[n].str);
result = 1;
}
else if (tests[n].exp >= 0 && tests[n].exp != res)
{
printf ("swprintf (buf, %Zu, L\"%%s\", \"%s\") expected to return %Zd, but got %Zd\n",
tests[n].n, tests[n].str, tests[n].exp, res);
result = 1;
}
else
printf ("swprintf (buf, %Zu, L\"%%s\", \"%s\") OK\n",
tests[n].n, tests[n].str);
}
if (swprintf (buf, nbuf, L"%.0s", "foo") != 0
|| wcslen (buf) != 0)
{
printf ("swprintf (buf, %Zu, L\"%%.0s\", \"foo\") create some output\n",
nbuf);
result = 1;
}
if (swprintf (buf, nbuf, L"%.0ls", L"foo") != 0
|| wcslen (buf) != 0)
{
printf ("swprintf (buf, %Zu, L\"%%.0ls\", L\"foo\") create some output\n",
nbuf);
result = 1;
}
return result;
}