summaryrefslogtreecommitdiff
path: root/src/test/test-json.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/test-json.c')
-rw-r--r--src/test/test-json.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/test/test-json.c b/src/test/test-json.c
index 5aa4d19dbe..fdf1b4f40c 100644
--- a/src/test/test-json.c
+++ b/src/test/test-json.c
@@ -1,9 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include <math.h>
-#if HAVE_VALGRIND_VALGRIND_H
-#include <valgrind/valgrind.h>
-#endif
#include "alloc-util.h"
#include "fd-util.h"
@@ -45,12 +42,13 @@ static void test_tokenizer(const char *data, ...) {
d = va_arg(ap, long double);
-#if HAVE_VALGRIND_VALGRIND_H
- if (!RUNNING_ON_VALGRIND)
-#endif
- /* Valgrind doesn't support long double calculations and automatically downgrades to 80bit:
- * http://www.valgrind.org/docs/manual/manual-core.html#manual-core.limits */
- assert_se(fabsl(d - v.real) < 0.001L);
+ /* Valgrind doesn't support long double calculations and automatically downgrades to 80bit:
+ * http://www.valgrind.org/docs/manual/manual-core.html#manual-core.limits.
+ * Some architectures might not support long double either.
+ */
+
+ assert_se(fabsl(d - v.real) < 1e-10 ||
+ fabsl((d - v.real) / v.real) < 1e-10);
} else if (t == JSON_TOKEN_INTEGER) {
intmax_t i;
@@ -211,7 +209,6 @@ static void test_2(JsonVariant *v) {
assert_se(p && json_variant_type(p) == JSON_VARIANT_REAL && fabsl(json_variant_real(p) - 1.27) < 0.001);
}
-
static void test_zeroes(JsonVariant *v) {
size_t i;
@@ -285,6 +282,7 @@ static void test_build(void) {
a = json_variant_unref(a);
b = json_variant_unref(b);
+ const char* arr_1234[] = {"one", "two", "three", "four", NULL};
assert_se(json_build(&a, JSON_BUILD_ARRAY(JSON_BUILD_OBJECT(JSON_BUILD_PAIR("x", JSON_BUILD_BOOLEAN(true)),
JSON_BUILD_PAIR("y", JSON_BUILD_OBJECT(JSON_BUILD_PAIR("this", JSON_BUILD_NULL)))),
JSON_BUILD_VARIANT(NULL),
@@ -292,8 +290,9 @@ static void test_build(void) {
JSON_BUILD_STRING(NULL),
JSON_BUILD_NULL,
JSON_BUILD_INTEGER(77),
- JSON_BUILD_ARRAY(JSON_BUILD_VARIANT(JSON_VARIANT_STRING_CONST("foobar")), JSON_BUILD_VARIANT(JSON_VARIANT_STRING_CONST("zzz"))),
- JSON_BUILD_STRV(STRV_MAKE("one", "two", "three", "four")))) >= 0);
+ JSON_BUILD_ARRAY(JSON_BUILD_VARIANT(JSON_VARIANT_STRING_CONST("foobar")),
+ JSON_BUILD_VARIANT(JSON_VARIANT_STRING_CONST("zzz"))),
+ JSON_BUILD_STRV((char**) arr_1234))) >= 0);
assert_se(json_variant_format(a, 0, &s) >= 0);
log_info("GOT: %s\n", s);