Blame stdio-common/tllformat.c

Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
Packit 6c4009
/* The original file was tiformat.c and it has been changed for long long tests\
Packit 6c4009
. */
Packit 6c4009
typedef struct
Packit 6c4009
{
Packit 6c4009
  int line;
Packit 6c4009
  long long int value;
Packit 6c4009
  const char *result;
Packit 6c4009
  const char *format_string;
Packit 6c4009
} sprint_int_type;
Packit 6c4009
Packit 6c4009
sprint_int_type sprint_ints[] =
Packit 6c4009
{
Packit 6c4009
  {__LINE__, 0x00000000ULL,             "0", "%llx"},
Packit 6c4009
  {__LINE__, 0xffff00000000208bULL,     "ffff00000000208b", "%llx"},
Packit 6c4009
  {__LINE__, 0xffff00000000208bULL,     "18446462598732849291", "%llu"},
Packit 6c4009
  {__LINE__, 18446462598732849291ULL,   "ffff00000000208b", "%llx"},
Packit 6c4009
  {__LINE__, 18446462598732849291ULL,   "18446462598732849291", "%llu"},
Packit 6c4009
  {__LINE__, 18359476226655002763ULL,   "fec9f65b0000208b", "%llx"},
Packit 6c4009
  {__LINE__, 18359476226655002763ULL,   "18359476226655002763", "%llu"},
Packit 6c4009
Packit 6c4009
  {0},
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
main (void)
Packit 6c4009
{
Packit 6c4009
  int errcount = 0;
Packit 6c4009
  int testcount = 0;
Packit 6c4009
#define BSIZE 1024
Packit 6c4009
  char buffer[BSIZE];
Packit 6c4009
  sprint_int_type *iptr;
Packit 6c4009
  for (iptr = sprint_ints; iptr->line; iptr++)
Packit 6c4009
    {
Packit 6c4009
      sprintf (buffer, iptr->format_string, iptr->value);
Packit 6c4009
      if (strcmp (buffer, iptr->result) != 0)
Packit 6c4009
	{
Packit 6c4009
	  ++errcount;
Packit 6c4009
	  printf ("\
Packit 6c4009
Error in line %d using \"%s\".  Result is \"%s\"; should be: \"%s\".\n",
Packit 6c4009
		  iptr->line, iptr->format_string, buffer, iptr->result);
Packit 6c4009
        }
Packit 6c4009
      ++testcount;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (errcount == 0)
Packit 6c4009
    {
Packit 6c4009
      printf ("Encountered no errors in %d tests.\n", testcount);
Packit 6c4009
      return 0;
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    {
Packit 6c4009
      printf ("Encountered %d errors in %d tests.\n",
Packit 6c4009
	      errcount, testcount);
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
}