From 004c69a27f4e2928c7a1963a4b79b2b66a1d3183 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 18 Jun 2024 12:21:31 +0200 Subject: sd-json: add sd_json_build() wrapper macro that implies SD_JSON_BUILD_OBJECT() In 99% of uses of sd_json_build() we want to build an object as outermost construct. Let's shorten this most common case a bit, by adding sd_json_buildo() that implies this. This allows us to shorten much of our code, all across the tree. --- src/test/test-json.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/test/test-json.c') diff --git a/src/test/test-json.c b/src/test/test-json.c index a3e7fe29af..69fb0859c7 100644 --- a/src/test/test-json.c +++ b/src/test/test-json.c @@ -412,6 +412,21 @@ TEST(build) { assert_se(sd_json_variant_equal(ssv, ssv2)); } +TEST(json_buildo) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *a = NULL, *b = NULL; + + assert_se(sd_json_buildo(&a, + SD_JSON_BUILD_PAIR("foo", SD_JSON_BUILD_INTEGER(4711)), + SD_JSON_BUILD_PAIR("bar", SD_JSON_BUILD_STRING("xxxx"))) >= 0); + + assert_se(sd_json_build(&b, + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR("bar", SD_JSON_BUILD_STRING("xxxx")), + SD_JSON_BUILD_PAIR("foo", SD_JSON_BUILD_INTEGER(4711)))) >= 0); + + assert_se(sd_json_variant_equal(a, b)); +} + TEST(json_parse_file_empty) { _cleanup_fclose_ FILE *f = NULL; _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; -- cgit v1.2.3