1 #define _POSIX_C_SOURCE 200809L
9 #define T(r, f, x, m) do { \
12 error("%s failed (got %d, expected %d, errno \"%s\") (%s)\n", \
13 #f, r, x, errno ? strerror(errno) : "", m); \
17 static void S(const char *s, const char *x, const char *m) {
18 if (strcmp(s, x) != 0)
19 error("got [%s], expected [%s] (%s)\n", s, x, m);
22 void test_fscanf(void) {
28 T(i, pipe(p), 0, "open pipe");
29 T(i, !(f = fdopen(p[0], "rb")), 0, "fdopen pipe");
36 T(i, write(p[1], "hello, world\n", 13), 13, "write to pipe");
37 T(i, fscanf(f, "%s %[own]", a, b), 2, "");
38 S(a, "hello,", "wrong result for %s");
39 S(b, "wo", "wrong result for %[own]");
40 T(i, fgetc(f), 'r', "fgetc 'r'");
42 T(i, write(p[1], " 0x12 0x34", 10), 10, "");
43 T(i, fscanf(f, "ld %5i%2i", &x, &y), 1, "");
45 T(i, fgetc(f), '3', "fgetc '3'");