glibc/stdio-common/tst-fphex.c

73 lines
1.9 KiB
C
Raw Normal View History

/* Test program for %a printf formats. */
#include <stdio.h>
#include <string.h>
2012-03-08 16:02:24 +08:00
#ifndef WIDE
2012-03-08 15:32:47 +08:00
# define STR_LEN strlen
# define STR_CMP strcmp
# define SPRINT snprintf
# define CHAR_T char
# define PRINT printf
# define L_(Str) Str
2012-03-08 16:02:24 +08:00
# define S "%s"
#else
# define STR_LEN wcslen
# define SPRINT swprintf
# define STR_CMP wcscmp
# define CHAR_T wchar_t
# define PRINT wprintf
# define L_(Str) L##Str
# define S "%ls"
2012-03-08 15:32:47 +08:00
#endif
struct testcase
{
double value;
2012-03-08 15:32:47 +08:00
const CHAR_T *fmt;
const CHAR_T *expect;
};
static const struct testcase testcases[] =
{
2012-03-08 15:32:47 +08:00
{ 0x0.0030p+0, L_("%a"), L_("0x1.8p-11") },
{ 0x0.0040p+0, L_("%a"), L_("0x1p-10") },
{ 0x0.0030p+0, L_("%040a"), L_("0x00000000000000000000000000000001.8p-11") },
{ 0x0.0040p+0, L_("%040a"), L_("0x0000000000000000000000000000000001p-10") },
{ 0x0.0040p+0, L_("%40a"), L_(" 0x1p-10") },
{ 0x0.0040p+0, L_("%#40a"), L_(" 0x1.p-10") },
{ 0x0.0040p+0, L_("%-40a"), L_("0x1p-10 ") },
{ 0x0.0040p+0, L_("%#-40a"), L_("0x1.p-10 ") },
{ 0x0.0030p+0, L_("%040e"), L_("00000000000000000000000000007.324219e-04") },
{ 0x0.0040p+0, L_("%040e"), L_("00000000000000000000000000009.765625e-04") },
};
static int
2012-03-08 15:32:47 +08:00
do_test (void)
{
const struct testcase *t;
int result = 0;
for (t = testcases;
t < &testcases[sizeof testcases / sizeof testcases[0]];
++t)
{
2012-03-08 15:32:47 +08:00
CHAR_T buf[1024];
int n = SPRINT (buf, sizeof buf / sizeof (buf[0]), t->fmt, t->value);
if (n != STR_LEN (t->expect) || STR_CMP (buf, t->expect) != 0)
{
2012-03-08 16:02:24 +08:00
PRINT (L_("" S "\tExpected \"" S "\" (%Zu)\n\tGot \""
S "\" (%d, %Zu)\n"),
t->fmt, t->expect, STR_LEN (t->expect),
2012-03-08 15:32:47 +08:00
buf, n, STR_LEN (buf));
result = 1;
}
}
return result;
}
2012-03-08 15:32:47 +08:00
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"