diff options
author | Lennart Poettering <lennart@poettering.net> | 2017-09-25 17:15:59 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2017-09-26 16:17:22 +0200 |
commit | ca543871b743423c5de28927895fe6021e6665b1 (patch) | |
tree | 267e3f2947195f328a34f8bb26f6d24b63235285 /src/test/test-set.c | |
parent | test-cpu-set-util.c: fix typo in comment (#6916) (diff) | |
download | systemd-ca543871b743423c5de28927895fe6021e6665b1.tar.xz systemd-ca543871b743423c5de28927895fe6021e6665b1.zip |
set: add new helper set_make() which is like set_new() + multiple set_put() in vararg
Diffstat (limited to 'src/test/test-set.c')
-rw-r--r-- | src/test/test-set.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/test/test-set.c b/src/test/test-set.c index 0ee5ddcc9f..3fab350cf6 100644 --- a/src/test/test-set.c +++ b/src/test/test-set.c @@ -55,9 +55,54 @@ static void test_set_put(void) { assert_se(set_put(m, (void*) "22") == 0); } +static void test_set_make(void) { + _cleanup_set_free_ Set *s = NULL; + + assert_se(set_make(&s, NULL, UINT_TO_PTR(4), UINT_TO_PTR(6), UINT_TO_PTR(8), NULL) == 0); + assert_se(set_size(s) == 3); + assert_se(!set_contains(s, UINT_TO_PTR(0))); + assert_se(!set_contains(s, UINT_TO_PTR(1))); + assert_se(!set_contains(s, UINT_TO_PTR(2))); + assert_se(!set_contains(s, UINT_TO_PTR(3))); + assert_se(set_contains(s, UINT_TO_PTR(4))); + assert_se(!set_contains(s, UINT_TO_PTR(5))); + assert_se(set_contains(s, UINT_TO_PTR(6))); + assert_se(!set_contains(s, UINT_TO_PTR(7))); + assert_se(set_contains(s, UINT_TO_PTR(8))); + assert_se(!set_contains(s, UINT_TO_PTR(9))); + s = set_free(s); + + assert_se(set_make(&s, NULL, NULL) == 0); + assert_se(set_size(s) == 0); + assert_se(!set_contains(s, UINT_TO_PTR(0))); + assert_se(!set_contains(s, UINT_TO_PTR(4))); + assert_se(!set_contains(s, UINT_TO_PTR(6))); + assert_se(!set_contains(s, UINT_TO_PTR(8))); + s = set_free(s); + + assert_se(set_make(&s, NULL, UINT_TO_PTR(3), NULL) == 0); + assert_se(set_size(s) == 1); + assert_se(!set_contains(s, UINT_TO_PTR(0))); + assert_se(!set_contains(s, UINT_TO_PTR(1))); + assert_se(!set_contains(s, UINT_TO_PTR(2))); + assert_se(set_contains(s, UINT_TO_PTR(3))); + assert_se(!set_contains(s, UINT_TO_PTR(4))); + + assert_se(set_make(&s, NULL, UINT_TO_PTR(2), UINT_TO_PTR(5), NULL) == 0); + assert_se(set_size(s) == 2); + assert_se(!set_contains(s, UINT_TO_PTR(0))); + assert_se(!set_contains(s, UINT_TO_PTR(1))); + assert_se(set_contains(s, UINT_TO_PTR(2))); + assert_se(!set_contains(s, UINT_TO_PTR(3))); + assert_se(!set_contains(s, UINT_TO_PTR(4))); + assert_se(set_contains(s, UINT_TO_PTR(5))); + assert_se(!set_contains(s, UINT_TO_PTR(6))); +} + int main(int argc, const char *argv[]) { test_set_steal_first(); test_set_put(); + test_set_make(); return 0; } |