]> git.ozlabs.org Git - ccan/blob - ccan/grab_file/test/run-grab.c
Fix sequence logic bug, and satisfies() logic fix/cleanup.
[ccan] / ccan / grab_file / test / run-grab.c
1 /* This is test for grab_file() function
2  */
3 #include        "grab_file/grab_file.h"
4 #include        <stdlib.h>
5 #include        <stdio.h>
6 #include        <err.h>
7 #include        <sys/stat.h>
8 #include        "grab_file/grab_file.c"
9 #include        "tap/tap.h"
10 #include        "str_talloc/str_talloc.h"
11 #include        "str/str.h"
12
13 int 
14 main(int argc, char *argv[])
15 {
16         unsigned int    i;
17         char            **split, *str;
18         int             length;
19         struct          stat st;
20
21         str = grab_file(NULL, "ccan/grab_file/test/run-grab.c", NULL);
22         split = strsplit(NULL, str, "\n", NULL);
23         length = strlen(split[0]);
24         ok1(streq(split[0], "/* This is test for grab_file() function"));
25         for (i = 1; split[i]; i++)      
26                 length += strlen(split[i]);
27         ok1(streq(split[i-1], "/* End of grab_file() test */"));
28         if (stat("ccan/grab_file/test/run-grab.c", &st) != 0) 
29                 err(1, "Could not stat self");
30         ok1(st.st_size == length + i);
31         
32         return 0;
33 }
34
35 /* End of grab_file() test */