Back to index

glibc  2.9
tllformat.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <string.h>
00003 
00004 /* The original file was tiformat.c and it has been changed for long long tests\
00005 . */
00006 typedef struct
00007 {
00008   int line;
00009   long long int value;
00010   const char *result;
00011   const char *format_string;
00012 } sprint_int_type;
00013 
00014 sprint_int_type sprint_ints[] =
00015 {
00016   {__LINE__, 0x00000000ULL,             "0", "%llx"},
00017   {__LINE__, 0xffff00000000208bULL,     "ffff00000000208b", "%llx"},
00018   {__LINE__, 0xffff00000000208bULL,     "18446462598732849291", "%llu"},
00019   {__LINE__, 18446462598732849291ULL,   "ffff00000000208b", "%llx"},
00020   {__LINE__, 18446462598732849291ULL,   "18446462598732849291", "%llu"},
00021   {__LINE__, 18359476226655002763ULL,   "fec9f65b0000208b", "%llx"},
00022   {__LINE__, 18359476226655002763ULL,   "18359476226655002763", "%llu"},
00023 
00024   {0},
00025 };
00026 
00027 int
00028 main (void)
00029 {
00030   int errcount = 0;
00031   int testcount = 0;
00032 #define BSIZE 1024
00033   char buffer[BSIZE];
00034   sprint_int_type *iptr;
00035   for (iptr = sprint_ints; iptr->line; iptr++)
00036     {
00037       sprintf (buffer, iptr->format_string, iptr->value);
00038       if (strcmp (buffer, iptr->result) != 0)
00039        {
00040          ++errcount;
00041          printf ("\
00042 Error in line %d using \"%s\".  Result is \"%s\"; should be: \"%s\".\n",
00043                 iptr->line, iptr->format_string, buffer, iptr->result);
00044         }
00045       ++testcount;
00046     }
00047 
00048   if (errcount == 0)
00049     {
00050       printf ("Encountered no errors in %d tests.\n", testcount);
00051       return 0;
00052     }
00053   else
00054     {
00055       printf ("Encountered %d errors in %d tests.\n",
00056              errcount, testcount);
00057       return 1;
00058     }
00059 }