Merge pull request #16238 from keszybz/set-handling-more
Fix handling of cases where a duplicate item is added to a set and related cleanups
This commit is contained in:
@@ -107,6 +107,49 @@ static void test_set_put_strdupv(void) {
|
||||
assert_se(set_size(m) == 3);
|
||||
}
|
||||
|
||||
static void test_set_ensure_allocated(void) {
|
||||
_cleanup_set_free_ Set *m = NULL;
|
||||
|
||||
assert_se(set_ensure_allocated(&m, &string_hash_ops) == 1);
|
||||
assert_se(set_ensure_allocated(&m, &string_hash_ops) == 0);
|
||||
assert_se(set_ensure_allocated(&m, NULL) == 0);
|
||||
assert_se(set_size(m) == 0);
|
||||
}
|
||||
|
||||
static void test_set_ensure_put(void) {
|
||||
_cleanup_set_free_ Set *m = NULL;
|
||||
|
||||
assert_se(set_ensure_put(&m, &string_hash_ops, "a") == 1);
|
||||
assert_se(set_ensure_put(&m, &string_hash_ops, "a") == 0);
|
||||
assert_se(set_ensure_put(&m, NULL, "a") == 0);
|
||||
assert_se(set_ensure_put(&m, &string_hash_ops, "b") == 1);
|
||||
assert_se(set_ensure_put(&m, &string_hash_ops, "b") == 0);
|
||||
assert_se(set_ensure_put(&m, &string_hash_ops, "a") == 0);
|
||||
assert_se(set_size(m) == 2);
|
||||
}
|
||||
|
||||
static void test_set_ensure_consume(void) {
|
||||
_cleanup_set_free_ Set *m = NULL;
|
||||
char *s, *t;
|
||||
|
||||
assert_se(s = strdup("a"));
|
||||
assert_se(set_ensure_consume(&m, &string_hash_ops_free, s) == 1);
|
||||
|
||||
assert_se(t = strdup("a"));
|
||||
assert_se(set_ensure_consume(&m, &string_hash_ops_free, t) == 0);
|
||||
|
||||
assert_se(t = strdup("a"));
|
||||
assert_se(set_ensure_consume(&m, &string_hash_ops_free, t) == 0);
|
||||
|
||||
assert_se(t = strdup("b"));
|
||||
assert_se(set_ensure_consume(&m, &string_hash_ops_free, t) == 1);
|
||||
|
||||
assert_se(t = strdup("b"));
|
||||
assert_se(set_ensure_consume(&m, &string_hash_ops_free, t) == 0);
|
||||
|
||||
assert_se(set_size(m) == 2);
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
test_set_steal_first();
|
||||
test_set_free_with_destructor();
|
||||
@@ -114,6 +157,9 @@ int main(int argc, const char *argv[]) {
|
||||
test_set_put();
|
||||
test_set_put_strdup();
|
||||
test_set_put_strdupv();
|
||||
test_set_ensure_allocated();
|
||||
test_set_ensure_put();
|
||||
test_set_ensure_consume();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user