1 #include <ccan/rbuf/rbuf.h>
2 /* Include the C files directly. */
3 #include <ccan/rbuf/rbuf.c>
4 #include <ccan/tap/tap.h>
15 int i, fd = open("test/run.c", O_RDONLY), len;
17 /* This is how many tests you plan to run */
20 /* Grab ourselves for comparison. */
21 len = read(fd, buf, sizeof(buf));
23 lseek(fd, SEEK_SET, 0);
25 for (i = 0, p = buf; *p; i++) {
33 rbuf_init(&in, fd, malloc(31), 31);
35 ok1(in.buf_end - in.buf == 31);
36 p = rbuf_read_str(&in, '\n', NULL);
38 ok1(strcmp(p, lines[0]) == 0);
40 p = rbuf_read_str(&in, '\n', realloc);
42 ok1(strcmp(p, lines[1]) == 0);
44 for (i = 2; lines[i]; i++) {
45 ok1(p = rbuf_read_str(&in, '\n', realloc));
46 ok1(strcmp(p, lines[i]) == 0);
49 p = rbuf_read_str(&in, '\n', realloc);
54 /* Another way of reading the entire (text) file. */
55 lseek(fd, SEEK_SET, 0);
56 rbuf_init(&in, fd, NULL, 0);
57 p = rbuf_read_str(&in, 0, realloc);
59 ok1(strlen(p) == len);
62 p = rbuf_read_str(&in, 0, realloc);