hjl / source-git / glibc

Forked from source-git/glibc 3 years ago
Clone

Blame stdio-common/tst-fphex.c

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