diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-10-12 16:46:38 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-10-18 16:44:51 +0200 |
commit | d520d519f0ad8c7bdc65e4cb375a23e37fffbedc (patch) | |
tree | c0dec1038848286918d75a0c0531ad759184dab3 /src/test/test-json.c | |
parent | 4fcb507a909c60d8568b17fc8a9dbb8c83029c01 (diff) | |
download | systemd-d520d519f0ad8c7bdc65e4cb375a23e37fffbedc.tar.gz |
json: add support for using static const strings directly as JsonVariant objects
This is a nice little optimization when using static const strings: we
can now use them directly as JsonVariant objecs, without any additional
allocation.
Diffstat (limited to 'src/test/test-json.c')
-rw-r--r-- | src/test/test-json.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/test/test-json.c b/src/test/test-json.c index bcf94b211c..6a57f88882 100644 --- a/src/test/test-json.c +++ b/src/test/test-json.c @@ -292,6 +292,7 @@ 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); assert_se(json_variant_format(a, 0, &s) >= 0); @@ -355,12 +356,11 @@ static void test_source(void) { } static void test_depth(void) { - _cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *k = NULL; + _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; unsigned i; int r; - assert_se(json_variant_new_string(&k, "hallo") >= 0); - v = json_variant_ref(k); + v = JSON_VARIANT_STRING_CONST("start"); /* Let's verify that the maximum depth checks work */ @@ -371,7 +371,7 @@ static void test_depth(void) { if (i & 1) r = json_variant_new_array(&w, &v, 1); else - r = json_variant_new_object(&w, (JsonVariant*[]) { k, v }, 2); + r = json_variant_new_object(&w, (JsonVariant*[]) { JSON_VARIANT_STRING_CONST("key"), v }, 2); if (r == -ELNRNG) { log_info("max depth at %u", i); break; @@ -384,6 +384,7 @@ static void test_depth(void) { } json_variant_dump(v, 0, stdout, NULL); + fputs("\n", stdout); } int main(int argc, char *argv[]) { |