]> git.ozlabs.org Git - ccan/blob - ccan/grab_file/test/run-grab.c
b3c18e5a4db20369c42096c00734b1e4ce098a9c
[ccan] / ccan / grab_file / test / run-grab.c
1 /* This is test for grab_file() function
2  */
3 #include <ccan/grab_file/grab_file.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <err.h>
7 #include <sys/stat.h>
8 #include <ccan/grab_file/grab_file.c>
9 #include <ccan/tap/tap.h>
10 #include <ccan/str_talloc/str_talloc.h>
11 #include <ccan/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, "test/run-grab.c", NULL);
22         /* FIXME: run_tests runs us from top level dir.  Kill this */
23         if (!str)
24                 str = grab_file(NULL, "ccan/grab_file/test/run-grab.c", NULL);
25         split = strsplit(NULL, str, "\n", NULL);
26         length = strlen(split[0]);
27         ok1(streq(split[0], "/* This is test for grab_file() function"));
28         for (i = 1; split[i]; i++)      
29                 length += strlen(split[i]);
30         ok1(streq(split[i-1], "/* End of grab_file() test */"));
31         if (stat("test/run-grab.c", &st) != 0) 
32                 /* FIXME: ditto */
33                 if (stat("ccan/grab_file/test/run-grab.c", &st) != 0) 
34                         err(1, "Could not stat self");
35         ok1(st.st_size == length + i);
36         
37         return 0;
38 }
39
40 /* End of grab_file() test */