fix snprintf "%#.0o" test
[libc-test] / src / functional / snprintf.c
index fefe814..c96f151 100644 (file)
 
 #define TEST(r, f, x, m) ( \
        ((r) = (f)) == (x) || \
-       (error("%s failed (" m ")\n", #f, r, x), 0) )
+       (t_error("%s failed (" m ")\n", #f, r, x), 0) )
 
 #define TEST_S(s, x, m) ( \
        !strcmp((s),(x)) || \
-       (error("[%s] != [%s] (%s)\n", s, x, m), 0) )
+       (t_error("[%s] != [%s] (%s)\n", s, x, m), 0) )
 
 static const struct {
        const char *fmt;
@@ -36,11 +36,11 @@ static const struct {
        { "%0-5d", 12, "12   " },
        { "%-05d", 12, "12   " },
 
-       /* ...explicit precision of 0 shall be no characters. */
+       /* ...explicit precision of 0 shall be no characters except for alt-octal. */
        { "%.0d", 0, "" },
        { "%.0o", 0, "" },
        { "%#.0d", 0, "" },
-       { "%#.0o", 0, "" },
+       { "%#.0o", 0, "0" },
        { "%#.0x", 0, "" },
 
        /* ...but it still has to honor width and flags. */
@@ -86,7 +86,8 @@ static const struct {
        { "%f", 1.3, "1.300000" },
        { "%f", 1.4, "1.400000" },
        { "%f", 1.5, "1.500000" },
-       { "%.4f", 1.06125, "1.0612" },
+       { "%.4f", 1.06125, "1.0613" }, /* input is not representible exactly as double */
+       { "%.4f", 1.03125, "1.0312" }, /* 0x1.08p0 */
        { "%.2f", 1.375, "1.38" },
        { "%.1f", 1.375, "1.4" },
        { "%.1lf", 1.375, "1.4" },
@@ -162,23 +163,23 @@ int main(void)
        for (j=0; int_tests[j].fmt; j++) {
                i = snprintf(b, sizeof b, int_tests[j].fmt, int_tests[j].i);
                if (i != strlen(int_tests[j].expect)) {
-                       error("snprintf(b, sizeof b, \"%s\", %d) returned %d wanted %d\n",
+                       t_error("snprintf(b, sizeof b, \"%s\", %d) returned %d wanted %d\n",
                                int_tests[j].fmt, int_tests[j].i, i, strlen(int_tests[j].expect));
                }
                if (strcmp(b, int_tests[j].expect) != 0)
-                       error("bad integer conversion: got \"%s\", want \"%s\"\n", b, int_tests[j].expect);
+                       t_error("bad integer conversion: got \"%s\", want \"%s\"\n", b, int_tests[j].expect);
        }
 
        for (j=0; fp_tests[j].fmt; j++) {
                i = snprintf(b, sizeof b, fp_tests[j].fmt, fp_tests[j].f);
                if (i != strlen(fp_tests[j].expect)) {
-                       error("snprintf(b, sizeof b, \"%s\", %f) returned %d wanted %d\n",
+                       t_error("snprintf(b, sizeof b, \"%s\", %f) returned %d wanted %d\n",
                                fp_tests[j].fmt, fp_tests[j].f, i, strlen(fp_tests[j].expect));
                }
                if (strcmp(b, fp_tests[j].expect) != 0)
-                       error("bad floating-point conversion: got \"%s\", want \"%s\"\n", b, fp_tests[j].expect);
+                       t_error("bad floating-point conversion: got \"%s\", want \"%s\"\n", b, fp_tests[j].expect);
        }
 
        TEST(i, snprintf(0, 0, "%.4a", 1.0), 11, "%d != %d");
-       return test_status;
+       return t_status;
 }