summaryrefslogtreecommitdiff
path: root/stdio-common/tst-fphex.c
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 /stdio-common/tst-fphex.c
parent67c6a3d919b492c68664c4b95e84efd2174309e7 (diff)
Enhance fphex test.
Diffstat (limited to 'stdio-common/tst-fphex.c')
-rw-r--r--stdio-common/tst-fphex.c60
1 files changed, 42 insertions, 18 deletions
diff --git a/stdio-common/tst-fphex.c b/stdio-common/tst-fphex.c
index 212e4ed9ec..4465bfb81a 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"