From 80b6074aa27815e3c824f1e01ccb2431b03feec4 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Wed, 20 Jun 2012 10:14:01 -0400 Subject: [PATCH] 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 file changed, 18 insertions(+), 1 deletion(-) diff --git a/gio/tests/pollable.c b/gio/tests/pollable.c index dd63a042f..fe12d3261 100644 --- a/gio/tests/pollable.c +++ b/gio/tests/pollable.c @@ -21,6 +21,7 @@ #include #ifdef G_OS_UNIX +#include #include #include #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