X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Foserver%2Ftest%2Frun.c;h=dc6031b9de547e715a4e6f54c80389afcc62fc4c;hb=55629c7a4496e0b559f30a8bf33af6cb3888d063;hp=3a93be8974e9976d51900b902dabe27d325126c6;hpb=b3458dbe49ae218f183affcb239433d66839e2c9;p=ccan-lca-2011.git diff --git a/ccan/oserver/test/run.c b/ccan/oserver/test/run.c index 3a93be8..dc6031b 100644 --- a/ccan/oserver/test/run.c +++ b/ccan/oserver/test/run.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -13,27 +14,38 @@ int main(void) int fd; int status; char buf[200]; + const char *input; /* This is how many tests you plan to run */ - plan_tests(3); + plan_tests(4 * 6); - 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); + foreach_ptr(input, + "This is a test\n", + "This is a test\r", + "This is a test\r\n", + "This is a test\nWith extra", + "This is a test\rWith extra", + "This is a test\r\nWith extra") { + fd = open("run-fd", O_RDWR|O_CREAT|O_TRUNC, 0600); - if (fork() == 0) - oserver_serve(fd); + write(fd, input, strlen(input)); + lseek(fd, 0, SEEK_SET); - wait(&status); + if (fork() == 0) + oserver_serve(fd); - ok1(WIFEXITED(status)); - ok1(WEXITSTATUS(status) == 0); + wait(&status); - lseek(fd, 0, SEEK_SET); - buf[read(fd, buf, sizeof(buf)-1)] = '\0'; + ok1(WIFEXITED(status)); + ok1(WEXITSTATUS(status) == 0); - ok1(streq(buf, "This is a test\n" - "Louder, like this: 'THIS IS A TEST'\r\n")); + lseek(fd, 0, SEEK_SET); + buf[read(fd, buf, sizeof(buf)-1)] = '\0'; + + ok1(strncmp(buf, input, strlen("This is a test")) == 0); + ok1(streq(buf + strlen("This is a test") + 1, + "Louder, like this: 'THIS IS A TEST'\r\n")); + } /* This exits depending on whether all tests passed */ return exit_status();