new test framework (one main per test)
[libc-test] / src / stdio / fscanf.c
index d5da238..62627b7 100644 (file)
@@ -6,7 +6,7 @@
 #include <unistd.h>
 #include "test.h"
 
-#define T(r, f, x, m) do { \
+#define T(f, x, m) do { \
        r = (f); \
        if (r != (x)) \
                error("%s failed (got %d, expected %d, errno \"%s\") (%s)\n", \
        errno = 0; \
 } while (0)
 
-static void S(const char *s, const char *x, const char *m) {
-       if (strcmp(s, x) != 0)
-               error("got [%s], expected [%s] (%s)\n", s, x, m);
-}
-
-void test_scanf_long(void) {
-       enum {n = 1<<21};
-       char *s = malloc(n+1);
-       int i;
-       int r;
-
-       for (i = 0; i < n; i++) s[i] = '1';
-       s[n] = 0;
-       r = sscanf(s, "%d", &i);
-       free(s);
-}
+#define S(s, x, m) do { \
+       if (strcmp(s, x) != 0) \
+               error("got [%s] want [%s] (%s)\n", s, x, m); \
+} while(0)
 
-void test_fscanf(void) {
-       int i, x, y;
+int main(void)
+{
+       int r, x, y;
        char a[100], b[100];
        int p[2];
        FILE *f;
 
-       T(i, pipe(p), 0, "open pipe");
-       T(i, !(f = fdopen(p[0], "rb")), 0, "fdopen pipe");
+       T(pipe(p), 0, "open pipe");
+       T(!(f = fdopen(p[0], "rb")), 0, "fdopen pipe");
        if (!f) {
                close(p[0]);
                close(p[1]);
-               return;
+               return test_status;
        }
 
-       T(i, write(p[1], "hello, world\n", 13), 13, "write to pipe");
-       T(i, fscanf(f, "%s %[own]", a, b), 2, "");
+       T(write(p[1], "hello, world\n", 13), 13, "write to pipe");
+       T(fscanf(f, "%s %[own]", a, b), 2, "");
        S(a, "hello,", "wrong result for %s");
        S(b, "wo", "wrong result for %[own]");
-       T(i, fgetc(f), 'r', "fgetc 'r'");
+       T(fgetc(f), 'r', "fgetc 'r'");
 
-       T(i, write(p[1], " 0x12 0x34", 10), 10, "");
-       T(i, fscanf(f, "ld %5i%2i", &x, &y), 1, "");
-       T(i, x, 0x12, "");
-       T(i, fgetc(f), '3', "fgetc '3'");
+       T(write(p[1], " 0x12 0x34", 10), 10, "");
+       T(fscanf(f, "ld %5i%2i", &x, &y), 1, "");
+       T(x, 0x12, "");
+       T(fgetc(f), '3', "fgetc '3'");
 
        fclose(f);
        close(p[1]);
+       return test_status;
 }