aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2012-03-08 08:32:47 +0100
committerMarek Polacek <polacek@redhat.com>2012-03-08 08:34:10 +0100
commit65b81130c5006b1140c3d8b59038a68004ff61c8 (patch)
tree6534d6bb5bbd13aecba952749624e87e767e3d7d
parent67c6a3d919b492c68664c4b95e84efd2174309e7 (diff)
downloadglibc-65b81130c5006b1140c3d8b59038a68004ff61c8.zip
glibc-65b81130c5006b1140c3d8b59038a68004ff61c8.tar.gz
glibc-65b81130c5006b1140c3d8b59038a68004ff61c8.tar.bz2
Enhance fphex test.
-rw-r--r--ChangeLog8
-rw-r--r--NEWS2
-rw-r--r--stdio-common/Makefile2
-rw-r--r--stdio-common/tst-fphex-wide.c30
-rw-r--r--stdio-common/tst-fphex.c60
5 files changed, 82 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 43f23dd..a96f05c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-03-08 Marek Polacek <polacek@redhat.com>
+
+ [BZ #13806]
+ * stdio-common/Makefile (tests): Add tst-fphex-wide.
+ * stdio-common/tst-fphex.c: Define a few macros to make the
+ test reusable. Use them.
+ * stdio-common/tst-fphex-wide.c: New file.
+
2012-03-08 Joseph Myers <joseph@codesourcery.com>
[BZ #6911]
diff --git a/NEWS b/NEWS
index 5021304..fd36632 100644
--- a/NEWS
+++ b/NEWS
@@ -14,7 +14,7 @@ Version 2.16
10210, 10545, 10716, 11174, 11322, 11365, 11494, 12047, 13058, 13525,
13526, 13527, 13528, 13529, 13530, 13531, 13532, 13533, 13547, 13551,
13552, 13553, 13555, 13559, 13583, 13618, 13637, 13656, 13695, 13704,
- 13706, 13726, 13738, 13786, 13792
+ 13706, 13726, 13738, 13786, 13792, 13806
* ISO C11 support:
diff --git a/stdio-common/Makefile b/stdio-common/Makefile
index c8a1365..266147e 100644
--- a/stdio-common/Makefile
+++ b/stdio-common/Makefile
@@ -58,7 +58,7 @@ tests := tstscanf test_rdwr test-popen tstgetln test-fseek \
tst-fwrite bug16 bug17 tst-swscanf tst-sprintf2 bug18 bug18a \
bug19 bug19a tst-popen2 scanf13 scanf14 scanf15 bug20 bug21 bug22 \
scanf16 scanf17 tst-setvbuf1 tst-grouping bug23 bug24 \
- bug-vfprintf-nargs tst-long-dbl-fphex
+ bug-vfprintf-nargs tst-long-dbl-fphex tst-fphex-wide
test-srcs = tst-unbputc tst-printf
diff --git a/stdio-common/tst-fphex-wide.c b/stdio-common/tst-fphex-wide.c
new file mode 100644
index 0000000..2fd9f6a
--- /dev/null
+++ b/stdio-common/tst-fphex-wide.c
@@ -0,0 +1,30 @@
+/* Test program for %a wprintf formats.
+ This file is part of the GNU C Library.
+ Copyright (C) 2012 Free Software Foundation, Inc.
+ Contributed by Marek Polacek <polacek@redhat.com>, 2012.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <wchar.h>
+
+#define STR_LEN wcslen
+#define SPRINT swprintf
+#define STR_CMP wcscmp
+#define CHAR_T wchar_t
+#define PRINT wprintf
+#define L_(Str) L##Str
+#define L "l"
+
+#include "tst-fphex.c"
diff --git a/stdio-common/tst-fphex.c b/stdio-common/tst-fphex.c
index 212e4ed..4465bfb 100644
--- a/stdio-common/tst-fphex.c
+++ b/stdio-common/tst-fphex.c
@@ -3,30 +3,52 @@
#include <stdio.h>
#include <string.h>
+#ifndef STR_LEN
+# define STR_LEN strlen
+#endif
+#ifndef STR_CMP
+# define STR_CMP strcmp
+#endif
+#ifndef SPRINT
+# define SPRINT snprintf
+#endif
+#ifndef CHAR_T
+# define CHAR_T char
+#endif
+#ifndef PRINT
+# define PRINT printf
+#endif
+#ifndef L_
+# define L_(Str) Str
+#endif
+#ifndef L
+# define L
+#endif
+
struct testcase
{
double value;
- const char *fmt;
- const char *expect;
+ const CHAR_T *fmt;
+ const CHAR_T *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" },
+ { 0x0.0030p+0, L_("%a"), L_("0x1.8p-11") },
+ { 0x0.0040p+0, L_("%a"), L_("0x1p-10") },
+ { 0x0.0030p+0, L_("%040a"), L_("0x00000000000000000000000000000001.8p-11") },
+ { 0x0.0040p+0, L_("%040a"), L_("0x0000000000000000000000000000000001p-10") },
+ { 0x0.0040p+0, L_("%40a"), L_(" 0x1p-10") },
+ { 0x0.0040p+0, L_("%#40a"), L_(" 0x1.p-10") },
+ { 0x0.0040p+0, L_("%-40a"), L_("0x1p-10 ") },
+ { 0x0.0040p+0, L_("%#-40a"), L_("0x1.p-10 ") },
+ { 0x0.0030p+0, L_("%040e"), L_("00000000000000000000000000007.324219e-04") },
+ { 0x0.0040p+0, L_("%040e"), L_("00000000000000000000000000009.765625e-04") },
};
static int
-do_test (int argc, char **argv)
+do_test (void)
{
const struct testcase *t;
int result = 0;
@@ -35,12 +57,13 @@ do_test (int argc, char **argv)
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)
+ CHAR_T buf[1024];
+ int n = SPRINT (buf, sizeof buf / sizeof (buf[0]), t->fmt, t->value);
+ if (n != STR_LEN (t->expect) || STR_CMP (buf, t->expect) != 0)
{
- printf ("%s\tExpected \"%s\" (%Zu)\n\tGot \"%s\" (%d, %Zu)\n",
- t->fmt, t->expect, strlen (t->expect), buf, n, strlen (buf));
+ PRINT (L_("%" L "s\tExpected \"%" L "s\" (%Zu)\n\tGot \"%" L
+ "s\" (%d, %Zu)\n"), t->fmt, t->expect, STR_LEN (t->expect),
+ buf, n, STR_LEN (buf));
result = 1;
}
}
@@ -48,4 +71,5 @@ do_test (int argc, char **argv)
return result;
}
+#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"