]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-fdset: add more tests
authorRonny Chevalier <chevalier.ronny@gmail.com>
Sat, 23 May 2015 16:51:38 +0000 (18:51 +0200)
committerRonny Chevalier <chevalier.ronny@gmail.com>
Sat, 30 May 2015 09:19:35 +0000 (11:19 +0200)
add tests for the following functions:
- fdset_new_array
- fdset_steal_first
- fdset_isempty

src/test/test-fdset.c

index 91df7eb6631fe2ee26e0921a51e7f44c97e3f4b5..242c5d9dc29aa943aff619f6bef468806c815534 100644 (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;
 }