X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Ftest%2Ftest-util.c;h=93929cd9fca7b26c96e1db619af6a1fc912cbd3b;hb=8fe65c03fce8739c0799231e46a3ad99ec53deb3;hp=6297182e0bdb714c54b3e16ca4e244cc7cc319c4;hpb=29bfbcd675d750c0af4d7dae217722932249e435;p=elogind.git diff --git a/src/test/test-util.c b/src/test/test-util.c index 6297182e0..93929cd9f 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -67,7 +67,7 @@ static void test_close_many(void) { assert_se(fcntl(fds[1], F_GETFD) == -1); assert_se(fcntl(fds[2], F_GETFD) >= 0); - close_nointr_nofail(fds[2]); + safe_close(fds[2]); unlink(name0); unlink(name1); @@ -645,6 +645,36 @@ static void test_hexdump(void) { hexdump(stdout, data, sizeof(data)); } +static void test_log2i(void) { + assert_se(log2i(1) == 0); + assert_se(log2i(2) == 1); + assert_se(log2i(3) == 1); + assert_se(log2i(4) == 2); + assert_se(log2i(32) == 5); + assert_se(log2i(33) == 5); + assert_se(log2i(63) == 5); + 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(); @@ -687,6 +717,8 @@ int main(int argc, char *argv[]) { test_in_set(); test_writing_tmpfile(); test_hexdump(); + test_log2i(); + test_foreach_string(); return 0; }