X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Ftest%2Ftest-util.c;h=1850f97723b6641d67992f5d07bb4f388a298c75;hb=ce049dcda4a9d0c9a44667ca82bc9e21d7ea7748;hp=ed91a67d10f25bbb4aa7a4f4d07d9515c4c27997;hpb=1cb1767a29458b3d16d6b161b4ee34dd496ff60d;p=elogind.git diff --git a/src/test/test-util.c b/src/test/test-util.c index ed91a67d1..1850f9772 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "util.h" #include "mkdir.h" @@ -129,6 +130,7 @@ static void test_parse_boolean(void) { assert_se(parse_boolean("garbage") < 0); assert_se(parse_boolean("") < 0); + assert_se(parse_boolean("full") < 0); } static void test_parse_pid(void) { @@ -190,7 +192,7 @@ static void test_safe_atod(void) { r = safe_atod("0.2244", &d); assert_se(r == 0); - assert_se(abs(d - 0.2244) < 0.000001); + assert_se(fabs(d - 0.2244) < 0.000001); r = safe_atod("0,5", &d); assert_se(r == -EINVAL); @@ -204,20 +206,20 @@ static void test_safe_atod(void) { r = safe_atod("0.2244", &d); assert_se(r == 0); - assert_se(abs(d - 0.2244) < 0.000001); + assert_se(fabs(d - 0.2244) < 0.000001); r = safe_atod("0,5", &d); assert_se(r == -EINVAL); errno = 0; - assert_se(abs(strtod("0,5", &e) - 0.5) < 0.00001); + assert_se(fabs(strtod("0.5", &e) - 0.5) < 0.00001); /* And check again, reset */ setlocale(LC_NUMERIC, "C"); r = safe_atod("0.2244", &d); assert_se(r == 0); - assert_se(abs(d - 0.2244) < 0.000001); + assert_se(fabs(d - 0.2244) < 0.000001); r = safe_atod("0,5", &d); assert_se(r == -EINVAL); @@ -310,7 +312,7 @@ static void test_cunescape(void) { } static void test_foreach_word(void) { - char *w, *state; + const char *word, *state; size_t l; int i = 0; const char test[] = "test abc d\te f "; @@ -324,13 +326,12 @@ static void test_foreach_word(void) { NULL }; - FOREACH_WORD(w, l, test, state) { - assert_se(strneq(expected[i++], w, l)); - } + FOREACH_WORD(word, l, test, state) + assert_se(strneq(expected[i++], word, l)); } static void test_foreach_word_quoted(void) { - char *w, *state; + const char *word, *state; size_t l; int i = 0; const char test[] = "test a b c 'd' e '' '' hhh '' '' \"a b c\""; @@ -351,13 +352,14 @@ static void test_foreach_word_quoted(void) { }; printf("<%s>\n", test); - FOREACH_WORD_QUOTED(w, l, test, state) { + FOREACH_WORD_QUOTED(word, l, test, state) { _cleanup_free_ char *t = NULL; - assert_se(t = strndup(w, l)); - assert_se(strneq(expected[i++], w, l)); + assert_se(t = strndup(word, l)); + assert_se(strneq(expected[i++], word, l)); printf("<%s>\n", t); } + assert(isempty(state)); } static void test_default_term_for_tty(void) { @@ -905,6 +907,19 @@ static void test_strshorten(void) { assert_se(strlen(strshorten(s, 0)) == 0); } +static void test_strappenda(void) { + char *actual; + + actual = strappenda("", "foo", "bar"); + assert_se(streq(actual, "foobar")); + + actual = strappenda("foo", "bar", "baz"); + assert_se(streq(actual, "foobarbaz")); + + actual = strappenda("foo", "", "bar", "baz"); + assert_se(streq(actual, "foobarbaz")); +} + int main(int argc, char *argv[]) { log_parse_environment(); log_open(); @@ -963,6 +978,7 @@ int main(int argc, char *argv[]) { test_read_one_char(); test_ignore_signals(); test_strshorten(); + test_strappenda(); return 0; }