]> git.ozlabs.org Git - ccan-lca-2011.git/blob - ccan/oserver/test/run.c
3a93be8974e9976d51900b902dabe27d325126c6
[ccan-lca-2011.git] / ccan / oserver / test / run.c
1 #include <ccan/oserver/oserver.h>
2 #include <ccan/oserver/oserver.c>
3 #include <ccan/str/str.h>
4 #include <ccan/tap/tap.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
8 #include <string.h>
9 #include <sys/wait.h>
10
11 int main(void)
12 {
13         int fd;
14         int status;
15         char buf[200];
16
17         /* This is how many tests you plan to run */
18         plan_tests(3);
19
20         fd = open("run-fd", O_RDWR|O_CREAT|O_TRUNC, 0600);
21         write(fd, "This is a test\n", sizeof("This is a test\n"));
22         lseek(fd, 0, SEEK_SET);
23
24         if (fork() == 0)
25                 oserver_serve(fd);
26
27         wait(&status);
28
29         ok1(WIFEXITED(status));
30         ok1(WEXITSTATUS(status) == 0);
31
32         lseek(fd, 0, SEEK_SET);
33         buf[read(fd, buf, sizeof(buf)-1)] = '\0';
34
35         ok1(streq(buf, "This is a test\n"
36                   "Louder, like this: 'THIS IS A TEST'\r\n"));
37
38         /* This exits depending on whether all tests passed */
39         return exit_status();
40 }