chiark / gitweb /
sd-rtnl: fix bogus warning about dropping 20 bytes from multi-part messages
[elogind.git] / src / test / test-fdset.c
index ed83ee18dea9fe44b9b9de4e607bd89ba5bb80e5..91df7eb6631fe2ee26e0921a51e7f44c97e3f4b5 100644 (file)
@@ -106,9 +106,61 @@ static void test_fdset_close_others(void) {
         unlink(name);
 }
 
+static void test_fdset_remove(void) {
+        _cleanup_close_ int fd = -1;
+        FDSet *fdset = NULL;
+        char name[] = "/tmp/test-fdset_remove.XXXXXX";
+
+        fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
+        assert_se(fd >= 0);
+
+        fdset = fdset_new();
+        assert_se(fdset);
+        assert_se(fdset_put(fdset, fd) >= 0);
+        assert_se(fdset_remove(fdset, fd) >= 0);
+        assert_se(!fdset_contains(fdset, fd));
+        fdset_free(fdset);
+
+        assert_se(fcntl(fd, F_GETFD) >= 0);
+
+        unlink(name);
+}
+
+static void test_fdset_iterate(void) {
+        int fd = -1;
+        FDSet *fdset = NULL;
+        char name[] = "/tmp/test-fdset_iterate.XXXXXX";
+        Iterator i;
+        int c = 0;
+        int a;
+
+        fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
+        assert_se(fd >= 0);
+
+        fdset = fdset_new();
+        assert_se(fdset);
+        assert_se(fdset_put(fdset, fd) >= 0);
+        assert_se(fdset_put(fdset, fd) >= 0);
+        assert_se(fdset_put(fdset, fd) >= 0);
+
+        FDSET_FOREACH(a, fdset, i) {
+                c++;
+                assert_se(a == fd);
+        }
+        assert_se(c == 1);
+
+        fdset_free(fdset);
+
+        unlink(name);
+}
+
 int main(int argc, char *argv[]) {
         test_fdset_new_fill();
         test_fdset_put_dup();
         test_fdset_cloexec();
         test_fdset_close_others();
+        test_fdset_remove();
+        test_fdset_iterate();
+
+        return 0;
 }