summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/shared/json.c1
-rw-r--r--src/test/test-json.c24
2 files changed, 24 insertions, 1 deletions
diff --git a/src/shared/json.c b/src/shared/json.c
index 5e162ec0ff..58d6117ac9 100644
--- a/src/shared/json.c
+++ b/src/shared/json.c
@@ -515,7 +515,6 @@ static void json_variant_set(JsonVariant *a, JsonVariant *b) {
static void json_variant_copy_source(JsonVariant *v, JsonVariant *from) {
assert(v);
- assert(from);
if (!json_variant_is_regular(from))
return;
diff --git a/src/test/test-json.c b/src/test/test-json.c
index d0bc810c7f..d1d551e746 100644
--- a/src/test/test-json.c
+++ b/src/test/test-json.c
@@ -569,6 +569,29 @@ static void test_float(void) {
test_float_match(w);
}
+static void test_equal_text(JsonVariant *v, const char *text) {
+ _cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
+
+ assert_se(json_parse(text, 0, &w, NULL, NULL) >= 0);
+ assert_se(json_variant_equal(v, w) || (!v && json_variant_is_null(w)));
+}
+
+static void test_set_field(void) {
+ _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
+
+ log_info("/* %s */", __func__);
+
+ test_equal_text(v, "null");
+ assert_se(json_variant_set_field(&v, "foo", NULL) >= 0);
+ test_equal_text(v, "{\"foo\" : null}");
+ assert_se(json_variant_set_field(&v, "bar", JSON_VARIANT_STRING_CONST("quux")) >= 0);
+ test_equal_text(v, "{\"foo\" : null, \"bar\" : \"quux\"}");
+ assert_se(json_variant_set_field(&v, "foo", JSON_VARIANT_STRING_CONST("quux2")) >= 0);
+ test_equal_text(v, "{\"foo\" : \"quux2\", \"bar\" : \"quux\"}");
+ assert_se(json_variant_set_field(&v, "bar", NULL) >= 0);
+ test_equal_text(v, "{\"foo\" : \"quux2\", \"bar\" : null}");
+}
+
int main(int argc, char *argv[]) {
test_setup_logging(LOG_DEBUG);
@@ -622,6 +645,7 @@ int main(int argc, char *argv[]) {
test_normalize();
test_bisect();
test_float();
+ test_set_field();
return 0;
}