about summary refs log tree commit diff
path: root/stdio-common
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2002-10-24 01:15:37 +0000
committerRoland McGrath <roland@gnu.org>2002-10-24 01:15:37 +0000
commit90d598708199f0506e390bb9866e4bdb592f858a (patch)
tree21303c2f0cbbd225561f60fd5e295f9fd5d98049 /stdio-common
parent240e87c2300c25b1cc8a78cccc2293874d89c67e (diff)
downloadglibc-90d598708199f0506e390bb9866e4bdb592f858a.tar.gz
glibc-90d598708199f0506e390bb9866e4bdb592f858a.tar.xz
glibc-90d598708199f0506e390bb9866e4bdb592f858a.zip
* stdio-common/tst-fphex.c: New file.
	* stdio-common/Makefile (tests): Add tst-fphex.
	* sysdeps/generic/printf_fphex.c (__printf_fphex): Fix initialization
	of WNUMEND.  Fix counting of decimal point in WIDTH.  Print '0' pad
	chars always before the value digits.
	Reported by James Antill <james.antill@redhat.com>.
Diffstat (limited to 'stdio-common')
-rw-r--r--stdio-common/Makefile2
-rw-r--r--stdio-common/tst-fphex.c51
2 files changed, 52 insertions, 1 deletions
diff --git a/stdio-common/Makefile b/stdio-common/Makefile
index c32a2db428..802e4e37e8 100644
--- a/stdio-common/Makefile
+++ b/stdio-common/Makefile
@@ -54,7 +54,7 @@ tests := tstscanf test_rdwr test-popen tstgetln test-fseek \
 	 scanf1 scanf2 scanf3 scanf4 scanf5 scanf7 scanf8 scanf9 scanf10 \
 	 scanf11 scanf12 tst-tmpnam tst-cookie tst-obprintf tst-sscanf \
 	 tst-swprintf tst-fseek tst-fmemopen test-vfprintf tst-gets \
-	 tst-perror tst-sprintf tst-rndseek tst-fdopen
+	 tst-perror tst-sprintf tst-rndseek tst-fdopen tst-fphex
 
 test-srcs = tst-unbputc tst-printf
 
diff --git a/stdio-common/tst-fphex.c b/stdio-common/tst-fphex.c
new file mode 100644
index 0000000000..aca2c0500d
--- /dev/null
+++ b/stdio-common/tst-fphex.c
@@ -0,0 +1,51 @@
+/* Test program for %a printf formats.  */
+
+#include <stdio.h>
+#include <string.h>
+
+struct testcase
+{
+  double value;
+  const char *fmt;
+  const char *expect;
+};
+
+static const struct testcase testcases[] =
+  {
+    { 0x0.0030p+0, "%a",	"0x1.8p-11" },
+    { 0x0.0040p+0, "%a",	"0x1p-10" },
+    { 0x0.0030p+0, "%040a",	"0x00000000000000000000000000000001.8p-11" },
+    { 0x0.0040p+0, "%040a",	"0x0000000000000000000000000000000001p-10" },
+    { 0x0.0040p+0, "%40a",	"                                 0x1p-10" },
+    { 0x0.0040p+0, "%#40a",	"                                0x1.p-10" },
+    { 0x0.0040p+0, "%-40a",	"0x1p-10                                 " },
+    { 0x0.0040p+0, "%#-40a",	"0x1.p-10                                " },
+    { 0x0.0030p+0, "%040e",	"00000000000000000000000000007.324219e-04" },
+    { 0x0.0040p+0, "%040e",	"00000000000000000000000000009.765625e-04" },
+  };
+
+
+static int
+do_test (int argc, char **argv)
+{
+  const struct testcase *t;
+  int result = 0;
+
+  for (t = testcases;
+       t < &testcases[sizeof testcases / sizeof testcases[0]];
+       ++t)
+    {
+      char buf[1024];
+      int n = snprintf (buf, sizeof buf, t->fmt, t->value);
+      if (n != strlen (t->expect) || strcmp (buf, t->expect) != 0)
+	{
+	  printf ("%s\tExpected \"%s\" (%u)\n\tGot      \"%s\" (%d, %u)\n",
+		  t->fmt, t->expect, strlen (t->expect), buf, n, strlen (buf));
+	  result = 1;
+	}
+    }
+
+  return result;
+}
+
+#include "../test-skeleton.c"