new test framework (one main per test)
[libc-test] / src / stdio / snprintf.c
index f8768a8..1187fd7 100644 (file)
@@ -1,4 +1,6 @@
+#ifndef _XOPEN_SOURCE
 #define _XOPEN_SOURCE 700
+#endif
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
@@ -67,10 +69,16 @@ static const struct {
        const char *expect;
 } fp_tests[] = {
        /* basic form, handling of exponent/precision for 0 */
+       { "%a", 0.0, "0x0p+0" },
        { "%e", 0.0, "0.000000e+00" },
        { "%f", 0.0, "0.000000" },
        { "%g", 0.0, "0" },
        { "%#g", 0.0, "0.00000" },
+       { "%la", 0.0, "0x0p+0" },
+       { "%le", 0.0, "0.000000e+00" },
+       { "%lf", 0.0, "0.000000" },
+       { "%lg", 0.0, "0" },
+       { "%#lg", 0.0, "0.00000" },
 
        /* rounding */
        { "%f", 1.1, "1.100000" },
@@ -81,6 +89,7 @@ static const struct {
        { "%.4f", 1.06125, "1.0612" },
        { "%.2f", 1.375, "1.38" },
        { "%.1f", 1.375, "1.4" },
+       { "%.1lf", 1.375, "1.4" },
        { "%.15f", 1.1, "1.100000000000000" },
        { "%.16f", 1.1, "1.1000000000000001" },
        { "%.17f", 1.1, "1.10000000000000009" },
@@ -116,10 +125,10 @@ static const struct {
        { NULL, 0.0, NULL }
 };
 
-void test_snprintf(void)
+int main(void)
 {
        int i, j, k;
-       char b[2000], *s;
+       char b[2000];
 
        TEST(i, snprintf(0, 0, "%d", 123456), 6, "length returned %d != %d");
        TEST(i, snprintf(0, 0, "%.4s", "hello"), 4, "length returned %d != %d");
@@ -161,4 +170,5 @@ void test_snprintf(void)
        }
 
        TEST(i, snprintf(0, 0, "%.4a", 1.0), 11, "%d != %d");
+       return test_status;
 }