summaryrefslogtreecommitdiffstats
path: root/src/test/test-json.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-11-01 14:56:44 +0100
committerLennart Poettering <lennart@poettering.net>2022-12-15 11:39:57 +0100
commit3bb326c558c33402923e081332170e574ed56c3f (patch)
tree46ae7834533da39212a7b1623670e294633dc336 /src/test/test-json.c
parentMerge pull request #25350 from poettering/efi-guid-equal (diff)
downloadsystemd-3bb326c558c33402923e081332170e574ed56c3f.tar.xz
systemd-3bb326c558c33402923e081332170e574ed56c3f.zip
json: add helper for adding variant to array suppressing duplicates
Diffstat (limited to 'src/test/test-json.c')
-rw-r--r--src/test/test-json.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/test/test-json.c b/src/test/test-json.c
index 7ff9c560dd..0f5c5b1a6e 100644
--- a/src/test/test-json.c
+++ b/src/test/test-json.c
@@ -726,4 +726,29 @@ TEST(json_array_append_without_source) {
json_array_append_with_source_one(false);
}
+TEST(json_array_append_nodup) {
+ _cleanup_(json_variant_unrefp) JsonVariant *l = NULL, *s = NULL, *wd = NULL, *nd = NULL;
+
+ assert_se(json_build(&l, JSON_BUILD_STRV(STRV_MAKE("foo", "bar", "baz", "bar", "baz", "foo", "qux", "baz"))) >= 0);
+ assert_se(json_build(&s, JSON_BUILD_STRV(STRV_MAKE("foo", "bar", "baz", "qux"))) >= 0);
+
+ assert_se(!json_variant_equal(l, s));
+ assert_se(json_variant_elements(l) == 8);
+ assert_se(json_variant_elements(s) == 4);
+
+ JsonVariant *i;
+ JSON_VARIANT_ARRAY_FOREACH(i, l) {
+ assert_se(json_variant_append_array(&wd, i) >= 0);
+ assert_se(json_variant_append_array_nodup(&nd, i) >= 0);
+ }
+
+ assert_se(json_variant_elements(wd) == 8);
+ assert_se(json_variant_equal(l, wd));
+ assert_se(!json_variant_equal(s, wd));
+
+ assert_se(json_variant_elements(nd) == 4);
+ assert_se(!json_variant_equal(l, nd));
+ assert_se(json_variant_equal(s, nd));
+}
+
DEFINE_TEST_MAIN(LOG_DEBUG);