mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-24 22:46:15 +01:00
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
This commit is contained in:
parent
7d0db04223
commit
80b6074aa2
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user