1 #include <ccan/rbuf/rbuf.h>
2 /* Include the C files directly. */
3 #include <ccan/rbuf/rbuf.c>
4 #include <ccan/tap/tap.h>
10 static bool test_realloc_fail;
11 static void *test_realloc(struct membuf *mb, void *buf, size_t n)
13 if (test_realloc_fail)
15 return realloc(buf, n);
22 int i, size, fd = open("run-all-file", O_WRONLY|O_CREAT, 0600);
24 /* This is how many tests you plan to run */
27 /* Make sure we're bigger than a single buffer! */
28 size = rbuf_good_size(fd)*2;
29 for (i = 0; i * sizeof(buf) < size; i++) {
30 memset(buf, 0x42 + i, sizeof(buf));
31 write(fd, buf, sizeof(buf));
35 ok1(rbuf_open(&in, "run-all-file", NULL, 0, test_realloc));
36 /* Can't fill if realloc fails. */
37 test_realloc_fail = true;
40 test_realloc_fail = false;
42 /* But can't load in whole file. */
43 test_realloc_fail = true;
44 ok1(!rbuf_fill_all(&in));
46 test_realloc_fail = false;
47 ok1(rbuf_fill_all(&in));
48 ok1(rbuf_len(&in) == size);
49 for (i = 0; i * sizeof(buf) < size; i++) {
50 memset(buf, 0x42 + i, sizeof(buf));
51 if (memcmp(buf, rbuf_start(&in), sizeof(buf)) != 0) {
52 fail("Bad buffer contents");
55 rbuf_consume(&in, sizeof(buf));
57 free(membuf_cleanup(&in.m));
59 /* This exits depending on whether all tests passed */