8 #define TEST(r, f, x, m) ( \
9 errno = 0, ((r) = (f)) == (x) || \
10 (t_error("%s failed (" m ")\n", #f, r, x, strerror(errno)), 0) )
12 #define TEST_S(s, x, m) ( \
14 (t_error("[%s] != [%s] (%s)\n", s, x, m), 0) )
22 TEST(i
, !(f
= tmpfile()), 0, "failed to create temp file %d!=%d (%s)");
24 if (!f
) return t_status
;
26 TEST(i
, fprintf(f
, "hello, world\n"), 13, "%d != %d (%m)");
27 TEST(i
, fseek(f
, 0, SEEK_SET
), 0, "%d != %d (%m)");
29 TEST(i
, feof(f
), 0, "%d != %d");
30 TEST(i
, fgetc(f
), 'h', "'%c' != '%c'");
31 TEST(i
, ftell(f
), 1, "%d != %d");
32 TEST(i
, ungetc('x', f
), 'x', "%d != %d");
33 TEST(i
, ftell(f
), 0, "%d != %d");
34 TEST(i
, fscanf(f
, "%[h]", a
), 0, "got %d fields, expected %d");
35 TEST(i
, ftell(f
), 0, "%d != %d");
36 TEST(i
, fgetc(f
), 'x', "'%c' != '%c'");
37 TEST(i
, ftell(f
), 1, "%d != %d");
39 TEST(i
, fseek(f
, 0, SEEK_SET
), 0, "%d != %d");
40 TEST(i
, ungetc('x', f
), 'x', "%d != %d");
41 TEST(i
, fread(a
, 1, sizeof a
, f
), 14, "read %d, expected %d");
43 TEST_S(a
, "xhello, world\n", "mismatch reading ungot character");
45 TEST(i
, fseek(f
, 0, SEEK_SET
), 0, "%d != %d");
46 TEST(i
, fscanf(f
, "%[x]", a
), 0, "got %d fields, expected %d");
47 TEST(i
, ungetc('x', f
), 'x', "unget failed after fscanf: %d != %d");
48 TEST(i
, fgetc(f
), 'x', "'%c' != '%c'");
49 TEST(i
, fgetc(f
), 'h', "'%c' != '%c'");