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