From c4a7b2c56e907e39fa9a6cdb21c1970464abd44e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 19 Mar 2014 00:54:41 +0100 Subject: util: add new FOREACH_STRING() macro as syntactic sugar to iterate through a number of fixed strings --- src/test/test-util.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/test/test-util.c') diff --git a/src/test/test-util.c b/src/test/test-util.c index 1d952ebf1d..93929cd9fc 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -656,6 +656,25 @@ static void test_log2i(void) { assert_se(log2i(INT_MAX) == sizeof(int)*8-2); } +static void test_foreach_string(void) { + const char * const t[] = { + "foo", + "bar", + "waldo", + NULL + }; + const char *x; + unsigned i = 0; + + FOREACH_STRING(x, "foo", "bar", "waldo") + assert_se(streq_ptr(t[i++], x)); + + assert_se(i == 3); + + FOREACH_STRING(x, "zzz") + assert_se(streq(x, "zzz")); +} + int main(int argc, char *argv[]) { log_parse_environment(); log_open(); @@ -699,6 +718,7 @@ int main(int argc, char *argv[]) { test_writing_tmpfile(); test_hexdump(); test_log2i(); + test_foreach_string(); return 0; } -- cgit v1.2.3-54-g00ecf