3 static ssize_t partial_read(int fd, void *buf, size_t count)
5 return read(fd, buf, 1);
7 static ssize_t full_read(int fd, void *buf, size_t count)
9 return read(fd, buf, count);
11 #define read partial_read
13 #include <ccan/rbuf/rbuf.h>
14 /* Include the C files directly. */
15 #include <ccan/rbuf/rbuf.c>
16 #include <ccan/tap/tap.h>
17 #include <sys/types.h>
27 int i, fd = open("test/run.c", O_RDONLY);
29 /* This is how many tests you plan to run */
32 /* Grab ourselves for comparison. */
33 buf[full_read(fd, buf, sizeof(buf))] = '\0';
34 lseek(fd, SEEK_SET, 0);
36 for (i = 0, p = buf; *p; i++) {
44 rbuf_init(&in, fd, malloc(31), 31, membuf_realloc);
46 ok1(membuf_num_space(&in.m) == 31);
47 p = rbuf_read_str(&in, '\n');
49 ok1(strcmp(p, lines[0]) == 0);
51 p = rbuf_read_str(&in, '\n');
53 ok1(strcmp(p, lines[1]) == 0);
55 for (i = 2; lines[i]; i++) {
56 ok1(p = rbuf_read_str(&in, '\n'));
57 ok1(strcmp(p, lines[i]) == 0);
60 p = rbuf_read_str(&in, '\n');
63 free(membuf_cleanup(&in.m));
65 /* This exits depending on whether all tests passed */