From 0805e9a9c87845be9f801efacc0a358da6991190 Mon Sep 17 00:00:00 2001 From: Ronny Chevalier Date: Sat, 23 May 2015 18:51:38 +0200 Subject: test-fdset: add more tests add tests for the following functions: - fdset_new_array - fdset_steal_first - fdset_isempty --- src/test/test-fdset.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'src/test/test-fdset.c') diff --git a/src/test/test-fdset.c b/src/test/test-fdset.c index 91df7eb663..242c5d9dc2 100644 --- a/src/test/test-fdset.c +++ b/src/test/test-fdset.c @@ -154,6 +154,56 @@ static void test_fdset_iterate(void) { unlink(name); } +static void test_fdset_isempty(void) { + int fd; + _cleanup_fdset_free_ FDSet *fdset = NULL; + char name[] = "/tmp/test-fdset_isempty.XXXXXX"; + + fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC); + assert_se(fd >= 0); + + fdset = fdset_new(); + assert_se(fdset); + + assert_se(fdset_isempty(fdset)); + assert_se(fdset_put(fdset, fd) >= 0); + assert_se(!fdset_isempty(fdset)); + + unlink(name); +} + +static void test_fdset_steal_first(void) { + int fd; + _cleanup_fdset_free_ FDSet *fdset = NULL; + char name[] = "/tmp/test-fdset_steal_first.XXXXXX"; + + fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC); + assert_se(fd >= 0); + + fdset = fdset_new(); + assert_se(fdset); + + assert_se(fdset_steal_first(fdset) < 0); + assert_se(fdset_put(fdset, fd) >= 0); + assert_se(fdset_steal_first(fdset) == fd); + assert_se(fdset_steal_first(fdset) < 0); + assert_se(fdset_put(fdset, fd) >= 0); + + unlink(name); +} + +static void test_fdset_new_array(void) { + int fds[] = {10, 11, 12, 13}; + _cleanup_fdset_free_ FDSet *fdset = NULL; + + assert_se(fdset_new_array(&fdset, fds, 4) >= 0); + assert_se(fdset_size(fdset) == 4); + assert_se(fdset_contains(fdset, 10)); + assert_se(fdset_contains(fdset, 11)); + assert_se(fdset_contains(fdset, 12)); + assert_se(fdset_contains(fdset, 13)); +} + int main(int argc, char *argv[]) { test_fdset_new_fill(); test_fdset_put_dup(); @@ -161,6 +211,9 @@ int main(int argc, char *argv[]) { test_fdset_close_others(); test_fdset_remove(); test_fdset_iterate(); + test_fdset_isempty(); + test_fdset_steal_first(); + test_fdset_new_array(); return 0; } -- cgit v1.2.3-54-g00ecf