1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-23 21:35:11 +03:00

set: modify the previously incorrect definition of set_copy and add test for it

This commit is contained in:
Maanya Goenka 2021-08-16 15:55:51 -07:00
parent 72fba0c4e5
commit 5ef8b072e9
2 changed files with 34 additions and 1 deletions

View File

@ -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)

View File

@ -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;
}