[glib] gio/tests/pollable: add can_poll() assertions



commit 80b6074aa27815e3c824f1e01ccb2431b03feec4
Author: Dan Winship <danw gnome org>
Date:   Wed Jun 20 10:14:01 2012 -0400

    gio/tests/pollable: add can_poll() assertions
    
    Assert that socket streams and socket/pipe-based unix streams are
    pollable, and file-based unix streams are not.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=677770

 gio/tests/pollable.c |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)
---
diff --git a/gio/tests/pollable.c b/gio/tests/pollable.c
index dd63a04..fe12d32 100644
--- a/gio/tests/pollable.c
+++ b/gio/tests/pollable.c
@@ -21,6 +21,7 @@
 #include <gio/gio.h>
 
 #ifdef G_OS_UNIX
+#include <fcntl.h>
 #include <gio/gunixinputstream.h>
 #include <gio/gunixoutputstream.h>
 #endif
@@ -92,6 +93,9 @@ test_streams (void)
   GSource *poll_source;
   gboolean success = FALSE;
 
+  g_assert (g_pollable_input_stream_can_poll (in));
+  g_assert (g_pollable_output_stream_can_poll (G_POLLABLE_OUTPUT_STREAM (out)));
+
   readable = g_pollable_input_stream_is_readable (in);
   g_assert (!readable);
 
@@ -136,7 +140,7 @@ test_streams (void)
 static void
 test_pollable_unix (void)
 {
-  int pipefds[2], status;
+  int pipefds[2], status, fd;
 
   status = pipe (pipefds);
   g_assert_cmpint (status, ==, 0);
@@ -148,6 +152,19 @@ test_pollable_unix (void)
 
   g_object_unref (in);
   g_object_unref (out);
+
+  /* Non-pipe/socket unix streams are not pollable */
+  fd = open ("/dev/null", O_RDWR);
+  g_assert_cmpint (fd, !=, -1);
+  in = G_POLLABLE_INPUT_STREAM (g_unix_input_stream_new (fd, FALSE));
+  out = g_unix_output_stream_new (fd, FALSE);
+
+  g_assert (!g_pollable_input_stream_can_poll (in));
+  g_assert (!g_pollable_output_stream_can_poll (G_POLLABLE_OUTPUT_STREAM (out)));
+
+  g_object_unref (in);
+  g_object_unref (out);
+  close (fd);
 }
 #endif
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]