2002-10-24 01:15:37 +00:00
|
|
|
/* Test program for %a printf formats. */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-03-08 07:32:47 +00:00
|
|
|
#ifndef STR_LEN
|
|
|
|
# define STR_LEN strlen
|
|
|
|
#endif
|
|
|
|
#ifndef STR_CMP
|
|
|
|
# define STR_CMP strcmp
|
|
|
|
#endif
|
|
|
|
#ifndef SPRINT
|
|
|
|
# define SPRINT snprintf
|
|
|
|
#endif
|
|
|
|
#ifndef CHAR_T
|
|
|
|
# define CHAR_T char
|
|
|
|
#endif
|
|
|
|
#ifndef PRINT
|
|
|
|
# define PRINT printf
|
|
|
|
#endif
|
|
|
|
#ifndef L_
|
|
|
|
# define L_(Str) Str
|
|
|
|
#endif
|
|
|
|
#ifndef L
|
|
|
|
# define L
|
|
|
|
#endif
|
|
|
|
|
2002-10-24 01:15:37 +00:00
|
|
|
struct testcase
|
|
|
|
{
|
|
|
|
double value;
|
2012-03-08 07:32:47 +00:00
|
|
|
const CHAR_T *fmt;
|
|
|
|
const CHAR_T *expect;
|
2002-10-24 01:15:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct testcase testcases[] =
|
|
|
|
{
|
2012-03-08 07:32:47 +00: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") },
|
2002-10-24 01:15:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2012-03-08 07:32:47 +00:00
|
|
|
do_test (void)
|
2002-10-24 01:15:37 +00:00
|
|
|
{
|
|
|
|
const struct testcase *t;
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
for (t = testcases;
|
|
|
|
t < &testcases[sizeof testcases / sizeof testcases[0]];
|
|
|
|
++t)
|
|
|
|
{
|
2012-03-08 07:32:47 +00: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)
|
2002-10-24 01:15:37 +00:00
|
|
|
{
|
2012-03-08 07:32:47 +00:00
|
|
|
PRINT (L_("%" L "s\tExpected \"%" L "s\" (%Zu)\n\tGot \"%" L
|
|
|
|
"s\" (%d, %Zu)\n"), t->fmt, t->expect, STR_LEN (t->expect),
|
|
|
|
buf, n, STR_LEN (buf));
|
2002-10-24 01:15:37 +00:00
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-03-08 07:32:47 +00:00
|
|
|
#define TEST_FUNCTION do_test ()
|
2002-10-24 01:15:37 +00:00
|
|
|
#include "../test-skeleton.c"
|