From: Maanya Goenka Date: Mon, 16 Aug 2021 22:55:51 +0000 (-0700) Subject: set: modify the previously incorrect definition of set_copy and add test for it X-Git-Tag: v250-rc1~794^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5ef8b072e911fdb66aa7927e65e2cf1b35b9986c;p=thirdparty%2Fsystemd.git set: modify the previously incorrect definition of set_copy and add test for it --- diff --git a/src/basic/set.h b/src/basic/set.h index 0f8673934f1..5cae13160bc 100644 --- a/src/basic/set.h +++ b/src/basic/set.h @@ -26,7 +26,7 @@ static inline Set* set_free_free(Set *s) { /* no set_free_free_free */ -#define set_copy(s) ((Set*) _hashmap_copy(HASHMAP_BASE(h) HASHMAP_DEBUG_SRC_ARGS)) +#define set_copy(s) ((Set*) _hashmap_copy(HASHMAP_BASE(s) HASHMAP_DEBUG_SRC_ARGS)) int _set_ensure_allocated(Set **s, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS); #define set_ensure_allocated(h, ops) _set_ensure_allocated(h, ops HASHMAP_DEBUG_SRC_ARGS) diff --git a/src/test/test-set.c b/src/test/test-set.c index f89c968f21a..fd12021cfa7 100644 --- a/src/test/test-set.c +++ b/src/test/test-set.c @@ -117,6 +117,38 @@ static void test_set_ensure_allocated(void) { assert_se(set_size(m) == 0); } +static void test_set_copy(void) { + Set *s, *copy; + char *key1, *key2, *key3, *key4; + + log_info("/* %s */", __func__); + + key1 = strdup("key1"); + assert_se(key1); + key2 = strdup("key2"); + assert_se(key2); + key3 = strdup("key3"); + assert_se(key3); + key4 = strdup("key4"); + assert_se(key4); + + s = set_new(&string_hash_ops); + assert_se(s); + + assert_se(set_put(s, key1) >= 0); + assert_se(set_put(s, key2) >= 0); + assert_se(set_put(s, key3) >= 0); + assert_se(set_put(s, key4) >= 0); + + copy = set_copy(s); + assert_se(copy); + + assert(set_equal(s, copy)); + + set_free(s); + set_free_free(copy); +} + static void test_set_ensure_put(void) { _cleanup_set_free_ Set *m = NULL; @@ -311,6 +343,7 @@ int main(int argc, const char *argv[]) { test_set_ensure_consume(); test_set_strjoin(); test_set_equal(); + test_set_copy(); return 0; }