]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-json: add function headers
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 1 Sep 2020 07:29:13 +0000 (09:29 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 1 Sep 2020 14:48:40 +0000 (16:48 +0200)
src/test/test-json.c

index 3295287a6779e423974243c1b396a30f2f18795d..6da93d6aed6291844b26c7313ec71a6a20f603c1 100644 (file)
@@ -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;