]> git.ozlabs.org Git - ccan-lca-2011.git/commitdiff
lca2011: test
authorRusty Russell <rusty@rustcorp.com.au>
Fri, 21 Jan 2011 03:37:27 +0000 (14:07 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Fri, 21 Jan 2011 03:37:27 +0000 (14:07 +1030)
ccan/oserver/_info
ccan/oserver/test/run.c [new file with mode: 0644]

index 087b0436185d69db59678f70e8e232210aaa900c..e73e85555272a8ed3abc6eccf2108893206f8964 100644 (file)
@@ -37,6 +37,7 @@ int main(int argc, char *argv[])
        if (strcmp(argv[1], "depends") == 0) {
                printf("ccan/compiler\n");
                printf("ccan/read_write_all\n");
+               printf("ccan/str\n");
                return 0;
        }
 
diff --git a/ccan/oserver/test/run.c b/ccan/oserver/test/run.c
new file mode 100644 (file)
index 0000000..3a93be8
--- /dev/null
@@ -0,0 +1,40 @@
+#include <ccan/oserver/oserver.h>
+#include <ccan/oserver/oserver.c>
+#include <ccan/str/str.h>
+#include <ccan/tap/tap.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <sys/wait.h>
+
+int main(void)
+{
+       int fd;
+       int status;
+       char buf[200];
+
+       /* This is how many tests you plan to run */
+       plan_tests(3);
+
+       fd = open("run-fd", O_RDWR|O_CREAT|O_TRUNC, 0600);
+       write(fd, "This is a test\n", sizeof("This is a test\n"));
+       lseek(fd, 0, SEEK_SET);
+
+       if (fork() == 0)
+               oserver_serve(fd);
+
+       wait(&status);
+
+       ok1(WIFEXITED(status));
+       ok1(WEXITSTATUS(status) == 0);
+
+       lseek(fd, 0, SEEK_SET);
+       buf[read(fd, buf, sizeof(buf)-1)] = '\0';
+
+       ok1(streq(buf, "This is a test\n"
+                 "Louder, like this: 'THIS IS A TEST'\r\n"));
+
+       /* This exits depending on whether all tests passed */
+       return exit_status();
+}