chiark / gitweb /
test: fix strtod() test
[elogind.git] / src / test / test-util.c
index 470475aa5d8b307cff8b93e82fd0149e21ce869a..1850f97723b6641d67992f5d07bb4f388a298c75 100644 (file)
@@ -26,6 +26,7 @@
 #include <locale.h>
 #include <errno.h>
 #include <signal.h>
+#include <math.h>
 
 #include "util.h"
 #include "mkdir.h"
@@ -191,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);
@@ -205,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);
@@ -906,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();
@@ -964,6 +978,7 @@ int main(int argc, char *argv[]) {
         test_read_one_char();
         test_ignore_signals();
         test_strshorten();
+        test_strappenda();
 
         return 0;
 }