core: set_put never returns -EEXIST

When the value is already there it returns 0.

Also add a test to ensure this
This commit is contained in:
Ronny Chevalier
2015-04-10 17:13:15 +02:00
parent 17493fa5d1
commit 756c09e672
3 changed files with 23 additions and 15 deletions
+17
View File
@@ -39,8 +39,25 @@ static void test_set_steal_first(void) {
assert_se(set_isempty(m));
}
static void test_set_put(void) {
_cleanup_set_free_ Set *m = NULL;
m = set_new(&string_hash_ops);
assert_se(m);
assert_se(set_put(m, (void*) "1") == 1);
assert_se(set_put(m, (void*) "22") == 1);
assert_se(set_put(m, (void*) "333") == 1);
assert_se(set_put(m, (void*) "333") == 0);
assert_se(set_remove(m, (void*) "333"));
assert_se(set_put(m, (void*) "333") == 1);
assert_se(set_put(m, (void*) "333") == 0);
assert_se(set_put(m, (void*) "22") == 0);
}
int main(int argc, const char *argv[]) {
test_set_steal_first();
test_set_put();
return 0;
}