From 1fceb2207aed183c4855b3ad48ec886bbb06ae85 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Mon, 1 Aug 2016 15:04:54 +0200 Subject: [PATCH] test: add test of 'json_object_to_json_string_length' MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The test is implied in test1. The idea is to check that the returned lengths and strings are identical to what is expected to return the already tested function 'json_object_to_json_string_ext'. Signed-off-by: José Bollo --- tests/test1.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/test1.c b/tests/test1.c index 3cbd1860..05956d13 100644 --- a/tests/test1.c +++ b/tests/test1.c @@ -28,7 +28,27 @@ static int sort_fn (const void *j1, const void *j2) } #ifdef TEST_FORMATTED -#define json_object_to_json_string(obj) json_object_to_json_string_ext(obj,sflags) +static const char *to_json_string(json_object *obj, int flags) +{ + size_t length; + char *copy; + const char *result; + + result = json_object_to_json_string_length(obj, flags, &length); + copy = strndup(result, length); + if (copy == NULL) + printf("to_json_string: Allocation failed!\n"); + else { + result = json_object_to_json_string_ext(obj, flags); + if (length != strlen(result)) + printf("to_json_string: Length mismatch!\n"); + if (strcmp(copy, result) != 0) + printf("to_json_string: Comparison Failed!\n"); + free(copy); + } + return result; +} +#define json_object_to_json_string(obj) to_json_string(obj,sflags) #else /* no special define */ #endif -- 2.39.5