Back to index

glibc  2.9
tst-fphex.c
Go to the documentation of this file.
00001 /* Test program for %a printf formats.  */
00002 
00003 #include <stdio.h>
00004 #include <string.h>
00005 
00006 struct testcase
00007 {
00008   double value;
00009   const char *fmt;
00010   const char *expect;
00011 };
00012 
00013 static const struct testcase testcases[] =
00014   {
00015     { 0x0.0030p+0, "%a",    "0x1.8p-11" },
00016     { 0x0.0040p+0, "%a",    "0x1p-10" },
00017     { 0x0.0030p+0, "%040a", "0x00000000000000000000000000000001.8p-11" },
00018     { 0x0.0040p+0, "%040a", "0x0000000000000000000000000000000001p-10" },
00019     { 0x0.0040p+0, "%40a",  "                                 0x1p-10" },
00020     { 0x0.0040p+0, "%#40a", "                                0x1.p-10" },
00021     { 0x0.0040p+0, "%-40a", "0x1p-10                                 " },
00022     { 0x0.0040p+0, "%#-40a",       "0x1.p-10                                " },
00023     { 0x0.0030p+0, "%040e", "00000000000000000000000000007.324219e-04" },
00024     { 0x0.0040p+0, "%040e", "00000000000000000000000000009.765625e-04" },
00025   };
00026 
00027 
00028 static int
00029 do_test (int argc, char **argv)
00030 {
00031   const struct testcase *t;
00032   int result = 0;
00033 
00034   for (t = testcases;
00035        t < &testcases[sizeof testcases / sizeof testcases[0]];
00036        ++t)
00037     {
00038       char buf[1024];
00039       int n = snprintf (buf, sizeof buf, t->fmt, t->value);
00040       if (n != strlen (t->expect) || strcmp (buf, t->expect) != 0)
00041        {
00042          printf ("%s\tExpected \"%s\" (%Zu)\n\tGot      \"%s\" (%d, %Zu)\n",
00043                 t->fmt, t->expect, strlen (t->expect), buf, n, strlen (buf));
00044          result = 1;
00045        }
00046     }
00047 
00048   return result;
00049 }
00050 
00051 #include "../test-skeleton.c"