diff options
author | Maanya Goenka <t-magoenka@microsoft.com> | 2021-08-17 00:55:51 +0200 |
---|---|---|
committer | Maanya Goenka <t-magoenka@microsoft.com> | 2021-08-20 19:02:49 +0200 |
commit | 5ef8b072e911fdb66aa7927e65e2cf1b35b9986c (patch) | |
tree | d8bf0c1dc33e4b9634c934e2ab0f0196a529da1d /src/test/test-set.c | |
parent | Merge pull request #20488 from yuwata/timesync-fix (diff) | |
download | systemd-5ef8b072e911fdb66aa7927e65e2cf1b35b9986c.tar.xz systemd-5ef8b072e911fdb66aa7927e65e2cf1b35b9986c.zip |
set: modify the previously incorrect definition of set_copy and add test for it
Diffstat (limited to 'src/test/test-set.c')
-rw-r--r-- | src/test/test-set.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/test/test-set.c b/src/test/test-set.c index f89c968f21..fd12021cfa 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; } |