diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-09-01 09:29:13 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-09-01 16:48:40 +0200 |
commit | 4d7f51756a5b665342f32f89ea7a2ea887e8fe01 (patch) | |
tree | a46370b92b866d8dd469ea889b808ccaf74e72c9 /src/test/test-json.c | |
parent | shared/json: reject non-utf-8 strings (diff) | |
download | systemd-4d7f51756a5b665342f32f89ea7a2ea887e8fe01.tar.xz systemd-4d7f51756a5b665342f32f89ea7a2ea887e8fe01.zip |
test-json: add function headers
Diffstat (limited to 'src/test/test-json.c')
-rw-r--r-- | src/test/test-json.c | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/src/test/test-json.c b/src/test/test-json.c index 3295287a67..6da93d6aed 100644 --- a/src/test/test-json.c +++ b/src/test/test-json.c @@ -3,6 +3,7 @@ #include <math.h> #include "alloc-util.h" +#include "escape.h" #include "fd-util.h" #include "fileio.h" #include "json-internal.h" @@ -17,6 +18,10 @@ static void test_tokenizer(const char *data, ...) { void *state = NULL; va_list ap; + _cleanup_free_ char *cdata; + assert_se(cdata = cescape(data)); + log_info("/* %s data=\"%s\" */", __func__, cdata); + va_start(ap, data); for (;;) { @@ -82,6 +87,10 @@ static void test_variant(const char *data, Test test) { _cleanup_free_ char *s = NULL; int r; + _cleanup_free_ char *cdata; + assert_se(cdata = cescape(data)); + log_info("/* %s data=\"%s\" */", __func__, cdata); + r = json_parse(data, 0, &v, NULL, NULL); assert_se(r == 0); assert_se(v); @@ -140,6 +149,8 @@ static void test_1(JsonVariant *v) { JsonVariant *p, *q; unsigned i; + log_info("/* %s */", __func__); + /* 3 keys + 3 values */ assert_se(json_variant_elements(v) == 6); @@ -173,6 +184,8 @@ static void test_1(JsonVariant *v) { static void test_2(JsonVariant *v) { JsonVariant *p, *q; + log_info("/* %s */", __func__); + /* 2 keys + 2 values */ assert_se(json_variant_elements(v) == 4); @@ -216,13 +229,12 @@ static void test_2(JsonVariant *v) { } static void test_zeroes(JsonVariant *v) { - size_t i; - /* Make sure zero is how we expect it. */ + log_info("/* %s */", __func__); assert_se(json_variant_elements(v) == 13); - for (i = 0; i < json_variant_elements(v); i++) { + for (size_t i = 0; i < json_variant_elements(v); i++) { JsonVariant *w; size_t j; @@ -255,6 +267,8 @@ static void test_zeroes(JsonVariant *v) { } static void test_build(void) { + log_info("/* %s */", __func__); + _cleanup_(json_variant_unrefp) JsonVariant *a = NULL, *b = NULL; _cleanup_free_ char *s = NULL, *t = NULL; @@ -355,6 +369,8 @@ static void test_source(void) { "false, 7.5, {} ]\n" "}\n"; + log_info("/* %s */", __func__); + _cleanup_fclose_ FILE *f = NULL; _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; @@ -376,15 +392,16 @@ static void test_source(void) { } static void test_depth(void) { + log_info("/* %s */", __func__); + _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; - unsigned i; int r; v = JSON_VARIANT_STRING_CONST("start"); /* Let's verify that the maximum depth checks work */ - for (i = 0;; i++) { + for (unsigned i = 0;; i++) { _cleanup_(json_variant_unrefp) JsonVariant *w = NULL; assert_se(i <= UINT16_MAX); @@ -415,6 +432,8 @@ static void test_depth(void) { } static void test_normalize(void) { + log_info("/* %s */", __func__); + _cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *w = NULL; _cleanup_free_ char *t = NULL; @@ -459,12 +478,13 @@ static void test_normalize(void) { } static void test_bisect(void) { + log_info("/* %s */", __func__); + _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; - char c; /* Tests the bisection logic in json_variant_by_key() */ - for (c = 'z'; c >= 'a'; c--) { + for (char c = 'z'; c >= 'a'; c--) { if ((c % 3) == 0) continue; @@ -484,7 +504,7 @@ static void test_bisect(void) { json_variant_dump(v, JSON_FORMAT_COLOR|JSON_FORMAT_PRETTY, NULL, NULL); - for (c = 'a'; c <= 'z'; c++) { + for (char c = 'a'; c <= 'z'; c++) { JsonVariant *k; const char *z; |