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

Function main

ccan/ccan/rbuf/test/run-partial-read.c:22–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20#include <stdlib.h>
21
22int main(void)
23{
24 struct rbuf in;
25 char buf[4096];
26 char *lines[100], *p;
27 int i, fd = open("test/run.c", O_RDONLY);
28
29 /* This is how many tests you plan to run */
30 plan_tests(160);
31
32 /* Grab ourselves for comparison. */
33 buf[full_read(fd, buf, sizeof(buf))] = '\0';
34 lseek(fd, 0, SEEK_SET);
35
36 for (i = 0, p = buf; *p; i++) {
37 lines[i] = p;
38 p = strchr(p, '\n');
39 *p = '\0';
40 p++;
41 }
42 lines[i] = NULL;
43
44 rbuf_init(&in, fd, malloc(31), 31, membuf_realloc);
45 ok1(in.fd == fd);
46 ok1(membuf_num_space(&in.m) == 31);
47 p = rbuf_read_str(&in, '\n');
48 ok1(p);
49 ok1(strcmp(p, lines[0]) == 0);
50
51 p = rbuf_read_str(&in, '\n');
52 ok1(p);
53 ok1(strcmp(p, lines[1]) == 0);
54
55 for (i = 2; lines[i]; i++) {
56 ok1(p = rbuf_read_str(&in, '\n'));
57 ok1(strcmp(p, lines[i]) == 0);
58 }
59
60 p = rbuf_read_str(&in, '\n');
61 ok1(errno == 0);
62 ok1(p == NULL);
63 free(rbuf_cleanup(&in));
64
65 /* This exits depending on whether all tests passed */
66 return exit_status();
67}

Callers

nothing calls this directly

Calls 4

full_readFunction · 0.85
rbuf_initFunction · 0.85
rbuf_read_strFunction · 0.85
rbuf_cleanupFunction · 0.85

Tested by

no test coverage detected