test-fdset: add more tests

add tests for the following functions:
- fdset_new_array
- fdset_steal_first
- fdset_isempty
This commit is contained in:
Ronny Chevalier 2015-05-23 18:51:38 +02:00
parent 0763adbed5
commit 0805e9a9c8

View file

@ -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;
}