MCPcopy Create free account
hub / github.com/ElementsProject/lightning / main

Function main

ccan/ccan/rbuf/test/run-term-eof.c:18–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16}
17
18int main(void)
19{
20 struct rbuf in;
21 char buf[4096], *p;
22 int fd = open("test/run-term-eof.c", O_RDONLY), len;
23
24 /* This is how many tests you plan to run */
25 plan_tests(10);
26
27 /* Grab ourselves for comparison. */
28 len = read(fd, buf, sizeof(buf));
29 buf[len] = '\0';
30 lseek(fd, 0, SEEK_SET);
31
32 /* We have exact-size buffer, which causes problems adding term. */
33 rbuf_init(&in, fd, malloc(len), len, test_realloc);
34 test_realloc_fail = true;
35 p = rbuf_read_str(&in, 64); /* At symbol does not appear. */
36 ok1(errno == ENOMEM);
37 ok1(!p);
38 /* This should succeed... */
39 test_realloc_fail = false;
40 p = rbuf_read_str(&in, 64);
41 ok1(p);
42 ok1(strcmp(p, buf) == 0);
43 ok1(rbuf_start(&in) == p + strlen(p));
44 free(rbuf_cleanup(&in));
45
46 /* Try again. */
47 lseek(fd, 0, SEEK_SET);
48 rbuf_init(&in, fd, malloc(len), len, test_realloc);
49 p = rbuf_read_str(&in, 64);
50 ok1(p);
51 ok1(strcmp(p, buf) == 0);
52 ok1(rbuf_start(&in) == p + strlen(p));
53 free(rbuf_cleanup(&in));
54
55 /* Normal case, we get rbuf_start after nul */
56 lseek(fd, 0, SEEK_SET);
57 rbuf_init(&in, fd, NULL, 0, test_realloc);
58 p = rbuf_read_str(&in, '^');
59 ok1(p);
60 ok1(rbuf_start(&in) == p + strlen(p) + 1);
61 free(rbuf_cleanup(&in));
62
63 return exit_status();
64}

Callers

nothing calls this directly

Calls 4

rbuf_initFunction · 0.85
rbuf_read_strFunction · 0.85
rbuf_startFunction · 0.85
rbuf_cleanupFunction · 0.85

Tested by

no test coverage detected