6 #define TEST(r, f, x, m) ( \
7 ((r) = (f)) == (x) || \
8 (t_error("%s failed (" m ")\n", #f, r, x), 0) )
10 #define TEST_S(s, x, m) ( \
12 (t_error("[%s] != [%s] (%s)\n", s, x, m), 0) )
15 TEST(i, sscanf(# x, "%lf", &d), 1, "got %d fields, expected %d"), \
16 TEST(t, d, (double)x, "%g != %g") )
25 TEST(i
, sscanf("hello, world\n", "%s %s", a
, b
), 2, "only %d fields, expected %d");
26 TEST_S(a
, "hello,", "");
27 TEST_S(b
, "world", "");
29 TEST(i
, sscanf("hello, world\n", "%[hel]%s", a
, b
), 2, "only %d fields, expected %d");
30 TEST_S(a
, "hell", "");
33 TEST(i
, sscanf("hello, world\n", "%[hel] %s", a
, b
), 2, "only %d fields, expected %d");
34 TEST_S(a
, "hell", "");
39 TEST(i
, sscanf("hello, world\n", "%8c%8c", a
, b
), 1, "%d fields, expected %d");
40 TEST_S(a
, "hello, wX", "");
42 TEST(i
, sscanf("56789 0123 56a72", "%2d%d%*d %[0123456789]\n", &x
, &y
, a
), 3, "only %d fields, expected %d");
43 TEST(i
, x
, 56, "%d != %d");
44 TEST(i
, y
, 789, "%d != %d");
47 TEST(i
, sscanf("011 0x100 11 0x100 100", "%i %i %o %x %x\n", &x
, &y
, &z
, &u
, &v
), 5, "only %d fields, expected %d");
48 TEST(i
, x
, 9, "%d != %d");
49 TEST(i
, y
, 256, "%d != %d");
50 TEST(i
, z
, 9, "%d != %d");
51 TEST(i
, u
, 256, "%d != %d");
52 TEST(i
, v
, 256, "%d != %d");
54 TEST(i
, sscanf("20 xyz", "%d %d\n", &x
, &y
), 1, "only %d fields, expected %d");
55 TEST(i
, x
, 20, "%d != %d");
57 TEST(i
, sscanf("xyz", "%d %d\n", &x
, &y
), 0, "got %d fields, expected no match (%d)");
59 TEST(i
, sscanf("", "%d %d\n", &x
, &y
), -1, "got %d fields, expected input failure (%d)");
61 TEST(i
, sscanf(" 12345 6", "%2d%d%d", &x
, &y
, &z
), 3, "only %d fields, expected %d");
62 TEST(i
, x
, 12, "%d != %d");
63 TEST(i
, y
, 345, "%d != %d");
64 TEST(i
, z
, 6, "%d != %d");
66 TEST(i
, sscanf(" 0x12 0x34", "%5i%2i", &x
, &y
), 1, "got %d fields, expected %d");
67 TEST(i
, x
, 0x12, "%d != %d");
83 TEST(i
, sscanf("10e", "%lf", &d
), 0, "got %d fields, expected no match (%d)");
84 TEST(i
, sscanf("", "%lf\n", &d
), -1, "got %d fields, expected input failure (%d)");