X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Ffscanf.c;h=62627b7fc54cd312d4b76c2056e6e2e50ba82395;hb=462b4f35652098e26c677f89df6990428a4aad6a;hp=d5da2383da3d1b406f60c4f38dd72efe11651518;hpb=80371a77c4d6978e786ab2322161c4f8e299e891;p=libc-test diff --git a/src/stdio/fscanf.c b/src/stdio/fscanf.c index d5da238..62627b7 100644 --- a/src/stdio/fscanf.c +++ b/src/stdio/fscanf.c @@ -6,7 +6,7 @@ #include #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", \ @@ -14,48 +14,38 @@ 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; }