From 55629c7a4496e0b559f30a8bf33af6cb3888d063 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 21 Jan 2011 14:08:50 +1030 Subject: [PATCH] lca2011: enhance test/run to use ccan/foreach --- ccan/oserver/_info | 1 + ccan/oserver/test/run.c | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/ccan/oserver/_info b/ccan/oserver/_info index e73e855..a05fa03 100644 --- a/ccan/oserver/_info +++ b/ccan/oserver/_info @@ -38,6 +38,7 @@ int main(int argc, char *argv[]) printf("ccan/compiler\n"); printf("ccan/read_write_all\n"); printf("ccan/str\n"); + printf("ccan/foreach\n"); return 0; } diff --git a/ccan/oserver/test/run.c b/ccan/oserver/test/run.c index f6c5b45..dc6031b 100644 --- a/ccan/oserver/test/run.c +++ b/ccan/oserver/test/run.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include #include @@ -11,23 +11,24 @@ int main(void) { - int fd, i; + int fd; int status; char buf[200]; - const char *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" }; + const char *input; /* This is how many tests you plan to run */ - plan_tests(4 * ARRAY_SIZE(input)); - - for (i = 0; i < ARRAY_SIZE(input); i++) { + plan_tests(4 * 6); + + 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); - write(fd, input[i], strlen(input[i])); + write(fd, input, strlen(input)); lseek(fd, 0, SEEK_SET); if (fork() == 0) @@ -41,11 +42,11 @@ int main(void) lseek(fd, 0, SEEK_SET); buf[read(fd, buf, sizeof(buf)-1)] = '\0'; - ok1(strncmp(buf, input[i], strlen("This is a test")) == 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(); } -- 2.39.2