source: vendor/glibc-tests/glibc/stdio-common/tst-fphex.c

Last change on this file was 2036, checked in by bird, 20 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.4 KB
Line 
1/* Test program for %a printf formats. */
2
3#include <stdio.h>
4#include <string.h>
5
6struct testcase
7{
8 double value;
9 const char *fmt;
10 const char *expect;
11};
12
13static const struct testcase testcases[] =
14 {
15 { 0x0.0030p+0, "%a", "0x1.8p-11" },
16 { 0x0.0040p+0, "%a", "0x1p-10" },
17 { 0x0.0030p+0, "%040a", "0x00000000000000000000000000000001.8p-11" },
18 { 0x0.0040p+0, "%040a", "0x0000000000000000000000000000000001p-10" },
19 { 0x0.0040p+0, "%40a", " 0x1p-10" },
20 { 0x0.0040p+0, "%#40a", " 0x1.p-10" },
21 { 0x0.0040p+0, "%-40a", "0x1p-10 " },
22 { 0x0.0040p+0, "%#-40a", "0x1.p-10 " },
23 { 0x0.0030p+0, "%040e", "00000000000000000000000000007.324219e-04" },
24 { 0x0.0040p+0, "%040e", "00000000000000000000000000009.765625e-04" },
25 };
26
27
28static int
29do_test (int argc, char **argv)
30{
31 const struct testcase *t;
32 int result = 0;
33
34 for (t = testcases;
35 t < &testcases[sizeof testcases / sizeof testcases[0]];
36 ++t)
37 {
38 char buf[1024];
39 int n = snprintf (buf, sizeof buf, t->fmt, t->value);
40 if (n != strlen (t->expect) || strcmp (buf, t->expect) != 0)
41 {
42 printf ("%s\tExpected \"%s\" (%Zu)\n\tGot \"%s\" (%d, %Zu)\n",
43 t->fmt, t->expect, strlen (t->expect), buf, n, strlen (buf));
44 result = 1;
45 }
46 }
47
48 return result;
49}
50
51#include "../test-skeleton.c"
Note: See TracBrowser for help on using the repository browser.